[llvm] [llvm-readobj, ELF] Support reading binary with more than PN_XNUM segments. (PR #165278)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 17 00:48:05 PST 2026
================
@@ -935,9 +935,13 @@ template <class ELFT> ELFFile<ELFT>::ELFFile(StringRef Object) : Buf(Object) {}
template <class ELFT> Error ELFFile<ELFT>::readShdrZero() {
const Elf_Ehdr &Header = getHeader();
- if ((Header.e_phnum == ELF::PN_XNUM || Header.e_shnum == 0 ||
- Header.e_shstrndx == ELF::SHN_XINDEX) &&
- Header.e_shoff != 0) {
+ // If e_shnum == 0 && e_shoff == 0, that means we actually have no section and
+ // thus is a valid ELF. But if the condition is still true when e_phnum ==
+ // PN_XNUM || e_shtstrndx == SHN_XINDEX and e_shoff == 0 The error will
+ // trigger when getSection() and e_shoff == 0
----------------
jh7370 wrote:
Hmm, it looks to me like you've changed the intent of this check, which is a bit outside the scope of this PR. Previously, if `e_shoff` was 0, we didn't emit an error for any of `e_phnum == ELF::PN_XNUM`, `e_shnum == 0`, or `e_shstrndx == ELF_SHN_XINDEX`. I accept that there's probably a case for emitting a warning in the e_phnum and e_shstrndx cases, but making that change of behaviour is independent of supporting reading more than PN_XNUM segments, which is what this PR is ostensibly about, so it should be in its own PR.
https://github.com/llvm/llvm-project/pull/165278
More information about the llvm-commits
mailing list