Nasm - Symbol `printf' causes overflow in R_X86_64_PC32 relocation [duplicate] Nasm - Symbol `printf' causes overflow in R_X86_64_PC32 relocation [duplicate] linux linux

Nasm - Symbol `printf' causes overflow in R_X86_64_PC32 relocation [duplicate]


try compiling with -no-pie, check out these posts for explanation:Assembling with GCC causes weird relocation error with regards to .data

in short:

Debian switched to PIC/PIE binaries in 64-bits mode & GCC in your case is trying to link your object as PIC, but it will encounter absolute address in mov $str, %rdi.


Full credit to https://stackoverflow.com/users/3062591/brian

for figuring out how to get this to work. If you're like me and very new to nasm OR if for some reason you're new to nasm and have done little to nothing with gcc then you're going to need to run the command:

nasm -felf64 YOUR_FILE.asm && gcc -no-pie YOUR_FILE.o && ./a.out

I was able to get this using a

call printf

without needing to change it to

printf wrt ..got

which had on previous attempts with some NASM introductory examples but not all.