Test if the target supports the visibility attribute and apply it to
internal functions.

libga68/ChangeLog:

        * acinclude.m4: New file. Add visibility attribute test.
        * configure.ac: Use the new test.
        * Makefile.in: Regenerate.
        * aclocal.m4: Likewise.
        * config.h.in: Likewise.
        * configure: Likewise.
        * ga68.h (GA68_HIDDEN): New macro.
        (_libga68_abort): Add visibility hidden attribute.
        (_libga68_init_heap): Likewise.
        (_libga68_malloc_internal): Likewise.
        (_libga68_realloc): Likewise.
        (_libga68_realloc_unchecked): Likewise.
        (_libga68_free_internal): Likewise.
        (_libga68_u8_uctomb): Likewise.
        (_libga68_u8_mbtouc): Likewise.
        (_libga68_u32_to_u8): Likewise.

Signed-off-by: Pietro Monteiro <[email protected]>
---
 libga68/Makefile.in  |  3 ++-
 libga68/acinclude.m4 | 14 ++++++++++++++
 libga68/aclocal.m4   |  1 +
 libga68/config.h.in  |  3 +++
 libga68/configure    | 37 +++++++++++++++++++++++++++++++++++++
 libga68/configure.ac |  3 +++
 libga68/ga68.h       | 23 +++++++++++++++--------
 7 files changed, 75 insertions(+), 9 deletions(-)
 create mode 100644 libga68/acinclude.m4

diff --git a/libga68/Makefile.in b/libga68/Makefile.in
index 7f4fd870192..0e90927e707 100644
--- a/libga68/Makefile.in
+++ b/libga68/Makefile.in
@@ -127,7 +127,8 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
        $(top_srcdir)/../config/override.m4 \
        $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
        $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
-       $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac
+       $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \
+       $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
        $(ACLOCAL_M4)
 DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \
diff --git a/libga68/acinclude.m4 b/libga68/acinclude.m4
new file mode 100644
index 00000000000..54ada357a68
--- /dev/null
+++ b/libga68/acinclude.m4
@@ -0,0 +1,14 @@
+dnl Check whether the target supports hidden visibility.
+AC_DEFUN([LIBGA68_CHECK_ATTRIBUTE_VISIBILITY], [
+  AC_CACHE_CHECK([whether the target supports hidden visibility],
+                libga68_cv_have_attribute_visibility, [
+  save_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -Werror"
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[void 
__attribute__((visibility("hidden"))) foo(void) { }]], [])],
+                   [libga68_cv_have_attribute_visibility=yes],
+                   [libga68_cv_have_attribute_visibility=no])
+  CFLAGS="$save_CFLAGS"])
+  if test $libga68_cv_have_attribute_visibility = yes; then
+    AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY, 1,
+      [Define to 1 if the target supports __attribute__((visibility(...))).])
+  fi])
diff --git a/libga68/aclocal.m4 b/libga68/aclocal.m4
index 21d6365e326..830fb238bbe 100644
--- a/libga68/aclocal.m4
+++ b/libga68/aclocal.m4
@@ -1201,3 +1201,4 @@ m4_include([../ltoptions.m4])
 m4_include([../ltsugar.m4])
 m4_include([../ltversion.m4])
 m4_include([../lt~obsolete.m4])
+m4_include([acinclude.m4])
diff --git a/libga68/config.h.in b/libga68/config.h.in
index b4e941a2bf7..1ba191b9772 100644
--- a/libga68/config.h.in
+++ b/libga68/config.h.in
@@ -1,5 +1,8 @@
 /* config.h.in.  Generated from configure.ac by autoheader.  */
 
+/* Define to 1 if the target supports __attribute__((visibility(...))). */
+#undef HAVE_ATTRIBUTE_VISIBILITY
+
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #undef HAVE_DLFCN_H
 
