Skip to content

Instantly share code, notes, and snippets.

@michaeljclark
Last active August 1, 2018 15:24
Show Gist options
  • Save michaeljclark/a0b0e8039884a581e788e027a5e93185 to your computer and use it in GitHub Desktop.
Save michaeljclark/a0b0e8039884a581e788e027a5e93185 to your computer and use it in GitHub Desktop.
emulating indirect weak aliases with strong direct aliases for Mach-O
#include <stdio.h>
#if HAVE_ALIASES
#define weak_alias(old, new) \
extern __typeof(old) new __attribute__((weak, alias(#old)))
#else
#define weak_alias(old, new) \
__asm__(".globl _" #new); \
__asm__("_" #new " = _" #old); \
extern __typeof(old) new __attribute__((weak_import))
#endif
void __foo()
{
printf("foo\n");
}
weak_alias(__foo, foo);
int main()
{
foo();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment