Linkers are supposed to mark PIE binaries with DF_1_PIE, such binary cannot be correctly and usefully loaded neither by dlopen(3) nor as a dependency of other object.
Requested by: emaste
Differential D25086
Do not allow to load ET_DYN object with DF_1_PIE flag set. kib on May 31 2020, 10:48 PM. Authored by Tags None Referenced Files
Subscribers
Details Linkers are supposed to mark PIE binaries with DF_1_PIE, such binary cannot be correctly and usefully loaded neither by dlopen(3) nor as a dependency of other object. Requested by: emaste I cannot test, because it seems -fPIE -Wl,-pie is broken for all current toolchains, both base and ports.
Diff Detail
Event TimelineComment Actions lld 10 refuses to link with -fPIE -Wl,--pie with errors like ld: error: cannot preempt symbol: _DYNAMIC >>> defined in >>> referenced by crt1.c:62 (/usr/home/emaste/src/freebsd-svn/head/lib/csu/amd64/crt1.c:62) >>> /usr/lib/crt1.o:(_start) ... lld 8 proceeds: $ cc -fuse-ld=lld80 -fPIE -Wl,--pie -Wl,-z,notext ~/hello.c $ but the resulting binary segfaults on startup Comment Actions
Hrm, $ cc -g -pie -Wl,--pie -Wl,-z,notext ~/hello.c $ ./a.out Hello, world $ file a.out a.out: ELF 64-bit LSB shared object, x86-64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 13.0 (1300087), FreeBSD-style, with debug_info, not stripped Comment Actions Following up after discussions on IRC, the canonical way do do this is: Comment Actions This looks reasonable to me. We'll need to bring in a couple of LLVM commits to be able to test.
|