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)) {
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
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);
}
// 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;
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);
"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;
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;
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;
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;
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;
## 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
Sections:
- Name: .dynsym
Type: SHT_DYNSYM
- [[LINK]]
+ Link: [[LINK=<none>]]
- Name: .dynstr
Type: SHT_STRTAB
- Name: .foo
## 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
## 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
## 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