From be22a664367468fc4b7073694ce1ba551a3d974b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vivek=20Das=C2=A0Mohapatra?= <vivek@collabora.co.uk>
Date: Wed, 13 Sep 2017 23:07:50 +0100
Subject: [PATCH] If a stubroutine in the shim is called dump some backtrace
 info

We shouldn't ever reach a shim stubroutine, so if we do it means
a relocation has probably failed: We dump a few backtrace frames
if this happens so we can track down which DSO called into the
shim, and hopefully figure out what kind of relocation it was.
---
 data/capsule-shim.h | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/data/capsule-shim.h b/data/capsule-shim.h
index 3283f5501..fb2ad3032 100644
--- a/data/capsule-shim.h
+++ b/data/capsule-shim.h
@@ -21,15 +21,36 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <execinfo.h>
 
 #include <capsule.h>
 
 #define UNVERSIONED_STUB(name) \
-    void name (void) { fprintf(stderr, "! SHIM " #name " called\n" ); return; }
+    void name (void)                                   \
+    {                                                  \
+        fprintf(stderr, "! SHIM " #name " called\n" ); \
+        backtrace_shim_call();                         \
+        return;                                        \
+    }
 
 #define VERSIONED_STUB(name,version) \
     UNVERSIONED_STUB(name);
 
+void backtrace_shim_call (void)
+{
+    void *trace[16] = { NULL };
+    int traced = 0;
+    char **symbols = NULL;
+
+    traced  = backtrace( trace, sizeof(trace)/sizeof(void *) );
+    symbols = backtrace_symbols( trace, traced );
+
+    for( int x = 1; x < traced; x++ )
+        fprintf( stderr, "  -> %s\n", symbols[x] );
+
+    free( symbols );
+}
+
 // We don't support versioned symbols properly yet, they need som
 // asm magic that looks like this and I'm not clear on the details:
 // __asm__(".symver _" #name "," #name #version)
-- 
GitLab