Ryan Prichard | 058eb8f | 2020-12-17 22:59:04 -0800 | [diff] [blame] | 1 | #include <dlfcn.h> |
| 2 | #include <stdio.h> |
| 3 | |
| 4 | // Mark foo and bar weak so that Clang allows the run-time linker to decide which DSO's symbol to |
| 5 | // use. |
| 6 | |
| 7 | __attribute__((weak)) extern "C" void foo() { |
| 8 | printf("foo lib1\n"); |
| 9 | void (*next)(void) = reinterpret_cast<void (*)()>(dlsym(RTLD_NEXT, "foo")); |
| 10 | if (next != nullptr) next(); |
| 11 | } |
| 12 | |
| 13 | __attribute__((weak)) extern "C" void bar(); |
| 14 | |
| 15 | void lib1_call_funcs() { |
| 16 | printf("lib1_call_funcs\n"); |
| 17 | foo(); |
| 18 | bar(); |
Jiyong Park | 02586a2 | 2017-05-20 01:01:24 +0900 | [diff] [blame] | 19 | } |