.vectors overwritten by .text in gnu linker

1

I have the following sections defined in the linker script for gnu arm embedded 4.9 2014q4:

MEMORY
{
    SRAM_L (rwx) : ORIGIN = 0x00000000, LENGTH = 32K
    SRAM_U (rwx) : ORIGIN = 0x20000000, LENGTH = 32K
}

SECTIONS
{
    . = ORIGIN(SRAM_L);

    .isr_vector :
    {
        KEEP(*(.isr_vector))
    } >SRAM_L

    .text :
    {
        . = ALIGN (4);
        *(.text);
    } >SRAM_L

vectors.S contains the following code:

/* vectors.s */
.section .isr_vector
.thumb
.word   _start_of_stack /* stack top address */
.word   _reset      /* 1 Reset */
.word   hang        /* 2 NMI */
.word   hang        /* 3 HardFault */
...

.thumb_func
.global _reset
_reset:
    mov r0, #0
    ldr r1, [r0]
    mov sp, r1
    bl low_level_init
    b hang

.thumb_func
hang:   b .

When the program links it appears in the map file that the .text and .vector section overlap:

.isr_vector        0x00000000      0x146
 *(.isr_vector)
 .isr_vector    0x00000000      0x146 ./src/vectors.o
                0x00000138                _reset

.text           0x00000000      0x6cc
                0x00000000                . = ALIGN (0x4)
 *(.text)
 .text          0x00000000      0x134

Is there some rule I missed around the location of .text?

gcc
linker
ld
asked on Stack Overflow Mar 9, 2015 by devanl • edited Mar 10, 2015 by devanl

1 Answer

2

I found some information over at http://hertaville.com/2012/06/29/the-startup-file/

Looks like the following was missing from my vectors.S. I believe this is indicating proper type (.data) and size to the linker? (please correct me if I'm wrong here)

/* vectors.s */
  .syntax unified
  .cpu cortex-m4
  .fpu softvfp
  .thumb

.global g_pfnVectors
.global _reset
.global hang

/*******************************************************************************
*
* The minimal vector table for a Cortex M4. Note that the proper constructs
* must be placed on this to ensure that it ends up at physical address
* 0x0000.0000.
*******************************************************************************/
  .section .isr_vector,"a",%progbits
  .type g_pfnVectors, %object
  .size g_pfnVectors, .-g_pfnVectors

g_pfnVectors:
  .word   _start_of_stack   /* stack top address */
answered on Stack Overflow Mar 10, 2015 by devanl • edited Mar 10, 2015 by devanl

User contributions licensed under CC BY-SA 3.0