https://sourceware.org/bugzilla/show_bug.cgi?id=33223

            Bug ID: 33223
           Summary: ppc64le: ld.bfd segfaults on (invalid) object file
                    with unknown relocation
           Product: binutils
           Version: 2.44
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: sourceware-bugzilla at mhxnet dot de
  Target Milestone: ---

When cross-compiling libucontext-1.3.2 [1] for ppc64le, I'm running into the
following segfault when using ld.bfd:

```
$ 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=bfd' 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=bfd
clang: error: unable to execute command: Segmentation fault
clang: error: linker command failed due to signal (use -v to see invocation)
make: *** [Makefile:127: libucontext.so] Error 1
```

Clang is generating an object file with an unknown/unrecognized relocation from
the assembly input; this is a separate issue [2]:

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

Both ld.mold and ld.lld handle this gracefully reporting an error instead of
crashing:

```
ld.lld: error: arch/ppc64/startcontext.o:(.text+0x20): unknown relocation (18)
against symbol exit
```

```
mold: error: arch/ppc64/startcontext.o:(.text): unknown relocation: unknown
(0x12)
```

This is ld.bfd from binutils-2.44 without any patches:

```
$ /opt/cross/O2/usr/ppc64le-alpine-linux-musl/bin/ld.bfd -V
GNU ld (GNU Binutils) 2.44
  Supported emulations:
   elf64lppc
   elf32lppc
   elf32lppclinux
   elf32lppcsim
   elf64ppc
   elf32ppc
   elf32ppclinux
   elf32ppcsim
```

Please let me know if you need any more information.

[1] https://github.com/kaniini/libucontext
[2] https://github.com/llvm/llvm-project/issues/150913

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to