[llvm] [Object,ELF] Implement PN_XNUM extension for program headers (PR #162288)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 27 02:22:31 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;
----------------
aokblast wrote:
This change is to reflect the following comment. I think I misunderstand something.
We need to read section 0 not only in e_shnum == 0 but also when e_phnum == PN_XNUM.
> This code should be guarded by an e_shnum == 0 check. If e_shnum != 0, we don't need to do funky things to read the index 0 header, like pre-filling RealShNum with a fake value, and can instead just set RealShNum to the right value up-front prior to calling sections().
https://github.com/llvm/llvm-project/pull/162288
More information about the llvm-commits
mailing list