@@ -37,7 +37,7 @@ class ELFDumper {
37
37
38
38
BumpPtrAllocator StringAllocator;
39
39
40
- Expected<StringRef> getUniquedSectionName (const Elf_Shdr * Sec);
40
+ Expected<StringRef> getUniquedSectionName (const Elf_Shdr & Sec);
41
41
Expected<StringRef> getUniquedSymbolName (const Elf_Sym *Sym,
42
42
StringRef StrTable,
43
43
const Elf_Shdr *SymTab);
@@ -115,13 +115,12 @@ ELFDumper<ELFT>::ELFDumper(const object::ELFFile<ELFT> &O,
115
115
116
116
template <class ELFT >
117
117
Expected<StringRef>
118
- ELFDumper<ELFT>::getUniquedSectionName(const Elf_Shdr *Sec) {
119
- unsigned SecIndex = Sec - &Sections[0 ];
120
- assert (&Sections[SecIndex] == Sec);
118
+ ELFDumper<ELFT>::getUniquedSectionName(const Elf_Shdr &Sec) {
119
+ unsigned SecIndex = &Sec - &Sections[0 ];
121
120
if (!SectionNames[SecIndex].empty ())
122
121
return SectionNames[SecIndex];
123
122
124
- auto NameOrErr = Obj.getSectionName (* Sec);
123
+ auto NameOrErr = Obj.getSectionName (Sec);
125
124
if (!NameOrErr)
126
125
return NameOrErr;
127
126
StringRef Name = *NameOrErr;
@@ -150,10 +149,12 @@ ELFDumper<ELFT>::getUniquedSymbolName(const Elf_Sym *Sym, StringRef StrTable,
150
149
return SymbolNameOrErr;
151
150
StringRef Name = *SymbolNameOrErr;
152
151
if (Name.empty () && Sym->getType () == ELF::STT_SECTION) {
153
- auto ShdrOrErr = Obj.getSection (*Sym, SymTab, ShndxTables.lookup (SymTab));
152
+ Expected<const Elf_Shdr *> ShdrOrErr =
153
+ Obj.getSection (*Sym, SymTab, ShndxTables.lookup (SymTab));
154
154
if (!ShdrOrErr)
155
155
return ShdrOrErr.takeError ();
156
- return getUniquedSectionName (*ShdrOrErr);
156
+ // The null section has no name.
157
+ return (*ShdrOrErr == nullptr ) ? " " : getUniquedSectionName (**ShdrOrErr);
157
158
}
158
159
159
160
// Symbols in .symtab can have duplicate names. For example, it is a common
@@ -678,7 +679,7 @@ Error ELFDumper<ELFT>::dumpSymbol(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
678
679
if (!Shdr)
679
680
return Error::success ();
680
681
681
- auto NameOrErr = getUniquedSectionName (Shdr);
682
+ auto NameOrErr = getUniquedSectionName (* Shdr);
682
683
if (!NameOrErr)
683
684
return NameOrErr.takeError ();
684
685
S.Section = NameOrErr.get ();
@@ -755,7 +756,7 @@ Error ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr,
755
756
756
757
S.OriginalSecNdx = Shdr - &Sections[0 ];
757
758
758
- auto NameOrErr = getUniquedSectionName (Shdr);
759
+ Expected<StringRef> NameOrErr = getUniquedSectionName (* Shdr);
759
760
if (!NameOrErr)
760
761
return NameOrErr.takeError ();
761
762
S.Name = NameOrErr.get ();
@@ -764,14 +765,14 @@ Error ELFDumper<ELFT>::dumpCommonSection(const Elf_Shdr *Shdr,
764
765
S.EntSize = static_cast <llvm::yaml::Hex64>(Shdr->sh_entsize );
765
766
766
767
if (Shdr->sh_link != ELF::SHN_UNDEF) {
767
- auto LinkSection = Obj.getSection (Shdr->sh_link );
768
+ Expected< const Elf_Shdr *> LinkSection = Obj.getSection (Shdr->sh_link );
768
769
if (!LinkSection)
769
770
return make_error<StringError>(
770
771
" unable to resolve sh_link reference in section '" + S.Name +
771
772
" ': " + toString (LinkSection.takeError ()),
772
773
inconvertibleErrorCode ());
773
774
774
- NameOrErr = getUniquedSectionName (*LinkSection);
775
+ NameOrErr = getUniquedSectionName (** LinkSection);
775
776
if (!NameOrErr)
776
777
return NameOrErr.takeError ();
777
778
S.Link = NameOrErr.get ();
@@ -795,7 +796,7 @@ Error ELFDumper<ELFT>::dumpCommonRelocationSection(
795
796
if (!InfoSection)
796
797
return InfoSection.takeError ();
797
798
798
- auto NameOrErr = getUniquedSectionName (*InfoSection);
799
+ Expected<StringRef> NameOrErr = getUniquedSectionName (* *InfoSection);
799
800
if (!NameOrErr)
800
801
return NameOrErr.takeError ();
801
802
S.RelocatableSec = NameOrErr.get ();
@@ -1462,10 +1463,10 @@ ELFDumper<ELFT>::dumpGroupSection(const Elf_Shdr *Shdr) {
1462
1463
continue ;
1463
1464
}
1464
1465
1465
- auto SHdrOrErr = Obj.getSection (Member);
1466
+ Expected< const Elf_Shdr *> SHdrOrErr = Obj.getSection (Member);
1466
1467
if (!SHdrOrErr)
1467
1468
return SHdrOrErr.takeError ();
1468
- auto NameOrErr = getUniquedSectionName (*SHdrOrErr);
1469
+ Expected<StringRef> NameOrErr = getUniquedSectionName (* *SHdrOrErr);
1469
1470
if (!NameOrErr)
1470
1471
return NameOrErr.takeError ();
1471
1472
S->Members ->push_back ({*NameOrErr});
0 commit comments