Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用使用 sparc v8 架构的处理器。我想编译我的可执行文件,使每个函数调用都是绝对地址。使用 -fPIC 选项生成与位置无关的代码,此标志是否有任何反转?
大多数 GCC 选项同时具有-fxxx和-fno-xxx变体。
-fxxx
-fno-xxx
您可以轻松测试fPIC. 只需编译一些简单的测试:
fPIC
int main () { printf ("Hello, world!\n"); }
使用如下命令行:
gcc -fPIC test.c -S
并在汇编程序中寻找与 PLT 相关的调用
call puts@PLT
现在尝试用相反的方式取消这个选项:
gcc -fPIC test.c -S -fno-PIC
你会看到,与 PLT 相关的调用已经消失,所以一切正常。