commit
bba5c8a39a
109 files changed
+14085
No files matched your search
@@ -0,0 +1,55 @@
|
||||
// E2E: multi-object merge. math_a.o (add, square) and math_b.o
|
||||
// (add_and_double, sum_of_squares — calling into math_a) are merged into a
|
||||
// single .vlc. Tests that cross-object PLT32 relocs are resolved as direct
|
||||
// PC32 calls (no PLT stub for internally-defined symbols).
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#ifndef VOIDLIBC_TEST_VLC_PATH
|
||||
#error "VOIDLIBC_TEST_VLC_PATH must be set by CMake"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
#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 run() {
|
||||
void* h = ::dlopen(VOIDLIBC_TEST_VLC_PATH, RTLD_NOW);
|
||||
REQUIRE(h != nullptr);
|
||||
|
||||
using int2_fn = int (*)(int, int);
|
||||
using int1_fn = int (*)(int);
|
||||
|
||||
auto* add = reinterpret_cast<int2_fn>(::dlsym(h, "add"));
|
||||
auto* square = reinterpret_cast<int1_fn>(::dlsym(h, "square"));
|
||||
auto* add_and_double = reinterpret_cast<int2_fn>(::dlsym(h, "add_and_double"));
|
||||
auto* sum_of_squares = reinterpret_cast<int2_fn>(::dlsym(h, "sum_of_squares"));
|
||||
|
||||
REQUIRE(add != nullptr);
|
||||
REQUIRE(square != nullptr);
|
||||
REQUIRE(add_and_double != nullptr);
|
||||
REQUIRE(sum_of_squares != nullptr);
|
||||
|
||||
REQUIRE(add(3, 4) == 7);
|
||||
REQUIRE(square(5) == 25);
|
||||
REQUIRE(add_and_double(3, 4) == 14); // (3+4)*2
|
||||
REQUIRE(sum_of_squares(3, 4) == 25); // 9+16
|
||||
|
||||
REQUIRE(::dlclose(h) == 0);
|
||||
std::printf("PASS: e2e_load_multi_obj — multi-object merge + cross-object call\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() { return run(); }
|
||||
Reference in new issue
Block a user