[llvm] [Object,ELF] Implement PN_XNUM extension for program headers (PR #162288)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 17 22:48:54 PDT 2025
================
@@ -889,7 +887,31 @@ Expected<uint64_t> ELFFile<ELFT>::getDynSymtabSize() const {
return 0;
}
-template <class ELFT> ELFFile<ELFT>::ELFFile(StringRef Object) : Buf(Object) {}
+template <class ELFT> ELFFile<ELFT>::ELFFile(StringRef Object) : Buf(Object) {
+ const Elf_Ehdr &Header = getHeader();
+ RealPhNum = Header.e_phnum;
+ RealShNum = Header.e_shnum;
+ RealShStrNdx = Header.e_shstrndx;
+ if (!Header.hasPhdrNumExtension())
+ return;
+
+ // An ELF binary may report `hasExtendedHeader` as true but not actually
----------------
MaskRay wrote:
Even if we don't want to introduce a test with 0xffff program headers, we can create a test, adapted from `test/llvm-objcopy/ELF/invalid-e_phoff.test`, that shows the llvm-readelf behavior when e_phnum is 0xffff, but the section header table doesn't contain that many of sections. The diagnostic is probably different.
https://github.com/llvm/llvm-project/pull/162288
More information about the llvm-commits
mailing list