This is the mail archive of the 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]
Other format: [Raw text]

[PATCH] Fix dlerror (was Re: C++/dlerror/pthread problem)

On Thu, Jul 31, 2003 at 04:28:01PM +0200, Thorsten Kukuk wrote:
> Hi,
> The appended example program works fine, if not linked against
> libpthread or if it is compiled as C program. But as C++ program
> linked against libpthread, it will seg.fault in dlerror().
> Does somebody know why? I know it is a bad idea to call dlerror()
> without any other dl* call before, but people are doing so ...

The problem is that key is only initialized if _dlerror_run is called.
The following patch should fix it:

2003-07-31  Jakub Jelinek  <>

	* dlfcn/dlerror.c (once): New.
	(dlerror): Call __libc_once.
	(_dlerror_run): Remove once.

--- libc/dlfcn/dlerror.c.jj	2003-03-15 15:06:37.000000000 -0500
+++ libc/dlfcn/dlerror.c	2003-07-31 13:09:44.000000000 -0400
@@ -1,5 +1,5 @@
 /* Return error detail for failing <dlfcn.h> functions.
-   Copyright (C) 1995,1996,1997,1998,1999,2000,2002, 2003
+   Copyright (C) 1995,1996,1997,1998,1999,2000,2002,2003
 	Free Software Foundation, Inc.
    This file is part of the GNU C Library.
@@ -38,6 +38,7 @@ static struct dl_action_result *static_b
 /* This is the key for the thread specific memory.  */
 static __libc_key_t key;
+__libc_once_define (static, once);
 /* Destructor for the thread-specific data.  */
 static void init (void);
@@ -50,6 +51,9 @@ dlerror (void)
   char *buf = NULL;
   struct dl_action_result *result;
+  /* If we have not yet initialized the buffer do it now.  */
+  __libc_once (once, init);
   /* Get error string.  */
   result = (struct dl_action_result *) __libc_getspecific (key);
   if (result == NULL)
@@ -100,7 +104,6 @@ int
 _dlerror_run (void (*operate) (void *), void *args)
-  __libc_once_define (static, once);
   struct dl_action_result *result;
   /* If we have not yet initialized the buffer do it now.  */


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