Skip to content

[ppc64le] unknown relocation (18) against symbol exit #150913

@mhx

Description

@mhx

When cross-compiling libucontext-1.3.2 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:

$ 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions