Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ ELF文件中的resolve函数如何知道符号所在的LIB?_C++_Debugging_Elf - Fatal编程技术网

C++ ELF文件中的resolve函数如何知道符号所在的LIB?

C++ ELF文件中的resolve函数如何知道符号所在的LIB?,c++,debugging,elf,C++,Debugging,Elf,在符号表中,只有符号名称的偏移量,但没有符号所属库的信息 typedef struct { Elf32_Word st_name; Elf32_Addr st_value; Elf32_Word st_size; unsigned char st_info; /* bind, type: ELF_32_ST_... */ unsigned char st_other; Elf32_

在符号表中,只有符号名称的偏移量,但没有符号所属库的信息

typedef struct { Elf32_Word st_name; Elf32_Addr st_value; Elf32_Word st_size; unsigned char st_info; /* bind, type: ELF_32_ST_... */ unsigned char st_other; Elf32_Half st_shndx; /* SHN_... */ } Elf32_Sym; 类型定义结构{ Elf32_单词st_名称; Elf32地址st值; ELF 32_单词st_大小; 未签名字符st_info;/*绑定,类型:ELF_32_st_*/ 未签名字符st_other; Elf32半圣士德;/*圣士德*/ }Elf32_-Sym; 在运行时调用解析函数时,符号表的偏移量和另一个DWORD将传递给它。那个DWORD和符号的库有关吗?如果不是,那么解析函数如何查找符号库

解析函数如何查找符号库

通过线性搜索加载到进程中的库(加载程序维护)

定义给定函数“wins”的第一个库。这允许例如
libtcmalloc.so
定义
malloc
calloc
,并覆盖这些符号(您可以使用
LD_PRELOAD
,或者在
libc
之前链接
libtcmalloc
,因此
libtcmalloc
libc
之前出现在加载程序列表中)


搜索与库的数量成线性关系,但在每个库中都是
O(1)
,因为每个库都有其符号的哈希表(在
.hash
.gnu hash
部分)。

是,ELF与Windows PE文件相比,我认为Apple Mac-O格式不会将导出的符号绑定到给定的动态库:在广度优先搜索中,会在所有库中搜索它们(在图中,其边是所需的
dtu
条目,即ELF模块之间的依赖关系)。使用的图是全局图,而不是当前ELF文件的子图。