[llvm] [Object,ELF] Implement PN_XNUM extension for program headers (PR #162288)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 21 02:24:50 PDT 2025
================
@@ -891,6 +925,49 @@ 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
+ RealShNum = 0;
+ auto SecsOrErr = sections();
+ if (!SecsOrErr) {
+ RealShNum = std::nullopt;
+ return SecsOrErr.takeError();
+ }
+
+ // We can really have 0 number of seciton
+ if ((*SecsOrErr).size() == 0) {
+ if (Header.e_phnum == ELF::PN_XNUM ||
+ Header.e_shstrndx == ELF::SHN_XINDEX) {
+ return createError("Unable to find Section 0");
----------------
aokblast wrote:
Fix comments.
https://github.com/llvm/llvm-project/pull/162288
More information about the llvm-commits
mailing list