Backport of http://git.uclibc.org/uClibc/commit/?id=82f8d0bce10403deab704871e638edc24e7933ee

--- libc/stdlib/abort.c
+++ libc/stdlib/abort.c
@@ -38,6 +38,7 @@
 
 #ifdef __UCLIBC_HAS_STDIO_SHUTDOWN_ON_ABORT__
 extern void weak_function _stdio_term(void) attribute_hidden;
+#include "_not_null_ptr.c"
 #endif
 static smallint been_there_done_that = 0;
 
@@ -68,7 +69,7 @@
 			 * this will attempt to commit all buffered writes.  It may also
 			 * unbuffer all writable files, or close them outright.
 			 * Check the stdio routines for details. */
-			if (_stdio_term) {
+			if (not_null_ptr(_stdio_term)) {
 				_stdio_term();
 			}
 #endif
--- libc/stdlib/_atexit.c
+++ libc/stdlib/_atexit.c
@@ -303,6 +303,7 @@
 #endif
 
 #ifdef L_exit
+#include "_not_null_ptr.c"
 extern void weak_function _stdio_term(void) attribute_hidden;
 attribute_hidden void (*__exit_cleanup) (int) = 0;
 __UCLIBC_MUTEX_INIT(__atexit_lock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
@@ -317,7 +318,7 @@
 {
 	/* Perform exit-specific cleanup (atexit and on_exit) */
 	__UCLIBC_MUTEX_LOCK(__atexit_lock);
-	if (__exit_cleanup) {
+	if (not_null_ptr(__exit_cleanup)) {
 		__exit_cleanup(rv);
 	}
 	__UCLIBC_MUTEX_UNLOCK(__atexit_lock);
@@ -328,7 +329,7 @@
 	 * this will attempt to commit all buffered writes.  It may also
 	 * unbuffer all writable files, or close them outright.
 	 * Check the stdio routines for details. */
-	if (_stdio_term)
+	if (not_null_ptr(_stdio_term))
 	    _stdio_term();
 
 	_exit(rv);
--- libc/stdlib/_not_null_ptr.c
+++ libc/stdlib/_not_null_ptr.c
@@ -0,0 +1,10 @@
+/* Defeat compiler optimization which assumes function addresses are never NULL */
+static __always_inline int not_null_ptr(const void *p)
+{
+	const void *q;
+	__asm__ (""
+		: "=r" (q) /* output */
+		: "0" (p) /* input */
+	);
+	return q != 0;
+}
