【发布时间】:2019-09-03 17:01:12
【问题描述】:
我试图了解 ld-linux.so 如何解析对 Linux 上版本符号的引用。我有以下文件:
test.c:
void f();
int main()
{
f();
}
a.c 和 b.c:
void f() {}
symbols.txt:
ABC {
global:
*;
};
生成文件:
all: liba.so libb.so test
liba.so: a.c
gcc -g -shared $^ -o $@ -Wl,--version-script=symbols.txt
libb.so: b.c
gcc -g -shared $^ -o $@
test: test.c liba.so
gcc -g test.c -la -L. -o $@
clean:
rm -f liba.so libb.so test
然后我运行了以下命令
LD_PRELOAD=./libb.so LD_LIBRARY_PATH=. ./test
我发现调用了来自 b.c 的 f(),即使 libb.so 中的符号 f 没有 test所需的版本> (f@ABC)。为什么会这样?
【问题讨论】: