From d6f15183b4064af11ce78cbf8a55edb04ad4a672 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Thu, 15 Dec 2011 19:01:47 +0400 Subject: [PATCH] Instruct configure to hide internal libgc.so symbols if supported (GCC) * configure.ac (ac_cv_fvisibility_hidden): New variable (set to "yes" if only shared library is built and GCC supports "-fvisibility" option. * configure.ac (CFLAGS): Add "-fvisibility=hidden" and "-DGC_VISIBILITY_HIDDEN_SET" if ac_cv_fvisibility_hidden is "yes". * include/gc_config_macros.h (GC_API): Force "default visibility" attribute if GC_VISIBILITY_HIDDEN_SET (only if GCC and GC_BUILD). * tests/staticrootstest.c (GC_VISIBILITY_HIDDEN_SET): Test the macro and skip the test if defined (since "staticrootslib" symbols are of hidden visibility). --- configure.ac | 13 ++++++++++++- include/gc_config_macros.h | 3 ++- tests/staticrootstest.c | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 0f96066..ab8b27c 100644 --- a/configure.ac +++ b/configure.ac @@ -505,7 +505,18 @@ AC_MSG_RESULT($enable_shared) if test "${enable_shared}" == yes; then if test "${enable_static}" == no; then AC_DEFINE(GC_DLL) - # FIXME: Also pass -fvisibility=hidden option if GCC v4+ and not Win32. + if test "$GCC" = yes; then + # Pass -fvisibility=hidden option if supported + AC_MSG_CHECKING([whether gcc supports -fvisibility]) + old_CFLAGS="$CFLAGS" + CFLAGS="-fvisibility=hidden $CFLAGS" + AC_TRY_COMPILE([],[], [ac_cv_fvisibility_hidden=yes], + [ac_cv_fvisibility_hidden=no]) + AS_IF([test "$ac_cv_fvisibility_hidden" = yes], + [CFLAGS="-DGC_VISIBILITY_HIDDEN_SET $CFLAGS"], + [CFLAGS="$old_CFLAGS"]) + AC_MSG_RESULT($ac_cv_fvisibility_hidden) + fi fi fi diff --git a/include/gc_config_macros.h b/include/gc_config_macros.h index 73db584..d407a6b 100644 --- a/include/gc_config_macros.h +++ b/include/gc_config_macros.h @@ -195,7 +195,8 @@ # elif defined(__GNUC__) /* Only matters if used in conjunction with -fvisibility=hidden option. */ -# if __GNUC__ >= 4 && defined(GC_BUILD) +# if defined(GC_BUILD) && (__GNUC__ >= 4 \ + || defined(GC_VISIBILITY_HIDDEN_SET)) # define GC_API extern __attribute__((__visibility__("default"))) # endif # endif diff --git a/tests/staticrootstest.c b/tests/staticrootstest.c index 222f209..f0b45bb 100644 --- a/tests/staticrootstest.c +++ b/tests/staticrootstest.c @@ -9,6 +9,8 @@ #include "gc.h" #include "gc_backptr.h" +#ifndef GC_VISIBILITY_HIDDEN_SET + struct treenode { struct treenode *x; struct treenode *y; @@ -55,3 +57,15 @@ int main(void) } return 0; } + +#else + +/* Skip since symbols defined in staticrootslib are not visible */ + +int main(void) +{ + printf("staticrootstest skipped\n"); + return 0; +} + +#endif -- 2.7.4