My system is Ubuntu 18.04 64bit . with build-essentials and devtools installed.
Hi, I have an assembly file called Hello.s Here is it's content:
#This is a simple "Hello World!" program .section .rodata #read only data section str: .string "Hello World!\n" ######## .text #the beginnig of the code .globl main #the label "main" is used to state the initial point of this program .type main, @function # the label "main" representing the beginning of a function main: # the main function: pushq %rbp #save the old frame pointer movq %rsp, %rbp #create the new frame pointer movq $str,%rdi #the string is the only paramter passed to the printf function (remember- first parameter goes in %rdi). movq $0,%rax call printf #calling to printf AFTER we passed its parameters. #return from printf: movq $0, %rax #return value is zero (just like in c - we tell the OS that this program finished seccessfully) movq %rbp, %rsp #restore the old stack pointer - release all used memory. popq %rbp #restore old frame pointer (the caller function frame) ret #return to caller function (OS)
Trying to compile it using gcc -Hello.s returns the following message:
/usr/bin/ld: /tmp/ccY9hdWi.o: relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output collect2: error: ld returned 1 exit status
Tried gcc -fPIC Hello.s that has no effect - brings the same message.
Some people told me to install gcc-4.8, well that didn't work
Installing a previous version of ubuntu was also proposed.. well that's the last resort in my opinion.