You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While investigating a problem with ifunc on FreeBSD/PPC64 kernel I came with a example code[1] that crashes with segmentation fault on FreeBSD. The key appears to be the combination of -static and -pie flags. The binary works if linked with GNU BFD (-fuse-ld=bfd)
On Linux PPC64 the binary works fine, but clang isn't actually producing a PIE binary, and it warns that -pie argument is not being used.
Results:
Build command
Result
CC=clang CFLAGS="-fuse-ld=lld" make && ./ifunc2_static
OK
CC=clang CFLAGS="-pie -fuse-ld=lld" make && ./ifunc2_static
SEGFAULT
CC=clang CFLAGS="-pie -fuse-ld=bfd" make && ./ifunc2_static
OK
I'm always availabe on IRC as adalava and I'll be happy to do any test or provide a FreeBSD VM. Thanks!
Using -Bdynamic with -static is incorrect: it links against libc.so while the used crt file does not expect non-IRELATIVE dynamic relocations.
In driver options, -static overrides -pie so you get a -Wunused-command-line-argument warning.
I believe early static PIE systems (OpenBSD, musl) actually made -static -pie mean static PIE, but upstream GCC made a decision to use -static-pie instead
and keep the -static -pie => -static status quo. Clang emulates its behavior while giving a useful warning.
ld.lld has an extension that --export-dynamic adds PT_DYNAMIC to a position-dependent executable. A PDE almost never has PT_DYNAMIC and therefore some system libc/crt may not support it. The libc/crt should be fixed to no longer assume PT_DYNAMIC implies PIE/shared object.
On Linux, this command produces a working executable: bmake CC='clang --target=powerpc64le-linux-gnu' LDFLAGS=-fuse-ld=lld _CFLAGS='-g -Xlinker --discard-locals'
While investigating a problem with ifunc on FreeBSD/PPC64 kernel I came with a example code[1] that crashes with segmentation fault on FreeBSD. The key appears to be the combination of
-staticand-pieflags. The binary works if linked with GNU BFD (-fuse-ld=bfd)On Linux PPC64 the binary works fine, but clang isn't actually producing a PIE binary, and it warns that -pie argument is not being used.
Results:
I'm always availabe on IRC as adalava and I'll be happy to do any test or provide a FreeBSD VM. Thanks!
[1] https://people.freebsd.org/~alfredo/tmp/ifunc-crash.tar.gz
The text was updated successfully, but these errors were encountered: