[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


================
@@ -4853,10 +4875,16 @@ template <class ELFT> void GNUELFDumper<ELFT>::printProgramHeaders() {
   const Elf_Ehdr &Header = this->Obj.getHeader();
   Field Fields[8] = {2,         17,        26,        37 + Bias,
                      48 + Bias, 56 + Bias, 64 + Bias, 68 + Bias};
+  uint32_t PhNum = 0;
+  if (Expected<uint32_t> PhNumOrErr = this->Obj.getPhNum(); PhNumOrErr)
+    PhNum = *PhNumOrErr;
+  else
+    this->reportUniqueWarning(PhNumOrErr.takeError());
----------------
jh7370 wrote:

This isn't especially readable, in my opinion. I'd just follow what you do in the similar case in the function above.

I'd also look into what GNU does in this case, assuming GNU readelf supports PN_XNUM. It seems odd to report there are 0 program headers when the value is known to be incorrect.

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


More information about the llvm-branch-commits mailing list