Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPC64 segfault using ifunc with -static and -pie #57851

Closed
adalava opened this issue Sep 20, 2022 · 2 comments
Closed

PPC64 segfault using ifunc with -static and -pie #57851

adalava opened this issue Sep 20, 2022 · 2 comments
Labels
backend:PowerPC invalid Resolved as invalid, i.e. not a bug

Comments

@adalava
Copy link
Contributor

adalava commented Sep 20, 2022

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!

[1] https://people.freebsd.org/~alfredo/tmp/ifunc-crash.tar.gz

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 20, 2022

@llvm/issue-subscribers-backend-powerpc

@MaskRay MaskRay added the invalid Resolved as invalid, i.e. not a bug label Sep 22, 2022
@MaskRay
Copy link
Member

MaskRay commented Sep 22, 2022

This issue is invalid.

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'

@MaskRay MaskRay closed this as not planned Won't fix, can't repro, duplicate, stale Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:PowerPC invalid Resolved as invalid, i.e. not a bug
Projects
None yet
Development

No branches or pull requests

4 participants