mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 12:12:47 +01:00
[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
This commit is contained in:
parent
63a46a6070
commit
76c7f0ba36
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
|
@ -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]]
|
||||
|
@ -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]]
|
||||
|
@ -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]]
|
||||
|
@ -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]]
|
||||
|
@ -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
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user