[llvm] 2bfaf19 - [yaml2obj] - Make `Section::Link` field to be `Optional<>`.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 30 06:25:38 PDT 2020
Author: Georgii Rymar
Date: 2020-10-30T16:18:53+03:00
New Revision: 2bfaf19516d6eb7fb94b736b091149952bae00f3
URL: https://github.com/llvm/llvm-project/commit/2bfaf19516d6eb7fb94b736b091149952bae00f3
DIFF: https://github.com/llvm/llvm-project/commit/2bfaf19516d6eb7fb94b736b091149952bae00f3.diff
LOG: [yaml2obj] - Make `Section::Link` field to be `Optional<>`.
`Link` is not an optional field currently.
Because of this it is not convenient to write macros.
This makes it optional and fixes corresponding test cases.
Differential revision: https://reviews.llvm.org/D90390
Added:
Modified:
llvm/include/llvm/ObjectYAML/ELFYAML.h
llvm/lib/ObjectYAML/ELFEmitter.cpp
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/test/tools/llvm-readobj/ELF/relr-relocs.test
llvm/test/tools/obj2yaml/ELF/DWARF/debug-addr.yaml
llvm/test/tools/obj2yaml/ELF/DWARF/debug-aranges.yaml
llvm/test/tools/obj2yaml/ELF/DWARF/debug-ranges.yaml
llvm/test/tools/obj2yaml/ELF/DWARF/debug-str.yaml
llvm/test/tools/yaml2obj/ELF/dynsym-section.yaml
llvm/tools/obj2yaml/elf2yaml.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ObjectYAML/ELFYAML.h b/llvm/include/llvm/ObjectYAML/ELFYAML.h
index f3805a91853b..f7b02f585154 100644
--- a/llvm/include/llvm/ObjectYAML/ELFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/ELFYAML.h
@@ -174,7 +174,7 @@ struct Section : public Chunk {
ELF_SHT Type;
Optional<ELF_SHF> Flags;
Optional<llvm::yaml::Hex64> Address;
- StringRef Link;
+ Optional<StringRef> Link;
llvm::yaml::Hex64 AddressAlign;
Optional<llvm::yaml::Hex64> EntSize;
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index a1acd2a69da8..124af979de8f 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -694,8 +694,8 @@ void ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
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<ELFYAML::RawContentSection>(Sec)) {
@@ -866,10 +866,10 @@ void ELFState<ELFT>::initSymtabSectionHeader(Elf_Shdr &SHeader,
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 @@ void ELFState<ELFT>::initDWARFSectionHeader(Elf_Shdr &SHeader, StringRef Name,
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 @@ void ELFState<ELFT>::writeSectionContent(
// 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 @@ void ELFState<ELFT>::writeSectionContent(
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 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
"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 @@ void ELFState<ELFT>::writeSectionContent(
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 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
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 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
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 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
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;
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index cd4fd338d6ec..f9ee4ce02a13 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -1101,7 +1101,7 @@ static void commonSectionMapping(IO &IO, ELFYAML::Section &Section) {
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);
diff --git a/llvm/test/tools/llvm-readobj/ELF/relr-relocs.test b/llvm/test/tools/llvm-readobj/ELF/relr-relocs.test
index 22a56c193684..7de0f1b01de3 100644
--- a/llvm/test/tools/llvm-readobj/ELF/relr-relocs.test
+++ b/llvm/test/tools/llvm-readobj/ELF/relr-relocs.test
@@ -151,7 +151,7 @@ Sections:
0x000F0501, 0x50400009 ]
EntSize: [[ENTSIZE=<none>]]
ShType: [[SHTYPE=<none>]]
- Link: [[LINK=""]]
+ Link: [[LINK=<none>]]
## Check we report a warning when we are unable to dump relocations
## for a SHT_RELR/SHT_ANDROID_RELR section.
diff --git a/llvm/test/tools/obj2yaml/ELF/DWARF/debug-addr.yaml b/llvm/test/tools/obj2yaml/ELF/DWARF/debug-addr.yaml
index b294adff5cbd..2bdb1bf74006 100644
--- a/llvm/test/tools/obj2yaml/ELF/DWARF/debug-addr.yaml
+++ b/llvm/test/tools/obj2yaml/ELF/DWARF/debug-addr.yaml
@@ -165,7 +165,7 @@ Sections:
- Name: .debug_addr
Type: [[TYPE=SHT_PROGBITS]]
Flags: [[FLAGS=<none>]]
- Link: [[LINK='']]
+ Link: [[LINK=<none>]]
EntSize: [[ENTSIZE=<none>]]
Info: [[INFO=<none>]]
AddressAlign: [[ADDRALIGN=0]]
diff --git a/llvm/test/tools/obj2yaml/ELF/DWARF/debug-aranges.yaml b/llvm/test/tools/obj2yaml/ELF/DWARF/debug-aranges.yaml
index cc3c2393fe2d..5f296bb4e5ee 100644
--- a/llvm/test/tools/obj2yaml/ELF/DWARF/debug-aranges.yaml
+++ b/llvm/test/tools/obj2yaml/ELF/DWARF/debug-aranges.yaml
@@ -105,7 +105,7 @@ Sections:
- Name: .debug_aranges
Type: [[TYPE=SHT_PROGBITS]]
Flags: [[FLAGS=<none>]]
- Link: [[LINK='']]
+ Link: [[LINK=<none>]]
EntSize: [[ENTSIZE=<none>]]
Info: [[INFO=<none>]]
AddressAlign: [[ADDRALIGN=0]]
diff --git a/llvm/test/tools/obj2yaml/ELF/DWARF/debug-ranges.yaml b/llvm/test/tools/obj2yaml/ELF/DWARF/debug-ranges.yaml
index 0e3fbae13071..c4a4c4111154 100644
--- a/llvm/test/tools/obj2yaml/ELF/DWARF/debug-ranges.yaml
+++ b/llvm/test/tools/obj2yaml/ELF/DWARF/debug-ranges.yaml
@@ -216,7 +216,7 @@ Sections:
- Name: .debug_ranges
Type: [[TYPE=SHT_PROGBITS]]
Flags: [[FLAGS=<none>]]
- Link: [[LINK='']]
+ Link: [[LINK=<none>]]
EntSize: [[ENTSIZE=<none>]]
Info: [[INFO=<none>]]
AddressAlign: [[ADDRALIGN=0]]
diff --git a/llvm/test/tools/obj2yaml/ELF/DWARF/debug-str.yaml b/llvm/test/tools/obj2yaml/ELF/DWARF/debug-str.yaml
index 76c1c5c1b365..dbe022effab8 100644
--- a/llvm/test/tools/obj2yaml/ELF/DWARF/debug-str.yaml
+++ b/llvm/test/tools/obj2yaml/ELF/DWARF/debug-str.yaml
@@ -56,7 +56,7 @@ Sections:
- Name: .debug_str
Type: SHT_[[TYPE=PROGBITS]]
Flags: [[FLAGS=<none>]]
- Link: [[LINK='']]
+ Link: [[LINK=<none>]]
EntSize: [[ENTSIZE=1]]
Info: [[INFO=<none>]]
AddressAlign: [[ADDRALIGN=1]]
diff --git a/llvm/test/tools/yaml2obj/ELF/dynsym-section.yaml b/llvm/test/tools/yaml2obj/ELF/dynsym-section.yaml
index 5c461132fc9d..294b91e9e321 100644
--- a/llvm/test/tools/yaml2obj/ELF/dynsym-section.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/dynsym-section.yaml
@@ -34,7 +34,7 @@ Sections:
## 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 @@ FileHeader:
Sections:
- Name: .dynsym
Type: SHT_DYNSYM
- [[LINK]]
+ Link: [[LINK=<none>]]
- Name: .dynstr
Type: SHT_STRTAB
- Name: .foo
@@ -57,7 +57,7 @@ Sections:
## 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 @@ Sections:
## 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 @@ Sections:
## 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
diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index fb62f4739b1a..edb2aa3f3ed7 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -203,9 +203,8 @@ bool ELFDumper<ELFT>::shouldPrintSection(const ELFYAML::Section &S,
if (DWARF && DWARF->getNonEmptySectionNames().count(SecName)) {
if (const ELFYAML::RawContentSection *RawSec =
dyn_cast<const ELFYAML::RawContentSection>(&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));
More information about the llvm-commits
mailing list