相关疑难解决方法(0)

如何在.so文件中列出符号

如何列出从.so文件导出的符号?如果可能的话,我也想知道它们的来源(例如,如果它们是从静态库中引入的).

我正在使用gcc 4.0.2,如果这有所不同.

c c++ gcc symbols name-mangling

444
推荐指数
10
解决办法
34万
查看次数

什么是LD_PRELOAD技巧?

我最近在proggit看到了它的引用,并且(截至目前)它没有被解释.

我怀疑可能是它,但我不确定.

c linux environment-variables

321
推荐指数
6
解决办法
29万
查看次数

使用-Bsymbolic函数有不利之处吗?

我最近在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)

linker visibility elf dynamic-library

22
推荐指数
2
解决办法
1万
查看次数

对于采用 const 结构的函数,编译器不会优化函数体吗?

我有以下代码:

#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

c c++ gcc compiler-optimization

17
推荐指数
3
解决办法
2618
查看次数

什么是.data.rel.ro用于?

我使用objdump来分析共享对象的内存使用情况.与.data和.rodata部分一起,我看到.data.rel.ro部分.

有谁知道这用了什么?

gcc objdump

9
推荐指数
1
解决办法
8032
查看次数