@@ -38,6 +38,7 @@ class OutputSection {
38
38
Offset = NewOffset;
39
39
}
40
40
void createHeader (size_t BodySize);
41
+ virtual bool isNeeded () const { return true ; }
41
42
virtual size_t getSize () const = 0;
42
43
virtual void writeTo (uint8_t *Buf) = 0;
43
44
virtual void finalizeContents () = 0;
@@ -46,54 +47,24 @@ class OutputSection {
46
47
47
48
std::string Header;
48
49
uint32_t Type;
50
+ uint32_t SectionIndex = UINT32_MAX;
49
51
std::string Name;
52
+ OutputSectionSymbol *SectionSym = nullptr ;
50
53
51
54
protected:
52
55
size_t Offset = 0 ;
53
56
};
54
57
55
- class SyntheticSection : public OutputSection {
56
- public:
57
- SyntheticSection (uint32_t Type, std::string Name = " " )
58
- : OutputSection(Type, Name), BodyOutputStream(Body) {
59
- if (!Name.empty ())
60
- writeStr (BodyOutputStream, Name, " section name" );
61
- }
62
-
63
- void writeTo (uint8_t *Buf) override {
64
- assert (Offset);
65
- log (" writing " + toString (*this ));
66
- memcpy (Buf + Offset, Header.data (), Header.size ());
67
- memcpy (Buf + Offset + Header.size (), Body.data (), Body.size ());
68
- }
69
-
70
- size_t getSize () const override { return Header.size () + Body.size (); }
71
-
72
- virtual void writeBody () {}
73
-
74
- void finalizeContents () override {
75
- writeBody ();
76
- BodyOutputStream.flush ();
77
- createHeader (Body.size ());
78
- }
79
-
80
- raw_ostream &getStream () { return BodyOutputStream; }
81
-
82
- std::string Body;
83
-
84
- protected:
85
- llvm::raw_string_ostream BodyOutputStream;
86
- };
87
-
88
58
class CodeSection : public OutputSection {
89
59
public:
90
60
explicit CodeSection (ArrayRef<InputFunction *> Functions)
91
61
: OutputSection(llvm::wasm::WASM_SEC_CODE), Functions(Functions) {}
92
62
93
- size_t getSize () const override { assert (BodySize); return Header.size () + BodySize; }
63
+ size_t getSize () const override { return Header.size () + BodySize; }
94
64
void writeTo (uint8_t *Buf) override ;
95
65
uint32_t numRelocations () const override ;
96
66
void writeRelocations (raw_ostream &OS) const override ;
67
+ bool isNeeded () const override { return Functions.size () > 0 ; }
97
68
void finalizeContents () override ;
98
69
99
70
protected:
@@ -111,6 +82,7 @@ class DataSection : public OutputSection {
111
82
void writeTo (uint8_t *Buf) override ;
112
83
uint32_t numRelocations () const override ;
113
84
void writeRelocations (raw_ostream &OS) const override ;
85
+ bool isNeeded () const override { return Segments.size () > 0 ; }
114
86
void finalizeContents () override ;
115
87
116
88
protected:
@@ -145,19 +117,6 @@ class CustomSection : public OutputSection {
145
117
std::string NameData;
146
118
};
147
119
148
- class RelocSection : public SyntheticSection {
149
- public:
150
- RelocSection (StringRef Name, OutputSection *Sec, uint32_t SectionIndex)
151
- : SyntheticSection(llvm::wasm::WASM_SEC_CUSTOM, Name), Sec(Sec),
152
- SectionIndex (SectionIndex) {}
153
- void writeBody () override ;
154
-
155
- protected:
156
- OutputSection* Sec;
157
- uint32_t SectionIndex;
158
- };
159
-
160
-
161
120
} // namespace wasm
162
121
} // namespace lld
163
122
0 commit comments