diff options
Diffstat (limited to 'ldso/libdl')
-rw-r--r-- | ldso/libdl/Makefile | 15 | ||||
-rw-r--r-- | ldso/libdl/dlfcn.h | 41 | ||||
-rw-r--r-- | ldso/libdl/dlib.c | 91 | ||||
-rw-r--r-- | ldso/libdl/libdl.c | 91 |
4 files changed, 51 insertions, 187 deletions
diff --git a/ldso/libdl/Makefile b/ldso/libdl/Makefile index 1ac194400..12461d77e 100644 --- a/ldso/libdl/Makefile +++ b/ldso/libdl/Makefile @@ -21,9 +21,16 @@ TOPDIR=../../ include $(TOPDIR)Rules.mak -XXFLAGS+=-DUCLIBC_TARGET_PREFIX=\"$(TARGET_PREFIX)\" \ +XXFLAGS=$(XWARNINGS) $(OPTIMIZATION) $(XARCH_CFLAGS) $(CPU_CFLAGS) \ + -DUCLIBC_TARGET_PREFIX=\"$(TARGET_PREFIX)\" \ -DUCLIBC_DEVEL_PREFIX=\"$(DEVEL_PREFIX)\" \ - -DUCLIBC_BUILD_DIR=\"$(shell cd $(TOPDIR) && pwd)\" + -DUCLIBC_BUILD_DIR=\"$(shell cd $(TOPDIR) && pwd)\" \ + -fno-builtin -nostdinc -D_LIBC -I$(TOPDIR)ldso/include -I. -I$(TOPDIR)include +XXFLAGS+=$(shell $(CC) -print-search-dirs | sed -ne "s/install: *\(.*\)/-I\1include/gp") +XXFLAGS_NOPIC:=$(XXFLAGS) +ifeq ($(DOPIC),y) + XXFLAGS += $(PICFLAG) +endif ifeq ($(strip $(SUPPORT_LD_DEBUG)),y) XXFLAGS+=-D__SUPPORT_LD_DEBUG__ endif @@ -50,11 +57,11 @@ ar-target: $(OBJS) $(PIC_OBJS) dlib.o: dlib.c - $(CC) -I../ldso -I../ldso/$(TARGET_ARCH) $(CFLAGS_NOPIC) $(XXFLAGS) -c dlib.c -o dlib.o + $(CC) $(XXFLAGS_NOPIC) -c dlib.c -o dlib.o $(STRIPTOOL) -x -R .note -R .comment $*.o dlib_pic.o: dlib.c - $(CC) -I../ldso -I../ldso/$(TARGET_ARCH) $(CFLAGS) $(XXFLAGS) -c dlib.c -o dlib_pic.o + $(CC) $(XXFLAGS) -c dlib.c -o dlib_pic.o $(STRIPTOOL) -x -R .note -R .comment $*.o $(OBJ): Makefile diff --git a/ldso/libdl/dlfcn.h b/ldso/libdl/dlfcn.h deleted file mode 100644 index 620181173..000000000 --- a/ldso/libdl/dlfcn.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef DLFCN_H -#define DLFCN_H - -#include <features.h> - -/* - * Various defines and so forth for the dynamic linker - */ - -/* For dlopen () */ -#define RTLD_LAZY 1 -#define RTLD_NOW 2 -#define RTLD_GLOBAL 0x100 - -/* For dlsym */ -#define RTLD_NEXT ((void *)-1) - -__BEGIN_DECLS - -/* The usual prototypes. We use void * instead of the actual - * datatype - the user does not manipulate the handles at all. - */ - -extern void * dlopen __P((__const char * __filename, int __flag)); -extern __const char * dlerror __P((void)); -extern void * dlsym __P((void *, __const char *)); -extern int dlclose __P((void *)); - -typedef struct -{ - const char * dli_fname; /* filename */ - void * dli_fbase; /* base address of object */ - const char * dli_sname; /* nearest symbol name */ - void * dli_saddr; /* nearest symbol address */ -} Dl_info; - -extern int dladdr __P((void * __address, Dl_info * __dlip )); - -__END_DECLS - -#endif diff --git a/ldso/libdl/dlib.c b/ldso/libdl/dlib.c index c2949c981..a15518230 100644 --- a/ldso/libdl/dlib.c +++ b/ldso/libdl/dlib.c @@ -4,27 +4,17 @@ * Functions required for dlopen et. al. */ -#include <stdlib.h> -#include <features.h> -#include "dlfcn.h" -#include "linuxelf.h" -#include "ld_syscall.h" -#include "ld_hash.h" -#include "ld_string.h" +#include <ldso.h> -extern struct r_debug *_dl_debug_addr; - -extern void *(*_dl_malloc_function) (size_t size); - -static int do_fixup(struct elf_resolve *tpnt, int flag); -static int do_dlclose(void *, int need_fini); +/* The public interfaces */ void *dlopen(const char *, int) __attribute__ ((__weak__, __alias__ ("_dlopen"))); -const char *dlerror(void) __attribute__ ((__weak__, __alias__ ("_dlerror"))); -void *dlsym(void *, const char *) __attribute__ ((__weak__, __alias__ ("_dlsym"))); int dlclose(void *) __attribute__ ((__weak__, __alias__ ("_dlclose"))); +void *dlsym(void *, const char *) __attribute__ ((__weak__, __alias__ ("_dlsym"))); +const char *dlerror(void) __attribute__ ((__weak__, __alias__ ("_dlerror"))); int dladdr(void *, Dl_info *) __attribute__ ((__weak__, __alias__ ("_dladdr"))); + #ifdef __PIC__ /* This is a real hack. We need access to the dynamic linker, but we also need to make it possible to link against this library without any @@ -43,10 +33,10 @@ extern char *_dl_find_hash(const char *, struct dyn_elf *, struct elf_resolve *, __attribute__ ((__weak__, __alias__ ("foobar"))); extern struct elf_resolve * _dl_load_shared_library(int, struct dyn_elf **, struct elf_resolve *, char *) __attribute__ ((__weak__, __alias__ ("foobar"))); -extern int _dl_parse_relocation_information(struct elf_resolve *, unsigned long, unsigned long, int) - __attribute__ ((__weak__, __alias__ ("foobar"))); -extern void _dl_parse_lazy_relocation_information(struct elf_resolve *, unsigned long, unsigned long, int) - __attribute__ ((__weak__, __alias__ ("foobar"))); +extern int _dl_fixup(struct elf_resolve *tpnt, int lazy) + __attribute__ ((__weak__, __alias__ ("foobar"))); +extern int _dl_copy_fixups(struct dyn_elf * tpnt) + __attribute__ ((__weak__, __alias__ ("foobar"))); #ifdef __mips__ extern void _dl_perform_mips_global_got_relocations(struct elf_resolve *tpnt) __attribute__ ((__weak__, __alias__ ("foobar"))); @@ -62,6 +52,9 @@ extern struct elf_resolve *_dl_loaded_modules __attribute__ ((__weak__, __alias_ extern struct r_debug *_dl_debug_addr __attribute__ ((__weak__, __alias__ ("foobar1"))); extern unsigned long _dl_error_number __attribute__ ((__weak__, __alias__ ("foobar1"))); extern void *(*_dl_malloc_function)(size_t) __attribute__ ((__weak__, __alias__ ("foobar1"))); +#ifdef __SUPPORT_LD_DEBUG__ +#define _dl_debug_file 2 +#endif #else #ifdef __SUPPORT_LD_DEBUG__ static char *_dl_debug = 0; @@ -79,11 +72,16 @@ char *_dl_library_path = 0; char *_dl_ldsopath = 0; struct r_debug *_dl_debug_addr = NULL; static char *_dl_malloc_addr, *_dl_mmap_zero; -#include "../ldso/ldso.h" /* Pull in the name of ld.so */ +#include "../ldso/_dl_progname.h" /* Pull in the name of ld.so */ #include "../ldso/hash.c" #include "../ldso/readelflib1.c" +void *(*_dl_malloc_function) (size_t size); +int _dl_fixup(struct elf_resolve *tpnt, int lazy); #endif +static int do_dlclose(void *, int need_fini); + + static const char *dl_error_names[] = { "", "File not found", @@ -237,7 +235,7 @@ void *_dlopen(const char *libname, int flag) _dl_perform_mips_global_got_relocations(tpnt); #endif - if (do_fixup(tpnt, flag)) { + if (_dl_fixup(tpnt, (flag & RTLD_LAZY))) { _dl_error_number = LD_NO_SYMBOL; goto oops; } @@ -296,55 +294,6 @@ void *_dlopen(const char *libname, int flag) return NULL; } -static int do_fixup(struct elf_resolve *tpnt, int flag) -{ - int goof = 0; - - if (tpnt->next) - goof += do_fixup(tpnt->next, flag); - - if (tpnt->dynamic_info[DT_REL]) { -#ifdef ELF_USES_RELOCA - goof++; -#else - if (tpnt->init_flag & RELOCS_DONE) - return goof; - tpnt->init_flag |= RELOCS_DONE; - - goof += _dl_parse_relocation_information(tpnt, - tpnt->dynamic_info[DT_REL], tpnt->dynamic_info[DT_RELSZ], 0); -#endif - } - if (tpnt->dynamic_info[DT_RELA]) { -#ifdef ELF_USES_RELOCA - if (tpnt->init_flag & RELOCS_DONE) - return goof; - tpnt->init_flag |= RELOCS_DONE; - - goof += _dl_parse_relocation_information(tpnt, - tpnt->dynamic_info[DT_RELA], tpnt->dynamic_info[DT_RELASZ], 0); -#else - goof++; -#endif - } - if (tpnt->dynamic_info[DT_JMPREL]) { - if (tpnt->init_flag & JMP_RELOCS_DONE) - return goof; - tpnt->init_flag |= JMP_RELOCS_DONE; - - if (flag == RTLD_LAZY) { - _dl_parse_lazy_relocation_information(tpnt, - tpnt->dynamic_info[DT_JMPREL], - tpnt->dynamic_info[DT_PLTRELSZ], 0); - } else { - goof += _dl_parse_relocation_information(tpnt, - tpnt->dynamic_info[DT_JMPREL], - tpnt->dynamic_info[DT_PLTRELSZ], 0); - } - }; - return goof; -} - void *_dlsym(void *vhandle, const char *name) { struct elf_resolve *tpnt, *tfrom; @@ -408,7 +357,7 @@ static int do_dlclose(void *vhandle, int need_fini) { struct dyn_elf *rpnt, *rpnt1; struct dyn_elf *spnt, *spnt1; - elf_phdr *ppnt; + ElfW(Phdr) *ppnt; struct elf_resolve *tpnt; int (*dl_elf_fini) (void); void (*dl_brk) (void); diff --git a/ldso/libdl/libdl.c b/ldso/libdl/libdl.c index c2949c981..a15518230 100644 --- a/ldso/libdl/libdl.c +++ b/ldso/libdl/libdl.c @@ -4,27 +4,17 @@ * Functions required for dlopen et. al. */ -#include <stdlib.h> -#include <features.h> -#include "dlfcn.h" -#include "linuxelf.h" -#include "ld_syscall.h" -#include "ld_hash.h" -#include "ld_string.h" +#include <ldso.h> -extern struct r_debug *_dl_debug_addr; - -extern void *(*_dl_malloc_function) (size_t size); - -static int do_fixup(struct elf_resolve *tpnt, int flag); -static int do_dlclose(void *, int need_fini); +/* The public interfaces */ void *dlopen(const char *, int) __attribute__ ((__weak__, __alias__ ("_dlopen"))); -const char *dlerror(void) __attribute__ ((__weak__, __alias__ ("_dlerror"))); -void *dlsym(void *, const char *) __attribute__ ((__weak__, __alias__ ("_dlsym"))); int dlclose(void *) __attribute__ ((__weak__, __alias__ ("_dlclose"))); +void *dlsym(void *, const char *) __attribute__ ((__weak__, __alias__ ("_dlsym"))); +const char *dlerror(void) __attribute__ ((__weak__, __alias__ ("_dlerror"))); int dladdr(void *, Dl_info *) __attribute__ ((__weak__, __alias__ ("_dladdr"))); + #ifdef __PIC__ /* This is a real hack. We need access to the dynamic linker, but we also need to make it possible to link against this library without any @@ -43,10 +33,10 @@ extern char *_dl_find_hash(const char *, struct dyn_elf *, struct elf_resolve *, __attribute__ ((__weak__, __alias__ ("foobar"))); extern struct elf_resolve * _dl_load_shared_library(int, struct dyn_elf **, struct elf_resolve *, char *) __attribute__ ((__weak__, __alias__ ("foobar"))); -extern int _dl_parse_relocation_information(struct elf_resolve *, unsigned long, unsigned long, int) - __attribute__ ((__weak__, __alias__ ("foobar"))); -extern void _dl_parse_lazy_relocation_information(struct elf_resolve *, unsigned long, unsigned long, int) - __attribute__ ((__weak__, __alias__ ("foobar"))); +extern int _dl_fixup(struct elf_resolve *tpnt, int lazy) + __attribute__ ((__weak__, __alias__ ("foobar"))); +extern int _dl_copy_fixups(struct dyn_elf * tpnt) + __attribute__ ((__weak__, __alias__ ("foobar"))); #ifdef __mips__ extern void _dl_perform_mips_global_got_relocations(struct elf_resolve *tpnt) __attribute__ ((__weak__, __alias__ ("foobar"))); @@ -62,6 +52,9 @@ extern struct elf_resolve *_dl_loaded_modules __attribute__ ((__weak__, __alias_ extern struct r_debug *_dl_debug_addr __attribute__ ((__weak__, __alias__ ("foobar1"))); extern unsigned long _dl_error_number __attribute__ ((__weak__, __alias__ ("foobar1"))); extern void *(*_dl_malloc_function)(size_t) __attribute__ ((__weak__, __alias__ ("foobar1"))); +#ifdef __SUPPORT_LD_DEBUG__ +#define _dl_debug_file 2 +#endif #else #ifdef __SUPPORT_LD_DEBUG__ static char *_dl_debug = 0; @@ -79,11 +72,16 @@ char *_dl_library_path = 0; char *_dl_ldsopath = 0; struct r_debug *_dl_debug_addr = NULL; static char *_dl_malloc_addr, *_dl_mmap_zero; -#include "../ldso/ldso.h" /* Pull in the name of ld.so */ +#include "../ldso/_dl_progname.h" /* Pull in the name of ld.so */ #include "../ldso/hash.c" #include "../ldso/readelflib1.c" +void *(*_dl_malloc_function) (size_t size); +int _dl_fixup(struct elf_resolve *tpnt, int lazy); #endif +static int do_dlclose(void *, int need_fini); + + static const char *dl_error_names[] = { "", "File not found", @@ -237,7 +235,7 @@ void *_dlopen(const char *libname, int flag) _dl_perform_mips_global_got_relocations(tpnt); #endif - if (do_fixup(tpnt, flag)) { + if (_dl_fixup(tpnt, (flag & RTLD_LAZY))) { _dl_error_number = LD_NO_SYMBOL; goto oops; } @@ -296,55 +294,6 @@ void *_dlopen(const char *libname, int flag) return NULL; } -static int do_fixup(struct elf_resolve *tpnt, int flag) -{ - int goof = 0; - - if (tpnt->next) - goof += do_fixup(tpnt->next, flag); - - if (tpnt->dynamic_info[DT_REL]) { -#ifdef ELF_USES_RELOCA - goof++; -#else - if (tpnt->init_flag & RELOCS_DONE) - return goof; - tpnt->init_flag |= RELOCS_DONE; - - goof += _dl_parse_relocation_information(tpnt, - tpnt->dynamic_info[DT_REL], tpnt->dynamic_info[DT_RELSZ], 0); -#endif - } - if (tpnt->dynamic_info[DT_RELA]) { -#ifdef ELF_USES_RELOCA - if (tpnt->init_flag & RELOCS_DONE) - return goof; - tpnt->init_flag |= RELOCS_DONE; - - goof += _dl_parse_relocation_information(tpnt, - tpnt->dynamic_info[DT_RELA], tpnt->dynamic_info[DT_RELASZ], 0); -#else - goof++; -#endif - } - if (tpnt->dynamic_info[DT_JMPREL]) { - if (tpnt->init_flag & JMP_RELOCS_DONE) - return goof; - tpnt->init_flag |= JMP_RELOCS_DONE; - - if (flag == RTLD_LAZY) { - _dl_parse_lazy_relocation_information(tpnt, - tpnt->dynamic_info[DT_JMPREL], - tpnt->dynamic_info[DT_PLTRELSZ], 0); - } else { - goof += _dl_parse_relocation_information(tpnt, - tpnt->dynamic_info[DT_JMPREL], - tpnt->dynamic_info[DT_PLTRELSZ], 0); - } - }; - return goof; -} - void *_dlsym(void *vhandle, const char *name) { struct elf_resolve *tpnt, *tfrom; @@ -408,7 +357,7 @@ static int do_dlclose(void *vhandle, int need_fini) { struct dyn_elf *rpnt, *rpnt1; struct dyn_elf *spnt, *spnt1; - elf_phdr *ppnt; + ElfW(Phdr) *ppnt; struct elf_resolve *tpnt; int (*dl_elf_fini) (void); void (*dl_brk) (void); |