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