@@ -80,7 +80,6 @@ void MCContext::reset() {
80
80
MCSubtargetAllocator.DestroyAll ();
81
81
UsedNames.clear ();
82
82
Symbols.clear ();
83
- SectionSymbols.clear ();
84
83
Allocator.Reset ();
85
84
Instances.clear ();
86
85
CompilationDir.clear ();
@@ -124,18 +123,6 @@ MCSymbol *MCContext::getOrCreateSymbol(const Twine &Name) {
124
123
return Sym;
125
124
}
126
125
127
- MCSymbolELF *MCContext::getOrCreateSectionSymbol (const MCSectionELF &Section) {
128
- MCSymbol *&Sym = SectionSymbols[&Section];
129
- if (Sym)
130
- return cast<MCSymbolELF>(Sym);
131
-
132
- StringRef Name = Section.getSectionName ();
133
- auto NameIter = UsedNames.insert (std::make_pair (Name, false )).first ;
134
- Sym = new (&*NameIter, *this ) MCSymbolELF (&*NameIter, /* isTemporary*/ false );
135
-
136
- return cast<MCSymbolELF>(Sym);
137
- }
138
-
139
126
MCSymbol *MCContext::getOrCreateFrameAllocSymbol (StringRef FuncName,
140
127
unsigned Idx) {
141
128
return getOrCreateSymbol (Twine (MAI->getPrivateGlobalPrefix ()) + FuncName +
@@ -316,6 +303,38 @@ void MCContext::renameELFSection(MCSectionELF *Section, StringRef Name) {
316
303
const_cast <MCSectionELF *>(Section)->setSectionName (CachedName);
317
304
}
318
305
306
+ MCSectionELF *MCContext::createELFSectionImpl (StringRef Section, unsigned Type,
307
+ unsigned Flags, SectionKind K,
308
+ unsigned EntrySize,
309
+ const MCSymbolELF *Group,
310
+ unsigned UniqueID,
311
+ const MCSectionELF *Associated) {
312
+
313
+ MCSymbolELF *R;
314
+ MCSymbol *&Sym = Symbols[Section];
315
+ if (Sym && Sym->isUndefined ()) {
316
+ R = cast<MCSymbolELF>(Sym);
317
+ } else {
318
+ auto NameIter = UsedNames.insert (std::make_pair (Section, false )).first ;
319
+ R = new (&*NameIter, *this ) MCSymbolELF (&*NameIter, /* isTemporary*/ false );
320
+ if (!Sym)
321
+ Sym = R;
322
+ }
323
+ R->setBinding (ELF::STB_LOCAL);
324
+ R->setType (ELF::STT_SECTION);
325
+ R->setRedefinable (true );
326
+
327
+ auto *Ret = new (ELFAllocator.Allocate ()) MCSectionELF (
328
+ Section, Type, Flags, K, EntrySize, Group, UniqueID , R, Associated);
329
+
330
+ auto *F = new MCDataFragment ();
331
+ Ret->getFragmentList ().insert (Ret->begin (), F);
332
+ F->setParent (Ret);
333
+ R->setFragment (F);
334
+
335
+ return Ret;
336
+ }
337
+
319
338
MCSectionELF *MCContext::createELFRelSection (const Twine &Name, unsigned Type,
320
339
unsigned Flags, unsigned EntrySize,
321
340
const MCSymbolELF *Group,
@@ -325,9 +344,9 @@ MCSectionELF *MCContext::createELFRelSection(const Twine &Name, unsigned Type,
325
344
std::tie (I, Inserted) =
326
345
ELFRelSecNames.insert (std::make_pair (Name.str (), true ));
327
346
328
- return new (ELFAllocator. Allocate ())
329
- MCSectionELF (I-> getKey (), Type, Flags, SectionKind::getReadOnly (),
330
- EntrySize, Group, true , nullptr , Associated);
347
+ return createELFSectionImpl (I-> getKey (), Type, Flags,
348
+ SectionKind::getReadOnly (), EntrySize, Group ,
349
+ true , Associated);
331
350
}
332
351
333
352
MCSectionELF *MCContext::getELFNamedSection (const Twine &Prefix,
@@ -339,21 +358,19 @@ MCSectionELF *MCContext::getELFNamedSection(const Twine &Prefix,
339
358
340
359
MCSectionELF *MCContext::getELFSection (const Twine &Section, unsigned Type,
341
360
unsigned Flags, unsigned EntrySize,
342
- const Twine &Group, unsigned UniqueID,
343
- const char *BeginSymName) {
361
+ const Twine &Group, unsigned UniqueID) {
344
362
MCSymbolELF *GroupSym = nullptr ;
345
363
if (!Group.isTriviallyEmpty () && !Group.str ().empty ())
346
364
GroupSym = cast<MCSymbolELF>(getOrCreateSymbol (Group));
347
365
348
366
return getELFSection (Section, Type, Flags, EntrySize, GroupSym, UniqueID ,
349
- BeginSymName, nullptr );
367
+ nullptr );
350
368
}
351
369
352
370
MCSectionELF *MCContext::getELFSection (const Twine &Section, unsigned Type,
353
371
unsigned Flags, unsigned EntrySize,
354
372
const MCSymbolELF *GroupSym,
355
373
unsigned UniqueID,
356
- const char *BeginSymName,
357
374
const MCSectionELF *Associated) {
358
375
StringRef Group = " " ;
359
376
if (GroupSym)
@@ -375,22 +392,16 @@ MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
375
392
else
376
393
Kind = SectionKind::getReadOnly ();
377
394
378
- MCSymbol *Begin = nullptr ;
379
- if (BeginSymName)
380
- Begin = createTempSymbol (BeginSymName, false );
381
-
382
- MCSectionELF *Result = new (ELFAllocator.Allocate ())
383
- MCSectionELF (CachedName, Type, Flags, Kind, EntrySize, GroupSym, UniqueID ,
384
- Begin, Associated);
395
+ MCSectionELF *Result = createELFSectionImpl (
396
+ CachedName, Type, Flags, Kind, EntrySize, GroupSym, UniqueID , Associated);
385
397
Entry.second = Result;
386
398
return Result;
387
399
}
388
400
389
401
MCSectionELF *MCContext::createELFGroupSection (const MCSymbolELF *Group) {
390
- MCSectionELF *Result = new (ELFAllocator.Allocate ())
391
- MCSectionELF (" .group" , ELF::SHT_GROUP, 0 , SectionKind::getReadOnly (), 4 ,
392
- Group, ~0 , nullptr , nullptr );
393
- return Result;
402
+ return createELFSectionImpl (" .group" , ELF::SHT_GROUP, 0 ,
403
+ SectionKind::getReadOnly (), 4 , Group, ~0 ,
404
+ nullptr );
394
405
}
395
406
396
407
MCSectionCOFF *MCContext::getCOFFSection (StringRef Section,
0 commit comments