Fix: don't call __builtin_return_address(0) on 32-bit powerpc
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 24 May 2016 22:58:14 +0000 (18:58 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 26 May 2016 02:03:16 +0000 (22:03 -0400)
Invoking __builtin_return_address(0) corrupts the stack, as previously
noticed for the "ip" context. Disable its use on 32-bit powerpc
everywhere else in the lttng-ust code base.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/helper.h
liblttng-ust-dl/lttng-ust-dl.c
liblttng-ust-libc-wrapper/lttng-ust-malloc.c
liblttng-ust-libc-wrapper/lttng-ust-pthread.c
liblttng-ust/tracef.c
liblttng-ust/tracelog.c

index 9d6617a8de044b2f1fa04481c9c1874cb8ffbcd2..9873feadd85b020556c1cd1e4f45925094b1fdd1 100644 (file)
@@ -43,4 +43,16 @@ void *zmalloc(size_t len)
 
 #define LTTNG_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
+/*
+ * Use of __builtin_return_address(0) sometimes seems to cause stack
+ * corruption on 32-bit PowerPC. Disable this feature on that
+ * architecture for now by always using the NULL value for the ip
+ * context.
+ */
+#if defined(__PPC__) && !defined(__PPC64__)
+#define LTTNG_UST_CALLER_IP()          NULL
+#else /* #if defined(__PPC__) && !defined(__PPC64__) */
+#define LTTNG_UST_CALLER_IP()          __builtin_return_address(0)
+#endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
+
 #endif /* _LTTNG_UST_HELPER_H */
index d366f64f8f46c2195bd0bc3a1ba8af69b3ec28ec..25912890c3366794dcb8c22fbb92aafd2b7a2b64 100644 (file)
@@ -29,6 +29,7 @@
 #include <signal.h>
 #include <sched.h>
 #include <stdarg.h>
+#include <helper.h>
 #include "usterr-signal-safe.h"
 
 #include <lttng/ust-compiler.h>
@@ -95,7 +96,7 @@ void *dlopen(const char *filename, int flag)
                if (dlinfo(handle, RTLD_DI_LINKMAP, &p) != -1 && p != NULL
                                && p->l_addr != 0)
                        lttng_ust_dl_dlopen((void *) p->l_addr, p->l_name,
-                               __builtin_return_address(0));
+                               LTTNG_UST_CALLER_IP());
        }
        return handle;
 }
@@ -107,7 +108,7 @@ int dlclose(void *handle)
                if (dlinfo(handle, RTLD_DI_LINKMAP, &p) != -1 && p != NULL
                                && p->l_addr != 0)
                        tracepoint(lttng_ust_dl, dlclose, (void *) p->l_addr,
-                               __builtin_return_address(0));
+                               LTTNG_UST_CALLER_IP());
        }
        return _lttng_ust_dl_libc_dlclose(handle);
 }
index ba8e4d42ac018e5808e80431aabe213bd9f5df7c..d1ad3cf5b146260cf93548df5bf2a41ae9358057 100644 (file)
@@ -28,6 +28,7 @@
 #include <urcu/tls-compat.h>
 #include <urcu/arch.h>
 #include <lttng/align.h>
+#include <helper.h>
 
 #define TRACEPOINT_DEFINE
 #define TRACEPOINT_CREATE_PROBES
@@ -262,7 +263,7 @@ void *malloc(size_t size)
        retval = cur_alloc.malloc(size);
        if (URCU_TLS(malloc_nesting) == 1) {
                tracepoint(lttng_ust_libc, malloc,
-                       size, retval, __builtin_return_address(0));
+                       size, retval, LTTNG_UST_CALLER_IP());
        }
        URCU_TLS(malloc_nesting)--;
        return retval;
@@ -282,7 +283,7 @@ void free(void *ptr)
 
        if (URCU_TLS(malloc_nesting) == 1) {
                tracepoint(lttng_ust_libc, free,
-                       ptr, __builtin_return_address(0));
+                       ptr, LTTNG_UST_CALLER_IP());
        }
 
        if (cur_alloc.free == NULL) {
@@ -312,7 +313,7 @@ void *calloc(size_t nmemb, size_t size)
        retval = cur_alloc.calloc(nmemb, size);
        if (URCU_TLS(malloc_nesting) == 1) {
                tracepoint(lttng_ust_libc, calloc,
-                       nmemb, size, retval, __builtin_return_address(0));
+                       nmemb, size, retval, LTTNG_UST_CALLER_IP());
        }
        URCU_TLS(malloc_nesting)--;
        return retval;
