Hi,

unfortunately, we still have no cool upstream fix for
-fvisibility=hidden compiler flag handling.
There is still no visibility-attribute "hidden" available or defined.

I see people again fell over this issue [2].

I have one concern...

GCC uses "default" visibility-attribute (defined as PUBLIC) when
compiler-flag "-fvisibility=hidden" is used.
But CLANG needs in some cases "hidden" visibility-attribute.

[ src/util/macros.h ]

/**
 * PUBLIC/USED macros
 *
 * If we build the library with gcc's -fvisibility=hidden flag, we'll
 * use the PUBLIC macro to mark functions that are to be exported.
 *
 * We also need to define a USED attribute, so the optimizer doesn't
 * inline a static function that we later use in an alias. - ajax
 */
#ifndef PUBLIC
#  if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
#    define PUBLIC __attribute__((visibility("default")))
#    define USED __attribute__((used))
#  elif defined(_MSC_VER)
#    define PUBLIC __declspec(dllexport)
#    define USED
#  else
#    define PUBLIC
#    define USED
#  endif
#endif

#ifdef HAVE_FUNC_ATTRIBUTE_VISIBILITY
#define HIDDEN __attribute__((visibility("hidden")))
#else
#define HIDDEN
#endif

[ src/util/macros.h ]

Alan pointed to a solution like in [4] ("Use clang's __has_attribute
to check for attribute support")

So, what can people do to help to nail this down?

I have attached a refreshed version of Marc's and added the TDS
snippet from [2] to 0002 patch.
( Patches have no changelog and are against mesa v10.6.8. )

Hope this helps!

Regards,
- Sedat -

[1] https://www.mail-archive.com/mesa-dev@lists.freedesktop.org/msg76122.html
[2] http://patchwork.freedesktop.org/patch/49494/
[3] 
https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/CppRuntimeEnv/Articles/SymbolVisibility.html
[4] http://cgit.freedesktop.org/xorg/proto/x11proto/commit/?id=ffd4a13042d24cb5c
From 4491f1246b79a3224c4d4a46b33e3fb0bde129fe Mon Sep 17 00:00:00 2001
From: Sedat Dilek <sedat.di...@gmail.com>
Date: Sat, 26 Sep 2015 00:40:26 +0200
Subject: [PATCH] configure: add visibility macro detection

---
 configure.ac      | 30 +++++++-----------------------
 src/util/macros.h |  6 ++++++
 2 files changed, 13 insertions(+), 23 deletions(-)

diff --git a/configure.ac b/configure.ac
index 0f21282d77ec..4a075515a6f4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -211,6 +211,7 @@ AX_GCC_FUNC_ATTRIBUTE([format])
 AX_GCC_FUNC_ATTRIBUTE([malloc])
 AX_GCC_FUNC_ATTRIBUTE([packed])
 AX_GCC_FUNC_ATTRIBUTE([unused])
+AX_GCC_FUNC_ATTRIBUTE([visibility])
 
 AM_CONDITIONAL([GEN_ASM_OFFSETS], test "x$GEN_ASM_OFFSETS" = xyes)
 
@@ -267,16 +268,6 @@ if test "x$GCC" = xyes; then
 		   AC_MSG_RESULT([yes]),
 		   [CFLAGS="$save_CFLAGS -Wmissing-prototypes";
 		    AC_MSG_RESULT([no])]);
-
-    # Enable -fvisibility=hidden if using a gcc that supports it
-    save_CFLAGS="$CFLAGS"
-    AC_MSG_CHECKING([whether $CC supports -fvisibility=hidden])
-    VISIBILITY_CFLAGS="-fvisibility=hidden"
-    CFLAGS="$CFLAGS $VISIBILITY_CFLAGS"
-    AC_LINK_IFELSE([AC_LANG_PROGRAM()], AC_MSG_RESULT([yes]),
-		   [VISIBILITY_CFLAGS=""; AC_MSG_RESULT([no])]);
-
-    # Restore CFLAGS; VISIBILITY_CFLAGS are added to it where needed.
     CFLAGS=$save_CFLAGS
 
     # Work around aliasing bugs - developers should comment this out
@@ -313,19 +304,6 @@ fi
 if test "x$GXX" = xyes; then
     CXXFLAGS="$CXXFLAGS -Wall"
 
-    # Enable -fvisibility=hidden if using a gcc that supports it
-    save_CXXFLAGS="$CXXFLAGS"
-    AC_MSG_CHECKING([whether $CXX supports -fvisibility=hidden])
-    VISIBILITY_CXXFLAGS="-fvisibility=hidden"
-    CXXFLAGS="$CXXFLAGS $VISIBILITY_CXXFLAGS"
-    AC_LANG_PUSH([C++])
-    AC_LINK_IFELSE([AC_LANG_PROGRAM()], AC_MSG_RESULT([yes]),
-		   [VISIBILITY_CXXFLAGS="" ; AC_MSG_RESULT([no])]);
-    AC_LANG_POP([C++])
-
-    # Restore CXXFLAGS; VISIBILITY_CXXFLAGS are added to it where needed.
-    CXXFLAGS=$save_CXXFLAGS
-
     # Work around aliasing bugs - developers should comment this out
     CXXFLAGS="$CXXFLAGS -fno-strict-aliasing"
 
