From 1dc333167a3c4a3ac024082d3163cff84f6d7ca0 Mon Sep 17 00:00:00 2001 From: tmm Date: Fri, 18 Jun 2004 02:01:37 +0000 Subject: [PATCH] Fix the problem that surfaced with the new binutils import on sparc64 (and that is for now being worked around by a binutils patch). The rtld code tested &_DYNAMIC against 0 to see whether rtld itself was built as PIC or not. While the sparc64 MD code did not rely on the preset value of the GOT slot for _DYNAMIC any more due to previous binutils changes, it still used to not be 0, so that this check did work. The new binutils do however initialize this slot with 0. As a consequence, rtld would not properly initialize itself and crash. Fix that by introducing a new macro, RTLD_IS_DYNAMIC, to take the role of this test. For sparc64, it is implemented using the rtld_dynamic() code that was already there. If an architecture does not provide its own implementation, we default to the old check. While being there, mark _DYNAMIC as a weak symbol in the sparc64 rtld_start.S. This is needed in the LDSCRIPT case, which is however not currently supported for want of an actual ldscript. Sanity checked with md5 on alpha, amd64, i386 and ia64. --- libexec/rtld-elf/rtld.c | 5 ++++- libexec/rtld-elf/sparc64/rtld_machdep.h | 4 +++- libexec/rtld-elf/sparc64/rtld_start.S | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index cd8385d1d74d..62ca650116a3 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -162,6 +162,9 @@ static Elf_Sym sym_zero; /* For resolving undefined weak refs. */ extern Elf_Dyn _DYNAMIC; #pragma weak _DYNAMIC +#ifndef RTLD_IS_DYNAMIC +#define RTLD_IS_DYNAMIC() (&_DYNAMIC != NULL) +#endif /* * These are the functions the dynamic linker exports to application @@ -1008,7 +1011,7 @@ init_rtld(caddr_t mapbase) #ifdef PIC objtmp.relocbase = mapbase; #endif - if (&_DYNAMIC != 0) { + if (RTLD_IS_DYNAMIC()) { objtmp.dynamic = rtld_dynamic(&objtmp); digest_dynamic(&objtmp, 1); assert(objtmp.needed == NULL); diff --git a/libexec/rtld-elf/sparc64/rtld_machdep.h b/libexec/rtld-elf/sparc64/rtld_machdep.h index d92055c71381..27276eeb860f 100644 --- a/libexec/rtld-elf/sparc64/rtld_machdep.h +++ b/libexec/rtld-elf/sparc64/rtld_machdep.h @@ -37,7 +37,9 @@ struct Struct_Obj_Entry; /* Return the address of the .dynamic section in the dynamic linker. */ -Elf_Dyn *rtld_dynamic(const struct Struct_Obj_Entry *); +Elf_Dyn *rtld_dynamic_addr(); +#define rtld_dynamic(obj) rtld_dynamic_addr() +#define RTLD_IS_DYNAMIC() (rtld_dynamic_addr() != NULL) Elf_Addr reloc_jmpslot(Elf_Addr *, Elf_Addr, const struct Struct_Obj_Entry *, diff --git a/libexec/rtld-elf/sparc64/rtld_start.S b/libexec/rtld-elf/sparc64/rtld_start.S index 146c6314fc63..58bdd1bbc944 100644 --- a/libexec/rtld-elf/sparc64/rtld_start.S +++ b/libexec/rtld-elf/sparc64/rtld_start.S @@ -71,8 +71,9 @@ END(.rtld_start) * Find the address of _DYNAMIC by disassembling a call instruction to it. * Binutils may not fill in the GOT as expected on other architectures. */ +.weak _DYNAMIC -ENTRY(rtld_dynamic) +ENTRY(rtld_dynamic_addr) save %sp, -CCFSZ, %sp call 1f nop @@ -82,7 +83,7 @@ ENTRY(rtld_dynamic) sra %o0, 0, %o0 ret restore %o0, %o7, %o0 -END(rtld_dynamic) +END(rtld_dynamic_addr) /* * We have two separate entry points to the runtime linker.