Skip to content

Commit

Permalink
lib/crypt-port.h: Add bits for compiling with link-time optimization.
Browse files Browse the repository at this point in the history
GCC 10 and LLVM/Clang 10 offer initial support for building libraries,
that are using symbol versioning features, with LTO.

To make use of this with GCC 10, the exported versioned symbols need
to be declared explicitly with __attribute__((symver (...))).

LLVM/Clang 10 supports symbol versioning with LTO out of the box
without any changes needed.

Fixes #24.
  • Loading branch information
besser82 committed Mar 31, 2021
1 parent 6d98870 commit 089295d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/crypt-port.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,29 @@ extern size_t strcpy_or_abort (void *dst, size_t d_size, const void *src);
# define _strong_alias(name, aliasname) \
extern __typeof (name) aliasname __THROW __attribute__ ((alias (#name)))

/* Starting with GCC 10, we can use the symver attribute, which also works
with link-time optimization enabled. */
# if __GNUC__ >= 10

/* Set the symbol version for EXTNAME, which uses INTNAME as its
implementation. */
# define symver_set(extstr, intname, version, mode) \
extern __typeof (intname) intname __THROW \
__attribute__((symver (extstr mode #version)))

/* Referencing specific _compatibility_ symbols still needs inline asm. */
# define _symver_ref(extstr, intname, version) \
__asm__ (".symver " #intname "," extstr "@" #version)

# else

/* Set the symbol version for EXTNAME, which uses INTNAME as its
implementation. */
# define symver_set(extstr, intname, version, mode) \
__asm__ (".symver " #intname "," extstr mode #version)

# endif

#else
# error "Don't know how to do symbol versioning with this compiler"
#endif
Expand Down Expand Up @@ -267,9 +285,14 @@ extern size_t strcpy_or_abort (void *dst, size_t d_size, const void *src);

/* Tests may need to _refer_ to compatibility symbols, but should never need
to _define_ them. */

#define symver_ref(extstr, intname, version) \
_symver_ref(extstr, intname, version)

/* Generic way for referencing specific _compatibility_ symbols. */
#ifndef _symver_ref
#define _symver_ref(extstr, intname, version) \
symver_set(extstr, intname, version, "@")
#endif

/* Define configuration macros used during compile-time by the
GOST R 34.11-2012 "Streebog" hash function. */
Expand Down

0 comments on commit 089295d

Please sign in to comment.