This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa libmudflap] shared library startup
- From: "Frank Ch. Eigler" <fche at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 2 Apr 2003 11:21:16 -0500
- Subject: [tree-ssa libmudflap] shared library startup
Hi -
The attached patch works around an interesting infinite recursion
problem that can occur within libmudflap.so. (It was observed
on a linux host with a recent glibc and including -lpthreads.)
The gist of it is that while libmudflap initializes the
intercepted malloc/free/etc. functions by using
"dlsym (RTLD_NEXT, ...)", reentrant malloc/etc. calls may occur.
The patch makes available dummy functions that would impersonate
the functions during this initialization state. It turns out
that on the test platform, having these dummy functions return
failure is sufficient to let the app start. In the future, it
might be necessary to put a baby malloc/free implementation
in there.
- FChE
+2003-04-02 Frank Ch. Eigler <fche at redhat dot com>
+
+ * mf-hooks.c (BEGIN_PROTECT): Handle startup-time reentrant
+ calls specially.
+ (__mf_0fn_malloc ... _munmap): New dummy backup calls.
+ * mf-impl.h (CALL_BACKUP): New macros.
+ * mf-runtime.c (__mf_init): Tweak __mf_state during startup.
+
Index: mf-hooks.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/mf-hooks.c,v
retrieving revision 1.1.2.27
diff -u -p -r1.1.2.27 mf-hooks.c
--- mf-hooks.c 31 Mar 2003 21:09:43 -0000 1.1.2.27
+++ mf-hooks.c 2 Apr 2003 16:15:53 -0000
@@ -45,10 +45,14 @@ XXX: libgcc license?
#define BEGIN_PROTECT(ty, fname, ...) \
ty result; \
enum __mf_state old_state; \
- if (UNLIKELY (__mf_state != active)) \
+ if (UNLIKELY (__mf_state == reentrant)) \
{ \
return CALL_REAL(fname, __VA_ARGS__); \
} \
+ else if (UNLIKELY (__mf_state == starting)) \
+ { \
+ return CALL_BACKUP(fname, __VA_ARGS__); \
+ } \
else \
{ \
old_state = __mf_state; \
@@ -65,6 +69,16 @@ XXX: libgcc license?
/* malloc/free etc. */
#ifdef WRAP_malloc
+
+#if PIC
+/* A special bootstrap variant. */
+static void *
+__mf_0fn_malloc (size_t c)
+{
+ return NULL;
+}
+#endif
+
#undef malloc
WRAPPER(void *, malloc, size_t c)
{
@@ -91,6 +105,16 @@ WRAPPER(void *, malloc, size_t c)
#ifdef WRAP_calloc
+
+#ifdef PIC
+/* A special bootstrap variant. */
+static void *
+__mf_0fn_calloc (size_t c, size_t n)
+{
+ return NULL;
+}
+#endif
+
#undef calloc
WRAPPER(void *, calloc, size_t c, size_t n)
{
@@ -122,6 +146,16 @@ WRAPPER(void *, calloc, size_t c, size_t
#endif
#ifdef WRAP_realloc
+
+#if PIC
+/* A special bootstrap variant. */
+static void *
+__mf_0fn_realloc (void *buf, size_t c)
+{
+ return NULL;
+}
+#endif
+
#undef realloc
WRAPPER(void *, realloc, void *buf, size_t c)
{
@@ -165,6 +199,16 @@ WRAPPER(void *, realloc, void *buf, size
#ifdef WRAP_free
+
+#if PIC
+/* A special bootstrap variant. */
+static void
+__mf_0fn_free (void *buf)
+{
+ return;
+}
+#endif
+
#undef free
WRAPPER(void, free, void *buf)
{
@@ -239,6 +283,17 @@ WRAPPER(void, free, void *buf)
#ifdef WRAP_mmap
+
+#if PIC
+/* A special bootstrap variant. */
+static void *
+__mf_0fn_mmap (void *start, size_t l, int prot, int f, int fd, off_t off)
+{
+ return NULL;
+}
+#endif
+
+
#undef mmap
WRAPPER(void *, mmap,
void *start, size_t length, int prot,
@@ -287,6 +342,17 @@ WRAPPER(void *, mmap,
#ifdef WRAP_munmap
+
+#if PIC
+/* A special bootstrap variant. */
+static int
+__mf_0fn_munmap (void *start, size_t length)
+{
+ return -1;
+}
+#endif
+
+
#undef munmap
WRAPPER(int , munmap, void *start, size_t length)
{
Index: mf-impl.h
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/mf-impl.h,v
retrieving revision 1.1.2.16
diff -u -p -r1.1.2.16 mf-impl.h
--- mf-impl.h 31 Mar 2003 21:09:44 -0000 1.1.2.16
+++ mf-impl.h 2 Apr 2003 16:15:53 -0000
@@ -261,6 +261,8 @@ ret fname (__VA_ARGS__)
__mf_resolve_dynamics (); \
((__mf_fn_ ## fname)(__mf_dynamic.dyn_ ## fname)) \
(__VA_ARGS__);})
+#define CALL_BACKUP(fname, ...) \
+ __mf_0fn_ ## fname(__VA_ARGS__)
#define CALL_WRAP(fname, ...) \
(__wrap_ ## fname (__VA_ARGS__))
@@ -272,6 +274,8 @@ ret __wrap_ ## fname (__VA_ARGS__)
extern ty __real_ ## fname (__VA_ARGS__)
#define CALL_REAL(fname, ...) \
__real_ ## fname (__VA_ARGS__)
+#define CALL_BACKUP(fname, ...) \
+ __real_ ## fname(__VA_ARGS__)
#define CALL_WRAP(fname, ...) \
__wrap_ ## fname (__VA_ARGS__)
Index: mf-runtime.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/mf-runtime.c,v
retrieving revision 1.1.2.30
diff -u -p -r1.1.2.30 mf-runtime.c
--- mf-runtime.c 31 Mar 2003 21:09:44 -0000 1.1.2.30
+++ mf-runtime.c 2 Apr 2003 16:15:53 -0000
@@ -511,10 +511,10 @@ void __mf_init ()
char *ov = 0;
__mf_state = starting;
-
#ifdef PIC
__mf_resolve_dynamics ();
#endif
+ __mf_state = active;
__mf_set_default_options ();
@@ -528,8 +528,6 @@ void __mf_init ()
exit (1);
}
}
-
- __mf_state = active;
/* Initialize to a non-zero description epoch. */
__mf_describe_object (NULL);