summaryrefslogtreecommitdiff
path: root/ldso/libdl
diff options
context:
space:
mode:
Diffstat (limited to 'ldso/libdl')
-rw-r--r--ldso/libdl/Makefile32
-rw-r--r--ldso/libdl/dlib.c39
-rw-r--r--ldso/libdl/libdl.c39
3 files changed, 87 insertions, 23 deletions
diff --git a/ldso/libdl/Makefile b/ldso/libdl/Makefile
index 1727c7d5e..1109d9966 100644
--- a/ldso/libdl/Makefile
+++ b/ldso/libdl/Makefile
@@ -16,42 +16,52 @@
# You should have received a copy of the GNU Library General Public License
# along with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# Derived in part from the Linux-8086 C library, the GNU C Library, and several
-# other sundry sources. Files within this library are copyright by their
-# respective copyright holders.
TOPDIR=../../
include $(TOPDIR)Rules.mak
+XXFLAGS+=-DUCLIBC_TARGET_PREFIX=\"$(TARGET_PREFIX)\" \
+ -DUCLIBC_DEVEL_PREFIX=\"$(DEVEL_PREFIX)\" \
+ -DUCLIBC_BUILD_DIR=\"$(shell cd $(TOPDIR) && pwd)\"
+ifeq ($(strip $(SUPPORT_LD_DEBUG)),y)
+XXFLAGS+=-D__SUPPORT_LD_DEBUG__
+endif
+
LIBDL=libdl.a
+LIBDL_PIC=libdl_pic.a
LIBDL_SHARED=libdl.so
LIBDL_SHARED_FULLNAME=libdl-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so
-CSRC= dlib.c
-OBJS=$(patsubst %.c,%.o, $(CSRC))
+CSRC=dlib.c
+OBJS=dlib.o
+PIC_OBJS=dlib_pic.o
all: $(OBJS) $(LIBDL) shared
$(LIBDL): ar-target
-ar-target: $(OBJS)
- $(AR) $(ARFLAGS) $(LIBDL) $(OBJS)
+ar-target: $(OBJS) $(PIC_OBJS)
+ $(AR) $(ARFLAGS) $(LIBDL) ../ldso/$(TARGET_ARCH)/resolve.o $(OBJS)
+ $(AR) $(ARFLAGS) $(LIBDL_PIC) $(PIC_OBJS)
install -d $(TOPDIR)lib
rm -f $(TOPDIR)lib/$(LIBDL)
install -m 644 $(LIBDL) $(TOPDIR)lib
-$(OBJS): %.o : %.c
- $(CC) -I../ldso -I../ldso/$(TARGET_ARCH) $(CFLAGS) -c $< -o $@
+dlib.o: dlib.c
+ $(CC) -I../ldso -I../ldso/$(TARGET_ARCH) $(CFLAGS_NOPIC) $(XXFLAGS) -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) -c dlib.c -o dlib_pic.o
$(STRIPTOOL) -x -R .note -R .comment $*.o
$(OBJ): Makefile
shared:
$(LD) $(LDFLAGS) -soname=$(LIBDL_SHARED).$(MAJOR_VERSION) \
- -o $(LIBDL_SHARED_FULLNAME) --whole-archive $(LIBDL) \
+ -o $(LIBDL_SHARED_FULLNAME) --whole-archive $(LIBDL_PIC) \
--no-whole-archive $(TOPDIR)/libc/misc/internals/interp.o \
-L$(TOPDIR)/lib -lc;
install -d $(TOPDIR)lib
diff --git a/ldso/libdl/dlib.c b/ldso/libdl/dlib.c
index a0d3ec805..0b7f7738a 100644
--- a/ldso/libdl/dlib.c
+++ b/ldso/libdl/dlib.c
@@ -12,7 +12,6 @@
#include "ld_hash.h"
#include "ld_string.h"
-extern int _dl_error_number;
extern struct r_debug *_dl_debug_addr;
extern void *(*_dl_malloc_function) (size_t size);
@@ -26,6 +25,7 @@ void *dlsym(void *, const char *) __attribute__ ((__weak__, __alias__ ("_dlsym")
int dlclose(void *) __attribute__ ((__weak__, __alias__ ("_dlclose")));
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
unresolved externals. We provide these weak symbols to make the link
@@ -60,8 +60,27 @@ extern struct dyn_elf *_dl_symbol_tables __attribute__ ((__weak__, __alias__ ("f
extern struct dyn_elf *_dl_handles __attribute__ ((__weak__, __alias__ ("foobar1")));
extern struct elf_resolve *_dl_loaded_modules __attribute__ ((__weak__, __alias__ ("foobar1")));
extern struct r_debug *_dl_debug_addr __attribute__ ((__weak__, __alias__ ("foobar1")));
-extern int _dl_error_number __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")));
+#else
+#ifdef __SUPPORT_LD_DEBUG__
+static char *_dl_debug = 0;
+static char *_dl_debug_symbols = 0;
+static char *_dl_debug_move = 0;
+static char *_dl_debug_reloc = 0;
+static char *_dl_debug_detail = 0;
+static char *_dl_debug_nofixups = 0;
+static char *_dl_debug_bindings = 0;
+static int _dl_debug_file = 2;
+#endif
+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/hash.c"
+#include "../ldso/readelflib1.c"
+#endif
static const char *dl_error_names[] = {
"",
@@ -109,7 +128,9 @@ void *_dlopen(const char *libname, int flag)
static int dl_init = 0;
char *from;
void (*dl_brk) (void);
+#ifdef __PIC__
int (*dl_elf_init) (void);
+#endif
from = __builtin_return_address(0);
@@ -213,15 +234,18 @@ void *_dlopen(const char *libname, int flag)
goto oops;
}
- dl_brk = (void (*)(void)) _dl_debug_addr->r_brk;
- if (dl_brk != NULL) {
+ if (_dl_debug_addr) {
+ dl_brk = (void (*)(void)) _dl_debug_addr->r_brk;
+ if (dl_brk != NULL) {
_dl_debug_addr->r_state = RT_ADD;
(*dl_brk) ();
_dl_debug_addr->r_state = RT_CONSISTENT;
(*dl_brk) ();
+ }
}
+#ifdef __PIC__
for (rpnt = dyn_chain; rpnt; rpnt = rpnt->next) {
tpnt = rpnt->dyn;
/* Apparently crt1 for the application is responsible for handling this.
@@ -244,6 +268,7 @@ void *_dlopen(const char *libname, int flag)
}
}
+#endif
#ifdef USE_CACHE
_dl_unmap_cache();
@@ -476,13 +501,15 @@ static int do_dlclose(void *vhandle, int need_fini)
}
- dl_brk = (void (*)(void)) _dl_debug_addr->r_brk;
- if (dl_brk != NULL) {
+ if (_dl_debug_addr) {
+ dl_brk = (void (*)(void)) _dl_debug_addr->r_brk;
+ if (dl_brk != NULL) {
_dl_debug_addr->r_state = RT_DELETE;
(*dl_brk) ();
_dl_debug_addr->r_state = RT_CONSISTENT;
(*dl_brk) ();
+ }
}
return 0;
diff --git a/ldso/libdl/libdl.c b/ldso/libdl/libdl.c
index a0d3ec805..0b7f7738a 100644
--- a/ldso/libdl/libdl.c
+++ b/ldso/libdl/libdl.c
@@ -12,7 +12,6 @@
#include "ld_hash.h"
#include "ld_string.h"
-extern int _dl_error_number;
extern struct r_debug *_dl_debug_addr;
extern void *(*_dl_malloc_function) (size_t size);
@@ -26,6 +25,7 @@ void *dlsym(void *, const char *) __attribute__ ((__weak__, __alias__ ("_dlsym")
int dlclose(void *) __attribute__ ((__weak__, __alias__ ("_dlclose")));
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
unresolved externals. We provide these weak symbols to make the link
@@ -60,8 +60,27 @@ extern struct dyn_elf *_dl_symbol_tables __attribute__ ((__weak__, __alias__ ("f
extern struct dyn_elf *_dl_handles __attribute__ ((__weak__, __alias__ ("foobar1")));
extern struct elf_resolve *_dl_loaded_modules __attribute__ ((__weak__, __alias__ ("foobar1")));
extern struct r_debug *_dl_debug_addr __attribute__ ((__weak__, __alias__ ("foobar1")));
-extern int _dl_error_number __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")));
+#else
+#ifdef __SUPPORT_LD_DEBUG__
+static char *_dl_debug = 0;
+static char *_dl_debug_symbols = 0;
+static char *_dl_debug_move = 0;
+static char *_dl_debug_reloc = 0;
+static char *_dl_debug_detail = 0;
+static char *_dl_debug_nofixups = 0;
+static char *_dl_debug_bindings = 0;
+static int _dl_debug_file = 2;
+#endif
+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/hash.c"
+#include "../ldso/readelflib1.c"
+#endif
static const char *dl_error_names[] = {
"",
@@ -109,7 +128,9 @@ void *_dlopen(const char *libname, int flag)
static int dl_init = 0;
char *from;
void (*dl_brk) (void);
+#ifdef __PIC__
int (*dl_elf_init) (void);
+#endif
from = __builtin_return_address(0);
@@ -213,15 +234,18 @@ void *_dlopen(const char *libname, int flag)
goto oops;
}
- dl_brk = (void (*)(void)) _dl_debug_addr->r_brk;
- if (dl_brk != NULL) {
+ if (_dl_debug_addr) {
+ dl_brk = (void (*)(void)) _dl_debug_addr->r_brk;
+ if (dl_brk != NULL) {
_dl_debug_addr->r_state = RT_ADD;
(*dl_brk) ();
_dl_debug_addr->r_state = RT_CONSISTENT;
(*dl_brk) ();
+ }
}
+#ifdef __PIC__
for (rpnt = dyn_chain; rpnt; rpnt = rpnt->next) {
tpnt = rpnt->dyn;
/* Apparently crt1 for the application is responsible for handling this.
@@ -244,6 +268,7 @@ void *_dlopen(const char *libname, int flag)
}
}
+#endif
#ifdef USE_CACHE
_dl_unmap_cache();
@@ -476,13 +501,15 @@ static int do_dlclose(void *vhandle, int need_fini)
}
- dl_brk = (void (*)(void)) _dl_debug_addr->r_brk;
- if (dl_brk != NULL) {
+ if (_dl_debug_addr) {
+ dl_brk = (void (*)(void)) _dl_debug_addr->r_brk;
+ if (dl_brk != NULL) {
_dl_debug_addr->r_state = RT_DELETE;
(*dl_brk) ();
_dl_debug_addr->r_state = RT_CONSISTENT;
(*dl_brk) ();
+ }
}
return 0;