1 //===- InputSegment.h -------------------------------------------*- C++ -*-===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Represents a WebAssembly data segment which can be included as part of
11 // an output data segments. Note that in WebAssembly, unlike ELF and other
12 // formats, used the term "data segment" to refer to the continous regions of
13 // memory that make on the data section. See:
14 // https://webassembly.github.io/spec/syntax/modules.html#syntax-data
16 // For example, by default, clang will produce a separate data section for
17 // each global variable.
19 //===----------------------------------------------------------------------===//
21 #ifndef LLD_WASM_INPUT_SEGMENT_H
22 #define LLD_WASM_INPUT_SEGMENT_H
24 #include "WriterUtils.h"
25 #include "lld/Common/ErrorHandler.h"
26 #include "llvm/Object/Wasm.h"
28 using llvm::object::WasmSegment;
29 using llvm::wasm::WasmRelocation;
39 InputSegment(const WasmSegment *Seg, const ObjFile *F)
40 : Segment(Seg), File(F) {}
42 // Translate an offset in the input segment to an offset in the output
44 uint32_t translateVA(uint32_t Address) const;
46 const OutputSegment *getOutputSegment() const { return OutputSeg; }
48 uint32_t getOutputSegmentOffset() const { return OutputSegmentOffset; }
50 uint32_t getInputSectionOffset() const { return Segment->SectionOffset; }
52 void setOutputSegment(const OutputSegment *Segment, uint32_t Offset) {
54 OutputSegmentOffset = Offset;
57 uint32_t getSize() const { return Segment->Data.Content.size(); }
58 uint32_t getAlignment() const { return Segment->Data.Alignment; }
59 uint32_t startVA() const { return Segment->Data.Offset.Value.Int32; }
60 uint32_t endVA() const { return startVA() + getSize(); }
61 StringRef getName() const { return Segment->Data.Name; }
63 const WasmSegment *Segment;
65 std::vector<WasmRelocation> Relocations;
66 std::vector<OutputRelocation> OutRelocations;
69 const OutputSegment *OutputSeg = nullptr;
70 uint32_t OutputSegmentOffset = 0;
76 #endif // LLD_WASM_INPUT_SEGMENT_H