@@ -339,6 +317,12 @@ AC_SUBST([MSVC2013_COMPAT_CXXFLAGS])
 AC_SUBST([MSVC2008_COMPAT_CFLAGS])
 AC_SUBST([MSVC2008_COMPAT_CXXFLAGS])
 
+# Enable -fvisibility=hidden if using a compiler that supports it
+if test "x${ax_cv_have_func_attribute_visibility}" = xyes; then
+	VISIBILITY_CFLAGS="-fvisibility=hidden"
+	VISIBILITY_CXXFLAGS="-fvisibility=hidden"
+fi
+
 dnl even if the compiler appears to support it, using visibility attributes isn't
 dnl going to do anything useful currently on cygwin apart from emit lots of warnings
 case "$host_os" in
diff --git a/src/util/macros.h b/src/util/macros.h
index 3b708ed6aa2a..8784e38a91b6 100644
--- a/src/util/macros.h
+++ b/src/util/macros.h
@@ -176,6 +176,12 @@ do {                       \
 #  endif
 #endif
 
+#ifdef HAVE_FUNC_ATTRIBUTE_VISIBILITY
+#define HIDDEN __attribute__((visibility("hidden")))
+#else
+#define HIDDEN
+#endif
+
 #ifdef HAVE_FUNC_ATTRIBUTE_UNUSED
 #define UNUSED __attribute__((unused))
 #else
-- 
2.5.3

From f95bb5ed912bda8d7e044d004b114815d2cf5559 Mon Sep 17 00:00:00 2001
From: Sedat Dilek <sedat.di...@gmail.com>
Date: Sat, 26 Sep 2015 01:15:43 +0200
Subject: [PATCH] mapi: add visibility hidden to tls entry points

---
 src/mapi/Makefile.am        | 1 +
 src/mapi/entry_x86-64_tls.h | 4 ++--
 src/mapi/entry_x86_tls.h    | 4 ++--
 src/mapi/entry_x86_tsd.h    | 5 +++--
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/mapi/Makefile.am b/src/mapi/Makefile.am
index 50c5b2ebba32..fcc019b430f2 100644
--- a/src/mapi/Makefile.am
+++ b/src/mapi/Makefile.am
@@ -48,6 +48,7 @@ AM_CPPFLAGS =							\
 	-I$(top_srcdir)/include					\
 	-I$(top_srcdir)/src					\
 	-I$(top_srcdir)/src/mapi				\
+	-I$(top_srcdir)/src/util				\
 	-I$(top_builddir)/src/mapi
 
 include Makefile.sources
diff --git a/src/mapi/entry_x86-64_tls.h b/src/mapi/entry_x86-64_tls.h
index 5c03b045606c..fe9d2d597cc2 100644
--- a/src/mapi/entry_x86-64_tls.h
+++ b/src/mapi/entry_x86-64_tls.h
@@ -25,6 +25,7 @@
  *    Chia-I Wu <o...@lunarg.com>
  */
 
+#include "macros.h"
 
 __asm__(".text\n"
         ".balign 32\n"
@@ -61,8 +62,7 @@ entry_patch_public(void)
 {
 }
 
-static char
-x86_64_entry_start[];
+extern char HIDDEN x86_64_entry_start[];
 
 mapi_func
 entry_get_public(int slot)
diff --git a/src/mapi/entry_x86_tls.h b/src/mapi/entry_x86_tls.h
index 46d2eced24f8..5bb33b7ebefa 100644
--- a/src/mapi/entry_x86_tls.h
+++ b/src/mapi/entry_x86_tls.h
@@ -71,8 +71,8 @@ __asm__(".text");
 extern unsigned long
 x86_current_tls();
 
-static char x86_entry_start[];
-static char x86_entry_end[];
+extern char HIDDEN x86_entry_start[];
+extern char HIDDEN x86_entry_end[];
 
 void
 entry_patch_public(void)
diff --git a/src/mapi/entry_x86_tsd.h b/src/mapi/entry_x86_tsd.h
index ea7bacb43e48..e40525935d4d 100644
--- a/src/mapi/entry_x86_tsd.h
+++ b/src/mapi/entry_x86_tsd.h
@@ -25,6 +25,7 @@
  *    Chia-I Wu <o...@lunarg.com>
  */
 
+#include "macros.h"
 
 #define X86_ENTRY_SIZE 32
 
@@ -58,8 +59,8 @@ __asm__(".balign 32\n"
 #include <string.h>
 #include "u_execmem.h"
 
-static const char x86_entry_start[];
-static const char x86_entry_end[];
+extern const char HIDDEN x86_entry_start[];
+extern const char HIDDEN x86_entry_end[];
 
 void
 entry_patch_public(void)
-- 
2.5.3

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to