From b8beba5bf3c25b47dda51fc2951042bfb4787dec Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Tue, 10 Dec 2013 13:22:58 +0100 Subject: [PATCH] ldso: Support for setting global object values Make 'set_program_var' accessible outside of 'rtld.c'. Also, compile dynamically linked programs with the '-fPIC' option. Doing not so, yields to program-global symbols being put in the '.symtab' section (which can be stripped) only. In order to get access to global variables from the dynamic linker, the symbols need to reside within the '.dynsym' section additionally. Hence the '-fPIC'. ref #989 fix #1002 --- base/mk/prg.mk | 8 ++++++++ os/src/lib/ldso/contrib/rtld.c | 3 +-- os/src/lib/ldso/contrib/rtld.h | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/base/mk/prg.mk b/base/mk/prg.mk index e97e8ffe4c..7e8b17a29c 100644 --- a/base/mk/prg.mk +++ b/base/mk/prg.mk @@ -64,6 +64,7 @@ endif # CXX_LINK_OPT += $(CC_MARCH) + # # Generic linker script for statically linked binaries # @@ -123,6 +124,13 @@ LD_CMD += -Wl,--dynamic-linker=$(DYNAMIC_LINKER).lib.so \ # FILTER_DEPS := $(filter-out $(BASE_LIBS),$(DEPS:.lib=)) SHARED_LIBS += $(LIB_CACHE_DIR)/$(DYNAMIC_LINKER)/$(DYNAMIC_LINKER).lib.so + +# +# Build program position independent as well +# +CC_OPT_PIC ?= -fPIC +CC_OPT += $(CC_OPT_PIC) + endif # diff --git a/os/src/lib/ldso/contrib/rtld.c b/os/src/lib/ldso/contrib/rtld.c index f72c778362..ffdfd4d6e4 100644 --- a/os/src/lib/ldso/contrib/rtld.c +++ b/os/src/lib/ldso/contrib/rtld.c @@ -125,7 +125,6 @@ static int rtld_dirname(const char *, char *); static void rtld_exit(void); static char *search_library_path(const char *, const char *); static const void **get_program_var_addr(const char *); -static void set_program_var(const char *, const void *); static const Elf_Sym *symlook_default(const char *, unsigned long, const Obj_Entry *, const Obj_Entry **, const Ver_Entry *, int); static const Elf_Sym *symlook_list(const char *, unsigned long, const Objlist *, @@ -2429,7 +2428,7 @@ get_program_var_addr(const char *name) * is used to set key variables such as "environ" before any of the * init functions are called. */ -static void +void set_program_var(const char *name, const void *value) { const void **addr; diff --git a/os/src/lib/ldso/contrib/rtld.h b/os/src/lib/ldso/contrib/rtld.h index 75f78fa8d1..75bb258a4f 100644 --- a/os/src/lib/ldso/contrib/rtld.h +++ b/os/src/lib/ldso/contrib/rtld.h @@ -272,6 +272,7 @@ void *allocate_module_tls(int index); bool allocate_tls_offset(Obj_Entry *obj); void free_tls_offset(Obj_Entry *obj); const Ver_Entry *fetch_ventry(const Obj_Entry *obj, unsigned long); +void set_program_var(const char *name, const void *value); /* * MD function declarations.