Jelajahi Sumber

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>
Mike Frysinger 15 tahun lalu
induk
melakukan
1f5e333a15

+ 6 - 7
ldso/include/dl-hash.h

@@ -131,7 +131,7 @@ struct elf_resolve {
 
 
 extern struct dyn_elf     * _dl_symbol_tables;
 extern struct dyn_elf     * _dl_symbol_tables;
 extern struct elf_resolve * _dl_loaded_modules;
 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,
 extern struct elf_resolve * _dl_add_elf_hash_table(const char * libname,
 	DL_LOADADDR_TYPE loadaddr, unsigned long * dynamic_info,
 	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__
 #if USE_TLS || defined __FDPIC__
 #define _DL_LOOKUP_HASH_NEEDS_EXTRA_TPNT
 #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
 #else
 #undef _DL_LOOKUP_HASH_NEEDS_EXTRA_TPNT
 #undef _DL_LOOKUP_HASH_NEEDS_EXTRA_TPNT
 #define _DL_LOOKUP_HASH_EXTRA_TPNT
 #define _DL_LOOKUP_HASH_EXTRA_TPNT
 #endif
 #endif
 
 
 extern char * _dl_lookup_hash(const char * name, struct dyn_elf * rpnt,
 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,
 static __always_inline char *_dl_find_hash(const char *name, struct dyn_elf *rpnt,
 					struct elf_resolve *mytpnt, int type_class,
 					struct elf_resolve *mytpnt, int type_class,
 					struct elf_resolve **tpntp)
 					struct elf_resolve **tpntp)
 {
 {
 #ifdef _DL_LOOKUP_HASH_NEEDS_EXTRA_TPNT
 #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
 #else
-        return _dl_lookup_hash(name, rpnt, mytpnt, type_class);
+	return _dl_lookup_hash(name, rpnt, mytpnt, type_class);
 #endif
 #endif
 }
 }
 
 
@@ -183,6 +184,4 @@ static __inline__ int _dl_symbol(char * name)
 #define LD_BAD_HANDLE 10
 #define LD_BAD_HANDLE 10
 #define LD_NO_SYMBOL 11
 #define LD_NO_SYMBOL 11
 
 
-
-
 #endif /* _LD_HASH_H_ */
 #endif /* _LD_HASH_H_ */

+ 2 - 2
ldso/include/ldso.h

@@ -119,8 +119,8 @@ extern int   _dl_debug_file;
 #endif
 #endif
 
 
 extern void *_dl_malloc(size_t size);
 extern void *_dl_malloc(size_t size);
-extern void * _dl_calloc(size_t __nmemb, 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_realloc(void *__ptr, size_t __size);
 extern void _dl_free(void *);
 extern void _dl_free(void *);
 extern char *_dl_getenv(const char *symbol, char **envp);
 extern char *_dl_getenv(const char *symbol, char **envp);
 extern void _dl_unsetenv(const char *symbol, char **envp);
 extern void _dl_unsetenv(const char *symbol, char **envp);

+ 1 - 1
ldso/ldso/arm/aeabi_read_tp.S

@@ -53,7 +53,7 @@
 #ifndef NOT_IN_libc
 #ifndef NOT_IN_libc
 	.global __aeabi_read_tp
 	.global __aeabi_read_tp
 #else
 #else
-        .hidden __aeabi_read_tp
+	.hidden __aeabi_read_tp
 #endif
 #endif
 ENTRY (__aeabi_read_tp)
 ENTRY (__aeabi_read_tp)
 	mov	r0, #0xffff0fff
 	mov	r0, #0xffff0fff

+ 9 - 10
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) {
 	if (!_dl_debug_nofixups) {
-		*got_addr = (char*)new_addr;
+		*got_addr = (char *)new_addr;
 	}
 	}
 #else
 #else
-	*got_addr = (char*)new_addr;
+	*got_addr = (char *)new_addr;
 #endif
 #endif
 
 
 	return new_addr;
 	return new_addr;
@@ -192,8 +192,7 @@ _dl_do_reloc (struct elf_resolve *tpnt,struct dyn_elf *scope,
 	struct elf_resolve *def_mod = 0;
 	struct elf_resolve *def_mod = 0;
 	int goof = 0;
 	int goof = 0;
 
 
-	reloc_addr = (unsigned long *) (tpnt->loadaddr
+	reloc_addr = (unsigned long *) (tpnt->loadaddr + (unsigned long) rpnt->r_offset);
-                                    + (unsigned long) rpnt->r_offset);
 
 
 	reloc_type = ELF32_R_TYPE(rpnt->r_info);
 	reloc_type = ELF32_R_TYPE(rpnt->r_info);
 	symtab_index = ELF32_R_SYM(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) {
 	if (symtab_index) {
 		symbol_addr = _dl_find_hash(strtab + symtab[symtab_index].st_name,
 		symbol_addr = _dl_find_hash(strtab + symtab[symtab_index].st_name,
-                                scope, tpnt,
+			scope, tpnt, elf_machine_type_class(reloc_type), &def_mod);
-                                elf_machine_type_class(reloc_type),
-                                &def_mod);
 
 
 		/*
 		/*
 		 * We want to allow undefined references to weak symbols - this might
 		 * 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 {
 	} else {
-        /* Relocs against STN_UNDEF are usually treated as using a
+		/*
-           symbol value of zero, and using the module containing the
+		 * Relocs against STN_UNDEF are usually treated as using a
-           reloc itself.  */
+		 * symbol value of zero, and using the module containing the
+		 * reloc itself.
+		 */
 		symbol_addr = symtab[symtab_index].st_value;
 		symbol_addr = symtab[symtab_index].st_value;
 		def_mod = tpnt;
 		def_mod = tpnt;
 	}
 	}

+ 3 - 5
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;
 				maxvma = ppnt->p_vaddr + ppnt->p_memsz;
 			}
 			}
 		}
 		}
