diff options
author | Mike Frysinger <vapier@gentoo.org> | 2009-10-15 16:15:59 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2009-10-15 17:09:23 -0400 |
commit | 1f5e333a158f4398437287b8b64260371422194f (patch) | |
tree | 93d3ccf85cd0e03d9d534a615af1646123e433ec | |
parent | 21cec43543081b47f9f7d5860af44d04c92746cd (diff) | |
download | uClibc-alpine-1f5e333a158f4398437287b8b64260371422194f.tar.bz2 uClibc-alpine-1f5e333a158f4398437287b8b64260371422194f.tar.xz |
ldso: clean up breakage in tls merge
The TLS merge 534661b91c9849 introduced multiple style problems as well as
random breakage:
- missing _dl_free
- incomplete parametrization of _dl_lookup_hash
- restore FDPIC handling in _dl_lookup_hash
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r-- | ldso/include/dl-hash.h | 13 | ||||
-rw-r--r-- | ldso/include/ldso.h | 4 | ||||
-rw-r--r-- | ldso/ldso/arm/aeabi_read_tp.S | 2 | ||||
-rw-r--r-- | ldso/ldso/arm/elfinterp.c | 19 | ||||
-rw-r--r-- | ldso/ldso/dl-elf.c | 8 | ||||
-rw-r--r-- | ldso/ldso/dl-hash.c | 69 | ||||
-rw-r--r-- | ldso/ldso/dl-startup.c | 4 | ||||
-rw-r--r-- | ldso/ldso/dl-tls.c | 16 | ||||
-rw-r--r-- | ldso/ldso/ldso.c | 37 | ||||
-rw-r--r-- | ldso/ldso/mips/elfinterp.c | 18 | ||||
-rw-r--r-- | ldso/ldso/sh/dl-sysdep.h | 2 | ||||
-rw-r--r-- | ldso/ldso/sh/elfinterp.c | 5 | ||||
-rw-r--r-- | ldso/ldso/sparc/elfinterp.c | 60 | ||||
-rw-r--r-- | ldso/libdl/libdl.c | 39 |
14 files changed, 137 insertions, 159 deletions
diff --git a/ldso/include/dl-hash.h b/ldso/include/dl-hash.h index d8a927378..496ec0fa5 100644 --- a/ldso/include/dl-hash.h +++ b/ldso/include/dl-hash.h @@ -131,7 +131,7 @@ struct elf_resolve { extern struct dyn_elf * _dl_symbol_tables; extern struct elf_resolve * _dl_loaded_modules; -extern struct dyn_elf * _dl_handles; +extern struct dyn_elf * _dl_handles; extern struct elf_resolve * _dl_add_elf_hash_table(const char * libname, DL_LOADADDR_TYPE loadaddr, unsigned long * dynamic_info, @@ -139,23 +139,24 @@ extern struct elf_resolve * _dl_add_elf_hash_table(const char * libname, #if USE_TLS || defined __FDPIC__ #define _DL_LOOKUP_HASH_NEEDS_EXTRA_TPNT -#define _DL_LOOKUP_HASH_EXTRA_TPNT ,struct elf_resolve **tpntp +#define _DL_LOOKUP_HASH_EXTRA_TPNT , struct elf_resolve **tpntp #else #undef _DL_LOOKUP_HASH_NEEDS_EXTRA_TPNT #define _DL_LOOKUP_HASH_EXTRA_TPNT #endif extern char * _dl_lookup_hash(const char * name, struct dyn_elf * rpnt, - struct elf_resolve *mytpnt, int type_class _DL_LOOKUP_HASH_EXTRA_TPNT); + struct elf_resolve *mytpnt, int type_class + _DL_LOOKUP_HASH_EXTRA_TPNT); static __always_inline char *_dl_find_hash(const char *name, struct dyn_elf *rpnt, struct elf_resolve *mytpnt, int type_class, struct elf_resolve **tpntp) { #ifdef _DL_LOOKUP_HASH_NEEDS_EXTRA_TPNT - return _dl_lookup_hash(name, rpnt, mytpnt, type_class, tpntp); + return _dl_lookup_hash(name, rpnt, mytpnt, type_class, tpntp); #else - return _dl_lookup_hash(name, rpnt, mytpnt, type_class); + return _dl_lookup_hash(name, rpnt, mytpnt, type_class); #endif } @@ -183,6 +184,4 @@ static __inline__ int _dl_symbol(char * name) #define LD_BAD_HANDLE 10 #define LD_NO_SYMBOL 11 - - #endif /* _LD_HASH_H_ */ diff --git a/ldso/include/ldso.h b/ldso/include/ldso.h index 3612fa80f..99dcf839c 100644 --- a/ldso/include/ldso.h +++ b/ldso/include/ldso.h @@ -119,8 +119,8 @@ extern int _dl_debug_file; #endif extern void *_dl_malloc(size_t size); -extern void * _dl_calloc(size_t __nmemb, size_t __size); -extern void * _dl_realloc(void * __ptr, size_t __size); +extern void *_dl_calloc(size_t __nmemb, size_t __size); +extern void *_dl_realloc(void *__ptr, size_t __size); extern void _dl_free(void *); extern char *_dl_getenv(const char *symbol, char **envp); extern void _dl_unsetenv(const char *symbol, char **envp); diff --git a/ldso/ldso/arm/aeabi_read_tp.S b/ldso/ldso/arm/aeabi_read_tp.S index f81bae676..e906d07ce 100644 --- a/ldso/ldso/arm/aeabi_read_tp.S +++ b/ldso/ldso/arm/aeabi_read_tp.S @@ -53,7 +53,7 @@ #ifndef NOT_IN_libc .global __aeabi_read_tp #else - .hidden __aeabi_read_tp + .hidden __aeabi_read_tp #endif ENTRY (__aeabi_read_tp) mov r0, #0xffff0fff diff --git a/ldso/ldso/arm/elfinterp.c b/ldso/ldso/arm/elfinterp.c index 1469df016..bf7426790 100644 --- a/ldso/ldso/arm/elfinterp.c +++ b/ldso/ldso/arm/elfinterp.c @@ -89,10 +89,10 @@ unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) } } if (!_dl_debug_nofixups) { - *got_addr = (char*)new_addr; + *got_addr = (char *)new_addr; } #else - *got_addr = (char*)new_addr; + *got_addr = (char *)new_addr; #endif return new_addr; @@ -192,8 +192,7 @@ _dl_do_reloc (struct elf_resolve *tpnt,struct dyn_elf *scope, struct elf_resolve *def_mod = 0; int goof = 0; - reloc_addr = (unsigned long *) (tpnt->loadaddr - + (unsigned long) rpnt->r_offset); + reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); reloc_type = ELF32_R_TYPE(rpnt->r_info); symtab_index = ELF32_R_SYM(rpnt->r_info); @@ -201,9 +200,7 @@ _dl_do_reloc (struct elf_resolve *tpnt,struct dyn_elf *scope, if (symtab_index) { symbol_addr = _dl_find_hash(strtab + symtab[symtab_index].st_name, - scope, tpnt, - elf_machine_type_class(reloc_type), - &def_mod); + scope, tpnt, elf_machine_type_class(reloc_type), &def_mod); /* * We want to allow undefined references to weak symbols - this might @@ -217,9 +214,11 @@ _dl_do_reloc (struct elf_resolve *tpnt,struct dyn_elf *scope, } } else { - /* Relocs against STN_UNDEF are usually treated as using a - symbol value of zero, and using the module containing the - reloc itself. */ + /* + * Relocs against STN_UNDEF are usually treated as using a + * symbol value of zero, and using the module containing the + * reloc itself. + */ symbol_addr = symtab[symtab_index].st_value; def_mod = tpnt; } diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c index e4086d5e9..e7cb138d4 100644 --- a/ldso/ldso/dl-elf.c +++ b/ldso/ldso/dl-elf.c @@ -436,8 +436,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, maxvma = ppnt->p_vaddr + ppnt->p_memsz; } } - if (ppnt->p_type == PT_TLS) - { + if (ppnt->p_type == PT_TLS) { #if USE_TLS if (ppnt->p_memsz == 0) /* Nothing to do for an empty segment. */ @@ -735,8 +734,7 @@ struct elf_resolve *_dl_load_elf_shared_library(int secure, tpnt->n_phent = epnt->e_phnum; #if USE_TLS - if (tlsppnt) - { + if (tlsppnt) { _dl_debug_early("Found TLS header for %s\n", libname); #if NO_TLS_OFFSET != 0 tpnt->l_tls_offset = NO_TLS_OFFSET; @@ -875,7 +873,7 @@ int _dl_fixup(struct dyn_elf *rpnt, int now_flag) } #if 0 -/* _dl_add_to_slotinfo is called by init_tls() for initial DSO +/* _dl_add_to_slotinfo is called by init_tls() for initial DSO or by dlopen() for dynamically loaded DSO. */ #if USE_TLS /* Add object to slot information data if necessasy. */ diff --git a/ldso/ldso/dl-hash.c b/ldso/ldso/dl-hash.c index 3103d9f0b..1ac5b948d 100644 --- a/ldso/ldso/dl-hash.c +++ b/ldso/ldso/dl-hash.c @@ -159,27 +159,27 @@ check_match (const ElfW(Sym) *sym, char *strtab, const char* undef_name, int typ { #if USE_TLS - if((sym->st_value == 0 && (ELF_ST_TYPE(sym->st_info) != STT_TLS)) - || (type_class & (sym->st_shndx == SHN_UNDEF))) - /* No value or undefined symbol itself */ - return NULL; - - if(ELF_ST_TYPE(sym->st_info) > STT_FUNC - && ELF_ST_TYPE(sym->st_info) != STT_COMMON - && ELF_ST_TYPE(sym->st_info) != STT_TLS) - /* Ignore all but STT_NOTYPE, STT_OBJECT, STT_FUNC and STT_COMMON - * entries (and STT_TLS if TLS is supported) since these - * are no code/data definitions. - */ - return NULL; -#else - if (type_class & (sym->st_shndx == SHN_UNDEF)) - /* undefined symbol itself */ - return NULL; - - if (sym->st_value == 0) - /* No value */ - return NULL; + if ((sym->st_value == 0 && (ELF_ST_TYPE(sym->st_info) != STT_TLS)) + || (type_class & (sym->st_shndx == SHN_UNDEF))) + /* No value or undefined symbol itself */ + return NULL; + + if (ELF_ST_TYPE(sym->st_info) > STT_FUNC + && ELF_ST_TYPE(sym->st_info) != STT_COMMON + && ELF_ST_TYPE(sym->st_info) != STT_TLS) + /* Ignore all but STT_NOTYPE, STT_OBJECT, STT_FUNC and STT_COMMON + * entries (and STT_TLS if TLS is supported) since these + * are no code/data definitions. + */ + return NULL; +#else + if (type_class & (sym->st_shndx == SHN_UNDEF)) + /* undefined symbol itself */ + return NULL; + + if (sym->st_value == 0) + /* No value */ + return NULL; if (ELF_ST_TYPE(sym->st_info) > STT_FUNC && ELF_ST_TYPE(sym->st_info) != STT_COMMON) @@ -268,11 +268,8 @@ _dl_lookup_sysv_hash(struct elf_resolve *tpnt, ElfW(Sym) *symtab, unsigned long * This function resolves externals, and this is either called when we process * relocations or when we call an entry in the PLT table for the first time. */ -char *_dl_lookup_hash(const char *name, struct dyn_elf *rpnt, struct elf_resolve *mytpnt, int type_class -#if USE_TLS -,struct elf_resolve **tls_tpnt -#endif -) +char *_dl_lookup_hash(const char *name, struct dyn_elf *rpnt, struct elf_resolve *mytpnt, + int type_class _DL_LOOKUP_HASH_EXTRA_TPNT) { struct elf_resolve *tpnt = NULL; ElfW(Sym) *symtab; @@ -338,12 +335,12 @@ char *_dl_lookup_hash(const char *name, struct dyn_elf *rpnt, struct elf_resolve if (sym) { /* At this point we have found the requested symbol, do binding */ -#if USE_TLS - if(ELF_ST_TYPE(sym->st_info) == STT_TLS) { - _dl_assert((tls_tpnt != NULL)); +#if USE_TLS + if (ELF_ST_TYPE(sym->st_info) == STT_TLS) { + _dl_assert(tls_tpnt != NULL); *tls_tpnt = tpnt; - return (char*)sym->st_value; + return (char *)sym->st_value; } #endif @@ -353,14 +350,22 @@ char *_dl_lookup_hash(const char *name, struct dyn_elf *rpnt, struct elf_resolve /* Perhaps we should support old style weak symbol handling * per what glibc does when you export LD_DYNAMIC_WEAK */ if (!weak_result) - weak_result = (char *)tpnt->loadaddr + sym->st_value; + weak_result = (char *)DL_FIND_HASH_VALUE(tpnt, type_class, sym); break; #endif case STB_GLOBAL: - return (char*)tpnt->loadaddr + sym->st_value; +#ifdef __FDPIC__ + if (tpntp) + *tpntp = tpnt; +#endif + return (char *)DL_FIND_HASH_VALUE(tpnt, type_class, sym); default: /* Local symbols not handled here */ break; } } +#ifdef __FDPIC__ + if (tpntp) + *tpntp = tpnt; +#endif return weak_result; } diff --git a/ldso/ldso/dl-startup.c b/ldso/ldso/dl-startup.c index 6f07b960a..91b11dc7f 100644 --- a/ldso/ldso/dl-startup.c +++ b/ldso/ldso/dl-startup.c @@ -220,8 +220,8 @@ DL_START(unsigned long args) /* tpnt->l_tls_modid = 0; */ # if NO_TLS_OFFSET != 0 tpnt->l_tls_offset = NO_TLS_OFFSET; -# endif -#endif +# endif +#endif SEND_EARLY_STDERR_DEBUG("Done scanning DYNAMIC section\n"); diff --git a/ldso/ldso/dl-tls.c b/ldso/ldso/dl-tls.c index e718373cd..52b7aa534 100644 --- a/ldso/ldso/dl-tls.c +++ b/ldso/ldso/dl-tls.c @@ -46,7 +46,7 @@ void * _dl_calloc (size_t __nmemb, size_t __size) { void *result; - size_t size = (__size * __nmemb); + size_t size = (__size * __nmemb); if (_dl_calloc_function) return (*_dl_calloc_function) (__nmemb, __size); @@ -68,18 +68,6 @@ _dl_realloc (void * __ptr, size_t __size) return NULL; } -void -_dl_free (void *__ptr) -{ - if (_dl_free_function) - (*_dl_free_function) (__ptr); - -#if 0 - _dl_debug_early("NOT IMPLEMENTED PROPERLY!!!\n"); -#endif -} - - /* The __tls_get_addr function has two basic forms which differ in the arguments. The IA-64 form takes two parameters, the module ID and offset. The form used, among others, on IA-32 takes a reference to @@ -1009,7 +997,7 @@ init_tls (void) /* This is a module with TLS data. Store the map reference. The generation counter is zero. */ - /* Skeep slot[0]: it will be never used */ + /* Skeep slot[0]: it will be never used */ slotinfo[++i].map = l; } _dl_assert (i == _dl_tls_max_dtv_idx); diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c index 485204298..021f109cd 100644 --- a/ldso/ldso/ldso.c +++ b/ldso/ldso/ldso.c @@ -219,8 +219,14 @@ static void *_dl_zalloc(size_t size) return p; } +void _dl_free(void *p) +{ + if (_dl_free_function) + (*_dl_free_function) (p); +} + #if USE_TLS -void * _dl_memalign (size_t __boundary, size_t __size) +void *_dl_memalign(size_t __boundary, size_t __size) { void *result; int i = 0; @@ -291,7 +297,6 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr, #if USE_TLS void *tcbp = NULL; #endif - /* Wahoo!!! We managed to make a function call! Get malloc * setup so we can use _dl_dprintf() to print debug noise @@ -530,15 +535,12 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr, * Adjust the address of the TLS initialization image in * case the executable is actually an ET_DYN object. */ - if (app_tpnt->l_tls_initimage != NULL) - { -#ifdef __SUPPORT_LD_DEBUG_EARLY__ - unsigned int tmp = (unsigned int) app_tpnt->l_tls_initimage; -#endif + if (app_tpnt->l_tls_initimage != NULL) { app_tpnt->l_tls_initimage = (char *) app_tpnt->l_tls_initimage + app_tpnt->loadaddr; - _dl_debug_early("Relocated TLS initial image from %x to %x (size = %x)\n", tmp, app_tpnt->l_tls_initimage, app_tpnt->l_tls_initimage_size); - + _dl_debug_early("Relocated TLS initial image from %x to %x (size = %x)\n", + (unsigned int)app_tpnt->l_tls_initimage, + app_tpnt->l_tls_initimage, app_tpnt->l_tls_initimage_size); } #endif @@ -937,8 +939,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr, * used. Trying to do it lazily is too hairy to try when there could be * multiple threads (from a non-TLS-using libpthread). */ bool was_tls_init_tp_called = tls_init_tp_called; - if (tcbp == NULL) - { + if (tcbp == NULL) { _dl_debug_early("Calling init_tls()!\n"); tcbp = init_tls (); } @@ -982,11 +983,9 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr, /* And finally install it for the main thread. If ld.so itself uses TLS we know the thread pointer was initialized earlier. */ - if (! tls_init_tp_called) - { + if (! tls_init_tp_called) { const char *lossage = (char *) TLS_INIT_TP (tcbp, USE___THREAD); - if (__builtin_expect (lossage != NULL, 0)) - { + if (__builtin_expect (lossage != NULL, 0)) { _dl_debug_early("cannot set up thread-local storage: %s\n", lossage); _dl_exit(30); } @@ -1062,16 +1061,16 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr, /* Find the real functions and make ldso functions use them from now on */ _dl_calloc_function = (void* (*)(size_t, size_t)) (intptr_t) _dl_find_hash(__C_SYMBOL_PREFIX__ "calloc", _dl_symbol_tables, NULL, ELF_RTYPE_CLASS_PLT, NULL); - + _dl_realloc_function = (void* (*)(void *, size_t)) (intptr_t) _dl_find_hash(__C_SYMBOL_PREFIX__ "realloc", _dl_symbol_tables, NULL, ELF_RTYPE_CLASS_PLT, NULL); - + _dl_free_function = (void (*)(void *)) (intptr_t) _dl_find_hash(__C_SYMBOL_PREFIX__ "free", _dl_symbol_tables, NULL, ELF_RTYPE_CLASS_PLT, NULL); - + _dl_memalign_function = (void* (*)(size_t, size_t)) (intptr_t) _dl_find_hash(__C_SYMBOL_PREFIX__ "memalign", _dl_symbol_tables, NULL, ELF_RTYPE_CLASS_PLT, NULL); - + #endif /* Notify the debugger that all objects are now mapped in. */ diff --git a/ldso/ldso/mips/elfinterp.c b/ldso/ldso/mips/elfinterp.c index 78cc4c15a..b49f09d36 100644 --- a/ldso/ldso/mips/elfinterp.c +++ b/ldso/ldso/mips/elfinterp.c @@ -213,14 +213,14 @@ int _dl_parse_relocation_information(struct dyn_elf *xpnt, _dl_symbol_tables, tpnt_tls, 1, &sym_tls); } - switch (reloc_type) - { + switch (reloc_type) { case R_MIPS_TLS_DTPMOD64: case R_MIPS_TLS_DTPMOD32: if (tpnt_tls) *(ElfW(Word) *)reloc_addr = tpnt_tls->l_tls_modid; -#if defined (__SUPPORT_LD_DEBUG__) -_dl_dprintf(2, "TLS_DTPMOD : %s, %d, %d\n", (strtab + symtab[symtab_index].st_name), old_val, *((unsigned int *)reloc_addr)); +#ifdef __SUPPORT_LD_DEBUG__ + _dl_dprintf(2, "TLS_DTPMOD : %s, %d, %d\n", + (strtab + symtab[symtab_index].st_name), old_val, *((unsigned int *)reloc_addr)); #endif break; @@ -228,8 +228,9 @@ _dl_dprintf(2, "TLS_DTPMOD : %s, %d, %d\n", (strtab + symtab[symtab_index].st_na case R_MIPS_TLS_DTPREL32: *(ElfW(Word) *)reloc_addr += TLS_DTPREL_VALUE (sym_tls); -#if defined (__SUPPORT_LD_DEBUG__) -_dl_dprintf(2, "TLS_DTPREL : %s, %x, %x\n", (strtab + symtab[symtab_index].st_name), old_val, *((unsigned int *)reloc_addr)); +#ifdef __SUPPORT_LD_DEBUG__ + _dl_dprintf(2, "TLS_DTPREL : %s, %x, %x\n", + (strtab + symtab[symtab_index].st_name), old_val, *((unsigned int *)reloc_addr)); #endif break; @@ -238,8 +239,9 @@ _dl_dprintf(2, "TLS_DTPREL : %s, %x, %x\n", (strtab + symtab[symtab_index].st_na CHECK_STATIC_TLS((struct link_map *)tpnt_tls); *(ElfW(Word) *)reloc_addr += TLS_TPREL_VALUE (tpnt_tls, sym_tls); -#if defined (__SUPPORT_LD_DEBUG__) -_dl_dprintf(2, "TLS_TPREL : %s, %x, %x\n", (strtab + symtab[symtab_index].st_name), old_val, *((unsigned int *)reloc_addr)); +#ifdef __SUPPORT_LD_DEBUG__ + _dl_dprintf(2, "TLS_TPREL : %s, %x, %x\n", + (strtab + symtab[symtab_index].st_name), old_val, *((unsigned int *)reloc_addr)); #endif break; } diff --git a/ldso/ldso/sh/dl-sysdep.h b/ldso/ldso/sh/dl-sysdep.h index 7937ceb08..56e1820f3 100644 --- a/ldso/ldso/sh/dl-sysdep.h +++ b/ldso/ldso/sh/dl-sysdep.h @@ -99,7 +99,7 @@ _dl_urem(unsigned int n, unsigned int base) #define elf_machine_type_class(type) \ ((((type) == R_SH_JMP_SLOT) * ELF_RTYPE_CLASS_PLT) \ | (((type) == R_SH_COPY) * ELF_RTYPE_CLASS_COPY)) -#endif +#endif /* Return the link-time address of _DYNAMIC. Conveniently, this is the first element of the GOT. This must be inlined in a function which diff --git a/ldso/ldso/sh/elfinterp.c b/ldso/ldso/sh/elfinterp.c index cce563e23..594da53aa 100644 --- a/ldso/ldso/sh/elfinterp.c +++ b/ldso/ldso/sh/elfinterp.c @@ -160,8 +160,7 @@ _dl_do_reloc (struct elf_resolve *tpnt,struct dyn_elf *scope, unsigned long old_val; #endif -struct elf_resolve *tls_tpnt = NULL; - + struct elf_resolve *tls_tpnt = NULL; reloc_addr = (unsigned long *)(intptr_t) (tpnt->loadaddr + (unsigned long) rpnt->r_offset); reloc_type = ELF32_R_TYPE(rpnt->r_info); @@ -197,7 +196,7 @@ struct elf_resolve *tls_tpnt = NULL; /* In case of a TLS reloc, tls_tpnt NULL means we have an 'anonymous' symbol. This is the case for a static tls variable, so the lookup module is just that one is referencing the tls variable. */ - if(!tls_tpnt) + if (!tls_tpnt) tls_tpnt = tpnt; #endif switch (reloc_type) { diff --git a/ldso/ldso/sparc/elfinterp.c b/ldso/ldso/sparc/elfinterp.c index a3f9d647f..75e77772c 100644 --- a/ldso/ldso/sparc/elfinterp.c +++ b/ldso/ldso/sparc/elfinterp.c @@ -170,7 +170,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; + struct elf_resolve *tls_tpnt = 0; ElfW(Sym) *sym; ElfW(Addr) *reloc_addr; ElfW(Addr) symbol_addr; @@ -194,18 +194,18 @@ _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope, * symbols here, so all bases should be covered. */ 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; + && (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; - } + /* 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; @@ -235,8 +235,8 @@ _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope, break; case R_SPARC_JMP_SLOT: - reloc_addr[1] = OPCODE_SETHI_G1 | (( symbol_addr >> 10 ) & 0x3fffff); - reloc_addr[2] = OPCODE_JMP_G1 | ( symbol_addr & 0x3ff ); + reloc_addr[1] = OPCODE_SETHI_G1 | (( symbol_addr >> 10 ) & 0x3fffff); + reloc_addr[2] = OPCODE_JMP_G1 | ( symbol_addr & 0x3ff ); break; case R_SPARC_RELATIVE: @@ -273,24 +273,24 @@ _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope, _dl_dprintf(_dl_debug_file, "no symbol_addr to copy !?\n"); break; #if USE_TLS - case R_SPARC_TLS_DTPMOD32: - *reloc_addr = tls_tpnt->l_tls_modid; - break; - - case R_SPARC_TLS_DTPOFF32: - /* 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_SPARC_TLS_TPOFF32: - /* 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_SPARC_TLS_DTPMOD32: + *reloc_addr = tls_tpnt->l_tls_modid; + break; + + case R_SPARC_TLS_DTPOFF32: + /* 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_SPARC_TLS_TPOFF32: + /* 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; #endif default: return -1; /* Calls _dl_exit(1). */ diff --git a/ldso/libdl/libdl.c b/ldso/libdl/libdl.c index d1c61f744..22b622d28 100644 --- a/ldso/libdl/libdl.c +++ b/ldso/libdl/libdl.c @@ -671,7 +671,7 @@ void *dlsym(void *vhandle, const char *name) ret = _dl_find_hash(name2, handle, NULL, 0, &tls_tpnt); #if defined USE_TLS && defined SHARED - if(tls_tpnt) { + if (tls_tpnt) { /* The found symbol is a thread-local storage variable. Return the address for to the current thread. */ ret = _dl_tls_symaddr ((struct link_map *)tls_tpnt, (Elf32_Addr)ret); @@ -776,8 +776,7 @@ static int do_dlclose(void *vhandle, int need_fini) tls_lmap = (struct link_map *) tpnt; /* Remove the object from the dtv slotinfo array if it uses TLS. */ - if (__builtin_expect (tls_lmap->l_tls_blocksize > 0, 0)) - { + if (__builtin_expect (tls_lmap->l_tls_blocksize > 0, 0)) { any_tls = true; if (_dl_tls_dtv_slotinfo_list != NULL @@ -787,8 +786,7 @@ static int do_dlclose(void *vhandle, int need_fini) /* All dynamically loaded modules with TLS are unloaded. */ _dl_tls_max_dtv_idx = _dl_tls_static_nelem; - if (tls_lmap->l_tls_offset != NO_TLS_OFFSET) - { + if (tls_lmap->l_tls_offset != NO_TLS_OFFSET) { /* * Collect a contiguous chunk built from the objects in * this search list, going in either direction. When the @@ -797,8 +795,7 @@ static int do_dlclose(void *vhandle, int need_fini) */ # if defined(TLS_TCB_AT_TP) if (tls_free_start == NO_TLS_OFFSET - || (size_t) tls_lmap->l_tls_offset == tls_free_start) - { + || (size_t) tls_lmap->l_tls_offset == tls_free_start) { /* Extend the contiguous chunk being reclaimed. */ tls_free_start = tls_lmap->l_tls_offset - @@ -806,31 +803,26 @@ static int do_dlclose(void *vhandle, int need_fini) if (tls_free_end == NO_TLS_OFFSET) tls_free_end = tls_lmap->l_tls_offset; - } - else if (tls_lmap->l_tls_offset - tls_lmap->l_tls_blocksize + } else if (tls_lmap->l_tls_offset - tls_lmap->l_tls_blocksize == tls_free_end) /* Extend the chunk backwards. */ tls_free_end = tls_lmap->l_tls_offset; - else - { + else { /* * This isn't contiguous with the last chunk freed. * One of them will be leaked unless we can free * one block right away. */ - if (tls_free_end == _dl_tls_static_used) - { + if (tls_free_end == _dl_tls_static_used) { _dl_tls_static_used = tls_free_start; tls_free_end = tls_lmap->l_tls_offset; tls_free_start = tls_free_end - tls_lmap->l_tls_blocksize; - } - else if ((size_t) tls_lmap->l_tls_offset + } else if ((size_t) tls_lmap->l_tls_offset == _dl_tls_static_used) _dl_tls_static_used = tls_lmap->l_tls_offset - tls_lmap->l_tls_blocksize; - else if (tls_free_end < (size_t) tls_lmap->l_tls_offset) - { + else if (tls_free_end < (size_t) tls_lmap->l_tls_offset) { /* * We pick the later block. It has a chance * to be freed. @@ -848,8 +840,7 @@ static int do_dlclose(void *vhandle, int need_fini) == tls_free_start) /* Extend the chunk backwards. */ tls_free_start = tls_lmap->l_tls_offset; - else - { + else { /* * This isn't contiguous with the last chunk * freed. One of them will be leaked. @@ -870,7 +861,7 @@ static int do_dlclose(void *vhandle, int need_fini) dtv_t *dtv = THREAD_DTV (); _dl_assert(!(dtv[tls_lmap->l_tls_modid].pointer.is_static)); - if(dtv[tls_lmap->l_tls_modid].pointer.val != TLS_DTV_UNALLOCATED) { + if (dtv[tls_lmap->l_tls_modid].pointer.val != TLS_DTV_UNALLOCATED) { /* Note that free is called for NULL is well. We deallocate even if it is this dtv entry we are supposed to load. The reason is that we call @@ -935,11 +926,9 @@ static int do_dlclose(void *vhandle, int need_fini) #if USE_TLS /* If we removed any object which uses TLS bump the generation counter. */ - if (any_tls) - { - if (__builtin_expect (++_dl_tls_generation == 0, 0)) - { - _dl_debug_early ("TLS generation counter wrapped! Please report to the uClibc mailing list.\n"); + if (any_tls) { + if (__builtin_expect(++_dl_tls_generation == 0, 0)) { + _dl_debug_early("TLS generation counter wrapped! Please report to the uClibc mailing list.\n"); _dl_exit(30); } |