blob: 94e15704d5a5071bc048065495c6badeb6de9993 [file] [log] [blame]
Ryan Prichard058eb8f2020-12-17 22:59:04 -08001#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 lib3\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 printf("bar lib3\n");
15 void (*next)(void) = reinterpret_cast<void (*)()>(dlsym(RTLD_NEXT, "bar"));
16 if (next != nullptr) next();
17}
18
19void lib3_call_funcs() {
20 printf("lib3_call_funcs\n");
21 foo();
22 bar();
Jiyong Park02586a22017-05-20 01:01:24 +090023}