================
@@ -3572,45 +3572,62 @@ static inline void printFields(formatted_raw_ostream
&OS, StringRef Str1,
OS.flush();
}
+template <class ELFT>
+static std::string getProgramHeadersNumString(const ELFFile<ELFT> &Obj,
+ StringRef FileName) {
+
+ if (Obj.getHeader().e_phnum != ELF::PN_XNUM)
+ return to_string(Obj.getHeader().e_phnum);
+
+ Expected<uint32_t> PhNumOrErr = Obj.getPhNum();
+ if (!PhNumOrErr) {
+ // In this case we can ignore an error, because we have already reported a
+ // warning about the broken section header table earlier.
+ consumeError(PhNumOrErr.takeError());
+ return "<?>";
+ }
+
+ if (*PhNumOrErr == ELF::PN_XNUM)
+ return "65535 (corrupt)";
+ return "65535 (" + to_string(*PhNumOrErr) + ")";
+}
+
template <class ELFT>
static std::string getSectionHeadersNumString(const ELFFile<ELFT> &Obj,
StringRef FileName) {
- const typename ELFT::Ehdr &ElfHeader = Obj.getHeader();
- if (ElfHeader.e_shnum != 0)
- return to_string(ElfHeader.e_shnum);
+ if (Obj.getHeader().e_shnum != 0)
+ return to_string(Obj.getHeader().e_shnum);
- Expected<ArrayRef<typename ELFT::Shdr>> ArrOrErr = Obj.sections();
- if (!ArrOrErr) {
+ Expected<uint64_t> ShNumOrErr = Obj.getShNum();
+ if (!ShNumOrErr) {
// In this case we can ignore an error, because we have already reported a
// warning about the broken section header table earlier.
- consumeError(ArrOrErr.takeError());
+ consumeError(ShNumOrErr.takeError());
return "<?>";
}
- if (ArrOrErr->empty())
+ if (*ShNumOrErr == 0)
return "0";
- return "0 (" + to_string((*ArrOrErr)[0].sh_size) + ")";
+ return "0 (" + to_string(*ShNumOrErr) + ")";
}
template <class ELFT>
static std::string getSectionHeaderTableIndexString(const ELFFile<ELFT> &Obj,
StringRef FileName) {
- const typename ELFT::Ehdr &ElfHeader = Obj.getHeader();
- if (ElfHeader.e_shstrndx != SHN_XINDEX)
- return to_string(ElfHeader.e_shstrndx);
+ if (Obj.getHeader().e_shstrndx != ELF::SHN_XINDEX)
+ return to_string(Obj.getHeader().e_shstrndx);
- Expected<ArrayRef<typename ELFT::Shdr>> ArrOrErr = Obj.sections();
- if (!ArrOrErr) {
+ Expected<uint32_t> ShStrNdxOrErr = Obj.getShStrNdx();
+ if (!ShStrNdxOrErr) {
// In this case we can ignore an error, because we have already reported a
// warning about the broken section header table earlier.
- consumeError(ArrOrErr.takeError());
+ consumeError(ShStrNdxOrErr.takeError());
----------------
jh7370 wrote:
Same as above.
https://github.com/llvm/llvm-project/pull/165278
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits