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

    <tr>
        <th>Summary</th>
        <td>
            lld: sh_size % sh_entsize != 0
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lld,
            lld:ELF
      </td>
    </tr>

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

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

<pre>
    TL;DR;
------

I think lld 18.1.6 produces a `.relro_padding` ELF section that has a size (`0x000d14`) and an entry size (`0x08`) where the modulus of size and entry size is non-zero (`4`).

How I got here
--------------

I'm sorry for this long issue but in order to understand how I got here I've document the whole process.

I've build [clang-18.1.8](https://kojihub.stream.rdu2.redhat.com/koji/buildinfo?buildID=65849) for CentOS Stream and our downstream tests discovered that for the i686 build, there's no clang-devel-debuginfo package falling out in the end.

By looking at the [logs for the i686 build](https://kojihub.stream.rdu2.redhat.com/kojifiles/packages/clang/18.1.8/1.el9/data/logs/i686/build.log) we noticed that `eu-strip` complains about `invalid section entry size` in multiple places. This message comes from [this comparison](https://sourceware.org/git/?p=elfutils.git;a=blob;f=libelf/elf32_updatenull.c;h=3594e8bad6c0fc87dafba5302b00ab691910b515;hb=HEAD#l416) in `eu-strip`:

```c
sh_size % shdr->sh_entsize != 0
```

In order to reproduce this `eu-strip` call locally, one can do the following. First get the libraries:

```console
$ mkdir foo
$ cd foo
$ curl -so clang-libs.rpm https://kojihub.stream.rdu2.redhat.com/kojifiles/packages/clang/18.1.8/1.el9/i686/clang-libs-18.1.8-1.el9.i686.rpm
$ rpm2cpio clang-libs.rpm | cpio -idmv
```

Then run `eu-strip`:

```console
$ eu-strip ./usr/lib/libclang.so.18.1.8
eu-strip: while writing './usr/lib/libclang.so.18.1.8': invalid section entry size
```

Let's analyze the section headers of the above library and ignore those headers that have an entry size of 0:

```console
$ readelf --section-headers ./usr/lib/libclang.so.18.1.8 | grep -v " 00 "
There are 41 section headers, starting at offset 0x90914cc:

Section Headers:
  [Nr] Name              Type Addr     Off    Size   ES Flg Lk Inf Al
  [ 3] .dynsym           DYNSYM 000001f4 0001f4 005610 10   A  8   1  4
  [ 4] .gnu.version VERSYM          00005804 005804 000ac2 02   A  3   0  2
  [ 7] .gnu.hash GNU_HASH        000064d8 0064d8 000c10 04   A  3   0  4
  [ 9] .rel.dyn          REL             00015680 015680 159a10 08   A  3   0  4
 [10] .rel.plt          REL             0016f090 16f090 001d48 08  AI  3  25 4
  [21] .fini_array       FINI_ARRAY      0205f830 205d830 000004 04  WA 0   0  4
  [22] .init_array       INIT_ARRAY      0205f834 205d834 000018 04  WA  0   0  4
  [23] .dynamic          DYNAMIC         0205f84c 205d84c 000108 08  WA  8   0  4
  [26] .relro_padding    NOBITS          020612ec 205f2ec 000d14 08  WA  3   0  1
  [31] .comment          PROGBITS 00000000 2062bec 00006d 01  MS  0   0  1
  [35] .debug_str        PROGBITS 00000000 5d38cb5 4d8848 01  MS  0   0  1
  [38] .symtab SYMTAB          00000000 893f864 0e6ea0 10     39 57738  4
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  D (mbind), p (processor specific)
```

Now we're almost there. Let's calculate the modules of the `Size` and `ES` (aka entry size) to find out if there's a section where the modulus is non-zero:

```console
echo "[ 4] .gnu.version    $((0x000ac2 % 0x02 ))"
echo "[ 7] .gnu.hash $((0x000c10 % 0x04 ))"
echo "[ 9] .rel.dyn        $((0x159a10 % 0x08 ))"
echo "[10] .rel.plt        $((0x001d48 % 0x08 ))"
echo "[21] .fini_array     $((0x000004 % 0x04 ))"
echo "[22] .init_array $((0x000018 % 0x04 ))"
echo "[23] .dynamic        $((0x000108 % 0x08 ))"
echo "[26] .relro_padding  $((0x000d14 % 0x08 ))"
echo "[31] .comment        $((0x00006d % 0x01 ))"
echo "[35] .debug_str $((0x4d8848 % 0x01 ))"
echo "[38] .symtab         $((0x0e6ea0 % 0x10 ))"
[ 3] .dynsym         0
[ 4] .gnu.version    0
[ 7] .gnu.hash 0
[ 9] .rel.dyn        0
[10] .rel.plt        0
[21] .fini_array 0
[22] .init_array     0
[23] .dynamic        0
[26] .relro_padding  4
[31] .comment        0
[35] .debug_str      0
[38] .symtab         0
````

Apparently the `.relro_padding  4` is non-zero.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0mN9y4jrSwJ9GuenCJct_MBe5gCGcob5M8tWQ3bNzlZItGXQiLFayYZin32rZgE2YnNRWrSsVQ0v6qbvV6pbgzql1JeU9SWYkmd_xpt4Ye_92eLvLjTjevzySaDb_TqIZoXNCpyP_tJ_b_0uoN6p6A60FhFkQBinsrBFNIR1wICkNrNTWvO64EKpak5TCw-MCnCxqZSqoN7yGDce-Tv2SQFhGUkp_UkpFGJOUEjYBXgngFciqtserblnX5bCRVkK9kbA1otGNA1O2XXFwb6RyUJlq9Eta01G6WYK-VV_NAZawNjUgt2_76Rn4gLDxFpyx9gilsegRB9pUa1DONRLypgZVgbFCWqgNNJWQ1tWo2WYwESBpL0GYotnKqvYGHTZGS3RqIZ0LrufdI15pASSZFZpX65FfhYwkc8KyTV3vHImmhC0IW7yZv9SmyQNXW8m3gRUNC6wUG14Hhdl2HQhbeKCqSkOi9vNyTqJ5mmTxBH2NJn6RVf28gpUneR-bxoIwh6qFQy1d7UAoV5i9tFK0K916R4JKs7TVm7AvKLGSsDEuDbRGCLmXeiRk3qxREdjx4o2vJZRca1WtwbQuRZasxMArsyNoY96wF289SJKZNmt3a_b_1kul0tIRtuj0wo9eccIWnf_ZIgyknhC2ELzmhC1QBcIWOPnJx4E2ax-9EipTq-LkJpJS2YxcbdUON0xhtjvNVeWA52g4Samq9lwrcd5HlwjHAaqCbaNrtcPA0byQLoAXDMqtdA7dWJitdFBas0Xn-HjFSbhVzlS3nOJMYwt54FYGxqKVa1Vj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