Code:
new1.asm-
section .text
global main
extern printf
main:
mov rax, 5
mov rbx, 55
add rax,rbx
PUSH rax
PUSH message
call printf WRT ..plt
add esp,8
ret
message db "Sum = %08X", 10, 0
Command:
nasm -f elf64 new1.asm -o new1.o
Above runs without error
gcc -fpie -m64 -o new1 new1.o
Error:
/usr/bin/ld: new1.o: relocation R_X86_64_32S against `.text' can not be used when making a PIE object; recompile with -fPIE
collect2: error: ld returned 1 exit status
System Specs:
Ubuntu 21.04
Kernel: 5.11.0-34-generic
Machine: x86_64
Processor: x86_64
Operating system : GNU/Linux
I have also tried to use what is discussed in this
What mistake am I making and how do I fix this.
Also I cannot do -m32 because it returns
cannot find -lgcc
and I want to use 64 bit registers
Edit 1:
After reading this NASM printf print 64 bit double segfaults I changed my code to-
section .text
global main
extern printf
main:
mov rax, 5
mov rbx, 55
add rax,rbx
mov RDI,rax
call printf WRT ..plt
add rsp,8
ret
message db "Sum = %08X", 10, 0
It compiles and links but now I get segmentation fault.
I compiled with gcc -fpic -m64 -o new1 new1.o
this time