@@ -415,15 +415,15 @@ template <class ELFT> void DynamicSection<ELFT>::addEntries() {
415
415
// Add strings to .dynstr early so that .dynstr's size will be
416
416
// fixed early.
417
417
for (StringRef S : Config->AuxiliaryList )
418
- Add ({DT_AUXILIARY, Out <ELFT>::DynStrTab->addString (S)});
418
+ Add ({DT_AUXILIARY, In <ELFT>::DynStrTab->addString (S)});
419
419
if (!Config->RPath .empty ())
420
420
Add ({Config->EnableNewDtags ? DT_RUNPATH : DT_RPATH,
421
- Out <ELFT>::DynStrTab->addString (Config->RPath )});
421
+ In <ELFT>::DynStrTab->addString (Config->RPath )});
422
422
for (SharedFile<ELFT> *F : Symtab<ELFT>::X->getSharedFiles ())
423
423
if (F->isNeeded ())
424
- Add ({DT_NEEDED, Out <ELFT>::DynStrTab->addString (F->getSoName ())});
424
+ Add ({DT_NEEDED, In <ELFT>::DynStrTab->addString (F->getSoName ())});
425
425
if (!Config->SoName .empty ())
426
- Add ({DT_SONAME, Out <ELFT>::DynStrTab->addString (Config->SoName )});
426
+ Add ({DT_SONAME, In <ELFT>::DynStrTab->addString (Config->SoName )});
427
427
428
428
// Set DT_FLAGS and DT_FLAGS_1.
429
429
uint32_t DtFlags = 0 ;
@@ -455,7 +455,7 @@ template <class ELFT> void DynamicSection<ELFT>::finalize() {
455
455
if (this ->Size )
456
456
return ; // Already finalized.
457
457
458
- this ->Link = Out <ELFT>::DynStrTab->SectionIndex ;
458
+ this ->Link = In <ELFT>::DynStrTab-> OutSec ->SectionIndex ;
459
459
460
460
if (Out<ELFT>::RelaDyn->hasRelocs ()) {
461
461
bool IsRela = Config->Rela ;
@@ -483,8 +483,8 @@ template <class ELFT> void DynamicSection<ELFT>::finalize() {
483
483
484
484
Add ({DT_SYMTAB, Out<ELFT>::DynSymTab});
485
485
Add ({DT_SYMENT, sizeof (Elf_Sym)});
486
- Add ({DT_STRTAB, Out <ELFT>::DynStrTab});
487
- Add ({DT_STRSZ, Out <ELFT>::DynStrTab->Size });
486
+ Add ({DT_STRTAB, In <ELFT>::DynStrTab});
487
+ Add ({DT_STRSZ, In <ELFT>::DynStrTab->getSize () });
488
488
if (Out<ELFT>::GnuHashTab)
489
489
Add ({DT_GNU_HASH, Out<ELFT>::GnuHashTab});
490
490
if (Out<ELFT>::HashTab)
@@ -650,6 +650,15 @@ template <class ELFT> void OutputSection<ELFT>::finalize() {
650
650
this ->Link = D->OutSec ->SectionIndex ;
651
651
}
652
652
}
653
+
654
+ // Recalculate input section offsets if we own any synthetic section
655
+ for (auto *SS : In<ELFT>::SyntheticSections)
656
+ if (SS && this == SS->OutSec ) {
657
+ this ->Size = 0 ;
658
+ assignOffsets ();
659
+ break ;
660
+ }
661
+
653
662
if (Type != SHT_RELA && Type != SHT_REL)
654
663
return ;
655
664
this ->Link = Out<ELFT>::SymTab->SectionIndex ;
@@ -1051,40 +1060,6 @@ template <class ELFT> void MergeOutputSection<ELFT>::finalizePieces() {
1051
1060
Sec->finalizePieces ();
1052
1061
}
1053
1062
1054
- template <class ELFT >
1055
- StringTableSection<ELFT>::StringTableSection(StringRef Name, bool Dynamic)
1056
- : OutputSectionBase(Name, SHT_STRTAB, Dynamic ? (uintX_t)SHF_ALLOC : 0 ),
1057
- Dynamic (Dynamic) {
1058
- // ELF string tables start with a NUL byte, so 1.
1059
- this ->Size = 1 ;
1060
- }
1061
-
1062
- // Adds a string to the string table. If HashIt is true we hash and check for
1063
- // duplicates. It is optional because the name of global symbols are already
1064
- // uniqued and hashing them again has a big cost for a small value: uniquing
1065
- // them with some other string that happens to be the same.
1066
- template <class ELFT >
1067
- unsigned StringTableSection<ELFT>::addString(StringRef S, bool HashIt) {
1068
- if (HashIt) {
1069
- auto R = StringMap.insert (std::make_pair (S, this ->Size ));
1070
- if (!R.second )
1071
- return R.first ->second ;
1072
- }
1073
- unsigned Ret = this ->Size ;
1074
- this ->Size = this ->Size + S.size () + 1 ;
1075
- Strings.push_back (S);
1076
- return Ret;
1077
- }
1078
-
1079
- template <class ELFT > void StringTableSection<ELFT>::writeTo(uint8_t *Buf) {
1080
- // ELF string tables start with NUL byte, so advance the pointer by one.
1081
- ++Buf;
1082
- for (StringRef S : Strings) {
1083
- memcpy (Buf, S.data (), S.size ());
1084
- Buf += S.size () + 1 ;
1085
- }
1086
- }
1087
-
1088
1063
template <class ELFT >
1089
1064
typename ELFT::uint DynamicReloc<ELFT>::getOffset() const {
1090
1065
if (OutputSec)
@@ -1148,7 +1123,7 @@ template <class ELFT> void SymbolTableSection<ELFT>::finalize() {
1148
1123
return ; // Already finalized.
1149
1124
1150
1125
this ->Size = getNumSymbols () * sizeof (Elf_Sym);
1151
- this ->Link = StrTabSec.SectionIndex ;
1126
+ this ->Link = StrTabSec.OutSec -> SectionIndex ;
1152
1127
this ->Info = NumLocals + 1 ;
1153
1128
1154
1129
if (Config->Relocatable ) {
@@ -1300,12 +1275,12 @@ static StringRef getFileDefName() {
1300
1275
}
1301
1276
1302
1277
template <class ELFT > void VersionDefinitionSection<ELFT>::finalize() {
1303
- FileDefNameOff = Out <ELFT>::DynStrTab->addString (getFileDefName ());
1278
+ FileDefNameOff = In <ELFT>::DynStrTab->addString (getFileDefName ());
1304
1279
for (VersionDefinition &V : Config->VersionDefinitions )
1305
- V.NameOff = Out <ELFT>::DynStrTab->addString (V.Name );
1280
+ V.NameOff = In <ELFT>::DynStrTab->addString (V.Name );
1306
1281
1307
1282
this ->Size = (sizeof (Elf_Verdef) + sizeof (Elf_Verdaux)) * getVerDefNum ();
1308
- this ->Link = Out <ELFT>::DynStrTab->SectionIndex ;
1283
+ this ->Link = In <ELFT>::DynStrTab-> OutSec ->SectionIndex ;
1309
1284
1310
1285
// sh_info should be set to the number of definitions. This fact is missed in
1311
1286
// documentation, but confirmed by binutils community:
@@ -1389,13 +1364,13 @@ void VersionNeedSection<ELFT>::addSymbol(SharedSymbol<ELFT> *SS) {
1389
1364
// to create one by adding it to our needed list and creating a dynstr entry
1390
1365
// for the soname.
1391
1366
if (F->VerdefMap .empty ())
1392
- Needed.push_back ({F, Out <ELFT>::DynStrTab->addString (F->getSoName ())});
1367
+ Needed.push_back ({F, In <ELFT>::DynStrTab->addString (F->getSoName ())});
1393
1368
typename SharedFile<ELFT>::NeededVer &NV = F->VerdefMap [SS->Verdef ];
1394
1369
// If we don't already know that we need an Elf_Vernaux for this Elf_Verdef,
1395
1370
// prepare to create one by allocating a version identifier and creating a
1396
1371
// dynstr entry for the version name.
1397
1372
if (NV.Index == 0 ) {
1398
- NV.StrTab = Out <ELFT>::DynStrTab->addString (
1373
+ NV.StrTab = In <ELFT>::DynStrTab->addString (
1399
1374
SS->file ()->getStringTable ().data () + SS->Verdef ->getAux ()->vda_name );
1400
1375
NV.Index = NextIndex++;
1401
1376
}
@@ -1438,7 +1413,7 @@ template <class ELFT> void VersionNeedSection<ELFT>::writeTo(uint8_t *Buf) {
1438
1413
}
1439
1414
1440
1415
template <class ELFT > void VersionNeedSection<ELFT>::finalize() {
1441
- this ->Link = Out <ELFT>::DynStrTab->SectionIndex ;
1416
+ this ->Link = In <ELFT>::DynStrTab-> OutSec ->SectionIndex ;
1442
1417
this ->Info = Needed.size ();
1443
1418
unsigned Size = Needed.size () * sizeof (Elf_Verneed);
1444
1419
for (std::pair<SharedFile<ELFT> *, size_t > &P : Needed)
@@ -1590,11 +1565,6 @@ template class MergeOutputSection<ELF32BE>;
1590
1565
template class MergeOutputSection <ELF64LE>;
1591
1566
template class MergeOutputSection <ELF64BE>;
1592
1567
1593
- template class StringTableSection <ELF32LE>;
1594
- template class StringTableSection <ELF32BE>;
1595
- template class StringTableSection <ELF64LE>;
1596
- template class StringTableSection <ELF64BE>;
1597
-
1598
1568
template class SymbolTableSection <ELF32LE>;
1599
1569
template class SymbolTableSection <ELF32BE>;
1600
1570
template class SymbolTableSection <ELF64LE>;
0 commit comments