arm-elf-gcc problem

From: Steffen Lutzmann (steffen.lutzmann_at_web.de)
Date: 06/24/04


Date: Thu, 24 Jun 2004 16:28:10 +0200

Hi group,

I'm a newbie regarding the GNU ARM stuff.
After many trials with intensive studying of the manuals for the gnu
linker and assembler I have no more idea to solve the following problem:

I want to compile and link a very simple main.c with startup code and
linker script (see below my sample files, its for ARM7TDMI). The linker,
invoked by arm-elf-gcc, can't find the entry point symbol, which is
referenced in my linker script and defined in the startup code as
.global. The linker complains with:

arm-elf-gcc -nostartfiles -Wl,-Map=mapfile.map
-Wl,--script=my_linker_script -Wl,-cref cstartup.o main.o -o
main.elf
/gnuarm/bin/../lib/gcc-lib/arm-elf/3.3.3/../../../../arm-elf/bin/ld:
warning: cannot find entry symbol __main; defaulting to 04000000

This is confusing because '__main' is defined as '.global' in the
startup file. Did I miss something in the makefile? Hope anybody can
give me hint.

Thanks in advance
Steffen

The startup code fragment:
--------------------------

   .include "../at91lib_gnu/periph/arm7tdmi/arm.inc"
   .include "phycore.inc"
                                
/******************************
    code entry point
******************************/
                
/* Define "__main" to ensure that C runtime system is not linked */
                
            .global __main
                
/* Exception vectors (before Remap) */

__main:

            B InitReset /* reset */
undefvec:
            B undefvec /* Undefined Instruction */
swivec:
            B swivec /* Software Interrupt */
pabtvec:
            B pabtvec /* Prefetch Abort */
dabtvec:
            B dabtvec /* Data Abort */
rsvdvec:
            B rsvdvec /* reserved */
irqvec:
            B irqvec /* reserved */
fiqvec:
            B fiqvec /* reserved */

/* EBI Initialization Data */

InitTableEBI:
     .word EBI_CSR_0
     .word EBI_CSR_1
     .word EBI_CSR_2
     .word EBI_CSR_3
     .word EBI_CSR_4
     .word EBI_CSR_5
     .word EBI_CSR_6
     .word EBI_CSR_7
     .word 0x00000001 /* REMAP command */
     .word 0x00000006 /* memory regions, standard read */

PtEBIBase:
     .word EBI_BASE /* EBI Base Address */

/*
  The reset handler before Remap
  From here, the code is executed from SRAM address
  Exporting labels used in other files
*/

InitReset:

/*
   Load System EBI Base address and CSR0 Init Value
*/

      ldr r0, PtEBIBase
      ldr r1, InitTableEBI

/*- Speed up code execution by disabling wait state on Chip Select 0*/

      str r1, [r0]
      bl __low_level_init

  ...and so on...

pretty simple main.c:
-----------------------
int main(void)
{
     int a,b;
     volatile int my_var;

     a=10;
     b=20;
     my_var=a+b;

     return 0;
}

my linker script:
-----------------------

ENTRY(__main)

MEMORY
{
    int_ram : org = 0x00000000, len = 8K /* internal RAM */
    ram : org = 0x04000000, len = 1024K /* RAM at CS1 */
}

SECTIONS
{
   .startup :
      {
           cstartup.o;
           *(.glue_7t);
           *(.glue_7);
           *(.rdata);
           *(.fini);

       } > int_ram

    .text :
       {
          main.o;
          *(.text);
       } > ram

    .data :
       {
          *(.data);
       } > ram

     .bss :
       {
          *(.bss) *(COMMON);
       } > ram
}

my makefile:
---------------------------

CC = arm-elf-gcc
AS = arm-elf-as

INC =
INC += -I ../at91lib_gnu

ASM.FILES =
ASM.FILES += cstartup.S

ASM.FLAGS +=
ASM.FLAGS += -mthumb-interwork
ASM.FLAGS += -mcpu=arm7tdmi
ASM.FLAGS += -gstabs

C.FILES = main.c

C.FLAGS +=
C.FLAGS += -c
C.FLAGS += -g
C.FLAGS += -mcpu=arm7tdmi
C.FLAGS += -mthumb-interwork

L.FLAGS =
L.FLAGS += -nostartfiles
L.FLAGS += -Wl,-Map=mapfile.map
L.FLAGS += -Wl,--script=my_linker_script
L.FLAGS += -Wl,-cref

OBJ =
OBJ += $(patsubst %.S,%.o,$(ASM.FILES))
OBJ += $(patsubst %.c,%.o,$(C.FILES))

%.o : %.S makefile
         $(AS) $(INC) $(ASM.FLAGS) $< -o $@

%.o : %.c makefile
         $(CC) $(INC) $(C.FLAGS) $< -o $@

all: $(OBJ)

exec: $(OBJ)
         $(CC) $(L.FLAGS) $(OBJ) -o main.elf

clean:
         rm *.o
         rm *.elf
         rm *.map

-- 
http://www.da0hq.de


Relevant Pages

  • Re: strangeness with objcopy and large binaries
    ... Possibly because it is being thrown out by the linker. ... to specify the sections I want copied - other sections, such as .bss, are then dropped during the copy. ... Presumably because the garbage collection is not throwing out the empty .data section. ... If you have no ..data section, perhaps the linker ends up using some sort of default addresses for some of the symbols used in the startup code. ...
    (comp.arch.embedded)
  • Re: Startup ASM Windows PE Problem???
    ... > The icon displays properly for the exe file ... you're probably dying in some startup code you got ... about Borland's linker, but try "/map"), you'll see the extra code. ... apparent entry point. ...
    (comp.lang.asm.x86)
  • Re: iostream breaks plug-in DSO
    ... > executable and links in the wrong startup code. ... Yes, that's the fix. ... I was so focused on what the linker should be doing ... I turned a few hairs grey tracking this one down. ...
    (comp.os.linux.development.apps)
  • makefile question / problem
    ... I have a problem with a makefile ... Why does the linker gets executed after the compiling finished? ... [root@FedoraPC tftpboot]# make mcf_qspi ... m68k-elf-strip -g mcf_qspi.o ...
    (comp.os.linux.development.system)
  • Re: Sound/Music for Scheme
    ... think you need to add -lc to the LIBS list at the top of the makefile, but I'm just guessing -- I don't have any info about cygwin libraries. ... '__divdi3' is the reason for the linker to not link correctly. ...
    (comp.lang.scheme)