Skip to content

Commit

Permalink
[BZ #3112]
Browse files Browse the repository at this point in the history
2007-10-27  Andreas Jaeger  <aj@suse.de>
	[BZ #3112]
	* sysdeps/ia64/backtrace.c (init): Free shared library if incorrect.
	(__cleanup): Free shared library when exiting.
	* sysdeps/i386/backtrace.c (init): Free shared library if incorrect.
	(__cleanup): Free shared library when exiting.
  • Loading branch information
Ulrich Drepper committed Oct 28, 2007
1 parent e6b29af commit 05d6914
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2007-10-27 Andreas Jaeger <aj@suse.de>

[BZ #3112]
* sysdeps/ia64/backtrace.c (init): Free shared library if incorrect.
(__cleanup): Free shared library when exiting.
* sysdeps/i386/backtrace.c (init): Free shared library if incorrect.
(__cleanup): Free shared library when exiting.

2006-04-14 H.J. Lu <hongjiu.lu@intel.com>

[BZ #2549]
Expand Down
35 changes: 27 additions & 8 deletions sysdeps/i386/backtrace.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Return backtrace of current program state.
Copyright (C) 1998, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
Copyright (C) 1998, 2000, 2003-2005, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
Expand Down Expand Up @@ -36,21 +36,26 @@ static _Unwind_Reason_Code (*unwind_backtrace) (_Unwind_Trace_Fn, void *);
static _Unwind_Ptr (*unwind_getip) (struct _Unwind_Context *);
static _Unwind_Ptr (*unwind_getcfa) (struct _Unwind_Context *);
static _Unwind_Ptr (*unwind_getgr) (struct _Unwind_Context *, int);
static void *libgcc_handle;

static void
init (void)
{
void *handle = __libc_dlopen ("libgcc_s.so.1");
libgcc_handle = __libc_dlopen ("libgcc_s.so.1");

if (handle == NULL)
if (libgcc_handle == NULL)
return;

unwind_backtrace = __libc_dlsym (handle, "_Unwind_Backtrace");
unwind_getip = __libc_dlsym (handle, "_Unwind_GetIP");
unwind_getcfa = __libc_dlsym (handle, "_Unwind_GetCFA");
unwind_getgr = __libc_dlsym (handle, "_Unwind_GetGR");
unwind_backtrace = __libc_dlsym (libgcc_handle, "_Unwind_Backtrace");
unwind_getip = __libc_dlsym (libgcc_handle, "_Unwind_GetIP");
unwind_getcfa = __libc_dlsym (libgcc_handle, "_Unwind_GetCFA");
unwind_getgr = __libc_dlsym (libgcc_handle, "_Unwind_GetGR");
if (unwind_getip == NULL || unwind_getgr == NULL || unwind_getcfa == NULL)
unwind_backtrace = NULL;
{
unwind_backtrace = NULL;
__libc_dlclose (libgcc_handle);
libgcc_handle = NULL;
}
}
#else
# define unwind_backtrace _Unwind_Backtrace
Expand Down Expand Up @@ -142,3 +147,17 @@ __backtrace (array, size)
}
weak_alias (__backtrace, backtrace)
libc_hidden_def (__backtrace)


#ifdef SHARED
/* Free all resources if necessary. */
libc_freeres_fn (free_mem)
{
unwind_backtrace = NULL;
if (libgcc_handle != NULL)
{
__libc_dlclose (libgcc_handle);
libgcc_handle = NULL;
}
}
#endif
25 changes: 20 additions & 5 deletions sysdeps/ia64/backtrace.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Return backtrace of current program state.
Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
Expand Down Expand Up @@ -33,17 +33,18 @@ struct trace_arg
#ifdef SHARED
static _Unwind_Reason_Code (*unwind_backtrace) (_Unwind_Trace_Fn, void *);
static _Unwind_Ptr (*unwind_getip) (struct _Unwind_Context *);
static void *libgcc_handle;

static void
init (void)
{
void *handle = __libc_dlopen ("libgcc_s.so.1");
libgcc_handle = __libc_dlopen ("libgcc_s.so.1");

if (handle == NULL)
if (libgcc_handle == NULL)
return;

unwind_backtrace = __libc_dlsym (handle, "_Unwind_Backtrace");
unwind_getip = __libc_dlsym (handle, "_Unwind_GetIP");
unwind_backtrace = __libc_dlsym (libgcc_handle, "_Unwind_Backtrace");
unwind_getip = __libc_dlsym (libgcc_handle, "_Unwind_GetIP");
if (unwind_getip == NULL)
unwind_backtrace = NULL;
}
Expand Down Expand Up @@ -91,3 +92,17 @@ __backtrace (array, size)
}
weak_alias (__backtrace, backtrace)
libc_hidden_def (__backtrace)


#ifdef SHARED
/* Free all resources if necessary. */
libc_freeres_fn (free_mem)
{
unwind_backtrace = NULL;
if (libgcc_handle != NULL)
{
__libc_dlclose (libgcc_handle);
libgcc_handle = NULL;
}
}
#endif

0 comments on commit 05d6914

Please sign in to comment.