Path: blob/main/libexec/rtld-elf/tests/rtld_deepbind/rtld_deepbind.c
34927 views
/*-1*2* Copyright (C) 2023 NetApp, Inc.3*4* SPDX-License-Identifier: BSD-2-Clause5*6*/78#include <dlfcn.h>910#include <atf-c.h>1112int get_value(void);13void set_value(int);1415#define APP_VALUE 516#define LIB_VALUE 201718ATF_TC_WITHOUT_HEAD(deepbind_simple);19ATF_TC_BODY(deepbind_simple, tc)20{21void *hdl;22void (*proxy_set_value)(int);23int (*proxy_get_value)(void);24int app_value, lib_value;2526set_value(APP_VALUE);2728/*29* libdeep has a dependency on libval2.so, which is a rebuild of30* libval.so that provides get_value() and set_value() for both us and31* the lib. The lib's get_value() and set_value() should bind to the32* versions in libval2 instead of libval with RTLD_DEEPBIND.33*/34hdl = dlopen("$ORIGIN/libdeep.so", RTLD_LAZY | RTLD_DEEPBIND);35ATF_REQUIRE(hdl != NULL);3637proxy_set_value = dlsym(hdl, "proxy_set_value");38ATF_REQUIRE(proxy_set_value != NULL);3940proxy_get_value = dlsym(hdl, "proxy_get_value");41ATF_REQUIRE(proxy_get_value != NULL);4243(*proxy_set_value)(LIB_VALUE);4445lib_value = (*proxy_get_value)();46app_value = get_value();4748/*49* In the initial implementation or if libdeep.so is *not* linked50* against its own libval2, then these both return the later set51* LIB_VALUE (20) as they bind to the symbol provided by libval and52* use its .bss val.53*/54ATF_REQUIRE_INTEQ(lib_value, LIB_VALUE);55ATF_REQUIRE_INTEQ(app_value, APP_VALUE);56}5758ATF_TP_ADD_TCS(tp)59{6061ATF_TP_ADD_TC(tp, deepbind_simple);6263return atf_no_error();64}656667