<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/132216>132216</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            llvm-readelf fails to report > 65535 segments
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:binary-utilities
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          emaste
      </td>
    </tr>
</table>

<pre>
    From FreeBSD bug [285547](https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=285547) a regression test started failing after we switched to LLVM's binutils replacements.

The test creates an ELF core file with more than 65535 segments ([test source code](https://github.com/freebsd/freebsd-src/blob/main/tests/sys/kern/coredump_phnum_helper.c)). llvm-readelf reports 65535 program headers.



GNU readelf:
```
$ /usr/local/bin/readelf -h ./coredump_phnum_help.core
ELF Header:
  Magic: 7f 45 4c 46 02 01 01 09 00 00 00 00 00 00 00 00 
  Class: ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI: UNIX - FreeBSD
  ABI Version:                       0
 Type:                              CORE (Core file)
  Machine: Advanced Micro Devices X86-64
  Version: 0x1
  Entry point address:               0x0
  Start of program headers: 64 (bytes into file)
  Start of section headers:          3726864 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         65535 (66550)
  Size of section headers:           64 (bytes)
  Number of section headers: 1
  Section header string table index: 0
```

llvm-readelf:
```
$ readelf -h ./coredump_phnum_help.core
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 09 00 00 00 00 00 00 00 00
  Class: ELF64
  Data:                              2's complement, little endian
 Version:                           1 (current)
  OS/ABI: UNIX - FreeBSD
  ABI Version:                       0
  Type: CORE (Core file)
  Machine: Advanced Micro Devices X86-64
  Version:                           0x1
 Entry point address:               0x0
  Start of program headers: 64 (bytes into file)
  Start of section headers:          3726864 (bytes into file)
  Flags:                             0x0
  Size of this header: 64 (bytes)
  Size of program headers:           56 (bytes)
 Number of program headers:         65535
  Size of section headers: 64 (bytes)
  Number of section headers:         1
  Section header string table index: 0
```

Support added to FreeBSD's copy of ELF Tool Chain: https://github.com/freebsd/freebsd-src/commit/714935be5a0448c889ae3a3dcf261ea2a7edece3
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkVt9v2zYQ_mvol4MNmvph-UEPchxtBZoWWNqibwVFnSVulCiQVFL3rx9OtpM0cZN1y7CHCURiU767j8f7PnzSe930iDlLNizZzuQYWuty7KQPOKtsvc9LZzsoHeLmegvV2ABLNiJLknjFki0TWRvC4FlUMFEyUVZj4xc7h1j5emFdc9j6po2RTJS-tbdfqrFZqEazqNQ1i7bHXGINEhw2Dr3XtoeAPoAP0gWsYSe10X0DchfQwS2Cv9VBtVhDsPD27acrJlYeKt2PQRsPDgcjFXbYB79gvGC8-NDiIaVyKAN6kD1cvi1BWYew0wbhVocWOvoaWtlDmiRRAh6bKQswkbFkcwBlR6cQlK3xXAcaHdqxWijbMVEeO3H_ae6dop4YWzFRdlL3TJSU1lN79vT3D3S0ScjqsRu-DG0_dl9aNAO6hWJizcR6AcbcdHOHskazowNbF_wR9OBs42QHLb11pw4c1i_vPsIxihDzgqX8uHjBRAxMlKN3TJTGKmkI6gTxVGnewuI8uAXtMV5QV3-dKh8KAFzJRisWFbDaQZxArCBOgQvgy2mtgfPza4q-MNJTd-m60nja2sogaefZR0wzoWw3mGkSmLgAo0MwCNjXWvZTqk_oaNyez7ak61ejc1Oa9RT4_pqJsti8ociP7958hvmJJNPrYvPm5dzUc_iwH_DFw1y8_-2SQFycxvUE40qqVvdTgqK-kb3CGq60cha2eKMVevicpfNj3x4A4l-X09ZlH9weBqv7ALKuiX1PwfCvE1K4JjqC3T2eMIpIaXSyak_c0n2w36G8C_SoArH7QeDdE61Emj2bpjSyOQPvB2D1N6SSodX-WO9p6INyd1iPcWfOeP8k6ZO4d2NXoXsh8k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