public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* mudflap: main objects are inited too late for a shared library constructor
@ 2005-07-30  7:10 Eyal Lebedinsky
  2005-07-30  9:02 ` mudflap: main objects are inited too late for a shared library constructor [patch] Eyal Lebedinsky
  0 siblings, 1 reply; 2+ messages in thread
From: Eyal Lebedinsky @ 2005-07-30  7:10 UTC (permalink / raw)
  To: list gcc; +Cc: Frank Ch. Eigler

[-- Attachment #1: Type: text/plain, Size: 441 bytes --]

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 program demonstrates 'stderr' (simple to do)
but my main problem is 'environ' which I interrogate at
that time.

What is the correct way of handling this?

-- 
Eyal Lebedinsky (eyal@eyal.emu.id.au) <http://samba.org/eyal/>

[-- Attachment #2: zz40.sh --]
[-- Type: application/x-shellscript, Size: 1386 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: mudflap: main objects are inited too late for a shared library constructor [patch]
  2005-07-30  7:10 mudflap: main objects are inited too late for a shared library constructor Eyal Lebedinsky
@ 2005-07-30  9:02 ` Eyal Lebedinsky
  0 siblings, 0 replies; 2+ messages in thread
From: Eyal Lebedinsky @ 2005-07-30  9:02 UTC (permalink / raw)
  To: list gcc; +Cc: Frank Ch. Eigler

[-- Attachment #1: Type: text/plain, Size: 554 bytes --]

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 (eyal@eyal.emu.id.au) <http://samba.org/eyal/>
	attach .zip as .dat

[-- Attachment #2: mf-runtime.c.diff --]
[-- Type: text/x-patch, Size: 2774 bytes --]

--- 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-07-30  9:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-30  7:10 mudflap: main objects are inited too late for a shared library constructor Eyal Lebedinsky
2005-07-30  9:02 ` mudflap: main objects are inited too late for a shared library constructor [patch] Eyal Lebedinsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).