Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 490688 - sys-libs/uclibc-0.9.33.2[nptl]: segfault when static linking pthreads
Summary: sys-libs/uclibc-0.9.33.2[nptl]: segfault when static linking pthreads
Status: RESOLVED OBSOLETE
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: x86 Linux
: Normal normal (vote)
Assignee: Embedded Gentoo Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: uclibc-porting
  Show dependency tree
 
Reported: 2013-11-07 15:13 UTC by Gino Badouri
Modified: 2018-10-14 12:12 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Sample for testing (detached.c,693 bytes, text/x-csrc)
2013-11-07 15:15 UTC, Gino Badouri
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gino Badouri 2013-11-07 15:13:40 UTC
When using uclibc-0.9.33.2-r4, r5 or r6 with nptl, static applications will segfault on exit.
It seems to be related to pthread_exit () which causes siglongjmp to go to NULL.

I've attached a sample I found on the net to reproduce the problem.

[code]gcc -o detached -pthread detached.c 
./detached 
Main: creating thread
Thread starting...
Thread done.
Main: program completed. Exiting

# Now static
gcc -o detached -pthread -static -ggdb detached.c 
./detached
Main: creating thread
Thread starting...
Thread done.
Segmentation fault

# Backtrace
#0  0x00000000 in ?? ()
#1  0x0804bdf5 in siglongjmp ()
#2  0x0804a46d in ?? ()
#3  0x08055384 in _Unwind_ForcedUnwind_Phase2 ()
#4  0x080559ab in _Unwind_ForcedUnwind ()
#5  0x0804a4fd in __pthread_unwind ()
#6  0x0804a52a in pthread_exit ()
#7  0x08048aab in doWork (t=0x0) at detached.c:25
#8  0x080498eb in ?? ()
#9  0x0804a7e6 in clone ()[/code]

I tried the following patch:
http://git.uclibc.org/uClibc/commit/libpthread?id=23691332c8458adb469ad78051493ef0db434222
[code]diff --git a/libpthread/nptl/pthread_exit.c b/libpthread/nptl/pthread_exit.c
index b37be7a..141ca75 100644
--- a/libpthread/nptl/pthread_exit.c
+++ b/libpthread/nptl/pthread_exit.c
@@ -29,3 +29,9 @@ __pthread_exit (void* value)
   __do_cancel ();
 }
 strong_alias (__pthread_exit, pthread_exit)
+
+/*
+ * After a thread terminates, __uClibc_main decrements __nptl_nthreads
+ * defined in pthread_create.c.
+ */
+PTHREAD_STATIC_FN_REQUIRE (pthread_create)[/code]

But it doesn't seem to fix it.

I also tried to disable: UCLIBC_DYNAMIC_ATEXIT
Which according to the Config.in:
[code]When this option is enabled, uClibc will support an infinite number,
of atexit() and on_exit() functions, limited only by your available
memory.  This can be important when uClibc is used with C++, since
global destructors are implemented via atexit(), and it is quite
possible to exceed the default number when this option is disabled.
Enabling this option adds a few bytes, and more significantly makes
atexit and on_exit depend on malloc, which can be bad when compiling
static executables.

Unless you use uClibc with C++, you should probably answer N.[/code]

But still the problem exists when compiling static binaries using pthread.

The same happens when compiling busybox statically for use with iniramfs.
Each applets works correctly, but segfaults on exit (spamming my dmesg during booting).
Comment 1 Gino Badouri 2013-11-07 15:15:13 UTC
Created attachment 362738 [details]
Sample for testing
Comment 2 Anthony Basile gentoo-dev 2018-10-14 12:12:02 UTC
sys-libs/uclibc has been removed from the tree, replaced by sys-libs/uclibc-ng.  if this is still a problem on uclibc-ng, please open a new bug.