-		if (ppnt->p_type == PT_TLS)
+		if (ppnt->p_type == PT_TLS) {
-		{
 #if USE_TLS
 #if USE_TLS
 			if (ppnt->p_memsz == 0)
 			if (ppnt->p_memsz == 0)
 				/* Nothing to do for an empty segment.  */
 				/* 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;
 	tpnt->n_phent = epnt->e_phnum;
 
 
 #if USE_TLS
 #if USE_TLS
-	if (tlsppnt)
+	if (tlsppnt) {
-	{
 		_dl_debug_early("Found TLS header for %s\n", libname);
 		_dl_debug_early("Found TLS header for %s\n", libname);
 #if NO_TLS_OFFSET != 0
 #if NO_TLS_OFFSET != 0
 		tpnt->l_tls_offset = NO_TLS_OFFSET;
 		tpnt->l_tls_offset = NO_TLS_OFFSET;
@@ -875,7 +873,7 @@ int _dl_fixup(struct dyn_elf *rpnt, int now_flag)
 	}
 	}
 
 
 #if 0
 #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. */
    or by dlopen() for dynamically loaded DSO. */
 #if USE_TLS
 #if USE_TLS
 	/* Add object to slot information data if necessasy. */
 	/* Add object to slot information data if necessasy. */

+ 37 - 32
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 USE_TLS
-		if((sym->st_value == 0 && (ELF_ST_TYPE(sym->st_info) != STT_TLS))
+	if ((sym->st_value == 0 && (ELF_ST_TYPE(sym->st_info) != STT_TLS))
-			      || (type_class & (sym->st_shndx == SHN_UNDEF)))
+		      || (type_class & (sym->st_shndx == SHN_UNDEF)))
-			/* No value or undefined symbol itself */				  
+		/* No value or undefined symbol itself */
-			return NULL;
+		return NULL;
-			
+
-		if(ELF_ST_TYPE(sym->st_info) > STT_FUNC 
+	if (ELF_ST_TYPE(sym->st_info) > STT_FUNC
-			&& ELF_ST_TYPE(sym->st_info) != STT_COMMON
+		&& ELF_ST_TYPE(sym->st_info) != STT_COMMON
-			&& ELF_ST_TYPE(sym->st_info) != STT_TLS)
+		&& ELF_ST_TYPE(sym->st_info) != STT_TLS)
-			/* Ignore all but STT_NOTYPE, STT_OBJECT, STT_FUNC and STT_COMMON
+		/* Ignore all but STT_NOTYPE, STT_OBJECT, STT_FUNC and STT_COMMON
-			 * entries (and STT_TLS if TLS is supported) since these
+		 * entries (and STT_TLS if TLS is supported) since these
-			 * are no code/data definitions.
+		 * are no code/data definitions.
-			 */
+		 */
-			return NULL;
+		return NULL;
-#else			  
+#else
-		if (type_class & (sym->st_shndx == SHN_UNDEF))
+	if (type_class & (sym->st_shndx == SHN_UNDEF))
-			/* undefined symbol itself */
+		/* undefined symbol itself */
-			return NULL;
+		return NULL;
-
+
-		if (sym->st_value == 0)
+	if (sym->st_value == 0)
-			/* No value */
+		/* No value */
-			return NULL;
+		return NULL;
 
 
 	if (ELF_ST_TYPE(sym->st_info) > STT_FUNC
 	if (ELF_ST_TYPE(sym->st_info) > STT_FUNC
 		&& ELF_ST_TYPE(sym->st_info) != STT_COMMON)
 		&& 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
  * 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.
  * 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
+char *_dl_lookup_hash(const char *name, struct dyn_elf *rpnt, struct elf_resolve *mytpnt,
-#if USE_TLS
+	int type_class _DL_LOOKUP_HASH_EXTRA_TPNT)
-,struct elf_resolve **tls_tpnt
-#endif			    
-)
 {
 {
 	struct elf_resolve *tpnt = NULL;
 	struct elf_resolve *tpnt = NULL;
 	ElfW(Sym) *symtab;
 	ElfW(Sym) *symtab;
@@ -338,12 +335,12 @@ char *_dl_lookup_hash(const char *name, struct dyn_elf *rpnt, struct elf_resolve
 
 
 	if (sym) {
 	if (sym) {
 		/* At this point we have found the requested symbol, do binding */
 		/* At this point we have found the requested symbol, do binding */
-#if USE_TLS	
+#if USE_TLS
-		if(ELF_ST_TYPE(sym->st_info) == STT_TLS) {
+		if (ELF_ST_TYPE(sym->st_info) == STT_TLS) {
-			_dl_assert((tls_tpnt != NULL));
+			_dl_assert(tls_tpnt != NULL);
 			*tls_tpnt = tpnt;
 			*tls_tpnt = tpnt;
 
 
-			return (char*)sym->st_value;
+			return (char *)sym->st_value;
 		}
 		}
 #endif
 #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
 	/* Perhaps we should support old style weak symbol handling
 	* per what glibc does when you export LD_DYNAMIC_WEAK */
 	* per what glibc does when you export LD_DYNAMIC_WEAK */
 				if (!weak_result)
 				if (!weak_result)
-					weak_result = (char *)tpnt->loadaddr + sym->st_value;
+					weak_result = (char *)DL_FIND_HASH_VALUE(tpnt, type_class, sym);
 				break;
 				break;
 #endif
 #endif
 			case STB_GLOBAL:
 			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 */
 			default:	/* Local symbols not handled here */
 				break;
 				break;
 		}
 		}
 	}
 	}
+#ifdef __FDPIC__
+	if (tpntp)
+		*tpntp = tpnt;
+#endif
 	return weak_result;
 	return weak_result;
 }
 }

+ 2 - 2
ldso/ldso/dl-startup.c

@@ -220,8 +220,8 @@ DL_START(unsigned long args)
 	/* tpnt->l_tls_modid = 0; */
 	/* tpnt->l_tls_modid = 0; */
 # if NO_TLS_OFFSET != 0
 # if NO_TLS_OFFSET != 0
 	tpnt->l_tls_offset = NO_TLS_OFFSET;
 	tpnt->l_tls_offset = NO_TLS_OFFSET;
-# endif 
+# endif
-#endif 
+#endif
 
 
 	SEND_EARLY_STDERR_DEBUG("Done scanning DYNAMIC section\n");
 	SEND_EARLY_STDERR_DEBUG("Done scanning DYNAMIC section\n");
 
 

+ 2 - 14
ldso/ldso/dl-tls.c

@@ -46,7 +46,7 @@ void *
 _dl_calloc (size_t __nmemb, size_t __size)
 _dl_calloc (size_t __nmemb, size_t __size)
 {
 {
 	void *result;
 	void *result;
-	size_t size = (__size * __nmemb); 
+	size_t size = (__size * __nmemb);
 
 
 	if (_dl_calloc_function)
 	if (_dl_calloc_function)
 		return (*_dl_calloc_function) (__nmemb, __size);
 		return (*_dl_calloc_function) (__nmemb, __size);
@@ -68,18 +68,6 @@ _dl_realloc (void * __ptr, size_t __size)
 	return NULL;
 	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
 /* 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
    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
    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.
 			/* This is a module with TLS data.  Store the map reference.
 			   The generation counter is zero.  */
 			   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;
 			slotinfo[++i].map = l;
 		}
 		}
 	_dl_assert (i == _dl_tls_max_dtv_idx);
 	_dl_assert (i == _dl_tls_max_dtv_idx);

+ 18 - 19
ldso/ldso/ldso.c

@@ -219,8 +219,14 @@ static void *_dl_zalloc(size_t size)
 	return p;
 	return p;
 }
 }
 
 
+void _dl_free(void *p)
+{
+	if (_dl_free_function)
+		(*_dl_free_function) (p);
+}
+
 #if USE_TLS
 #if USE_TLS
-void * _dl_memalign (size_t __boundary, size_t __size)
+void *_dl_memalign(size_t __boundary, size_t __size)
 {
 {
 	void *result;
 	void *result;
 	int i = 0;
 	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
 #if USE_TLS
 	void *tcbp = NULL;
 	void *tcbp = NULL;
 #endif
 #endif
-	
 
 
 	/* Wahoo!!! We managed to make a function call!  Get malloc
 	/* Wahoo!!! We managed to make a function call!  Get malloc
 	 * setup so we can use _dl_dprintf() to print debug noise
 	 * 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
 	 * Adjust the address of the TLS initialization image in
 	 * case the executable is actually an ET_DYN object.
 	 * case the executable is actually an ET_DYN object.
 	 */
 	 */
-	if (app_tpnt->l_tls_initimage != NULL)
+	if (app_tpnt->l_tls_initimage != NULL) {
-	{
-#ifdef __SUPPORT_LD_DEBUG_EARLY__
-		unsigned int tmp = (unsigned int) app_tpnt->l_tls_initimage;
-#endif
 		app_tpnt->l_tls_initimage =
 		app_tpnt->l_tls_initimage =
 			(char *) app_tpnt->l_tls_initimage + app_tpnt->loadaddr;
 			(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
 #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
 	 * used.  Trying to do it lazily is too hairy to try when there could be
 	 * multiple threads (from a non-TLS-using libpthread).  */
 	 * multiple threads (from a non-TLS-using libpthread).  */
 	bool was_tls_init_tp_called = tls_init_tp_called;
 	bool was_tls_init_tp_called = tls_init_tp_called;
-	if (tcbp == NULL)
+	if (tcbp == NULL) {
-	{
 		_dl_debug_early("Calling init_tls()!\n");
 		_dl_debug_early("Calling init_tls()!\n");
 		tcbp = init_tls ();
 		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
 	/* And finally install it for the main thread.  If ld.so itself uses
 	   TLS we know the thread pointer was initialized earlier.  */
 	   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);
 		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_debug_early("cannot set up thread-local storage: %s\n", lossage);
 			_dl_exit(30);
 			_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 */
 	/* Find the real functions and make ldso functions use them from now on */
 	_dl_calloc_function = (void* (*)(size_t, size_t)) (intptr_t)
 	_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_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_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_find_hash(__C_SYMBOL_PREFIX__ "realloc", _dl_symbol_tables, NULL, ELF_RTYPE_CLASS_PLT, NULL);
-										
+
 	_dl_free_function = (void (*)(void *)) (intptr_t)
 	_dl_free_function = (void (*)(void *)) (intptr_t)
 		_dl_find_hash(__C_SYMBOL_PREFIX__ "free", _dl_symbol_tables, NULL, ELF_RTYPE_CLASS_PLT, NULL);
 		_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_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);
 		_dl_find_hash(__C_SYMBOL_PREFIX__ "memalign", _dl_symbol_tables, NULL, ELF_RTYPE_CLASS_PLT, NULL);
-			
+
 #endif
 #endif
 
 
 	/* Notify the debugger that all objects are now mapped in.  */
 	/* Notify the debugger that all objects are now mapped in.  */

+ 10 - 8
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);
 							_dl_symbol_tables, tpnt_tls, 1, &sym_tls);
 				}
 				}
 
 
-				switch (reloc_type)
+				switch (reloc_type) {
-	  			{
 					case R_MIPS_TLS_DTPMOD64:
 					case R_MIPS_TLS_DTPMOD64:
 					case R_MIPS_TLS_DTPMOD32:
 					case R_MIPS_TLS_DTPMOD32:
 						if (tpnt_tls)
 						if (tpnt_tls)
 							*(ElfW(Word) *)reloc_addr = tpnt_tls->l_tls_modid;
 							*(ElfW(Word) *)reloc_addr = tpnt_tls->l_tls_modid;
-#if defined (__SUPPORT_LD_DEBUG__)
+#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));
+						_dl_dprintf(2, "TLS_DTPMOD : %s, %d, %d\n",
+							(strtab + symtab[symtab_index].st_name), old_val, *((unsigned int *)reloc_addr));
 #endif
 #endif
 						break;
 						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:
 					case R_MIPS_TLS_DTPREL32:
 						*(ElfW(Word) *)reloc_addr +=
 						*(ElfW(Word) *)reloc_addr +=
 							TLS_DTPREL_VALUE (sym_tls);
 							TLS_DTPREL_VALUE (sym_tls);
-#if defined (__SUPPORT_LD_DEBUG__)
+#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));
+						_dl_dprintf(2, "TLS_DTPREL : %s, %x, %x\n",
+							(strtab + symtab[symtab_index].st_name), old_val, *((unsigned int *)reloc_addr));
 #endif
 #endif
 						break;
 						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);
 						CHECK_STATIC_TLS((struct link_map *)tpnt_tls);
 						*(ElfW(Word) *)reloc_addr +=
 						*(ElfW(Word) *)reloc_addr +=
 							TLS_TPREL_VALUE (tpnt_tls, sym_tls);
 							TLS_TPREL_VALUE (tpnt_tls, sym_tls);
-#if defined (__SUPPORT_LD_DEBUG__)
+#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));
+						_dl_dprintf(2, "TLS_TPREL  : %s, %x, %x\n",
+							(strtab + symtab[symtab_index].st_name), old_val, *((unsigned int *)reloc_addr));
 #endif
 #endif
 						break;
 						break;
 				}
 				}

+ 1 - 1
ldso/ldso/sh/dl-sysdep.h

@@ -99,7 +99,7 @@ _dl_urem(unsigned int n, unsigned int base)
 #define elf_machine_type_class(type) \
 #define elf_machine_type_class(type) \
   ((((type) == R_SH_JMP_SLOT) * ELF_RTYPE_CLASS_PLT)	\
   ((((type) == R_SH_JMP_SLOT) * ELF_RTYPE_CLASS_PLT)	\
    | (((type) == R_SH_COPY) * ELF_RTYPE_CLASS_COPY))
    | (((type) == R_SH_COPY) * ELF_RTYPE_CLASS_COPY))
-#endif   
+#endif
 
 
 /* Return the link-time address of _DYNAMIC.  Conveniently, this is the
 /* Return the link-time address of _DYNAMIC.  Conveniently, this is the
    first element of the GOT.  This must be inlined in a function which
    first element of the GOT.  This must be inlined in a function which

+ 2 - 3
ldso/ldso/sh/elfinterp.c

@@ -160,8 +160,7 @@ _dl_do_reloc (struct elf_resolve *tpnt,struct dyn_elf *scope,
 	unsigned long old_val;
 	unsigned long old_val;
 #endif
 #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_addr = (unsigned long *)(intptr_t) (tpnt->loadaddr + (unsigned long) rpnt->r_offset);
 	reloc_type = ELF32_R_TYPE(rpnt->r_info);
 	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'
 	/* 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
 	   symbol.  This is the case for a static tls variable, so the lookup
 	   module is just that one is referencing the tls variable. */
 	   module is just that one is referencing the tls variable. */
