Created
September 10, 2023 02:36
-
-
Save fzakaria/afefef95c4d6eb8235d538b7b57dc2c3 to your computer and use it in GitHub Desktop.
Order of linked libraries can affect symbol resolution
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> | |
void f(); | |
void a() { | |
puts("liba.so: hello world"); | |
f(); | |
} |
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> | |
void f() { puts("libaltf.so: goodbye world"); } |
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> | |
void f(); | |
void b() { | |
puts("libb.so: hello world"); | |
f(); | |
} |
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 a(); | |
void b(); | |
int main() { | |
a(); | |
b(); | |
} |
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> | |
void f() { puts("libf.so: hello world"); } |
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
example: example.c liba.so libb.so | |
gcc -o example -lb -la -laltf -lf -x c -L. example.c | |
libf.so: f.c | |
gcc -shared -o libf.so -x c f.c | |
libaltf.so: alternative-f.c | |
gcc -shared -o libaltf.so -x c alternative-f.c | |
liba.so: a.c libf.so | |
gcc -shared -o liba.so -L. -lf -x c a.c | |
libb.so: b.c libaltf.so | |
gcc -shared -o libb.so -L. -laltf -x c b.c | |
clean: | |
rm -f *.so example | |
.PHONY: clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment