Bug 193 - main thread dies after daemon() && pthread_create()
Summary: main thread dies after daemon() && pthread_create()
Status: NEW
Alias: None
Product: uClibc
Classification: Unclassified
Component: Threads (show other bugs)
Version: 0.9.30
Hardware: PC Linux
: P2 critical
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-18 14:29 UTC by Gustavo Andrés Angulo
Modified: 2015-04-16 09:20 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:


Attachments
Testcase (752 bytes, text/plain)
2009-03-18 18:11 UTC, Oliver Metz
Details
Testcase Threaded "hello world" (1.95 KB, text/plain)
2009-03-18 18:14 UTC, Oliver Metz
Details
simpler daemon/pthread test code (467 bytes, text/plain)
2009-03-19 05:27 UTC, Mike Frysinger
Details
strace of simple pthread test (3.70 KB, text/plain)
2009-03-19 16:08 UTC, Oliver Metz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gustavo Andrés Angulo 2009-03-18 14:29:58 UTC
Problem with pthread_create when use this function

error: https://sartrac.informatik.hu-berlin.de/seismo-openwrt/ticket/46


sqlite3 use libpthread and when call pthread_create 

-> lua+luasqlite3+libsqlite3

error: http://paste.pocoo.org/show/108381/
Comment 1 Oliver Metz 2009-03-18 15:59:25 UTC
Same problem here with uClibc-0.9.29 and some patches:
http://trac.freetz.org/browser/trunk/toolchain/make/target/uclibc/0.9.29

arch: mipsel (4kc)
binutils: 2.17.50.0.17
gcc: 4.2.1

Attached testcase prints out:
Mar 18 16:52:11 freetz user.info daemon_pthread_create: main - before daemon()
Mar 18 16:52:11 freetz user.info daemon_pthread_create: main - after daemon() before pthread_create()
Mar 18 16:52:11 freetz user.info daemon_pthread_create: thread running
Comment 2 Oliver Metz 2009-03-18 18:11:38 UTC
Created attachment 157 [details]
Testcase
Comment 3 Oliver Metz 2009-03-18 18:12:39 UTC
Perhaps following testcase is also related to this problem. Fails on same system.
Comment 4 Oliver Metz 2009-03-18 18:14:32 UTC
Created attachment 159 [details]
Testcase Threaded "hello world"
Comment 5 solar 2009-03-18 18:41:37 UTC
Please confirm if this is a problem with the current release. Our time machines are broken currently, so fixing older releases is hard.
Comment 6 Oliver Metz 2009-03-18 19:01:53 UTC
Should I try with linuxthreads_old or new? Don't know if this affects the testcases.
I will try newest release. But the result will be that the failures occur also. ;-)
Comment 7 solar 2009-03-18 19:06:13 UTC
libpthread.old (linuxthreads was never fully checked into the tree and thus is fundamentally broken)
Comment 8 Mike Frysinger 2009-03-19 05:26:54 UTC
you need to post all relevant information in the bug report.  references to other sites is a waste of time.

the usage of syslog() is not necessary and if anything, complicates things.
Comment 9 Mike Frysinger 2009-03-19 05:27:36 UTC
Created attachment 163 [details]
simpler daemon/pthread test code
Comment 10 Gustavo Andrés Angulo 2009-03-19 12:39:46 UTC
when I run simpler daemon the output for this program is:

root@:~# main - going to pthread_create()
thread running


and never ends, my sistem has uclibc 0.9.30.1 with libpthread.old, for the others test have the same behavior. 
Comment 11 Oliver Metz 2009-03-19 16:07:55 UTC
Attached strace of simpler daemon. Linked with uClibc-0.9.30.1.
Comment 12 Oliver Metz 2009-03-19 16:08:53 UTC
Created attachment 169 [details]
strace of simple pthread test
Comment 13 Oliver Metz 2009-03-30 09:39:42 UTC
Can I provide further information/details to speed up fixing this bug? Because it's very anoying...
No, I can't provide a patch. ;-)
Comment 14 Mike Frysinger 2009-04-06 06:46:38 UTC
the test case i posted is all the info that is required to reproduce.

if you really want to spend more effort, then it'd be helpful to bisect what introduced the problem.  0.9.28.3 works for me while 0.9.30.1 does not.  according to you, 0.9.29 also does not work ...
Comment 15 Oliver Metz 2009-04-16 09:04:28 UTC
https://dev.openwrt.org/ticket/4809

Here is a pending ticket addressing this issue. The description ("... the last uclibc has a broken "daemon" function implementation. "daemon" calls a wrong "fork" function (libc instead linuxthreads version) breaking the pthread environment. ") seems to be correct but the attached doesn't fix the problem for me.
Perhaps you can give me a hint how I get this weak linking of (pthread's) fork working.
Comment 16 Oliver Metz 2009-04-18 11:39:07 UTC
Build two i686 uclibc (0.9.28.3, 0.9.30.1) toolchains with buildroot today. I'm astonished to see the same problem here. Thought this is related to mipsel!?
Comment 17 Natanael Copa 2009-07-02 12:31:08 UTC
(In reply to comment #16)
> Build two i686 uclibc (0.9.28.3, 0.9.30.1) toolchains with buildroot today. I'm
> astonished to see the same problem here. Thought this is related to mipsel!?
> 

I can not reporoduce this on alpine linux, x86, uclibc 0.9.30.1 + patches, linuxthreads.new. You might want to try some of the patches we use.

http://git.alpinelinux.org/cgit/aports/tree/core/uclibc
Comment 18 Mike Frysinger 2009-07-22 06:20:09 UTC
this appears to be caused by the hidden alias to fork().  libpthread has its own fork() symbol but because daemon() calls the hidden one, that isnt used.

this simple patch fixes things for me:

--- a/include/unistd.h
+++ b/include/unistd.h
@@ -761 +761 @@
-libc_hidden_proto(fork)
+//libc_hidden_proto(fork)
--- a/libc/sysdeps/linux/common/fork.c
+++ b/libc/sysdeps/linux/common/fork.c
@@ -21 +21 @@
-libc_hidden_weak(fork)
+//libc_hidden_weak(fork)

but this doesnt address static linking ... the same bug will be observed
Comment 19 Oliver Metz 2011-04-22 09:43:59 UTC
The problem still occurs with uClibc-0.9.31. And I assume it will never be fixed for linuxthreads.old?