-	if(!tls_tpnt)
+	if (!tls_tpnt)
 		tls_tpnt = tpnt;
 		tls_tpnt = tpnt;
 #endif
 #endif
 	switch (reloc_type) {
 	switch (reloc_type) {

+ 30 - 30
ldso/ldso/sparc/elfinterp.c

@@ -170,7 +170,7 @@ _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope,
 	int reloc_type;
 	int reloc_type;
 	int symtab_index;
 	int symtab_index;
 	char *symname;
 	char *symname;
-    struct elf_resolve *tls_tpnt = 0;
+	struct elf_resolve *tls_tpnt = 0;
 	ElfW(Sym) *sym;
 	ElfW(Sym) *sym;
 	ElfW(Addr) *reloc_addr;
 	ElfW(Addr) *reloc_addr;
 	ElfW(Addr) symbol_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.
 		 * symbols here, so all bases should be covered.
 		 */
 		 */
 		if (unlikely(!symbol_addr && (ELF_ST_TYPE(sym->st_info) != STT_TLS)
 		if (unlikely(!symbol_addr && (ELF_ST_TYPE(sym->st_info) != STT_TLS)
-            && (ELF_ST_BIND(sym->st_info) != STB_WEAK))) {
+		    && (ELF_ST_BIND(sym->st_info) != STB_WEAK))) {
-            /* This may be non-fatal if called from dlopen. */
+			/* This may be non-fatal if called from dlopen. */
-            return 1;
+			return 1;
 
 
 		}
 		}
 	} else {
 	} else {
-        /* Relocs against STN_UNDEF are usually treated as using a
+		/* Relocs against STN_UNDEF are usually treated as using a
-         * symbol value of zero, and using the module containing the
+		 * symbol value of zero, and using the module containing the
-         * reloc itself. */
+		 * reloc itself. */
-        symbol_addr = sym->st_value;
+		symbol_addr = sym->st_value;
-        tls_tpnt = tpnt;
+		tls_tpnt = tpnt;
-    }
+	}
 
 
 #if defined (__SUPPORT_LD_DEBUG__)
 #if defined (__SUPPORT_LD_DEBUG__)
 	old_val = *reloc_addr;
 	old_val = *reloc_addr;
