[llvm-branch-commits] [llvm] [llvm-readobj, ELF] Support reading binary with more than PN_XNUM segments. (PR #165278)

James Henderson via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Feb 27 01:13:50 PST 2026


================
@@ -0,0 +1,45 @@
+## When an ELF object has PN_XNUM (0xffff) or more sections, its e_phnum field
+## should be PN_XNUM and sh_info of the section header at index 0 is used
+## to store the value.
+
+# RUN: yaml2obj --docnum=1 %s -o %t1
+# RUN: llvm-readelf --file-headers %t1 | FileCheck %s --check-prefix=VALID-GNU
+## The ELF header should have e_phnum == PN_XNUM
+# VALID-GNU:         Number of program headers: 65535 (2)
+# RUN: llvm-readobj --file-headers %t1 | FileCheck %s --check-prefix=VALID-LLVM
+# VALID-LLVM:        ProgramHeaderCount: 65535 (2)
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  EPhNum:  65535
+Sections:
+  - Type: SHT_NULL
+    Info: 2
+ProgramHeaders:
+  - Type:     PT_LOAD
+  - Type:     PT_LOAD
+
+# RUN: yaml2obj --docnum=2 %s -o %t2
+
+# RUN: llvm-readobj --file-headers %t2 2>&1 | FileCheck %s --implicit-check-not=warning: -DFILE=%t2 --check-prefix=INVALID-LLVM
+# RUN: llvm-readelf --file-headers %t2 2>&1 | FileCheck %s --implicit-check-not=warning: -DFILE=%t2 --check-prefix=INVALID-GNU
+
+# INVALID-LLVM: warning: '[[FILE]]': unable to read program headers to locate the PT_DYNAMIC segment: program headers are longer than binary of size 336: e_phoff = 0x40, e_phnum = 65536, e_phentsize = 56
+# INVALID-LLVM: ProgramHeaderCount: 65535 (65536)
+# INVALID-GNU: warning: '[[FILE]]': unable to read program headers to locate the PT_DYNAMIC segment: program headers are longer than binary of size 336: e_phoff = 0x40, e_phnum = 65536, e_phentsize = 56
+# INVALID-GNU: Number of program headers: 65535 (65536)
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  EPhNum:  65535
+Sections:
+  - Type: SHT_NULL
+    Info: 65536
+ProgramHeaders:
+  - Type: PT_LOAD
----------------
jh7370 wrote:

I'd be tempted to omit this part of the YAML, as I don't think it adds anything to the test and could caused confusion (i.e. "how many program headers should there be? The YAML lists 1").

https://github.com/llvm/llvm-project/pull/165278


More information about the llvm-branch-commits mailing list