[Mesa-dev] [PATCH 05/12] mesa: Consolidate used/visibility function attributes.

Matt Turner mattst88 at gmail.com
Mon Sep 22 11:51:02 PDT 2014


And check for them in configure.
---
 configure.ac             |  2 ++
 src/mapi/u_compiler.h    | 11 -----------
 src/mesa/main/compiler.h | 20 --------------------
 src/util/macros.h        | 14 ++++++++++++++
 4 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/configure.ac b/configure.ac
index 024050e..2fe1539 100644
--- a/configure.ac
+++ b/configure.ac
@@ -145,6 +145,8 @@ AX_GCC_FUNC_ATTRIBUTE([flatten])
 AX_GCC_FUNC_ATTRIBUTE([format])
 AX_GCC_FUNC_ATTRIBUTE([malloc])
 AX_GCC_FUNC_ATTRIBUTE([packed])
+AX_GCC_FUNC_ATTRIBUTE([used])
+AX_GCC_FUNC_ATTRIBUTE([visibility])
 
 AM_CONDITIONAL([GEN_ASM_OFFSETS], test "x$GEN_ASM_OFFSETS" = xyes)
 
diff --git a/src/mapi/u_compiler.h b/src/mapi/u_compiler.h
index f376e97..b305beb 100644
--- a/src/mapi/u_compiler.h
+++ b/src/mapi/u_compiler.h
@@ -9,17 +9,6 @@
 #  define INLINE inline
 #endif
 
-/* Function visibility */
-#ifndef PUBLIC
-#  if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
-#    define PUBLIC __attribute__((visibility("default")))
-#  elif defined(_MSC_VER)
-#    define PUBLIC __declspec(dllexport)
-#  else
-#    define PUBLIC
-#  endif
-#endif
-
 #ifndef likely
 #  if defined(__GNUC__)
 #    define likely(x)   __builtin_expect(!!(x), 1)
diff --git a/src/mesa/main/compiler.h b/src/mesa/main/compiler.h
index 813bf19..c1c1005 100644
--- a/src/mesa/main/compiler.h
+++ b/src/mesa/main/compiler.h
@@ -112,26 +112,6 @@ extern "C" {
 #endif
 
 
-/**
- * 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__) && __GNUC__ >= 4) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
-#    define PUBLIC __attribute__((visibility("default")))
-#    define USED __attribute__((used))
-#  else
-#    define PUBLIC
-#    define USED
-#  endif
-#endif
-
-
 /* XXX: Use standard `__func__` instead */
 #ifndef __FUNCTION__
 #  define __FUNCTION__ __func__
diff --git a/src/util/macros.h b/src/util/macros.h
index 40ebf02..c65ce8a 100644
--- a/src/util/macros.h
+++ b/src/util/macros.h
@@ -102,6 +102,20 @@ do {                        \
 #define PACKED
 #endif
 
+#ifdef HAVE_FUNC_ATTRIBUTE_USED
+#define USED __attribute__((__used__))
+#else
+#define USED
+#endif
+
+#ifdef HAVE_FUNC_ATTRIBUTE_VISIBILITY
+#define PUBLIC __attribute__((__visibility__("default")))
+#elif defined(_MSC_VER)
+#define PUBLIC __declspec(dllexport)
+#else
+#define PUBLIC
+#endif
+
 #ifdef __cplusplus
 /**
  * Macro function that evaluates to true if T is a trivially
-- 
1.8.5.5



More information about the mesa-dev mailing list