如何列出从.so文件导出的符号?如果可能的话,我也想知道它们的来源(例如,如果它们是从静态库中引入的).
我正在使用gcc 4.0.2,如果这有所不同.
我最近在GNU ld中发现了链接器选项"-Bsymbolic-functions":
-Bsymbolic
When creating a shared library, bind references to global symbols to the
definition within the shared library, if any. Normally, it is possible
for a program linked against a shared library to override the definition
within the shared library.
This option is only meaningful on ELF platforms which support shared libraries.
-Bsymbolic-functions
When creating a shared library, bind references to global function symbols
to the definition within the shared library, if any.
This option is only meaningful …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
#include <stdio.h>
typedef struct {
bool some_var;
} model_t;
const model_t model = {
true
};
void bla(const model_t *m) {
if (m->some_var) {
printf("Some var is true!\n");
}
else {
printf("Some var is false!\n");
}
}
int main() {
bla(&model);
}
Run Code Online (Sandbox Code Playgroud)
我想编译器拥有消除函数else中的子句所需的所有信息bla()。调用该函数的唯一代码路径来自 main,并且它接受const model_t,因此它应该能够确定该代码路径未被使用。然而:
在 GCC 12.2 中,我们看到第二部分被链接进来。
如果我的inline功能这个消失了:
我在这里缺少什么?有什么方法可以让编译器做一些更智能的工作吗?在 C 和 C++ 中,使用-O3和都会发生这种情况-Os。
我使用objdump来分析共享对象的内存使用情况.与.data和.rodata部分一起,我看到.data.rel.ro部分.
有谁知道这用了什么?