diff options
38 files changed, 1899 insertions, 697 deletions
diff --git a/ldso/ldso/arm/dl-debug.h b/ldso/ldso/arm/dl-debug.h new file mode 100644 index 000000000..d5103202c --- /dev/null +++ b/ldso/ldso/arm/dl-debug.h @@ -0,0 +1,44 @@ +/* vi: set sw=4 ts=4: */ +/* ARM ELF shared library loader suppport + * + * Copyright (C) 2001-2004 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. + */ + +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", +}; diff --git a/ldso/ldso/arm/dl-startup.h b/ldso/ldso/arm/dl-startup.h index cd4a1047b..b7ab57b0c 100644 --- a/ldso/ldso/arm/dl-startup.h +++ b/ldso/ldso/arm/dl-startup.h @@ -8,18 +8,51 @@ asm( " .text\n" " .globl _start\n" " .type _start,%function\n" - "_start:\n" - " mov r7, sp\n" - " @ldr r0, [sp], #4\n" - " mov r0, sp\n" - " bl _dl_start\n" - " mov r6, r0\n" - " mov r0, r7\n" - " mov pc, r6\n" + "_start:\n" + " @ at start time, all the args are on the stack\n" + " mov r0, sp\n" + " bl _dl_start\n" + " @ returns user entry point in r0\n" + " mov r6, r0\n" + " @ we are PIC code, so get global offset table\n" + " ldr sl, .L_GET_GOT\n" + " add sl, pc, sl\n" + ".L_GOT_GOT:\n" + " @ See if we were run as a command with the executable file\n" + " @ name as an extra leading argument.\n" + " ldr r4, .L_SKIP_ARGS\n" + " ldr r4, [sl, r4]\n" + " @ get the original arg count\n" + " ldr r1, [sp]\n" + " @ subtract _dl_skip_args from it\n" + " sub r1, r1, r4\n" + " @ adjust the stack pointer to skip them\n" + " add sp, sp, r4, lsl #2\n" + " @ get the argv address\n" + " add r2, sp, #4\n" + " @ store the new argc in the new stack location\n" + " str r1, [sp]\n" + " @ compute envp\n" + " add r3, r2, r1, lsl #2\n" + " add r3, r3, #4\n" + "\n\n" + " @ load the finalizer function\n" + " ldr r0, .L_FINI_PROC\n" + " ldr r0, [sl, r0]\n" + " @ jump to the user_s entry point\n" + " mov pc, r6\n" + ".L_GET_GOT:\n" + " .word _GLOBAL_OFFSET_TABLE_ - .L_GOT_GOT - 4\n" + ".L_SKIP_ARGS:\n" + " .word _dl_skip_args(GOTOFF)\n" + ".L_FINI_PROC:\n" + " .word _dl_fini(GOT)\n" + "\n\n" " .size _start,.-_start\n" - " .previous\n" + ".previous\n" ); + /* Get a pointer to the argv array. On many platforms this can be just * the address if the first argument, on other platforms we need to * do something a little more subtle here. */ diff --git a/ldso/ldso/arm/elfinterp.c b/ldso/ldso/arm/elfinterp.c index 228a1cee2..8086250ac 100644 --- a/ldso/ldso/arm/elfinterp.c +++ b/ldso/ldso/arm/elfinterp.c @@ -27,79 +27,6 @@ * SUCH DAMAGE. */ -#if defined (__SUPPORT_LD_DEBUG__) -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. References to symbols in sharable libraries can be resolved by either an ELF sharable library or a linux style of shared library. */ @@ -201,10 +128,8 @@ _dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope, symtab_index = ELF32_R_SYM(rpnt->r_info); -#if defined (__SUPPORT_LD_DEBUG__) debug_sym(symtab,strtab,symtab_index); debug_reloc(symtab,strtab,rpnt); -#endif res = reloc_fnc (tpnt, scope, rpnt, symtab, strtab); diff --git a/ldso/ldso/cris/dl-debug.h b/ldso/ldso/cris/dl-debug.h new file mode 100644 index 000000000..f6c03d21f --- /dev/null +++ b/ldso/ldso/cris/dl-debug.h @@ -0,0 +1,42 @@ +/* + * CRIS ELF shared library loader support. + * + * Program to load an elf binary on a linux system, and run it. + * References to symbols in sharable libraries can be resolved + * by either an ELF sharable library or a linux style of shared + * library. + * + * Copyright (C) 2002-2004, Axis Communications AB + * All rights reserved + * + * Author: Tobias Anderberg, <tobiasa@axis.com> + * + * 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. + */ + +static const char *_dl_reltypes_tab[] = { + [0] "R_CRIS_NONE", "R_CRIS_8", "R_CRIS_16", "R_CRIS_32", + [4] "R_CRIS_8_PCREL", "R_CRIS_16_PCREL", "R_CRIS_32_PCREL", "R_CRIS_GNU_VTINHERIT", + [8] "R_CRIS_GNU_VTENTRY", "R_CRIS_COPY", "R_CRIS_GLOB_DAT", "R_CRIS_JUMP_SLOT", + [16] "R_CRIS_RELATIVE", "R_CRIS_16_GOT", "R_CRIS_32_GOT", "R_CRIS_16_GOTPLT", + [32] "R_CRIS_32_GOTPLT", "R_CRIS_32_GOTREL", "R_CRIS_32_PLT_GOTREL", "R_CRIS_32_PLT_PCREL", +}; diff --git a/ldso/ldso/cris/dl-startup.h b/ldso/ldso/cris/dl-startup.h index afc158517..191657a43 100644 --- a/ldso/ldso/cris/dl-startup.h +++ b/ldso/ldso/cris/dl-startup.h @@ -26,6 +26,11 @@ asm("" \ * do something a little more subtle here. */ #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long *) ARGS)+1) + +/* We can't call functions earlier in the dl startup process */ +#define NO_FUNCS_BEFORE_BOOTSTRAP + + /* Handle relocation of the symbols in the dynamic loader. */ static inline void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr, diff --git a/ldso/ldso/cris/elfinterp.c b/ldso/ldso/cris/elfinterp.c index 5932fd0f1..abf4167a5 100644 --- a/ldso/ldso/cris/elfinterp.c +++ b/ldso/ldso/cris/elfinterp.c @@ -35,76 +35,6 @@ #include "ldso.h" -/* Support for the LD_DEBUG variable. */ -#if defined (__SUPPORT_LD_DEBUG__) -static const char *_dl_reltypes_tab[] = { - [0] "R_CRIS_NONE", "R_CRIS_8", "R_CRIS_16", "R_CRIS_32", - [4] "R_CRIS_8_PCREL", "R_CRIS_16_PCREL", "R_CRIS_32_PCREL", "R_CRIS_GNU_VTINHERIT", - [8] "R_CRIS_GNU_VTENTRY", "R_CRIS_COPY", "R_CRIS_GLOB_DAT", "R_CRIS_JUMP_SLOT", - [16] "R_CRIS_RELATIVE", "R_CRIS_16_GOT", "R_CRIS_32_GOT", "R_CRIS_16_GOTPLT", - [32] "R_CRIS_32_GOTPLT", "R_CRIS_32_GOTREL", "R_CRIS_32_PLT_GOTREL", "R_CRIS_32_PLT_PCREL", -}; - -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\n\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"; - - if (_dl_debug_symbols) - _dl_dprintf(_dl_debug_file, "\n\t"); - else - _dl_dprintf(_dl_debug_file, "\n%s\n\t", sym); - -#ifdef ELF_USES_RELOCA - _dl_dprintf(_dl_debug_file, "%s\toffset=%x\taddend=%x", - _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)), - rpnt->r_offset, - rpnt->r_addend); -#else - _dl_dprintf(_dl_debug_file, "%s\toffset=%x\n", - _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)), - rpnt->r_offset); -#endif - } -} -#endif /* __SUPPORT_LD_DEBUG__ */ - /* Defined in resolve.S. */ extern int _dl_linux_resolve(void); @@ -192,10 +122,8 @@ _dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope, symtab_index = ELF32_R_SYM(rpnt->r_info); -#if defined (__SUPPORT_LD_DEBUG__) debug_sym(symtab, strtab, symtab_index); debug_reloc(symtab, strtab, rpnt); -#endif /* Pass over to actual relocation function. */ res = reloc_fnc(tpnt, scope, rpnt, symtab, strtab); diff --git a/ldso/ldso/frv/dl-debug.h b/ldso/ldso/frv/dl-debug.h new file mode 100644 index 000000000..8d392d319 --- /dev/null +++ b/ldso/ldso/frv/dl-debug.h @@ -0,0 +1,43 @@ +/* FR-V FDPIC ELF shared library loader suppport + Copyright (C) 2003, 2004 Red Hat, Inc. + Contributed by Alexandre Oliva <aoliva@redhat.com> + Lots of code copied from ../i386/elfinterp.c, so: + 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. + +This file is part of uClibc. + +uClibc is free software; you can redistribute it and/or modify it +under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +uClibc 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 +Library General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with uClibc; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, +USA. */ + +static const char *_dl_reltypes_tab[] = +{ + [0] "R_FRV_NONE", "R_FRV_32", + [2] "R_FRV_LABEL16", "R_FRV_LABEL24", + [4] "R_FRV_LO16", "R_FRV_HI16", + [6] "R_FRV_GPREL12", "R_FRV_GPRELU12", + [8] "R_FRV_GPREL32", "R_FRV_GPRELHI", "R_FRV_GPRELLO", + [11] "R_FRV_GOT12", "R_FRV_GOTHI", "R_FRV_GOTLO", + [14] "R_FRV_FUNCDESC", + [15] "R_FRV_FUNCDESC_GOT12", "R_FRV_FUNCDESC_GOTHI", "R_FRV_FUNCDESC_GOTLO", + [18] "R_FRV_FUNCDESC_VALUE", "R_FRV_FUNCDESC_GOTOFF12", + [20] "R_FRV_FUNCDESC_GOTOFFHI", "R_FRV_FUNCDESC_GOTOFFLO", + [22] "R_FRV_GOTOFF12", "R_FRV_GOTOFFHI", "R_FRV_GOTOFFLO", +#if 0 + [200] "R_FRV_GNU_VTINHERIT", "R_FRV_GNU_VTENTRY" +#endif +}; diff --git a/ldso/ldso/frv/elfinterp.c b/ldso/ldso/frv/elfinterp.c index 9ab1a9777..cccf9b70c 100644 --- a/ldso/ldso/frv/elfinterp.c +++ b/ldso/ldso/frv/elfinterp.c @@ -26,83 +26,6 @@ USA. */ #include <sys/cdefs.h> /* __attribute_used__ */ -#if defined (__SUPPORT_LD_DEBUG__) -static const char *_dl_reltypes_tab[] = -{ - [0] "R_FRV_NONE", "R_FRV_32", - [2] "R_FRV_LABEL16", "R_FRV_LABEL24", - [4] "R_FRV_LO16", "R_FRV_HI16", - [6] "R_FRV_GPREL12", "R_FRV_GPRELU12", - [8] "R_FRV_GPREL32", "R_FRV_GPRELHI", "R_FRV_GPRELLO", - [11] "R_FRV_GOT12", "R_FRV_GOTHI", "R_FRV_GOTLO", - [14] "R_FRV_FUNCDESC", - [15] "R_FRV_FUNCDESC_GOT12", "R_FRV_FUNCDESC_GOTHI", "R_FRV_FUNCDESC_GOTLO", - [18] "R_FRV_FUNCDESC_VALUE", "R_FRV_FUNCDESC_GOTOFF12", - [20] "R_FRV_FUNCDESC_GOTOFFHI", "R_FRV_FUNCDESC_GOTOFFLO", - [22] "R_FRV_GOTOFF12", "R_FRV_GOTOFFHI", "R_FRV_GOTOFFLO", -#if 0 - [200] "R_FRV_GNU_VTINHERIT", "R_FRV_GNU_VTENTRY" -#endif -}; - -static const char * -_dl_reltypes(int type) -{ - static char buf[22]; - const char *str; - - if (type >= (int)(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\n\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"; - - if(_dl_debug_symbols) - _dl_dprintf(_dl_debug_file, "\n\t"); - else - _dl_dprintf(_dl_debug_file, "\n%s\n\t", sym); -#ifdef ELF_USES_RELOCA - _dl_dprintf(_dl_debug_file, "%s\toffset=%x\taddend=%x", - _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)), - rpnt->r_offset, - rpnt->r_addend); -#else - _dl_dprintf(_dl_debug_file, "%s\toffset=%x\n", - _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)), - rpnt->r_offset); -#endif - } -} -#endif - /* Program to load an ELF binary on a linux system, and run it. References to symbols in sharable libraries can be resolved by either an ELF sharable library or a linux style of shared library. */ @@ -213,10 +136,8 @@ _dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope, int res; symtab_index = ELF32_R_SYM(rpnt->r_info); -#if defined (__SUPPORT_LD_DEBUG__) debug_sym(symtab,strtab,symtab_index); debug_reloc(symtab,strtab,rpnt); -#endif res = reloc_fnc (tpnt, scope, rpnt, symtab, strtab); diff --git a/ldso/ldso/i386/dl-debug.h b/ldso/ldso/i386/dl-debug.h new file mode 100644 index 000000000..72a01f8df --- /dev/null +++ b/ldso/ldso/i386/dl-debug.h @@ -0,0 +1,36 @@ +/* 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-2004 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. + */ + +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", +}; diff --git a/ldso/ldso/i386/dl-startup.h b/ldso/ldso/i386/dl-startup.h index b0612b923..95609bbb3 100644 --- a/ldso/ldso/i386/dl-startup.h +++ b/ldso/ldso/i386/dl-startup.h @@ -16,6 +16,17 @@ asm( " call 1f\n" "1: popl %ebx\n" " addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx\n" + " # See if we were run as a command with the executable file\n" + " # name as an extra leading argument.\n" + " movl _dl_skip_args@GOTOFF(%ebx), %eax\n" + " # Pop the original argument count.\n" + " popl %edx\n" + " # Adjust the stack pointer to skip _dl_skip_args words.\n" + " leal (%esp,%eax,4), %esp\n" + " # Subtract _dl_skip_args from argc.\n" + " subl %eax, %edx\n" + " # Push argc back on the stack.\n" + " push %edx\n" " # Pass our FINI ptr() to the user in %edx, as per ELF ABI.\n" " leal _dl_fini@GOTOFF(%ebx), %edx\n" " # Jump to the user's entry point.\n" diff --git a/ldso/ldso/i386/elfinterp.c b/ldso/ldso/i386/elfinterp.c index 334b72e20..6292a2df8 100644 --- a/ldso/ldso/i386/elfinterp.c +++ b/ldso/ldso/i386/elfinterp.c @@ -31,73 +31,6 @@ #include "ldso.h" -#if defined (__SUPPORT_LD_DEBUG__) -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 >= (int)(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\n\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"; - - if (_dl_debug_symbols) - _dl_dprintf(_dl_debug_file, "\n\t"); - else - _dl_dprintf(_dl_debug_file, "\n%s\n\t", sym); - -#ifdef ELF_USES_RELOCA - _dl_dprintf(_dl_debug_file, "%s\toffset=%x\taddend=%x", - _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)), - rpnt->r_offset, - rpnt->r_addend); -#else - _dl_dprintf(_dl_debug_file, "%s\toffset=%x\n", - _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)), - rpnt->r_offset); -#endif - } -} -#endif /* __SUPPORT_LD_DEBUG__ */ - /* Program to load an ELF binary on a linux system, and run it. References to symbols in sharable libraries can be resolved by either an ELF sharable library or a linux style of shared library. */ @@ -126,7 +59,6 @@ _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) char *symname; rel_addr = (char *)tpnt->dynamic_info[DT_JMPREL]; - this_reloc = (ELF_RELOC *)(intptr_t)(rel_addr + reloc_entry); reloc_type = ELF32_R_TYPE(this_reloc->r_info); symtab_index = ELF32_R_SYM(this_reloc->r_info); @@ -137,7 +69,7 @@ _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) if (unlikely(reloc_type != R_386_JMP_SLOT)) { _dl_dprintf(2, "%s: Incorrect relocation type in jump relocations\n", - _dl_progname); + _dl_progname); _dl_exit(1); } @@ -159,8 +91,8 @@ _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) _dl_dprintf(_dl_debug_file, "\nresolve function: %s", symname); if (_dl_debug_detail) _dl_dprintf(_dl_debug_file, - "\n\tpatched: %x ==> %x @ %x", - *got_addr, new_addr, got_addr); + "\n\tpatched: %x ==> %x @ %x", + *got_addr, new_addr, got_addr); } } if (!_dl_debug_nofixups) { @@ -197,10 +129,8 @@ _dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope, symtab_index = ELF32_R_SYM(rpnt->r_info); -#if defined (__SUPPORT_LD_DEBUG__) debug_sym(symtab, strtab, symtab_index); debug_reloc(symtab, strtab, rpnt); -#endif res = reloc_fnc(tpnt, scope, rpnt, symtab, strtab); diff --git a/ldso/ldso/m68k/dl-debug.h b/ldso/ldso/m68k/dl-debug.h new file mode 100644 index 000000000..a9a80a067 --- /dev/null +++ b/ldso/ldso/m68k/dl-debug.h @@ -0,0 +1,42 @@ +/* vi: set sw=4 ts=4: */ +/* m68k ELF shared library loader suppport + * + * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald, + * David Engel, Hongjiu Lu and Mitch D'Souza + * Adapted to ELF/68k by Andreas Schwab. + * + * 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. + */ + +static const char *_dl_reltypes_tab[] = { + [0] "R_68K_NONE", + [1] "R_68K_32", "R_68K_16", "R_68K_8", + [4] "R_68K_PC32", "R_68K_PC16", "R_68K_PC8", + [7] "R_68K_GOT32", "R_68K_GOT16", "R_68K_GOT8", + [10] "R_68K_GOT32O", "R_68K_GOT16O", "R_68K_GOT8O", + [13] "R_68K_PLT32", "R_68K_PLT16", "R_68K_PLT8", + [16] "R_68K_PLT32O", "R_68K_PLT16O", "R_68K_PLT8O", + [19] "R_68K_COPY", "R_68K_GLOB_DAT", "R_68K_JMP_SLOT", "R_68K_RELATIVE", + [23] "R_68K_NUM" +}; diff --git a/ldso/ldso/m68k/elfinterp.c b/ldso/ldso/m68k/elfinterp.c index b7d0f362a..c777faa5b 100644 --- a/ldso/ldso/m68k/elfinterp.c +++ b/ldso/ldso/m68k/elfinterp.c @@ -29,21 +29,6 @@ * SUCH DAMAGE. */ -#if defined (__SUPPORT_LD_DEBUG__) -static const char *_dl_reltypes[] = -{ - "R_68K_NONE", - "R_68K_32", "R_68K_16", "R_68K_8", - "R_68K_PC32", "R_68K_PC16", "R_68K_PC8", - "R_68K_GOT32", "R_68K_GOT16", "R_68K_GOT8", - "R_68K_GOT32O", "R_68K_GOT16O", "R_68K_GOT8O", - "R_68K_PLT32", "R_68K_PLT16", "R_68K_PLT8", - "R_68K_PLT32O", "R_68K_PLT16O", "R_68K_PLT8O", - "R_68K_COPY", "R_68K_GLOB_DAT", "R_68K_JMP_SLOT", "R_68K_RELATIVE", - "R_68K_NUM" -}; -#endif - /* Program to load an ELF binary on a linux system, and run it. References to symbols in sharable libraries can be resolved by either an ELF sharable library or a linux style of shared library. */ @@ -55,60 +40,55 @@ 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 int -_dl_linux_resolver (struct elf_resolve *tpnt, int reloc_entry) +_dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) { int reloc_type; - Elf32_Rela *this_reloc; + ELF_RELOC *this_reloc; char *strtab; Elf32_Sym *symtab; - ELF_RELOC *rel_addr; int symtab_index; + ELF_RELOC *rel_addr; char *new_addr; char **got_addr; unsigned int instr_addr; + char *symname; rel_addr = (ELF_RELOC *)tpnt->dynamic_info[DT_JMPREL]; - this_reloc = (Elf32_Rela *) (rel_addr + reloc_entry); - reloc_type = ELF32_R_TYPE (this_reloc->r_info); - symtab_index = ELF32_R_SYM (this_reloc->r_info); + this_reloc = (ELF_RELOC *)(intptr_t)(rel_addr + reloc_entry); + reloc_type = ELF32_R_TYPE(this_reloc->r_info); + symtab_index = ELF32_R_SYM(this_reloc->r_info); - symtab = (Elf32_Sym *)tpnt->dynamic_info[DT_SYMTAB]; + symtab = (Elf32_Sym *)(intptr_t)tpnt->dynamic_info[DT_SYMTAB]; strtab = (char *)tpnt->dynamic_info[DT_STRTAB]; + symname = strtab + symtab[symtab_index].st_name; if (unlikely(reloc_type != R_68K_JMP_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 = (int) this_reloc->r_offset + (int) tpnt->loadaddr; - got_addr = (char **) instr_addr; + /* Address of the jump instruction to fix up. */ + instr_addr = ((int)this_reloc->r_offset + (int)tpnt->loadaddr); + got_addr = (char **)instr_addr; -#ifdef __SUPPORT_LD_DEBUG__ - if (_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, ELF_RTYPE_CLASS_PLT); + /* Get the address of the GOT entry. */ + new_addr = _dl_find_hash(symname, tpnt->symbol_scope, tpnt, ELF_RTYPE_CLASS_PLT); if (unlikely(!new_addr)) { - _dl_dprintf (2, "%s: can't resolve symbol '%s'\n", - _dl_progname, strtab + symtab[symtab_index].st_name); - _dl_exit (1); + _dl_dprintf(2, "%s: Can't resolve symbol '%s'\n", _dl_progname, symname); + _dl_exit(1); } + #if defined (__SUPPORT_LD_DEBUG__) - if ((unsigned long) got_addr < 0x40000000) { + if ((unsigned long)got_addr < 0x40000000) { 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", + _dl_dprintf(_dl_debug_file, "\nresolve function: %s", symname); + if (_dl_debug_detail) + _dl_dprintf(_dl_debug_file, + "\n\tpatched: %x ==> %x @ %x", *got_addr, new_addr, got_addr); } } @@ -119,7 +99,7 @@ _dl_linux_resolver (struct elf_resolve *tpnt, int reloc_entry) *got_addr = new_addr; #endif - return (unsigned int) new_addr; + return (unsigned int)new_addr; } void @@ -157,7 +137,7 @@ _dl_parse_lazy_relocation_information(struct dyn_elf *arg_rpnt, default: _dl_dprintf (2, "%s: (LAZY) can't handle reloc type ", _dl_progname); #if defined (__SUPPORT_LD_DEBUG__) - _dl_dprintf (2, "%s ", _dl_reltypes[reloc_type]); + _dl_dprintf (2, "%s ", _dl_reltypes_tab[reloc_type]); #endif if (symtab_index) _dl_dprintf (2, "'%s'", strtab + symtab[symtab_index].st_name); @@ -254,7 +234,7 @@ _dl_parse_relocation_information(struct dyn_elf *arg_rpnt, default: _dl_dprintf (2, "%s: can't handle reloc type ", _dl_progname); #if defined (__SUPPORT_LD_DEBUG__) - _dl_dprintf (2, "%s ", _dl_reltypes[reloc_type]); + _dl_dprintf (2, "%s ", _dl_reltypes_tab[reloc_type]); #endif if (symtab_index) _dl_dprintf (2, "'%s'", strtab + symtab[symtab_index].st_name); diff --git a/ldso/ldso/powerpc/dl-debug.h b/ldso/ldso/powerpc/dl-debug.h new file mode 100644 index 000000000..cf203d25e --- /dev/null +++ b/ldso/ldso/powerpc/dl-debug.h @@ -0,0 +1,44 @@ +/* vi: set sw=4 ts=4: */ +/* powerpc shared library loader suppport + * + * Copyright (C) 2001-2002 David A. Schleef + * Copyright (C) 2003-2004 Erik Andersen + * Copyright (C) 2004 Joakim Tjernlund + * + * 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. + */ + +static const char *_dl_reltypes_tab[] = + { "R_PPC_NONE", "R_PPC_ADDR32", "R_PPC_ADDR24", "R_PPC_ADDR16", + "R_PPC_ADDR16_LO", "R_PPC_ADDR16_HI", "R_PPC_ADDR16_HA", + "R_PPC_ADDR14", "R_PPC_ADDR14_BRTAKEN", "R_PPC_ADDR14_BRNTAKEN", + "R_PPC_REL24", "R_PPC_REL14", "R_PPC_REL14_BRTAKEN", + "R_PPC_REL14_BRNTAKEN", "R_PPC_GOT16", "R_PPC_GOT16_LO", + "R_PPC_GOT16_HI", "R_PPC_GOT16_HA", "R_PPC_PLTREL24", + "R_PPC_COPY", "R_PPC_GLOB_DAT", "R_PPC_JMP_SLOT", "R_PPC_RELATIVE", + "R_PPC_LOCAL24PC", "R_PPC_UADDR32", "R_PPC_UADDR16", "R_PPC_REL32", + "R_PPC_PLT32", "R_PPC_PLTREL32", "R_PPC_PLT16_LO", "R_PPC_PLT16_HI", + "R_PPC_PLT16_HA", "R_PPC_SDAREL16", "R_PPC_SECTOFF", + "R_PPC_SECTOFF_LO", "R_PPC_SECTOFF_HI", "R_PPC_SECTOFF_HA", +}; diff --git a/ldso/ldso/powerpc/elfinterp.c b/ldso/ldso/powerpc/elfinterp.c index dd2aa5aac..4ec459854 100644 --- a/ldso/ldso/powerpc/elfinterp.c +++ b/ldso/ldso/powerpc/elfinterp.c @@ -29,80 +29,6 @@ * SUCH DAMAGE. */ -#if defined (__SUPPORT_LD_DEBUG__) -static const char *_dl_reltypes_tab[] = - { "R_PPC_NONE", "R_PPC_ADDR32", "R_PPC_ADDR24", "R_PPC_ADDR16", - "R_PPC_ADDR16_LO", "R_PPC_ADDR16_HI", "R_PPC_ADDR16_HA", - "R_PPC_ADDR14", "R_PPC_ADDR14_BRTAKEN", "R_PPC_ADDR14_BRNTAKEN", - "R_PPC_REL24", "R_PPC_REL14", "R_PPC_REL14_BRTAKEN", - "R_PPC_REL14_BRNTAKEN", "R_PPC_GOT16", "R_PPC_GOT16_LO", - "R_PPC_GOT16_HI", "R_PPC_GOT16_HA", "R_PPC_PLTREL24", - "R_PPC_COPY", "R_PPC_GLOB_DAT", "R_PPC_JMP_SLOT", "R_PPC_RELATIVE", - "R_PPC_LOCAL24PC", "R_PPC_UADDR32", "R_PPC_UADDR16", "R_PPC_REL32", - "R_PPC_PLT32", "R_PPC_PLTREL32", "R_PPC_PLT16_LO", "R_PPC_PLT16_HI", - "R_PPC_PLT16_HA", "R_PPC_SDAREL16", "R_PPC_SECTOFF", - "R_PPC_SECTOFF_LO", "R_PPC_SECTOFF_HI", "R_PPC_SECTOFF_HA", -}; - -static const char * -_dl_reltypes(int type) -{ - static char buf[22]; - const char *str; - - if (type >= (int)(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\n\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"; - - if(_dl_debug_symbols) - _dl_dprintf(_dl_debug_file, "\n\t"); - else - _dl_dprintf(_dl_debug_file, "\n%s\n\t", sym); -#ifdef ELF_USES_RELOCA - _dl_dprintf(_dl_debug_file, "%s\toffset=%x\taddend=%x", - _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)), - rpnt->r_offset, - rpnt->r_addend); -#else - _dl_dprintf(_dl_debug_file, "%s\toffset=%x\n", - _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)), - rpnt->r_offset); -#endif - } -} -#endif - extern int _dl_linux_resolve(void); void _dl_init_got(unsigned long *plt,struct elf_resolve *tpnt) @@ -190,10 +116,10 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) strtab = (char *)tpnt->dynamic_info[DT_STRTAB]; symname = strtab + symtab[symtab_index].st_name; -#if defined (__SUPPORT_LD_DEBUG__) debug_sym(symtab,strtab,symtab_index); debug_reloc(symtab,strtab,this_reloc); +#if defined (__SUPPORT_LD_DEBUG__) if (unlikely(ELF32_R_TYPE(this_reloc->r_info) != R_PPC_JMP_SLOT)) { _dl_dprintf(2, "%s: Incorrect relocation type in jump relocation\n", _dl_progname); _dl_exit(1); @@ -437,10 +363,8 @@ _dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope, symtab_index = ELF32_R_SYM(rpnt->r_info); -#if defined (__SUPPORT_LD_DEBUG__) debug_sym(symtab,strtab,symtab_index); debug_reloc(symtab,strtab,rpnt); -#endif res = reloc_fnc (tpnt, scope, rpnt, symtab, strtab); diff --git a/ldso/ldso/sh/dl-debug.h b/ldso/ldso/sh/dl-debug.h new file mode 100644 index 000000000..e862da1ee --- /dev/null +++ b/ldso/ldso/sh/dl-debug.h @@ -0,0 +1,41 @@ +/* vi: set sw=4 ts=4: */ +/* SuperH ELF shared library loader suppport + * + * Copyright (C) 2002, Stefan Allius <allius@atecom.com> and + * Eddie C. Dost <ecd@atecom.com> + * + * 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. + */ + +static const char *_dl_reltypes_tab[] = +{ + [0] "R_SH_NONE", "R_SH_DIR32", "R_SH_REL32", "R_SH_DIR8WPN", + [4] "R_SH_IND12W", "R_SH_DIR8WPL", "R_SH_DIR8WPZ", "R_SH_DIR8BP", + [8] "R_SH_DIR8W", "R_SH_DIR8L", + [25] "R_SH_SWITCH16","R_SH_SWITCH32","R_SH_USES", + [28] "R_SH_COUNT", "R_SH_ALIGN", "R_SH_CODE", "R_SH_DATA", + [32] "R_SH_LABEL", "R_SH_SWITCH8", "R_SH_GNU_VTINHERIT","R_SH_GNU_VTENTRY", +[160] "R_SH_GOT32", "R_SH_PLT32", "R_SH_COPY", "R_SH_GLOB_DAT", +[164] "R_SH_JMP_SLOT","R_SH_RELATIVE","R_SH_GOTOFF", "R_SH_GOTPC", +}; diff --git a/ldso/ldso/sh/elfinterp.c b/ldso/ldso/sh/elfinterp.c index 794910c6d..393435bbb 100644 --- a/ldso/ldso/sh/elfinterp.c +++ b/ldso/ldso/sh/elfinterp.c @@ -28,78 +28,6 @@ * SUCH DAMAGE. */ -#if defined (__SUPPORT_LD_DEBUG__) -static const char *_dl_reltypes_tab[] = -{ - [0] "R_SH_NONE", "R_SH_DIR32", "R_SH_REL32", "R_SH_DIR8WPN", - [4] "R_SH_IND12W", "R_SH_DIR8WPL", "R_SH_DIR8WPZ", "R_SH_DIR8BP", - [8] "R_SH_DIR8W", "R_SH_DIR8L", - [25] "R_SH_SWITCH16","R_SH_SWITCH32","R_SH_USES", - [28] "R_SH_COUNT", "R_SH_ALIGN", "R_SH_CODE", "R_SH_DATA", - [32] "R_SH_LABEL", "R_SH_SWITCH8", "R_SH_GNU_VTINHERIT","R_SH_GNU_VTENTRY", -[160] "R_SH_GOT32", "R_SH_PLT32", "R_SH_COPY", "R_SH_GLOB_DAT", -[164] "R_SH_JMP_SLOT","R_SH_RELATIVE","R_SH_GOTOFF", "R_SH_GOTPC", -}; - -static const char * -_dl_reltypes(int type) -{ - static char buf[22]; - const char *str; - - if (type >= (int)(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"; - - if(_dl_debug_symbols) - _dl_dprintf(_dl_debug_file, "\n\t"); - else - _dl_dprintf(_dl_debug_file, "\n%s\n\t", sym); - -#ifdef ELF_USES_RELOCA - _dl_dprintf(_dl_debug_file, "%s\toffset=%x\taddend=%x", - _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)), - rpnt->r_offset, - rpnt->r_addend); -#else - _dl_dprintf(_dl_debug_file, "%s\toffset=%x\n", - _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)), - rpnt->r_offset); -#endif - } -} -#endif - /* Program to load an ELF binary on a linux system, and run it. References to symbols in sharable libraries can be resolved by either an ELF sharable library or a linux style of shared library. */ @@ -199,10 +127,8 @@ _dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope, int res; symtab_index = ELF32_R_SYM(rpnt->r_info); -#if defined (__SUPPORT_LD_DEBUG__) debug_sym(symtab,strtab,symtab_index); debug_reloc(symtab,strtab,rpnt); -#endif res = reloc_fnc (tpnt, scope, rpnt, symtab, strtab); diff --git a/ldso/ldso/sh64/dl-debug.h b/ldso/ldso/sh64/dl-debug.h new file mode 100644 index 000000000..485aac7fa --- /dev/null +++ b/ldso/ldso/sh64/dl-debug.h @@ -0,0 +1,79 @@ +/* vi: set sw=8 ts=8: */ +/* + * ldso/ldso/sh64/elfinterp.c + * + * SuperH (sh64) ELF shared library loader suppport + * + * Copyright (C) 2003, 2004, 2005 Paul Mundt <lethal@linux-sh.org> + * + * 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. + */ + +static const char *_dl_reltypes_tab[] = { + /* SHcompact relocs */ + [0] = "R_SH_NONE", "R_SH_DIR32", + "R_SH_REL32", "R_SH_DIR8WPN", + [4] = "R_SH_IND12W", "R_SH_DIR8WPL", + "R_SH_DIR8WPZ", "R_SH_DIR8BP", + [8] = "R_SH_DIR8W", "R_SH_DIR8L", + [25] = "R_SH_SWITCH16", "R_SH_SWITCH32", + "R_SH_USES", "R_SH_COUNT", + [29] = "R_SH_ALIGN", "R_SH_CODE", + "R_SH_DATA", "R_SH_LABEL", + [33] = "R_SH_SWITCH8", "R_SH_GNU_VTINHERIT", + "R_SH_GNU_VTENTRY", + [160] = "R_SH_GOT32", "R_SH_PLT32", + "R_SH_COPY", "R_SH_GLOB_DAT", + [164] = "R_SH_JMP_SLOT", "R_SH_RELATIVE", + "R_SH_GOTOFF", "R_SH_GOTPC", + + /* SHmedia relocs */ + [45] = "R_SH_DIR5U", "R_SH_DIR6U", + "R_SH_DIR6S", "R_SH_DIR10S", + [49] = "R_SH_DIR10SW", "R_SH_DIR10SL", + "R_SH_DIR10SQ", + [169] = "R_SH_GOT_LOW16", "R_SH_GOT_MEDLOW16", + "R_SH_GOT_MEDHI16", "R_SH_GOT_HI16", + [173] = "R_SH_GOTPLT_LOW16", "R_SH_GOTPLT_MEDLOW16", + "R_SH_GOTPLT_MEDHI16", "R_SH_GOTPLT_HI16", + [177] = "R_SH_PLT_LOW16", "R_SH_PLT_MEDLOW16", + "R_SH_PLT_MEDHI16", "R_SH_PLT_HI16", + [181] = "R_SH_GOTOFF_LOW16", "R_SH_GOTOFF_MEDLOW16", + "R_SH_GOTOFF_MEDHI16", "R_SH_GOTOFF_HI16", + [185] = "R_SH_GOTPC_LOW16", "R_SH_GOTPC_MEDLOW16", + "R_SH_GOTPC_MEDHI16", "R_SH_GOTPC_HI16", + [189] = "R_SH_GOT10BY4", "R_SH_GOTPLT10BY4", + "R_SH_GOT10BY8", "R_SH_GOTPLT10BY8", + [193] = "R_SH_COPY64", "R_SH_GLOB_DAT64", + "R_SH_JMP_SLOT64", "R_SH_RELATIVE64", + [197] = "R_SH_RELATIVE_LOW16", "R_SH_RELATIVE_MEDLOW16", + "R_SH_RELATIVE_MEDHI16","R_SH_RELATIVE_HI16", + [242] = "R_SH_SHMEDIA_CODE", "R_SH_PT_16", + "R_SH_IMMS16", "R_SH_IMMU16", + [246] = "R_SH_IMM_LOW16", "R_SH_IMM_LOW16_PCREL", + "R_SH_IMM_MEDLOW16", "R_SH_IMM_MEDLOW16_PCREL", + [250] = "R_SH_IMM_MEDHI16", "R_SH_IMM_MEDHI16_PCREL", + "R_SH_IMM_HI16", "R_SH_IMM_HI16_PCREL", + [254] = "R_SH_64", "R_SH_64_PCREL", +}; diff --git a/ldso/ldso/sh64/elfinterp.c b/ldso/ldso/sh64/elfinterp.c index 6ac096b32..c20314a85 100644 --- a/ldso/ldso/sh64/elfinterp.c +++ b/ldso/ldso/sh64/elfinterp.c @@ -30,116 +30,6 @@ * SUCH DAMAGE. */ -#ifdef __SUPPORT_LD_DEBUG__ -static const char *_dl_reltypes_tab[] = { - /* SHcompact relocs */ - [0] = "R_SH_NONE", "R_SH_DIR32", - "R_SH_REL32", "R_SH_DIR8WPN", - [4] = "R_SH_IND12W", "R_SH_DIR8WPL", - "R_SH_DIR8WPZ", "R_SH_DIR8BP", - [8] = "R_SH_DIR8W", "R_SH_DIR8L", - [25] = "R_SH_SWITCH16", "R_SH_SWITCH32", - "R_SH_USES", "R_SH_COUNT", - [29] = "R_SH_ALIGN", "R_SH_CODE", - "R_SH_DATA", "R_SH_LABEL", - [33] = "R_SH_SWITCH8", "R_SH_GNU_VTINHERIT", - "R_SH_GNU_VTENTRY", - [160] = "R_SH_GOT32", "R_SH_PLT32", - "R_SH_COPY", "R_SH_GLOB_DAT", - [164] = "R_SH_JMP_SLOT", "R_SH_RELATIVE", - "R_SH_GOTOFF", "R_SH_GOTPC", - - /* SHmedia relocs */ - [45] = "R_SH_DIR5U", "R_SH_DIR6U", - "R_SH_DIR6S", "R_SH_DIR10S", - [49] = "R_SH_DIR10SW", "R_SH_DIR10SL", - "R_SH_DIR10SQ", - [169] = "R_SH_GOT_LOW16", "R_SH_GOT_MEDLOW16", - "R_SH_GOT_MEDHI16", "R_SH_GOT_HI16", - [173] = "R_SH_GOTPLT_LOW16", "R_SH_GOTPLT_MEDLOW16", - "R_SH_GOTPLT_MEDHI16", "R_SH_GOTPLT_HI16", - [177] = "R_SH_PLT_LOW16", "R_SH_PLT_MEDLOW16", - "R_SH_PLT_MEDHI16", "R_SH_PLT_HI16", - [181] = "R_SH_GOTOFF_LOW16", "R_SH_GOTOFF_MEDLOW16", - "R_SH_GOTOFF_MEDHI16", "R_SH_GOTOFF_HI16", - [185] = "R_SH_GOTPC_LOW16", "R_SH_GOTPC_MEDLOW16", - "R_SH_GOTPC_MEDHI16", "R_SH_GOTPC_HI16", - [189] = "R_SH_GOT10BY4", "R_SH_GOTPLT10BY4", - "R_SH_GOT10BY8", "R_SH_GOTPLT10BY8", - [193] = "R_SH_COPY64", "R_SH_GLOB_DAT64", - "R_SH_JMP_SLOT64", "R_SH_RELATIVE64", - [197] = "R_SH_RELATIVE_LOW16", "R_SH_RELATIVE_MEDLOW16", - "R_SH_RELATIVE_MEDHI16","R_SH_RELATIVE_HI16", - [242] = "R_SH_SHMEDIA_CODE", "R_SH_PT_16", - "R_SH_IMMS16", "R_SH_IMMU16", - [246] = "R_SH_IMM_LOW16", "R_SH_IMM_LOW16_PCREL", - "R_SH_IMM_MEDLOW16", "R_SH_IMM_MEDLOW16_PCREL", - [250] = "R_SH_IMM_MEDHI16", "R_SH_IMM_MEDHI16_PCREL", - "R_SH_IMM_HI16", "R_SH_IMM_HI16_PCREL", - [254] = "R_SH_64", "R_SH_64_PCREL", -}; - -static const char *_dl_reltypes(int type) -{ - static char buf[22]; - const char *str; - int tabsize; - - tabsize = sizeof(_dl_reltypes_tab)/sizeof(_dl_reltypes_tab[0]); - str = _dl_reltypes_tab[type]; - - if (type >= tabsize || str == NULL) - 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 || !symtab_index) - return; - - _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) - return; - - if (_dl_debug_symbols) { - _dl_dprintf(_dl_debug_file, "\n\t"); - } else { - 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"; - - _dl_dprintf(_dl_debug_file, "\n%s\n\t", sym); - } - - _dl_dprintf(_dl_debug_file, "%s\toffset=%x", - _dl_reltypes(ELF32_R_TYPE(rpnt->r_info)), - rpnt->r_offset); - -#ifdef ELF_USES_RELOCA - _dl_dprintf(_dl_debug_file, "\taddend=%x", rpnt->r_addend); -#endif - - _dl_dprintf(_dl_debug_file, "\n"); - -} -#endif /* __SUPPORT_LD_DEBUG__ */ - /* Program to load an ELF binary on a linux system, and run it. References to symbols in sharable libraries can be resolved by either an ELF sharable library or a linux style of shared library. */ @@ -242,10 +132,8 @@ static int _dl_parse(struct elf_resolve *tpnt, struct dyn_elf *scope, int res; symtab_index = ELF32_R_SYM(rpnt->r_info); -#ifdef __SUPPORT_LD_DEBUG__ debug_sym(symtab,strtab,symtab_index); debug_reloc(symtab,strtab,rpnt); -#endif res = reloc_fnc (tpnt, scope, rpnt, symtab, strtab); if (res == 0) diff --git a/ldso/ldso/sparc/dl-debug.h b/ldso/ldso/sparc/dl-debug.h new file mode 100644 index 000000000..1249f7798 --- /dev/null +++ b/ldso/ldso/sparc/dl-debug.h @@ -0,0 +1,40 @@ +/* vi: set sw=4 ts=4: */ +/* sparc ELF shared library loader suppport + * + * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald, + * David Engel, Hongjiu Lu and Mitch D'Souza + * + * 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. + */ + +static const char * _dl_reltypes_tab[] = { + "R_SPARC_NONE", "R_SPARC_8", + "R_SPARC_16", "R_SPARC_32", "R_SPARC_DISP8", "R_SPARC_DISP16", + "R_SPARC_DISP32", "R_SPARC_WDISP30", "R_SPARC_WDISP22", + "R_SPARC_HI22", "R_SPARC_22", "R_SPARC_13", "R_SPARC_LO10", + "R_SPARC_GOT10", "R_SPARC_GOT13", "R_SPARC_GOT22", "R_SPARC_PC10", + "R_SPARC_PC22", "R_SPARC_WPLT30", "R_SPARC_COPY", + "R_SPARC_GLOB_DAT", "R_SPARC_JMP_SLOT", "R_SPARC_RELATIVE", + "R_SPARC_UA32" +}; diff --git a/ldso/ldso/sparc/dl-startup.h b/ldso/ldso/sparc/dl-startup.h index ce51aa244..73db327bd 100644 --- a/ldso/ldso/sparc/dl-startup.h +++ b/ldso/ldso/sparc/dl-startup.h @@ -4,13 +4,13 @@ * can be done. */ asm( - " .text\n" - " .globl _start\n" - " .type _start,@function\n" - "_start:\n" - " .set _start,_dl_start\n" - " .size _start,.-_start\n" - " .previous\n" + " .text\n" + " .global _start\n" + " .type _start,%function\n" + "_start:\n" + " .set _start,_dl_start\n" + " .size _start,.-_start\n" + " .previous\n" ); /* @@ -26,39 +26,38 @@ asm( * bootstrapping the dynamic loader. */ #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \ - switch(ELF32_R_TYPE((RELP)->r_info)) { \ - case R_SPARC_32: \ - *REL = SYMBOL + (RELP)->r_addend; \ - break; \ - case R_SPARC_GLOB_DAT: \ - *REL = SYMBOL + (RELP)->r_addend; \ - break; \ - case R_SPARC_JMP_SLOT: \ - REL[1] = 0x03000000 | ((SYMBOL >> 10) & 0x3fffff); \ - REL[2] = 0x81c06000 | (SYMBOL & 0x3ff); \ - break; \ - case R_SPARC_NONE: \ - break; \ - case R_SPARC_WDISP30: \ - break; \ - case R_SPARC_RELATIVE: \ - *REL += (unsigned int) LOAD + (RELP)->r_addend; \ - break; \ - default: \ - _dl_exit(1); \ + switch(ELF32_R_TYPE((RELP)->r_info)) { \ + case R_SPARC_32: \ + *REL = SYMBOL + (RELP)->r_addend; \ + break; \ + case R_SPARC_GLOB_DAT: \ + *REL = SYMBOL + (RELP)->r_addend; \ + break; \ + case R_SPARC_JMP_SLOT: \ + REL[1] = 0x03000000 | ((SYMBOL >> 10) & 0x3fffff); \ + REL[2] = 0x81c06000 | (SYMBOL & 0x3ff); \ + break; \ + case R_SPARC_NONE: \ + break; \ + case R_SPARC_WDISP30: \ + break; \ + case R_SPARC_RELATIVE: \ + *REL += (unsigned int) LOAD + (RELP)->r_addend; \ + break; \ + default: \ + _dl_exit(1); \ } - /* * Transfer control to the user's application, once the dynamic loader * is done. The crt calls atexit with $g1 if not null, so we need to * ensure that it contains NULL. */ -#define START() \ +#define START() \ __asm__ volatile ( \ - "add %%g0,%%g0,%%g1\n\t" \ - "jmpl %0, %%o7\n\t" \ - "restore %%g0,%%g0,%%g0\n\t" \ - : /*"=r" (status) */ : \ - "r" (_dl_elf_main): "g1", "o0", "o1") + "add %%g0,%%g0,%%g1\n\t" \ + "jmpl %0, %%o7\n\t" \ + "restore %%g0,%%g0,%%g0\n\t" \ + : /*"=r" (status) */ : \ + "r" (_dl_elf_main): "g1", "o0", "o1") diff --git a/ldso/ldso/sparc/elfinterp.c b/ldso/ldso/sparc/elfinterp.c index a84507b91..8b169b575 100644 --- a/ldso/ldso/sparc/elfinterp.c +++ b/ldso/ldso/sparc/elfinterp.c @@ -28,17 +28,6 @@ * SUCH DAMAGE. */ -#if defined (__SUPPORT_LD_DEBUG__) -static const char * _dl_reltypes[] = { "R_SPARC_NONE", "R_SPARC_8", - "R_SPARC_16", "R_SPARC_32", "R_SPARC_DISP8", "R_SPARC_DISP16", - "R_SPARC_DISP32", "R_SPARC_WDISP30", "R_SPARC_WDISP22", - "R_SPARC_HI22", "R_SPARC_22", "R_SPARC_13", "R_SPARC_LO10", - "R_SPARC_GOT10", "R_SPARC_GOT13", "R_SPARC_GOT22", "R_SPARC_PC10", - "R_SPARC_PC22", "R_SPARC_WPLT30", "R_SPARC_COPY", - "R_SPARC_GLOB_DAT", "R_SPARC_JMP_SLOT", "R_SPARC_RELATIVE", - "R_SPARC_UA32"}; -#endif - /* Program to load an ELF binary on a linux system, and run it. References to symbols in sharable libraries can be resolved by either an ELF sharable library or a linux style of shared library. */ @@ -176,7 +165,7 @@ void _dl_parse_lazy_relocation_information(struct dyn_elf *arg_rpnt, default: _dl_dprintf(2, "%s: (LAZY) can't handle reloc type ", _dl_progname); #if defined (__SUPPORT_LD_DEBUG__) - _dl_dprintf(2, "%s ", _dl_reltypes[reloc_type]); + _dl_dprintf(2, "%s ", _dl_reltypes_tab[reloc_type]); #endif if(symtab_index) _dl_dprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name); @@ -267,7 +256,7 @@ int _dl_parse_relocation_information(struct dyn_elf *arg_rpnt, default: _dl_dprintf(2, "%s: can't handle reloc type ", _dl_progname); #if defined (__SUPPORT_LD_DEBUG__) - _dl_dprintf(2, "%s ", _dl_reltypes[reloc_type]); + _dl_dprintf(2, "%s ", _dl_reltypes_tab[reloc_type]); #endif if (symtab_index) _dl_dprintf(2, "'%s'\n", strtab + symtab[symtab_index].st_name); diff --git a/ldso/ldso/x86_64/dl-debug.h b/ldso/ldso/x86_64/dl-debug.h new file mode 100644 index 000000000..21412bd03 --- /dev/null +++ b/ldso/ldso/x86_64/dl-debug.h @@ -0,0 +1,36 @@ +/* vi: set sw=4 ts=4: */ +/* x86_64 debug code for ELF shared library loader suppport + * + * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald, + * David Engel, Hongjiu Lu and Mitch D'Souza + * Copyright (C) 2001-2004 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. + */ + +static const char *_dl_reltypes_tab[] = { + [0] "R_X86_64_NONE", "R_X86_64_64", "R_X86_64_PC32", "R_X86_64_GOT32", + [4] "R_X86_64_PLT32", "R_X86_64_COPY", "R_X86_64_GLOB_DAT", "R_X86_64_JUMP_SLOT", + [8] "R_X86_64_RELATIVE", "R_X86_64_GOTPCREL", "R_X86_64_32" +}; diff --git a/ldso/ldso/x86_64/dl-startup.h b/ldso/ldso/x86_64/dl-startup.h new file mode 100644 index 000000000..eb2e0b7f4 --- /dev/null +++ b/ldso/ldso/x86_64/dl-startup.h @@ -0,0 +1,70 @@ +/* vi: set sw=4 ts=4: */ +/* + * Architecture specific code used by dl-startup.c + * Copyright (C) 2000-2005 by Erik Andersen <andersen@codepoet.org> + * Copyright (C) 2005 by Mike Frysinger <vapier@gentoo.org> + * + * Parts taken from glibc/sysdeps/x86_64/dl-machine.h + */ +asm( + " .text\n" + " .align 16\n" + " .global _start\n" + " .type _start,%function\n" + "_start:\n" + " movq %rsp, %rdi\n" + " call _dl_start\n" + " # Save the user entry point address in %r12.\n" + " movq %rax, %r12\n" + " # See if we were run as a command with the executable file\n" + " # name as an extra leading argument.\n" + " movl _dl_skip_args(%rip), %eax\n" + " # Pop the original argument count.\n" + " popq %rdx\n" + " # Adjust the stack pointer to skip _dl_skip_args words.\n" + " leaq (%rsp,%rax,8), %rsp\n" + " # Subtract _dl_skip_args from argc.\n" + " subl %eax, %edx\n" + " # Push argc back on the stack.\n" + " pushq %rdx\n" + " # Pass our finalizer function to the user in %rdx, as per ELF ABI.\n" + " leaq _dl_fini(%rip), %rdx\n" + " # Jump to the user's entry point.\n" + " jmp *%r12\n" + " .size _start,.-_start\n" + " .previous\n" +); + +/* Get a pointer to the argv array. On many platforms this can be just + * the address if the first argument, on other platforms we need to + * do something a little more subtle here. */ +#define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*) ARGS)+1) + +/* Handle relocation of the symbols in the dynamic loader. */ +static __always_inline +void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr, + unsigned long symbol_addr, unsigned long load_addr, Elf64_Sym *sym) +{ + switch (ELF64_R_TYPE(rpnt->r_info)) { + case R_X86_64_GLOB_DAT: + case R_X86_64_JUMP_SLOT: + *reloc_addr = symbol_addr + rpnt->r_addend; + break; + case R_X86_64_DTPMOD64: + *reloc_addr = 1; + break; + case R_X86_64_NONE: + case R_X86_64_DTPOFF64: + break; + case R_X86_64_TPOFF64: + *reloc_addr = sym->st_value + rpnt->r_addend - symbol_addr; + break; + default: + _dl_exit(1); + } +} + +/* Transfer control to the user's application, once the dynamic loader is + * done. This routine has to exit the current function, then call the + * _dl_elf_main function. */ +#define START() return _dl_elf_main diff --git a/ldso/ldso/x86_64/dl-syscalls.h b/ldso/ldso/x86_64/dl-syscalls.h new file mode 100644 index 000000000..dc0cc6164 --- /dev/null +++ b/ldso/ldso/x86_64/dl-syscalls.h @@ -0,0 +1,5 @@ +/* We can't use the real errno in ldso, since it has not yet + * been dynamicly linked in yet. */ +extern int _dl_errno; +#define __set_errno(X) {(_dl_errno) = (X);} +#include "sys/syscall.h" diff --git a/ldso/ldso/x86_64/dl-sysdep.h b/ldso/ldso/x86_64/dl-sysdep.h new file mode 100644 index 000000000..ae12deb0d --- /dev/null +++ b/ldso/ldso/x86_64/dl-sysdep.h @@ -0,0 +1,115 @@ +/* vi: set sw=4 ts=4: */ +/* yoinked from glibc/sysdeps/x86_64/dl-machine.h */ +/* Machine-dependent ELF dynamic relocation inline functions. x86-64 version. + Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Andreas Jaeger <aj@suse.de>. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* Define this if the system uses RELOCA. */ +#define ELF_USES_RELOCA +#include <elf.h> +#include <link.h> +/* Initialization sequence for the GOT. */ +#define INIT_GOT(GOT_BASE,MODULE) \ +do { \ + GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \ + GOT_BASE[1] = (unsigned long) MODULE; \ +} while(0) + +/* Here we define the magic numbers that this dynamic loader should accept */ +#define MAGIC1 EM_X86_64 +#undef MAGIC2 + +/* Used for error messages */ +#define ELF_TARGET "x86_64" + +struct elf_resolve; +extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry); + +#define do_rem(result, n, base) ((result) = (n) % (base)) + +/* 4096 bytes alignment */ +#define PAGE_ALIGN 0xfffff000 +#define ADDR_ALIGN 0xfff +#define OFFS_ALIGN 0x7ffff000 + +/* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or + TLS variable, so undefined references should not be allowed to + define the value. + ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one + of the main executable's symbols, as for a COPY reloc. */ +#define elf_machine_type_class(type) \ + ((((type) == R_X86_64_JUMP_SLOT) * ELF_RTYPE_CLASS_PLT) \ + | (((type) == R_X86_64_COPY) * ELF_RTYPE_CLASS_COPY)) + +/* Return the link-time address of _DYNAMIC. Conveniently, this is the + first element of the GOT. This must be inlined in a function which + uses global data. */ +static __always_inline Elf64_Addr __attribute__ ((unused)) +elf_machine_dynamic (void) +{ + Elf64_Addr addr; + + /* This works because we have our GOT address available in the small PIC + model. */ + addr = (Elf64_Addr) &_DYNAMIC; + + return addr; +} + + +/* Return the run-time load address of the shared object. */ +static __always_inline Elf64_Addr __attribute__ ((unused)) +elf_machine_load_address (void) +{ + register Elf64_Addr addr, tmp; + + /* The easy way is just the same as on x86: + leaq _dl_start, %0 + leaq _dl_start(%%rip), %1 + subq %0, %1 + but this does not work with binutils since we then have + a R_X86_64_32S relocation in a shared lib. + + Instead we store the address of _dl_start in the data section + and compare it with the current value that we can get via + an RIP relative addressing mode. */ + + asm ("movq 1f(%%rip), %1\n" + "0:\tleaq _dl_start(%%rip), %0\n\t" + "subq %1, %0\n\t" + ".section\t.data\n" + "1:\t.quad _dl_start\n\t" + ".previous\n\t" + : "=r" (addr), "=r" (tmp) : : "cc"); + + return addr; +} + +static __always_inline void +elf_machine_relative(Elf64_Addr load_off, const Elf64_Addr rel_addr, + Elf64_Word relative_count) +{ + Elf64_Rela *rpnt = (Elf64_Rela*)rel_addr; + --rpnt; + do { + Elf64_Addr *const reloc_addr = (Elf64_Addr*)(load_off + (++rpnt)->r_offset); + + *reloc_addr = load_off + rpnt->r_addend; + } while (--relative_count); +} diff --git a/ldso/ldso/x86_64/elfinterp.c b/ldso/ldso/x86_64/elfinterp.c new file mode 100644 index 000000000..66552d879 --- /dev/null +++ b/ldso/ldso/x86_64/elfinterp.c @@ -0,0 +1,324 @@ +/* vi: set sw=4 ts=4: */ +/* x86_64 ELF shared library loader suppport + * + * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald, + * David Engel, Hongjiu Lu and Mitch D'Souza + * Copyright (C) 2001-2004 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. + */ + +#include "ldso.h" + +/* Program to load an ELF binary on a linux system, and run it. + References to symbols in sharable libraries can be resolved by either + an ELF sharable library or a linux style of shared library. */ + +/* Disclaimer: I have never seen any AT&T source code for SVr4, nor have + I ever taken any courses on internals. This program was developed using + information available through the book "UNIX SYSTEM V RELEASE 4, + Programmers guide: Ansi C and Programming Support Tools", which did + 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; + ELF_RELOC *this_reloc; + char *strtab; + ElfW(Sym) *symtab; + int symtab_index; + char *rel_addr; + char *new_addr; + char **got_addr; + ElfW(Addr) instr_addr; + char *symname; + + rel_addr = (char *)tpnt->dynamic_info[DT_JMPREL]; + this_reloc = (ELF_RELOC *)(rel_addr + reloc_entry); + reloc_type = ELF_R_TYPE(this_reloc->r_info); + symtab_index = ELF_R_SYM(this_reloc->r_info); + + symtab = (ElfW(Sym) *)tpnt->dynamic_info[DT_SYMTAB]; + strtab = (char *)tpnt->dynamic_info[DT_STRTAB]; + symname = strtab + symtab[symtab_index].st_name; + + if (unlikely(reloc_type != R_X86_64_JUMP_SLOT)) { + _dl_dprintf(2, "%s: Incorrect relocation type in jump relocations\n", + _dl_progname); + _dl_exit(1); + } + + /* Address of the jump instruction to fix up. */ + instr_addr = (this_reloc->r_offset + tpnt->loadaddr); + got_addr = (char **)instr_addr; + + /* Get the address of the GOT entry. */ + new_addr = _dl_find_hash(symname, tpnt->symbol_scope, tpnt, ELF_RTYPE_CLASS_PLT); + if (unlikely(!new_addr)) { + _dl_dprintf(2, "%s: Can't resolve symbol '%s'\n", _dl_progname, symname); + _dl_exit(1); + } + +#if defined (__SUPPORT_LD_DEBUG__) + if ((unsigned long)got_addr < 0x40000000) { + if (_dl_debug_bindings) { + _dl_dprintf(_dl_debug_file, "\nresolve function: %s", symname); + if (_dl_debug_detail) + _dl_dprintf(_dl_debug_file, + "\tpatched: %x ==> %x @ %x\n", + *got_addr, new_addr, got_addr); + } + } + if (!_dl_debug_nofixups) +#endif + *got_addr = new_addr; + + return (unsigned long)new_addr; +} + +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, ElfW(Sym) *symtab, char *strtab)) +{ + unsigned int i; + char *strtab; + ElfW(Sym) *symtab; + ELF_RELOC *rpnt; + int symtab_index; + + /* Parse the relocation information. */ + rpnt = (ELF_RELOC *)rel_addr; + rel_size /= sizeof(ELF_RELOC); + + symtab = (ElfW(Sym) *)tpnt->dynamic_info[DT_SYMTAB]; + strtab = (char *)tpnt->dynamic_info[DT_STRTAB]; + + for (i = 0; i < rel_size; i++, rpnt++) { + int res; + + symtab_index = ELF_R_SYM(rpnt->r_info); + + debug_sym(symtab, strtab, symtab_index); + debug_reloc(symtab, strtab, rpnt); + + 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 (unlikely(res < 0)) { + int reloc_type = ELF_R_TYPE(rpnt->r_info); + + _dl_dprintf(2, "can't handle reloc type " +#if defined (__SUPPORT_LD_DEBUG__) + "%s\n", _dl_reltypes(reloc_type)); +#else + "%x\n", reloc_type); +#endif + _dl_exit(-res); + } else if (unlikely(res > 0)) { + _dl_dprintf(2, "can't resolve symbol\n"); + return res; + } + } + + return 0; +} + +static int +_dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope, + ELF_RELOC *rpnt, ElfW(Sym) *symtab, char *strtab) +{ + int reloc_type; + int symtab_index; + char *symname; + ElfW(Addr) *reloc_addr; + ElfW(Addr) symbol_addr; +#if defined (__SUPPORT_LD_DEBUG__) + ElfW(Addr) old_val; +#endif + + reloc_addr = (ElfW(Addr)*)(tpnt->loadaddr + (unsigned long)rpnt->r_offset); + reloc_type = ELF_R_TYPE(rpnt->r_info); + symtab_index = ELF_R_SYM(rpnt->r_info); + symbol_addr = 0; + symname = strtab + symtab[symtab_index].st_name; + + if (symtab_index) { + symbol_addr = (ElfW(Addr))_dl_find_hash(symname, scope, tpnt, + elf_machine_type_class(reloc_type)); + /* + * 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 (unlikely(!symbol_addr && ELF_ST_BIND(symtab[symtab_index].st_info) != STB_WEAK)) { + _dl_dprintf(2, "%s: can't resolve symbol '%s'\n", _dl_progname, symname); + _dl_exit(1); + }; + } + +#if defined (__SUPPORT_LD_DEBUG__) + old_val = *reloc_addr; +#endif + + switch (reloc_type) { + case R_X86_64_NONE: + break; + + case R_X86_64_64: + *reloc_addr = symbol_addr + rpnt->r_addend; + break; + + case R_X86_64_PC32: + *reloc_addr = symbol_addr + rpnt->r_addend - rpnt->r_offset; + break; + + case R_X86_64_GLOB_DAT: + case R_X86_64_JUMP_SLOT: + *reloc_addr = symbol_addr; + break; + + /* handled by elf_machine_relative() + case R_X86_64_RELATIVE: + *reloc_addr = map->l_addr + rpnt->r_addend; + break; + */ +#if 0 + case R_X86_64_DTPMOD64: + break; + case R_X86_64_DTPOFF64: + *reloc_addr = symbol_addr + rpnt->r_addend; + break; + case R_X86_64_TPOFF64: + *reloc_addr = symbol_addr + rpnt->r_addend; + break; + case R_X86_64_32: + *reloc_addr = symbol_addr + rpnt->r_addend; + break; + +#endif + case R_X86_64_COPY: + if (symbol_addr) { +#if defined (__SUPPORT_LD_DEBUG__) + if (_dl_debug_move) + _dl_dprintf(_dl_debug_file, + "\t%s move %d bytes from %x to %x\n", + symname, symtab[symtab_index].st_size, + symbol_addr, reloc_addr); +#endif + + _dl_memcpy((char *)reloc_addr, + (char *)symbol_addr, + symtab[symtab_index].st_size); + } else + _dl_dprintf(_dl_debug_file, "no symbol_addr to copy !?\n"); + break; + + default: + return -1; /* Calls _dl_exit(1). */ + } + +#if defined (__SUPPORT_LD_DEBUG__) + if (_dl_debug_reloc && _dl_debug_detail) + _dl_dprintf(_dl_debug_file, "\tpatched: %x ==> %x @ %x\n", + old_val, *reloc_addr, reloc_addr); +#endif + + return 0; +} + +#if 0 +static int +_dl_do_lazy_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope, + ELF_RELOC *rpnt, ElfW(Sym) *symtab, char *strtab) +{ + int reloc_type; + int symtab_index; + ElfW(Addr) *reloc_addr; +#if defined (__SUPPORT_LD_DEBUG__) + ElfW(Addr) old_val; +#endif + + (void)scope; + symtab_index = ELF_R_SYM(rpnt->r_info); + (void)strtab; + + reloc_addr = (ElfW(Addr)*)(tpnt->loadaddr + rpnt->r_offset); + reloc_type = ELF_R_TYPE(rpnt->r_info); + +#if defined (__SUPPORT_LD_DEBUG__) + old_val = *reloc_addr; +#endif + + switch (reloc_type) { + case R_X86_64_NONE: + break; + case R_X86_64_JUMP_SLOT: + *reloc_addr = tpnt->loadaddr + symtab[symtab_index].st_value; + break; + default: + _dl_exit(1); + } + +#if defined (__SUPPORT_LD_DEBUG__) + if (_dl_debug_reloc && _dl_debug_detail) + _dl_dprintf(_dl_debug_file, "\tpatched_lazy: %x ==> %x @ %x\n", + old_val, *reloc_addr, reloc_addr); +#endif + + return 0; +} +#endif + +void +_dl_parse_lazy_relocation_information(struct dyn_elf *rpnt, + unsigned long rel_addr, + unsigned long rel_size) +{ + _dl_parse_relocation_information(rpnt, rel_addr, rel_size); +/* jump slot isnt working + (void)_dl_parse(rpnt->dyn, NULL, rel_addr, rel_size, _dl_do_lazy_reloc); +*/ +} + +int +_dl_parse_relocation_information(struct dyn_elf *rpnt, + unsigned long rel_addr, + unsigned long rel_size) +{ + return _dl_parse(rpnt->dyn, rpnt->dyn->symbol_scope, rel_addr, rel_size, _dl_do_reloc); +} diff --git a/libc/string/powerpc/string.c b/libc/string/powerpc/string.c index 1835e6aa7..acd5d0144 100644 --- a/libc/string/powerpc/string.c +++ b/libc/string/powerpc/string.c @@ -32,15 +32,16 @@ #include <locale.h> /* for __LOCALE_C_ONLY */ #ifdef L_memcpy -void *memcpy(void *to, const void *from, size_t n) +void attribute_hidden *__memcpy(void *to, const void *from, size_t n) /* PPC can do pre increment and load/store, but not post increment and load/store. Therefore use *++ptr instead of *ptr++. */ { unsigned long rem, chunks, tmp1, tmp2; - void *tmp_to; + unsigned char *tmp_to; + unsigned char *tmp_from = (unsigned char *)from; chunks = n / 8; - from -= 4; + tmp_from -= 4; tmp_to = to - 4; if (!chunks) goto lessthan8; @@ -50,9 +51,9 @@ void *memcpy(void *to, const void *from, size_t n) copy_chunks: do { /* make gcc to load all data, then store it */ - tmp1 = *(unsigned long *)(from+4); - from += 8; - tmp2 = *(unsigned long *)from; + tmp1 = *(unsigned long *)(tmp_from+4); + tmp_from += 8; + tmp2 = *(unsigned long *)tmp_from; *(unsigned long *)(tmp_to+4) = tmp1; tmp_to += 8; *(unsigned long *)tmp_to = tmp2; @@ -60,23 +61,25 @@ void *memcpy(void *to, const void *from, size_t n) lessthan8: n = n % 8; if (n >= 4) { - *++(unsigned long *)tmp_to = *++(unsigned long *)from; + *(unsigned long *)(tmp_to+4) = *(unsigned long *)(tmp_from+4); + tmp_from += 4; + tmp_to += 4; n = n-4; } if (!n ) return to; - from += 3; + tmp_from += 3; tmp_to += 3; do { - *++(unsigned char *)tmp_to = *++(unsigned char *)from; + *++tmp_to = *++tmp_from; } while (--n); return to; align: rem = 4 - rem; - n = n-rem; + n = n - rem; do { - *(unsigned char *)(tmp_to+4) = *(unsigned char *)(from+4); - ++from; + *(tmp_to+4) = *(tmp_from+4); + ++tmp_from; ++tmp_to; } while (--rem); chunks = n / 8; @@ -84,18 +87,20 @@ void *memcpy(void *to, const void *from, size_t n) goto copy_chunks; goto lessthan8; } +strong_alias(__memcpy, memcpy); #endif #ifdef L_memmove -void *memmove(void *to, const void *from, size_t n) +void attribute_hidden *__memmove(void *to, const void *from, size_t n) { unsigned long rem, chunks, tmp1, tmp2; - void *tmp_to; + unsigned char *tmp_to; + unsigned char *tmp_from = (unsigned char *)from; - if (from >= to) + if (tmp_from >= (unsigned char *)to) return memcpy(to, from, n); chunks = n / 8; - from += n; + tmp_from += n; tmp_to = to + n; if (!chunks) goto lessthan8; @@ -105,9 +110,9 @@ void *memmove(void *to, const void *from, size_t n) copy_chunks: do { /* make gcc to load all data, then store it */ - tmp1 = *(unsigned long *)(from-4); - from -= 8; - tmp2 = *(unsigned long *)from; + tmp1 = *(unsigned long *)(tmp_from-4); + tmp_from -= 8; + tmp2 = *(unsigned long *)tmp_from; *(unsigned long *)(tmp_to-4) = tmp1; tmp_to -= 8; *(unsigned long *)tmp_to = tmp2; @@ -115,26 +120,29 @@ void *memmove(void *to, const void *from, size_t n) lessthan8: n = n % 8; if (n >= 4) { - *--(unsigned long *)tmp_to = *--(unsigned long *)from; + *(unsigned long *)(tmp_to-4) = *(unsigned long *)(tmp_from-4); + tmp_from -= 4; + tmp_to -= 4; n = n-4; } if (!n ) return to; do { - *--(unsigned char *)tmp_to = *--(unsigned char *)from; + *--tmp_to = *--tmp_from; } while (--n); return to; align: rem = 4 - rem; - n = n-rem; + n = n - rem; do { - *--(unsigned char *)tmp_to = *--(unsigned char *)from; + *--tmp_to = *--tmp_from; } while (--rem); chunks = n / 8; if (chunks) goto copy_chunks; goto lessthan8; } +strong_alias(__memmove, memmove); #endif #ifdef L_memset @@ -148,10 +156,10 @@ static inline int expand_byte_word(int c){ : "=r" (c) : "0" (c)); return c; } -void *memset(void *to, int c, size_t n) +void attribute_hidden *__memset(void *to, int c, size_t n) { unsigned long rem, chunks; - void *tmp_to; + unsigned char *tmp_to; chunks = n / 8; tmp_to = to - 4; @@ -163,19 +171,22 @@ void *memset(void *to, int c, size_t n) goto align; copy_chunks: do { - *++(unsigned long *)tmp_to = c; - *++(unsigned long *)tmp_to = c; + *(unsigned long *)(tmp_to+4) = c; + tmp_to += 4; + *(unsigned long *)(tmp_to+4) = c; + tmp_to += 4; } while (--chunks); lessthan8: n = n % 8; if (n >= 4) { - *++(unsigned long *)tmp_to = c; + *(unsigned long *)(tmp_to+4) = c; + tmp_to += 4; n = n-4; } if (!n ) return to; tmp_to += 3; do { - *++(unsigned char *)tmp_to = c; + *++tmp_to = c; } while (--n); return to; @@ -183,7 +194,7 @@ void *memset(void *to, int c, size_t n) rem = 4 - rem; n = n-rem; do { - *(unsigned char *)(tmp_to+4) = c; + *(tmp_to+4) = c; ++tmp_to; } while (--rem); chunks = n / 8; @@ -191,6 +202,7 @@ void *memset(void *to, int c, size_t n) goto copy_chunks; goto lessthan8; } +strong_alias(__memset, memset); #endif #ifdef L_bzero diff --git a/libc/sysdeps/linux/alpha/crt1.S b/libc/sysdeps/linux/alpha/crt1.S new file mode 100644 index 000000000..0831ecf6f --- /dev/null +++ b/libc/sysdeps/linux/alpha/crt1.S @@ -0,0 +1,80 @@ +/* Startup code for Alpha/ELF. + Copyright (C) 1993,1995,1996,1997,1998,2000,2001 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Richard Henderson <rth@tamu.edu> + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <features.h> +#include <asm/regdef.h> + +.text +.global _start +.ent _start,0 +.type _start,%function +#if defined(__UCLIBC_CTOR_DTOR__) +.type _init,%function +.type _fini,%function +#else +.weak _init +.weak _fini +#endif +.type __uClibc_main,%function +/* Stick in a dummy reference to main(), so that if an application + * is linking when the main() function is in a static library (.a) + * we can be sure that main() actually gets linked in */ +.type main,%function + +_start: + .frame $15, 0, $15 + br gp, 1f +1: ldgp gp, 0(gp) + subq sp, 16, sp + mov 0, $15 + .prologue 0 + + /* Load address of the user's main function. */ + lda a0, main + + ldl a1, 16(sp) /* get argc */ + lda a2, 24(sp) /* get argv */ + + /* Load address of our own entry points to .fini and .init. */ + lda a3, _init + lda a4, _fini + + /* Store address of the shared library termination function. */ + mov v0, a5 + + /* Provide the highest stack address to the user code. */ + stq sp, 0(sp) + + /* Call the user's main function, and exit with its value. + * But let the libc call main. */ + jsr ra, __uClibc_main + + /* Die very horribly if exit returns. Call_pal hlt is callable from + * kernel mode only; this will result in an illegal instruction trap. */ + call_pal 0 + .end _start + +/* Define a symbol for the first piece of initialized data. */ +.data +.global __data_start +__data_start: +.long 0 +.weak data_start + data_start = __data_start diff --git a/libc/sysdeps/linux/arm/__syscall_error.c b/libc/sysdeps/linux/arm/__syscall_error.c new file mode 100644 index 000000000..de65a1f39 --- /dev/null +++ b/libc/sysdeps/linux/arm/__syscall_error.c @@ -0,0 +1,29 @@ +/* Wrapper for setting errno. + Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <features.h> + +/* This routine is jumped to by all the syscall handlers, to stash + * an error number into errno. */ +int attribute_hidden __syscall_error(int err_no) +{ + __set_errno(err_no); + return -1; +} diff --git a/libc/sysdeps/linux/arm/crt1.S b/libc/sysdeps/linux/arm/crt1.S new file mode 100644 index 000000000..01e1f61d3 --- /dev/null +++ b/libc/sysdeps/linux/arm/crt1.S @@ -0,0 +1,143 @@ +/* Startup code for ARM & ELF + Copyright (C) 1995, 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* This is the canonical entry point, usually the first thing in the text + segment. + + Note that the code in the .init section has already been run. + This includes _init and _libc_init + + + At this entry point, most registers' values are unspecified, except: + + a1 Contains a function pointer to be registered with `atexit'. + This is how the dynamic linker arranges to have DT_FINI + functions called for shared libraries that have been loaded + before this code runs. + + sp The stack contains the arguments and environment: + 0(sp) argc + 4(sp) argv[0] + ... + (4*argc)(sp) NULL + (4*(argc+1))(sp) envp[0] + ... + NULL +*/ +/* + For uClinux it looks like this: + + argc argument counter (integer) + argv char *argv[] + envp char *envp[] + argv[0] program name (pointer) + argv[1...N] program args (pointers) + argv[argc-1] end of args (integer) + NULL + env[0...N] environment variables (pointers) + NULL + +ARM register quick reference: + + Name Number ARM Procedure Calling Standard Role + + a1 r0 argument 1 / integer result / scratch register / argc + a2 r1 argument 2 / scratch register / argv + a3 r2 argument 3 / scratch register / envp + a4 r3 argument 4 / scratch register + v1 r4 register variable + v2 r5 register variable + v3 r6 register variable + v4 r7 register variable + v5 r8 register variable + sb/v6 r9 static base / register variable + sl/v7 r10 stack limit / stack chunk handle / reg. variable + fp r11 frame pointer + ip r12 scratch register / new-sb in inter-link-unit calls + sp r13 lower end of current stack frame + lr r14 link address / scratch register + pc r15 program counter +*/ + + .text + .globl _start + .type _start,#function +_start: + /* Clear the frame pointer and link register since this is the outermost frame. */ + mov fp, #0 + mov lr, #0 + + /* Pop argc off the stack and save a pointer to argv */ + ldr a2, [sp], #4 + mov a3, sp + + /* Push stack limit */ + str a3, [sp, #-4]! + + /* Push rtld_fini */ + str a1, [sp, #-4]! + +#ifdef __PIC__ + ldr sl, .L_GOT +.L_GOT_OFF: + add sl, pc, sl + + ldr ip, .L_GOT+4 /* _fini */ + ldr a1, [sl, ip] + str a1, [sp, #-4]! /* Push _fini */ + + ldr ip, .L_GOT+8 /* _init */ + ldr a4, [sl, ip] + + ldr ip, .L_GOT+12 /* main */ + ldr a1, [sl, ip] + + /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */ + /* Let the libc call main and exit with its return code. */ + b __uClibc_main(PLT) +#else + /* Fetch address of fini */ + ldr ip, =_fini + /* Push fini */ + str ip, [sp, #-4]! + + /* Set up the other arguments in registers */ + ldr a1, =main + ldr a4, =_init + + /* __uClibc_main (main, argc, argv, init, fini, rtld_fini, stack_end) */ + /* Let the libc call main and exit with its return code. */ + b __uClibc_main +#endif + +#ifdef __PIC__ +.L_GOT: + .word _GLOBAL_OFFSET_TABLE_-(.L_GOT_OFF+8) + .word _fini(GOT) + .word _init(GOT) + .word main(GOT) +#endif + +/* Define a symbol for the first piece of initialized data. */ + .data + .globl __data_start +__data_start: + .long 0 + .weak data_start + data_start = __data_start diff --git a/libc/sysdeps/linux/i386/__syscall_error.c b/libc/sysdeps/linux/i386/__syscall_error.c new file mode 100644 index 000000000..de65a1f39 --- /dev/null +++ b/libc/sysdeps/linux/i386/__syscall_error.c @@ -0,0 +1,29 @@ +/* Wrapper for setting errno. + Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <features.h> + +/* This routine is jumped to by all the syscall handlers, to stash + * an error number into errno. */ +int attribute_hidden __syscall_error(int err_no) +{ + __set_errno(err_no); + return -1; +} diff --git a/libc/sysdeps/linux/i386/crt1.S b/libc/sysdeps/linux/i386/crt1.S new file mode 100644 index 000000000..a133cb9e0 --- /dev/null +++ b/libc/sysdeps/linux/i386/crt1.S @@ -0,0 +1,140 @@ +/* Startup code compliant to the ELF i386 ABI. + Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + In addition to the permissions in the GNU Lesser General Public + License, the Free Software Foundation gives you unlimited + permission to link the compiled version of this file with other + programs, and to distribute those programs without any restriction + coming from the use of this file. (The GNU Lesser General Public + License restrictions do apply in other respects; for example, they + cover modification of the file, and distribution when not linked + into another program.) + + Note that people who make modified versions of this file are not + obligated to grant this special exception for their modified + versions; it is their choice whether to do so. The GNU Lesser + General Public License gives permission to release a modified + version without this exception; this exception also makes it + possible to release a modified version which carries forward this + exception. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* This is the canonical entry point, usually the first thing in the text + segment. The SVR4/i386 ABI (pages 3-31, 3-32) says that when the entry + point runs, most registers' values are unspecified, except for: + + %edx Contains a function pointer to be registered with `atexit'. + This is how the dynamic linker arranges to have DT_FINI + functions called for shared libraries that have been loaded + before this code runs. + + %esp The stack contains the arguments and environment: + 0(%esp) argc + 4(%esp) argv[0] + ... + (4*argc)(%esp) NULL + (4*(argc+1))(%esp) envp[0] + ... + NULL +*/ + +#include <features.h> + +.text +.global _start +.type _start,%function +#if defined(__UCLIBC_CTOR_DTOR__) +.type _init,%function +.type _fini,%function +#else +.weak _init +.weak _fini +#endif +.type main,%function +.type __uClibc_main,%function +_start: + /* Clear the frame pointer. The ABI suggests this be done, to mark + the outermost frame obviously. */ + xorl %ebp, %ebp + + /* Extract the arguments as encoded on the stack and set up + the arguments for `main': argc, argv. envp will be determined + later in __libc_start_main. */ + popl %esi /* Pop the argument count. */ + movl %esp, %ecx /* argv starts just at the current stack top.*/ + + /* Before pushing the arguments align the stack to a 16-byte + (SSE needs 16-byte alignment) boundary to avoid penalties from + misaligned accesses. Thanks to Edward Seidl <seidl@janed.com> + for pointing this out. */ + andl $0xfffffff0, %esp + pushl %eax /* Push garbage because we allocate + 28 more bytes. */ + + /* Provide the highest stack address to the user code (for stacks + which grow downwards). */ + pushl %esp + + pushl %edx /* Push address of the shared library + termination function. */ + +#ifdef __PIC__ + /* Load PIC register. */ + call .L0 +.L0: + pop %ebx + addl $_GLOBAL_OFFSET_TABLE_+[.-.L0],%ebx + + /* Push address of our own entry points to .fini and .init. */ + pushl _fini@GOT(%ebx) + pushl _init@GOT(%ebx) + + pushl %ecx /* Push second argument: argv. */ + pushl %esi /* Push first argument: argc. */ + + pushl main@GOT(%ebx) + + /* Call the user's main function, and exit with its value. + But let the libc call main. */ + call __uClibc_main@PLT +#else + /* Push address of our own entry points to .fini and .init. */ + pushl $_fini + pushl $_init + + pushl %ecx /* Push second argument: argv. */ + pushl %esi /* Push first argument: argc. */ + + pushl $main + + /* Call the user's main function, and exit with its value. + But let the libc call main. */ + call __uClibc_main +#endif + + hlt /* Crash if somehow `exit' does return. */ +.size _start,.-_start + +/* Define a symbol for the first piece of initialized data. */ +.data +.global __data_start +__data_start: +.long 0 +.weak data_start + data_start = __data_start diff --git a/libc/sysdeps/linux/sparc/__syscall_error.c b/libc/sysdeps/linux/sparc/__syscall_error.c new file mode 100644 index 000000000..de65a1f39 --- /dev/null +++ b/libc/sysdeps/linux/sparc/__syscall_error.c @@ -0,0 +1,29 @@ +/* Wrapper for setting errno. + Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <features.h> + +/* This routine is jumped to by all the syscall handlers, to stash + * an error number into errno. */ +int attribute_hidden __syscall_error(int err_no) +{ + __set_errno(err_no); + return -1; +} diff --git a/libc/sysdeps/linux/sparc/crt1.S b/libc/sysdeps/linux/sparc/crt1.S new file mode 100644 index 000000000..f33a714ef --- /dev/null +++ b/libc/sysdeps/linux/sparc/crt1.S @@ -0,0 +1,134 @@ +/* Startup code for elf{32,64}-sparc + Copyright (C) 1997, 1998, 2002, 2004 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + In addition to the permissions in the GNU Lesser General Public + License, the Free Software Foundation gives you unlimited + permission to link the compiled version of this file with other + programs, and to distribute those programs without any restriction + coming from the use of this file. (The GNU Lesser General Public + License restrictions do apply in other respects; for example, they + cover modification of the file, and distribution when not linked + into another program.) + + Note that people who make modified versions of this file are not + obligated to grant this special exception for their modified + versions; it is their choice whether to do so. The GNU Lesser + General Public License gives permission to release a modified + version without this exception; this exception also makes it + possible to release a modified version which carries forward this + exception. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* Originally based on glibc's sysdeps/sparc/sparc{32,64}/elf/start.S */ + +#include <features.h> +#include <bits/wordsize.h> + +/* macro out the 32 / 64 bit differences */ +#if __WORDSIZE == 32 +# define STACK_BIAS 0 +# define ELE_SIZE 4 +# define LD ld +#else +# define STACK_BIAS 2047 /* see glibc/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep.h */ +# define ELE_SIZE 8 +# define LD ldx +#endif + +.text +.align 4 +.global _start +.type _start,%function +#if defined(__UCLIBC_CTOR_DTOR__) +.type _init,%function +.type _fini,%function +#else +.weak _init +.weak _fini +#endif +.type __uClibc_main,%function +/* Stick in a dummy reference to main(), so that if an application + * is linking when the main() function is in a static library (.a) + * we can be sure that main() actually gets linked in */ +.global main +.type main,%function + +#ifdef __PIC__ +.LLGETPC0: + retl + add %o7, %l7, %l7 +#endif + +_start: +#ifdef __PIC__ + sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %l7 + call .LLGETPC0 + add %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7 +#endif + + /* Terminate the stack frame, and reserve space for functions to + * drop their arguments. */ + mov %g0, %fp + sub %sp, 6*ELE_SIZE, %sp + + /* Extract the arguments and environment as encoded on the stack. The + * argument info starts after one register window (16 words) past the SP. */ + LD [%sp+STACK_BIAS+22*ELE_SIZE], %o1 /* %o1 = argc */ + add %sp, STACK_BIAS+23*ELE_SIZE, %o2 /* %o2 = argv */ + + /* Load the addresses of the user entry points. */ + sethi %hi(main), %o0 + sethi %hi(_init), %o3 + sethi %hi(_fini), %o4 + or %o0, %lo(main), %o0 + or %o3, %lo(_init), %o3 + or %o4, %lo(_fini), %o4 +#ifdef __PIC__ + /* Need a little more magic when building PIC to get addr of main */ + LD [%l7 + %o0], %o0 + LD [%l7 + %o3], %o3 + LD [%l7 + %o4], %o4 +#endif + + /* When starting a binary via the dynamic linker, %g1 contains the + * address of the shared library termination function, which will be + * registered with atexit(). If we are statically linked, this will + * be NULL. */ + mov %g1, %o5 + + /* Let libc do the rest of the initialization, and call main. */ + call __uClibc_main + nop + + /* Die very horribly if exit returns. */ +#if __WORDSIZE == 32 + unimp +#else + illtrap 0 +#endif + +.size _start,.-_start + +/* Define a symbol for the first piece of initialized data. */ +.data +.global __data_start +__data_start: +.long 0 +.weak data_start + data_start = __data_start diff --git a/libc/sysdeps/linux/x86_64/__syscall_error.c b/libc/sysdeps/linux/x86_64/__syscall_error.c new file mode 100644 index 000000000..de65a1f39 --- /dev/null +++ b/libc/sysdeps/linux/x86_64/__syscall_error.c @@ -0,0 +1,29 @@ +/* Wrapper for setting errno. + Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <features.h> + +/* This routine is jumped to by all the syscall handlers, to stash + * an error number into errno. */ +int attribute_hidden __syscall_error(int err_no) +{ + __set_errno(err_no); + return -1; +} diff --git a/libc/sysdeps/linux/x86_64/crt1.S b/libc/sysdeps/linux/x86_64/crt1.S new file mode 100644 index 000000000..f6c1eb1e7 --- /dev/null +++ b/libc/sysdeps/linux/x86_64/crt1.S @@ -0,0 +1,140 @@ +/* Startup code compliant to the ELF x86-64 ABI. + Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Andreas Jaeger <aj@suse.de>, 2001. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + In addition to the permissions in the GNU Lesser General Public + License, the Free Software Foundation gives you unlimited + permission to link the compiled version of this file with other + programs, and to distribute those programs without any restriction + coming from the use of this file. (The GNU Lesser General Public + License restrictions do apply in other respects; for example, they + cover modification of the file, and distribution when not linked + into another program.) + + Note that people who make modified versions of this file are not + obligated to grant this special exception for their modified + versions; it is their choice whether to do so. The GNU Lesser + General Public License gives permission to release a modified + version without this exception; this exception also makes it + possible to release a modified version which carries forward this + exception. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* Originally based on glibc's sysdeps/x86_64/elf/start.S */ + +/* This is the canonical entry point, usually the first thing in the text + segment. The SVR4/i386 ABI (pages 3-31, 3-32) says that when the entry + point runs, most registers' values are unspecified, except for: + + %rdx Contains a function pointer to be registered with `atexit'. + This is how the dynamic linker arranges to have DT_FINI + functions called for shared libraries that have been loaded + before this code runs. + + %rsp The stack contains the arguments and environment: + 0(%rsp) argc + 8(%rsp) argv[0] + ... + (8*argc)(%rsp) NULL + (8*(argc+1))(%rsp) envp[0] + ... + NULL +*/ + +#include <features.h> + +.text +.global _start +.type _start,%function +#if defined(__UCLIBC_CTOR_DTOR__) +.type _init,%function +.type _fini,%function +#else +.weak _init +.weak _fini +#endif +.type __uClibc_main,%function +/* Stick in a dummy reference to main(), so that if an application + * is linking when the main() function is in a static library (.a) + * we can be sure that main() actually gets linked in */ +.type main,%function + +_start: + /* Clear the frame pointer. The ABI suggests this be done, to mark + the outermost frame obviously. */ + xorl %ebp, %ebp + + /* Extract the arguments as encoded on the stack and set up + the arguments for __libc_start_main (int (*main) (int, char **, char **), + int argc, char *argv, + void (*init) (void), void (*fini) (void), + void (*rtld_fini) (void), void *stack_end). + The arguments are passed via registers and on the stack: + main: %rdi + argc: %rsi + argv: %rdx + init: %rcx + fini: %r8 + rtld_fini: %r9 + stack_end: stack. */ + + movq %rdx, %r9 /* Address of the shared library termination function. */ + popq %rsi /* Pop the argument count. */ + movq %rsp, %rdx /* argv starts just at the current stack top. */ + + /* Align the stack to a 16 byte boundary to follow the ABI. */ + andq $~15, %rsp + + pushq %rax /* Push garbage because we push 8 more bytes. */ + + /* Provide the highest stack address to the user code (for stacks + which grow downwards). */ + pushq %rsp + +#if defined(L_Scrt1) + /* Give address for main() */ + movq main@GOTPCREL(%rip), %rdi + + /* setup init/fini address */ + movq _init@GOTPCREL(%rip), %rcx + movq _fini@GOTPCREL(%rip), %r8 + + /* start the fun */ + call __uClibc_main@PLT +#else + /* Give address for main() */ + movq $main, %rdi + + /* setup init/fini address */ + movq $_init, %rcx + movq $_fini, %r8 + + /* start the fun */ + call __uClibc_main +#endif + + hlt /* Crash if somehow `exit' does return. */ +.size _start,.-_start + +/* Define a symbol for the first piece of initialized data. */ +.data +.global __data_start +__data_start: +.long 0 +.weak data_start + data_start = __data_start diff --git a/libc/sysdeps/linux/x86_64/mmap.c b/libc/sysdeps/linux/x86_64/mmap.c new file mode 100644 index 000000000..117d93ddc --- /dev/null +++ b/libc/sysdeps/linux/x86_64/mmap.c @@ -0,0 +1,17 @@ +/* vi: set sw=4 ts=4: */ +/* + * mmap() for uClibc/x86_64 + * + * Copyright (C) 2005 by Erik Andersen <andersen@codepoet.org> + * Copyright (C) 2005 by Mike Frysinger <vapier@gentoo.org> + * + * GNU Library General Public License (LGPL) version 2 or later. + */ + +#include <errno.h> +#include <unistd.h> +#include <sys/mman.h> +#include <sys/syscall.h> + +_syscall6(void *, mmap, void *, start, size_t, length, int, prot, + int, flags, int, fd, off_t, offset); |
