This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
system() (from libpthread) doesn't call cleanup handler when statically linked
- From: "Carmelo Amoroso" <carmelo73 at gmail dot com>
- To: libc-alpha at sourceware dot org
- Date: Mon, 22 Jan 2007 11:43:54 +0100
- Subject: system() (from libpthread) doesn't call cleanup handler when statically linked
Hi All,
I executed tst-cancel7 test statically linked using glibc-2.5 on sh4
using the following command:
sh4-linux-gcc -static -D_GNU_SOURCE -D__USE_GNU -std=gnu99 -Os
tst-cancel7.c -lpthread -o tst-cancel7
Running the executable on SH4 platform I got the following message:
"child xxx still running" with return code 1
while it works fine using DSO.
Doing further investigation I found that the problem is inside
system() implementation
from libpthread.
The call chain is as follows:
system() (libpthead.a:pt-system.o)
|__ __libc_system (libc.a:system.o)
|__ __libc_cleanup_region_start (macro from libc-lock.h)
|__ _pthread_cleanup_push_defer (if not NULL)
Being _pthread_push_cleanup_defer a weak undefined symbol, the static linker
doesn't report an error at link time, so the function will be resolved
to null and never
called by the __libc_system).
My proposal is:
1- make _pthread_cleanup_push_defer (and _pthread_cleanup_pop_restore)
a global undefined in static build.
2- change system implementation (libpthread.a:pt-system.o) simply including
the source file "system.c" forcing _pthread_cleanup_push_defer to be
resolved inside
libpthread.a:cleanup_compat_defer.o
3- provide a stub implementation into libc.a for
_pthread_cleanup_push_defer (and _pthread_cleanup_pop_restore) needed
when -lpthread is not used
Any comments are welcome.
If you think I'm correct, I could try to post a full patch