Created attachment 145830 [details] Demo code for bug Combinations of -pie, -lm(|_p) and -pthread compile successfully but then segfault. Using attached demo code I get this on FreeBSD 11.0-CURRENT #0 r268981: [1]> clang -pg -pie -pthread -lm profile.c && ./a.out Segmentation fault (core dumped) [2]> clang -pg -pie -pthread -lm_p profile.c && ./a.out Segmentation fault (core dumped) [3]> clang -pg -pthread -lm profile.c && ./a.out Segmentation fault (core dumped) [4]> clang -pg -pthread -lm_p profile.c && ./a.out [SUCCESS] [5]> clang -pg -pthread -lm profile.c && ./a.out Segmentation fault (core dumped) [6]> clang -pg -pie -pthread profile.c && ./a.out Segmentation fault (core dumped) At least 2,4,6 are supposed to work, if not all. On 10-STABLE, e.g. 3+4 work as expected.
My attempts to build with -pie -fPIE -pg on -CURRENT fail to link with errors like ld: error: cannot preempt symbol: _DYNAMIC >>> defined in >>> referenced by crt1_c.c:61 (/usr/home/emaste/src/freebsd-git/laptop/lib/csu/amd64/crt1_c.c:61) >>> /usr/lib/gcrt1.o:(_start)
Hitting this with (some?) ports, in this case lang/php80: 14.0-CURRENT #0 main-n251899-fa255ab1b89-dirty /GENERIC-NODEBUG amd6 configure:4149: $? = 1 configure:4169: checking whether the C compiler works configure:4191: cc -march=sandybridge -mtune=sandybridge -O2 -pipe -fpie -fPIC -flto=thin -fstack-protector-strong -fno-strict-aliasing -I/usr/local/include -D_FORTIFY_SOURCE=2 -Wl,--enable-new-dtags -Wl,-z,relro,-z,now -Wl,-pie,-z> ld: error: cannot preempt symbol: _DYNAMIC >>> referenced by crt1_c.c:59 (/usr/src/lib/csu/amd64/crt1_c.c:59) >>> /usr/lib/crt1.o:(_start) ld: error: cannot preempt symbol: _DYNAMIC >>> referenced by ignore_init.c:106 (/usr/src/lib/csu/common/ignore_init.c:106) >>> /usr/lib/crt1.o:(handle_static_init) ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC >>> defined in /usr/lib/crt1.o >>> referenced by ignore_init.c:109 (/usr/src/lib/csu/common/ignore_init.c:109) >>> /usr/lib/crt1.o:(handle_static_init) Google found me this bug and review D25086 Is this the same issue as on i386 as reported here?
Is this still relevant? It was reported for 11.x, but in 14.x profiled libraries are gone by default.
(In reply to Dimitry Andric from comment #3) Change of the default setting in FreeBSD does not make the linker less broken.