From: Frank Ch. Eigler Date: Fri, 10 Nov 2006 18:42:28 +0000 (+0000) Subject: re PR libmudflap/28578 (A most simple multithreaded program (practically any multithr... X-Git-Tag: releases/gcc-4.3.0~8550 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f70d742fc89c922a9ad5508753027eb17827369c;p=thirdparty%2Fgcc.git re PR libmudflap/28578 (A most simple multithreaded program (practically any multithreaded one) causes mudflap violation) 2006-11-10 Frank Ch. Eigler PR libmudflap/28578 * mf-hooks1.c (__mf_0fn_malloc): Make the bootstrap buffers static but not function scope static. (free): Skip deallocation attempts for objects placed into bootstrap buffers. * testsuite/libmudflap.cth/pass59-frag.c: New test. M libmudflap/mf-hooks1.c M libmudflap/ChangeLog A libmudflap/testsuite/libmudflap.cth/pass59-frag.c From-SVN: r118662 --- diff --git a/libmudflap/ChangeLog b/libmudflap/ChangeLog index 206411667e4a..5b9da8b73479 100644 --- a/libmudflap/ChangeLog +++ b/libmudflap/ChangeLog @@ -1,3 +1,12 @@ +2006-11-10 Frank Ch. Eigler + + PR libmudflap/28578 + * mf-hooks1.c (__mf_0fn_malloc): Make the bootstrap buffers + static but not function scope static. + (free): Skip deallocation attempts for objects placed into + bootstrap buffers. + * testsuite/libmudflap.cth/pass59-frag.c: New test. + 2006-11-06 Frank Ch. Eigler From Herman ten Brugge : diff --git a/libmudflap/mf-hooks1.c b/libmudflap/mf-hooks1.c index bef22687f195..acdbc447a5d7 100644 --- a/libmudflap/mf-hooks1.c +++ b/libmudflap/mf-hooks1.c @@ -75,21 +75,24 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA #if PIC + +enum { BS = 4096, NB=10 }; +static char __mf_0fn_bufs[NB][BS]; +static unsigned __mf_0fn_bufs_used[NB]; + + /* A special bootstrap variant. */ void * __mf_0fn_malloc (size_t c) { - enum foo { BS = 4096, NB=10 }; - static char bufs[NB][BS]; - static unsigned bufs_used[NB]; unsigned i; for (i=0; i= (uintptr_t) __mf_0fn_bufs && + (uintptr_t) buf < ((uintptr_t) __mf_0fn_bufs + sizeof(__mf_0fn_bufs)))) + { + VERBOSE_TRACE ("skipping free of boot (0fn) alloc buffer %p\n", buf); + return; + } +#endif + LOCKTH (); if (UNLIKELY(!freeq_initialized)) { diff --git a/libmudflap/testsuite/libmudflap.cth/pass59-frag.c b/libmudflap/testsuite/libmudflap.cth/pass59-frag.c new file mode 100644 index 000000000000..bf6c293136d5 --- /dev/null +++ b/libmudflap/testsuite/libmudflap.cth/pass59-frag.c @@ -0,0 +1,39 @@ +#include +#include + +/* PR 28578 */ + +void* test_thread(void* arg) +{ + printf("Hello from thread!\n"); + pthread_exit(NULL); + return 0; +} + +int main() +{ + pthread_t thread; + int arg = 0; + pthread_create(&thread, NULL, test_thread, (void*)arg); + pthread_join(thread, NULL); + pthread_exit(NULL); + return 0; +} + +/* { dg-output "Hello from thread!\n" } */ + +#if 0 + +/* Even this test case replicates the problem. However, when built in + static mode, it blows up during __mf_init (?!?!?!) with a + pthread_mutex_lock deadlock error. */ + +#include +#include + +int main () +{ + pthread_exit(NULL); + return 0; +} +#endif