]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Check if gcc complains about __attribute__ (visibility(..))
authorUlf Hermann <ulf.hermann@qt.io>
Fri, 18 Aug 2017 11:06:36 +0000 (13:06 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 18 Aug 2017 20:32:44 +0000 (22:32 +0200)
If so, define attribute_hidden to be empty. Also, use attribute_hidden
in all places where we hide symbols. If this attribute is missing, it
simply means that we cannot hide private symbols in the binary using
attributes. This disables some optimizations and may increase the risk
of symbol name clashes with other libraries, but is not fatal.

However, we still employ linker version scripts to explicitly define
the exported symbols. This serves much of the same purpose. Also, as
all our symbols are prefixed with the library name, and "__" for
private ones, the chance of clashes is low anyway.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
ChangeLog
configure.ac
lib/ChangeLog
lib/eu-config.h
libdw/ChangeLog
libdw/libdwP.h
libdw/libdw_alloc.c
libelf/ChangeLog
libelf/libelfP.h

index 621462270006d98a586a27e0fce42dcf4ed4fe1f..84fd2555a601f9f7089a4bc1bb65b831bd201411 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-04-27  Ulf Hermann  <ulf.hermann@qt.io>
+
+       * configure.ac: Check if the compiler supports
+       __attribute__((visibility(...))).
+
 2017-04-27  Ulf Hermann  <ulf.hermann@qt.io>
 
        * configure.ac: Check if -fPIC, -fPIE, -Wl,-z,defs,
index e6e3b6751bd11a92b593f4387e9d584dde7d1882..c4fc7e3d7c588f0c7a21a008d7761b7ebfeb55c3 100644 (file)
@@ -127,6 +127,22 @@ CFLAGS="$old_CFLAGS"])
 AS_IF([test "x$ac_cv_c99" != xyes],
       AC_MSG_ERROR([gcc with GNU99 support required]))
 
+AC_CACHE_CHECK([whether gcc supports __attribute__((visibility()))],
+       ac_cv_visibility, [dnl
+save_CFLAGS="$CFLAGS"
+CFLAGS="$save_CFLAGS -Werror"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl
+int __attribute__((visibility("hidden")))
+foo (int a)
+{
+  return a;
+}])], ac_cv_visibility=yes, ac_cv_visibility=no)
+CFLAGS="$save_CFLAGS"])
+if test "$ac_cv_visibility" = "yes"; then
+       AC_DEFINE([HAVE_VISIBILITY], [1],
+                 [Defined if __attribute__((visibility())) is supported])
+fi
+
 AC_CACHE_CHECK([whether gcc supports -fPIC], ac_cv_fpic, [dnl
 save_CFLAGS="$CFLAGS"
 CFLAGS="$save_CFLAGS -fPIC -Werror"
index 67ef2792408e94142eeb2c91155889121fb85b74..23c0f41b1749197874948860480f44fab007665a 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-27  Ulf Hermann  <ulf.hermann@qt.io>
+
+       * eu-config.h: Define attribute_hidden to be empty if the compiler
+       doesn't support it.
+
 2017-04-27  Ulf Hermann  <ulf.hermann@qt.io>
 
        * Makefile.am: Use fpic_CFLAGS.
index 400cdc6e77c227a9d1a5373a33e580ee54f843ae..070982828910926ece4ed0b5caecbeb8cc62d96a 100644 (file)
 #define internal_strong_alias(name, aliasname) \
   extern __typeof (name) aliasname __attribute__ ((alias (#name))) internal_function;
 
+#ifdef HAVE_VISIBILITY
 #define attribute_hidden \
   __attribute__ ((visibility ("hidden")))
+#else
+#define attribute_hidden /* empty */
+#endif
 
 /* Define ALLOW_UNALIGNED if the architecture allows operations on
    unaligned memory locations.  */
index 67d7799d2a1c736994d680146478e507d2b5b025..c13344af26f4d3c91a8bb1170f721226c72dd699 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-27  Ulf Hermann  <ulf.hermann@qt.io>
+
+       * libdwP.h: Use attribute_hidden.
+       * libdw_alloc.c: Likewise.
+
 2017-02-27  Ulf Hermann  <ulf.hermann@qt.io>
 
        * Makefile.am: Use fpic_CFLAGS and dso_LDFLAGS.
index 6ad322c1c530475932acba1ed910b5c33932d3f4..78c00132e745c1d978dfe61cfdff84e6a20d758f 100644 (file)
@@ -434,7 +434,7 @@ extern void *__libdw_allocate (Dwarf *dbg, size_t minsize, size_t align)
      __attribute__ ((__malloc__)) __nonnull_attribute__ (1);
 
 /* Default OOM handler.  */
-extern void __libdw_oom (void) __attribute ((noreturn, visibility ("hidden")));
+extern void __libdw_oom (void) __attribute ((noreturn)) attribute_hidden;
 
 /* Allocate the internal data for a unit not seen before.  */
 extern struct Dwarf_CU *__libdw_intern_next_unit (Dwarf *dbg, bool debug_types)
index 28a8cf6e44f2e200592aaa8f365e5dadcf47e9cc..d6af23a2a2acfd54774440c895d04b29c79c7f2e 100644 (file)
@@ -70,7 +70,7 @@ dwarf_new_oom_handler (Dwarf *dbg, Dwarf_OOM handler)
 
 
 void
-__attribute ((noreturn, visibility ("hidden")))
+__attribute ((noreturn)) attribute_hidden
 __libdw_oom (void)
 {
   while (1)
index a07364676d3617d29b59c1ecd79e86ce3781008a..9793d0684aac22ebd0581d4317b22a8fec0bfad6 100644 (file)
@@ -1,3 +1,7 @@
+2017-04-27  Ulf Hermann  <ulf.hermann@qt.io>
+
+       * libelfP.h: Use attribute_hidden.
+
 2017-04-27  Ulf Hermann  <ulf.hermann@qt.io>
 
        * Makefile.am: Use fpic_CFLAGS and dso_LDFLAGS.
index 7ee6625a45ae18c4b64985f919785bbe65397bcf..a4a0a3a9af5e73c33d330a36c7000b5a253a17f1 100644 (file)
@@ -578,7 +578,7 @@ extern Elf_Data *__elf64_xlatetof_internal (Elf_Data *__dest,
 extern unsigned int __elf_version_internal (unsigned int __version)
      attribute_hidden;
 extern unsigned long int __elf_hash_internal (const char *__string)
-       __attribute__ ((__pure__, visibility ("hidden")));
+       __attribute__ ((__pure__)) attribute_hidden;
 extern long int __elf32_checksum_internal (Elf *__elf) attribute_hidden;
 extern long int __elf64_checksum_internal (Elf *__elf) attribute_hidden;