views:

654

answers:

4

Hi Guys, I'm writing software for a Cortex-A8 processor and I have to write some ARM assembly code to access specific registers. I'm making use of the gnu compilers and related tool chains, these tools are installed on the processor board(Freescale i.MX515) with Ubuntu. I make a connection to it from my host PC(Windows) using WinSCP and the PuTTY terminal.

As usual I started with a simple C project having main.c and functions.s. I compile the main.c using GCC, assemble the functions.s using as and link the generated object files using once again GCC, but I get strange errors during this process.

An important finding -

Meanwhile, I found out that my assembly code may have some issues because when I individually assemble it using the command as -o functions.o functions.s and try running the generated functions.o using ./functions.o command, the bash shell is failing to recognize this file as an executable(on pressing tab functions.o is not getting selected/PuTTY is not highlighting the file).

Can anyone suggest whats happening here? Are there any specific options I have to send, to GCC during the linking process? The errors I see are strange and beyond my understanding, I don't understand to what the GCC is referring.

I'm pasting here the contents of main.c, functions.s, the Makefile and the list of errors.

Help, please!!!

Vikram

Latest errors included after the makfile was edited as suggested by guys here -

ubuntu@ubuntu-desktop:~/Documents/Project/Others/helloworld$ make
gcc -c -mcpu=cortex-a8 main.c
as -mcpu=cortex-a8 -o functions.o functions.s
gcc -o hello main.o functions.o
functions.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/arm-linux-gnueabi/4.3.3/../../../crt1.o:init.c:(.text+0x0): first defined here
collect2: ld returned 1 exit status
make: *** [hello] Error 1

main.c

#include <stdio.h>
#include <stdlib.h>

int main(void) {

    puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
    return EXIT_SUCCESS;
}

functions.s

* Main program */
    .equ      STACK_TOP, 0x20000800
    .text
    .global _start
    .syntax unified

_start:
    .word STACK_TOP, start
    .type start, function

start:
    movs  r0, #10
    movs  r1, #0
    .end

Makefile

all: hello

hello: main.o functions.o
    gcc hello -o main.o functions.o

-- hello was included here after suggested here by guys at stackoverflow, but the problem still persists, I still get the same errors.

main.o: main.c
    gcc -c -mcpu=cortex-a8 main.c

functions.o: functions.s
    as -mcpu=cortex-a8 -o functions.o functions.s

Errors

ubuntu@ubuntu-desktop:~/Documents/Project/Others/helloworld$ make
gcc -c -mcpu=cortex-a8 main.c
as -mcpu=cortex-a8 -o functions.o functions.s
gcc -o main.o functions.o
functions.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/arm-linux-gnueabi/4.3.3/../../../crt1.o:init.c:(.text+0x0): first defined here
/usr/lib/gcc/arm-linux-gnueabi/4.3.3/../../../crt1.o: In function `_start':
init.c:(.text+0x30): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [hello] Error 1
+5  A: 

In the makefile:

hello: main.o functions.o
    gcc -o main.o functions.o

should be:

hello: main.o functions.o
    gcc -o hello main.o functions.o

As it stands, you are linking functions.o, but not main.o, and producing an output executable called main.o, which is overwriting your existing main.o.

anon
Hi Neil, I made the change and I still see similar errors, I'm pasting them below -ubuntu@ubuntu-desktop:~/Documents/Project/Others/helloworld$ makegcc -c -mcpu=cortex-a8 main.cas -mcpu=cortex-a8 -o functions.o functions.sgcc -o hello main.o functions.ofunctions.o: In function `_start':(.text+0x0): multiple definition of `_start'/usr/lib/gcc/arm-linux-gnueabi/4.3.3/../../../crt1.o:init.c:(.text+0x0): first defined herecollect2: ld returned 1 exit statusmake: *** [hello] Error 1
vikramtheone
@vikram Edit the new info into your question. It looks to me as if the RT library is defining _start as well.
anon
Neil I have included the new list of errors, the init is somehow getting invoked I don't know how.
vikramtheone
+1  A: 

Shouldn't

hello: main.o functions.o
    gcc -o main.o functions.o

be

hello: main.o functions.o
    gcc -o hello main.o functions.o
codaddict
A: 

I think that has something to do with the Runtime library the gcc is linking at the end.

And in this library there already is a "_start".

I think you have to compile without "std library". but than you wont have printf,getchar and all the other useful stuff.

Bigbohne
Bigbonhne, I commented out the stdio.h and stdlib.h, but no changes, I once again get complaints about the multiple definitions to _start.
vikramtheone
A: 

As Bigbohne suggests, gcc is trying to link in the standard runtime library. Try adding the -nostdlib option to your gcc call:

gcc -nostdlib -o hello main.o functions.o
tikiboy