[llvm] [Object,ELF] Implement PN_XNUM extension for program headers (PR #162288)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 27 02:10:02 PDT 2025
================
@@ -891,6 +927,38 @@ Expected<uint64_t> ELFFile<ELFT>::getDynSymtabSize() const {
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) {
+ // Pretend we have section 0 or sections() would call getShNum and thus
+ // become an infinite recursion.
+ if (Header.e_shnum == 0)
+ RealShNum = 1;
+ else
+ RealShNum = Header.e_shnum;
----------------
jh7370 wrote:
This can be simplified to simply assigning 1 to `RealShNum` unconditionally. The code that assigns `RealShNum` below will fix it to the right value afterwards, regardless of whether `Header.e_shnum == 0` or otherwise.
https://github.com/llvm/llvm-project/pull/162288
More information about the llvm-commits
mailing list