Created
April 23, 2024 17:54
-
-
Save Cyberax/a60dce723d4e80a5d182d60677f1df98 to your computer and use it in GitHub Desktop.
Revisions
-
Cyberax created this gist
Apr 23, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ $ gcc -dynamiclib -o test.dyld file.c $ gcc trial.c $ ./a.out [file.c] [initializer1] [file.c] [initializer2] [file.c] [initializer3] [trial.c] [main] Finished loading. Now quitting. [file.c] [finalizer3] [file.c] [finalizer2] [file.c] [finalizer1] This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ #include <stdio.h> __attribute__((constructor)) static void initializer1() { printf("[%s] [%s]\n", __FILE__, __FUNCTION__); } __attribute__((constructor)) static void initializer2() { printf("[%s] [%s]\n", __FILE__, __FUNCTION__); } __attribute__((constructor)) static void initializer3() { printf("[%s] [%s]\n", __FILE__, __FUNCTION__); } __attribute__((destructor)) static void finalizer1() { printf("[%s] [%s]\n", __FILE__, __FUNCTION__); } __attribute__((destructor)) static void finalizer2() { printf("[%s] [%s]\n", __FILE__, __FUNCTION__); } __attribute__((destructor)) static void finalizer3() { printf("[%s] [%s]\n", __FILE__, __FUNCTION__); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ #include <stdio.h> #include <dlfcn.h> int main(int argc, char** argv) { void *lib = dlopen("./test.dyld", RTLD_LAZY); printf("[%s] [%s] Finished loading. Now quitting.\n", __FILE__, __FUNCTION__); return 0; }