Bug 192686 - Segfaults using combinations of -pie -pthread -lm(|_p) when profiling
Summary: Segfaults using combinations of -pie -pthread -lm(|_p) when profiling
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: threads (show other bugs)
Version: 11.4-RELEASE
Hardware: i386 Any
: --- Affects Some People
Assignee: freebsd-threads (Nobody)
URL:
Keywords: needs-qa
Depends on:
Blocks:
 
Reported: 2014-08-15 17:09 UTC by Thomas Zander
Modified: 2023-01-22 21:57 UTC (History)
4 users (show)

See Also:
koobs: maintainer-feedback? (toolchain)


Attachments
Demo code for bug (158 bytes, text/plain)
2014-08-15 17:09 UTC, Thomas Zander
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Zander freebsd_committer freebsd_triage 2014-08-15 17:09:50 UTC
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.
Comment 1 Ed Maste freebsd_committer freebsd_triage 2021-02-05 19:02:10 UTC
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)
Comment 2 Kubilay Kocak freebsd_committer freebsd_triage 2022-02-09 01:59:29 UTC
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?
Comment 3 Dimitry Andric freebsd_committer freebsd_triage 2023-01-22 21:37:35 UTC
Is this still relevant? It was reported for 11.x, but in 14.x profiled libraries are gone by default.
Comment 4 Konstantin Belousov freebsd_committer freebsd_triage 2023-01-22 21:57:56 UTC
(In reply to Dimitry Andric from comment #3)
Change of the default setting in FreeBSD does not make the linker less broken.