为什么gcc在没有flag-fno饼图的情况下生成奇怪的代码?
我正在尝试在gcc中编译带flag-fno饼图和不带饼图的伪函数为什么gcc在没有flag-fno饼图的情况下生成奇怪的代码?,gcc,assembly,x86,i386,position-independent-code,Gcc,Assembly,X86,I386,Position Independent Code,我正在尝试在gcc中编译带flag-fno饼图和不带饼图的伪函数 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: 90
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: 90 nop
4: 5d pop ebp
5: c3 ret
我得到以下反汇编代码
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:
0:55推ebp
1:89 e5 mov ebp,esp
3:e8 fc ff呼叫4
8:05 01 00添加eax,0x1
d:90不
e:5d波普ebp
f:c3 ret
当我使用该标志编译时
gcc -m32 -ffreestanding -c test.c -o test.o
00000000 <dummy_test_entrypoint>:
0: 55 push ebp
1: 89 e5 mov ebp,esp
3: 90 nop
4: 5d pop ebp
5: c3 ret
00000000:
0:55推ebp
1:89 e5 mov ebp,esp
3:90不
4:5d波普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
3:e8 fc ff呼叫4
8:05 01 00添加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_
3:e8 fc ff呼叫4
4:R_386_PC32__x86.get_pc_thunk.ax
8:05 01 00添加$0x1,%eax
9:R_386_GOTPC_GLOBAL_OFFSET_表_
子例程如下所示:
00000000 <__x86.get_pc_thunk.ax>:
0: 8b 04 24 mov (%esp),%eax
3: c3 ret
00000000:
0:8b 04 24 mov(%esp),%eax
3:c3 ret
此构造将get指针加载到%eax
,以防函数需要引用全局数据。该函数不包含这样的引用,但由于您未进行优化就编译了代码,所以GCC没有删除死代码