我已阅读主题GCC -fPIC option
所以我创建了我的 testlib.cpp。
int foo(int num)
{
int result;
if (num != 0)
{
result = 1;
}
else
{
result = 2;
}
return result;
}
当我编译为 g++ -c -o testlib.o testlib.cpp 和 g++ -fPIC -c -o testlib.o testlib.cpp 时,testlib.o 的相应 objdump 是相同的:
objdump -d testlib.o -M intel
testlib.o: file format elf32-i386
Disassembly of section .text:
00000000 <_Z3fooi>:
0: 55 push ebp
1: 89 e5 mov ebp,esp
3: 83 ec 10 sub esp,0x10
6: 83 7d 08 00 cmp DWORD PTR [ebp+0x8],0x0
a: 74 09 je 15 <_Z3fooi+0x15>
c: c7 45 fc 01 00 00 00 mov DWORD PTR [ebp-0x4],0x1
13: eb 07 jmp 1c <_Z3fooi+0x1c>
15: c7 45 fc 02 00 00 00 mov DWORD PTR [ebp-0x4],0x2
1c: 8b 45 fc mov eax,DWORD PTR [ebp-0x4]
1f: c9 leave
20: c3 ret
而且我希望在使用 -fPIC 编译时,跳转和je命令的参数地址与位置无关。所以这两个objdumps应该是不同的。我理解错了什么?