@@ -235,8 +235,8 @@ _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope,
 			break;
 			break;
 
 
 		case R_SPARC_JMP_SLOT:
 		case R_SPARC_JMP_SLOT:
-            reloc_addr[1] = OPCODE_SETHI_G1 | (( symbol_addr >> 10 ) & 0x3fffff);
+			reloc_addr[1] = OPCODE_SETHI_G1 | (( symbol_addr >> 10 ) & 0x3fffff);
-            reloc_addr[2] = OPCODE_JMP_G1 | ( symbol_addr & 0x3ff );
+			reloc_addr[2] = OPCODE_JMP_G1 | ( symbol_addr & 0x3ff );
 			break;
 			break;
 
 
 		case R_SPARC_RELATIVE:
 		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");
 				_dl_dprintf(_dl_debug_file, "no symbol_addr to copy !?\n");
 			break;
 			break;
 #if USE_TLS
 #if USE_TLS
-        case R_SPARC_TLS_DTPMOD32:
+		case R_SPARC_TLS_DTPMOD32:
-            *reloc_addr = tls_tpnt->l_tls_modid;
+			*reloc_addr = tls_tpnt->l_tls_modid;
-            break;
+			break;
-
+
-        case R_SPARC_TLS_DTPOFF32:
+		case R_SPARC_TLS_DTPOFF32:
-            /* During relocation all TLS symbols are defined and used.
+			/* During relocation all TLS symbols are defined and used.
-             * Therefore the offset is already correct.  */
+			 * Therefore the offset is already correct.  */
-            *reloc_addr = sym->st_value + rpnt->r_addend;
+			*reloc_addr = sym->st_value + rpnt->r_addend;
-            break;
+			break;
-
+
-        case R_SPARC_TLS_TPOFF32:
+		case R_SPARC_TLS_TPOFF32:
-            /* The offset is negative, forward from the thread pointer.
+			/* The offset is negative, forward from the thread pointer.
-             * We know the offset of the object the symbol is contained in.
+			 * We know the offset of the object the symbol is contained in.
-             * It is a negative value which will be added to the
+			 * It is a negative value which will be added to the
-             * thread pointer.  */
+			 * thread pointer.  */
-            CHECK_STATIC_TLS ((struct link_map *) tls_tpnt);
+			CHECK_STATIC_TLS ((struct link_map *) tls_tpnt);
-            *reloc_addr = sym->st_value - tls_tpnt->l_tls_offset + rpnt->r_addend;
+			*reloc_addr = sym->st_value - tls_tpnt->l_tls_offset + rpnt->r_addend;
-            break;
+			break;
 #endif
 #endif
 		default:
 		default:
 			return -1;	/* Calls _dl_exit(1). */
 			return -1;	/* Calls _dl_exit(1). */

