Index: llvm/include/llvm/ObjectYAML/ELFYAML.h =================================================================== --- llvm/include/llvm/ObjectYAML/ELFYAML.h +++ llvm/include/llvm/ObjectYAML/ELFYAML.h @@ -174,7 +174,7 @@ ELF_SHT Type; Optional Flags; Optional Address; - StringRef Link; + Optional Link; llvm::yaml::Hex64 AddressAlign; Optional EntSize; Index: llvm/lib/ObjectYAML/ELFEmitter.cpp =================================================================== --- llvm/lib/ObjectYAML/ELFEmitter.cpp +++ llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -694,8 +694,8 @@ assignSectionAddress(SHeader, Sec); - if (!Sec->Link.empty()) - SHeader.sh_link = toSectionIndex(Sec->Link, Sec->Name); + if (Sec->Link) + SHeader.sh_link = toSectionIndex(*Sec->Link, Sec->Name); if (IsFirstUndefSection) { if (auto RawSec = dyn_cast(Sec)) { @@ -866,10 +866,10 @@ else SHeader.sh_type = IsStatic ? ELF::SHT_SYMTAB : ELF::SHT_DYNSYM; - if (RawSec && !RawSec->Link.empty()) { + if (RawSec && RawSec->Link) { // If the Link field is explicitly defined in the document, // we should use it. - SHeader.sh_link = toSectionIndex(RawSec->Link, RawSec->Name); + SHeader.sh_link = toSectionIndex(*RawSec->Link, RawSec->Name); } else { // When we describe the .dynsym section in the document explicitly, it is // allowed to omit the "DynamicSymbols" tag. In this case .dynstr is not @@ -1023,8 +1023,8 @@ else if (Name == ".debug_str") SHeader.sh_flags = ELF::SHF_MERGE | ELF::SHF_STRINGS; - if (YAMLSec && !YAMLSec->Link.empty()) - SHeader.sh_link = toSectionIndex(YAMLSec->Link, Name); + if (YAMLSec && YAMLSec->Link) + SHeader.sh_link = toSectionIndex(*YAMLSec->Link, Name); assignSectionAddress(SHeader, YAMLSec); } @@ -1180,7 +1180,7 @@ // For relocation section set link to .symtab by default. unsigned Link = 0; - if (Section.Link.empty() && !ExcludedSectionHeaders.count(".symtab") && + if (!Section.Link && !ExcludedSectionHeaders.count(".symtab") && SN2I.lookup(".symtab", Link)) SHeader.sh_link = Link; @@ -1191,9 +1191,9 @@ return; for (const ELFYAML::Relocation &Rel : *Section.Relocations) { - unsigned SymIdx = Rel.Symbol ? toSymbolIndex(*Rel.Symbol, Section.Name, - Section.Link == ".dynsym") - : 0; + const bool IsDynamic = Section.Link && (*Section.Link == ".dynsym"); + unsigned SymIdx = + Rel.Symbol ? toSymbolIndex(*Rel.Symbol, Section.Name, IsDynamic) : 0; if (IsRela) { Elf_Rela REntry; zero(REntry); @@ -1261,7 +1261,7 @@ "Section type is not SHT_GROUP"); unsigned Link = 0; - if (Section.Link.empty() && !ExcludedSectionHeaders.count(".symtab") && + if (!Section.Link && !ExcludedSectionHeaders.count(".symtab") && SN2I.lookup(".symtab", Link)) SHeader.sh_link = Link; @@ -1379,7 +1379,7 @@ SHeader.sh_entsize = 16; unsigned Link = 0; - if (Section.Link.empty() && !ExcludedSectionHeaders.count(".symtab") && + if (!Section.Link && !ExcludedSectionHeaders.count(".symtab") && SN2I.lookup(".symtab", Link)) SHeader.sh_link = Link; @@ -1402,7 +1402,7 @@ const ELFYAML::HashSection &Section, ContiguousBlobAccumulator &CBA) { unsigned Link = 0; - if (Section.Link.empty() && !ExcludedSectionHeaders.count(".dynsym") && + if (!Section.Link && !ExcludedSectionHeaders.count(".dynsym") && SN2I.lookup(".dynsym", Link)) SHeader.sh_link = Link; @@ -1592,7 +1592,7 @@ const ELFYAML::AddrsigSection &Section, ContiguousBlobAccumulator &CBA) { unsigned Link = 0; - if (Section.Link.empty() && !ExcludedSectionHeaders.count(".symtab") && + if (!Section.Link && !ExcludedSectionHeaders.count(".symtab") && SN2I.lookup(".symtab", Link)) SHeader.sh_link = Link; @@ -1653,7 +1653,7 @@ const ELFYAML::GnuHashSection &Section, ContiguousBlobAccumulator &CBA) { unsigned Link = 0; - if (Section.Link.empty() && !ExcludedSectionHeaders.count(".dynsym") && + if (!Section.Link && !ExcludedSectionHeaders.count(".dynsym") && SN2I.lookup(".dynsym", Link)) SHeader.sh_link = Link; Index: llvm/lib/ObjectYAML/ELFYAML.cpp =================================================================== --- llvm/lib/ObjectYAML/ELFYAML.cpp +++ llvm/lib/ObjectYAML/ELFYAML.cpp @@ -1101,7 +1101,7 @@ IO.mapRequired("Type", Section.Type); IO.mapOptional("Flags", Section.Flags); IO.mapOptional("Address", Section.Address); - IO.mapOptional("Link", Section.Link, StringRef()); + IO.mapOptional("Link", Section.Link); IO.mapOptional("AddressAlign", Section.AddressAlign, Hex64(0)); IO.mapOptional("EntSize", Section.EntSize); IO.mapOptional("Offset", Section.Offset); Index: llvm/test/tools/llvm-readobj/ELF/relr-relocs.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/relr-relocs.test +++ llvm/test/tools/llvm-readobj/ELF/relr-relocs.test @@ -151,7 +151,7 @@ 0x000F0501, 0x50400009 ] EntSize: [[ENTSIZE=]] ShType: [[SHTYPE=]] - Link: [[LINK=""]] + Link: [[LINK=]] ## Check we report a warning when we are unable to dump relocations ## for a SHT_RELR/SHT_ANDROID_RELR section. Index: llvm/test/tools/obj2yaml/ELF/DWARF/debug-addr.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/DWARF/debug-addr.yaml +++ llvm/test/tools/obj2yaml/ELF/DWARF/debug-addr.yaml @@ -165,7 +165,7 @@ - Name: .debug_addr Type: [[TYPE=SHT_PROGBITS]] Flags: [[FLAGS=]] - Link: [[LINK='']] + Link: [[LINK=]] EntSize: [[ENTSIZE=]] Info: [[INFO=]] AddressAlign: [[ADDRALIGN=0]] Index: llvm/test/tools/obj2yaml/ELF/DWARF/debug-aranges.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/DWARF/debug-aranges.yaml +++ llvm/test/tools/obj2yaml/ELF/DWARF/debug-aranges.yaml @@ -105,7 +105,7 @@ - Name: .debug_aranges Type: [[TYPE=SHT_PROGBITS]] Flags: [[FLAGS=]] - Link: [[LINK='']] + Link: [[LINK=]] EntSize: [[ENTSIZE=]] Info: [[INFO=]] AddressAlign: [[ADDRALIGN=0]] Index: llvm/test/tools/obj2yaml/ELF/DWARF/debug-ranges.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/DWARF/debug-ranges.yaml +++ llvm/test/tools/obj2yaml/ELF/DWARF/debug-ranges.yaml @@ -216,7 +216,7 @@ - Name: .debug_ranges Type: [[TYPE=SHT_PROGBITS]] Flags: [[FLAGS=]] - Link: [[LINK='']] + Link: [[LINK=]] EntSize: [[ENTSIZE=]] Info: [[INFO=]] AddressAlign: [[ADDRALIGN=0]] Index: llvm/test/tools/obj2yaml/ELF/DWARF/debug-str.yaml =================================================================== --- llvm/test/tools/obj2yaml/ELF/DWARF/debug-str.yaml +++ llvm/test/tools/obj2yaml/ELF/DWARF/debug-str.yaml @@ -56,7 +56,7 @@ - Name: .debug_str Type: SHT_[[TYPE=PROGBITS]] Flags: [[FLAGS=]] - Link: [[LINK='']] + Link: [[LINK=]] EntSize: [[ENTSIZE=1]] Info: [[INFO=]] AddressAlign: [[ADDRALIGN=1]] Index: llvm/test/tools/yaml2obj/ELF/dynsym-section.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/dynsym-section.yaml +++ llvm/test/tools/yaml2obj/ELF/dynsym-section.yaml @@ -34,7 +34,7 @@ ## Check we are able to set Link = 0 for the .dynsym section explicitly. -# RUN: yaml2obj %s --docnum=2 -DLINK="Link: 0" -o %t2 +# RUN: yaml2obj %s --docnum=2 -DLINK=0 -o %t2 # RUN: llvm-readelf --section-headers %t2 | FileCheck %s --check-prefix=LINK-NULL # LINK-NULL: [Nr] Name {{.*}} Flg Lk Inf @@ -48,7 +48,7 @@ Sections: - Name: .dynsym Type: SHT_DYNSYM - [[LINK]] + Link: [[LINK=]] - Name: .dynstr Type: SHT_STRTAB - Name: .foo @@ -57,7 +57,7 @@ ## Check that by default the .dynsym section will be linked to the .dynstr section, ## when the latter one exists. -# RUN: yaml2obj %s --docnum=2 -DLINK="" -o %t3 +# RUN: yaml2obj %s --docnum=2 -o %t3 # RUN: llvm-readelf --section-headers %t3 | FileCheck %s --check-prefix=LINK-DEFAULT # LINK-DEFAULT: [Nr] Name {{.*}} Flg Lk Inf @@ -67,7 +67,7 @@ ## Even when the .dynstr section exists, we can explicitly link the .dynsym section ## to another section. -# RUN: yaml2obj %s --docnum=2 -DLINK="Link: 3" -o %t4 +# RUN: yaml2obj %s --docnum=2 -DLINK=3 -o %t4 # RUN: llvm-readelf --section-headers %t4 | FileCheck %s --check-prefix=LINK-FOO # LINK-FOO: [Nr] Name {{.*}} Flg Lk Inf @@ -76,5 +76,5 @@ ## Check we can use a section name as a Link value for .dynsym. -# RUN: yaml2obj %s --docnum=2 -DLINK="Link: .foo" -o %t5 +# RUN: yaml2obj %s --docnum=2 -DLINK=.foo -o %t5 # RUN: llvm-readelf --section-headers %t5 | FileCheck %s --check-prefix=LINK-FOO Index: llvm/tools/obj2yaml/elf2yaml.cpp =================================================================== --- llvm/tools/obj2yaml/elf2yaml.cpp +++ llvm/tools/obj2yaml/elf2yaml.cpp @@ -203,9 +203,8 @@ if (DWARF && DWARF->getNonEmptySectionNames().count(SecName)) { if (const ELFYAML::RawContentSection *RawSec = dyn_cast(&S)) { - if (RawSec->Type != ELF::SHT_PROGBITS || !RawSec->Link.empty() || - RawSec->Info || RawSec->AddressAlign != 1 || RawSec->Address || - RawSec->EntSize) + if (RawSec->Type != ELF::SHT_PROGBITS || RawSec->Link || RawSec->Info || + RawSec->AddressAlign != 1 || RawSec->Address || RawSec->EntSize) return true; ELFYAML::ELF_SHF ShFlags = RawSec->Flags.getValueOr(ELFYAML::ELF_SHF(0));