summaryrefslogtreecommitdiffstats
path: root/ldso
diff options
context:
space:
mode:
Diffstat (limited to 'ldso')
-rw-r--r--ldso/include/ldso.h2
-rw-r--r--ldso/ldso/arm/aeabi_read_tp.S1
-rw-r--r--ldso/ldso/dl-tls.c5
-rw-r--r--ldso/ldso/ldso.c26
-rw-r--r--ldso/ldso/x86_64/dl-sysdep.h8
-rw-r--r--ldso/ldso/x86_64/elfinterp.c28
6 files changed, 46 insertions, 24 deletions
diff --git a/ldso/include/ldso.h b/ldso/include/ldso.h
index e5669057c..53bb5be9e 100644
--- a/ldso/include/ldso.h
+++ b/ldso/include/ldso.h
@@ -72,7 +72,7 @@ extern char *_dl_ldsopath; /* Where the shared lib loader was found
extern const char *_dl_progname; /* The name of the executable being run */
extern size_t _dl_pagesize; /* Store the page size for use later */
-#ifdef USE_TLS
+#if defined(USE_TLS) && USE_TLS
extern void _dl_add_to_slotinfo (struct link_map *l);
extern void ** __attribute__ ((const)) _dl_initial_error_catch_tsd (void);
#endif
diff --git a/ldso/ldso/arm/aeabi_read_tp.S b/ldso/ldso/arm/aeabi_read_tp.S
index e906d07ce..564f59331 100644
--- a/ldso/ldso/arm/aeabi_read_tp.S
+++ b/ldso/ldso/arm/aeabi_read_tp.S
@@ -38,7 +38,6 @@
#ifdef __UCLIBC_HAS_THREADS_NATIVE__
#include <sysdep.h>
-#include <tls.h>
/* GCC will emit calls to this routine under -mtp=soft. Linux has an
equivalent helper function (which clobbers fewer registers than
diff --git a/ldso/ldso/dl-tls.c b/ldso/ldso/dl-tls.c
index 52b7aa534..d2808f968 100644
--- a/ldso/ldso/dl-tls.c
+++ b/ldso/ldso/dl-tls.c
@@ -842,7 +842,10 @@ __tls_get_addr (GET_ADDR_ARGS)
void *p;
if (__builtin_expect (dtv[0].counter != _dl_tls_generation, 0))
- the_map = _dl_update_slotinfo (GET_ADDR_MODULE);
+ {
+ the_map = _dl_update_slotinfo (GET_ADDR_MODULE);
+ dtv = THREAD_DTV ();
+ }
p = dtv[GET_ADDR_MODULE].pointer.val;
diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c
index 0fbc8f135..74da58860 100644
--- a/ldso/ldso/ldso.c
+++ b/ldso/ldso/ldso.c
@@ -376,19 +376,6 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
_dl_init_static_tls = &_dl_nothread_init_static_tls;
#endif
-#ifdef __UCLIBC_HAS_SSP__
- /* Set up the stack checker's canary. */
- stack_chk_guard = _dl_setup_stack_chk_guard ();
-# ifdef THREAD_SET_STACK_GUARD
- THREAD_SET_STACK_GUARD (stack_chk_guard);
-# ifdef __UCLIBC_HAS_SSP_COMPAT__
- __guard = stack_chk_guard;
-# endif
-# else
- __stack_chk_guard = stack_chk_guard;
-# endif
-#endif
-
/* At this point we are now free to examine the user application,
* and figure out which libraries are supposed to be called. Until
* we have this list, we will not be completely ready for dynamic
@@ -944,6 +931,19 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
tcbp = init_tls ();
}
#endif
+#ifdef __UCLIBC_HAS_SSP__
+ /* Set up the stack checker's canary. */
+ stack_chk_guard = _dl_setup_stack_chk_guard ();
+# ifdef THREAD_SET_STACK_GUARD
+ THREAD_SET_STACK_GUARD (stack_chk_guard);
+# ifdef __UCLIBC_HAS_SSP_COMPAT__
+ __guard = stack_chk_guard;
+# endif
+# else
+ __stack_chk_guard = stack_chk_guard;
+# endif
+#endif
+
_dl_debug_early("Beginning relocation fixups\n");
diff --git a/ldso/ldso/x86_64/dl-sysdep.h b/ldso/ldso/x86_64/dl-sysdep.h
index 0eed657e8..ae3542aed 100644
--- a/ldso/ldso/x86_64/dl-sysdep.h
+++ b/ldso/ldso/x86_64/dl-sysdep.h
@@ -46,8 +46,12 @@ extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_ent
define the value.
ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
of the main executable's symbols, as for a COPY reloc. */
-#define elf_machine_type_class(type) \
- ((((type) == R_X86_64_JUMP_SLOT) * ELF_RTYPE_CLASS_PLT) \
+#define elf_machine_type_class(type) \
+ ((((type) == R_X86_64_JUMP_SLOT \
+ || (type) == R_X86_64_DTPMOD64 \
+ || (type) == R_X86_64_DTPOFF64 \
+ || (type) == R_X86_64_TPOFF64) \
+ * ELF_RTYPE_CLASS_PLT) \
| (((type) == R_X86_64_COPY) * ELF_RTYPE_CLASS_COPY))
/* Return the link-time address of _DYNAMIC. Conveniently, this is the
diff --git a/ldso/ldso/x86_64/elfinterp.c b/ldso/ldso/x86_64/elfinterp.c
index 92ac5acbc..54528d382 100644
--- a/ldso/ldso/x86_64/elfinterp.c
+++ b/ldso/ldso/x86_64/elfinterp.c
@@ -157,6 +157,7 @@ _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope,
int reloc_type;
int symtab_index;
char *symname;
+ struct elf_resolve *tls_tpnt = 0;
ElfW(Sym) *sym;
ElfW(Addr) *reloc_addr;
ElfW(Addr) symbol_addr;
@@ -173,18 +174,26 @@ _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope,
if (symtab_index) {
symbol_addr = (ElfW(Addr))_dl_find_hash(symname, scope, tpnt,
- elf_machine_type_class(reloc_type), NULL);
+ elf_machine_type_class(reloc_type), &tls_tpnt);
/*
* We want to allow undefined references to weak symbols - this
* might have been intentional. We should not be linking local
* symbols here, so all bases should be covered.
*/
- if (unlikely(!symbol_addr && ELF_ST_BIND(sym->st_info) != STB_WEAK)) {
- _dl_dprintf(2, "%s: can't resolve symbol '%s'\n", _dl_progname, symname);
- _dl_exit(1);
+ if (unlikely(!symbol_addr && (ELF_ST_TYPE(sym->st_info) != STT_TLS)
+ && (ELF_ST_BIND(sym->st_info) != STB_WEAK))) {
+ /* This may be non-fatal if called from dlopen. */
+ return 1;
}
+ } else {
+ /* Relocs against STN_UNDEF are usually treated as using a
+ * symbol value of zero, and using the module containing the
+ * reloc itself. */
+ symbol_addr = sym->st_value;
+ tls_tpnt = tpnt;
}
+
#if defined (__SUPPORT_LD_DEBUG__)
old_val = *reloc_addr;
#endif
@@ -212,13 +221,20 @@ _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope,
break;
*/
case R_X86_64_DTPMOD64:
- *reloc_addr = 1;
+ *reloc_addr = tls_tpnt->l_tls_modid;
break;
case R_X86_64_DTPOFF64:
+ /* During relocation all TLS symbols are defined and used.
+ * Therefore the offset is already correct. */
*reloc_addr = sym->st_value + rpnt->r_addend;
break;
case R_X86_64_TPOFF64:
- *reloc_addr = sym->st_value + rpnt->r_addend - symbol_addr;
+ /* The offset is negative, forward from the thread pointer.
+ * We know the offset of the object the symbol is contained in.
+ * It is a negative value which will be added to the
+ * thread pointer. */
+ CHECK_STATIC_TLS ((struct link_map *) tls_tpnt);
+ *reloc_addr = sym->st_value - tls_tpnt->l_tls_offset + rpnt->r_addend;
break;
case R_X86_64_32:
*(unsigned int *) reloc_addr = symbol_addr + rpnt->r_addend;