diff --git a/libga68/configure b/libga68/configure
index 705694a1891..2ccd04ab940 100755
--- a/libga68/configure
+++ b/libga68/configure
@@ -12991,6 +12991,43 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 CC_FOR_BUILD=${CC_FOR_BUILD:-gcc}
 
 
+# Check whether the target supports hidden visibility.
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the target 
supports hidden visibility" >&5
+$as_echo_n "checking whether the target supports hidden visibility... " >&6; }
+if ${libga68_cv_have_attribute_visibility+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+  save_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -Werror"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+void __attribute__((visibility("hidden"))) foo(void) { }
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  libga68_cv_have_attribute_visibility=yes
+else
+  libga68_cv_have_attribute_visibility=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  CFLAGS="$save_CFLAGS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: 
$libga68_cv_have_attribute_visibility" >&5
+$as_echo "$libga68_cv_have_attribute_visibility" >&6; }
+  if test $libga68_cv_have_attribute_visibility = yes; then
+
+$as_echo "#define HAVE_ATTRIBUTE_VISIBILITY 1" >>confdefs.h
+
+  fi
+
 # Search for needed functions in host libraries.
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing 
malloc" >&5
 $as_echo_n "checking for library containing malloc... " >&6; }
diff --git a/libga68/configure.ac b/libga68/configure.ac
index 5ff5e124f8f..1d8a4a95e79 100644
--- a/libga68/configure.ac
+++ b/libga68/configure.ac
@@ -169,6 +169,9 @@ AC_LANG([C])
 CC_FOR_BUILD=${CC_FOR_BUILD:-gcc}
 AC_SUBST(CC_FOR_BUILD)
 
+# Check whether the target supports hidden visibility.
+LIBGA68_CHECK_ATTRIBUTE_VISIBILITY
+
 # Search for needed functions in host libraries.
 AC_SEARCH_LIBS([malloc], [c])
 AC_SEARCH_LIBS([cosf], [m])
diff --git a/libga68/ga68.h b/libga68/ga68.h
index ed8b71fce79..18f3a563112 100644
--- a/libga68/ga68.h
+++ b/libga68/ga68.h
@@ -33,9 +33,16 @@
 # endif
 #endif
 
+#ifdef HAVE_ATTRIBUTE_VISIBILITY
+# define GA68_HIDDEN __attribute__ ((__visibility__ ("hidden")))
+#else
+# define GA68_HIDDEN
+#endif
+
 /* ga68-error.c  */
 
 void _libga68_abort (const char *fmt, ...)
+  GA68_HIDDEN
   __attribute__ ((__format__ (__printf__, 1, 2), __nonnull__ (1),
                  __noreturn__));
 
@@ -61,12 +68,12 @@ void _libga68_bounds_mismatch (const char *filename, 
unsigned int lineno,
 
 /* ga68-alloc.c  */
 
-void _libga68_init_heap (void);
+void _libga68_init_heap (void) GA68_HIDDEN;
 void *_libga68_malloc (size_t size);
-void *_libga68_malloc_internal (size_t size);
-void *_libga68_realloc (void *ptr, size_t size);
-void *_libga68_realloc_unchecked (void *ptr, size_t size);
-void _libga68_free_internal (void *ptr);
+void *_libga68_malloc_internal (size_t size) GA68_HIDDEN;
+void *_libga68_realloc (void *ptr, size_t size) GA68_HIDDEN;
+void *_libga68_realloc_unchecked (void *ptr, size_t size) GA68_HIDDEN;
+void _libga68_free_internal (void *ptr) GA68_HIDDEN;
 
 /* ga68-standenv.c  */
 
@@ -106,10 +113,10 @@ long long int _libga68_posixlseek (int fd, long long int 
offset, int whence);
 
 int _libga68_u32_cmp2 (const uint32_t *s1, size_t n1, size_t stride1,
                       const uint32_t *s2, size_t n2, size_t stride2);
-int _libga68_u8_uctomb (uint8_t *s, uint32_t uc, ptrdiff_t n);
-int _libga68_u8_mbtouc (uint32_t *puc, const uint8_t *s, size_t n);
+int _libga68_u8_uctomb (uint8_t *s, uint32_t uc, ptrdiff_t n) GA68_HIDDEN;
+int _libga68_u8_mbtouc (uint32_t *puc, const uint8_t *s, size_t n) GA68_HIDDEN;
 uint8_t *_libga68_u32_to_u8 (const uint32_t *s, size_t n, size_t stride,
-                            uint8_t *resultbuf, size_t *lengthp);
+                            uint8_t *resultbuf, size_t *lengthp) GA68_HIDDEN;
 uint32_t *_libga68_u8_to_u32 (const uint8_t *s, size_t n,
                              uint32_t *resultbuf, size_t *lengthp);
 

base-commit: 7274c781e8e0ad113c4a16427b83f7e8b8107c70
-- 
2.43.0

Reply via email to