CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
139 lines
4.2 KiB
C++
139 lines
4.2 KiB
C++
//===- OutputSections.h -----------------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLD_WASM_OUTPUT_SECTIONS_H
|
|
#define LLD_WASM_OUTPUT_SECTIONS_H
|
|
|
|
#include "InputChunks.h"
|
|
#include "WriterUtils.h"
|
|
#include "lld/Common/ErrorHandler.h"
|
|
#include "lld/Common/LLVM.h"
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
namespace lld {
|
|
|
|
namespace wasm {
|
|
class OutputSection;
|
|
}
|
|
std::string toString(const wasm::OutputSection §ion);
|
|
|
|
namespace wasm {
|
|
|
|
class OutputSegment;
|
|
|
|
class OutputSection {
|
|
public:
|
|
OutputSection(uint32_t type, std::string name = "")
|
|
: type(type), name(name) {}
|
|
virtual ~OutputSection() = default;
|
|
|
|
StringRef getSectionName() const;
|
|
void setOffset(size_t newOffset) { offset = newOffset; }
|
|
void createHeader(size_t bodySize);
|
|
virtual bool isNeeded() const { return true; }
|
|
virtual size_t getSize() const = 0;
|
|
virtual size_t getOffset() { return offset; }
|
|
virtual void writeTo(uint8_t *buf) = 0;
|
|
virtual void finalizeContents() = 0;
|
|
virtual uint32_t getNumRelocations() const { return 0; }
|
|
virtual uint32_t getNumLiveRelocations() const { return getNumRelocations(); }
|
|
virtual void writeRelocations(raw_ostream &os) const {}
|
|
|
|
std::string header;
|
|
uint32_t type;
|
|
uint32_t sectionIndex = UINT32_MAX;
|
|
std::string name;
|
|
OutputSectionSymbol *sectionSym = nullptr;
|
|
|
|
protected:
|
|
size_t offset = 0;
|
|
};
|
|
|
|
class CodeSection : public OutputSection {
|
|
public:
|
|
explicit CodeSection(ArrayRef<InputFunction *> functions)
|
|
: OutputSection(llvm::wasm::WASM_SEC_CODE), functions(functions) {}
|
|
|
|
static bool classof(const OutputSection *sec) {
|
|
return sec->type == llvm::wasm::WASM_SEC_CODE;
|
|
}
|
|
|
|
size_t getSize() const override { return header.size() + bodySize; }
|
|
void writeTo(uint8_t *buf) override;
|
|
uint32_t getNumRelocations() const override;
|
|
void writeRelocations(raw_ostream &os) const override;
|
|
bool isNeeded() const override { return functions.size() > 0; }
|
|
void finalizeContents() override;
|
|
|
|
ArrayRef<InputFunction *> functions;
|
|
|
|
protected:
|
|
std::string codeSectionHeader;
|
|
size_t bodySize = 0;
|
|
};
|
|
|
|
class DataSection : public OutputSection {
|
|
public:
|
|
explicit DataSection(ArrayRef<OutputSegment *> segments)
|
|
: OutputSection(llvm::wasm::WASM_SEC_DATA), segments(segments) {}
|
|
|
|
static bool classof(const OutputSection *sec) {
|
|
return sec->type == llvm::wasm::WASM_SEC_DATA;
|
|
}
|
|
|
|
size_t getSize() const override { return header.size() + bodySize; }
|
|
void writeTo(uint8_t *buf) override;
|
|
uint32_t getNumRelocations() const override;
|
|
void writeRelocations(raw_ostream &os) const override;
|
|
bool isNeeded() const override;
|
|
void finalizeContents() override;
|
|
|
|
ArrayRef<OutputSegment *> segments;
|
|
|
|
protected:
|
|
std::string dataSectionHeader;
|
|
size_t bodySize = 0;
|
|
};
|
|
|
|
// Represents a custom section in the output file. Wasm custom sections are
|
|
// used for storing user-defined metadata. Unlike the core sections types
|
|
// they are identified by their string name.
|
|
// The linker combines custom sections that have the same name by simply
|
|
// concatenating them.
|
|
// Note that some custom sections such as "name" and "linking" are handled
|
|
// separately and are instead synthesized by the linker.
|
|
class CustomSection : public OutputSection {
|
|
public:
|
|
CustomSection(std::string name, ArrayRef<InputChunk *> inputSections)
|
|
: OutputSection(llvm::wasm::WASM_SEC_CUSTOM, name),
|
|
inputSections(inputSections) {}
|
|
|
|
static bool classof(const OutputSection *sec) {
|
|
return sec->type == llvm::wasm::WASM_SEC_CUSTOM;
|
|
}
|
|
|
|
size_t getSize() const override {
|
|
return header.size() + nameData.size() + payloadSize;
|
|
}
|
|
void writeTo(uint8_t *buf) override;
|
|
uint32_t getNumRelocations() const override;
|
|
void writeRelocations(raw_ostream &os) const override;
|
|
void finalizeContents() override;
|
|
|
|
protected:
|
|
void finalizeInputSections();
|
|
size_t payloadSize = 0;
|
|
std::vector<InputChunk *> inputSections;
|
|
std::string nameData;
|
|
};
|
|
|
|
} // namespace wasm
|
|
} // namespace lld
|
|
|
|
#endif // LLD_WASM_OUTPUT_SECTIONS_H
|