From c7a5d780ae58b6f7ae7d814fd5bc53cf1f58ee5f Mon Sep 17 00:00:00 2001 From: Alexander Miller Date: Thu, 30 Sep 2021 03:39:57 +0200 Subject: [PATCH] build: Allow building with -flto on gcc-10 and newer Global asm statements (like .symver directives) do not work reliably in gcc with link time optimization. Use the symver attribute introduced with gcc-10 to set symbol versions instead, if available. [guillem@hadrons.org: - Simplify by using __has_attribute fallback from . - Coding style changes. ] Signed-off-by: Guillem Jover --- src/local-link.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/local-link.h b/src/local-link.h index 55fd028..fd1949c 100644 --- a/src/local-link.h +++ b/src/local-link.h @@ -27,16 +27,28 @@ #ifndef LIBBSD_LOCAL_LINK_H #define LIBBSD_LOCAL_LINK_H +#include + #define libbsd_link_warning(symbol, msg) \ static const char libbsd_emit_link_warning_##symbol[] \ __attribute__((__used__,__section__(".gnu.warning." #symbol))) = msg #ifdef __ELF__ +# if __has_attribute(symver) +/* The symver attribute is supported since gcc 10.x. */ +#define libbsd_symver_default(alias, symbol, version) \ + extern __typeof(symbol) symbol \ + __attribute((__symver__(#alias "@@" #version))) +#define libbsd_symver_variant(alias, symbol, version) \ + extern __typeof(symbol) symbol \ + __attribute((__symver__(#alias "@" #version))) +# else #define libbsd_symver_default(alias, symbol, version) \ __asm__(".symver " #symbol "," #alias "@@" #version) #define libbsd_symver_variant(alias, symbol, version) \ __asm__(".symver " #symbol "," #alias "@" #version) +# endif #else #define libbsd_symver_default(alias, symbol, version) \ extern __typeof(symbol) alias __attribute__((__alias__(#symbol)))