Skip to content

Commit

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

To make use of this, the exported versioned symbols need their
visibility attributes declared explicitly.

Fixes #24.
  • Loading branch information
besser82 committed Aug 13, 2020
1 parent e9a6b2d commit 1b1baee
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/crypt-des-obsolete.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ do_setkey_r (const char *key, struct des_ctx *ctx)
#endif

#if INCLUDE_setkey_r
xcrypt_symbol
void
setkey_r (ARG_UNUSED (const char *key), ARG_UNUSED (struct crypt_data *data))
{
Expand Down Expand Up @@ -148,6 +149,7 @@ do_encrypt_r (char *block, int edflag, struct des_ctx *ctx)
#endif

#if INCLUDE_encrypt_r
xcrypt_symbol
void
encrypt_r (char *block, ARG_UNUSED (int edflag),
ARG_UNUSED (struct crypt_data *data))
Expand Down Expand Up @@ -180,6 +182,7 @@ static struct des_ctx nr_encrypt_ctx;
#endif

#if INCLUDE_setkey
xcrypt_symbol
void
setkey (ARG_UNUSED (const char *key))
{
Expand All @@ -194,6 +197,7 @@ SYMVER_setkey;
#endif

#if INCLUDE_encrypt
xcrypt_symbol
void
encrypt (char *block, ARG_UNUSED (int edflag))
{
Expand Down
2 changes: 2 additions & 0 deletions lib/crypt-gensalt-static.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
will not have the state objects in its data segment. */

#if INCLUDE_crypt_gensalt
xcrypt_symbol
char *
crypt_gensalt (const char *prefix, unsigned long count,
const char *rbytes, int nrbytes)
Expand All @@ -36,6 +37,7 @@ SYMVER_crypt_gensalt;

/* For code compatibility with older versions (v3.1.1 and earlier). */
#if INCLUDE_crypt_gensalt && INCLUDE_xcrypt_gensalt
xcrypt_symbol
strong_alias (crypt_gensalt, xcrypt_gensalt);
SYMVER_xcrypt_gensalt;
#endif
16 changes: 16 additions & 0 deletions lib/crypt-port.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ _crypt_strcpy_or_abort (void *, const size_t, const void *);
/* Define ALIASNAME as a strong alias for NAME. */
#define strong_alias(name, aliasname) _strong_alias(name, aliasname)

/* Define a symbol to be external visible. */
#if (defined __GNUC__ && __GNUC__ >= 5) && !defined __clang__

# define xcrypt_symbol \
__attribute__((visibility("default"), externally_visible))

#elif defined __GNUC__ && __GNUC__ >= 3

# define xcrypt_symbol \
__attribute__((visibility("default")))

#else

# define xcrypt_symbol

#endif
/* Darwin (Mach-O) doesn't support alias attributes or symbol versioning.
It does, however, support symbol aliasing at the object file level. */
#ifdef __APPLE__
Expand Down
4 changes: 4 additions & 0 deletions lib/crypt-static.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
will not have the state objects in its data segment. */

#if INCLUDE_crypt || INCLUDE_fcrypt
xcrypt_symbol
char *
crypt (const char *key, const char *setting)
{
Expand All @@ -38,6 +39,7 @@ SYMVER_crypt;

#if INCLUDE_fcrypt
#if ENABLE_OBSOLETE_API_ENOSYS
xcrypt_symbol
char *
fcrypt (ARG_UNUSED (const char *key), ARG_UNUSED (const char *setting))
{
Expand All @@ -54,13 +56,15 @@ fcrypt (ARG_UNUSED (const char *key), ARG_UNUSED (const char *setting))
#endif
}
#else
xcrypt_symbol
strong_alias (crypt, fcrypt);
#endif
SYMVER_fcrypt;
#endif

/* For code compatibility with older versions (v3.1.1 and earlier). */
#if INCLUDE_crypt && INCLUDE_xcrypt
xcrypt_symbol
strong_alias (crypt, xcrypt);
SYMVER_xcrypt;
#endif
10 changes: 10 additions & 0 deletions lib/crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ do_crypt (const char *phrase, const char *setting, struct crypt_data *data)
}

#if INCLUDE_crypt_rn
xcrypt_symbol
char *
crypt_rn (const char *phrase, const char *setting, void *data, int size)
{
Expand All @@ -163,6 +164,7 @@ SYMVER_crypt_rn;
#endif

#if INCLUDE_crypt_ra
xcrypt_symbol
char *
crypt_ra (const char *phrase, const char *setting, void **data, int *size)
{
Expand Down Expand Up @@ -191,6 +193,7 @@ SYMVER_crypt_ra;
#endif

#if INCLUDE_crypt_r
xcrypt_symbol
char *
crypt_r (const char *phrase, const char *setting, struct crypt_data *data)
{
Expand All @@ -207,11 +210,13 @@ SYMVER_crypt_r;

/* For code compatibility with older versions (v3.1.1 and earlier). */
#if INCLUDE_crypt_r && INCLUDE_xcrypt_r
xcrypt_symbol
strong_alias (crypt_r, xcrypt_r);
SYMVER_xcrypt_r;
#endif

#if INCLUDE_crypt_gensalt_rn
xcrypt_symbol
char *
crypt_gensalt_rn (const char *prefix, unsigned long count,
const char *rbytes, int nrbytes, char *output,
Expand Down Expand Up @@ -279,17 +284,20 @@ SYMVER_crypt_gensalt_rn;

/* For code compatibility with older versions (v3.1.1 and earlier). */
#if INCLUDE_crypt_gensalt_rn && INCLUDE_crypt_gensalt_r
xcrypt_symbol
strong_alias (crypt_gensalt_rn, crypt_gensalt_r);
SYMVER_crypt_gensalt_r;
#endif

/* For code compatibility with older versions (v3.1.1 and earlier). */
#if INCLUDE_crypt_gensalt_rn && INCLUDE_xcrypt_gensalt_r
xcrypt_symbol
strong_alias (crypt_gensalt_rn, xcrypt_gensalt_r);
SYMVER_xcrypt_gensalt_r;
#endif

#if INCLUDE_crypt_gensalt_ra
xcrypt_symbol
char *
crypt_gensalt_ra (const char *prefix, unsigned long count,
const char *rbytes, int nrbytes)
Expand All @@ -310,6 +318,7 @@ SYMVER_crypt_gensalt_ra;
#if INCLUDE_crypt_checksalt
static_assert(CRYPT_SALT_OK == 0, "CRYPT_SALT_OK does not equal zero");

xcrypt_symbol
int
crypt_checksalt (const char *setting)
{
Expand All @@ -329,6 +338,7 @@ SYMVER_crypt_checksalt;
#endif

#if INCLUDE_crypt_preferred_method
xcrypt_symbol
const char *
crypt_preferred_method (void)
{
Expand Down

0 comments on commit 1b1baee

Please sign in to comment.