relocation R_X86_64_32S against `.data‘ can not be used when making a PIE object; recompile with -fP

Posted Dontla

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了relocation R_X86_64_32S against `.data‘ can not be used when making a PIE object; recompile with -fP相关的知识,希望对你有一定的参考价值。

linux下编译汇编语言报错:

relocation R_X86_64_32S against `.data' can not be used when making a PIE object; recompile with -fPIE

代码如下:

test.asm

global main

main:
    mov ebx, 1
    mov ecx, 2
    add ebx, ecx
    
    mov [sui_bian_xie], ebx
    mov eax, [sui_bian_xie]
    
    ret

section .data
sui_bian_xie   dw    0
dontla@dontla-virtual-machine:~/桌面/test$ nasm -f elf64 test.asm -o test.o
dontla@dontla-virtual-machine:~/桌面/test$ gcc -m64 test.o -o test
/usr/bin/ld: test.o: relocation R_X86_64_32S against `.data' can not be used when making a PIE object; recompile with -fPIE
collect2: error: ld returned 1 exit status

解决办法:
添加-no-pie指令

gcc -m64 test.o -o test -no-pie

结果:
在这里插入图片描述
参考文章:relocation R_X86_64_32S against `.data’ can not be used when making a shared object; recompile with -fPIC with gcc

以上是关于relocation R_X86_64_32S against `.data‘ can not be used when making a PIE object; recompile with -fP的主要内容,如果未能解决你的问题,请参考以下文章