- Name: bar
Size: 0x1
Value: 0x1
+
+## Check how we dump unnamed section symbols.
+## Check we are able to handle the section symbol for the null section.
+## Document we name them with a section name they describe.
+
+# RUN: yaml2obj --docnum=2 %s -o %t2
+# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=SECTION-SYM
+
+# SECTION-SYM: --- !ELF
+# SECTION-SYM-NEXT: FileHeader:
+# SECTION-SYM-NEXT: Class: ELFCLASS64
+# SECTION-SYM-NEXT: Data: ELFDATA2LSB
+# SECTION-SYM-NEXT: Type: ET_REL
+# SECTION-SYM-NEXT: Sections:
+# SECTION-SYM-NEXT: - Name: .section
+# SECTION-SYM-NEXT: Type: SHT_PROGBITS
+# SECTION-SYM-NEXT: Symbols:
+# SECTION-SYM-NEXT: - Type: STT_SECTION
+# SECTION-SYM-NEXT: - Name: .section
+# SECTION-SYM-NEXT: Type: STT_SECTION
+# SECTION-SYM-NEXT: Section: .section
+# SECTION-SYM-NEXT: - Name: .section
+# SECTION-SYM-NEXT: Type: STT_SECTION
+# SECTION-SYM-NEXT: Section: .section
+# SECTION-SYM-NEXT: ...
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+Sections:
+ - Name: .section
+ Type: SHT_PROGBITS
+Symbols:
+ - Type: STT_SECTION
+ Index: 0
+ - Type: STT_SECTION
+ Index: 1
+ - Type: STT_SECTION
+ Index: 1
BumpPtrAllocator StringAllocator;
- Expected<StringRef> getUniquedSectionName(const Elf_Shdr *Sec);
+ Expected<StringRef> getUniquedSectionName(const Elf_Shdr &Sec);
Expected<StringRef> getUniquedSymbolName(const Elf_Sym *Sym,
StringRef StrTable,
const Elf_Shdr *SymTab);
template <class ELFT>
Expected<StringRef>
-ELFDumper<ELFT>::getUniquedSectionName(const Elf_Shdr *Sec) {
- unsigned SecIndex = Sec - &Sections[0];
- assert(&Sections[SecIndex] == Sec);
+ELFDumper<ELFT>::getUniquedSectionName(const Elf_Shdr &Sec) {
+ unsigned SecIndex = &Sec - &Sections[0];
if (!SectionNames[SecIndex].empty())
return SectionNames[SecIndex];
- auto NameOrErr = Obj.getSectionName(*Sec);
+ auto NameOrErr = Obj.getSectionName(Sec);
if (!NameOrErr)
return NameOrErr;
StringRef Name = *NameOrErr;
return SymbolNameOrErr;
StringRef Name = *SymbolNameOrErr;
if (Name.empty() && Sym->getType() == ELF::STT_SECTION) {
- auto ShdrOrErr = Obj.getSection(*Sym, SymTab, ShndxTables.lookup(SymTab));
+ Expected<const Elf_Shdr *> ShdrOrErr =
+ Obj.getSection(*Sym, SymTab, ShndxTables.lookup(SymTab));
if (!ShdrOrErr)
return ShdrOrErr.takeError();
- return getUniquedSectionName(*ShdrOrErr);
+ // The null section has no name.
+ return (*ShdrOrErr == nullptr) ? "" : getUniquedSectionName(**ShdrOrErr);
}
// Symbols in .symtab can have duplicate names. For example, it is a common
if (!Shdr)
return Error::success();
- auto NameOrErr = getUniquedSectionName(Shdr);
+ auto NameOrErr = getUniquedSectionName(*Shdr);
if (!NameOrErr)
return NameOrErr.takeError();
S.Section = NameOrErr.get();
S.OriginalSecNdx = Shdr - &Sections[0];
- auto NameOrErr = getUniquedSectionName(Shdr);
+ Expected<StringRef> NameOrErr = getUniquedSectionName(*Shdr);
if (!NameOrErr)
return NameOrErr.takeError();
S.Name = NameOrErr.get();
S.EntSize = static_cast<llvm::yaml::Hex64>(Shdr->sh_entsize);
if (Shdr->sh_link != ELF::SHN_UNDEF) {
- auto LinkSection = Obj.getSection(Shdr->sh_link);
+ Expected<const Elf_Shdr *> LinkSection = Obj.getSection(Shdr->sh_link);
if (!LinkSection)
return make_error<StringError>(
"unable to resolve sh_link reference in section '" + S.Name +
"': " + toString(LinkSection.takeError()),
inconvertibleErrorCode());
- NameOrErr = getUniquedSectionName(*LinkSection);
+ NameOrErr = getUniquedSectionName(**LinkSection);
if (!NameOrErr)
return NameOrErr.takeError();
S.Link = NameOrErr.get();
if (!InfoSection)
return InfoSection.takeError();
- auto NameOrErr = getUniquedSectionName(*InfoSection);
+ Expected<StringRef> NameOrErr = getUniquedSectionName(**InfoSection);
if (!NameOrErr)
return NameOrErr.takeError();
S.RelocatableSec = NameOrErr.get();
continue;
}
- auto SHdrOrErr = Obj.getSection(Member);
+ Expected<const Elf_Shdr *> SHdrOrErr = Obj.getSection(Member);
if (!SHdrOrErr)
return SHdrOrErr.takeError();
- auto NameOrErr = getUniquedSectionName(*SHdrOrErr);
+ Expected<StringRef> NameOrErr = getUniquedSectionName(**SHdrOrErr);
if (!NameOrErr)
return NameOrErr.takeError();
S->Members->push_back({*NameOrErr});