dlopen.so无法在已剥离的可执行文件中找到符号

问题描述

| 我在Linux中有一个可执行文件-
exe
该可执行文件具有一些功能,这些功能在整个代码中都使用:
sendMsg
debugPrint
然后,我想动态加载一个为我的可执行文件提供额外功能的ѭ3。 在此共享库中,我包含
sendMsg
debugPrint
的标头。 我用
dlopen()
加载了这个共享库,并用ѭ7create创建了一个API。 但是,在ѭ6时,我使用
RTLD_NOW
在加载时解析所有符号。 它未能说明找不到
sendMsg
符号。 该符号必须在可执行文件中,因为在其中编译了“ 11”。 但是,我的可执行文件已被“ 12”进程删除。因此,
dlopen
找不到符号将是有意义的。 我该如何解决这种情况? 我可以将共享功能构建到静态库中,并将该静态库链接到
exe
.so
中。这会增加代码大小:( 我可以去掉ѭ0的剥离,以便可以找到符号 进行一些我不知道的魔术链接时的编译时间,以便
.so
知道符号在ѭ0中的位置     

解决方法

man ld
   -E
   --export-dynamic
   --no-export-dynamic
       When  creating  a  dynamically  linked  executable,using the -E option or the --export-dynamic option causes the linker to add all symbols to the dynamic symbol table.  The
       dynamic symbol table is the set of symbols which are visible from dynamic objects at run time.

       If you do not use either of these options (or use the --no-export-dynamic option to restore the default behavior),the dynamic symbol table will normally contain only  those
       symbols which are referenced by some dynamic object mentioned in the link.

       If  you  use \"dlopen\" to load a dynamic object which needs to refer back to the symbols defined by the program,rather than some other dynamic object,then you will probably
       need to use this option when linking the program itself.

       You can also use the dynamic list to control what symbols should be added to  the  dynamic  symbol  table  if  the  output  format  supports  it.   See  the  description  of
       --dynamic-list.

       Note  that  this  option  is  specific  to  ELF  targeted  ports.   PE  targets  support  a  similar function to export all symbols from a DLL or EXE; see the description of
       --export-all-symbols below.
您还可以将
-rdynamic
选项传递给gcc / g ++(如注释中所述)。根据您设置make脚本的方式,这将很方便     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...