动态链接:用于索引重定位表的偏移值
我试图了解动态链接过程...对库函数(我们称之为 func
)的调用通过 plt
表。我知道当符号尚未重新定位时,函数的调用会从 plt
表传递,该表包含一个指令(例如 i1
),如 jmp *function_in_GOT
> 指向 i1
之后的下一条指令,类似于 push $offset
:在控制权传递到修复相对 GOT
的动态链接器之后code> 条目的地址为的功能。 offset
应该是重定位表中条目的索引,但我不明白......如何通过读取可执行文件的精灵找到这个值。可以
objdump --dynamic-reloc prog
找到一些东西吗?例如,我编写了一个非常简单的程序,仅使用 printf
和 strcpy
,上一个命令的输出是:
DYNAMIC RELOCATION RECORDS
OFFSET TYPE VALUE
08049ff0 R_386_GLOB_DAT __gmon_start__
0804a000 R_386_JUMP_SLOT __gmon_start__
0804a004 R_386_JUMP_SLOT __libc_start_main
0804a008 R_386_JUMP_SLOT strcpy
0804a00c R_386_JUMP_SLOT printf
例如,通过使用 gdb
读取从 printf@plt
开始的指令:
0x8048324 <printf@plt>: jmp *0x804a00c
0x804832a <printf@plt+6>: push $0x18
0x804832f <printf@plt+11>: jmp 0x80482e4
我们可以看到 offset
的值为 0x18
(十进制 24),但读取 的输出code>objdump
似乎是偏移量第一个重定位条目中的 printf
是 0x1c
。
一些想法?
I'm trying to understand dynamic linking process...the call to a library function (let's call it func
) passes through the plt
table. I know when the symbol is not yet relocated the call of the function passes from plt
table which contains an istruction (say i1
) like jmp *function_in_GOT
which points to the next instruction after i1
that appears like push $offset
: after the control is passed to the dynamic linker that fixes up the relative GOT
entry with the address of the function. offset
should be the index of the entry in the relocation table but i don't understand...how this value can be find by reading the elf of the executable. Is possible with
objdump --dynamic-reloc prog
to find something? For example i wrote a very simple program that uses only printf
and strcpy
and output of the previous command is:
DYNAMIC RELOCATION RECORDS
OFFSET TYPE VALUE
08049ff0 R_386_GLOB_DAT __gmon_start__
0804a000 R_386_JUMP_SLOT __gmon_start__
0804a004 R_386_JUMP_SLOT __libc_start_main
0804a008 R_386_JUMP_SLOT strcpy
0804a00c R_386_JUMP_SLOT printf
For example by reading with gdb
the instructions starting at printf@plt
:
0x8048324 <printf@plt>: jmp *0x804a00c
0x804832a <printf@plt+6>: push $0x18
0x804832f <printf@plt+11>: jmp 0x80482e4
we can see that the value for the offset
is 0x18
(24 in decimal) but reading the output of objdump
seems that offset of printf
from the first reloc entry is 0x1c
.
Some ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,offset是文件重定位表上的索引。
来自 ELF 规范版本 1.2:
5 。因此,程序将重定位偏移量(offset)压入堆栈。重定位偏移量是
重定位表中的 32 位非负字节偏移量。指定的搬迁条目将有
类型为R_386_JMP_SLOT,其偏移量将指定前面使用的全局偏移表条目
jmp指令。重定位项还包含符号表索引,从而告诉动态
链接器正在引用什么符号,在本例中为 name1。
但我不知道为什么你的结果存在差异。
Yes, offset is a index on the file relocation table.
From ELF specification version 1.2:
5 . Consequently, the program pushes a relocation offset (offset) on the stack. The relocation offset is a
32-bit, non-negative byte offset into the relocation table. The designated relocation entry will have
type R_386_JMP_SLOT, and its offset will specify the global offset table entry used in the previous
jmp instruction. The relocation entry also contains a symbol table index, thus telling the dynamic
linker what symbol is being referenced, name1 in this case.
But I don't know why the discrepancies in your results.