[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 20 01:02:51 PST 2026


================
@@ -222,14 +224,15 @@ Sections:
 ## Check we don't dump anything except the file header when the section header table can't be read.
 
 # RUN: not llvm-readobj -a %t.invalid1 2>&1 \
-# RUN:  | FileCheck %s -DFILE=%t.invalid1 -DSECHDRCOUNT=8192 -DSECHDRSTRTABINDEX=12288 --check-prefix=INVALID-LLVM
+# RUN:  | FileCheck %s -DFILE=%t.invalid1 -DPHDRCOUNT="0" -DSECHDRCOUNT=8192 -DSECHDRSTRTABINDEX=12288 --check-prefix=INVALID-LLVM
 # RUN: not llvm-readelf -a %t.invalid1 2>&1 \
-# RUN:  | FileCheck %s -DFILE=%t.invalid1 -DSECHDRCOUNT=8192 -DSECHDRSTRTABINDEX=12288 --check-prefix=INVALID-GNU
+# RUN:  | FileCheck %s -DFILE=%t.invalid1 -DPHDRCOUNT="0" -DSECHDRCOUNT=8192 -DSECHDRSTRTABINDEX=12288 --check-prefix=INVALID-GNU
 
 ## Check what we print when e_shnum == 0, e_shstrndx == SHN_XINDEX and the section header table can't be read.
+## TODO: We should not report LLVM-BAD-PHDR and GNU-BAD-PHDR in the future since these are duplicate errors.
 
 # RUN: yaml2obj %s -DSHNUM=0 -DSHSTRNDX=0xffff --docnum=4 -o %t.invalid2
 # RUN: not llvm-readobj --file-headers %t.invalid2 2>&1 \
-# RUN:  | FileCheck %s -DFILE=%t.invalid2 -DSECHDRCOUNT="<?>" -DSECHDRSTRTABINDEX="<?>" --check-prefix=INVALID-LLVM
+# RUN:  | FileCheck %s -DFILE=%t.invalid2 -DPHDRCOUNT="<?>" -DSECHDRCOUNT="<?>" -DSECHDRSTRTABINDEX="<?>" --check-prefix=INVALID-LLVM,LLVM-BAD-PHDR
 # RUN: not llvm-readelf --file-headers %t.invalid2 2>&1 \
-# RUN:  | FileCheck %s -DFILE=%t.invalid2 -DSECHDRCOUNT="<?>" -DSECHDRSTRTABINDEX="<?>" --check-prefix=INVALID-GNU
+# RUN:  | FileCheck %s -DFILE=%t.invalid2 -DPHDRCOUNT="<?>" -DSECHDRCOUNT="<?>" -DSECHDRSTRTABINDEX="<?>" --check-prefix=INVALID-GNU,GNU-BAD-PHDR
----------------
jh7370 wrote:

I've taken a fresh look at these, hence why I didn't see this before, but it doesn't make sense to be reporting `<?>` for the program header count in this case, because e_phnum is 0, which is unambiguous and doesn't require any section headers.

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


More information about the llvm-branch-commits mailing list