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

    <tr>
        <th>Summary</th>
        <td>
            [ppc64le] unknown relocation (18) against symbol exit
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    When cross-compiling [libucontext-1.3.2](https://github.com/kaniini/libucontext) for `ppc64le`, I'm running into the following linker error from `ld.lld`:

```
$ CC=clang CFLAGS='--target=ppc64le-alpine-linux-musl --sysroot=/opt/cross/O2' LDFLAGS='--target=ppc64le-alpine-linux-musl --sysroot=/opt/cross/O2 -static-libgcc -fuse-ld=lld' make ARCH=ppc64le
clang -std=gnu99 -D_DEFAULT_SOURCE -fPIC -DPIC --target=ppc64le-alpine-linux-musl --sysroot=/opt/cross/O2 -Iinclude -Iarch/ppc64 -Iarch/common -Iarch/common/include -DFORCE_SOFT_FLOAT -DEXPORT_UNPREFIXED -c -o arch/ppc64/makecontext.o arch/ppc64/makecontext.c
clang -std=gnu99 -D_DEFAULT_SOURCE -fPIC -DPIC --target=ppc64le-alpine-linux-musl --sysroot=/opt/cross/O2 -Iinclude -Iarch/ppc64 -Iarch/common -Iarch/common/include -DFORCE_SOFT_FLOAT -DEXPORT_UNPREFIXED -c -o arch/ppc64/retfromsyscall.o arch/ppc64/retfromsyscall.c
clang -fPIC -DPIC --target=ppc64le-alpine-linux-musl --sysroot=/opt/cross/O2 -Iinclude -Iarch/ppc64 -Iarch/common -Iarch/common/include -DFORCE_SOFT_FLOAT -DEXPORT_UNPREFIXED -Wa,--noexecstack -c -o arch/ppc64/getcontext.o arch/ppc64/getcontext.S
clang -fPIC -DPIC --target=ppc64le-alpine-linux-musl --sysroot=/opt/cross/O2 -Iinclude -Iarch/ppc64 -Iarch/common -Iarch/common/include -DFORCE_SOFT_FLOAT -DEXPORT_UNPREFIXED -Wa,--noexecstack -c -o arch/ppc64/setcontext.o arch/ppc64/setcontext.S
clang -fPIC -DPIC --target=ppc64le-alpine-linux-musl --sysroot=/opt/cross/O2 -Iinclude -Iarch/ppc64 -Iarch/common -Iarch/common/include -DFORCE_SOFT_FLOAT -DEXPORT_UNPREFIXED -Wa,--noexecstack -c -o arch/ppc64/startcontext.o arch/ppc64/startcontext.S
clang -fPIC -DPIC --target=ppc64le-alpine-linux-musl --sysroot=/opt/cross/O2 -Iinclude -Iarch/ppc64 -Iarch/common -Iarch/common/include -DFORCE_SOFT_FLOAT -DEXPORT_UNPREFIXED -Wa,--noexecstack -c -o arch/ppc64/swapcontext.o arch/ppc64/swapcontext.S
clang -fPIC -o libucontext.so -shared -Wl,-soname,libucontext.so.1 -Wl,-z,noexecstack arch/ppc64/makecontext.o arch/ppc64/retfromsyscall.o arch/ppc64/getcontext.o arch/ppc64/setcontext.o arch/ppc64/startcontext.o arch/ppc64/swapcontext.o --target=ppc64le-alpine-linux-musl --sysroot=/opt/cross/O2 -static-libgcc -fuse-ld=lld
ld.lld: error: arch/ppc64/startcontext.o:(.text+0x20): unknown relocation (18) against symbol exit
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:127: libucontext.so] Error 1
```

Using `ld.mold` gives a similar error, using `ld.bfd` makes `bfd` segfault.

The error is caused by Clang creating an object file with an unrecognized relocation type (0x12 == 18) from the `arch/ppc64/startcontext.S` assembly input:

```
$ clang --target=ppc64le-alpine-linux-musl -Iarch/common -Wa,--noexecstack -c -o arch/ppc64/startcontext.o arch/ppc64/startcontext.S
$ readelf -r arch/ppc64/startcontext.o 

Relocation section '.rela.text' at offset 0xc8 contains 1 entry:
  Offset          Info           Type           Sym. Value Sym. Name + Addend
000000000020  000300000012 unrecognized: 12 0000000000000000 exit + 0
```

OTOH, GCC produces valid output:

```
$ /opt/cross/O2/usr/bin/ppc64le-alpine-linux-musl-gcc -Iarch/common -Wa,--noexecstack -c -o arch/ppc64/startcontext.o arch/ppc64/startcontext.S
$ readelf -r arch/ppc64/startcontext.o 

Relocation section '.rela.text' at offset 0x158 contains 1 entry:
 Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000020  00070000000e R_PPC64_GOT16     0000000000000000 exit + 0
```

This is with [Clang 20 from Alpine Linux 3.22](https://pkgs.alpinelinux.org/package/v3.22/main/x86_64/clang20):

```
$ clang -v
Alpine clang version 20.1.8
Target: x86_64-alpine-linux-musl
Thread model: posix
InstalledDir: /usr/lib/llvm20/bin
Configuration file: /etc/clang20/x86_64-alpine-linux-musl.cfg
System configuration file directory: /etc/clang20
Found candidate GCC installation: /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0
Selected GCC installation: /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
```

Please let me know if you need any other information.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkWN1u4zjSfRr6piCBovx74QvFinoC5BsHifvruQtoqiRzQ5EGSTn2PP2CktJxJx3P9KJ3gd0WhMQUyWLVqcPikbhzstaISzK5IpN8xFu_M3bZ7I6jrSlPyy871CCscS4SptlLJXUNZHKl5LYVRns8-iiJ05iRSU7YfOf93pE0I6wgrKil37XbWJiGsOKJaym1JKw4m0vYAipjgUzpfi-mY4VkSglbwQ1hswZsq3VYUGpvwO8QKqOUeQ6PlNRPaAGtNRYqa5pgQ5WxUmUwkWaEdveUDjfNCBvDakXSXCiua1gVt9mnB5LmhM2iyHNboydpPvgRcbWXGiMldXuMmtYpiCJ3ctYY380pzN4TVnTYEFasGWEzuM1_slGInOdeikjJbS0ERFXrMFIlSfMQKZtBw58QsvvVb6_LEJr1IUbOh5G1bhcLiPLH_LrIPt9uHh_Wn-9X1xBVdzcriPLu709x9kZqodoSIbrhVuwIKzpjr01hmsbot23Ciq8T82J9v7p-fFgXm8fidp1tIMqv_7hb328eP_9-d39d3Pxx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