2

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.

Any suggestions?

SDIdo
  • 105
  • 1
  • 1
  • 10
  • Did you try to compile with `-fPIC` as the error text suggest ? Also don't post terminal output as image, but insert and format it as text instead. – Soren A Oct 19 '18 at 09:42
  • Thanks, I've edited. Yes I did and it does nothing else. – SDIdo Oct 19 '18 at 09:46

1 Answers1

1

For anyone interested. (Not so trivial for newbies like me :)) One can actually choose between the compilers! so:

gcc-4.8 Hello.s

is the answer.

SDIdo
  • 105
  • 1
  • 1
  • 10
  • What was the default compiler version? Is this using an older compiler or a newer compiler? When I run `gcc --version` on my Ubuntu 18.04 system, I get back version 7.3.0. Though it's possible I may have updated my compiler from the default install and forgotten about it. – Daniel Stevens Dec 20 '18 at 16:20
  • Hi Daniel, yeah mine is also 7.3.0. We were instructed to use the 4.8 one for this file. So yeah.. this one needs an older compiler @.@ (<-- & that's an assembly smiley) – SDIdo Dec 20 '18 at 19:12