This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: more on the emacs-20.3 segfault


> This won't change anything.  You cannot install the malloc hook before the
> dynamic linker has passed control to the executable, when it is already
> too late.  A constructor won't help either because initializers are called
> after the initial atexit.

Yes, but using __malloc_initialize_hook seems to work just fine for me
with glibc-2.2.1.  Patch for emacs-20.3 appended below.  Only issue
before I forward it to the Emacs maintainers is whether it works with
libc5, where __malloc_initialize_hook wasn't a weak symbol.  Can you
all check whether the patch works for you as well ?

Thanks,
Wolfram.

1999-05-28  Wolfram Gloger  <wmglo@dent.med.uni-muenchen.de>

	* emacs.c [DOUG_LEA_MALLOC] (malloc_initialize_hook): New
	function, assigned to the global __malloc_initialize_hook pointer.
	(main): Move malloc_set_state call into malloc_initialize_hook
	so that it happens as early as possible.

--- emacs.c	1999/05/28 11:16:33	1.1
+++ emacs.c	1999/05/28 11:52:37
@@ -543,6 +543,26 @@
     }
 }
 
+#ifdef DOUG_LEA_MALLOC
+
+/* malloc() can be invoked even before main() (e.g. by the dynamic
+   linker), so the dumped malloc state must be restored as early as
+   possible using this special hook. */
+
+static void
+malloc_initialize_hook ()
+{
+  if (initialized)
+    {
+      malloc_set_state (malloc_state_ptr);
+      free (malloc_state_ptr);
+    }
+}
+
+void (*__malloc_initialize_hook)() = malloc_initialize_hook;
+
+#endif /* DOUG_LEA_MALLOC */
+
 /* ARGSUSED */
 int
 main (argc, argv, envp)
@@ -567,8 +587,6 @@
   if (initialized)
     {
       extern void r_alloc_reinit ();
-      malloc_set_state (malloc_state_ptr);
-      free (malloc_state_ptr);
       r_alloc_reinit ();
     }
 #endif

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]