Created
January 30, 2020 03:05
-
-
Save pczarn/ecee491533a19b0a4ef4f43785f8badc to your computer and use it in GitHub Desktop.
weak and strong symbols
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 characters
clang -Wall -fPIC -c ctest1.c ctest2.c | |
clang -shared -Wl,-soname,libctest.so.1.0 -o libctest.so.1.0 *.o | |
clang -fPIC prog.c -Wl,-rpath,. libctest.so.1.0 -o prog1 | |
./prog1 > result1 | |
clang prog.c ctest*.c -o prog2 | |
./prog2 > result2 |
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 characters
void ctest1(char **s) | |
{ | |
*s = "from first"; | |
} |
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 characters
void ctest2(char **s) | |
{ | |
*s = "from second"; | |
} |
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 characters
#include <stdio.h> | |
__attribute((weak)) void ctest1(char** s) { | |
*s = "from weak"; | |
} | |
void ctest2(char**); | |
int main() | |
{ | |
char *x; | |
ctest1(&x); | |
printf("result=%s\n",x); | |
ctest2(&x); | |
printf("result=%s\n",x); | |
return 0; | |
} |
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 characters
result=from weak | |
result=from second |
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 characters
result=from first | |
result=from second |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment