I'm trying to use the printf function in nasm. My program is set up like this:
section .text
global main
extern printf
main:
endbr64
push rbp
mov rdi, [array + 1 * 4]
mov rsi, specifer
mov rax, 0
call printf
pop rbp
mov rax, 0
ret
section .data
array db 1,2,3,4,5,6,7,8,9,1
arrlen equ $ - array
specifer db '%d',0xa,0
speclen equ $ - specifer
I am running these commands to compile:
nasm -f elf64 arrays.asm
gcc arrays.o
But when I do, I get this error:
arrays.asm:6: warning: label alone on a line without a colon might be in error [-w+orphan-labels]
/usr/bin/ld: arrays.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
I tried recompiling with -fPIE but I got the literal same exact error. What am I doing wrong?
Here are the versions of the tools I am using:
NASM: 2.14.02 GCC: 9.4.0 ld: 2.34
My goal at this point is just to get it to compile. I have tried using LD instead of GCC, but I just kept getting a segfault.