Forum: ARM programming with GCC/GNU tools Linker places wrong code at correct location?

Author: sNOOBy (Guest)
Posted on:

Rate this post
0 useful
not useful
I am currently programming an ADuC7026 (ARM7) with the GNU toolchain and 
have a problem with my linker script.

Here the code:

        . = 0x00010000;
    RAM_START = . ;
  ram_except_vecs : AT (FLASH_RAM_EXCEPT_START) {
    * (ram_except_vecs);
    . = ALIGN(0x4);
  } >ram
  . = ALIGN(0x4);


.section "ram_except_vecs"
    ram_reset:  LDR  PC, [PC,#0x18]
    ram_undef:  LDR  PC, [PC,#0x18]
    ram_swi:  LDR  PC, [PC,#0x18]
    ram_pref:  LDR  PC, [PC,#0x18]
    ram_data:  LDR  PC, [PC,#0x18]
        LDR  PC, [PC,#0x18]
    ram_irq:  LDR  PC, [PC,#0x18]
    ram_fiq:  LDR  PC, [PC,#0x18]
    .word  0x00080020
    .word  0x00010004
    .word  0x00010008
    .word  0x0001000C
    .word  0x00010010
    .word  0x00010014
    .word  0x00010018
    .word  0x0001001C

At runtime the code is copied from ROM to RAM with the following:

    LDR    R1, =_RAM_START_
    CMP    R2, #0
    BEQ    endCopyVectors
    LDR    R3, [R0], #4
    STR    R3, [R1], #4
    SUBS  R2, R2, #4
    BNE    vectorLoop

The Problem I have is that according to my emulator (KEIL uVision) the 
section is correctly located in ROM (right after the .text section), is 
also linked to the correct address in RAM and when copying copies the 
correct amount (16 orders). However instead of the expected code, there 
are only zeros in ROM (and of course in RAM as well).

I have no idea what I am doing wrong! Please help!
Thanks a lot in advance!

Author: code tag (Guest)
Posted on:

Rate this post
0 useful
not useful
You can use code tags so that the softare won't garbage up your _ 

Author: sNOOBy (Guest)
Posted on:

Rate this post
0 useful
not useful
I just figured out that renaming the section to ".text.(something)" will 
solve the problem. Apparently the Linker doesn't consider the code 
relevant enough to place it into the program if it isn't related to any 
of the "standard-sections" .text .data or .bss. I have no idea why that 
it though. Anyone got any ideas?

Sorry for messing up the code-tags!

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Not enough and/or incomplete information given so it's difficult to help 
here. Create a minimal example with all needed information (source, 
linker-script and all options passed to compiler, assembler and linker - 
makefile prefered).

If in input-section named .text does not result in code in the 
output-section this may be caused by the -function-sections option. With 
this option all functions are placed in separate input-sections. The 
linker will take them into account if .text.* is used as input-section 
(.text will not match .text.functionfoo). If function-sections and 
gc-sections options get used the input-section which holds the 
exceptions-vectors should be wrapped with KEEP in the linker-script.

See compiler- and linker documentation on function-sections, gc-sections 
and KEEP for further information.


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.