On Sat, Sep 26, 2015 at 1:59 AM, Sedat Dilek <sedat.di...@gmail.com> wrote:
> 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

So, I played a bit more and the result is a v3 of both patches with
some simplification etc.

Emil asked in another thread to check with --enable-asm and
--{en|dis}able-shared-glapi, but disabling for the latter was not
suitable for my setup (disabling OpenGL resulted in a conflict with
dri-drivers etc.).

Brian asked if this works with GCC v4.9 - yes.

Have fun!

- Sedat -
From f9b6ab85755c08f2fee801e0fe64384c62fe6bd7 Mon Sep 17 00:00:00 2001
From: Sedat Dilek <sedat.di...@gmail.com>
Date: Sat, 26 Sep 2015 04:23:31 +0200
Subject: [PATCH] configure: add visibility macro detection (v3)

---
 configure.ac      | 30 +++++++-----------------------
 src/util/macros.h | 11 ++++++++++-
 2 files changed, 17 insertions(+), 24 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..80b93940f8cd 100644
--- a/src/util/macros.h
+++ b/src/util/macros.h
@@ -155,7 +155,7 @@ do {                       \
 #endif
 
 /**
- * PUBLIC/USED macros
+ * PUBLIC/USED and HIDDEN 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.
@@ -163,6 +163,7 @@ do {                       \
  * 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
  */
+#ifdef HAVE_FUNC_ATTRIBUTE_VISIBILITY
 #ifndef PUBLIC
 #  if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
 #    define PUBLIC __attribute__((visibility("default")))
@@ -175,6 +176,14 @@ do {                       \
 #    define USED
 #  endif
 #endif
+#ifndef HIDDEN
+#  if (defined(__GNUC__) && (__GNUC__ >= 4)) && !defined(__CYGWIN__) && !defined(__MINGW32__)
+#    define HIDDEN __attribute__((visibility("hidden")))
+#  else
+#    define HIDDEN
+#  endif
+#endif
+#endif /* HAVE_FUNC_ATTRIBUTE_VISIBILITY */
 
 #ifdef HAVE_FUNC_ATTRIBUTE_UNUSED
 #define UNUSED __attribute__((unused))
-- 
2.5.3

From e5d54ee1e0174133406c293f3c2c923f2606ae18 Mon Sep 17 00:00:00 2001
From: Sedat Dilek <sedat.di...@gmail.com>
Date: Sat, 26 Sep 2015 04:06:07 +0200
Subject: [PATCH] mapi: add visibility hidden to tls entry points (v3)

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

diff --git a/src/mapi/entry_x86-64_tls.h b/src/mapi/entry_x86-64_tls.h
index 5c03b045606c..2da7eb17c732 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 "util/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..cd36f0f82a22 100644
--- a/src/mapi/entry_x86_tls.h
+++ b/src/mapi/entry_x86_tls.h
@@ -26,6 +26,7 @@
  */
 
 #include <string.h>
+#include "util/macros.h"
 
 __asm__(".text");
 
@@ -71,8 +72,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..7bcc4b4ac624 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 "util/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

Attachment: build_mesa-with-llvm.sh
Description: Bourne shell script

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

Reply via email to