gcc - 为什么 gcc 会生成没有标志 -fno-pie 的奇怪代码?
问题描述
我正在尝试使用标志 -fno-pie 和不使用标志在 gcc 中编译虚拟函数。
void dummy_test_entrypoint() { }
当我在没有标志的情况下编译时。
gcc -m32 -ffreestanding -c test.c -o test.o
我得到以下反汇编代码。
00000000 <dummy_test_entrypoint>:
0: 55 push ebp
1: 89 e5 mov ebp,esp
3: e8 fc ff ff ff call 4 <dummy_test_entrypoint+0x4>
8: 05 01 00 00 00 add eax,0x1
d: 90 nop
e: 5d pop ebp
f: c3 ret
当我用标志编译时。
00000000 <dummy_test_entrypoint>:
0: 55 push ebp
1: 89 e5 mov ebp,esp
3: 90 nop
4: 5d pop ebp
5: c3 ret
我的问题。
它是什么???
3: e8 fc ff ff ff call 4 <dummy_test_entrypoint+0x4>
8: 05 01 00 00 00 add eax,0x1
解决方案
您在没有标志的情况下反汇编了目标文件--reloc
,因此输出具有误导性。使用--reloc
标志,您将看到:
3: e8 fc ff ff ff call 4 <dummy_test_entrypoint+0x4>
4: R_386_PC32 __x86.get_pc_thunk.ax
8: 05 01 00 00 00 add $0x1,%eax
9: R_386_GOTPC _GLOBAL_OFFSET_TABLE_
子程序如下所示:
00000000 <__x86.get_pc_thunk.ax>:
0: 8b 04 24 mov (%esp),%eax
3: c3 ret
此构造将 GOT 指针加载到%eax
中,以防函数需要引用全局数据。该函数不包含这样的引用,但由于您编译的代码没有优化,GCC 没有删除死代码。
推荐阅读
- excel - 我无法让我的宏循环遍历列以执行我需要的操作
- ruby - 如何在运行时在冰糕中的`T::Struct`上动态定义`prop`s?
- firebase - 这个谷歌云功能会导致firestore触发器无限循环吗?
- amazon-web-services - 如何在 aws 检查器资源组上多次使用相同的标签
- node.js - nodeJs中的路由-我的路由不起作用的原因是什么?
- raspberry-pi - 我怎么知道这不是病毒?
- c++ - 在 Visual Studio 2019/2022 中构建之前可以删除特定文件吗
- java - 如何使用 Spring Reactive webflux 在 Mongodb 中保存 excel 文件的数据?
- javascript - vuetify - 根据按钮的状态更改 v-select 项目
- python - SQLAlchemy 中的标准 Python 类与数据类