@@ -205,46 +205,8 @@ void elf::reportDiscarded(InputSectionBase *IS) {
205
205
IS->File ->getName () + " '" );
206
206
}
207
207
208
- void OutputSectionFactory::addInputSec (InputSectionBase *IS,
209
- StringRef OutsecName) {
210
- // Sections with the SHT_GROUP attribute reach here only when the - r option
211
- // is given. Such sections define "section groups", and InputFiles.cpp has
212
- // dedup'ed section groups by their signatures. For the -r, we want to pass
213
- // through all SHT_GROUP sections without merging them because merging them
214
- // creates broken section contents.
215
- if (IS->Type == SHT_GROUP) {
216
- OutputSection *Out = nullptr ;
217
- addInputSec (IS, OutsecName, Out);
218
- return ;
219
- }
220
-
221
- // Imagine .zed : { *(.foo) *(.bar) } script. Both foo and bar may have
222
- // relocation sections .rela.foo and .rela.bar for example. Most tools do
223
- // not allow multiple REL[A] sections for output section. Hence we
224
- // should combine these relocation sections into single output.
225
- // We skip synthetic sections because it can be .rela.dyn/.rela.plt or any
226
- // other REL[A] sections created by linker itself.
227
- if (!isa<SyntheticSection>(IS) &&
228
- (IS->Type == SHT_REL || IS->Type == SHT_RELA)) {
229
- auto *Sec = cast<InputSection>(IS);
230
- OutputSection *Out = Sec->getRelocatedSection ()->getOutputSection ();
231
- addInputSec (IS, OutsecName, Out->RelocationSection );
232
- return ;
233
- }
234
-
235
- SectionKey Key = createKey (IS, OutsecName);
236
- OutputSection *&Sec = Map[Key];
237
- addInputSec (IS, OutsecName, Sec);
238
- }
239
-
240
- void OutputSectionFactory::addInputSec (InputSectionBase *IS,
241
- StringRef OutsecName,
242
- OutputSection *&Sec) {
243
- if (!IS->Live ) {
244
- reportDiscarded (IS);
245
- return ;
246
- }
247
-
208
+ static OutputSection *addSection (InputSectionBase *IS, StringRef OutsecName,
209
+ OutputSection *Sec) {
248
210
if (Sec && Sec->Live ) {
249
211
if (getIncompatibleFlags (Sec->Flags ) != getIncompatibleFlags (IS->Flags ))
250
212
error (" incompatible section flags for " + Sec->Name + " \n >>> " +
@@ -272,6 +234,50 @@ void OutputSectionFactory::addInputSec(InputSectionBase *IS,
272
234
}
273
235
274
236
Sec->addSection (cast<InputSection>(IS));
237
+ return Sec;
238
+ }
239
+
240
+ void OutputSectionFactory::addInputSec (InputSectionBase *IS,
241
+ StringRef OutsecName,
242
+ OutputSection *OS) {
243
+ if (!IS->Live ) {
244
+ reportDiscarded (IS);
245
+ return ;
246
+ }
247
+
248
+ // If we have destination output section - use it directly.
249
+ if (OS) {
250
+ addSection (IS, OutsecName, OS);
251
+ return ;
252
+ }
253
+
254
+ // Sections with the SHT_GROUP attribute reach here only when the - r option
255
+ // is given. Such sections define "section groups", and InputFiles.cpp has
256
+ // dedup'ed section groups by their signatures. For the -r, we want to pass
257
+ // through all SHT_GROUP sections without merging them because merging them
258
+ // creates broken section contents.
259
+ if (IS->Type == SHT_GROUP) {
260
+ addSection (IS, OutsecName, nullptr );
261
+ return ;
262
+ }
263
+
264
+ // Imagine .zed : { *(.foo) *(.bar) } script. Both foo and bar may have
265
+ // relocation sections .rela.foo and .rela.bar for example. Most tools do
266
+ // not allow multiple REL[A] sections for output section. Hence we
267
+ // should combine these relocation sections into single output.
268
+ // We skip synthetic sections because it can be .rela.dyn/.rela.plt or any
269
+ // other REL[A] sections created by linker itself.
270
+ if (!isa<SyntheticSection>(IS) &&
271
+ (IS->Type == SHT_REL || IS->Type == SHT_RELA)) {
272
+ auto *Sec = cast<InputSection>(IS);
273
+ OutputSection *Out = Sec->getRelocatedSection ()->getOutputSection ();
274
+ Out->RelocationSection = addSection (IS, OutsecName, Out->RelocationSection );
275
+ return ;
276
+ }
277
+
278
+ SectionKey Key = createKey (IS, OutsecName);
279
+ OutputSection *&Sec = Map[Key];
280
+ Sec = addSection (IS, OutsecName, Sec);
275
281
}
276
282
277
283
OutputSectionFactory::~OutputSectionFactory () {}
0 commit comments