40 lines
1.4 KiB
C++
40 lines
1.4 KiB
C++
// E2E: host-libc delegation — symbols from both libc.so.6 (strlen) and libm.so.6 (sqrt).
|
|
// Verifies that multi-DT_NEEDED ELF synthesis resolves symbols across two libraries.
|
|
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <dlfcn.h>
|
|
|
|
#ifndef VOIDLIBC_TEST_VLC_PATH
|
|
#error "VOIDLIBC_TEST_VLC_PATH must be set by CMake"
|
|
#endif
|
|
|
|
#define REQUIRE(cond) do { \
|
|
if (!(cond)) { \
|
|
std::fprintf(stderr, "FAIL: %s (line %d)\n", #cond, \
|
|
__LINE__); \
|
|
const char* le = ::dlerror(); \
|
|
if (le) std::fprintf(stderr, " dlerror: %s\n", le); \
|
|
std::exit(1); \
|
|
} \
|
|
} while (0)
|
|
|
|
int main() {
|
|
void* h = ::dlopen(VOIDLIBC_TEST_VLC_PATH, RTLD_NOW);
|
|
REQUIRE(h != nullptr);
|
|
|
|
using fn_t = int (*)();
|
|
auto* fn = reinterpret_cast<fn_t>(::dlsym(h, "multi_libc_test"));
|
|
REQUIRE(fn != nullptr);
|
|
|
|
const int result = fn();
|
|
if (result != 0) {
|
|
std::fprintf(stderr, "FAIL: multi_libc_test() = %d (expected 0)\n", result);
|
|
std::exit(1);
|
|
}
|
|
|
|
REQUIRE(::dlclose(h) == 0);
|
|
std::printf("PASS: e2e_host_libc_multi — strlen(libc) + sqrt(libm) resolved\n");
|
|
return 0;
|
|
}
|