是否有可能防止g++在跨优化级别的函数开始时推入epb并保存esp ?
Is it possible to prevent g++ from pushing epb and saving esp at the start of a function across optimization levels?
考虑以下代码,我将把它放入一个名为Epb.cc
的文件中。
void f() {
asm("nop");
}
现在,我在各种优化级别下编译它。
g++ -c -O0 -o Out0 Ebp.cc
g++ -c -O1 -o Out1 Ebp.cc
g++ -c -O2 -o Out2 Ebp.cc
g++ -c -O3 -o Out3 Ebp.cc
这是objdump -d
在每一个上的输出。
$ objdump -d Out*
Out0: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <_Z1fv>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 90 nop
5: 5d pop %rbp
6: c3 retq
Out1: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <_Z1fv>:
0: 90 nop
1: c3 retq
Out2: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <_Z1fv>:
0: 90 nop
1: c3 retq
Out3: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <_Z1fv>:
0: 90 nop
1: c3 retq
是否有可能指示g++
在所有优化级别中不为这个特定函数添加三个额外的指令?
正如@MichaelPetch在评论中指出的那样,一个会影响这个函数(以及其他函数)的解决方案是使用-fomit-frame-pointer
编译器选项,这将导致g++
在找到机会时忽略序言,无论优化级别如何。
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 为什么 -mmacosx-version-min=10.10 不阻止使用标记为从 10.11 开始的函数?
- 使用移动和复制语义时函数匹配如何工作?
- 在继承C++子项创建者开始时,是否可以不启动父创建者?
- 为什么每次执行时函数的地址都不同?
- C++中的编译时函数是什么?
- 如何使用模板生成常规参数列表并将其传递给运行时函数?
- 编译时函数的选择取决于类型大小
- 为什么引用不能与编译时函数一起使用?
- 多线程.如果我使用信号量,我可以在开始时创建很多线程还是应该只有几个线程?
- 查找涉及 while 循环的运行时函数
- 5000+ 深度递归时函数堆栈溢出
- 构建大型无序集,并在开始时使用所有可用数据
- 在字符串开始时删除某些字符
- PGI 不支持 OpenMP 4.5 运行时函数
- 在运行时开始时填充两个大向量
- 初始化函数中的静态变量,而不是在文件开始时
- 在函数开始时测试并返回,而不是嵌套的 if
- 是否有可能防止g++在跨优化级别的函数开始时推入epb并保存esp ?
- 在每分钟开始时运行一个函数