From 9cba52f0aedbb95671e8a14e3fd5ff98381ff2b0 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Thu, 8 Aug 2002 14:35:49 +0000 Subject: Patch from Stefan Allius and Edie C. Dost to add SuperH shared library support. This also adds some cleaner error handling, which I (Erik) then ported over to x86 and arm. In addition Stefan added the following fixes: - in hash.c was the lvalue handling of global library functions wrong. To fix this I had to change the prototype of _dl_find_hash. (==> TIS and ELF spec. Vers. 1.2) - in ldso.c was the order of the .init sections calls wrong. Before we call the initialization code of a library we have to check that all dependend libraries are already initialized. This can easily made by calling it in the revers loading order. For this I added a previous pointer chain. - in ldso.c the ELF magics wasn't checked fo PPC, MIPS and SH architecture --- ldso/ldso/Makefile | 34 ++- ldso/ldso/arm/boot1_arch.h | 2 +- ldso/ldso/arm/dl-startup.h | 2 +- ldso/ldso/arm/elfinterp.c | 468 +++++++++++++++++++++++--------------- ldso/ldso/dl-elf.c | 96 +++++--- ldso/ldso/dl-hash.c | 82 ++++--- ldso/ldso/hash.c | 82 ++++--- ldso/ldso/i386/boot1_arch.h | 2 +- ldso/ldso/i386/dl-startup.h | 2 +- ldso/ldso/i386/elfinterp.c | 494 +++++++++++++++++++++++++---------------- ldso/ldso/ld_hash.h | 26 ++- ldso/ldso/ld_string.h | 26 ++- ldso/ldso/ld_syscall.h | 10 +- ldso/ldso/ldso.c | 288 ++++++++++++++++-------- ldso/ldso/m68k/boot1_arch.h | 2 +- ldso/ldso/m68k/dl-startup.h | 2 +- ldso/ldso/m68k/elfinterp.c | 60 ++--- ldso/ldso/mips/boot1_arch.h | 2 +- ldso/ldso/mips/dl-startup.h | 2 +- ldso/ldso/mips/elfinterp.c | 69 +++--- ldso/ldso/powerpc/boot1_arch.h | 2 +- ldso/ldso/powerpc/dl-startup.h | 2 +- ldso/ldso/powerpc/elfinterp.c | 56 +++-- ldso/ldso/readelflib1.c | 96 +++++--- ldso/ldso/sh/boot1_arch.h | 23 ++ ldso/ldso/sh/dl-startup.h | 23 ++ ldso/ldso/sh/dl-syscalls.h | 7 + ldso/ldso/sh/dl-sysdep.h | 145 ++++++++++++ ldso/ldso/sh/elfinterp.c | 416 ++++++++++++++++++++++++++++++++++ ldso/ldso/sh/ld_syscalls.h | 7 + ldso/ldso/sh/ld_sysdep.h | 145 ++++++++++++ ldso/ldso/sh/resolve.S | 69 ++++++ ldso/ldso/sparc/boot1_arch.h | 2 +- ldso/ldso/sparc/dl-startup.h | 2 +- ldso/ldso/sparc/elfinterp.c | 56 +++-- 35 files changed, 2065 insertions(+), 737 deletions(-) create mode 100644 ldso/ldso/sh/boot1_arch.h create mode 100644 ldso/ldso/sh/dl-startup.h create mode 100644 ldso/ldso/sh/dl-syscalls.h create mode 100644 ldso/ldso/sh/dl-sysdep.h create mode 100644 ldso/ldso/sh/elfinterp.c create mode 100644 ldso/ldso/sh/ld_syscalls.h create mode 100644 ldso/ldso/sh/ld_sysdep.h create mode 100644 ldso/ldso/sh/resolve.S (limited to 'ldso') diff --git a/ldso/ldso/Makefile b/ldso/ldso/Makefile index 4100f82ff..ff1d9ea48 100644 --- a/ldso/ldso/Makefile +++ b/ldso/ldso/Makefile @@ -31,13 +31,35 @@ LDSO_FULLNAME=ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so # (i.e. where the shared library loader does all the heavy lifting) # Since this currently only saves about 300 bytes, I'm going to leave # it enabled... -XXFLAGS+= -DDL_TRACE +XXFLAGS+= -DLD_TRACE -# Enable this to enable debugging output from ld.so -#XXFLAGS+= -DDL_DEBUG -#XXFLAGS+= -DDL_DEBUG_SYMBOLS -#Enable this to never actually fixup symbols so you can watch each call... -#XXFLAGS+= -DDL_NEVER_FIXUP_SYMBOLS +# Enable this to enable all the code needed for debugging the runtime +# linking of an application using the LD_DEBUG environment variable: +# LD_DEBUG=token1,token2,.. prog +# enables diagnostics to the stderr. +# For now there are these tokens possible: +# bindings displays the resolve processing (function calls); detail shows the relocation patch +# detail provide more information for some options +# move display copy processings +# reloc display relocation processing; detail shows the relocation patch +# symbols display symbol table processing +# +# The additional environment variable: +# LD_DEBUG_OUTPUT=file +# redirects the diagnostics to an output file created using +# the specified name and the process id as a suffix. +# +# try this +# $ LD_DEBUG=binding,move,symbols,reloc,detail LD_DEBUG_OUTPUT=appname ./appname +# +#XXFLAGS+= -DSUPPORT_LD_DEBUG + +# Enable this for the very very early debugging. Really only useful +# for people porting to new architectures. +#XXFLAGS+= -DLD_DEBUG + +# Enable this to never actually fixup symbols... +#XXFLAGS+= -DLD_NEVER_FIXUP_SYMBOLS XXFLAGS+=-DUCLIBC_TARGET_PREFIX=\"$(TARGET_PREFIX)\" \ -DUCLIBC_DEVEL_PREFIX=\"$(DEVEL_PREFIX)\" \ diff --git a/ldso/ldso/arm/boot1_arch.h b/ldso/ldso/arm/boot1_arch.h index e4c9bafb7..af9acc22c 100644 --- a/ldso/ldso/arm/boot1_arch.h +++ b/ldso/ldso/arm/boot1_arch.h @@ -20,7 +20,7 @@ _dl_boot: "); #define _dl_boot _dl_boot2 -#define DL_BOOT(X) static void * __attribute__ ((unused)) _dl_boot (X) +#define LD_BOOT(X) static void * __attribute__ ((unused)) _dl_boot (X) /* It seems ARM needs an offset here */ diff --git a/ldso/ldso/arm/dl-startup.h b/ldso/ldso/arm/dl-startup.h index e4c9bafb7..af9acc22c 100644 --- a/ldso/ldso/arm/dl-startup.h +++ b/ldso/ldso/arm/dl-startup.h @@ -20,7 +20,7 @@ _dl_boot: "); #define _dl_boot _dl_boot2 -#define DL_BOOT(X) static void * __attribute__ ((unused)) _dl_boot (X) +#define LD_BOOT(X) static void * __attribute__ ((unused)) _dl_boot (X) /* It seems ARM needs an offset here */ diff --git a/ldso/ldso/arm/elfinterp.c b/ldso/ldso/arm/elfinterp.c index 39f29d634..dd68324a5 100644 --- a/ldso/ldso/arm/elfinterp.c +++ b/ldso/ldso/arm/elfinterp.c @@ -1,39 +1,102 @@ -/* Run an ELF binary on a linux system. - - Copyright (C) 1993, Eric Youngdale. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef VERBOSE_DLINKER -#define VERBOSE_DLINKER -#endif -#ifdef VERBOSE_DLINKER -static const char *_dl_reltypes[] = - { "R_ARM_NONE", "R_ARM_PC24", "R_ARM_ABS32", "R_ARM_REL32", - "R_ARM_PC13", "R_ARM_ABS16", "R_ARM_ABS12", "R_ARM_THM_ABS5", - "R_ARM_ABS8", "R_ARM_SBREL32", "R_ARM_THM_PC22", "R_ARM_THM_PC8", - "R_ARM_AMP_VCALL9", "R_ARM_SWI24", "R_ARM_THM_SWI8", "R_ARM_XPC25", - "R_ARM_THM_XPC22", "R_ARM_COPY", "R_ARM_GLOB_DAT", "R_ARM_JUMP_SLOT", - "R_ARM_RELATIVE", "R_ARM_GOTOFF", "R_ARM_GOTPC", "R_ARM_GOT32", - "R_ARM_PLT32", "R_ARM_ALU_PCREL_7_0", "R_ARM_ALU_PCREL_15_8", - "R_ARM_ALU_PCREL_23_15", "R_ARM_LDR_SBREL_11_0", "R_ARM_ALU_SBREL_19_12", - "R_ARM_ALU_SBREL_27_20", "R_ARM_GNU_VTENTRY", "R_ARM_GNU_VTINHERIT", - "R_ARM_THM_PC11", "R_ARM_THM_PC9", "R_ARM_RXPC25", "R_ARM_RSBREL32", - "R_ARM_THM_RPC22", "R_ARM_RREL32", "R_ARM_RABS22", "R_ARM_RPC24", - "R_ARM_RBASE", "R_ARM_NUM" +/* vi: set sw=4 ts=4: */ +/* ARM ELF shared library loader suppport + * + * Copyright (C) 2001-2002, Erik Andersen + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the above contributors may not be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined (SUPPORT_LD_DEBUG) || defined (LD_DEBUG_SYMBOLS) +static const char *_dl_reltypes_tab[] = + [0] "R_ARM_NONE", "R_ARM_PC24", "R_ARM_ABS32", "R_ARM_REL32", + [4] "R_ARM_PC13", "R_ARM_ABS16", "R_ARM_ABS12", "R_ARM_THM_ABS5", + [8] "R_ARM_ABS8", "R_ARM_SBREL32","R_ARM_THM_PC22", "R_ARM_THM_PC8", + [12] "R_ARM_AMP_VCALL9", "R_ARM_SWI24", "R_ARM_THM_SWI8", "R_ARM_XPC25", + [16] "R_ARM_THM_XPC22", + [20] "R_ARM_COPY", "R_ARM_GLOB_DAT","R_ARM_JUMP_SLOT", "R_ARM_RELATIVE", + [24] "R_ARM_GOTOFF", "R_ARM_GOTPC", "R_ARM_GOT32", "R_ARM_PLT32", + [32] "R_ARM_ALU_PCREL_7_0","R_ARM_ALU_PCREL_15_8","R_ARM_ALU_PCREL_23_15","R_ARM_LDR_SBREL_11_0", + [36] "R_ARM_ALU_SBREL_19_12","R_ARM_ALU_SBREL_27_20", + [100] "R_ARM_GNU_VTENTRY","R_ARM_GNU_VTINHERIT","R_ARM_THM_PC11","R_ARM_THM_PC9", + [249] "R_ARM_RXPC25", "R_ARM_RSBREL32", "R_ARM_THM_RPC22", "R_ARM_RREL32", + [253] "R_ARM_RABS22", "R_ARM_RPC24", "R_ARM_RBASE", }; + +static const char * +_dl_reltypes(int type) +{ + static char buf[22]; + const char *str; + + if (type >= (sizeof (_dl_reltypes_tab)/sizeof(_dl_reltypes_tab[0])) || + NULL == (str = _dl_reltypes_tab[type])) + { + str =_dl_simple_ltoa( buf, (unsigned long)(type)); + } + return str; +} + +static +void debug_sym(Elf32_Sym *symtab,char *strtab,int symtab_index) +{ + if(_dl_debug_symbols) + { + if(symtab_index){ + _dl_dprintf(_dl_debug_file, "\n%s\tvalue=%x\tsize=%x\tinfo=%x\tother=%x\tshndx=%x", + strtab + symtab[symtab_index].st_name, + symtab[symtab_index].st_value, + symtab[symtab_index].st_size, + symtab[symtab_index].st_info, + symtab[symtab_index].st_other, + symtab[symtab_index].st_shndx); + } + } +} + +static void debug_reloc(Elf32_Sym *symtab,char *strtab, ELF_RELOC *rpnt) +{ + if(_dl_debug_reloc) + { + int symtab_index; + const char *sym; + symtab_index = ELF32_R_SYM(rpnt->r_info); + sym = symtab_index ? strtab + symtab[symtab_index].st_name : "sym=0x0"; + +#ifdef ELF_USES_RELOCA + _dl_dprintf(_dl_debug_file, "\n%s\toffset=%x\taddend=%x %s", + _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)), + rpnt->r_offset, + rpnt->r_addend, + sym); +#else + _dl_dprintf(_dl_debug_file, "\n%s\toffset=%x %s", + _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)), + rpnt->r_offset, + sym); +#endif + } +} #endif /* Program to load an ELF binary on a linux system, and run it. @@ -47,22 +110,21 @@ static const char *_dl_reltypes[] = a more than adequate job of explaining everything required to get this working. */ - extern int _dl_linux_resolve(void); unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) { int reloc_type; - Elf32_Rel *this_reloc; + ELF_RELOC *this_reloc; char *strtab; Elf32_Sym *symtab; - Elf32_Rel *rel_addr; + ELF_RELOC *rel_addr; int symtab_index; char *new_addr; char **got_addr; unsigned long instr_addr; - rel_addr = (Elf32_Rel *) (tpnt->dynamic_info[DT_JMPREL] + tpnt->loadaddr); + rel_addr = (ELF_RELOC *) (tpnt->dynamic_info[DT_JMPREL] + tpnt->loadaddr); this_reloc = rel_addr + (reloc_entry >> 3); reloc_type = ELF32_R_TYPE(this_reloc->r_info); @@ -71,92 +133,114 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) symtab = (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr); strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr); + if (reloc_type != R_ARM_JUMP_SLOT) { - _dl_dprintf(2, "%s: Incorrect relocation type in jump relocations\n", - _dl_progname); - _dl_exit(1); + _dl_dprintf(2, "%s: Incorrect relocation type in jump relocations\n", + _dl_progname); + _dl_exit(1); }; - + /* Address of jump instruction to fix up */ instr_addr = ((unsigned long) this_reloc->r_offset + - (unsigned long) tpnt->loadaddr); + (unsigned long) tpnt->loadaddr); got_addr = (char **) instr_addr; -#ifdef DL_DEBUG_SYMBOLS - _dl_dprintf(2, "Resolving symbol %s\n", - strtab + symtab[symtab_index].st_name); -#endif - /* Get the address of the GOT entry */ new_addr = _dl_find_hash(strtab + symtab[symtab_index].st_name, - tpnt->symbol_scope, tpnt, 0); + tpnt->symbol_scope, tpnt, resolver); if (!new_addr) { _dl_dprintf(2, "%s: can't resolve symbol '%s'\n", _dl_progname, strtab + symtab[symtab_index].st_name); _dl_exit(1); }; -#ifdef DL_NEVER_FIXUP_SYMBOLS - if ((unsigned long) got_addr < 0x40000000) { - _dl_dprintf(2, "Calling library function: %s\n", +#if defined (SUPPORT_LD_DEBUG) || defined (LD_NEVER_FIXUP_SYMBOLS) + if ((unsigned long) got_addr < 0x40000000) + { +#ifndef SUPPORT_LD_DEBUG + if (_dl_debug_bindings) + { + _dl_dprintf(_dl_debug_file, "\nresolve function: %s", strtab + symtab[symtab_index].st_name); + if(_dl_debug_detail) _dl_dprintf(_dl_debug_file, "\tpatch %x ==> %x @ %x", *got_addr, new_addr, got_addr); + } +#endif +#ifndef LD_NEVER_FIXUP_SYMBOLS + *got_addr = new_addr; +#endif } else { - *got_addr = new_addr; + *got_addr = new_addr; } #else *got_addr = new_addr; #endif + return (unsigned long) new_addr; } -void _dl_parse_lazy_relocation_information(struct elf_resolve *tpnt, - unsigned long rel_addr, unsigned long rel_size, int type) +static int +_dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope, + unsigned long rel_addr, unsigned long rel_size, + int (*reloc_fnc) (struct elf_resolve *tpnt, struct dyn_elf *scope, + ELF_RELOC *rpnt, Elf32_Sym *symtab, char *strtab)) { int i; char *strtab; - int reloc_type; - int symtab_index; + int goof = 0; Elf32_Sym *symtab; - Elf32_Rel *rpnt; - unsigned long *reloc_addr; - + ELF_RELOC *rpnt; + int symtab_index; /* Now parse the relocation information */ - rpnt = (Elf32_Rel *) (rel_addr + tpnt->loadaddr); - rel_size = rel_size / sizeof(Elf32_Rel); - symtab = - (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr); + rpnt = (ELF_RELOC *) (rel_addr + tpnt->loadaddr); + rel_size = rel_size / sizeof(ELF_RELOC); + + symtab = (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr); strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr); - for (i = 0; i < rel_size; i++, rpnt++) { - reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); - reloc_type = ELF32_R_TYPE(rpnt->r_info); + for (i = 0; i < rel_size; i++, rpnt++) { + int res; + symtab_index = ELF32_R_SYM(rpnt->r_info); - + /* When the dynamic linker bootstrapped itself, it resolved some symbols. Make sure we do not do them again */ if (!symtab_index && tpnt->libtype == program_interpreter) continue; if (symtab_index && tpnt->libtype == program_interpreter && - _dl_symbol(strtab + symtab[symtab_index].st_name)) + _dl_symbol(strtab + symtab[symtab_index].st_name)) continue; - switch (reloc_type) { - case R_ARM_NONE: - break; - case R_ARM_JUMP_SLOT: - *reloc_addr += (unsigned long) tpnt->loadaddr; - break; - default: - _dl_dprintf(2, "%s: (LAZY) can't handle reloc type ", - _dl_progname); -#ifdef VERBOSE_DLINKER - _dl_dprintf(2, "%s ", _dl_reltypes[reloc_type]); +#if defined (SUPPORT_LD_DEBUG) || defined (LD_DEBUG_SYMBOLS) + debug_sym(symtab,strtab,symtab_index); + debug_reloc(symtab,strtab,rpnt); #endif - if (symtab_index) - _dl_dprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name); - _dl_exit(1); - }; - }; + + res = reloc_fnc (tpnt, scope, rpnt, symtab, strtab); + + if (res==0) continue; + + _dl_dprintf(2, "\n%s: ",_dl_progname); + + if (symtab_index) + _dl_dprintf(2, "symbol '%s': ", strtab + symtab[symtab_index].st_name); + + if (res <0) + { + int reloc_type = ELF32_R_TYPE(rpnt->r_info); +#if defined (SUPPORT_LD_DEBUG) + _dl_dprintf(2, "can't handle reloc type %s\n ", _dl_reltypes(reloc_type)); +#else + _dl_dprintf(2, "can't handle reloc type %x\n", reloc_type); +#endif + _dl_exit(-res); + } + else if (res >0) + { + _dl_dprintf(2, "can't resolve symbol '%s'\n"); + goof += res; + } + } + return goof; } static unsigned long @@ -183,58 +267,40 @@ fix_bad_pc24 (unsigned long *const reloc_addr, unsigned long value) return (unsigned long)fix_address; } - -int _dl_parse_relocation_information(struct elf_resolve *tpnt, - unsigned long rel_addr, unsigned long rel_size, int type) +static int +_dl_do_reloc (struct elf_resolve *tpnt,struct dyn_elf *scope, + ELF_RELOC *rpnt, Elf32_Sym *symtab, char *strtab) { - int i; - char *strtab; int reloc_type; - int goof = 0; - Elf32_Sym *symtab; - Elf32_Rel *rpnt; + int symtab_index; unsigned long *reloc_addr; unsigned long symbol_addr; - int symtab_index; - - /* Now parse the relocation information */ + int goof = 0; - rpnt = (Elf32_Rel *) (rel_addr + tpnt->loadaddr); - rel_size = rel_size / sizeof(Elf32_Rel); + reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); + reloc_type = ELF32_R_TYPE(rpnt->r_info); + symtab_index = ELF32_R_SYM(rpnt->r_info); + symbol_addr = 0; - symtab = (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr); - strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr); + if (symtab_index) { - for (i = 0; i < rel_size; i++, rpnt++) { - reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); - reloc_type = ELF32_R_TYPE(rpnt->r_info); - symtab_index = ELF32_R_SYM(rpnt->r_info); - symbol_addr = 0; + symbol_addr = (unsigned long) _dl_find_hash(strtab + symtab[symtab_index].st_name, + scope, (reloc_type == R_ARM_JUMP_SLOT ? tpnt : NULL), symbolrel); - if (!symtab_index && tpnt->libtype == program_interpreter) - continue; - - if (symtab_index) { - - if (tpnt->libtype == program_interpreter && - _dl_symbol(strtab + symtab[symtab_index].st_name)) - continue; - - symbol_addr = (unsigned long) _dl_find_hash(strtab + symtab[symtab_index].st_name, - tpnt->symbol_scope, - (reloc_type == R_ARM_JUMP_SLOT ? tpnt : NULL), 0); - - /* - * We want to allow undefined references to weak symbols - this might - * have been intentional. We should not be linking local symbols - * here, so all bases should be covered. - */ - if (!symbol_addr && ELF32_ST_BIND(symtab[symtab_index].st_info) == STB_GLOBAL) { - _dl_dprintf(2, "%s: can't resolve symbol '%s'\n", - _dl_progname, strtab + symtab[symtab_index].st_name); - goof++; - } + /* + * We want to allow undefined references to weak symbols - this might + * have been intentional. We should not be linking local symbols + * here, so all bases should be covered. + */ + if (!symbol_addr && ELF32_ST_BIND(symtab[symtab_index].st_info) == STB_GLOBAL) { + goof++; } + } + +#if defined (SUPPORT_LD_DEBUG) + { + unsigned long old_val = *reloc_addr; +#endif switch (reloc_type) { case R_ARM_NONE: break; @@ -286,19 +352,50 @@ int _dl_parse_relocation_information(struct elf_resolve *tpnt, #endif break; default: - _dl_dprintf(2, "%s: can't handle reloc type ", _dl_progname); -#ifdef VERBOSE_DLINKER - _dl_dprintf(2, "%s ", _dl_reltypes[reloc_type]); + return -1; /*call _dl_exit(1) */ + } +#if defined (SUPPORT_LD_DEBUG) + if(_dl_debug_reloc && _dl_debug_detail) + _dl_dprintf(_dl_debug_file, "\tpatch: %x ==> %x @ %x", old_val, *reloc_addr, reloc_addr); + } + #endif - if (symtab_index) - _dl_dprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name); - _dl_exit(1); - }; - }; return goof; } +static int +_dl_do_lazy_reloc (struct elf_resolve *tpnt, struct dyn_elf *scope, + ELF_RELOC *rpnt, Elf32_Sym *symtab, char *strtab) +{ + int reloc_type; + unsigned long *reloc_addr; + + reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); + reloc_type = ELF32_R_TYPE(rpnt->r_info); + +#if defined (SUPPORT_LD_DEBUG) + { + unsigned long old_val = *reloc_addr; +#endif + switch (reloc_type) { + case R_ARM_NONE: + break; + case R_ARM_JUMP_SLOT: + *reloc_addr += (unsigned long) tpnt->loadaddr; + break; + default: + return -1; /*call _dl_exit(1) */ + } +#if defined (SUPPORT_LD_DEBUG) + if(_dl_debug_reloc && _dl_debug_detail) + _dl_dprintf(_dl_debug_file, "\tpatch: %x ==> %x @ %x", old_val, *reloc_addr, reloc_addr); + } + +#endif + return 0; + +} /* This is done as a separate step, because there are cases where information is first copied and later initialized. This results in @@ -308,59 +405,60 @@ int _dl_parse_relocation_information(struct elf_resolve *tpnt, /* No, there are cases where the SVr4 linker fails to emit COPY relocs at all */ - -int _dl_parse_copy_information(struct dyn_elf *xpnt, unsigned long rel_addr, - unsigned long rel_size, int type) +static int +_dl_do_copy (struct elf_resolve *tpnt, struct dyn_elf *scope, + ELF_RELOC *rpnt, Elf32_Sym *symtab, char *strtab) { - int i; - char *strtab; - int reloc_type; - int goof = 0; - Elf32_Sym *symtab; - Elf32_Rel *rpnt; + int reloc_type; + int symtab_index; unsigned long *reloc_addr; unsigned long symbol_addr; - struct elf_resolve *tpnt; - int symtab_index; - - /* Now parse the relocation information */ + int goof = 0; + + reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); + reloc_type = ELF32_R_TYPE(rpnt->r_info); + if (reloc_type != R_ARM_COPY) + return 0; + symtab_index = ELF32_R_SYM(rpnt->r_info); + symbol_addr = 0; + + if (symtab_index) { + + symbol_addr = (unsigned long) _dl_find_hash(strtab + + symtab[symtab_index].st_name, scope, + NULL, copyrel); + if (!symbol_addr) goof++; + } + if (!goof) { +#if defined (SUPPORT_LD_DEBUG) + if(_dl_debug_move) + _dl_dprintf(_dl_debug_file,"\n%s move %x bytes from %x to %x", + strtab + symtab[symtab_index].st_name, + symtab[symtab_index].st_size, + symbol_addr, symtab[symtab_index].st_value); +#endif + _dl_memcpy((char *) symtab[symtab_index].st_value, + (char *) symbol_addr, symtab[symtab_index].st_size); + } - tpnt = xpnt->dyn; + return goof; +} - rpnt = (Elf32_Rel *) (rel_addr + tpnt->loadaddr); - rel_size = rel_size / sizeof(Elf32_Rel); +void _dl_parse_lazy_relocation_information(struct elf_resolve *tpnt, + unsigned long rel_addr, unsigned long rel_size, int type) +{ + (void)_dl_parse(tpnt, NULL, rel_addr, rel_size, _dl_do_lazy_reloc); +} - symtab = (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr); - strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr); +int _dl_parse_relocation_information(struct elf_resolve *tpnt, + unsigned long rel_addr, unsigned long rel_size, int type) +{ + return _dl_parse(tpnt, tpnt->symbol_scope, rel_addr, rel_size, _dl_do_reloc); +} - for (i = 0; i < rel_size; i++, rpnt++) { - reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); - reloc_type = ELF32_R_TYPE(rpnt->r_info); - if (reloc_type != R_ARM_COPY) - continue; - symtab_index = ELF32_R_SYM(rpnt->r_info); - symbol_addr = 0; - if (!symtab_index && tpnt->libtype == program_interpreter) - continue; - if (symtab_index) { - - if (tpnt->libtype == program_interpreter && - _dl_symbol(strtab + symtab[symtab_index].st_name)) - continue; - - symbol_addr = (unsigned long) _dl_find_hash(strtab + - symtab[symtab_index].st_name, xpnt->next, - NULL, 1); - if (!symbol_addr) { - _dl_dprintf(2, "%s: can't resolve symbol '%s'\n", - _dl_progname, strtab + symtab[symtab_index].st_name); - goof++; - }; - }; - if (!goof) { - _dl_memcpy((char *) symtab[symtab_index].st_value, - (char *) symbol_addr, symtab[symtab_index].st_size); - } - }; - return goof; +int _dl_parse_copy_information(struct dyn_elf *xpnt, unsigned long rel_addr, + unsigned long rel_size, int type) +{ + return _dl_parse(xpnt->dyn, xpnt->next, rel_addr, rel_size, _dl_do_copy); } + diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c index c5e7607e0..8c2314184 100644 --- a/ldso/ldso/dl-elf.c +++ b/ldso/ldso/dl-elf.c @@ -1,21 +1,34 @@ -/* Load an ELF sharable library into memory. - - Copyright (C) 1993-1996, Eric Youngdale. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - +/* vi: set sw=4 ts=4: */ +/* Program to load an ELF binary on a linux system, and run it + * after resolving ELF shared library symbols + * + * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald, + * David Engel, Hongjiu Lu and Mitch D'Souza + * Copyright (C) 2001-2002, Erik Andersen + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the above contributors may not be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ /* This file contains the helper routines to load an ELF sharable @@ -180,8 +193,8 @@ struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt, pnt++; } -#ifdef DL_DEBUG - _dl_dprintf(2, "searching for library: '%s'\n", libname); +#ifdef LD_DEBUG + _dl_dprintf(_dl_debug_file, "searching for library: '%s'\n", libname); #endif /* If the filename has any '/', try it straight and leave it at that. For IBCS2 compatibility under linux, we substitute the string @@ -204,8 +217,8 @@ struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt, if (pnt) { pnt += (unsigned long) tpnt->loadaddr + tpnt->dynamic_info[DT_STRTAB]; -#ifdef DL_DEBUG - _dl_dprintf(2, "searching RPATH: '%s'\n", pnt); +#ifdef LD_DEBUG + _dl_dprintf(_dl_debug_file, "searching RPATH: '%s'\n", pnt); #endif if ((tpnt1 = search_for_named_library(libname, secure, pnt, rpnt)) != NULL) { @@ -217,8 +230,8 @@ struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt, /* Check in LD_{ELF_}LIBRARY_PATH, if specified and allowed */ if (_dl_library_path) { -#ifdef DL_DEBUG - _dl_dprintf(2, "searching _dl_library_path: '%s'\n", _dl_library_path); +#ifdef LD_DEBUG + _dl_dprintf(_dl_debug_file, "searching _dl_library_path: '%s'\n", _dl_library_path); #endif if ((tpnt1 = search_for_named_library(libname, secure, _dl_library_path, rpnt)) != NULL) { @@ -251,8 +264,8 @@ struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt, /* Look for libraries wherever the shared library loader * was installed */ -#ifdef DL_DEBUG - _dl_dprintf(2, "searching in ldso dir: %s\n", _dl_ldsopath); +#ifdef LD_DEBUG + _dl_dprintf(_dl_debug_file, "searching in ldso dir: %s\n", _dl_ldsopath); #endif if ((tpnt1 = search_for_named_library(libname, secure, _dl_ldsopath, rpnt)) != NULL) { @@ -262,8 +275,8 @@ struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt, /* Lastly, search the standard list of paths for the library. This list must exactly match the list in uClibc/ldso/util/ldd.c */ -#ifdef DL_DEBUG - _dl_dprintf(2, "searching full lib path list\n"); +#ifdef LD_DEBUG + _dl_dprintf(_dl_debug_file, "searching full lib path list\n"); #endif if ((tpnt1 = search_for_named_library(libname, secure, UCLIBC_TARGET_PREFIX "/usr/lib:" @@ -282,8 +295,8 @@ goof: if (_dl_internal_error_number) _dl_error_number = _dl_internal_error_number; else - _dl_error_number = DL_ERROR_NOFILE; -#ifdef DL_DEBUG + _dl_error_number = LD_ERROR_NOFILE; +#ifdef LD_DEBUG _dl_dprintf(2, "Bummer: could not find '%s'!\n", libname); #endif return NULL; @@ -323,6 +336,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, (*rpnt)->next = (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf)); _dl_memset((*rpnt)->next, 0, sizeof(*((*rpnt)->next))); + (*rpnt)->next->prev = (*rpnt); *rpnt = (*rpnt)->next; (*rpnt)->dyn = tpnt; tpnt->symbol_scope = _dl_symbol_tables; @@ -352,7 +366,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, */ _dl_dprintf(2, "%s: can't open '%s'\n", _dl_progname, libname); #endif - _dl_internal_error_number = DL_ERROR_NOFILE; + _dl_internal_error_number = LD_ERROR_NOFILE; return NULL; } @@ -365,7 +379,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, { _dl_dprintf(2, "%s: '%s' is not an ELF file\n", _dl_progname, libname); - _dl_internal_error_number = DL_ERROR_NOTELF; + _dl_internal_error_number = LD_ERROR_NOTELF; _dl_close(infile); return NULL; }; @@ -377,7 +391,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, )) { _dl_internal_error_number = - (epnt->e_type != ET_DYN ? DL_ERROR_NOTDYN : DL_ERROR_NOTMAGIC); + (epnt->e_type != ET_DYN ? LD_ERROR_NOTDYN : LD_ERROR_NOTMAGIC); _dl_dprintf(2, "%s: '%s' is not an ELF executable for " ELF_TARGET "\n", _dl_progname, libname); _dl_close(infile); @@ -424,7 +438,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, maxvma - minvma, PROT_NONE, flags | MAP_ANONYMOUS, -1, 0); if (_dl_mmap_check_error(status)) { _dl_dprintf(2, "%s: can't map %s\n", _dl_progname, libname); - _dl_internal_error_number = DL_ERROR_MMAP_FAILED; + _dl_internal_error_number = LD_ERROR_MMAP_FAILED; _dl_close(infile); return NULL; }; @@ -457,7 +471,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, if (_dl_mmap_check_error(status)) { _dl_dprintf(2, "%s: can't map '%s'\n", _dl_progname, libname); - _dl_internal_error_number = DL_ERROR_MMAP_FAILED; + _dl_internal_error_number = LD_ERROR_MMAP_FAILED; _dl_munmap((char *) libaddr, maxvma - minvma); _dl_close(infile); return NULL; @@ -488,7 +502,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, infile, ppnt->p_offset & OFFS_ALIGN); if (_dl_mmap_check_error(status)) { _dl_dprintf(2, "%s: can't map '%s'\n", _dl_progname, libname); - _dl_internal_error_number = DL_ERROR_MMAP_FAILED; + _dl_internal_error_number = LD_ERROR_MMAP_FAILED; _dl_munmap((char *) libaddr, maxvma - minvma); _dl_close(infile); return NULL; @@ -516,7 +530,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, /* Start by scanning the dynamic section to get all of the pointers */ if (!dynamic_addr) { - _dl_internal_error_number = DL_ERROR_NODYNAMIC; + _dl_internal_error_number = LD_ERROR_NODYNAMIC; _dl_dprintf(2, "%s: '%s' is missing a dynamic section\n", _dl_progname, libname); return NULL; @@ -580,6 +594,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, (*rpnt)->next = (struct dyn_elf *) _dl_malloc(sizeof(struct dyn_elf)); _dl_memset((*rpnt)->next, 0, sizeof(*((*rpnt)->next))); + (*rpnt)->next->prev = (*rpnt); *rpnt = (*rpnt)->next; (*rpnt)->dyn = tpnt; tpnt->symbol_scope = _dl_symbol_tables; @@ -626,6 +641,10 @@ int _dl_copy_fixups(struct dyn_elf *rpnt) return goof; tpnt->init_flag |= COPY_RELOCS_DONE; +#if defined (SUPPORT_LD_DEBUG) + if(_dl_debug) _dl_dprintf(_dl_debug_file,"\nrelocation copy fixups: %s", tpnt->libname); +#endif + #ifdef ELF_USES_RELOCA goof += _dl_parse_copy_information(rpnt, tpnt->dynamic_info[DT_RELA], tpnt->dynamic_info[DT_RELASZ], 0); @@ -635,5 +654,8 @@ int _dl_copy_fixups(struct dyn_elf *rpnt) tpnt->dynamic_info[DT_RELSZ], 0); #endif +#if defined (SUPPORT_LD_DEBUG) + if(_dl_debug) _dl_dprintf(_dl_debug_file,"\nrelocation copy fixups: %s; finished\n\n", tpnt->libname); +#endif return goof; } diff --git a/ldso/ldso/dl-hash.c b/ldso/ldso/dl-hash.c index b063d0b79..5711bebaa 100644 --- a/ldso/ldso/dl-hash.c +++ b/ldso/ldso/dl-hash.c @@ -1,21 +1,34 @@ -/* Run an ELF binary on a linux system. - - Copyright (C) 1993-1996, Eric Youngdale. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - +/* vi: set sw=4 ts=4: */ +/* Program to load an ELF binary on a linux system, and run it + * after resolving ELF shared library symbols + * + * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald, + * David Engel, Hongjiu Lu and Mitch D'Souza + * Copyright (C) 2001-2002, Erik Andersen + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the above contributors may not be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ /* Various symbol table handling functions, including symbol lookup */ @@ -150,7 +163,7 @@ struct elf_resolve *_dl_add_elf_hash_table(char *libname, */ char *_dl_find_hash(char *name, struct dyn_elf *rpnt1, - struct elf_resolve *f_tpnt, int copyrel) + struct elf_resolve *f_tpnt, enum caller_type caller_type) { struct elf_resolve *tpnt; int si; @@ -172,7 +185,7 @@ char *_dl_find_hash(char *name, struct dyn_elf *rpnt1, that any shared library data symbols referenced in the executable will be seen at the same address by the executable, shared libraries and dynamically loaded code. -Rob Ryan (robr@cmu.edu) */ - if (!copyrel && rpnt1) { + if (copyrel!=caller_type && rpnt1) { first = (*_dl_symbol_tables); first.next = rpnt1; rpnt1 = (&first); @@ -247,11 +260,12 @@ char *_dl_find_hash(char *name, struct dyn_elf *rpnt1, pnt = strtab + symtab[si].st_name; if (_dl_strcmp(pnt, name) == 0 && - (ELF32_ST_TYPE(symtab[si].st_info) == STT_FUNC || - ELF32_ST_TYPE(symtab[si].st_info) == STT_NOTYPE || - ELF32_ST_TYPE(symtab[si].st_info) == STT_OBJECT) && - symtab[si].st_value != 0 && - symtab[si].st_shndx != 0) { + symtab[si].st_value != 0) + { + if ((ELF32_ST_TYPE(symtab[si].st_info) == STT_FUNC || + ELF32_ST_TYPE(symtab[si].st_info) == STT_NOTYPE || + ELF32_ST_TYPE(symtab[si].st_info) == STT_OBJECT) && + symtab[si].st_shndx != SHN_UNDEF) { /* Here we make sure that we find a module where the symbol is * actually defined. @@ -284,6 +298,24 @@ char *_dl_find_hash(char *name, struct dyn_elf *rpnt1, default: /* Do local symbols need to be examined? */ break; } + } + /* + * References to the address of a function from an executable file and + * the shared objects associated with it might not resolve to the same + * value. To allow comparisons of function addresses we must resolve + * to the address of the plt entry of the executable instead of the + * real function address. + * see "TIS ELF Specification Version 1.2, Book 3, A-11 (Function + * Adresses) + */ + if (resolver != caller_type && + NULL==f_tpnt && /*trick: don't handle R_??_JMP_SLOT reloc type*/ + tpnt->libtype == elf_executable && + ELF32_ST_TYPE(symtab[si].st_info) == STT_FUNC && + symtab[si].st_shndx == SHN_UNDEF) + { + return (char*)symtab[si].st_value; + } } } } diff --git a/ldso/ldso/hash.c b/ldso/ldso/hash.c index b063d0b79..5711bebaa 100644 --- a/ldso/ldso/hash.c +++ b/ldso/ldso/hash.c @@ -1,21 +1,34 @@ -/* Run an ELF binary on a linux system. - - Copyright (C) 1993-1996, Eric Youngdale. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - +/* vi: set sw=4 ts=4: */ +/* Program to load an ELF binary on a linux system, and run it + * after resolving ELF shared library symbols + * + * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald, + * David Engel, Hongjiu Lu and Mitch D'Souza + * Copyright (C) 2001-2002, Erik Andersen + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the above contributors may not be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ /* Various symbol table handling functions, including symbol lookup */ @@ -150,7 +163,7 @@ struct elf_resolve *_dl_add_elf_hash_table(char *libname, */ char *_dl_find_hash(char *name, struct dyn_elf *rpnt1, - struct elf_resolve *f_tpnt, int copyrel) + struct elf_resolve *f_tpnt, enum caller_type caller_type) { struct elf_resolve *tpnt; int si; @@ -172,7 +185,7 @@ char *_dl_find_hash(char *name, struct dyn_elf *rpnt1, that any shared library data symbols referenced in the executable will be seen at the same address by the executable, shared libraries and dynamically loaded code. -Rob Ryan (robr@cmu.edu) */ - if (!copyrel && rpnt1) { + if (copyrel!=caller_type && rpnt1) { first = (*_dl_symbol_tables); first.next = rpnt1; rpnt1 = (&first); @@ -247,11 +260,12 @@ char *_dl_find_hash(char *name, struct dyn_elf *rpnt1, pnt = strtab + symtab[si].st_name; if (_dl_strcmp(pnt, name) == 0 && - (ELF32_ST_TYPE(symtab[si].st_info) == STT_FUNC || - ELF32_ST_TYPE(symtab[si].st_info) == STT_NOTYPE || - ELF32_ST_TYPE(symtab[si].st_info) == STT_OBJECT) && - symtab[si].st_value != 0 && - symtab[si].st_shndx != 0) { + symtab[si].st_value != 0) + { + if ((ELF32_ST_TYPE(symtab[si].st_info) == STT_FUNC || + ELF32_ST_TYPE(symtab[si].st_info) == STT_NOTYPE || + ELF32_ST_TYPE(symtab[si].st_info) == STT_OBJECT) && + symtab[si].st_shndx != SHN_UNDEF) { /* Here we make sure that we find a module where the symbol is * actually defined. @@ -284,6 +298,24 @@ char *_dl_find_hash(char *name, struct dyn_elf *rpnt1, default: /* Do local symbols need to be examined? */ break; } + } + /* + * References to the address of a function from an executable file and + * the shared objects associated with it might not resolve to the same + * value. To allow comparisons of function addresses we must resolve + * to the address of the plt entry of the executable instead of the + * real function address. + * see "TIS ELF Specification Version 1.2, Book 3, A-11 (Function + * Adresses) + */ + if (resolver != caller_type && + NULL==f_tpnt && /*trick: don't handle R_??_JMP_SLOT reloc type*/ + tpnt->libtype == elf_executable && + ELF32_ST_TYPE(symtab[si].st_info) == STT_FUNC && + symtab[si].st_shndx == SHN_UNDEF) + { + return (char*)symtab[si].st_value; + } } } } diff --git a/ldso/ldso/i386/boot1_arch.h b/ldso/ldso/i386/boot1_arch.h index 2f8fe1357..cd1f016a6 100644 --- a/ldso/ldso/i386/boot1_arch.h +++ b/ldso/ldso/i386/boot1_arch.h @@ -4,4 +4,4 @@ * can be done. */ -#define DL_BOOT(X) void _dl_boot (X) +#define LD_BOOT(X) void _dl_boot (X) diff --git a/ldso/ldso/i386/dl-startup.h b/ldso/ldso/i386/dl-startup.h index 2f8fe1357..cd1f016a6 100644 --- a/ldso/ldso/i386/dl-startup.h +++ b/ldso/ldso/i386/dl-startup.h @@ -4,4 +4,4 @@ * can be done. */ -#define DL_BOOT(X) void _dl_boot (X) +#define LD_BOOT(X) void _dl_boot (X) diff --git a/ldso/ldso/i386/elfinterp.c b/ldso/ldso/i386/elfinterp.c index 3c9979e49..4bfa349e8 100644 --- a/ldso/ldso/i386/elfinterp.c +++ b/ldso/ldso/i386/elfinterp.c @@ -1,31 +1,96 @@ -/* Run an ELF binary on a linux system. - - Copyright (C) 1993, Eric Youngdale. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef VERBOSE_DLINKER -#define VERBOSE_DLINKER -#endif -#ifdef VERBOSE_DLINKER -static const char *_dl_reltypes[] = - { "R_386_NONE", "R_386_32", "R_386_PC32", "R_386_GOT32", - "R_386_PLT32", "R_386_COPY", "R_386_GLOB_DAT", - "R_386_JMP_SLOT", "R_386_RELATIVE", "R_386_GOTOFF", - "R_386_GOTPC", "R_386_NUM" +/* vi: set sw=4 ts=4: */ +/* i386 ELF shared library loader suppport + * + * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald, + * David Engel, Hongjiu Lu and Mitch D'Souza + * Copyright (C) 2001-2002, Erik Andersen + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the above contributors may not be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined (SUPPORT_LD_DEBUG) || defined (LD_DEBUG_SYMBOLS) +static const char *_dl_reltypes_tab[] = +{ + [0] "R_386_NONE", "R_386_32", "R_386_PC32", "R_386_GOT32", + [4] "R_386_PLT32", "R_386_COPY", "R_386_GLOB_DAT", "R_386_JMP_SLOT", + [8] "R_386_RELATIVE", "R_386_GOTOFF", "R_386_GOTPC", }; + +static const char * +_dl_reltypes(int type) +{ + static char buf[22]; + const char *str; + + if (type >= (sizeof (_dl_reltypes_tab)/sizeof(_dl_reltypes_tab[0])) || + NULL == (str = _dl_reltypes_tab[type])) + { + str =_dl_simple_ltoa( buf, (unsigned long)(type)); + } + return str; +} + +static +void debug_sym(Elf32_Sym *symtab,char *strtab,int symtab_index) +{ + if(_dl_debug_symbols) + { + if(symtab_index){ + _dl_dprintf(_dl_debug_file, "\n%s\tvalue=%x\tsize=%x\tinfo=%x\tother=%x\tshndx=%x", + strtab + symtab[symtab_index].st_name, + symtab[symtab_index].st_value, + symtab[symtab_index].st_size, + symtab[symtab_index].st_info, + symtab[symtab_index].st_other, + symtab[symtab_index].st_shndx); + } + } +} + +static void debug_reloc(Elf32_Sym *symtab,char *strtab, ELF_RELOC *rpnt) +{ + if(_dl_debug_reloc) + { + int symtab_index; + const char *sym; + symtab_index = ELF32_R_SYM(rpnt->r_info); + sym = symtab_index ? strtab + symtab[symtab_index].st_name : "sym=0x0"; + +#ifdef ELF_USES_RELOCA + _dl_dprintf(_dl_debug_file, "\n%s\toffset=%x\taddend=%x %s", + _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)), + rpnt->r_offset, + rpnt->r_addend, + sym); +#else + _dl_dprintf(_dl_debug_file, "\n%s\toffset=%x %s", + _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)), + rpnt->r_offset, + sym); +#endif + } +} #endif /* Program to load an ELF binary on a linux system, and run it. @@ -44,16 +109,16 @@ extern int _dl_linux_resolve(void); unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) { int reloc_type; - Elf32_Rel *this_reloc; + ELF_RELOC *this_reloc; char *strtab; Elf32_Sym *symtab; - Elf32_Rel *rel_addr; + ELF_RELOC *rel_addr; int symtab_index; char *new_addr; char **got_addr; unsigned long instr_addr; - rel_addr = (Elf32_Rel *) (tpnt->dynamic_info[DT_JMPREL] + tpnt->loadaddr); + rel_addr = (ELF_RELOC *) (tpnt->dynamic_info[DT_JMPREL] + tpnt->loadaddr); this_reloc = rel_addr + (reloc_entry >> 3); reloc_type = ELF32_R_TYPE(this_reloc->r_info); @@ -74,175 +139,211 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) (unsigned long) tpnt->loadaddr); got_addr = (char **) instr_addr; -#ifdef DL_DEBUG_SYMBOLS - _dl_dprintf(2, "Resolving symbol %s\n", - strtab + symtab[symtab_index].st_name); -#endif - /* Get the address of the GOT entry */ new_addr = _dl_find_hash(strtab + symtab[symtab_index].st_name, - tpnt->symbol_scope, tpnt, 0); + tpnt->symbol_scope, tpnt, resolver); if (!new_addr) { _dl_dprintf(2, "%s: can't resolve symbol '%s'\n", _dl_progname, strtab + symtab[symtab_index].st_name); _dl_exit(1); }; -#ifdef DL_NEVER_FIXUP_SYMBOLS - if ((unsigned long) got_addr < 0x40000000) { - _dl_dprintf(2, "Calling library function: %s\n", +#if defined (SUPPORT_LD_DEBUG) || defined (LD_NEVER_FIXUP_SYMBOLS) + if ((unsigned long) got_addr < 0x40000000) + { +#ifndef SUPPORT_LD_DEBUG + if (_dl_debug_bindings) + { + _dl_dprintf(_dl_debug_file, "\nresolve function: %s", strtab + symtab[symtab_index].st_name); + if(_dl_debug_detail) _dl_dprintf(_dl_debug_file, "\tpatch %x ==> %x @ %x", *got_addr, new_addr, got_addr); + } +#endif +#ifndef LD_NEVER_FIXUP_SYMBOLS + *got_addr = new_addr; +#endif } else { - *got_addr = new_addr; + *got_addr = new_addr; } #else *got_addr = new_addr; #endif + return (unsigned long) new_addr; } -void _dl_parse_lazy_relocation_information(struct elf_resolve *tpnt, - unsigned long rel_addr, unsigned long rel_size, int type) +static int +_dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope, + unsigned long rel_addr, unsigned long rel_size, + int (*reloc_fnc) (struct elf_resolve *tpnt, struct dyn_elf *scope, + ELF_RELOC *rpnt, Elf32_Sym *symtab, char *strtab)) { int i; char *strtab; - int reloc_type; - int symtab_index; + int goof = 0; Elf32_Sym *symtab; - Elf32_Rel *rpnt; - unsigned long *reloc_addr; - + ELF_RELOC *rpnt; + int symtab_index; /* Now parse the relocation information */ - rpnt = (Elf32_Rel *) (rel_addr + tpnt->loadaddr); - rel_size = rel_size / sizeof(Elf32_Rel); - symtab = - (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr); + rpnt = (ELF_RELOC *) (rel_addr + tpnt->loadaddr); + rel_size = rel_size / sizeof(ELF_RELOC); + + symtab = (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr); strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr); - for (i = 0; i < rel_size; i++, rpnt++) { - reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); - reloc_type = ELF32_R_TYPE(rpnt->r_info); + for (i = 0; i < rel_size; i++, rpnt++) { + int res; + symtab_index = ELF32_R_SYM(rpnt->r_info); - + /* When the dynamic linker bootstrapped itself, it resolved some symbols. Make sure we do not do them again */ if (!symtab_index && tpnt->libtype == program_interpreter) continue; if (symtab_index && tpnt->libtype == program_interpreter && - _dl_symbol(strtab + symtab[symtab_index].st_name)) + _dl_symbol(strtab + symtab[symtab_index].st_name)) continue; - switch (reloc_type) { - case R_386_NONE: - break; - case R_386_JMP_SLOT: - *reloc_addr += (unsigned long) tpnt->loadaddr; - break; - default: - _dl_dprintf(2, "%s: (LAZY) can't handle reloc type ", - _dl_progname); -#ifdef VERBOSE_DLINKER - _dl_dprintf(2, "%s ", _dl_reltypes[reloc_type]); +#if defined (SUPPORT_LD_DEBUG) || defined (LD_DEBUG_SYMBOLS) + debug_sym(symtab,strtab,symtab_index); + debug_reloc(symtab,strtab,rpnt); #endif - if (symtab_index) - _dl_dprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name); - _dl_exit(1); - }; - }; + + res = reloc_fnc (tpnt, scope, rpnt, symtab, strtab); + + if (res==0) continue; + + _dl_dprintf(2, "\n%s: ",_dl_progname); + + if (symtab_index) + _dl_dprintf(2, "symbol '%s': ", strtab + symtab[symtab_index].st_name); + + if (res <0) + { + int reloc_type = ELF32_R_TYPE(rpnt->r_info); +#if defined (SUPPORT_LD_DEBUG) + _dl_dprintf(2, "can't handle reloc type %s\n ", _dl_reltypes(reloc_type)); +#else + _dl_dprintf(2, "can't handle reloc type %x\n", reloc_type); +#endif + _dl_exit(-res); + } + else if (res >0) + { + _dl_dprintf(2, "can't resolve symbol '%s'\n"); + goof += res; + } + } + return goof; } -int _dl_parse_relocation_information(struct elf_resolve *tpnt, - unsigned long rel_addr, unsigned long rel_size, int type) +static int +_dl_do_reloc (struct elf_resolve *tpnt,struct dyn_elf *scope, + ELF_RELOC *rpnt, Elf32_Sym *symtab, char *strtab) { - int i; - char *strtab; int reloc_type; - int goof = 0; - Elf32_Sym *symtab; - Elf32_Rel *rpnt; + int symtab_index; unsigned long *reloc_addr; unsigned long symbol_addr; - int symtab_index; - - /* Now parse the relocation information */ - - rpnt = (Elf32_Rel *) (rel_addr + tpnt->loadaddr); - rel_size = rel_size / sizeof(Elf32_Rel); + int goof = 0; - symtab = (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr); - strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr); + reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); + reloc_type = ELF32_R_TYPE(rpnt->r_info); + symtab_index = ELF32_R_SYM(rpnt->r_info); + symbol_addr = 0; - for (i = 0; i < rel_size; i++, rpnt++) { - reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); - reloc_type = ELF32_R_TYPE(rpnt->r_info); - symtab_index = ELF32_R_SYM(rpnt->r_info); - symbol_addr = 0; + if (symtab_index) { - if (!symtab_index && tpnt->libtype == program_interpreter) - continue; + symbol_addr = (unsigned long) _dl_find_hash(strtab + symtab[symtab_index].st_name, + scope, (reloc_type == R_386_JMP_SLOT ? tpnt : NULL), symbolrel); - if (symtab_index) { - - if (tpnt->libtype == program_interpreter && - _dl_symbol(strtab + symtab[symtab_index].st_name)) - continue; - - symbol_addr = (unsigned long) _dl_find_hash(strtab + symtab[symtab_index].st_name, - tpnt->symbol_scope, - (reloc_type == R_386_JMP_SLOT ? tpnt : NULL), 0); - - /* - * We want to allow undefined references to weak symbols - this might - * have been intentional. We should not be linking local symbols - * here, so all bases should be covered. - */ - if (!symbol_addr && - ELF32_ST_BIND(symtab[symtab_index].st_info) == STB_GLOBAL) { - _dl_dprintf(2, "%s: can't resolve symbol '%s'\n", - _dl_progname, strtab + symtab[symtab_index].st_name); - goof++; - } + /* + * We want to allow undefined references to weak symbols - this might + * have been intentional. We should not be linking local symbols + * here, so all bases should be covered. + */ + if (!symbol_addr && ELF32_ST_BIND(symtab[symtab_index].st_info) == STB_GLOBAL) { + goof++; } + } + +#if defined (SUPPORT_LD_DEBUG) + { + unsigned long old_val = *reloc_addr; +#endif switch (reloc_type) { - case R_386_NONE: - break; - case R_386_32: - *reloc_addr += symbol_addr; - break; - case R_386_PC32: - *reloc_addr += symbol_addr - (unsigned long) reloc_addr; - break; - case R_386_GLOB_DAT: - case R_386_JMP_SLOT: - *reloc_addr = symbol_addr; - break; - case R_386_RELATIVE: - *reloc_addr += (unsigned long) tpnt->loadaddr; - break; - case R_386_COPY: -#if 0 - /* Do this later */ - _dl_dprintf(2, "Doing copy for symbol "); - if (symtab_index) _dl_dprintf(2, strtab + symtab[symtab_index].st_name); - _dl_dprintf(2, "\n"); - _dl_memcpy((void *) symtab[symtab_index].st_value, - (void *) symbol_addr, symtab[symtab_index].st_size); + case R_386_NONE: + break; + case R_386_32: + *reloc_addr += symbol_addr; + break; + case R_386_PC32: + *reloc_addr += symbol_addr - (unsigned long) reloc_addr; + break; + case R_386_GLOB_DAT: + case R_386_JMP_SLOT: + *reloc_addr = symbol_addr; + break; + case R_386_RELATIVE: + *reloc_addr += (unsigned long) tpnt->loadaddr; + break; + case R_386_COPY: +#if 0 + /* Do this later */ + _dl_dprintf(2, "Doing copy for symbol "); + if (symtab_index) _dl_dprintf(2, strtab + symtab[symtab_index].st_name); + _dl_dprintf(2, "\n"); + _dl_memcpy((void *) symtab[symtab_index].st_value, + (void *) symbol_addr, symtab[symtab_index].st_size); #endif - break; - default: - _dl_dprintf(2, "%s: can't handle reloc type ", _dl_progname); -#ifdef VERBOSE_DLINKER - _dl_dprintf(2, "%s ", _dl_reltypes[reloc_type]); + break; + + default: + return -1; /*call _dl_exit(1) */ + } +#if defined (SUPPORT_LD_DEBUG) + if(_dl_debug_reloc && _dl_debug_detail) + _dl_dprintf(_dl_debug_file, "\tpatch: %x ==> %x @ %x", old_val, *reloc_addr, reloc_addr); + } + #endif - if (symtab_index) - _dl_dprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name); - _dl_exit(1); - }; - }; return goof; } +static int +_dl_do_lazy_reloc (struct elf_resolve *tpnt, struct dyn_elf *scope, + ELF_RELOC *rpnt, Elf32_Sym *symtab, char *strtab) +{ + int reloc_type; + unsigned long *reloc_addr; + + reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); + reloc_type = ELF32_R_TYPE(rpnt->r_info); + +#if defined (SUPPORT_LD_DEBUG) + { + unsigned long old_val = *reloc_addr; +#endif + switch (reloc_type) { + case R_386_NONE: + break; + case R_386_JMP_SLOT: + *reloc_addr += (unsigned long) tpnt->loadaddr; + break; + + default: + return -1; /*call _dl_exit(1) */ + } +#if defined (SUPPORT_LD_DEBUG) + if(_dl_debug_reloc && _dl_debug_detail) + _dl_dprintf(_dl_debug_file, "\tpatch: %x ==> %x @ %x", old_val, *reloc_addr, reloc_addr); + } + +#endif + return 0; + +} /* This is done as a separate step, because there are cases where information is first copied and later initialized. This results in @@ -252,59 +353,60 @@ int _dl_parse_relocation_information(struct elf_resolve *tpnt, /* No, there are cases where the SVr4 linker fails to emit COPY relocs at all */ - -int _dl_parse_copy_information(struct dyn_elf *xpnt, unsigned long rel_addr, - unsigned long rel_size, int type) +static int +_dl_do_copy (struct elf_resolve *tpnt, struct dyn_elf *scope, + ELF_RELOC *rpnt, Elf32_Sym *symtab, char *strtab) { - int i; - char *strtab; - int reloc_type; - int goof = 0; - Elf32_Sym *symtab; - Elf32_Rel *rpnt; + int reloc_type; + int symtab_index; unsigned long *reloc_addr; unsigned long symbol_addr; - struct elf_resolve *tpnt; - int symtab_index; - - /* Now parse the relocation information */ + int goof = 0; + + reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); + reloc_type = ELF32_R_TYPE(rpnt->r_info); + if (reloc_type != R_386_COPY) + return 0; + symtab_index = ELF32_R_SYM(rpnt->r_info); + symbol_addr = 0; + + if (symtab_index) { + + symbol_addr = (unsigned long) _dl_find_hash(strtab + + symtab[symtab_index].st_name, scope, + NULL, copyrel); + if (!symbol_addr) goof++; + } + if (!goof) { +#if defined (SUPPORT_LD_DEBUG) + if(_dl_debug_move) + _dl_dprintf(_dl_debug_file,"\n%s move %x bytes from %x to %x", + strtab + symtab[symtab_index].st_name, + symtab[symtab_index].st_size, + symbol_addr, symtab[symtab_index].st_value); +#endif + _dl_memcpy((char *) symtab[symtab_index].st_value, + (char *) symbol_addr, symtab[symtab_index].st_size); + } - tpnt = xpnt->dyn; + return goof; +} - rpnt = (Elf32_Rel *) (rel_addr + tpnt->loadaddr); - rel_size = rel_size / sizeof(Elf32_Rel); +void _dl_parse_lazy_relocation_information(struct elf_resolve *tpnt, + unsigned long rel_addr, unsigned long rel_size, int type) +{ + (void)_dl_parse(tpnt, NULL, rel_addr, rel_size, _dl_do_lazy_reloc); +} - symtab = (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr); - strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr); +int _dl_parse_relocation_information(struct elf_resolve *tpnt, + unsigned long rel_addr, unsigned long rel_size, int type) +{ + return _dl_parse(tpnt, tpnt->symbol_scope, rel_addr, rel_size, _dl_do_reloc); +} - for (i = 0; i < rel_size; i++, rpnt++) { - reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); - reloc_type = ELF32_R_TYPE(rpnt->r_info); - if (reloc_type != R_386_COPY) - continue; - symtab_index = ELF32_R_SYM(rpnt->r_info); - symbol_addr = 0; - if (!symtab_index && tpnt->libtype == program_interpreter) - continue; - if (symtab_index) { - - if (tpnt->libtype == program_interpreter && - _dl_symbol(strtab + symtab[symtab_index].st_name)) - continue; - - symbol_addr = (unsigned long) _dl_find_hash(strtab + - symtab[symtab_index].st_name, xpnt->next, - NULL, 1); - if (!symbol_addr) { - _dl_dprintf(2, "%s: can't resolve symbol '%s'\n", - _dl_progname, strtab + symtab[symtab_index].st_name); - goof++; - }; - }; - if (!goof) { - _dl_memcpy((char *) symtab[symtab_index].st_value, - (char *) symbol_addr, symtab[symtab_index].st_size); - } - }; - return goof; +int _dl_parse_copy_information(struct dyn_elf *xpnt, unsigned long rel_addr, + unsigned long rel_size, int type) +{ + return _dl_parse(xpnt->dyn, xpnt->next, rel_addr, rel_size, _dl_do_copy); } + diff --git a/ldso/ldso/ld_hash.h b/ldso/ldso/ld_hash.h index 639ae4510..b19d680a2 100644 --- a/ldso/ldso/ld_hash.h +++ b/ldso/ldso/ld_hash.h @@ -43,6 +43,7 @@ struct dyn_elf{ struct elf_resolve * dyn; struct dyn_elf * next_handle; /* Used by dlopen et al. */ struct dyn_elf * next; + struct dyn_elf * prev; }; struct elf_resolve{ @@ -113,8 +114,11 @@ extern struct elf_resolve * _dl_check_hashed_files(char * libname); extern struct elf_resolve * _dl_add_elf_hash_table(char * libname, char * loadaddr, unsigned long * dynamic_info, unsigned long dynamic_addr, unsigned long dynamic_size); + +enum caller_type{symbolrel=0,copyrel=1,resolver=2}; extern char * _dl_find_hash(char * name, struct dyn_elf * rpnt1, - struct elf_resolve * f_tpnt, int copyrel); + struct elf_resolve * f_tpnt, enum caller_type); + extern int _dl_linux_dynamic_link(void); extern char * _dl_library_path; @@ -129,16 +133,16 @@ static inline int _dl_symbol(char * name) } -#define DL_ERROR_NOFILE 1 -#define DL_ERROR_NOZERO 2 -#define DL_ERROR_NOTELF 3 -#define DL_ERROR_NOTMAGIC 4 -#define DL_ERROR_NOTDYN 5 -#define DL_ERROR_MMAP_FAILED 6 -#define DL_ERROR_NODYNAMIC 7 -#define DL_WRONG_RELOCS 8 -#define DL_BAD_HANDLE 9 -#define DL_NO_SYMBOL 10 +#define LD_ERROR_NOFILE 1 +#define LD_ERROR_NOZERO 2 +#define LD_ERROR_NOTELF 3 +#define LD_ERROR_NOTMAGIC 4 +#define LD_ERROR_NOTDYN 5 +#define LD_ERROR_MMAP_FAILED 6 +#define LD_ERROR_NODYNAMIC 7 +#define LD_WRONG_RELOCS 8 +#define LD_BAD_HANDLE 9 +#define LD_NO_SYMBOL 10 diff --git a/ldso/ldso/ld_string.h b/ldso/ldso/ld_string.h index e2b1f28c3..1de9f8d76 100644 --- a/ldso/ldso/ld_string.h +++ b/ldso/ldso/ld_string.h @@ -17,6 +17,7 @@ static int _dl_strcmp(const char * s1,const char * s2); static int _dl_strncmp(const char * s1,const char * s2,size_t len); static char * _dl_strchr(const char * str,int c); static char *_dl_strrchr(const char *str, int c); +static char *_dl_strstr(c