交流
商城
MCN
登入
注册
首页
提问
分享
讨论
建议
公告
动态
发表新帖
发表新帖
7 ELF节-.rela.text
分享
未结
0
3546
李延
LV6
2022-07-17
悬赏:20积分
# 1 .rela.text 前面都是对于汇编语句的分析,但在汇编是需要使用变量,或者函数。这些内容都是如何定位的,就需要用到.rela.text # 2 rela.text 作用 我们先看以下代码 ```c int sun1(){ return 1; } int sun2(){ return 1; } int main(){ return sun1()+sun2(); } ``` 这里我们分别调用了sun1 和sun2 ,并且使用了两个函数,我们先看一下它的test节 ```asm 0000000000000000 <sun1>: 0: 55 push %rbp 1: 48 89 e5 mov %rsp,%rbp 4: b8 01 00 00 00 mov $0x1,%eax 9: 5d pop %rbp a: c3 retq 000000000000000b <sun2>: b: 55 push %rbp c: 48 89 e5 mov %rsp,%rbp f: b8 01 00 00 00 mov $0x1,%eax 14: 5d pop %rbp 15: c3 retq 0000000000000016 <main>: 16: 55 push %rbp 17: 48 89 e5 mov %rsp,%rbp 1a: 53 push %rbx 1b: b8 00 00 00 00 mov $0x0,%eax 20: e8 00 00 00 00 callq 25 <main+0xf> 25: 89 c3 mov %eax,%ebx 27: b8 00 00 00 00 mov $0x0,%eax 2c: e8 00 00 00 00 callq 31 <main+0x1b> 31: 01 d8 add %ebx,%eax 33: 5b pop %rbx 34: 5d pop %rbp 35: c3 retq ``` 这里我们发现使用的函数地址都是 0x0 那么它们是如何区分这两个不同的函数的,就需要我们rela.text # 3 格式 同样 在linux的服务器的`/usr/include/elf.h` 这个文件中找到它的结构定义 ```c typedef struct { Elf32_Addr r_offset; /* Address */ Elf32_Word r_info; /* Relocation type and symbol index */ Elf32_Sword r_addend; /* Addend */ } Elf32_Rela; typedef struct { Elf64_Addr r_offset; /* Address 64位 */ Elf64_Xword r_info; /* Relocation type and symbol index 64位*/ Elf64_Sxword r_addend; /* Addend 64位*/ } Elf64_Rela; ``` 分为两个版本64和32位,但都是 包括3个结构, - r_offset 重定位入口的偏移量,在可重定位文件中,对于.test段中的位置。 - r_info,分位两部分,低4字节,重定位入口类型,高4字节重定位入口的在符号表中的下标 - r_addend 在链接时说明。 我们看到.rela.text 将.text 通过systab表将各自调用关联起来。 # 4 命令查看 通过 ```c objdump -r call1.o ``` 可以查看具体内容 # 5 示例 ```c int sun1(){ return 1; } int sun2(); int main(){ return sun1()+sun2(); } ```  .test 在 0x1A处调用,使用的是systab表中下标为0x08的内容。 # 6 其他 这一章内容,与链接相关,我们具体在链接时说明
回帖
消灭零回复
提交回复
热议榜
java 相关知识分享
8
好的程序员与不好的程序员
6
写给工程师的十条精进原则
5
spring boot以jar包运行配置的logback日志文件没生成
5
一步一步分析SpringBoot启动源码(一)
5
MockMvc测试
5
【吐槽向】是不是有个吐槽的板块比较好玩
4
logstash jdbc同步mysql多表数据到elasticsearch
3
IntelliJ IDEA 优质License Server
3
.gitignore忽略规则
3
SpringBoot启动源码分析
3
一步一步分析SpringBoot启动源码(三)
3
2
一步一步分析SpringBoot启动源码(二)
2
积分不够将无法发表新帖
2
官方产品
Meta-Boot - 基于MCN
MCN - 快速构建SpringBoot应用
微信扫码关注公众号