This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "uClibc-ng - small C library for embedded systems".
The branch, 1.0 has been updated via 003b266cbeb370a8eae91dc256197f00798c6f93 (commit) via 931fd627f61957dbe33860f659c7cf2939f94113 (commit) via 6f15c3b452c94098f3a9e2a0686ca5e5ffe65461 (commit) via 7c1b847a49aea3e00b86843cb77a1585e7955201 (commit) via 2f389d46df6a9634589554708e2a7ea6ca901b86 (commit) via d6d36639c6a5dffbcdb77e947aafd1e858bbb714 (commit) via fb6a51ed43626cb16bda3d75b28b26cfb1449e52 (commit) via 7c89984515021f3b3b1ad486c379f0eac1ad2605 (commit) via 405c9b96cb639da9ff910f0bcafe810e8f58e2e5 (commit) via d9c3a16dcab57d6b56225b9a67e9119cc9e2e4ac (commit) via 27f1b2c66c67e601dd619a1def70a8fd7ca5eeba (commit) from 12a85731dc5fda3bc01ab19c82678b3bf122d794 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- commit 003b266cbeb370a8eae91dc256197f00798c6f93 Author: Waldemar Brodkorb wbx@uclibc-ng.org Date: Sun Jan 31 17:42:51 2016 +0100
bump version for release
commit 931fd627f61957dbe33860f659c7cf2939f94113 Author: Waldemar Brodkorb wbx@uclibc-ng.org Date: Sat Jan 30 10:37:44 2016 +0100
mips: fix clashing symbols
ISC bind9 uses ptrsize, better use something else.
Reported-By: Gustavo Zacarias gustavo@zacarias.com.ar Signed-off-by: Waldemar Brodkorb wbx@uclibc-ng.org
commit 6f15c3b452c94098f3a9e2a0686ca5e5ffe65461 Author: Waldemar Brodkorb wbx@openadk.org Date: Fri Jan 29 09:32:21 2016 +0100
mips64: fix memcpy, patch from glibc
Signed-off-by: Waldemar Brodkorb wbx@uclibc-ng.org
commit 7c1b847a49aea3e00b86843cb77a1585e7955201 Author: Waldemar Brodkorb wbx@openadk.org Date: Mon Jan 25 21:27:44 2016 +0100
add $ORIGIN test-case
Signed-off-by: Leonid Lisovskiy lly.dev@gmail.com Signed-off-by: Waldemar Brodkorb wbx@uclibc-ng.org
commit 2f389d46df6a9634589554708e2a7ea6ca901b86 Author: Leonid Lisovskiy lly.dev@gmail.com Date: Tue Jan 26 20:12:58 2016 +0300
ldso: Use single rtld_flags interpretation through all the calls
Implement single rtld_flags interpretation through all the do_dlopen()/_dl_load_shared_library()/_dl_load_elf_shared_library() calls chain. This adds the ability to use the flags, passed to dlopen(), in all underlaying functions and implement rtld_flags inheritance. Saves a few bytes code.
Signed-off-by: Leonid Lisovskiy lly.dev@gmail.com Signed-off-by: Waldemar Brodkorb wbx@uclibc-ng.org
commit d6d36639c6a5dffbcdb77e947aafd1e858bbb714 Author: Leonid Lisovskiy lly.dev@gmail.com Date: Tue Jan 26 20:12:57 2016 +0300
ldso: Fix fail of $ORIGIN expansion in case of RTLD_NOLOAD
$ORIGIN expansion in search_for_named_library() wrongly takes into account all bits of rflags.
Signed-off-by: Leonid Lisovskiy lly.dev@gmail.com Signed-off-by: Waldemar Brodkorb wbx@uclibc-ng.org
commit fb6a51ed43626cb16bda3d75b28b26cfb1449e52 Author: Leonid Lisovskiy lly.dev@gmail.com Date: Sat Jan 23 23:26:56 2016 +0300
Provide __adjtimex() alias, like glibc.
Althought recent versions of sofware don't require it, old ntpd wants - see http://bugs.ntp.org/show_bug.cgi?id=769
Signed-off-by: Leonid Lisovskiy lly.dev@gmail.com Signed-off-by: Waldemar Brodkorb wbx@uclibc-ng.org
commit 7c89984515021f3b3b1ad486c379f0eac1ad2605 Author: Leonid Lisovskiy lly.dev@gmail.com Date: Fri Jan 22 22:02:49 2016 +0300
tests: Extend OMIT LDFLAGS logic to test binaries too
In continue of 72215487 "tests: add OMIT logic to remove compilation flag." commit.
Signed-off-by: Leonid Lisovskiy lly.dev@gmail.com Signed-off-by: Waldemar Brodkorb wbx@uclibc-ng.org
commit 405c9b96cb639da9ff910f0bcafe810e8f58e2e5 Author: Waldemar Brodkorb wbx@openadk.org Date: Mon Jan 25 21:11:34 2016 +0100
Make sure to always terminate decoded string
Write a terminating '\0' to dest when the first byte of the encoded data is 0. This corner case was previously missed.
Signed-off-by: Daniel Fahlgren daniel@fahlgren.se Signed-off-by: Waldemar Brodkorb wbx@uclibc-ng.org
commit d9c3a16dcab57d6b56225b9a67e9119cc9e2e4ac Author: Waldemar Brodkorb wbx@openadk.org Date: Sun Jan 17 15:47:22 2016 +0100
Do not follow compressed items forever.
It is possible to get stuck in an infinite loop when receiving a specially crafted DNS reply. Exit the loop after a number of iteration and consider the packet invalid.
Signed-off-by: Daniel Fahlgren daniel@fahlgren.se Signed-off-by: Waldemar Brodkorb wbx@uclibc-ng.org
commit 27f1b2c66c67e601dd619a1def70a8fd7ca5eeba Author: Leonid Lisovskiy lly.dev@gmail.com Date: Wed Jan 13 21:00:05 2016 +0300
libdl: dlopen() mustn't forget RTLD_NODELETE flag
If RTLD_NODELETE is passed to dlopen() rather than set on shared library itself, flag propagation to rtld_flags is missed.
Test-case taken from glibc.
Signed-off-by: Leonid Lisovskiy lly.dev@gmail.com Signed-off-by: Waldemar Brodkorb wbx@uclibc-ng.org
-----------------------------------------------------------------------
Summary of changes: Rules.mak | 2 +- include/dlfcn.h | 3 + include/sys/timex.h | 2 - ldso/include/dl-elf.h | 7 +- ldso/ldso/dl-elf.c | 16 +-- ldso/ldso/ldso.c | 5 +- ldso/libdl/libdl.c | 12 +- libc/inet/resolv.c | 6 +- libc/string/mips/memcpy.S | 2 +- libc/sysdeps/linux/common/adjtimex.c | 1 + libc/sysdeps/linux/mips/bits/setjmp.h | 12 +- libc/sysdeps/linux/mips/setjmp_aux.c | 6 +- test/Test.mak | 5 +- test/dlopen/Makefile.in | 19 ++- test/dlopen/nodelete.c | 205 +++++++++++++++++++++++++++++++++ test/dlopen/nodelmod1.c | 10 ++ test/dlopen/nodelmod2.c | 10 ++ test/dlopen/nodelmod3.c | 8 ++ test/dlopen/nodelmod4.c | 10 ++ test/dlopen/{test2.c => tst-origin.c} | 22 ++-- 20 files changed, 312 insertions(+), 51 deletions(-) create mode 100644 test/dlopen/nodelete.c create mode 100644 test/dlopen/nodelmod1.c create mode 100644 test/dlopen/nodelmod2.c create mode 100644 test/dlopen/nodelmod3.c create mode 100644 test/dlopen/nodelmod4.c copy test/dlopen/{test2.c => tst-origin.c} (51%)
diff --git a/Rules.mak b/Rules.mak index 2f0b7d3..16c1c49 100644 --- a/Rules.mak +++ b/Rules.mak @@ -126,7 +126,7 @@ export RUNTIME_PREFIX DEVEL_PREFIX KERNEL_HEADERS MULTILIB_DIR # Now config hard core MAJOR_VERSION := 1 MINOR_VERSION := 0 -SUBLEVEL := 11 +SUBLEVEL := 12 EXTRAVERSION := VERSION := $(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL) ABI_VERSION := $(MAJOR_VERSION) diff --git a/include/dlfcn.h b/include/dlfcn.h index 241ec54..74825aa 100644 --- a/include/dlfcn.h +++ b/include/dlfcn.h @@ -26,6 +26,9 @@ /* Collect various system dependent definitions and declarations. */ #include <bits/dlfcn.h>
+/* Internally used flag. */ +#define __RTLD_SECURE 0x04000000 /* Apply additional security checks. */ +
#ifdef __USE_GNU /* If the first argument of `dlsym' or `dlvsym' is set to RTLD_NEXT diff --git a/include/sys/timex.h b/include/sys/timex.h index 57059bd..4cb81d2 100644 --- a/include/sys/timex.h +++ b/include/sys/timex.h @@ -120,9 +120,7 @@ struct timex
__BEGIN_DECLS
-#if 0 extern int __adjtimex (struct timex *__ntx) __THROW; -#endif extern int adjtimex (struct timex *__ntx) __THROW; libc_hidden_proto(adjtimex)
diff --git a/ldso/include/dl-elf.h b/ldso/include/dl-elf.h index 4cc9b2b..57f0ddc 100644 --- a/ldso/include/dl-elf.h +++ b/ldso/include/dl-elf.h @@ -29,18 +29,15 @@ static __inline__ void _dl_map_cache(void) { } static __inline__ void _dl_unmap_cache(void) { } #endif
-#define DL_RESOLVE_SECURE 0x0001 -#define DL_RESOLVE_NOLOAD 0x0002 - /* Function prototypes for non-static stuff in elfinterp.c */ extern void _dl_parse_lazy_relocation_information(struct dyn_elf *rpnt, unsigned long rel_addr, unsigned long rel_size); extern int _dl_parse_relocation_information(struct dyn_elf *rpnt, struct r_scope_elem *scope, unsigned long rel_addr, unsigned long rel_size); -extern struct elf_resolve * _dl_load_shared_library(unsigned rflags, +extern struct elf_resolve * _dl_load_shared_library(unsigned int rflags, struct dyn_elf **rpnt, struct elf_resolve *tpnt, char *full_libname, int trace_loaded_objects); -extern struct elf_resolve * _dl_load_elf_shared_library(unsigned rflags, +extern struct elf_resolve * _dl_load_elf_shared_library(unsigned int rflags, struct dyn_elf **rpnt, const char *libname); extern int _dl_linux_resolve(void); extern int _dl_fixup(struct dyn_elf *rpnt, struct r_scope_elem *scope, int flag); diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c index 01b29da..04e8c60 100644 --- a/ldso/ldso/dl-elf.c +++ b/ldso/ldso/dl-elf.c @@ -132,7 +132,7 @@ _dl_protect_relro (struct elf_resolve *l) /* This function's behavior must exactly match that * in uClibc/ldso/util/ldd.c */ static struct elf_resolve * -search_for_named_library(const char *name, unsigned rflags, const char *path_list, +search_for_named_library(const char *name, unsigned int rflags, const char *path_list, struct dyn_elf **rpnt, const char* origin) { char *mylibname; @@ -162,7 +162,9 @@ search_for_named_library(const char *name, unsigned rflags, const char *path_lis
if (plen >= 7 && _dl_memcmp(p, "$ORIGIN", 7) == 0) { int olen; - if (rflags && plen != 7) + /* $ORIGIN is not expanded for SUID/GUID programs + (except if it is $ORIGIN alone) */ + if ((rflags & __RTLD_SECURE) && plen != 7) continue; if (origin == NULL) continue; @@ -194,7 +196,7 @@ search_for_named_library(const char *name, unsigned rflags, const char *path_lis unsigned long _dl_error_number; unsigned long _dl_internal_error_number;
-struct elf_resolve *_dl_load_shared_library(unsigned rflags, struct dyn_elf **rpnt, +struct elf_resolve *_dl_load_shared_library(unsigned int rflags, struct dyn_elf **rpnt, struct elf_resolve *tpnt, char *full_libname, int attribute_unused trace_loaded_objects) { char *pnt; @@ -493,7 +495,7 @@ map_writeable (int infile, ElfW(Phdr) *ppnt, int piclib, int flags, * are required. */
-struct elf_resolve *_dl_load_elf_shared_library(unsigned rflags, +struct elf_resolve *_dl_load_elf_shared_library(unsigned int rflags, struct dyn_elf **rpnt, const char *libname) { ElfW(Ehdr) *epnt; @@ -532,7 +534,7 @@ struct elf_resolve *_dl_load_elf_shared_library(unsigned rflags, } /* If we are in secure mode (i.e. a setuid/gid binary using LD_PRELOAD), we don't load the library if it isn't setuid. */ - if (rflags & DL_RESOLVE_SECURE) { + if (rflags & __RTLD_SECURE) { if (!(st.st_mode & S_ISUID)) { _dl_close(infile); return NULL; @@ -548,7 +550,7 @@ struct elf_resolve *_dl_load_elf_shared_library(unsigned rflags, return tpnt; } } - if (rflags & DL_RESOLVE_NOLOAD) { + if (rflags & RTLD_NOLOAD) { _dl_close(infile); return NULL; } @@ -812,7 +814,7 @@ struct elf_resolve *_dl_load_elf_shared_library(unsigned rflags, DL_RELOC_ADDR(DL_GET_RUN_ADDR(tpnt->loadaddr, tpnt->mapaddr), epnt->e_phoff); tpnt->n_phent = epnt->e_phnum; - tpnt->rtld_flags |= rtld_flags; + tpnt->rtld_flags = rflags | rtld_flags; #ifdef __LDSO_STANDALONE_SUPPORT__ tpnt->l_entry = epnt->e_entry; #endif diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c index 0cdc91d..9f4e841 100644 --- a/ldso/ldso/ldso.c +++ b/ldso/ldso/ldso.c @@ -589,7 +589,8 @@ of this helper program; chances are you did not intend to run this program.\n\ * but it could be also a shared object (when ld.so used for tracing) * We keep the misleading app_tpnt name to avoid variable pollution */ - app_tpnt = _dl_load_elf_shared_library(_dl_secure, &rpnt, _dl_progname); + app_tpnt = _dl_load_elf_shared_library(_dl_secure ? __RTLD_SECURE : 0, + &rpnt, _dl_progname); if (!app_tpnt) { _dl_dprintf(2, "can't load '%s'\n", _dl_progname); _dl_exit(16); @@ -887,7 +888,7 @@ of this helper program; chances are you did not intend to run this program.\n\ _dl_if_debug_dprint("\tfile='%s'; needed by '%s'\n", str, _dl_progname);
tpnt1 = _dl_load_shared_library( - _dl_secure ? DL_RESOLVE_SECURE : 0, + _dl_secure ? __RTLD_SECURE : 0, &rpnt, NULL, str, trace_loaded_objects); if (!tpnt1) { #ifdef __LDSO_LDD_SUPPORT__ diff --git a/ldso/libdl/libdl.c b/ldso/libdl/libdl.c index 2c4b064..42a09a8 100644 --- a/ldso/libdl/libdl.c +++ b/ldso/libdl/libdl.c @@ -59,8 +59,6 @@ extern struct link_map *_dl_update_slotinfo(unsigned long int req_modid); * and use a pile of symbols from ldso... */ #include <dl-elf.h> #if 0 -extern struct elf_resolve * _dl_load_shared_library(unsigned, struct dyn_elf **, - struct elf_resolve *, char *, int); extern int _dl_fixup(struct dyn_elf *rpnt, struct r_scope_elem *scope, int lazy); extern void _dl_protect_relro(struct elf_resolve * tpnt); #endif @@ -385,7 +383,7 @@ static void *do_dlopen(const char *libname, int flag, ElfW(Addr) from) _dl_if_debug_print("Trying to dlopen '%s', RTLD_GLOBAL:%d RTLD_NOW:%d\n", (char*)libname, (flag & RTLD_GLOBAL ? 1:0), (now_flag & RTLD_NOW ? 1:0));
- tpnt = _dl_load_shared_library((flag & RTLD_NOLOAD) ? DL_RESOLVE_NOLOAD : 0, + tpnt = _dl_load_shared_library(flag & (RTLD_NOLOAD | RTLD_GLOBAL | RTLD_NODELETE), &rpnt, tfrom, (char*)libname, 0); if (tpnt == NULL) { _dl_unmap_cache(); @@ -394,7 +392,6 @@ static void *do_dlopen(const char *libname, int flag, ElfW(Addr) from) dyn_chain = (struct dyn_elf *) malloc(sizeof(struct dyn_elf)); memset(dyn_chain, 0, sizeof(struct dyn_elf)); dyn_chain->dyn = tpnt; - tpnt->rtld_flags |= (flag & RTLD_GLOBAL);
dyn_chain->next_handle = _dl_handles; _dl_handles = dyn_ptr = dyn_chain; @@ -407,7 +404,7 @@ static void *do_dlopen(const char *libname, int flag, ElfW(Addr) from) dyn_chain->init_fini.init_fini = handle->init_fini.init_fini; dyn_chain->init_fini.nlist = handle->init_fini.nlist; for (i = 0; i < dyn_chain->init_fini.nlist; i++) - dyn_chain->init_fini.init_fini[i]->rtld_flags |= (flag & RTLD_GLOBAL); + dyn_chain->init_fini.init_fini[i]->rtld_flags |= (flag & (RTLD_GLOBAL|RTLD_NODELETE)); dyn_chain->next = handle->next; break; } @@ -435,12 +432,11 @@ static void *do_dlopen(const char *libname, int flag, ElfW(Addr) from) dpnt->d_un.d_val); _dl_if_debug_print("Trying to load '%s', needed by '%s'\n", lpntstr, runp->tpnt->libname); - tpnt1 = _dl_load_shared_library(0, &rpnt, runp->tpnt, lpntstr, 0); + tpnt1 = _dl_load_shared_library(flag & (RTLD_GLOBAL | RTLD_NODELETE), + &rpnt, runp->tpnt, lpntstr, 0); if (!tpnt1) goto oops;
- tpnt1->rtld_flags |= (flag & RTLD_GLOBAL); - /* This list is for dlsym() and relocation */ dyn_ptr->next = (struct dyn_elf *) malloc(sizeof(struct dyn_elf)); memset (dyn_ptr->next, 0, sizeof (struct dyn_elf)); diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c index eb663ac..4028afc 100644 --- a/libc/inet/resolv.c +++ b/libc/inet/resolv.c @@ -669,11 +669,13 @@ int __decode_dotted(const unsigned char *packet, bool measure = 1; unsigned total = 0; unsigned used = 0; + unsigned maxiter = 256;
if (!packet) return -1;
- while (1) { + dest[0] = '\0'; + while (--maxiter) { if (offset >= packet_len) return -1; b = packet[offset++]; @@ -710,6 +712,8 @@ int __decode_dotted(const unsigned char *packet, else dest[used++] = '\0'; } + if (!maxiter) + return -1;
/* The null byte must be counted too */ if (measure) diff --git a/libc/string/mips/memcpy.S b/libc/string/mips/memcpy.S index 2a187ef..3afdb2c 100644 --- a/libc/string/mips/memcpy.S +++ b/libc/string/mips/memcpy.S @@ -565,11 +565,11 @@ L(lastw): #ifdef USE_DOUBLE andi t8,a2,3 /* a2 is the remainder past 4 byte chunks. */ beq t8,a2,L(lastb) + move a2,t8 lw REG3,0(a1) sw REG3,0(a0) PTR_ADDIU a0,a0,4 PTR_ADDIU a1,a1,4 - move a2,t8 #endif
/* Copy the last 8 (or 16) bytes */ diff --git a/libc/sysdeps/linux/common/adjtimex.c b/libc/sysdeps/linux/common/adjtimex.c index 45cb384..1996502 100644 --- a/libc/sysdeps/linux/common/adjtimex.c +++ b/libc/sysdeps/linux/common/adjtimex.c @@ -13,6 +13,7 @@
_syscall1(int, adjtimex, struct timex *, buf) libc_hidden_def(adjtimex) +weak_alias(adjtimex,__adjtimex) #if defined __UCLIBC_NTP_LEGACY__ strong_alias(adjtimex,ntp_adjtime) #endif diff --git a/libc/sysdeps/linux/mips/bits/setjmp.h b/libc/sysdeps/linux/mips/bits/setjmp.h index 375e537..51f972e 100644 --- a/libc/sysdeps/linux/mips/bits/setjmp.h +++ b/libc/sysdeps/linux/mips/bits/setjmp.h @@ -26,18 +26,18 @@ #include <sgidefs.h>
#if _MIPS_SIM == _MIPS_SIM_ABI32 -#define ptrsize void * +#define __ptr_size void * #else -#define ptrsize long long +#define __ptr_size long long #endif
typedef struct { /* Program counter. */ - ptrsize __pc; + __ptr_size __pc;
/* Stack pointer. */ - ptrsize __sp; + __ptr_size __sp;
/* Callee-saved registers s0 through s7. */ #if _MIPS_SIM == _MIPS_SIM_ABI32 @@ -47,10 +47,10 @@ typedef struct #endif
/* The frame pointer. */ - ptrsize __fp; + __ptr_size __fp;
/* The global pointer. */ - ptrsize __gp; + __ptr_size __gp;
/* Floating point status register. */ int __fpc_csr; diff --git a/libc/sysdeps/linux/mips/setjmp_aux.c b/libc/sysdeps/linux/mips/setjmp_aux.c index 9cffcc6..4338838 100644 --- a/libc/sysdeps/linux/mips/setjmp_aux.c +++ b/libc/sysdeps/linux/mips/setjmp_aux.c @@ -62,14 +62,14 @@ __sigsetjmp_aux (jmp_buf env, int savemask, int sp, int fp) #endif
/* .. and the stack pointer; */ - env[0].__jmpbuf[0].__sp = (ptrsize) sp; + env[0].__jmpbuf[0].__sp = (__ptr_size) sp;
/* .. and the FP; it'll be in s8. */ - env[0].__jmpbuf[0].__fp = (ptrsize) fp; + env[0].__jmpbuf[0].__fp = (__ptr_size) fp;
/* .. and the GP; */ #if _MIPS_SIM == _MIPS_SIM_ABI64 - env[0].__jmpbuf[0].__gp = (ptrsize) gp; + env[0].__jmpbuf[0].__gp = (__ptr_size) gp; #else __asm__ __volatile__ ("sw $gp, %0" : : "m" (env[0].__jmpbuf[0].__gp)); #endif diff --git a/test/Test.mak b/test/Test.mak index 98939e7..c1b34a7 100644 --- a/test/Test.mak +++ b/test/Test.mak @@ -121,14 +121,15 @@ MAKE_SRCS := Makefile $(TESTDIR)Makefile $(TESTDIR)Rules.mak $(TESTDIR)Test.mak $(U_TARGETS): $(U_TARGET_SRCS) $(MAKE_SRCS) $(showlink) $(Q)$(CC) $(filter-out $(CFLAGS-OMIT-$@),$(CFLAGS)) $(EXTRA_CFLAGS) $(CFLAGS_$(notdir $(CURDIR))) $(CFLAGS_$@) -c $@.c -o $@.o - $(Q)$(CC) $(LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$@) + $(Q)$(CC) $(filter-out $(LDFLAGS-OMIT-$@),$(LDFLAGS)) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$@)
$(G_TARGETS): $(U_TARGET_SRCS) $(MAKE_SRCS) $(showlink) $(Q)$(HOSTCC) $(filter-out $(HOST_CFLAGS-OMIT-$(patsubst %_glibc,%,$@)),$(HOST_CFLAGS)) \ $(CFLAGS_$(notdir $(CURDIR))) $(CFLAGS_$(patsubst %_glibc,%,$@)) \ -c $(patsubst %_glibc,%,$@).c -o $@.o - $(Q)$(HOSTCC) $(HOST_LDFLAGS) $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$(patsubst %_glibc,%,$@)) $(LDFLAGS_$@) + $(Q)$(HOSTCC) $(filter-out $(LDFLAGS-OMIT-$(patsubst %_glibc,%,$@)),$(HOST_LDFLAGS)) \ + $@.o -o $@ $(EXTRA_LDFLAGS) $(LDFLAGS_$(patsubst %_glibc,%,$@)) $(LDFLAGS_$@)
shell_%: diff --git a/test/dlopen/Makefile.in b/test/dlopen/Makefile.in index 85996de..0bed0f7 100644 --- a/test/dlopen/Makefile.in +++ b/test/dlopen/Makefile.in @@ -5,7 +5,7 @@ export UCLIBC_ONLY := 1
TESTS := dltest dltest2 dlstatic test1 test2 test3 dlundef dlafk dladdr \ - testscope + testscope nodelete tst-origin
ifneq ($(HAVE_SHARED),y) TESTS_DISABLED := test3 @@ -25,10 +25,19 @@ LDFLAGS_test2 := -ldl LDFLAGS_test3 := -ldl ./libtest1.so ./libtest2.so -Wl,-rpath,. LDFLAGS_dladdr := -ldl LDFLAGS_testscope:= -ldl +LDFLAGS_tst-origin:= -ldl -Wl,-rpath,$$ORIGIN/testlib
DEBUG_LIBS := X WRAPPER := env $(DEBUG_LIBS)=all LD_LIBRARY_PATH="$$PWD:.:$(LD_LIBRARY_PATH)"
+testlib: + @mkdir $@ + +testlib/libtest31.so: libtest3.so | testlib + @cp $^ $@ + +EXTRA_DIRS := testlib + # Build libC.so without -mprefergot compilation flag to force a # R_SH_JMP_SLOT relocation instead of R_SH_GLOB_DAT for _libC_fini. This is # needed to resolve the _libC_fini symbol when used (by libC.so destructor), @@ -53,6 +62,7 @@ LDFLAGS_libafk.so := ./libafk-temp.so -Wl,-rpath,. test1: libtest1.so test2: libtest1.so libtest2.so test3: libtest1.so libtest2.so +tst-origin: testlib/libtest31.so libtest1.so: libtest2.so libB.so: libC.so libA.so: libB.so @@ -63,3 +73,10 @@ LDFLAGS_libtest3.so := -lpthread -Wl,-rpath,. LDFLAGS_libC.so := -ldl LDFLAGS_libB.so := ./libC.so -Wl,-rpath,. LDFLAGS_libA.so := ./libB.so -Wl,-rpath,. + +nodelete: nodelmod1.so nodelmod2.so nodelmod3.so +nodelmod3.so: nodelmod4.so +LDFLAGS_nodelete := -rdynamic -ldl +LDFLAGS_nodelmod1.so := -Wl,-z,nodelete +LDFLAGS_nodelmod3.so := ./nodelmod4.so +LDFLAGS_nodelmod4.so := -Wl,-z,nodelete diff --git a/test/dlopen/nodelete.c b/test/dlopen/nodelete.c new file mode 100644 index 0000000..07ff961 --- /dev/null +++ b/test/dlopen/nodelete.c @@ -0,0 +1,205 @@ +#include <dlfcn.h> +#include <setjmp.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> + + +static sigjmp_buf jmpbuf; + + +int fini_ran; + + +static void +__attribute__ ((noreturn)) +handler (int sig) +{ + siglongjmp (jmpbuf, 1); +} + + +#define TEST_FUNCTION do_test () +static int +do_test (void) +{ + /* We are testing the two possibilities to mark an object as not deletable: + - marked on the linker commandline with `-z nodelete' + - with the RTLD_NODELETE flag at dlopen()-time. + + The test we are performing should be safe. We are loading the objects, + get the address of variables in the respective object, unload the object + and then try to read the variable. If the object is unloaded this + should lead to an segmentation fault. */ + void *p; + struct sigaction sa; + + sa.sa_handler = handler; + sigfillset (&sa.sa_mask); + sa.sa_flags = SA_RESTART; + + if (sigaction (SIGSEGV, &sa, NULL) == -1) + puts ("cannot install signal handler: %m"); + + p = dlopen ("nodelmod1.so", RTLD_LAZY); + if (p == NULL) + { + printf ("failed to load "nodelmod1.so": %s\n", dlerror ()); + exit (1); + } + else + { + int *varp; + + varp = dlsym (p, "var1"); + if (varp == NULL) + { + puts ("failed to get address of "var1" in "nodelmod1.so""); + exit (1); + } + else + { + *varp = 20000720; + + /* Now close the object. */ + fini_ran = 0; + if (dlclose (p) != 0) + { + puts ("failed to close "nodelmod1.so""); + exit (1); + } + else if (! sigsetjmp (jmpbuf, 1)) + { + /* Access the variable again. */ + if (*varp != 20000720) + { + puts (""var1" value not correct"); + exit (1); + } + else if (fini_ran != 0) + { + puts ("destructor of "nodelmod1.so" ran"); + exit (1); + } + else + puts ("-z nodelete test succeeded"); + } + else + { + /* We caught an segmentation fault. */ + puts (""nodelmod1.so" got deleted!"); + exit (1); + } + } + } + + p = dlopen ("nodelmod2.so", RTLD_LAZY | RTLD_NODELETE); + if (p == NULL) + { + printf ("failed to load "nodelmod2.so": %s\n", dlerror ()); + exit (1); + } + else + { + int *varp; + + varp = dlsym (p, "var2"); + if (varp == NULL) + { + puts ("failed to get address of "var2" in "nodelmod2.so""); + exit (1); + } + else + { + *varp = 42; + + /* Now close the object. */ + fini_ran = 0; + if (dlclose (p) != 0) + { + puts ("failed to close "nodelmod2.so""); + exit (1); + } + else if (! sigsetjmp (jmpbuf, 1)) + { + /* Access the variable again. */ + if (*varp != 42) + { + puts (""var2" value not correct"); + exit (1); + } + else if (fini_ran != 0) + { + puts ("destructor of "nodelmod2.so" ran"); + exit (1); + } + else + puts ("RTLD_NODELETE test succeeded"); + } + else + { + /* We caught an segmentation fault. */ + puts (""nodelmod2.so" got deleted!"); + exit (1); + } + } + } + + p = dlopen ("nodelmod3.so", RTLD_LAZY); + if (p == NULL) + { + printf ("failed to load "nodelmod3.so": %s\n", dlerror ()); + exit (1); + } + else + { + int *(*fctp) (void); + + fctp = dlsym (p, "addr"); + if (fctp == NULL) + { + puts ("failed to get address of "addr" in "nodelmod3.so""); + exit (1); + } + else + { + int *varp = fctp (); + + *varp = -1; + + /* Now close the object. */ + fini_ran = 0; + if (dlclose (p) != 0) + { + puts ("failed to close "nodelmod3.so""); + exit (1); + } + else if (! sigsetjmp (jmpbuf, 1)) + { + /* Access the variable again. */ + if (*varp != -1) + { + puts (""var_in_mod4" value not correct"); + exit (1); + } + else if (fini_ran != 0) + { + puts ("destructor of "nodelmod4.so" ran"); + exit (1); + } + else + puts ("-z nodelete in dependency succeeded"); + } + else + { + /* We caught an segmentation fault. */ + puts (""nodelmod4.so" got deleted!"); + exit (1); + } + } + } + + return 0; +} + +#include "../test-skeleton.c" diff --git a/test/dlopen/nodelmod1.c b/test/dlopen/nodelmod1.c new file mode 100644 index 0000000..51be080 --- /dev/null +++ b/test/dlopen/nodelmod1.c @@ -0,0 +1,10 @@ +extern int fini_ran; + +int var1 = 42; + +static void +__attribute__ ((__destructor__)) +destr (void) +{ + fini_ran = 1; +} diff --git a/test/dlopen/nodelmod2.c b/test/dlopen/nodelmod2.c new file mode 100644 index 0000000..ff2ffc2 --- /dev/null +++ b/test/dlopen/nodelmod2.c @@ -0,0 +1,10 @@ +extern int fini_ran; + +int var2 = 100; + +static void +__attribute__ ((__destructor__)) +destr (void) +{ + fini_ran = 1; +} diff --git a/test/dlopen/nodelmod3.c b/test/dlopen/nodelmod3.c new file mode 100644 index 0000000..817c94d --- /dev/null +++ b/test/dlopen/nodelmod3.c @@ -0,0 +1,8 @@ +extern int var_in_mod4; +extern int *addr (void); + +int * +addr (void) +{ + return &var_in_mod4; +} diff --git a/test/dlopen/nodelmod4.c b/test/dlopen/nodelmod4.c new file mode 100644 index 0000000..d7fa893 --- /dev/null +++ b/test/dlopen/nodelmod4.c @@ -0,0 +1,10 @@ +extern int fini_ran; + +int var_in_mod4 = 99; + +static void +__attribute__ ((__destructor__)) +destr (void) +{ + fini_ran = 1; +} diff --git a/test/dlopen/test2.c b/test/dlopen/tst-origin.c similarity index 51% copy from test/dlopen/test2.c copy to test/dlopen/tst-origin.c index d8428f7..a12be41 100644 --- a/test/dlopen/test2.c +++ b/test/dlopen/tst-origin.c @@ -8,32 +8,30 @@ extern void _dlinfo(void); #endif
int main(int argc, char **argv) { - void *handle; + void *h1, *h2; int (*mydltest)(const char *s); char *error;
- handle = dlopen ("./libtest2.so", RTLD_LAZY); - if (!handle) { - fprintf(stderr, "Could not open ./libtest2.so: %s\n", dlerror()); + h1 = dlopen ("libtest31.so", RTLD_LAZY); + if (!h1) { + fprintf(stderr, "Could not open libtest31.so: %s\n", dlerror()); exit(1); }
- handle = dlopen ("./libtest1.so", RTLD_LAZY); - if (!handle) { - fprintf(stderr, "Could not open ./libtest1.so: %s\n", dlerror()); + h2 = dlopen ("libtest31.so", RTLD_NOLOAD); + if (!h2) { + fprintf(stderr, "Could not open libtest31.so(RTLD_NOLOAD): %s\n", dlerror()); exit(1); }
- mydltest = dlsym(handle, "dltest"); + mydltest = dlsym(h1, "dltest"); if ((error = dlerror()) != NULL) { fprintf(stderr, "Could not locate symbol 'dltest': %s\n", error); exit(1); }
- mydltest("hello world!"); - - dlclose(handle); + dlclose(h2); + dlclose(h1);
return EXIT_SUCCESS; } -
hooks/post-receive