Skip to content

Commit

Permalink
On Darwin use assembler to support symbol aliases
Browse files Browse the repository at this point in the history
The alias attribute is not supported on Darwin, but we can alias using
assembler directives instead.

At the same time we switch the non-ELF fallback implementation for
libmd_symver_default to use libmd_alias.
  • Loading branch information
guillemj committed Apr 1, 2023
1 parent b74b777 commit ed69599
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/local-link.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,20 @@
* is too cumbersome, as it does not work when static linking, and when
* dynamic linking it does not make the aliases visible within the DLL itself.
*
* On macOS we cannot use proper strong aliases.
* On macOS we need to use an assembler alias as it does not support
* the alias attribute.
*
* Instead we use normal function wrapper in those cases, which are way more
* maintainable.
*/
#if !defined(_MSC_VER) && !defined(__APPLE__)
#if defined(__APPLE__)
#define libmd_alias(alias, symbol) \
extern __typeof(symbol) alias __attribute__((__alias__(#symbol)))
__asm__(".globl _" #alias); \
__asm__(".set _" #alias ", _" #symbol); \
extern __typeof__(symbol) alias
#elif !defined(_MSC_VER)
#define libmd_alias(alias, symbol) \
extern __typeof__(symbol) alias __attribute__((__alias__(#symbol)))
#endif

#ifdef __ELF__
Expand All @@ -54,7 +60,7 @@
__asm__(".symver " #symbol "," #alias "@" #version)
#else
#define libmd_symver_default(alias, symbol, version) \
extern __typeof(symbol) alias __attribute__((__alias__(#symbol)))
libmd_alias(alias, symbol)

#define libmd_symver_variant(alias, symbol, version)
#endif
Expand Down

0 comments on commit ed69599

Please sign in to comment.