@@ -365,7 +366,7 @@ void *realloc(void *ptr, size_t size)
 end:
        if (URCU_TLS(malloc_nesting) == 1) {
                tracepoint(lttng_ust_libc, realloc,
-                       ptr, size, retval, __builtin_return_address(0));
+                       ptr, size, retval, LTTNG_UST_CALLER_IP());
        }
        URCU_TLS(malloc_nesting)--;
        return retval;
@@ -387,7 +388,7 @@ void *memalign(size_t alignment, size_t size)
        if (URCU_TLS(malloc_nesting) == 1) {
                tracepoint(lttng_ust_libc, memalign,
                        alignment, size, retval,
-                       __builtin_return_address(0));
+                       LTTNG_UST_CALLER_IP());
        }
        URCU_TLS(malloc_nesting)--;
        return retval;
@@ -409,7 +410,7 @@ int posix_memalign(void **memptr, size_t alignment, size_t size)
        if (URCU_TLS(malloc_nesting) == 1) {
                tracepoint(lttng_ust_libc, posix_memalign,
                        *memptr, alignment, size,
-                       retval, __builtin_return_address(0));
+                       retval, LTTNG_UST_CALLER_IP());
        }
        URCU_TLS(malloc_nesting)--;
        return retval;
index fd3af1105a961422e276671a483b18c81a80389a..c6b8ae09955119ef6ac9ad4eeacc6ca7cbaff4e0 100644 (file)
@@ -18,6 +18,7 @@
 
 #define _GNU_SOURCE
 #include <lttng/ust-dlfcn.h>
+#include <helper.h>
 #include <pthread.h>
 
 #define TRACEPOINT_DEFINE
@@ -48,10 +49,10 @@ int pthread_mutex_lock(pthread_mutex_t *mutex)
 
        thread_in_trace = 1;
        tracepoint(lttng_ust_pthread, pthread_mutex_lock_req, mutex,
-               __builtin_return_address(0));
+               LTTNG_UST_CALLER_IP());
        retval = mutex_lock(mutex);
        tracepoint(lttng_ust_pthread, pthread_mutex_lock_acq, mutex,
-               retval, __builtin_return_address(0));
+               retval, LTTNG_UST_CALLER_IP());
        thread_in_trace = 0;
        return retval;
 }
@@ -78,7 +79,7 @@ int pthread_mutex_trylock(pthread_mutex_t *mutex)
        thread_in_trace = 1;
        retval = mutex_trylock(mutex);
        tracepoint(lttng_ust_pthread, pthread_mutex_trylock, mutex,
-               retval, __builtin_return_address(0));
+               retval, LTTNG_UST_CALLER_IP());
        thread_in_trace = 0;
        return retval;
 }
@@ -105,7 +106,7 @@ int pthread_mutex_unlock(pthread_mutex_t *mutex)
        thread_in_trace = 1;
        retval = mutex_unlock(mutex);
        tracepoint(lttng_ust_pthread, pthread_mutex_unlock, mutex,
-               retval, __builtin_return_address(0));
+               retval, LTTNG_UST_CALLER_IP());
        thread_in_trace = 0;
        return retval;
 }
index dcae3be746f45350d5d17b9decf5dae90e70de2b..ea98e43eeed198a3588ddb21d3668954383da810 100644 (file)
@@ -23,6 +23,7 @@
 #define _GNU_SOURCE
 #define _LGPL_SOURCE
 #include <stdio.h>
+#include <helper.h>
 
 #define TRACEPOINT_CREATE_PROBES
 #define TRACEPOINT_DEFINE
@@ -40,7 +41,7 @@ void _lttng_ust_tracef(const char *fmt, ...)
        if (len < 0)
                goto end;
        __tracepoint_cb_lttng_ust_tracef___event(msg, len,
-               __builtin_return_address(0));
+               LTTNG_UST_CALLER_IP());
        free(msg);
 end:
        va_end(ap);
index 93eb403a6bde5807d955f2351afc543384443356..65fc87ede57818c21d2af3b87ea7c8f3e133e5d7 100644 (file)
@@ -23,6 +23,7 @@
 #define _GNU_SOURCE
 #define _LGPL_SOURCE
 #include <stdio.h>
+#include <helper.h>
 
 #define TRACEPOINT_CREATE_PROBES
 #define TRACEPOINT_DEFINE
@@ -44,7 +45,7 @@
                        goto end; \
                __tracepoint_cb_lttng_ust_tracelog___##level(file, \
                        line, func, msg, len, \
-                       __builtin_return_address(0)); \
+                       LTTNG_UST_CALLER_IP()); \
                free(msg); \
        end: \
                va_end(ap); \
This page took 0.028638 seconds and 4 git commands to generate.