EmbDev.net

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


von sNOOBy (Guest)


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

Here the code:
LINKER_SCRIPT:

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

ASSEMBLY:

.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    R0, =_FLASH_RAM_EXCEPT_START_
    LDR    R1, =_RAM_START_
    LDR    R2, =_RAM_EXCEPT_VECS_LENGTH_
    CMP    R2, #0
    BEQ    endCopyVectors
  vectorLoop:
    LDR    R3, [R0], #4
    STR    R3, [R1], #4
    SUBS  R2, R2, #4
    BNE    vectorLoop
  endCopyVectors:


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!

von code tag (Guest)


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

von sNOOBy (Guest)


Rate this post
useful
not useful
Hi,
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!

von Martin T. (mthomas) (Moderator)


Rate this post
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.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.