[uclibc-ng-devel,27/32] nptl threads: Fix bug in using a weak variable.

Message ID 20180704155605.1892-28-christophe.lyon@st.com
State New
Headers show
Series
  • FDPIC ABI for ARM
Related show

Commit Message

Christophe Lyon July 4, 2018, 3:55 p.m.
In case __nptl_nthreads is not defined in the final binary then avoid
dereferencing the address since it's null. Anyway this means there is
no other thread and so we must exit.

	* libc/misc/internals/__uClibc_main.c (__uClibc_main): Handle case
	where &__nptl_nthreads is null.

Signed-off-by: Mickaël Guêné <mickael.guene@st.com>
Signed-off-by: Christophe Lyon <christophe.lyon@st.com>

Patch

diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c
index d8286f2..849bca8 100644
--- a/libc/misc/internals/__uClibc_main.c
+++ b/libc/misc/internals/__uClibc_main.c
@@ -544,7 +544,7 @@  void __uClibc_main(int (*main)(int, char **, char **), int argc,
 		result = 0;
 		unsigned int *const ptr = &__nptl_nthreads;
 
-		if (! atomic_decrement_and_test (ptr))
+		if (ptr && ! atomic_decrement_and_test (ptr))
 			/* Not much left to do but to exit the thread, not the process.  */
 			__exit_thread_inline (0);
 	}