summaryrefslogtreecommitdiff
path: root/libmudflap
diff options
context:
space:
mode:
authorfche <fche@138bc75d-0d04-0410-961f-82ee72b054a4>2006-11-10 18:42:28 +0000
committerfche <fche@138bc75d-0d04-0410-961f-82ee72b054a4>2006-11-10 18:42:28 +0000
commit721cae82d644adb901d4f29b6de5e4fc034ca45f (patch)
treef1e9d593de06af753a78e3763ac0ae92abff57ec /libmudflap
parenta60f2dd76587f4122e5c58df77fb7769e05e23c7 (diff)
downloadgcc-721cae82d644adb901d4f29b6de5e4fc034ca45f.tar.gz
2006-11-10 Frank Ch. Eigler <fche@redhat.com>
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 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@118662 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libmudflap')
-rw-r--r--libmudflap/ChangeLog9
-rw-r--r--libmudflap/mf-hooks1.c28
-rw-r--r--libmudflap/testsuite/libmudflap.cth/pass59-frag.c39
3 files changed, 70 insertions, 6 deletions
diff --git a/libmudflap/ChangeLog b/libmudflap/ChangeLog
index 206411667e4..5b9da8b7347 100644
--- a/libmudflap/ChangeLog
+++ b/libmudflap/ChangeLog
@@ -1,3 +1,12 @@
+2006-11-10 Frank Ch. Eigler <fche@redhat.com>
+
+ 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 <fche@redhat.com>
From Herman ten Brugge <hermantenbrugge@home.nl>:
diff --git a/libmudflap/mf-hooks1.c b/libmudflap/mf-hooks1.c
index bef22687f19..acdbc447a5d 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<NB; i++)
{
- if (! bufs_used[i] && c < BS)
+ if (! __mf_0fn_bufs_used[i] && c < BS)
{
- bufs_used[i] = 1;
- return & bufs[i][0];
+ __mf_0fn_bufs_used[i] = 1;
+ return & __mf_0fn_bufs[i][0];
}
}
return NULL;
@@ -246,6 +249,19 @@ WRAPPER(void, free, void *buf)
if (UNLIKELY(buf == NULL))
return;
+#if PIC
+ /* Check whether the given buffer might have come from a
+ __mf_0fn_malloc/calloc call that for whatever reason was not
+ redirected back to __mf_0fn_free. If so, we just ignore the
+ call. */
+ if (UNLIKELY((uintptr_t) buf >= (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 00000000000..bf6c293136d
--- /dev/null
+++ b/libmudflap/testsuite/libmudflap.cth/pass59-frag.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <pthread.h>
+
+/* 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 <stdio.h>
+#include <pthread.h>
+
+int main ()
+{
+ pthread_exit(NULL);
+ return 0;
+}
+#endif