diff --git a/support/Makefile b/support/Makefile index 59a9974539..0c670555ae 100644 --- a/support/Makefile +++ b/support/Makefile @@ -281,6 +281,8 @@ CFLAGS-temp_file.c += -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 ifeq (,$(CXX)) LINKS_DSO_PROGRAM = links-dso-program-c +CFLAGS-links-dso-program-c.c += -fexceptions +LDLIBS-links-dso-program-c = -lgcc -lgcc_s $(libunwind) else LINKS_DSO_PROGRAM = links-dso-program LDLIBS-links-dso-program = -lstdc++ -lgcc -lgcc_s $(libunwind) diff --git a/support/links-dso-program-c.c b/support/links-dso-program-c.c index 5fcbab2c17..efe65b4b19 100644 --- a/support/links-dso-program-c.c +++ b/support/links-dso-program-c.c @@ -1,4 +1,5 @@ #include +#include /* makedb needs selinux dso's. */ #ifdef HAVE_SELINUX @@ -13,6 +14,20 @@ such dependencies. */ +/* Use attribute cleanup to force linking against libgcc_s. */ +static void +cleanup_function (int *ignored) +{ + puts ("cleanup performed"); +} + +void +invoke_callback (void (*callback) (int *)) +{ + __attribute__ ((cleanup (cleanup_function))) int i = 0; + callback (&i); +} + int main (int argc, char **argv) { @@ -22,5 +37,10 @@ main (int argc, char **argv) /* This exists to force libselinux.so to be required. */ printf ("selinux %d\n", is_selinux_enabled ()); #endif + /* Prevent invoke_callback from being optimized away. */ + { + Dl_info dli; + dladdr (invoke_callback, &dli); + } return 0; }