* [PATCH] Fix LD_DEBUG=statistics
@ 2002-10-24 12:03 Jakub Jelinek
2002-10-25 3:38 ` Roland McGrath
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2002-10-24 12:03 UTC (permalink / raw)
To: Roland McGrath, Ulrich Drepper; +Cc: Glibc hackers
Hi!
ATM LD_DEBUG=statistics (or LD_TRACE_PRELINKING) fails with programs
linked againt libpthread.so.0.
The problem is that there are calls to _dl_debug_*printf after ld.so
is re-relocated (ie. when pthread_mutex_lock changes from NULL to
libpthread implementation) and before __pthread_initialize_minimal
is called.
Below are 2 fixes for that: due to missing sysdep.h include INTERNAL_SYSCALL
was not defined even on IA-32 linux in that file, plus if INTERNAL_SYSCALL
is not defined, then we should wait until __pthread_initialize_minimal
is called. This happens before dl_starting_up is cleared and no threads
should be started until then.
In addition to this, this patch defines INTERNAL_SYSCALL
on a few other arches.
2002-10-24 Jakub Jelinek <jakub@redhat.com>
* elf/dl-misc.c: Include <sysdep.h>.
(_dl_starting_up, _dl_starting_up_internal): New externs.
(_dl_debug_vdprintf): Only take dl_load_lock if not _dl_starting_up.
* sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/x86_64/sysdep.h (INTERNAL_SYSCALL,
INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO): New macros.
(INLINE_SYSCALL): Use that.
* sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h: Include
dl-sysdep.h.
(SYSCALL_ERROR_HANDLER): Define RTLD_PRIVATE_ERRNO variant.
(__INTERNAL_SYSCALL_STRING): Define.
* sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h: Include
dl-sysdep.h.
(SYSCALL_ERROR_HANDLER): Define RTLD_PRIVATE_ERRNO variant.
(__INTERNAL_SYSCALL_STRING): Define.
* sysdeps/unix/sysv/linux/sparc/sysdep.h (INLINE_SYSCALL): Pass
__SYSCALL_STRING to inline_syscall*.
(INTERNAL_SYSCALL, INTERNAL_SYSCALL_ERROR_P, INTERNAL_SYSCALL_ERRNO):
New macros.
(inline_syscall0, inline_syscall1, inline_syscall2, inline_syscall3,
inline_syscall4, inline_syscall5, inline_syscall6): Add string
argument.
--- libc/elf/dl-misc.c.jj 2002-10-11 16:24:32.000000000 +0200
+++ libc/elf/dl-misc.c 2002-10-24 15:57:23.000000000 +0200
@@ -30,6 +30,7 @@
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/uio.h>
+#include <sysdep.h>
#include <stdio-common/_itoa.h>
#include <bits/libc-lock.h>
@@ -80,6 +81,8 @@ _dl_sysdep_read_whole_file (const char *
return result;
}
+extern int _dl_starting_up;
+extern int _dl_starting_up_internal attribute_hidden;
/* Bare-bone printf implementation. This function only knows about
the formats and flags needed and can handle only up to 64 stripes in
@@ -251,9 +254,14 @@ _dl_debug_vdprintf (int fd, int tag_p, c
#elif RTLD_PRIVATE_ERRNO
/* We have to take this lock just to be sure we don't clobber the private
errno when it's being used by another thread that cares about it. */
- __libc_lock_lock_recursive (GL(dl_load_lock));
- __writev (fd, iov, niov);
- __libc_lock_unlock_recursive (GL(dl_load_lock));
+ if (__builtin_expect (INTUSE (_dl_starting_up), 0))
+ __writev (fd, iov, niov);
+ else
+ {
+ __libc_lock_lock_recursive (GL(dl_load_lock));
+ __writev (fd, iov, niov);
+ __libc_lock_unlock_recursive (GL(dl_load_lock));
+ }
#else
__writev (fd, iov, niov);
#endif
--- libc/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h.jj 2002-08-27 23:19:55.000000000 +0200
+++ libc/sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h 2002-10-24 16:32:25.000000000 +0200
@@ -119,24 +119,36 @@
#endif /* __ASSEMBLER__ */
#undef INLINE_SYSCALL
-#define INLINE_SYSCALL(name, nr, args...) \
- ({ \
- DECLARGS_##nr(args) \
- int err; \
- asm volatile ( \
- LOADARGS_##nr \
- "svc %b1\n\t" \
- "lr %0,%%r2\n\t" \
- : "=d" (err) \
- : "I" (__NR_##name) ASMFMT_##nr \
- : "memory", "cc", "2", "3", "4", "5", "6"); \
- if (err >= 0xfffff001) \
- { \
- __set_errno(-err); \
- err = 0xffffffff; \
- } \
+#define INLINE_SYSCALL(name, nr, args...) \
+ ({ \
+ unsigned int err = INTERNAL_SYSCALL (name, nr, args); \
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (err), 0)) \
+ { \
+ __set_errno (INTERNAL_SYSCALL_ERRNO (err)); \
+ err = 0xffffffff; \
+ } \
+ (int) err; })
+
+#undef INTERNAL_SYSCALL
+#define INTERNAL_SYSCALL(name, nr, args...) \
+ ({ \
+ DECLARGS_##nr(args) \
+ int err; \
+ asm volatile ( \
+ LOADARGS_##nr \
+ "svc %b1\n\t" \
+ "lr %0,%%r2\n\t" \
+ : "=d" (err) \
+ : "I" (__NR_##name) ASMFMT_##nr \
+ : "memory", "cc", "2", "3", "4", "5", "6"); \
(int) err; })
+#undef INTERNAL_SYSCALL_ERROR_P
+#define INTERNAL_SYSCALL_ERROR_P(val) ((unsigned int) (val) >= 0xfffff001u)
+
+#undef INTERNAL_SYSCALL_ERRNO
+#define INTERNAL_SYSCALL_ERRNO(val) (-(val))
+
#define DECLARGS_0()
#define DECLARGS_1(arg1) \
unsigned int gpr2 = (unsigned int) (arg1);
--- libc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h.jj 2002-08-27 23:19:55.000000000 +0200
+++ libc/sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h 2002-10-24 17:32:28.000000000 +0200
@@ -115,6 +115,17 @@
#undef INLINE_SYSCALL
#define INLINE_SYSCALL(name, nr, args...) \
({ \
+ unsigned int err = INTERNAL_SYSCALL (name, nr, args); \
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (err), 0)) \
+ { \
+ __set_errno (INTERNAL_SYSCALL_ERRNO (err)); \
+ err = -1; \
+ } \
+ (int) err; })
+
+#undef INTERNAL_SYSCALL
+#define INTERNAL_SYSCALL(name, nr, args...) \
+ ({ \
DECLARGS_##nr(args) \
int err; \
asm volatile ( \
@@ -124,13 +135,14 @@
: "=d" (err) \
: "I" (__NR_##name) ASMFMT_##nr \
: "memory", "cc", "2", "3", "4", "5", "6"); \
- if (err >= 0xfffff001) \
- { \
- __set_errno(-err); \
- err = -1; \
- } \
(int) err; })
+#undef INTERNAL_SYSCALL_ERROR_P
+#define INTERNAL_SYSCALL_ERROR_P(val) ((unsigned int) (val) >= 0xfffff001u)
+
+#undef INTERNAL_SYSCALL_ERRNO
+#define INTERNAL_SYSCALL_ERRNO(val) (-(val))
+
#define DECLARGS_0()
#define DECLARGS_1(arg1) \
unsigned long gpr2 = (unsigned long) (arg1);
--- libc/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h.jj 2002-04-25 22:02:29.000000000 +0200
+++ libc/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep.h 2002-10-24 17:17:09.000000000 +0200
@@ -22,6 +22,10 @@
#include <sysdeps/unix/sparc/sysdep.h>
+#ifdef IS_IN_rtld
+# include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
+#endif
+
#undef SYS_ify
#define SYS_ify(syscall_name) __NR_##syscall_name
@@ -50,25 +54,35 @@
#define LOC(name) .L##name
-#ifdef PIC
-#define SYSCALL_ERROR_HANDLER \
- .global C_SYMBOL_NAME(__errno_location); \
- .type C_SYMBOL_NAME(__errno_location),@function; \
- save %sp,-96,%sp; \
+#if RTLD_PRIVATE_ERRNO
+# define SYSCALL_ERROR_HANDLER \
+ .section .gnu.linkonce.t.__sparc.get_pic.l7,"ax",@progbits; \
+ .globl __sparc.get_pic.l7; \
+ .hidden __sparc.get_pic.l7; \
+ .type __sparc.get_pic.l7,@function; \
+__sparc.get_pic.l7: \
+ retl; \
+ add %o7, %l7, %l7; \
+ .previous; \
+ save %sp,-96,%sp; \
+ sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %l7; \
+ call __sparc.get_pic.l7; \
+ add %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7; \
+ ld [%l7 + errno], %l0; \
+ st %i0, [%l0]; \
+ jmpl %i7+8, %g0; \
+ restore %g0, -1, %o0;
+#else
+# define SYSCALL_ERROR_HANDLER \
+ .global __errno_location; \
+ .type __errno_location,@function; \
+ save %sp, -96, %sp; \
call __errno_location; \
nop; \
- st %i0,[%o0]; \
- jmpl %i7+8,%g0; \
- restore %g0,-1,%o0;
-#else
-#define SYSCALL_ERROR_HANDLER \
- save %sp,-96,%sp; \
- call __errno_location; \
- nop; \
- st %i0,[%o0]; \
- jmpl %i7+8,%g0; \
- restore %g0,-1,%o0;
-#endif /* PIC */
+ st %i0, [%o0]; \
+ jmpl %i7+8, %g0; \
+ restore %g0, -1, %o0;
+#endif
#define PSEUDO(name, syscall_name, args) \
.text; \
@@ -97,6 +111,12 @@
" restore %%g0, -1, %%o0;" \
".previous;"
+#define __INTERNAL_SYSCALL_STRING \
+ "ta 0x10;" \
+ "bcs,a 1f;" \
+ " sub %%g0, %%o0, %%o0;" \
+ "1:"
+
#define __SYSCALL_CLOBBERS "g2", "g3", "g4", "g5", "g7", \
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
"f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
--- libc/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h.jj 2001-08-23 18:51:33.000000000 +0200
+++ libc/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h 2002-10-24 17:21:44.000000000 +0200
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997.
@@ -22,6 +22,10 @@
#include <sysdeps/unix/sysdep.h>
+#ifdef IS_IN_rtld
+# include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
+#endif
+
#undef SYS_ify
#define SYS_ify(syscall_name) __NR_##syscall_name
@@ -43,13 +47,35 @@
C_LABEL(name); \
.type name,@function;
-#define SYSCALL_ERROR_HANDLER \
+#if RTLD_PRIVATE_ERRNO
+# define SYSCALL_ERROR_HANDLER \
+ .section .gnu.linkonce.t.__sparc64.get_pic.l7,"ax",@progbits; \
+ .globl __sparc64.get_pic.l7; \
+ .hidden __sparc64.get_pic.l7; \
+ .type __sparc64.get_pic.l7,@function; \
+__sparc64.get_pic.l7: \
+ retl; \
+ add %o7, %l7, %l7; \
+ .previous; \
save %sp, -192, %sp; \
- call __errno_location; \
- nop; \
- st %i0, [%o0]; \
+ sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %l7; \
+ call __sparc.get_pic.l7; \
+ add %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7; \
+ ldx [%l7 + errno], %l0; \
+ st %i0, [%l0]; \
jmpl %i7+8, %g0; \
- restore %g0, -1, %o0
+ restore %g0, -1, %o0;
+#else
+# define SYSCALL_ERROR_HANDLER \
+ .global __errno_location; \
+ .type __errno_location,@function; \
+ save %sp, -192, %sp; \
+ call __errno_location; \
+ nop; \
+ st %i0, [%o0]; \
+ jmpl %i7+8, %g0; \
+ restore %g0, -1, %o0;
+#endif
#define PSEUDO(name, syscall_name, args) \
.text; \
@@ -88,6 +114,12 @@
"restore %%g0, -1, %%o0;" \
"1:"
+#define __INTERNAL_SYSCALL_STRING \
+ "ta 0x6d;" \
+ "bcs,a,pt %%xcc, 1f;" \
+ " sub %%g0, %%o0, %%o0;" \
+ "1:"
+
#define __SYSCALL_CLOBBERS "g2", "g3", "g4", "g5", "g7", \
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
"f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
--- libc/sysdeps/unix/sysv/linux/sparc/sysdep.h.jj 2002-09-30 11:23:55.000000000 +0200
+++ libc/sysdeps/unix/sysv/linux/sparc/sysdep.h 2002-10-24 17:28:09.000000000 +0200
@@ -21,67 +21,78 @@
#define _LINUX_SPARC_SYSDEP_H 1
#undef INLINE_SYSCALL
-#define INLINE_SYSCALL(name, nr, args...) inline_syscall##nr(name, args)
+#define INLINE_SYSCALL(name, nr, args...) \
+ inline_syscall##nr(__SYSCALL_STRING, name, args)
-#define inline_syscall0(name,dummy...) \
+#undef INTERNAL_SYSCALL
+#define INTERNAL_SYSCALL(name, nr, args...) \
+ inline_syscall##nr(__INTERNAL_SYSCALL_STRING, name, args)
+
+#undef INTERNAL_SYSCALL_ERROR_P
+#define INTERNAL_SYSCALL_ERROR_P(val) ((unsigned long) (val) >= -515L)
+
+#undef INTERNAL_SYSCALL_ERRNO
+#define INTERNAL_SYSCALL_ERRNO(val) (-(val))
+
+#define inline_syscall0(string,name,dummy...) \
({ \
register long __o0 __asm__ ("o0"); \
register long __g1 __asm__ ("g1") = __NR_##name; \
- __asm __volatile (__SYSCALL_STRING : "=r" (__g1), "=r" (__o0) : \
+ __asm __volatile (string : "=r" (__g1), "=r" (__o0) : \
"0" (__g1) : \
__SYSCALL_CLOBBERS); \
__o0; \
})
-#define inline_syscall1(name,arg1) \
+#define inline_syscall1(string,name,arg1) \
({ \
register long __o0 __asm__ ("o0") = (long)(arg1); \
register long __g1 __asm__ ("g1") = __NR_##name; \
- __asm __volatile (__SYSCALL_STRING : "=r" (__g1), "=r" (__o0) : \
+ __asm __volatile (string : "=r" (__g1), "=r" (__o0) : \
"0" (__g1), "1" (__o0) : \
__SYSCALL_CLOBBERS); \
__o0; \
})
-#define inline_syscall2(name,arg1,arg2) \
+#define inline_syscall2(string,name,arg1,arg2) \
({ \
register long __o0 __asm__ ("o0") = (long)(arg1); \
register long __o1 __asm__ ("o1") = (long)(arg2); \
register long __g1 __asm__ ("g1") = __NR_##name; \
- __asm __volatile (__SYSCALL_STRING : "=r" (__g1), "=r" (__o0) : \
+ __asm __volatile (string : "=r" (__g1), "=r" (__o0) : \
"0" (__g1), "1" (__o0), "r" (__o1) : \
__SYSCALL_CLOBBERS); \
__o0; \
})
-#define inline_syscall3(name,arg1,arg2,arg3) \
+#define inline_syscall3(string,name,arg1,arg2,arg3) \
({ \
register long __o0 __asm__ ("o0") = (long)(arg1); \
register long __o1 __asm__ ("o1") = (long)(arg2); \
register long __o2 __asm__ ("o2") = (long)(arg3); \
register long __g1 __asm__ ("g1") = __NR_##name; \
- __asm __volatile (__SYSCALL_STRING : "=r" (__g1), "=r" (__o0) : \
+ __asm __volatile (string : "=r" (__g1), "=r" (__o0) : \
"0" (__g1), "1" (__o0), "r" (__o1), \
"r" (__o2) : \
__SYSCALL_CLOBBERS); \
__o0; \
})
-#define inline_syscall4(name,arg1,arg2,arg3,arg4) \
+#define inline_syscall4(string,name,arg1,arg2,arg3,arg4) \
({ \
register long __o0 __asm__ ("o0") = (long)(arg1); \
register long __o1 __asm__ ("o1") = (long)(arg2); \
register long __o2 __asm__ ("o2") = (long)(arg3); \
register long __o3 __asm__ ("o3") = (long)(arg4); \
register long __g1 __asm__ ("g1") = __NR_##name; \
- __asm __volatile (__SYSCALL_STRING : "=r" (__g1), "=r" (__o0) : \
+ __asm __volatile (string : "=r" (__g1), "=r" (__o0) : \
"0" (__g1), "1" (__o0), "r" (__o1), \
"r" (__o2), "r" (__o3) : \
__SYSCALL_CLOBBERS); \
__o0; \
})
-#define inline_syscall5(name,arg1,arg2,arg3,arg4,arg5) \
+#define inline_syscall5(string,name,arg1,arg2,arg3,arg4,arg5) \
({ \
register long __o0 __asm__ ("o0") = (long)(arg1); \
register long __o1 __asm__ ("o1") = (long)(arg2); \
@@ -89,14 +100,14 @@
register long __o3 __asm__ ("o3") = (long)(arg4); \
register long __o4 __asm__ ("o4") = (long)(arg5); \
register long __g1 __asm__ ("g1") = __NR_##name; \
- __asm __volatile (__SYSCALL_STRING : "=r" (__g1), "=r" (__o0) : \
+ __asm __volatile (string : "=r" (__g1), "=r" (__o0) : \
"0" (__g1), "1" (__o0), "r" (__o1), \
"r" (__o2), "r" (__o3), "r" (__o4) : \
__SYSCALL_CLOBBERS); \
__o0; \
})
-#define inline_syscall6(name,arg1,arg2,arg3,arg4,arg5,arg6) \
+#define inline_syscall6(string,name,arg1,arg2,arg3,arg4,arg5,arg6) \
({ \
register long __o0 __asm__ ("o0") = (long)(arg1); \
register long __o1 __asm__ ("o1") = (long)(arg2); \
@@ -105,7 +116,7 @@
register long __o4 __asm__ ("o4") = (long)(arg5); \
register long __o5 __asm__ ("o5") = (long)(arg6); \
register long __g1 __asm__ ("g1") = __NR_##name; \
- __asm __volatile (__SYSCALL_STRING : "=r" (__g1), "=r" (__o0) : \
+ __asm __volatile (string : "=r" (__g1), "=r" (__o0) : \
"0" (__g1), "1" (__o0), "r" (__o1), \
"r" (__o2), "r" (__o3), "r" (__o4), \
"r" (__o5) : \
--- libc/sysdeps/unix/sysv/linux/x86_64/sysdep.h.jj 2002-10-17 13:34:36.000000000 +0200
+++ libc/sysdeps/unix/sysv/linux/x86_64/sysdep.h 2002-10-24 16:34:26.000000000 +0200
@@ -186,6 +186,17 @@
#undef INLINE_SYSCALL
#define INLINE_SYSCALL(name, nr, args...) \
({ \
+ unsigned long resultvar = INTERNAL_SYSCALL (name, nr, args); \
+ if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar), 0)) \
+ { \
+ __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar)); \
+ resultvar = (unsigned long) -1; \
+ } \
+ (long) resultvar; })
+
+#undef INTERNAL_SYSCALL
+#define INTERNAL_SYSCALL(name, nr, args...) \
+ ({ \
unsigned long resultvar; \
LOAD_ARGS_##nr (args) \
asm volatile ( \
@@ -193,13 +204,14 @@
"syscall\n\t" \
: "=a" (resultvar) \
: "i" (__NR_##name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \
- if (resultvar >= (unsigned long) -4095) \
- { \
- __set_errno (-resultvar); \
- resultvar = (unsigned long) -1; \
- } \
(long) resultvar; })
+#undef INTERNAL_SYSCALL_ERROR_P
+#define INTERNAL_SYSCALL_ERROR_P(val) ((unsigned long) (val) >= -4095L)
+
+#undef INTERNAL_SYSCALL_ERRNO
+#define INTERNAL_SYSCALL_ERRNO(val) (-(val))
+
#define LOAD_ARGS_0()
#define ASM_ARGS_0
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix LD_DEBUG=statistics
2002-10-24 12:03 [PATCH] Fix LD_DEBUG=statistics Jakub Jelinek
@ 2002-10-25 3:38 ` Roland McGrath
0 siblings, 0 replies; 4+ messages in thread
From: Roland McGrath @ 2002-10-25 3:38 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Ulrich Drepper, Glibc hackers
Thanks, I'm putting that in with a couple of cosmetic cleanups.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix LD_DEBUG=statistics
2004-11-13 18:01 Jakub Jelinek
@ 2004-11-13 18:58 ` Ulrich Drepper
0 siblings, 0 replies; 4+ messages in thread
From: Ulrich Drepper @ 2004-11-13 18:58 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Glibc hackers
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Applied after fixing the typo in the REL code.
- --
⧠Ulrich Drepper ⧠Red Hat, Inc. ⧠444 Castro St ⧠Mountain View, CA â
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
iD8DBQFBlllD2ijCOnn/RHQRAltLAJ9gwMtJZ/aTx40nOma5tge9g+MG8ACgx7jS
yU9ZznEDyoLti8RDEoDZNMY=
=WXGf
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] Fix LD_DEBUG=statistics
@ 2004-11-13 18:01 Jakub Jelinek
2004-11-13 18:58 ` Ulrich Drepper
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2004-11-13 18:01 UTC (permalink / raw)
To: Ulrich Drepper; +Cc: Glibc hackers
Hi!
LD_DEBUG=statistics someprog leads to segfaults with current glibc.
The problem is that print_statistics doesn't check for NULL _ns_loaded
namespaces and happily dereferences it.
While looking into it, I have noticed the num_relative_relocations
computation doesn't match what do-rel.h is actually doing, particularly
on !ELF_MACHINE_REL_RELATIVE RELA architectures it is processing relative
relocations even if l_addr == 0, but the library is not prelinked.
2004-11-13 Jakub Jelinek <jakub@redhat.com>
* elf/rtld.c (print_statistics): Avoid segfaults if not all namespaces
are used. Fix computation of num_relative_relocations on RELA
architectures other than IA-64 and Alpha.
--- libc/elf/rtld.c.jj 2004-11-09 12:26:41.000000000 +0100
+++ libc/elf/rtld.c 2004-11-13 18:56:32.574028935 +0100
@@ -2336,19 +2336,29 @@ print_statistics (hp_timing_t *rtld_tota
unsigned long int num_relative_relocations = 0;
for (Lmid_t ns = 0; ns < DL_NNS; ++ns)
{
+ if (GL(dl_ns)[ns]._ns_loaded == NULL)
+ continue;
+
struct r_scope_elem *scope = &GL(dl_ns)[ns]._ns_loaded->l_searchlist;
for (unsigned int i = 0; i < scope->r_nlist; i++)
{
struct link_map *l = scope->r_list [i];
- if (!l->l_addr)
- continue;
-
- if (l->l_info[VERSYMIDX (DT_RELCOUNT)])
+ if (l->l_addr != 0 && l->l_info[VERSYMIDX (DT_RELCOUNT)])
num_relative_relocations
+= l->l_info[VERSYMIDX (DT_RELCOUNT)]->d_un.d_val;
- if (l->l_info[VERSYMIDX (DT_RELACOUNT)])
+#ifndef ELF_MACHINE_REL_RELATIVE
+ /* Relative relocations are processed on these architectures if
+ library is loaded to different address than p_vaddr or
+ if not prelinked. */
+ if ((l->l_addr != 0 || !map->l_info[VALIDX(DT_GNU_PRELINKED)])
+ && l->l_info[VERSYMIDX (DT_RELACOUNT)])
+#else
+ /* On e.g. IA-64 or Alpha, relative relocations are processed
+ only if library is loaded to different address than p_vaddr. */
+ if (l->l_addr != 0 && l->l_info[VERSYMIDX (DT_RELACOUNT)])
+#endif
num_relative_relocations
+= l->l_info[VERSYMIDX (DT_RELACOUNT)]->d_un.d_val;
}
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-11-13 18:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-24 12:03 [PATCH] Fix LD_DEBUG=statistics Jakub Jelinek
2002-10-25 3:38 ` Roland McGrath
2004-11-13 18:01 Jakub Jelinek
2004-11-13 18:58 ` Ulrich Drepper
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).