Eyal Lebedinsky wrote:
> I have a system that uses some shared libraries. I find that
> when a library constructor runs the __wrap_main() did not
> yet execute and as a results I get many violations on the
> objects that it registers.
The attached patch seems to work for me, is it proper?
It registers the standard data items at init time. I allowed it
to register in wrap_main too, but maybe all we need is to register
it at init time rather than in wrap_main.
--
Eyal Lebedinsky ([EMAIL PROTECTED]) <http://samba.org/eyal/>
attach .zip as .dat
--- gcc/libmudflap/mf-runtime.c.old 2005-07-30 18:53:17.000000000 +1000
+++ gcc/libmudflap/mf-runtime.c 2005-07-30 17:18:20.000000000 +1000
@@ -681,6 +681,38 @@
return trees[type];
}
+static void
+__mf_register_std_data (void)
+{
+ static int been_here = 0;
+ unsigned i;
+
+ if (!__mf_opts.heur_std_data || been_here)
+ return;
+
+ been_here = 1;
+
+ for (i=0; ; i++)
+ {
+ char *e = environ[i];
+ unsigned j;
+ if (e == NULL) break;
+ j = strlen (environ[i]);
+ __mf_register (environ[i], j+1, __MF_TYPE_STATIC, "environ element");
+ }
+ __mf_register (environ, sizeof(char *)*(i+1), __MF_TYPE_STATIC, "environ[]");
+
+ __mf_register (& errno, sizeof (errno), __MF_TYPE_STATIC, "errno area");
+
+ __mf_register (stdin, sizeof (*stdin), __MF_TYPE_STATIC, "stdin");
+ __mf_register (stdout, sizeof (*stdout), __MF_TYPE_STATIC, "stdout");
+ __mf_register (stderr, sizeof (*stderr), __MF_TYPE_STATIC, "stderr");
+
+ /* Make some effort to register ctype.h static arrays. */
+ /* XXX: e.g., on Solaris, may need to register __ctype, _ctype, __ctype_mask, __toupper, etc. */
+ /* On modern Linux GLIBC, these are thread-specific and changeable, and are dealt
+ with in mf-hooks2.c. */
+}
/* not static */void
__mf_init ()
@@ -724,6 +756,8 @@
/* Prevent access to *NULL. */
__mf_register (MINPTR, 1, __MF_TYPE_NOACCESS, "NULL");
__mf_lookup_cache[0].low = (uintptr_t) -1;
+
+ __mf_register_std_data ();
}
@@ -740,6 +774,8 @@
{
unsigned i;
+ __mf_register_std_data ();
+
been_here = 1;
__mf_register (argv, sizeof(char *)*(argc+1), __MF_TYPE_STATIC, "argv[]");
for (i=0; i<argc; i++)
@@ -748,26 +784,6 @@
__mf_register (argv[i], j+1, __MF_TYPE_STATIC, "argv element");
}
- for (i=0; ; i++)
- {
- char *e = environ[i];
- unsigned j;
- if (e == NULL) break;
- j = strlen (environ[i]);
- __mf_register (environ[i], j+1, __MF_TYPE_STATIC, "environ element");
- }
- __mf_register (environ, sizeof(char *)*(i+1), __MF_TYPE_STATIC, "environ[]");
-
- __mf_register (& errno, sizeof (errno), __MF_TYPE_STATIC, "errno area");
-
- __mf_register (stdin, sizeof (*stdin), __MF_TYPE_STATIC, "stdin");
- __mf_register (stdout, sizeof (*stdout), __MF_TYPE_STATIC, "stdout");
- __mf_register (stderr, sizeof (*stderr), __MF_TYPE_STATIC, "stderr");
-
- /* Make some effort to register ctype.h static arrays. */
- /* XXX: e.g., on Solaris, may need to register __ctype, _ctype, __ctype_mask, __toupper, etc. */
- /* On modern Linux GLIBC, these are thread-specific and changeable, and are dealt
- with in mf-hooks2.c. */
}
#ifdef PIC