This project demonstrate how the symbol interposition happens on Linux and how to prevent it by leveraging the -Wl,-Bsymbolic link option.
cmake -B build
cmake --build build
./build/main 0As you can see, bar() returns 0 but not 12346. It shows when bar() calls foo(), the definition of foo() comes from the definition in main.cc that returns -1 in main.cc, not the definition in foo.c from the library (libfoo.so) that returns 12345.
cmake -B build -DEXTRA_LINK_OPTIONS="-Wl,-Bsymbolic"
cmake --build build
./build/main 12346After adding the -Wl,-Bsymbolic link option, the local definition of foo() in libfoo.so will be found.