[PATCH 09/20] Prepare for creating hidden aliases of all routines

Richard Henderson rth at twiddle.net
Mon Mar 4 19:41:39 CET 2013


All of the mechanism is here, but not enabled -- configure has not
yet been updated to define HAVE_HIDDEN_ALIAS.

However, by hacking the generated config.h file by hand we'll be
able to find errors as they occur without having to create one
monster patch to do everything all at once.
---
 gen-renamei.c | 13 +++++++++++--
 gmp-h.in      | 21 +++++++++++++++++++--
 gmp-impl.h    | 19 ++++++++++++++++---
 3 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/gen-renamei.c b/gen-renamei.c
index 12a831f..6dd12d7 100644
--- a/gen-renamei.c
+++ b/gen-renamei.c
@@ -22,8 +22,17 @@ along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
 #include <obstack.h>
 
 #define __GMP_WITHIN_CONFIGURE
-#define __GMP_INTERN_FULL(TYPE, API_NAME, ARGS, NT, ATTRS, ABI_NAME) \
-  __GMP_XYZZY API_NAME ABI_NAME
+
+/* For GCC, we need to remember the ABI name we associated with a symbol.  */
+#ifdef __GNUC__
+# define __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, NT, ATTRS, ABI_NAME) \
+   __GMP_XYZZY __GMP_GLUE(abi_, API_NAME) ABI_NAME
+# define __GMP_INTERN_FULL(TYPE, API_NAME, ARGS, NT, ATTRS, ABI_NAME) \
+   __GMP_XYZZY __GMP_GLUE(abi_, API_NAME) ABI_NAME
+#else
+# define __GMP_INTERN_FULL(TYPE, API_NAME, ARGS, NT, ATTRS, ABI_NAME) \
+   __GMP_XYZZY API_NAME ABI_NAME
+#endif
 
 #include "gmp.h"
 #include "gmp-impl.h"
diff --git a/gmp-h.in b/gmp-h.in
index 1b27998..ff0dc45 100644
--- a/gmp-h.in
+++ b/gmp-h.in
@@ -251,6 +251,10 @@ typedef __mpq_struct *mpq_ptr;
      __GMP_PUBLIC_DATA	- for declaring data variables
      __GMP_PUBLIC_ALIAS	- for re-declaring symbols with another name
 
+   When using GCC and building an ELF shared library, we'll arrange for
+   the rest of GMP to see a hidden alias.  The true public symbol will
+   be created in the individual source files.
+
    When using GCC, we'll use __asm__ to give the ABI symbol the linkage
    name corresponding to the ABI name.  Similarly to define aliases.
 
@@ -264,14 +268,27 @@ typedef __mpq_struct *mpq_ptr;
 
 #if !defined(__GMP_WITHIN_CONFIGURE) || !defined(__GMP_PUBLIC_FULL)
 # ifdef __GNUC__
-#  define __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, NT, ATTRS, ABI_NAME) \
-    __GMP_DECLSPEC TYPE API_NAME ARGS NT __asm__(__GMP_STR(ABI_NAME)) ATTRS
+#  if defined(__GMP_WITHIN_GMP) && defined(HAVE_HIDDEN_ALIAS) && defined(PIC)
+#   define __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, NT, ATTRS, ABI_NAME) \
+	__GMP_DECLSPEC TYPE API_NAME ARGS NT				\
+	  __asm__("pub_" __GMP_STR(API_NAME))				\
+	  ATTRS __attribute__((visibility("hidden")))
+#   define __GMP_PUBLIC_DEFINE(API_NAME)				\
+	extern __typeof(API_NAME) __GMP_GLUE(ext_, API_NAME)		\
+	  __asm__(__GMP_STR(__GMP_GLUE(abi_, API_NAME)))		\
+	  __attribute__((alias ("pub_" __GMP_STR(API_NAME))));
+#  else
+#   define __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, NT, ATTRS, ABI_NAME) \
+     __GMP_DECLSPEC TYPE API_NAME ARGS NT __asm__(__GMP_STR(ABI_NAME)) ATTRS
+#   define __GMP_PUBLIC_DEFINE(API_NAME)
+#  endif
 #  define __GMP_PUBLIC_ALIAS_FULL(NEW_NAME, OLD_NAME, ABI_NAME) \
     __typeof(OLD_NAME) NEW_NAME __asm__(__GMP_STR(ABI_NAME));
 # else
 #  define __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, NT, ATTRS, ABI_NAME) \
     __GMP_DECLSPEC TYPE API_NAME ARGS NT ATTRS
 #  define __GMP_PUBLIC_ALIAS_FULL(NEW_NAME, OLD_NAME, ABI_NAME)
+#  define __GMP_PUBLIC_DEFINE(API_NAME)
 # endif
 #endif
 
diff --git a/gmp-impl.h b/gmp-impl.h
index 2f5d75e..1c1451d 100644
--- a/gmp-impl.h
+++ b/gmp-impl.h
@@ -113,11 +113,24 @@ along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
 
 #if !defined(__GMP_WITHIN_CONFIGURE) || !defined(__GMP_INTERN_FULL)
 # ifdef __GNUC__
-#  define __GMP_INTERN_FULL(TYPE, API_NAME, ARGS, NT, ATTRS, ABI_NAME) \
-    __GMP_DECLSPEC TYPE API_NAME ARGS NT __asm__(__GMP_STR(ABI_NAME)) ATTRS
+#  if defined(__GMP_WITHIN_GMP) && defined(HAVE_HIDDEN_ALIAS) && defined(PIC)
+#   define __GMP_INTERN_FULL(TYPE, API_NAME, ARGS, NT, ATTRS, ABI_NAME) \
+	__GMP_DECLSPEC TYPE API_NAME ARGS NT				\
+	  __asm__("int_" __GMP_STR(API_NAME))				\
+	  ATTRS __attribute__((visibility("hidden")))
+#   define __GMP_INTERN_DEFINE(API_NAME)				\
+	extern __typeof(API_NAME) __GMP_GLUE(ext_,API_NAME)		\
+	  __asm__(__GMP_STR(__GMP_GLUE(abi_, API_NAME)))		\
+	  __attribute__((alias ("int_" __GMP_STR(API_NAME))));
+#  else
+#   define __GMP_INTERN_FULL(TYPE, API_NAME, ARGS, NT, ATTRS, ABI_NAME) \
+     __GMP_DECLSPEC TYPE API_NAME ARGS NT __asm__(__GMP_STR(ABI_NAME)) ATTRS
+#   define __GMP_INTERN_DEFINE(API_NAME)
+#  endif
 # else
 #  define __GMP_INTERN_FULL(TYPE, API_NAME, ARGS, NT, ATTRS, ABI_NAME) \
     __GMP_DECLSPEC TYPE API_NAME ARGS NT ATTRS
+#   define __GMP_INTERN_DEFINE(API_NAME)
 # endif
 #endif
 
@@ -136,7 +149,7 @@ along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
   __GMP_INTERN_FULL(extern TYPE, API_NAME, , , ,			\
 		    __GMP_GLUE(__GMP_ABI_PREFIX, API_NAME))
 
-#if !defined(__GMP_WITHIN_CONFIGURE) && !defined(__GNUC__)
+#if !defined(__GMP_WITHIN_CONFIGURE)
 # include "gmp-renamei.h"
 #endif
 
-- 
1.8.1.2



More information about the gmp-devel mailing list