加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – ELF格式的重定位信息在哪里?

发布时间:2020-12-14 00:53:58 所属栏目:Linux 来源:网络整理
导读:在装载机部分引用“连接器和装载机” “load-time relocation is far simpler than link-time relocation, because the entire program is relocated as a unit. […] After reading the program into memory,the loader consults the relocation items in t
在装载机部分引用“连接器和装载机”

“load-time relocation is far simpler than link-time relocation,
because the entire program is relocated as a unit. […]
After reading the program into memory,the loader consults
the relocation items in the object file and fixes up the memory
locations to which the items point”

也许我误解了这一点,这只是在一些架构中,但我的问题是:在ELF格式中指定哪些项目需要在加载时重定位?我怎么查询这个清单?

解决方法

可以在ELF文件的特殊重定位部分中找到重定位.您可以使用readelf –sections命令查找可执行文件或共享库中的哪些部分,以及REL类型中包含重定位指令的部分.可以使用readelf –relocs显示这些重定位部分的内容.例如:

$readelf --relocs /bin/ls

Relocation section '.rela.dyn' at offset 0x16c8 contains 5 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
00000061afd8  000c00000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0
00000061b540  006d00000005 R_X86_64_COPY     000000000061b540 optind + 0
00000061b548  006e00000005 R_X86_64_COPY     000000000061b548 optarg + 0
00000061b550  006a00000005 R_X86_64_COPY     000000000061b550 stderr + 0
00000061b560  006600000005 R_X86_64_COPY     000000000061b560 stdout + 0

Relocation section '.rela.plt' at offset 0x1740 contains 99 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
00000061b000  000100000007 R_X86_64_JUMP_SLO 0000000000000000 strcoll + 0
00000061b008  000200000007 R_X86_64_JUMP_SLO 0000000000000000 mktime + 0
...

.rela.dyn部分包含对程序代码或数据符号中引用的引用,这些引用必须在加载时重定位,而.rela.plt主要包含用于调用共享对象中的函数的跳转槽.请注意,通常只将共享对象编译为与位置无关的代码,而通常的可执行文件则不编译.这是因为PIC代码比非PIC代码慢一点.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读