So I want to assemble this very simple code:
extern printf
Segment .data
string:
db "foo", 0
Segment .text
extern printf
global main
main:
push rbp
xor rax, rax
mov rdi, string
call printf
pop rbp
ret
but I wanted to make it a PIE so I changed
mov rdi, string
to
lea rdi, [rel+string]
but after doing that I get the following errors from ld/gcc:
relocation R_X86_64_PC32 against symbol `printf@GLIBC_2.2.5' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: final link failed: bad value
I'm compiling and assembling this with: nasm -f elf64 bar.s -o bar.o; gcc -fPIC bar.o -o bar
Why am I getting this error? It compiles just fine with the -no-pie flag