gpt4 book ai didi

linux - GDB如何执行共享库的基地址[ info sharedlibrary 命令的内部结构]

转载 作者:太空狗 更新时间:2023-10-29 11:09:16 24 4
gpt4 key购买 nike

我正在尝试了解 GDB 命令背后的内部工作原理。在了解 elf/共享库/地址空间随机化的初步作业后,我试图了解 GDB 在可执行文件和核心文件之间的意义。

solib.c 包含共享库处理的实现。 Esp 对 info sharedlibrary 命令很感兴趣。

solib.c 的注释是这样的..

 
/* Relocate the section binding addresses as recorded in the shared
object's file by the base address to which the object was actually
mapped. */

ops->relocate_section_addresses (so, p);

我无法从这条评论中理解太多。有人可以用简单的英语向我解释搬迁是如何发生的吗?即每次可执行文件加载共享对象时,它都会加载到某个位置,比如 X,并且共享库中的所有符号都将位于固定偏移量,比如 X+Y,大小为 Z。我的问题是, gdb 如何进行相同范围的地址重定位,使其与 corefile 中的加载段相匹配。它如何从可执行文件中获取提示。

最佳答案

how does gdb does the same range of address relocation, so that it matches with the load segments in the corefile

换句话说,GDB是如何找到重定位X的?

答案取决于操作系统。

在 Linux 上,GDB 在 core 文件中找到 _DYNAMIC[]struct Elf{32,64}_Dyn 数组,其中包含带有 .d_tag == DT_DEBUG 的元素。

该元素中的 .d_ptr 指向 struct r_debug(参见 /usr/include/link.h),它指向一个struct link_map 的链表,它描述了所有加载的共享库及其在 l_addr 中的重定位。

GDB中的相关文件是solib-svr4.c

编辑:

I see that, there are no .dynamic sections in the corefile.

不应该的。可执行文件中有一个.dynamic 部分 core 中匹配的LOAD 段(该段将“覆盖“.dynamic 部分,并包含运行时的内容。

关于linux - GDB如何执行共享库的基地址[ info sharedlibrary 命令的内部结构],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21811373/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com