Skip to content

Instantly share code, notes, and snippets.

@cormacrelf
Last active October 27, 2021 11:54
Show Gist options
  • Save cormacrelf/11dcf1787fcc284ad69d28d5932e1928 to your computer and use it in GitHub Desktop.
Save cormacrelf/11dcf1787fcc284ad69d28d5932e1928 to your computer and use it in GitHub Desktop.
/*
env MACOSX_DEPLOYMENT_TARGET=10.7 clang -o test10.7 test.c
objdump -s test10.7
env MACOSX_DEPLOYMENT_TARGET=12.0 clang -o test12.0 test.c
objdump -s test12.0
clang -o testunspec test.c
# note the replacement
objdump -s testunspec
# note the replacement of __DATA,__mod_init_func with __TEXT,__init_offsets
*/
#include <stdio.h>
void myinit(int argc, char **argv, char **envp) {
printf("%s: %s\n", __FILE__, __FUNCTION__);
}
__attribute__((section("__DATA,__mod_init_func"))) typeof(myinit) *__init = myinit;
int main(int argc, char **argv, char **envp) {
/* the below __init doesn't link on macOS 12.0, with no deployment target env var set:
* ld: reference to symbol (which has not been assigned an address) ___init in '_main'
*/
__init(argc, argv, envp);
printf("%s: %s\n", __FILE__, __FUNCTION__);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment