I have this simple program to compute the square root of a floating point number
global main
extern printf
section .data
float_t db '%f',0x0
val dq 123.45
res dq 0x0
section .text
main:
fld qword[val]
fsqrt
fst qword[res]
xor rax,rax
mov rdi, float_t
mov rsi, [res]
call printf
mov rax,60
mov rdi,0
syscall
I assembled it by
$ nasm -f elf64 fpu.asm -o fpu.o
and then tried to link to glibc with gcc as
$ gcc fpu.o -o fpu
GCC complains with:
/usr/bin/ld: fpu.o: relocation R_X86_64_32S against `.data' can not be used
when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status