+ 14 - 25
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);
 	ret = _dl_find_hash(name2, handle, NULL, 0, &tls_tpnt);
 
 
 #if defined USE_TLS && defined SHARED
 #if defined USE_TLS && defined SHARED
-	if(tls_tpnt) {
+	if (tls_tpnt) {
 		/* The found symbol is a thread-local storage variable.
 		/* The found symbol is a thread-local storage variable.
 		Return the address for to the current thread.  */
 		Return the address for to the current thread.  */
 		ret = _dl_tls_symaddr ((struct link_map *)tls_tpnt, (Elf32_Addr)ret);
 		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;
 			tls_lmap = (struct link_map *) tpnt;
 
 
 			/* Remove the object from the dtv slotinfo array if it uses TLS. */
 			/* 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;
 				any_tls = true;
 
 
 				if (_dl_tls_dtv_slotinfo_list != NULL
 				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. */
 					/* All dynamically loaded modules with TLS are unloaded. */
 					_dl_tls_max_dtv_idx = _dl_tls_static_nelem;
 					_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
 					 * Collect a contiguous chunk built from the objects in
 					 * this search list, going in either direction.  When the
 					 * 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 defined(TLS_TCB_AT_TP)
 					if (tls_free_start == NO_TLS_OFFSET
 					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. */
 						/* Extend the contiguous chunk being reclaimed. */
 						tls_free_start
 						tls_free_start
 							= tls_lmap->l_tls_offset -
 							= 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)
 						if (tls_free_end == NO_TLS_OFFSET)
 							tls_free_end = tls_lmap->l_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)
 							== tls_free_end)
 						/* Extend the chunk backwards.  */
 						/* Extend the chunk backwards.  */
 						tls_free_end = tls_lmap->l_tls_offset;
 						tls_free_end = tls_lmap->l_tls_offset;
-					else
+					else {
-					{
 						/*
 						/*
 						 * This isn't contiguous with the last chunk freed.
 						 * This isn't contiguous with the last chunk freed.
 						 * One of them will be leaked unless we can free
 						 * One of them will be leaked unless we can free
 						 * one block right away.
 						 * 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;
 							_dl_tls_static_used = tls_free_start;
 							tls_free_end = tls_lmap->l_tls_offset;
 							tls_free_end = tls_lmap->l_tls_offset;
 							tls_free_start
 							tls_free_start
 								= tls_free_end - tls_lmap->l_tls_blocksize;
 								= 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)
 							_dl_tls_static_used = tls_lmap->l_tls_offset -
 							_dl_tls_static_used = tls_lmap->l_tls_offset -
 								tls_lmap->l_tls_blocksize;
 								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
 							 * We pick the later block. It has a chance
 							 * to be freed.
 							 * to be freed.
@@ -848,8 +840,7 @@ static int do_dlclose(void *vhandle, int need_fini)
 							== tls_free_start)
 							== tls_free_start)
 						/* Extend the chunk backwards. */
 						/* Extend the chunk backwards. */
 						tls_free_start = tls_lmap->l_tls_offset;
 						tls_free_start = tls_lmap->l_tls_offset;
-					else
+					else {
-					{
 						/*
 						/*
 						 * This isn't contiguous with the last chunk
 						 * This isn't contiguous with the last chunk
 						 * freed. One of them will be leaked.
 						 * 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 ();
 					dtv_t *dtv = THREAD_DTV ();
 
 
 					_dl_assert(!(dtv[tls_lmap->l_tls_modid].pointer.is_static));
 					_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
 						/* Note that free is called for NULL is well.  We
 						deallocate even if it is this dtv entry we are
 						deallocate even if it is this dtv entry we are
 						supposed to load.  The reason is that we call
 						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 USE_TLS
 	/* If we removed any object which uses TLS bump the generation counter.  */
 	/* If we removed any object which uses TLS bump the generation counter.  */
-	if (any_tls)
+	if (any_tls) {
-	{
+		if (__builtin_expect(++_dl_tls_generation == 0, 0)) {
-		if (__builtin_expect (++_dl_tls_generation == 0, 0))
+			_dl_debug_early("TLS generation counter wrapped!  Please report to the uClibc mailing list.\n");
-		{
-			_dl_debug_early ("TLS generation counter wrapped!  Please report to the uClibc mailing list.\n");
 			_dl_exit(30);
 			_dl_exit(30);
 		}
 		}