[uclibc-ng-devel] problem with stack protection, threads and static binaries

Waldemar Brodkorb wbx at uclibc-ng.org
Mon Sep 14 06:52:37 CEST 2015

Hi Daniel,
Daniel Fahlgren wrote,

> Hi,
> I'm experiencing problems with uClibc-ng when creating static binaries
> that uses threads. I originally reported this to the buildroot mailing
> list but got redirected here instead.

I have seen your comprehensive bug report.
> The problem is when using a combination of stack protection, threads and
> static binaries. The program will during start up get a sigsegv in
> __pthread_initialize_minimal_internal(), and gdb says the instruction is
> a
>   mov    %fs:0x28,%rax
> where %fs is 0x00. The reason for that is that the pthread library is
> compiled with stack protection but __pthread_initialize_minimal_internal
> is called before __libc_setup_tls in static binaries.
> I have created an ugly patch to verify my hypothesis (attached). With
> that patch the test program works, but what is the proper way to solve
> this issue?

Does this happen only when uClibc itself is compiled with stack
protection? Or just when the pthread app is statically linked and
compiled with -fstack-protector?
> With uClibc 0.9.33.x the same thing happens. With glibc the program
> works.

I can reproduce the bug. Moving __libc_setup_tls from NPTL init to
__uClibc_main.c fixes it. Why do you think it is ugly to do this?

Does attached patch works for you? Just a cleaned up version of your
fix. It doesn't produce any regressions running the testsuite.

best regards
-------------- next part --------------
A non-text attachment was scrubbed...
Name: static-tls-ssp.patch
Type: text/x-diff
Size: 2607 bytes
Desc: not available
URL: <http://mailman.uclibc-ng.org/pipermail/devel/attachments/20150914/91522154/attachment.patch>

More information about the devel mailing list