Trying to compile this code:
global main
extern printf
[section .data]
fmtStr: db "Input string", 0xA, 0
[section .text]
main:
push rbp
push fmtStr
call printf
pop rbp
ret
First step goes well:
nasm -f elf64 printf.asm -o printf64.o
But gcc fails:
gcc printf64.o -o printf64
/bin/ld: printf64.o: relocation R_X86_64_32S against `.data' can not be used when making a shared object; recompile with -fPIC
/bin/ld: final link failed: Nonrepresentable section on output collect2: error: ld returned 1 exit status
I have
Linux 4.14.8-1-ARCH x86_64
gcc (GCC) 7.2.1 20171128
GNU ld (GNU Binutils) 2.29.1