问题描述
ELF格式的.got和.got.plt节有什么区别?
What is the difference between .got and .got.plt section in ELF format?
推荐答案
我先前的评论是正确的:
My previous comment turns to be right:
下面的示例使事情变得很清楚.
The example below makes things a bit clear.
这些是我的32位i686-linux/lib/libm.so的重定位
These are the relocations for my 32 bits i686-linux /lib/libm.so
Relocation section '.rel.dyn' at offset 0x32b8 contains 8 entries:
Offset Info Type Sym.Value Sym. Name
00025030 00000008 R_386_RELATIVE
00024fd8 00005706 R_386_GLOB_DAT 00025034 _LIB_VERSION
00024fdc 00000406 R_386_GLOB_DAT 00000000 __gmon_start__
00024fe0 00000506 R_386_GLOB_DAT 00000000 _Jv_RegisterClasses
00024fe4 00000806 R_386_GLOB_DAT 00000000 _rtld_global_ro
00024fe8 00000906 R_386_GLOB_DAT 00000000 stderr
00024fec 00013006 R_386_GLOB_DAT 0002507c signgam
00024ff0 00000e06 R_386_GLOB_DAT 00000000 __cxa_finalize
Relocation section '.rel.plt' at offset 0x32f8 contains 12 entries:
Offset Info Type Sym.Value Sym. Name
00025000 00000107 R_386_JUMP_SLOT 00000000 fputs
00025004 00000207 R_386_JUMP_SLOT 00000000 __errno_location
00025008 00000307 R_386_JUMP_SLOT 00000000 sprintf
0002500c 00000407 R_386_JUMP_SLOT 00000000 __gmon_start__
00025010 00000607 R_386_JUMP_SLOT 00000000 strtod
00025014 00000707 R_386_JUMP_SLOT 00000000 __assert_fail
00025018 00000a07 R_386_JUMP_SLOT 00000000 strlen
0002501c 00000b07 R_386_JUMP_SLOT 00000000 strtof
00025020 00000c07 R_386_JUMP_SLOT 00000000 fwrite
00025024 00000d07 R_386_JUMP_SLOT 00000000 strtold
00025028 00005e07 R_386_JUMP_SLOT 00005970 matherr
0002502c 00000e07 R_386_JUMP_SLOT 00000000 __cxa_finalize
请注意,正如您所指出的,有两个重定位部分,即.rel.dyn和.rel.plt.您可以看到,.rel.plt的所有重定位都是R_386_JUMP_SLOT类型,这意味着它们是分支重定位,而.rel.dyn中的几乎所有重定位都是R_386_GLOB_DAT,这意味着全局变量的重定位.
Look that as you noted there are two relocation sections, namely .rel.dyn and .rel.plt. You can see that all relocations for .rel.plt are of type R_386_JUMP_SLOT which means that they are branch relocations on the other hand almost all relocations in .rel.dyn are R_386_GLOB_DAT which means relocation for global variables.
.symtab和.dynsym之间存在另一个细微差别.虽然第一个包含对静态链接编辑期间使用的所有符号的引用,但后面一个仅包含动态链接所需的那些符号.因此,上面提到的重定位仅引用.dynsym部分.
Another subtle difference exist between .symtab and .dynsym. While the first contain references for all symbols used during static link editing the later contain only those symbols needed for dynamic linking. Thus, the relocations mentioned above refer only to .dynsym section.
这篇关于.got和.got.plt节有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!