@@ -694,8 +694,8 @@ void ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
694694
695695 assignSectionAddress (SHeader, Sec);
696696
697- if (! Sec->Link . empty () )
698- SHeader.sh_link = toSectionIndex (Sec->Link , Sec->Name );
697+ if (Sec->Link )
698+ SHeader.sh_link = toSectionIndex (* Sec->Link , Sec->Name );
699699
700700 if (IsFirstUndefSection) {
701701 if (auto RawSec = dyn_cast<ELFYAML::RawContentSection>(Sec)) {
@@ -866,10 +866,10 @@ void ELFState<ELFT>::initSymtabSectionHeader(Elf_Shdr &SHeader,
866866 else
867867 SHeader.sh_type = IsStatic ? ELF::SHT_SYMTAB : ELF::SHT_DYNSYM;
868868
869- if (RawSec && ! RawSec->Link . empty () ) {
869+ if (RawSec && RawSec->Link ) {
870870 // If the Link field is explicitly defined in the document,
871871 // we should use it.
872- SHeader.sh_link = toSectionIndex (RawSec->Link , RawSec->Name );
872+ SHeader.sh_link = toSectionIndex (* RawSec->Link , RawSec->Name );
873873 } else {
874874 // When we describe the .dynsym section in the document explicitly, it is
875875 // allowed to omit the "DynamicSymbols" tag. In this case .dynstr is not
@@ -1023,8 +1023,8 @@ void ELFState<ELFT>::initDWARFSectionHeader(Elf_Shdr &SHeader, StringRef Name,
10231023 else if (Name == " .debug_str" )
10241024 SHeader.sh_flags = ELF::SHF_MERGE | ELF::SHF_STRINGS;
10251025
1026- if (YAMLSec && ! YAMLSec->Link . empty () )
1027- SHeader.sh_link = toSectionIndex (YAMLSec->Link , Name);
1026+ if (YAMLSec && YAMLSec->Link )
1027+ SHeader.sh_link = toSectionIndex (* YAMLSec->Link , Name);
10281028
10291029 assignSectionAddress (SHeader, YAMLSec);
10301030}
@@ -1180,7 +1180,7 @@ void ELFState<ELFT>::writeSectionContent(
11801180
11811181 // For relocation section set link to .symtab by default.
11821182 unsigned Link = 0 ;
1183- if (Section.Link . empty () && !ExcludedSectionHeaders.count (" .symtab" ) &&
1183+ if (! Section.Link && !ExcludedSectionHeaders.count (" .symtab" ) &&
11841184 SN2I.lookup (" .symtab" , Link))
11851185 SHeader.sh_link = Link;
11861186
@@ -1191,9 +1191,9 @@ void ELFState<ELFT>::writeSectionContent(
11911191 return ;
11921192
11931193 for (const ELFYAML::Relocation &Rel : *Section.Relocations ) {
1194- unsigned SymIdx = Rel. Symbol ? toSymbolIndex (*Rel. Symbol , Section. Name ,
1195- Section. Link == " .dynsym " )
1196- : 0 ;
1194+ const bool IsDynamic = Section. Link && (*Section. Link == " .dynsym " );
1195+ unsigned SymIdx =
1196+ Rel. Symbol ? toSymbolIndex (*Rel. Symbol , Section. Name , IsDynamic) : 0 ;
11971197 if (IsRela) {
11981198 Elf_Rela REntry;
11991199 zero (REntry);
@@ -1261,7 +1261,7 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
12611261 " Section type is not SHT_GROUP" );
12621262
12631263 unsigned Link = 0 ;
1264- if (Section.Link . empty () && !ExcludedSectionHeaders.count (" .symtab" ) &&
1264+ if (! Section.Link && !ExcludedSectionHeaders.count (" .symtab" ) &&
12651265 SN2I.lookup (" .symtab" , Link))
12661266 SHeader.sh_link = Link;
12671267
@@ -1379,7 +1379,7 @@ void ELFState<ELFT>::writeSectionContent(
13791379 SHeader.sh_entsize = 16 ;
13801380
13811381 unsigned Link = 0 ;
1382- if (Section.Link . empty () && !ExcludedSectionHeaders.count (" .symtab" ) &&
1382+ if (! Section.Link && !ExcludedSectionHeaders.count (" .symtab" ) &&
13831383 SN2I.lookup (" .symtab" , Link))
13841384 SHeader.sh_link = Link;
13851385
@@ -1402,7 +1402,7 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
14021402 const ELFYAML::HashSection &Section,
14031403 ContiguousBlobAccumulator &CBA) {
14041404 unsigned Link = 0 ;
1405- if (Section.Link . empty () && !ExcludedSectionHeaders.count (" .dynsym" ) &&
1405+ if (! Section.Link && !ExcludedSectionHeaders.count (" .dynsym" ) &&
14061406 SN2I.lookup (" .dynsym" , Link))
14071407 SHeader.sh_link = Link;
14081408
@@ -1592,7 +1592,7 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
15921592 const ELFYAML::AddrsigSection &Section,
15931593 ContiguousBlobAccumulator &CBA) {
15941594 unsigned Link = 0 ;
1595- if (Section.Link . empty () && !ExcludedSectionHeaders.count (" .symtab" ) &&
1595+ if (! Section.Link && !ExcludedSectionHeaders.count (" .symtab" ) &&
15961596 SN2I.lookup (" .symtab" , Link))
15971597 SHeader.sh_link = Link;
15981598
@@ -1653,7 +1653,7 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
16531653 const ELFYAML::GnuHashSection &Section,
16541654 ContiguousBlobAccumulator &CBA) {
16551655 unsigned Link = 0 ;
1656- if (Section.Link . empty () && !ExcludedSectionHeaders.count (" .dynsym" ) &&
1656+ if (! Section.Link && !ExcludedSectionHeaders.count (" .dynsym" ) &&
16571657 SN2I.lookup (" .dynsym" , Link))
16581658 SHeader.sh_link = Link;
16591659
0 commit comments