diff options
30 files changed, 62 insertions, 1984 deletions
diff --git a/ldso/ldso/.cvsignore b/ldso/ldso/.cvsignore index 9103d4aa9..962b65384 100644 --- a/ldso/ldso/.cvsignore +++ b/ldso/ldso/.cvsignore @@ -1,2 +1,2 @@ ld-uclibc.so* -ld.so.h +ld-uClibc.h diff --git a/ldso/ldso/Makefile b/ldso/ldso/Makefile index d85900fbb..c91e0b85e 100644 --- a/ldso/ldso/Makefile +++ b/ldso/ldso/Makefile @@ -23,17 +23,17 @@ TOPDIR=../../ +DOPIC=true include $(TOPDIR)Rules.mak -TARGET_CFLAGS += #-DDL_DEBUG #-funroll-loops - - LDSO_FULLNAME=ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).so -TARGET_CFLAGS+=-fPIC -D__PIC__ -DUCLIBC_TARGET_PREFIX=\"$(TARGET_PREFIX)\" \ + +#XXFLAGS += #-DDL_DEBUG #-funroll-loops +XXFLAGS+=-DUCLIBC_TARGET_PREFIX=\"$(TARGET_PREFIX)\" \ -DUCLIBC_DEVEL_PREFIX=\"$(DEVEL_PREFIX)\" \ -DUCLIBC_BUILD_DIR=\"$(shell cd $(TOPDIR) && pwd)\" -CSRC= boot1.c hash.c readelflib1.c $(TARGET_ARCH)/elfinterp.c +CSRC= ldso.c hash.c readelflib1.c $(TARGET_ARCH)/elfinterp.c COBJS=$(patsubst %.c,%.o, $(CSRC)) ASRC=$(shell ls $(TARGET_ARCH)/*.S) AOBJS=$(patsubst %.S,%.o, $(ASRC)) @@ -42,20 +42,20 @@ OBJS=$(AOBJS) $(COBJS) all: lib -lib:: ld.so.h $(OBJS) $(DLINK_OBJS) - $(TARGET_CC) -e _dl_boot $(TARGET_LDFLAGS) -nostdlib -shared -o $(LDSO_FULLNAME) \ - -Wl,-soname,$(UCLIBC_LDSO) $(OBJS) +lib:: ldso.h $(OBJS) $(DLINK_OBJS) + $(LD) -e _dl_boot $(LDFLAGS) -nostdlib -shared -o $(LDSO_FULLNAME) \ + -soname=$(UCLIBC_LDSO) $(OBJS) install -d $(TOPDIR)lib install -m 755 $(LDSO_FULLNAME) $(TOPDIR)lib (cd $(TOPDIR)lib && ln -sf $(LDSO_FULLNAME) $(UCLIBC_LDSO)) -ld.so.h: Makefile - echo "#define _dl_static_progname \""$(UCLIBC_LDSO)"\"" > ld.so.h +ldso.h: Makefile + echo "#define _dl_static_progname \""$(UCLIBC_LDSO)"\"" > ld-uClibc.h $(COBJS): %.o : %.c - $(TARGET_CC) $(TARGET_CFLAGS) -I. -I./$(TARGET_ARCH) -I../libdl -c $< -o $@ + $(CC) $(CFLAGS) $(XXFLAGS) -I. -I./$(TARGET_ARCH) -I../libdl -c $< -o $@ $(STRIPTOOL) -x -R .note -R .comment $*.o clean:: - $(RM) -f $(UCLIBC_LDSO)* $(OBJS) $(LDSO_FULLNAME)* core *.o *.a *.s *.i tmp_make foo *~ + $(RM) -f $(UCLIBC_LDSO)* $(OBJS) $(LDSO_FULLNAME)* core *.o *.a *.s *.i ldso.h *~ diff --git a/ldso/ldso/arm/elfinterp.c b/ldso/ldso/arm/elfinterp.c index f0c83a166..d1616c5bf 100644 --- a/ldso/ldso/arm/elfinterp.c +++ b/ldso/ldso/arm/elfinterp.c @@ -49,11 +49,10 @@ static char *_dl_reltypes[] = #include <sys/types.h> #include <errno.h> -#include "elf.h" -#include "hash.h" -#include "syscall.h" -#include "string.h" -#include "sysdep.h" +#include "linuxelf.h" +#include "ld_hash.h" +#include "ld_syscall.h" +#include "ld_string.h" extern char *_dl_progname; diff --git a/ldso/ldso/arm/syscalls.h b/ldso/ldso/arm/syscalls.h deleted file mode 100644 index aa08421a5..000000000 --- a/ldso/ldso/arm/syscalls.h +++ /dev/null @@ -1,124 +0,0 @@ -#include <sys/types.h> - -/* - * This file contains the system call macros and syscall - * numbers used by the shared library loader. - */ - -#define __NR_SYSCALL_BASE 0x900000 - -#define __NR_exit (__NR_SYSCALL_BASE+ 1) -#define __NR_read (__NR_SYSCALL_BASE+ 3) -#define __NR_write (__NR_SYSCALL_BASE+ 4) -#define __NR_open (__NR_SYSCALL_BASE+ 5) -#define __NR_close (__NR_SYSCALL_BASE+ 6) -#define __NR_getuid (__NR_SYSCALL_BASE+ 24) -#define __NR_geteuid (__NR_SYSCALL_BASE+ 49) -#define __NR_getgid (__NR_SYSCALL_BASE+ 47) -#define __NR_getegid (__NR_SYSCALL_BASE+ 50) -#define __NR_mmap (__NR_SYSCALL_BASE+ 90) -#define __NR_munmap (__NR_SYSCALL_BASE+ 91) -#define __NR_stat (__NR_SYSCALL_BASE+106) -#define __NR_mprotect (__NR_SYSCALL_BASE+125) - - -/* Here are the macros which define how this platform makes - * system calls. This particular variant does _not_ set - * errno (note how it is disabled in __syscall_return) since - * these will get called before the errno symbol is dynamicly - * linked. */ - -/* These are Erik's versions of the syscall routines. His were - * cleaner than mine, so I adopted them instead with some - * reformating. Shane Nay. - */ - -#define __sys2(x) #x -#define __sys1(x) __sys2(x) - -#ifndef __syscall -#define __syscall(name) "swi\t" __sys1(__NR_##name) "\n\t" -#endif - -#undef __syscall_return -#define __syscall_return(type, res) \ -do { \ - if ((unsigned long)(res) >= (unsigned long)(-125)) { \ - /*errno = -(res);*/ \ - res = -1; \ - } \ - return (type) (res); \ -} while (0) - -#define _syscall0(type,name) \ -type name(void) { \ - long __res; \ - __asm__ __volatile__ ( \ - __syscall(name) \ - "mov %0,r0" \ - :"=r" (__res) : : "r0","lr"); \ - __syscall_return(type,__res); \ -} - -#define _syscall1(type,name,type1,arg1) \ -type name(type1 arg1) { \ - long __res; \ - __asm__ __volatile__ ( \ - "mov\tr0,%1\n\t" \ - __syscall(name) \ - "mov %0,r0" \ - : "=r" (__res) \ - : "r" ((long)(arg1)) \ - : "r0","lr"); \ - __syscall_return(type,__res); \ -} - -#define _syscall2(type,name,type1,arg1,type2,arg2) \ -type name(type1 arg1,type2 arg2) { \ - long __res; \ - __asm__ __volatile__ ( \ - "mov\tr0,%1\n\t" \ - "mov\tr1,%2\n\t" \ - __syscall(name) \ - "mov\t%0,r0" \ - : "=r" (__res) \ - : "r" ((long)(arg1)),"r" ((long)(arg2)) \ - : "r0","r1","lr"); \ - __syscall_return(type,__res); \ -} - - -#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ -type name(type1 arg1,type2 arg2,type3 arg3) { \ - long __res; \ - __asm__ __volatile__ ( \ - "mov\tr0,%1\n\t" \ - "mov\tr1,%2\n\t" \ - "mov\tr2,%3\n\t" \ - __syscall(name) \ - "mov\t%0,r0" \ - : "=r" (__res) \ - : "r" ((long)(arg1)),"r" ((long)(arg2)),"r" ((long)(arg3)) \ - : "r0","r1","r2","lr"); \ - __syscall_return(type,__res); \ -} - -#undef _syscall4 -#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\ -type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ - long __res; \ - __asm__ __volatile__ ( \ - "mov\tr0,%1\n\t" \ - "mov\tr1,%2\n\t" \ - "mov\tr2,%3\n\t" \ - "mov\tr3,%4\n\t" \ - __syscall(name) \ - "mov\t%0,r0" \ - : "=r" (__res) \ - : "r" ((long)(arg1)),"r" ((long)(arg2)), \ - "r" ((long)(arg3)),"r" ((long)(arg4)) \ - : "r0","r1","r2","r3","lr"); \ - __syscall_return(type,__res); \ -} - - diff --git a/ldso/ldso/arm/sysdep.h b/ldso/ldso/arm/sysdep.h deleted file mode 100644 index b3d430519..000000000 --- a/ldso/ldso/arm/sysdep.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Various assmbly language/system dependent hacks that are required - * so that we can minimize the amount of platform specific code. - */ - -/* - * Define this if the system uses RELOCA. - */ -#undef ELF_USES_RELOCA - -/* - * 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) - -/* - * Initialization sequence for a GOT. - */ -#define INIT_GOT(GOT_BASE,MODULE) \ -{ \ - GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \ - GOT_BASE[1] = (unsigned long) MODULE; \ -} - -/* - * Here is a macro to perform a relocation. This is only used when - * bootstrapping the dynamic loader. RELP is the relocation that we - * are performing, REL is the pointer to the address we are relocating. - * SYMBOL is the symbol involved in the relocation, and LOAD is the - * load address. - */ -#define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD) \ - switch(ELF32_R_TYPE((RELP)->r_info)){ \ - case R_ARM_ABS32: \ - *REL += SYMBOL; \ - break; \ - case R_ARM_PC24: \ - { \ - unsigned long newval, topbits; \ - long addend=*REL & 0x00ffffff; \ - if(addend & 0x00800000) \ - addend|=0xff000000; \ - newval=SYMBOL- ((unsigned long)REL) + (addend<<2); \ - topbits=newval & 0xfe000000; \ - if (topbits != 0xfe000000 && topbits != 0x00000000) {/* \ - newval=fix_bad_pc24(REL,value) - \ - ((unsigned long)REL) + (addend << 2); \ - topbits=newval & 0xfe000000; \ - if(topbits != 0xfe000000 && topbits != 0x00000000)*/ \ - _dl_exit(1); \ - } \ - newval>>=2; \ - SYMBOL= (*REL & 0xff000000)|(newval & 0x00ffffff); \ - *REL=SYMBOL; \ - } \ - break; \ - case R_ARM_GLOB_DAT: \ - case R_ARM_JUMP_SLOT: \ - *REL = SYMBOL; \ - break; \ - case R_ARM_RELATIVE: \ - *REL += (unsigned long) LOAD; \ - break; \ - case R_ARM_NONE: \ - 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; - - - -/* Here we define the magic numbers that this dynamic loader should accept */ - -#define MAGIC1 EM_ARM -#undef MAGIC2 -/* Used for error messages */ -#define ELF_TARGET "ARM" - -struct elf_resolve; -extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry); - -static inline unsigned long arm_modulus(unsigned long m, unsigned long p) { - unsigned long i,t,inc; - i=p; t=0; - while(!(i&(1<<31))) { - i<<=1; - t++; - } - t--; - for(inc=t;inc>2;inc--) { - i=p<<inc; - if(i&(1<<31)) - break; - while(m>=i) { - m-=i; - i<<=1; - if(i&(1<<31)) - break; - if(i<p) - break; - } - } - while(m>=p) { - m-=p; - } - return m; -} - -#define do_rem(result, n, base) result=arm_modulus(n,base); diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c index eed74321d..335f6fc29 100644 --- a/ldso/ldso/dl-elf.c +++ b/ldso/ldso/dl-elf.c @@ -21,12 +21,10 @@ /* This file contains the helper routines to load an ELF sharable library into memory and add the symbol table info to the chain. */ -#include <elf.h> #include "linuxelf.h" -#include "string.h" -#include "hash.h" -#include "sysdep.h" -#include "syscall.h" +#include "ld_hash.h" +#include "ld_syscall.h" +#include "ld_string.h" #include <sys/mman.h> #ifdef USE_CACHE #include "../config.h" diff --git a/ldso/ldso/dl-hash.c b/ldso/ldso/dl-hash.c index 5639a9a69..40d29bb44 100644 --- a/ldso/ldso/dl-hash.c +++ b/ldso/ldso/dl-hash.c @@ -20,13 +20,11 @@ /* Various symbol table handling functions, including symbol lookup */ -#include "string.h" #include "dlfcn.h" -#include "hash.h" #include "linuxelf.h" -#include "syscall.h" -#include "string.h" -#include "sysdep.h" +#include "ld_hash.h" +#include "ld_syscall.h" +#include "ld_string.h" /* * This is the start of the linked list that describes all of the files present diff --git a/ldso/ldso/hash.c b/ldso/ldso/hash.c index 5639a9a69..40d29bb44 100644 --- a/ldso/ldso/hash.c +++ b/ldso/ldso/hash.c @@ -20,13 +20,11 @@ /* Various symbol table handling functions, including symbol lookup */ -#include "string.h" #include "dlfcn.h" -#include "hash.h" #include "linuxelf.h" -#include "syscall.h" -#include "string.h" -#include "sysdep.h" +#include "ld_hash.h" +#include "ld_syscall.h" +#include "ld_string.h" /* * This is the start of the linked list that describes all of the files present diff --git a/ldso/ldso/hash.h b/ldso/ldso/hash.h deleted file mode 100644 index bb1b51fdc..000000000 --- a/ldso/ldso/hash.h +++ /dev/null @@ -1,141 +0,0 @@ -#ifndef _HASH_H_ -#define _HASH_H_ - -#include "elf.h" - -/* Header file that describes the internal data structures used by the - * ELF dynamic linker. */ - -struct link_map -{ - /* These entries must be in this order to be compatible with the - * interface used by gdb to obtain the list of symbols. */ - unsigned long l_addr; /* address at which object is mapped */ - char *l_name; /* full name of loaded object */ - Elf32_Dyn *l_ld; /* dynamic structure of object */ - struct link_map *l_next; - struct link_map *l_prev; -}; - -/* The DT_DEBUG entry in the .dynamic section is given the address of - * this structure. gdb can pick this up to obtain the correct list of - * loaded modules. */ -struct r_debug -{ - int r_version; /* debugging info version no */ - struct link_map *r_map; /* address of link_map */ - unsigned long r_brk; /* address of update routine */ - enum - { - RT_CONSISTENT, - RT_ADD, - RT_DELETE - } r_state; - unsigned long r_ldbase; /* base addr of ld.so */ -}; - -#ifndef RTLD_NEXT -#define RTLD_NEXT ((void*)-1) -#endif - -struct dyn_elf{ - unsigned long flags; - struct elf_resolve * dyn; - struct dyn_elf * next_handle; /* Used by dlopen et al. */ - struct dyn_elf * next; -}; - -struct elf_resolve{ - /* These entries must be in this order to be compatible with the interface used - by gdb to obtain the list of symbols. */ - char * loadaddr; - char * libname; - unsigned long dynamic_addr; - struct elf_resolve * next; - struct elf_resolve * prev; - /* Nothing after this address is used by gdb. */ - enum {elf_lib, elf_executable,program_interpreter, loaded_file} libtype; - struct dyn_elf * symbol_scope; - unsigned short usage_count; - unsigned short int init_flag; - unsigned int nbucket; - unsigned long * elf_buckets; - /* - * These are only used with ELF style shared libraries - */ - unsigned long nchain; - unsigned long * chains; - unsigned long dynamic_info[24]; - - unsigned long dynamic_size; - unsigned long n_phent; - Elf32_Phdr * ppnt; - -#ifdef __powerpc__ - /* this is used to store the address of relocation data words, so - * we don't have to calculate it every time, which requires a divide */ - unsigned long data_words; -#endif -}; - -#if 0 -/* - * The DT_DEBUG entry in the .dynamic section is given the address of this structure. - * gdb can pick this up to obtain the correct list of loaded modules. - */ - -struct r_debug{ - int r_version; - struct elf_resolve * link_map; - unsigned long brk_fun; - enum {RT_CONSISTENT, RT_ADD, RT_DELETE}; - unsigned long ldbase; -}; -#endif - -#define COPY_RELOCS_DONE 1 -#define RELOCS_DONE 2 -#define JMP_RELOCS_DONE 4 -#define INIT_FUNCS_CALLED 8 - -extern struct dyn_elf * _dl_symbol_tables; -extern struct elf_resolve * _dl_loaded_modules; -extern struct dyn_elf * _dl_handles; - -extern struct elf_resolve * _dl_check_hashed_files(char * libname); -extern struct elf_resolve * _dl_add_elf_hash_table(char * libname, - char * loadaddr, unsigned long * dynamic_info, - unsigned long dynamic_addr, unsigned long dynamic_size); -extern char * _dl_find_hash(char * name, struct dyn_elf * rpnt1, - unsigned long instr_addr, struct elf_resolve * f_tpnt, - int copyrel); -extern int _dl_linux_dynamic_link(void); - -extern char * _dl_library_path; -extern char * _dl_not_lazy; -extern unsigned long _dl_elf_hash(const char * name); - -static inline int _dl_symbol(char * name) -{ - if(name[0] != '_' || name[1] != 'd' || name[2] != 'l' || name[3] != '_') - return 0; - return 1; -} - - -#define DL_ERROR_NOFILE 1 -#define DL_ERROR_NOZERO 2 -#define DL_ERROR_NOTELF 3 -#define DL_ERROR_NOTMAGIC 4 -#define DL_ERROR_NOTDYN 5 -#define DL_ERROR_MMAP_FAILED 6 -#define DL_ERROR_NODYNAMIC 7 -#define DL_WRONG_RELOCS 8 -#define DL_BAD_HANDLE 9 -#define DL_NO_SYMBOL 10 - - - -#endif /* _HASH_H_ */ - - diff --git a/ldso/ldso/i386/dl-syscalls.h b/ldso/ldso/i386/dl-syscalls.h index b06c3238d..dc9c6934b 100644 --- a/ldso/ldso/i386/dl-syscalls.h +++ b/ldso/ldso/i386/dl-syscalls.h @@ -1,5 +1,3 @@ -#include <sys/types.h> - /* * This file contains the system call macros and syscall * numbers used by the shared library loader. diff --git a/ldso/ldso/i386/elfinterp.c b/ldso/ldso/i386/elfinterp.c index 621272bee..7745b1405 100644 --- a/ldso/ldso/i386/elfinterp.c +++ b/ldso/ldso/i386/elfinterp.c @@ -39,13 +39,10 @@ static char *_dl_reltypes[] = a more than adequate job of explaining everything required to get this working. */ -#include <sys/types.h> -#include <errno.h> -#include "elf.h" -#include "hash.h" -#include "syscall.h" -#include "string.h" -#include "sysdep.h" +#include "linuxelf.h" +#include "ld_hash.h" +#include "ld_syscall.h" +#include "ld_string.h" extern char *_dl_progname; diff --git a/ldso/ldso/i386/ld_syscalls.h b/ldso/ldso/i386/ld_syscalls.h index b06c3238d..dc9c6934b 100644 --- a/ldso/ldso/i386/ld_syscalls.h +++ b/ldso/ldso/i386/ld_syscalls.h @@ -1,5 +1,3 @@ -#include <sys/types.h> - /* * This file contains the system call macros and syscall * numbers used by the shared library loader. diff --git a/ldso/ldso/i386/syscalls.h b/ldso/ldso/i386/syscalls.h deleted file mode 100644 index b06c3238d..000000000 --- a/ldso/ldso/i386/syscalls.h +++ /dev/null @@ -1,166 +0,0 @@ -#include <sys/types.h> - -/* - * This file contains the system call macros and syscall - * numbers used by the shared library loader. - */ - -#define __NR_exit 1 -#define __NR_read 3 -#define __NR_write 4 -#define __NR_open 5 -#define __NR_close 6 -#define __NR_getuid 24 -#define __NR_geteuid 49 -#define __NR_getgid 47 -#define __NR_getegid 50 -#define __NR_mmap 90 -#define __NR_munmap 91 -#define __NR_stat 106 -#define __NR_mprotect 125 - -/* Here are the macros which define how this platform makes - * system calls. This particular variant does _not_ set - * errno (note how it is disabled in __syscall_return) since - * these will get called before the errno symbol is dynamicly - * linked. */ - -#define __syscall_return(type, res) \ -do { \ - if ((unsigned long)(res) >= (unsigned long)(-125)) { \ - /*errno = -(res); */ \ - res = -1; \ - } \ - return (type) (res); \ -} while (0) - -#define _syscall0(type,name) \ -type name(void) \ -{ \ -long __res; \ -__asm__ volatile ("int $0x80" \ - : "=a" (__res) \ - : "0" (__NR_##name)); \ -__syscall_return(type,__res); \ -} - -#if defined(__PIC__) - -/* - * PIC uses %ebx, so we need to save it during system calls - */ - -#define _syscall1(type,name,type1,arg1) \ -type name(type1 arg1) \ -{ \ -long __res; \ -__asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \ - : "=a" (__res) \ - : "0" (__NR_##name),"r" ((long)(arg1))); \ -__syscall_return(type,__res); \ -} - -#define _syscall2(type,name,type1,arg1,type2,arg2) \ -type name(type1 arg1,type2 arg2) \ -{ \ -long __res; \ -__asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \ - : "=a" (__res) \ - : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2))); \ -__syscall_return(type,__res); \ -} - -#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ -type name(type1 arg1,type2 arg2,type3 arg3) \ -{ \ -long __res; \ -__asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \ - : "=a" (__res) \ - : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2)), \ - "d" ((long)(arg3))); \ -__syscall_return(type,__res); \ -} - -#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ -long __res; \ -__asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \ - : "=a" (__res) \ - : "0" (__NR_##name),"r" ((long)(arg1)),"c" ((long)(arg2)), \ - "d" ((long)(arg3)),"S" ((long)(arg4))); \ -__syscall_return(type,__res); \ -} - -#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ - type5,arg5) \ -type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ -{ \ -long __res; \ -__asm__ volatile ("push %%ebx; movl %2,%%ebx; int $0x80; pop %%ebx" \ - : "=a" (__res) \ - : "0" (__NR_##name),"m" ((long)(arg1)),"c" ((long)(arg2)), \ - "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \ -__syscall_return(type,__res); \ -} - -#else /* not doing __PIC__ */ - -#define _syscall1(type,name,type1,arg1) \ -type name(type1 arg1) \ -{ \ -long __res; \ -__asm__ volatile ("int $0x80" \ - : "=a" (__res) \ - : "0" (__NR_##name),"b" ((long)(arg1))); \ -__syscall_return(type,__res); \ -} - -#define _syscall2(type,name,type1,arg1,type2,arg2) \ -type name(type1 arg1,type2 arg2) \ -{ \ -long __res; \ -__asm__ volatile ("int $0x80" \ - : "=a" (__res) \ - : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2))); \ -__syscall_return(type,__res); \ -} - -#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ -type name(type1 arg1,type2 arg2,type3 arg3) \ -{ \ -long __res; \ -__asm__ volatile ("int $0x80" \ - : "=a" (__res) \ - : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ - "d" ((long)(arg3))); \ -__syscall_return(type,__res); \ -} - -#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ -long __res; \ -__asm__ volatile ("int $0x80" \ - : "=a" (__res) \ - : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ - "d" ((long)(arg3)),"S" ((long)(arg4))); \ -__syscall_return(type,__res); \ -} - -#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ - type5,arg5) \ -type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ -{ \ -long __res; \ -__asm__ volatile ("int $0x80" \ - : "=a" (__res) \ - : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ - "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \ -__syscall_return(type,__res); \ -} - - -#endif /* __PIC__ */ - - diff --git a/ldso/ldso/i386/sysdep.h b/ldso/ldso/i386/sysdep.h deleted file mode 100644 index d44b020ee..000000000 --- a/ldso/ldso/i386/sysdep.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Various assmbly language/system dependent hacks that are required - * so that we can minimize the amount of platform specific code. - */ - -/* - * Define this if the system uses RELOCA. - */ -#undef ELF_USES_RELOCA - -/* - * 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) - -/* - * Initialization sequence for a GOT. - */ -#define INIT_GOT(GOT_BASE,MODULE) \ -{ \ - GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \ - GOT_BASE[1] = (unsigned long) MODULE; \ -} - -/* - * Here is a macro to perform a relocation. This is only used when - * bootstrapping the dynamic loader. RELP is the relocation that we - * are performing, REL is the pointer to the address we are relocating. - * SYMBOL is the symbol involved in the relocation, and LOAD is the - * load address. - */ -#define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD) \ - switch(ELF32_R_TYPE((RELP)->r_info)){ \ - case R_386_32: \ - *REL += SYMBOL; \ - break; \ - case R_386_PC32: \ - *REL += SYMBOL - (unsigned long) REL; \ - break; \ - case R_386_GLOB_DAT: \ - case R_386_JMP_SLOT: \ - *REL = SYMBOL; \ - break; \ - case R_386_RELATIVE: \ - *REL += (unsigned long) LOAD; \ - 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() \ - __asm__ volatile ("leave\n\t" \ - "jmp *%%eax\n\t" \ - : "=a" (status) : "a" (_dl_elf_main)) - - - -/* Here we define the magic numbers that this dynamic loader should accept */ - -#define MAGIC1 EM_386 -#undef MAGIC2 -/* Used for error messages */ -#define ELF_TARGET "386" - -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) diff --git a/ldso/ldso/ld_hash.h b/ldso/ldso/ld_hash.h index bb1b51fdc..01b3a4c33 100644 --- a/ldso/ldso/ld_hash.h +++ b/ldso/ldso/ld_hash.h @@ -1,7 +1,7 @@ #ifndef _HASH_H_ #define _HASH_H_ -#include "elf.h" +#include <elf.h> /* Header file that describes the internal data structures used by the * ELF dynamic linker. */ diff --git a/ldso/ldso/ld_syscall.h b/ldso/ldso/ld_syscall.h index 322c618f6..2542bc3e5 100644 --- a/ldso/ldso/ld_syscall.h +++ b/ldso/ldso/ld_syscall.h @@ -1,4 +1,13 @@ -#include "syscalls.h" +/* Pull in the arch specific type information */ +#include <sys/types.h> +/* Pull in the arch specific syscall implementation */ +#include "ld_syscalls.h" +/* For MAP_ANONYMOUS -- differs between platforms */ +#include <sys/mman.h> +/* Pull in whatever this particular arch's kernel thinks the kernel version of + * struct stat should look like. It turns out that each arch has a different + * opinion on the subject, and different kernel revs use different names... */ +#include <sys/stat.h> /* Here are the definitions for some syscalls that are used @@ -46,7 +55,6 @@ static inline void * _dl_mmap(void * addr, unsigned long size, int prot, #endif #define _dl_mmap_check_error(__res) \ (((int)__res) < 0 && ((int)__res) >= -_dl_MAX_ERRNO) -#include <sys/mman.h> // For MAP_ANONYMOUS -- differs between platforms #ifndef MAP_ANONYMOUS #ifdef __sparc__ #define MAP_ANONYMOUS 0x20 @@ -74,10 +82,6 @@ static inline _syscall3(int, _dl_mprotect, const void *, addr, unsigned long, le -/* Pull in whatever this particular arch's kernel thinks the kernel version of - * struct stat should look like. It turns out that each arch has a different - * opinion on the subject, and different kernel revs use different names... */ -#include <sys/stat.h> #define __NR__dl_stat __NR_stat static inline _syscall2(int, _dl_stat, const char *, file_name, struct stat *, buf); diff --git a/ldso/ldso/linuxelf.h b/ldso/ldso/linuxelf.h index 3bbcfa7c9..6d044a7ae 100644 --- a/ldso/ldso/linuxelf.h +++ b/ldso/ldso/linuxelf.h @@ -1,6 +1,11 @@ #ifndef LINUXELF_H #define LINUXELF_H + +#include <sys/types.h> +#include "ld_sysdep.h" /* before elf.h to get ELF_USES_RELOCA right */ +#include <elf.h> + /* Forward declarations for stuff defined in hash.h */ struct dyn_elf; struct elf_resolve; diff --git a/ldso/ldso/m68k/elfinterp.c b/ldso/ldso/m68k/elfinterp.c index cdd2d337d..f5554f6a1 100644 --- a/ldso/ldso/m68k/elfinterp.c +++ b/ldso/ldso/m68k/elfinterp.c @@ -48,12 +48,10 @@ static char *_dl_reltypes[] = a more than adequate job of explaining everything required to get this working. */ -#include <sys/types.h> -#include "elf.h" -#include "hash.h" -#include "syscall.h" -#include "string.h" -#include "sysdep.h" +#include "linuxelf.h" +#include "ld_hash.h" +#include "ld_syscall.h" +#include "ld_string.h" extern char *_dl_progname; diff --git a/ldso/ldso/m68k/syscalls.h b/ldso/ldso/m68k/syscalls.h deleted file mode 100644 index 5ffb61bac..000000000 --- a/ldso/ldso/m68k/syscalls.h +++ /dev/null @@ -1,175 +0,0 @@ -#include <sys/types.h> - -/* - * This file contains the system call macros and syscall - * numbers used by the shared library loader. - */ - -#define __NR_exit 1 -#define __NR_read 3 -#define __NR_write 4 -#define __NR_open 5 -#define __NR_close 6 -#define __NR_getuid 24 -#define __NR_geteuid 49 -#define __NR_getgid 47 -#define __NR_getegid 50 -#define __NR_mmap 90 -#define __NR_munmap 91 -#define __NR_stat 106 -#define __NR_mprotect 125 - - -/* Here are the macros which define how this platform makes - * system calls. This particular variant does _not_ set - * errno (note how it is disabled in __syscall_return) since - * these will get called before the errno symbol is dynamicly - * linked. */ - - -#define __syscall_return(type, res) \ -do { \ - if ((unsigned long)(res) >= (unsigned long)(-125)) { \ - /* avoid using res which is declared to be in register d0; \ - errno might expand to a function call and clobber it. */ \ - /* int __err = -(res); \ - errno = __err; */ \ - res = -1; \ - } \ - return (type) (res); \ -} while (0) - -#define _syscall0(type, name) \ -type name(void) \ -{ \ - long __res; \ - __asm__ __volatile__ ("movel %1, %%d0\n\t" \ - "trap #0\n\t" \ - "movel %%d0, %0" \ - : "=g" (__res) \ - : "i" (__NR_##name) \ - : "cc", "%d0"); \ - if ((unsigned long)(__res) >= (unsigned long)(-125)) { \ - /* errno = -__res; */ \ - __res = -1; \ - } \ - return (type)__res; \ -} - -#define _syscall1(type, name, atype, a) \ -type name(atype a) \ -{ \ - long __res; \ - __asm__ __volatile__ ("movel %2, %%d1\n\t" \ - "movel %1, %%d0\n\t" \ - "trap #0\n\t" \ - "movel %%d0, %0" \ - : "=g" (__res) \ - : "i" (__NR_##name), \ - "g" ((long)a) \ - : "cc", "%d0", "%d1"); \ - if ((unsigned long)(__res) >= (unsigned long)(-125)) { \ - /* errno = -__res; */ \ - __res = -1; \ - } \ - return (type)__res; \ -} - -#define _syscall2(type, name, atype, a, btype, b) \ -type name(atype a, btype b) \ -{ \ - long __res; \ - __asm__ __volatile__ ("movel %3, %%d2\n\t" \ - "movel %2, %%d1\n\t" \ - "movel %1, %%d0\n\t" \ - "trap #0\n\t" \ - "movel %%d0, %0" \ - : "=g" (__res) \ - : "i" (__NR_##name), \ - "a" ((long)a), \ - "g" ((long)b) \ - : "cc", "%d0", "%d1", "%d2"); \ - if ((unsigned long)(__res) >= (unsigned long)(-125)) { \ - /* errno = -__res; */ \ - __res = -1; \ - } \ - return (type)__res; \ -} - -#define _syscall3(type, name, atype, a, btype, b, ctype, c) \ -type name(atype a, btype b, ctype c) \ -{ \ - long __res; \ - __asm__ __volatile__ ("movel %4, %%d3\n\t" \ - "movel %3, %%d2\n\t" \ - "movel %2, %%d1\n\t" \ - "movel %1, %%d0\n\t" \ - "trap #0\n\t" \ - "movel %%d0, %0" \ - : "=g" (__res) \ - : "i" (__NR_##name), \ - "a" ((long)a), \ - "a" ((long)b), \ - "g" ((long)c) \ - : "cc", "%d0", "%d1", "%d2", "%d3"); \ - if ((unsigned long)(__res) >= (unsigned long)(-125)) { \ - /* errno = -__res; */ \ - __res = -1; \ - } \ - return (type)__res; \ -} - -#define _syscall4(type, name, atype, a, btype, b, ctype, c, dtype, d) \ -type name(atype a, btype b, ctype c, dtype d) \ -{ \ - long __res; \ - __asm__ __volatile__ ("movel %5, %%d4\n\t" \ - "movel %4, %%d3\n\t" \ - "movel %3, %%d2\n\t" \ - "movel %2, %%d1\n\t" \ - "movel %1, %%d0\n\t" \ - "trap #0\n\t" \ - "movel %%d0, %0" \ - : "=g" (__res) \ - : "i" (__NR_##name), \ - "a" ((long)a), \ - "a" ((long)b), \ - "a" ((long)c), \ - "g" ((long)d) \ - : "cc", "%d0", "%d1", "%d2", "%d3", \ - "%d4"); \ - if ((unsigned long)(__res) >= (unsigned long)(-125)) { \ - /* errno = -__res; */ \ - __res = -1; \ - } \ - return (type)__res; \ -} - -#define _syscall5(type, name, atype, a, btype, b, ctype, c, dtype, d, etype, e)\ -type name(atype a, btype b, ctype c, dtype d, etype e) \ -{ \ - long __res; \ - __asm__ __volatile__ ("movel %6, %%d5\n\t" \ - "movel %5, %%d4\n\t" \ - "movel %4, %%d3\n\t" \ - "movel %3, %%d2\n\t" \ - "movel %2, %%d1\n\t" \ - "movel %1, %%d0\n\t" \ - "trap #0\n\t" \ - "movel %%d0, %0" \ - : "=g" (__res) \ - : "i" (__NR_##name), \ - "a" ((long)a), \ - "a" ((long)b), \ - "a" ((long)c), \ - "a" ((long)d), \ - "g" ((long)e) \ - : "cc", "%d0", "%d1", "%d2", "%d3", \ - "%d4", "%d5"); \ - if ((unsigned long)(__res) >= (unsigned long)(-125)) { \ - /* errno = -__res; */ \ - __res = -1; \ - } \ - return (type)__res; \ -} - diff --git a/ldso/ldso/m68k/sysdep.h b/ldso/ldso/m68k/sysdep.h deleted file mode 100644 index a9089286b..000000000 --- a/ldso/ldso/m68k/sysdep.h +++ /dev/null @@ -1,83 +0,0 @@ - -/* Various assmbly language/system dependent hacks that are required - so that we can minimize the amount of platform specific code. */ - -/* Define this if the system uses RELOCA. */ -#define ELF_USES_RELOCA - -/* 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 int *) &(ARGS))) - -/* Initialization sequence for a GOT. */ -#define INIT_GOT(GOT_BASE,MODULE) \ -{ \ - GOT_BASE[2] = (int) _dl_linux_resolve; \ - GOT_BASE[1] = (int) (MODULE); \ -} - -/* Here is a macro to perform a relocation. This is only used when - bootstrapping the dynamic loader. RELP is the relocation that we - are performing, REL is the pointer to the address we are - relocating. SYMBOL is the symbol involved in the relocation, and - LOAD is the load address. */ -#define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD) \ - switch (ELF32_R_TYPE ((RELP)->r_info)) \ - { \ - case R_68K_8: \ - *(char *) (REL) = (SYMBOL) + (RELP)->r_addend; \ - break; \ - case R_68K_16: \ - *(short *) (REL) = (SYMBOL) + (RELP)->r_addend; \ - break; \ - case R_68K_32: \ - *(REL) = (SYMBOL) + (RELP)->r_addend; \ - break; \ - case R_68K_PC8: \ - *(char *) (REL) = ((SYMBOL) + (RELP)->r_addend \ - - (unsigned int) (REL)); \ - break; \ - case R_68K_PC16: \ - *(short *) (REL) = ((SYMBOL) + (RELP)->r_addend \ - - (unsigned int) (REL)); \ - break; \ - case R_68K_PC32: \ - *(REL) = ((SYMBOL) + (RELP)->r_addend \ - - (unsigned int) (REL)); \ - break; \ - case R_68K_GLOB_DAT: \ - case R_68K_JMP_SLOT: \ - *(REL) = (SYMBOL); \ - break; \ - case R_68K_RELATIVE: /* Compatibility kludge */ \ - *(REL) = ((unsigned int) (LOAD) + ((RELP)->r_addend ? : *(REL))); \ - break; \ - default: \ - _dl_exit (1); \ - } - - -/* Transfer control to the user's application, once the dynamic loader - is done. */ - -#define START() \ - __asm__ volatile ("unlk %%a6\n\t" \ - "jmp %0@" \ - : : "a" (_dl_elf_main)); - - - -/* Here we define the magic numbers that this dynamic loader should accept */ - -#define MAGIC1 EM_68K -#undef MAGIC2 -/* Used for error messages */ -#define ELF_TARGET "m68k" - -struct elf_resolve; -extern unsigned int _dl_linux_resolver (int, int, struct elf_resolve *, int); - -/* Define this because we do not want to call .udiv in the library. - Not needed for m68k. */ -#define do_rem(result, n, base) ((result) = (n) % (base)) diff --git a/ldso/ldso/powerpc/elfinterp.c b/ldso/ldso/powerpc/elfinterp.c index db53e8f46..4da5d9d98 100644 --- a/ldso/ldso/powerpc/elfinterp.c +++ b/ldso/ldso/powerpc/elfinterp.c @@ -48,14 +48,11 @@ static char *_dl_reltypes[] = a more than adequate job of explaining everything required to get this working. */ -#include <sys/types.h> -#include <errno.h> -#include "sysdep.h" -#include <elf.h> #include "linuxelf.h" -#include "hash.h" -#include "syscall.h" -#include "string.h" +#include "ld_hash.h" +#include "ld_syscall.h" +#include "ld_string.h" +#include <errno.h> #ifdef DEBUG static void debug_sym(Elf32_Sym *symtab,char *strtab,int symtab_index); diff --git a/ldso/ldso/powerpc/syscalls.h b/ldso/ldso/powerpc/syscalls.h deleted file mode 100644 index ae37aa822..000000000 --- a/ldso/ldso/powerpc/syscalls.h +++ /dev/null @@ -1,243 +0,0 @@ -#include <sys/types.h> - -/* - * This file contains the system call macros and syscall - * numbers used by the shared library loader. - */ - -#define __NR_exit 1 -#define __NR_read 3 -#define __NR_write 4 -#define __NR_open 5 -#define __NR_close 6 -#define __NR_getuid 24 -#define __NR_geteuid 49 -#define __NR_getgid 47 -#define __NR_getegid 50 -#define __NR_mmap 90 -#define __NR_munmap 91 -#define __NR_stat 106 -#define __NR_mprotect 125 - -/* Here are the macros which define how this platform makes - * system calls. This particular variant does _not_ set - * errno (note how it is disabled in __syscall_return) since - * these will get called before the errno symbol is dynamicly - * linked. */ - -#undef __syscall_return -#define __syscall_return(type) \ - return (__sc_err & 0x10000000 ? /*errno = __sc_ret,*/ __sc_ret = -1 : 0), \ - (type) __sc_ret - -#undef __syscall_clobbers -#define __syscall_clobbers \ - "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12" - -#undef _syscall0 -#define _syscall0(type,name) \ -type name(void) \ -{ \ - unsigned long __sc_ret, __sc_err; \ - { \ - register unsigned long __sc_0 __asm__ ("r0"); \ - register unsigned long __sc_3 __asm__ ("r3"); \ - \ - __sc_0 = __NR_##name; \ - __asm__ __volatile__ \ - ("sc \n\t" \ - "mfcr %1 " \ - : "=&r" (__sc_3), "=&r" (__sc_0) \ - : "0" (__sc_3), "1" (__sc_0) \ - : __syscall_clobbers); \ - __sc_ret = __sc_3; \ - __sc_err = __sc_0; \ - } \ - __syscall_return (type); \ -} - -#undef _syscall1 -#define _syscall1(type,name,type1,arg1) \ -type name(type1 arg1) \ -{ \ - unsigned long __sc_ret, __sc_err; \ - { \ - register unsigned long __sc_0 __asm__ ("r0"); \ - register unsigned long __sc_3 __asm__ ("r3"); \ - \ - __sc_3 = (unsigned long) (arg1); \ - __sc_0 = __NR_##name; \ - __asm__ __volatile__ \ - ("sc \n\t" \ - "mfcr %1 " \ - : "=&r" (__sc_3), "=&r" (__sc_0) \ - : "0" (__sc_3), "1" (__sc_0) \ - : __syscall_clobbers); \ - __sc_ret = __sc_3; \ - __sc_err = __sc_0; \ - } \ - __syscall_return (type); \ -} - -#undef _syscall2 -#define _syscall2(type,name,type1,arg1,type2,arg2) \ -type name(type1 arg1, type2 arg2) \ -{ \ - unsigned long __sc_ret, __sc_err; \ - { \ - register unsigned long __sc_0 __asm__ ("r0"); \ - register unsigned long __sc_3 __asm__ ("r3"); \ - register unsigned long __sc_4 __asm__ ("r4"); \ - \ - __sc_3 = (unsigned long) (arg1); \ - __sc_4 = (unsigned long) (arg2); \ - __sc_0 = __NR_##name; \ - __asm__ __volatile__ \ - ("sc \n\t" \ - "mfcr %1 " \ - : "=&r" (__sc_3), "=&r" (__sc_0) \ - : "0" (__sc_3), "1" (__sc_0), \ - "r" (__sc_4) \ - : __syscall_clobbers); \ - __sc_ret = __sc_3; \ - __sc_err = __sc_0; \ - } \ - __syscall_return (type); \ -} - -#undef _syscall3 -#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ -type name(type1 arg1, type2 arg2, type3 arg3) \ -{ \ - unsigned long __sc_ret, __sc_err; \ - { \ - register unsigned long __sc_0 __asm__ ("r0"); \ - register unsigned long __sc_3 __asm__ ("r3"); \ - register unsigned long __sc_4 __asm__ ("r4"); \ - register unsigned long __sc_5 __asm__ ("r5"); \ - \ - __sc_3 = (unsigned long) (arg1); \ - __sc_4 = (unsigned long) (arg2); \ - __sc_5 = (unsigned long) (arg3); \ - __sc_0 = __NR_##name; \ - __asm__ __volatile__ \ - ("sc \n\t" \ - "mfcr %1 " \ - : "=&r" (__sc_3), "=&r" (__sc_0) \ - : "0" (__sc_3), "1" (__sc_0), \ - "r" (__sc_4), \ - "r" (__sc_5) \ - : __syscall_clobbers); \ - __sc_ret = __sc_3; \ - __sc_err = __sc_0; \ - } \ - __syscall_return (type); \ -} - -#undef _syscall4 -#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ - unsigned long __sc_ret, __sc_err; \ - { \ - register unsigned long __sc_0 __asm__ ("r0"); \ - register unsigned long __sc_3 __asm__ ("r3"); \ - register unsigned long __sc_4 __asm__ ("r4"); \ - register unsigned long __sc_5 __asm__ ("r5"); \ - register unsigned long __sc_6 __asm__ ("r6"); \ - \ - __sc_3 = (unsigned long) (arg1); \ - __sc_4 = (unsigned long) (arg2); \ - __sc_5 = (unsigned long) (arg3); \ - __sc_6 = (unsigned long) (arg4); \ - __sc_0 = __NR_##name; \ - __asm__ __volatile__ \ - ("sc \n\t" \ - "mfcr %1 " \ - : "=&r" (__sc_3), "=&r" (__sc_0) \ - : "0" (__sc_3), "1" (__sc_0), \ - "r" (__sc_4), \ - "r" (__sc_5), \ - "r" (__sc_6) \ - : __syscall_clobbers); \ - __sc_ret = __sc_3; \ - __sc_err = __sc_0; \ - } \ - __syscall_return (type); \ -} - -#undef _syscall5 -#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5) \ -type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \ -{ \ - unsigned long __sc_ret, __sc_err; \ - { \ - register unsigned long __sc_0 __asm__ ("r0"); \ - register unsigned long __sc_3 __asm__ ("r3"); \ - register unsigned long __sc_4 __asm__ ("r4"); \ - register unsigned long __sc_5 __asm__ ("r5"); \ - register unsigned long __sc_6 __asm__ ("r6"); \ - register unsigned long __sc_7 __asm__ ("r7"); \ - \ - __sc_3 = (unsigned long) (arg1); \ - __sc_4 = (unsigned long) (arg2); \ - __sc_5 = (unsigned long) (arg3); \ - __sc_6 = (unsigned long) (arg4); \ - __sc_7 = (unsigned long) (arg5); \ - __sc_0 = __NR_##name; \ - __asm__ __volatile__ \ - ("sc \n\t" \ - "mfcr %1 " \ - : "=&r" (__sc_3), "=&r" (__sc_0) \ - : "0" (__sc_3), "1" (__sc_0), \ - "r" (__sc_4), \ - "r" (__sc_5), \ - "r" (__sc_6), \ - "r" (__sc_7) \ - : __syscall_clobbers); \ - __sc_ret = __sc_3; \ - __sc_err = __sc_0; \ - } \ - __syscall_return (type); \ -} - - -#undef _syscall6 -#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5,type6,arg6) \ -type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) \ -{ \ - unsigned long __sc_ret, __sc_err; \ - { \ - register unsigned long __sc_0 __asm__ ("r0"); \ - register unsigned long __sc_3 __asm__ ("r3"); \ - register unsigned long __sc_4 __asm__ ("r4"); \ - register unsigned long __sc_5 __asm__ ("r5"); \ - register unsigned long __sc_6 __asm__ ("r6"); \ - register unsigned long __sc_7 __asm__ ("r7"); \ - register unsigned long __sc_8 __asm__ ("r8"); \ - \ - __sc_3 = (unsigned long) (arg1); \ - __sc_4 = (unsigned long) (arg2); \ - __sc_5 = (unsigned long) (arg3); \ - __sc_6 = (unsigned long) (arg4); \ - __sc_7 = (unsigned long) (arg5); \ - __sc_8 = (unsigned long) (arg6); \ - __sc_0 = __NR_##name; \ - __asm__ __volatile__ \ - ("sc \n\t" \ - "mfcr %1 " \ - : "=&r" (__sc_3), "=&r" (__sc_0) \ - : "0" (__sc_3), "1" (__sc_0), \ - "r" (__sc_4), \ - "r" (__sc_5), \ - "r" (__sc_6), \ - "r" (__sc_7), \ - "r" (__sc_8) \ - : __syscall_clobbers); \ - __sc_ret = __sc_3; \ - __sc_err = __sc_0; \ - } \ - __syscall_return (type); \ -} - - diff --git a/ldso/ldso/powerpc/sysdep.h b/ldso/ldso/powerpc/sysdep.h deleted file mode 100644 index 3f4db4682..000000000 --- a/ldso/ldso/powerpc/sysdep.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Various assmbly language/system dependent hacks that are required - * so that we can minimize the amount of platform specific code. - */ - -/* - * Define this if the system uses RELOCA. - */ -#define ELF_USES_RELOCA - -/* - * 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) - -/* - * Initialization sequence for a GOT. - */ -#define INIT_GOT(GOT_BASE,MODULE) _dl_init_got(GOT_BASE,MODULE) - -/* Stuff for the PLT. */ -#define PLT_INITIAL_ENTRY_WORDS 18 -#define PLT_LONGBRANCH_ENTRY_WORDS 0 -#define PLT_TRAMPOLINE_ENTRY_WORDS 6 -#define PLT_DOUBLE_SIZE (1<<13) -#define PLT_ENTRY_START_WORDS(entry_number) \ - (PLT_INITIAL_ENTRY_WORDS + (entry_number)*2 \ - + ((entry_number) > PLT_DOUBLE_SIZE \ - ? ((entry_number) - PLT_DOUBLE_SIZE)*2 \ - : 0)) -#define PLT_DATA_START_WORDS(num_entries) PLT_ENTRY_START_WORDS(num_entries) - -/* Macros to build PowerPC opcode words. */ -#define OPCODE_ADDI(rd,ra,simm) \ - (0x38000000 | (rd) << 21 | (ra) << 16 | ((simm) & 0xffff)) -#define OPCODE_ADDIS(rd,ra,simm) \ - (0x3c000000 | (rd) << 21 | (ra) << 16 | ((simm) & 0xffff)) -#define OPCODE_ADD(rd,ra,rb) \ - (0x7c000214 | (rd) << 21 | (ra) << 16 | (rb) << 11) -#define OPCODE_B(target) (0x48000000 | ((target) & 0x03fffffc)) -#define OPCODE_BA(target) (0x48000002 | ((target) & 0x03fffffc)) -#define OPCODE_BCTR() 0x4e800420 -#define OPCODE_LWZ(rd,d,ra) \ - (0x80000000 | (rd) << 21 | (ra) << 16 | ((d) & 0xffff)) -#define OPCODE_LWZU(rd,d,ra) \ - (0x84000000 | (rd) << 21 | (ra) << 16 | ((d) & 0xffff)) -#define OPCODE_MTCTR(rd) (0x7C0903A6 | (rd) << 21) -#define OPCODE_RLWINM(ra,rs,sh,mb,me) \ - (0x54000000 | (rs) << 21 | (ra) << 16 | (sh) << 11 | (mb) << 6 | (me) << 1) - -#define OPCODE_LI(rd,simm) OPCODE_ADDI(rd,0,simm) -#define OPCODE_ADDIS_HI(rd,ra,value) \ - OPCODE_ADDIS(rd,ra,((value) + 0x8000) >> 16) -#define OPCODE_LIS_HI(rd,value) OPCODE_ADDIS_HI(rd,0,value) -#define OPCODE_SLWI(ra,rs,sh) OPCODE_RLWINM(ra,rs,sh,0,31-sh) - - -#define PPC_DCBST(where) asm volatile ("dcbst 0,%0" : : "r"(where) : "memory") -#define PPC_SYNC asm volatile ("sync" : : : "memory") -#define PPC_ISYNC asm volatile ("sync; isync" : : : "memory") -#define PPC_ICBI(where) asm volatile ("icbi 0,%0" : : "r"(where) : "memory") -#define PPC_DIE asm volatile ("tweq 0,0") - -/* - * Here is a macro to perform a relocation. This is only used when - * bootstrapping the dynamic loader. RELP is the relocation that we - * are performing, REL is the pointer to the address we are relocating. - * SYMBOL is the symbol involved in the relocation, and LOAD is the - * load address. - */ -// finaladdr = LOAD ? -#define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD) \ - {int type=ELF32_R_TYPE((RELP)->r_info); \ - if(type==R_PPC_NONE){ \ - }else if(type==R_PPC_ADDR32){ \ - *REL += (SYMBOL); \ - }else if(type==R_PPC_RELATIVE){ \ - *REL = (Elf32_Word)(LOAD) + (RELP)->r_addend; \ - }else if(type==R_PPC_REL24){ \ - Elf32_Sword delta = (Elf32_Word)(SYMBOL) - (Elf32_Word)(REL); \ - *REL &= 0xfc000003; \ - *REL |= (delta & 0x03fffffc); \ - }else if(type==R_PPC_JMP_SLOT){ \ - Elf32_Sword delta = (Elf32_Word)(SYMBOL) - (Elf32_Word)(REL); \ - /*if (delta << 6 >> 6 != delta)_dl_exit(99);*/ \ - *REL = OPCODE_B(delta); \ - }else{ \ - _dl_exit(100+ELF32_R_TYPE((RELP)->r_info)); \ - } \ -/*hexprint(*REL);*/ \ - PPC_DCBST(REL); PPC_SYNC; PPC_ICBI(REL); \ - } - -/* - * 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() \ - __asm__ volatile ( \ - "addi 1,%1,0\n\t" \ - "mtlr %0\n\t" \ - "blrl\n\t" \ - : : "r" (_dl_elf_main), "r" (args)) - - - -/* Here we define the magic numbers that this dynamic loader should accept */ - -#define MAGIC1 EM_PPC -#undef MAGIC2 -/* Used for error messages */ -#define ELF_TARGET "powerpc" - -struct elf_resolve; -extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry); -void _dl_init_got(unsigned long *lpnt,struct elf_resolve *tpnt); - - -#define do_rem(result, n, base) result = (n % base) diff --git a/ldso/ldso/readelflib1.c b/ldso/ldso/readelflib1.c index eed74321d..335f6fc29 100644 --- a/ldso/ldso/readelflib1.c +++ b/ldso/ldso/readelflib1.c @@ -21,12 +21,10 @@ /* This file contains the helper routines to load an ELF sharable library into memory and add the symbol table info to the chain. */ -#include <elf.h> #include "linuxelf.h" -#include "string.h" -#include "hash.h" -#include "sysdep.h" -#include "syscall.h" +#include "ld_hash.h" +#include "ld_syscall.h" +#include "ld_string.h" #include <sys/mman.h> #ifdef USE_CACHE #include "../config.h" diff --git a/ldso/ldso/sparc/elfinterp.c b/ldso/ldso/sparc/elfinterp.c index 8ca84e564..cd34babf6 100644 --- a/ldso/ldso/sparc/elfinterp.c +++ b/ldso/ldso/sparc/elfinterp.c @@ -41,12 +41,10 @@ an ELF sharable library or a linux style of shared library. */ a more than adequate job of explaining everything required to get this working. */ -#include <sys/types.h> -#include "elf.h" -#include "hash.h" -#include "syscall.h" -#include "string.h" -#include "sysdep.h" +#include "linuxelf.h" +#include "ld_hash.h" +#include "ld_syscall.h" +#include "ld_string.h" extern char *_dl_progname; diff --git a/ldso/ldso/sparc/resolve.S b/ldso/ldso/sparc/resolve.S index ea985b5c8..57c4b6804 100644 --- a/ldso/ldso/sparc/resolve.S +++ b/ldso/ldso/sparc/resolve.S @@ -2,7 +2,7 @@ * These are various helper routines that are needed to run an ELF image. */ #define COMPILE_ASM -#include "sysdep.h" +#include "ld_sysdep.h" .text .align 16 diff --git a/ldso/ldso/sparc/syscalls.h b/ldso/ldso/sparc/syscalls.h deleted file mode 100644 index d7cd3734b..000000000 --- a/ldso/ldso/sparc/syscalls.h +++ /dev/null @@ -1,156 +0,0 @@ -#include <sys/types.h> - -/* - * This file contains the system call macros and syscall - * numbers used by the shared library loader. - */ - -#define __NR_exit 1 -#define __NR_read 3 -#define __NR_write 4 -#define __NR_open 5 -#define __NR_close 6 -#define __NR_getuid 24 -#define __NR_getgid 47 -#define __NR_geteuid 49 -#define __NR_getegid 50 -#define __NR_mmap 71 -#define __NR_munmap 73 -#define __NR_stat 38 -#define __NR_mprotect 74 - -/* Here are the macros which define how this platform makes - * system calls. This particular variant does _not_ set - * errno (note how it is disabled in __syscall_return) since - * these will get called before the errno symbol is dynamicly - * linked. */ - -#define _syscall0(type,name) \ -type name(void) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##name; \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res)\ - : "r" (__g1) \ - : "o0", "cc"); \ -if (__res < -255 || __res >= 0) \ - return (type) __res; \ -/*errno = -__res; */\ -return -1; \ -} - -#define _syscall1(type,name,type1,arg1) \ -type name(type1 arg1) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##name; \ -register long __o0 __asm__ ("o0") = (long)(arg1); \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res), "=&r" (__o0) \ - : "1" (__o0), "r" (__g1) \ - : "cc"); \ -if (__res < -255 || __res >= 0) \ - return (type) __res; \ -/*errno = -__res;*/ \ -return -1; \ -} - -#define _syscall2(type,name,type1,arg1,type2,arg2) \ -type name(type1 arg1,type2 arg2) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##name; \ -register long __o0 __asm__ ("o0") = (long)(arg1); \ -register long __o1 __asm__ ("o1") = (long)(arg2); \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res), "=&r" (__o0) \ - : "1" (__o0), "r" (__o1), "r" (__g1) \ - : "cc"); \ -if (__res < -255 || __res >= 0) \ - return (type) __res; \ -/*errno = -__res;*/ \ -return -1; \ -} - -#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ -type name(type1 arg1,type2 arg2,type3 arg3) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##name; \ -register long __o0 __asm__ ("o0") = (long)(arg1); \ -register long __o1 __asm__ ("o1") = (long)(arg2); \ -register long __o2 __asm__ ("o2") = (long)(arg3); \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res), "=&r" (__o0) \ - : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__g1) \ - : "cc"); \ -if (__res < -255 || __res>=0) \ - return (type) __res; \ -/*errno = -__res;*/ \ -return -1; \ -} - -#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ -type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##name; \ -register long __o0 __asm__ ("o0") = (long)(arg1); \ -register long __o1 __asm__ ("o1") = (long)(arg2); \ -register long __o2 __asm__ ("o2") = (long)(arg3); \ -register long __o3 __asm__ ("o3") = (long)(arg4); \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res), "=&r" (__o0) \ - : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__g1) \ - : "cc"); \ -if (__res < -255 || __res>=0) \ - return (type) __res; \ -/*errno = -__res;*/ \ -return -1; \ -} - -#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ - type5,arg5) \ -type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ -{ \ -long __res; \ -register long __g1 __asm__ ("g1") = __NR_##name; \ -register long __o0 __asm__ ("o0") = (long)(arg1); \ -register long __o1 __asm__ ("o1") = (long)(arg2); \ -register long __o2 __asm__ ("o2") = (long)(arg3); \ -register long __o3 __asm__ ("o3") = (long)(arg4); \ -register long __o4 __asm__ ("o4") = (long)(arg5); \ -__asm__ __volatile__ ("t 0x10\n\t" \ - "bcc 1f\n\t" \ - "mov %%o0, %0\n\t" \ - "sub %%g0, %%o0, %0\n\t" \ - "1:\n\t" \ - : "=r" (__res), "=&r" (__o0) \ - : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__o3), "r" (__o4), "r" (__g1) \ - : "cc"); \ -if (__res < -255 || __res>=0) \ - return (type) __res; \ -/*errno = -__res; */\ -return -1; \ -} diff --git a/ldso/ldso/sparc/sysdep.h b/ldso/ldso/sparc/sysdep.h deleted file mode 100644 index 3c8d9b8d1..000000000 --- a/ldso/ldso/sparc/sysdep.h +++ /dev/null @@ -1,125 +0,0 @@ - -/* - * Various assmbly language/system dependent hacks that are required - * so that we can minimize the amount of platform specific code. - */ -#define LINUXBIN - -/* - * Define this if the system uses RELOCA. - */ -#define ELF_USES_RELOCA - -/* - * 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. We assume that argc is stored - * at the word just below the argvp that we return here. - */ -#define GET_ARGV(ARGVP, ARGS) __asm__("\tadd %%fp,68,%0\n" : "=r" (ARGVP)); - -/* - * Initialization sequence for a GOT. For the Sparc, this points to the - * PLT, and we need to initialize a couple of the slots. The PLT should - * look like: - * - * save %sp, -64, %sp - * call _dl_linux_resolve - * nop - * .word implementation_dependent - */ -#define INIT_GOT(GOT_BASE,MODULE) \ -{ \ - GOT_BASE[0] = 0x9de3bfc0; /* save %sp, -64, %sp */ \ - GOT_BASE[1] = 0x40000000 | (((unsigned int) _dl_linux_resolve - (unsigned int) GOT_BASE - 4) >> 2); \ - GOT_BASE[2] = 0x01000000; /* nop */ \ - GOT_BASE[3] = (int) MODULE; \ -} - -/* - * Here is a macro to perform a relocation. This is only used when - * bootstrapping the dynamic loader. - */ -#define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD) \ - 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() \ - __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") - - - -/* Here we define the magic numbers that this dynamic loader should accept */ - -#define MAGIC1 EM_SPARC -#undef MAGIC2 -/* Used for error messages */ -#define ELF_TARGET "Sparc" - -#ifndef COMPILE_ASM -extern unsigned int _dl_linux_resolver(unsigned int reloc_entry, - unsigned int * i); -#endif - -/* - * Define this if you want a dynamic loader that works on Solaris. - */ -#define SOLARIS_COMPATIBLE - -/* - * Define this because we do not want to call .udiv in the library. - * Change on the plans -miguel: - * We just statically link against .udiv. This is required - * if we want to be able to run on Sun4c machines. - */ - -/* We now link .urem against this one */ -#ifdef USE_V8 -#define do_rem(result,n,base) ({ \ -volatile int __res; \ -__asm__("mov %%g0,%%Y\n\t" \ - "sdiv %2,%3,%%l6\n\t" \ - "smul %%l6,%3,%%l6\n\t" \ - "sub %2,%%l6,%0\n\t" \ - :"=r" (result),"=r" (__res):"r" (n),"r"(base) : "l6" ); __res; }) -#else -#define do_rem(a,b,c) a = _dl_urem (b,c); -#endif -/* - * dbx wants the binder to have a specific name. Mustn't disappoint it. - */ -#ifdef SOLARIS_COMPATIBLE -#define _dl_linux_resolve _elf_rtbndr -#endif - diff --git a/ldso/ldso/string.h b/ldso/ldso/string.h deleted file mode 100644 index b94b1c5f9..000000000 --- a/ldso/ldso/string.h +++ /dev/null @@ -1,259 +0,0 @@ -#ifndef _LINUX_STRING_H_ -#define _LINUX_STRING_H_ - -#include <sys/types.h> /* for size_t */ - -extern void *_dl_malloc(int size); -extern char *_dl_getenv(char *symbol, char **envp); -extern void _dl_unsetenv(char *symbol, char **envp); -extern char *_dl_strdup(const char *string); -extern void _dl_dprintf(int, const char *, ...); - - -static size_t _dl_strlen(const char * str); -static char *_dl_strcat(char *dst, const char *src); -static char * _dl_strcpy(char * dst,const char *src); -static int _dl_strcmp(const char * s1,const char * s2); -static int _dl_strncmp(const char * s1,const char * s2,size_t len); -static char * _dl_strchr(const char * str,int c); -static char *_dl_strrchr(const char *str, int c); -static void * _dl_memcpy(void * dst, const void * src, size_t len); -static int _dl_memcmp(const void * s1,const void * s2,size_t len); -static void *_dl_memset(void * str,int c,size_t len); -static char *_dl_get_last_path_component(char *path); -static char *_dl_simple_ltoa(char * local, unsigned long i); -static char *_dl_simple_ltoahex(char * local, unsigned long i); - -#ifndef NULL -#define NULL ((void *) 0) -#endif - -static inline size_t _dl_strlen(const char * str) -{ - register char *ptr = (char *) str; - - while (*ptr) - ptr++; - return (ptr - str); -} - -static inline char *_dl_strcat(char *dst, const char *src) -{ - register char *ptr = dst; - - while (*ptr) - ptr++; - - while (*src) - *ptr++ = *src++; - *ptr = '\0'; - - return dst; -} - -static inline char * _dl_strcpy(char * dst,const char *src) -{ - register char *ptr = dst; - - while (*src) - *dst++ = *src++; - *dst = '\0'; - - return ptr; -} - -static inline int _dl_strcmp(const char * s1,const char * s2) -{ - unsigned register char c1, c2; - - do { - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0') - return c1 - c2; - } - while (c1 == c2); - - return c1 - c2; -} - -static inline int _dl_strncmp(const char * s1,const char * s2,size_t len) -{ - unsigned register char c1 = '\0'; - unsigned register char c2 = '\0'; - - while (len > 0) { - c1 = (unsigned char) *s1++; - c2 = (unsigned char) *s2++; - if (c1 == '\0' || c1 != c2) - return c1 - c2; - len--; - } - - return c1 - c2; -} - -static inline char * _dl_strchr(const char * str,int c) -{ - register char ch; - - do { - if ((ch = *str) == c) - return (char *) str; - str++; - } - while (ch); - - return 0; -} - -static inline char *_dl_strrchr(const char *str, int c) -{ - register char *prev = 0; - register char *ptr = (char *) str; - - while (*ptr != '\0') { - if (*ptr == c) - prev = ptr; - ptr++; - } - if (c == '\0') - return(ptr); - return(prev); -} - -static inline void * _dl_memcpy(void * dst, const void * src, size_t len) -{ - register char *a = dst; - register const char *b = src; - - while (len--) - *a++ = *b++; - - return dst; -} - - -static inline int _dl_memcmp(const void * s1,const void * s2,size_t len) -{ - unsigned char *c1 = (unsigned char *)s1; - unsigned char *c2 = (unsigned char *)s2; - - while (len--) { - if (*c1 != *c2) - return *c1 - *c2; - c1++; - c2++; - } - return 0; -} - -static inline void * _dl_memset(void * str,int c,size_t len) -{ - register char *a = str; - - while (len--) - *a++ = c; - - return str; -} - -static inline char *_dl_get_last_path_component(char *path) -{ - char *s; - register char *ptr = path; - register char *prev = 0; - - while (*ptr) - ptr++; - s = ptr - 1; - - /* strip trailing slashes */ - while (s != path && *s == '/') { - *s-- = '\0'; - } - - /* find last component */ - ptr = path; - while (*ptr != '\0') { - if (*ptr == '/') - prev = ptr; - ptr++; - } - s = prev; - - if (s == NULL || s[1] == '\0') - return path; - else - return s+1; -} - -/* Early on, we can't call printf, so use this to print out - * numbers using the SEND_STDERR() macro */ -static inline char *_dl_simple_ltoa(char * local, unsigned long i) -{ - /* 21 digits plus null terminator, good for 64-bit or smaller ints */ - char *p = &local[21]; - *p-- = '\0'; - do { - *p-- = '0' + i % 10; - i /= 10; - } while (i > 0); - return p + 1; -} - -static inline char *_dl_simple_ltoahex(char * local, unsigned long i) -{ - /* 21 digits plus null terminator, good for 64-bit or smaller ints */ - char *p = &local[21]; - *p-- = '\0'; - do { - char temp = i % 0x10; - if (temp <= 0x09) - *p-- = '0' + temp; - else - *p-- = 'a' - 0x0a + temp; - i /= 0x10; - } while (i > 0); - *p-- = 'x'; - *p-- = '0'; - return p + 1; -} - - -#if defined mc68000 || defined __arm__ -/* On some arches constant strings are referenced through the GOT. */ -/* XXX Requires load_addr to be defined. */ -#define SEND_STDERR(X) \ - { const char *__s = (X); \ - if (__s < (const char *) load_addr) __s += load_addr; \ - _dl_write (2, __s, _dl_strlen (__s)); \ - } -#else -#define SEND_STDERR(X) _dl_write(2, X, _dl_strlen(X)); -#endif - -#define SEND_ADDRESS_STDERR(X, add_a_newline) { \ - char tmp[13], *tmp1; \ - _dl_memset(tmp, 0, sizeof(tmp)); \ - tmp1=_dl_simple_ltoahex( tmp, (unsigned long)(X)); \ - _dl_write(2, tmp1, _dl_strlen(tmp1)); \ - if (add_a_newline) { \ - tmp[0]='\n'; \ - _dl_write(2, tmp, 1); \ - } \ -}; - -#define SEND_NUMBER_STDERR(X, add_a_newline) { \ - char tmp[13], *tmp1; \ - _dl_memset(tmp, 0, sizeof(tmp)); \ - tmp1=_dl_simple_ltoahex( tmp, (unsigned long)(X)); \ - _dl_write(2, tmp1, _dl_strlen(tmp1)); \ - if (add_a_newline) { \ - tmp[0]='\n'; \ - _dl_write(2, tmp, 1); \ - } \ -}; - - -#endif diff --git a/ldso/ldso/syscall.h b/ldso/ldso/syscall.h deleted file mode 100644 index 322c618f6..000000000 --- a/ldso/ldso/syscall.h +++ /dev/null @@ -1,118 +0,0 @@ -#include "syscalls.h" - - -/* Here are the definitions for some syscalls that are used - by the dynamic linker. The idea is that we want to be able - to call these before the errno symbol is dynamicly linked, so - we use our own version here. Note that we cannot assume any - dynamic linking at all, so we cannot return any error codes. - We just punt if there is an error. */ - - -#define __NR__dl_exit __NR_exit -static inline _syscall1(void, _dl_exit, int, status); - - -#define __NR__dl_close __NR_close -static inline _syscall1(int, _dl_close, int, fd); - - -#ifdef __powerpc__ -/* PowerPC has a different calling convention for mmap(). */ -#define __NR__dl_mmap __NR_mmap -static inline _syscall6(void *, _dl_mmap, void *, start, size_t, length, - int, prot, int, flags, int, fd, off_t, offset); -#else -#define __NR__dl_mmap_real __NR_mmap -static inline _syscall1(void *, _dl_mmap_real, unsigned long *, buffer); - -static inline void * _dl_mmap(void * addr, unsigned long size, int prot, - int flags, int fd, unsigned long offset) -{ - unsigned long buffer[6]; - - buffer[0] = (unsigned long) addr; - buffer[1] = (unsigned long) size; - buffer[2] = (unsigned long) prot; - buffer[3] = (unsigned long) flags; - buffer[4] = (unsigned long) fd; - buffer[5] = (unsigned long) offset; - return (void *) _dl_mmap_real(buffer); -} -#endif - -#ifndef _dl_MAX_ERRNO -#define _dl_MAX_ERRNO 4096 -#endif -#define _dl_mmap_check_error(__res) \ - (((int)__res) < 0 && ((int)__res) >= -_dl_MAX_ERRNO) -#include <sys/mman.h> // For MAP_ANONYMOUS -- differs between platforms -#ifndef MAP_ANONYMOUS -#ifdef __sparc__ -#define MAP_ANONYMOUS 0x20 -#else -#error MAP_ANONYMOUS not defined and suplementary value not known -#endif -#endif - - -#define __NR__dl_open __NR_open -#define O_RDONLY 0x0000 -static inline _syscall2(int, _dl_open, const char *, fn, int, flags); - -#define __NR__dl_write __NR_write -static inline _syscall3(unsigned long, _dl_write, int, fd, - const void *, buf, unsigned long, count); - - -#define __NR__dl_read __NR_read -static inline _syscall3(unsigned long, _dl_read, int, fd, - const void *, buf, unsigned long, count); - -#define __NR__dl_mprotect __NR_mprotect -static inline _syscall3(int, _dl_mprotect, const void *, addr, unsigned long, len, int, prot); - - - -/* Pull in whatever this particular arch's kernel thinks the kernel version of - * struct stat should look like. It turns out that each arch has a different - * opinion on the subject, and different kernel revs use different names... */ -#include <sys/stat.h> -#define __NR__dl_stat __NR_stat -static inline _syscall2(int, _dl_stat, const char *, file_name, struct stat *, buf); - - -#define __NR__dl_munmap __NR_munmap -static inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length); - -#define __NR__dl_getuid __NR_getuid -static inline _syscall0(uid_t, _dl_getuid); - -#define __NR__dl_geteuid __NR_geteuid -static inline _syscall0(uid_t, _dl_geteuid); - -#define __NR__dl_getgid __NR_getgid -static inline _syscall0(gid_t, _dl_getgid); - -#define __NR__dl_getegid __NR_getegid -static inline _syscall0(gid_t, _dl_getegid); - -/* - * Not an actual syscall, but we need something in assembly to say whether - * this is OK or not. - */ -static inline int _dl_suid_ok(void) -{ - uid_t uid, euid, gid, egid; - - uid = _dl_getuid(); - euid = _dl_geteuid(); - gid = _dl_getgid(); - egid = _dl_getegid(); - - if(uid == euid && gid == egid) - return 1; - else - return 0; -} - |