Bug 9689 - using profiling C library (-lc_p) segfaults early
Summary: using profiling C library (-lc_p) segfaults early
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.8
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-27 22:02 UTC by Mike Frysinger
Modified: 2015-08-21 21:19 UTC (History)
3 users (show)

See Also:
Host: x86_64-linux-gnu
Target:
Build:
Last reconfirmed: 2012-04-20 00:00:00
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Frysinger 2008-12-27 22:02:14 UTC
building up glibc with --enable-profile and then trying to use the resulting
library like so:
$ cat test.c
main(){}
$ gcc test.c -static -pg -lc_p -g

results in a crash:
$ gdb ./a.out
(gdb) r
Starting program: /home/vapier/test

Program received signal SIGSEGV, Segmentation fault.
0x000000000042fecb in __mcount_internal ()
(gdb) bt
#0  0x000000000042fecb in __mcount_internal ()
#1  0x000000000040dc04 in mcount ()
#2  0x0000000000000000 in ?? ()
(gdb)

the crash seems to be because gmon/mcount.c uses atomic code which relies on the
TLS descriptors being setup, but that doesnt happen until __libc_start_main.  but
since __libc_start_main itself (and other functions early on) calls mcount, we
crash.

crash is easily reproducible with current git and x86_64 or x86.  it's been this
way since at least glibc-2.6.1.
Comment 1 Andreas Jaeger 2012-04-20 19:24:22 UTC
This is still the case with glibc 2.15 on x86-64