summaryrefslogtreecommitdiff
path: root/tests/libs/ld_config_test_helper_lib1.cpp
blob: ffa9a457f9a5ae009d188ebe9cbd3fa3ba08f792 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <dlfcn.h>
#include <stdio.h>

// Mark foo and bar weak so that Clang allows the run-time linker to decide which DSO's symbol to
// use.

__attribute__((weak)) extern "C" void foo() {
  printf("foo lib1\n");
  void (*next)(void) = reinterpret_cast<void (*)()>(dlsym(RTLD_NEXT, "foo"));
  if (next != nullptr) next();
}

__attribute__((weak)) extern "C" void bar();

void lib1_call_funcs() {
  printf("lib1_call_funcs\n");
  foo();
  bar();
}