Global symbols come up as 0x00 after linking

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Global symbols come up as 0x00 after linking

306 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pflieger on Wed Sep 02 14:10:04 MST 2015
I'm using a custom script (for an lpc1549), and there are no errors during linking. The problem is, global variables, like SystemCoreClock, are coming up as 0x00 instead of the actual RAM location, which is listed as 0x02002c44 (ram) in the map file. The other big mess up is __section_table_start (flash), so I had to hardcode an address into the cr_startup in order to make it to main().

The linker script is pretty small, am I missing something?



GROUP(libcr_semihost.a libcr_c.a libcr_eabihelpers.a)


MEMORY
{
  /* Define each memory region */
  BootFlash24 (rx)    : ORIGIN = 0x0,        LENGTH = 0x6000  /* 24K bytes  */
  MFlash232 (rx)      : ORIGIN = 0x6000,     LENGTH = 0x3a000 /* 232K bytes */
  Ram0_16_32_36 (rwx) : ORIGIN = 0x02000000, LENGTH = 0x9000  /* 36K bytes  */
}

/* Define a symbol for the top of each memory region */
__top_MFlash232 = 0x6000 + 0x0003a000;
__top_BootFlash24 = 0x0 + 0x6000;
__top_Ram0_16_32_36 = 0x2000000 + 0x9000;

ENTRY(ResetISR)



SECTIONS
{

    .boot_vector : ALIGN(4)
    {
       FILL(0xFFFF)
       KEEP(*(.boot_vector))

       . = ALIGN(0x40);
       KEEP(*(.debug_boot_id))
       KEEP(*(.boot_redirects))
       KEEP(*(.debug_boot_data))
    } > BootFlash24

    /* MAIN TEXT SECTION */
    .text : ALIGN(4)
    {
        FILL(0xff)
        __vectors_start__ = ABSOLUTE(.) ;
        KEEP(*(.isr_vector))

        /* Global Section Table */
        . = ALIGN(4);
        __section_table_start = .;
        __data_section_table = .;
        LONG(LOADADDR(.data));
        LONG(    ADDR(.data));
        LONG(  SIZEOF(.data));
        __data_section_table_end = .;
        __bss_section_table = .;
        LONG(    ADDR(.bss));
        LONG(  SIZEOF(.bss));
        __bss_section_table_end = .;
        __section_table_end = . ;
        /* End of Global Section Table */

        *(.after_vectors*)

    } >MFlash232

    .text : ALIGN(4)
    {
        *(.text*)
        *(.rodata .rodata.* .constdata .constdata.*)
        . = ALIGN(4);

    } > MFlash232

    /*
     * for exception handling/unwind - some Newlib functions (in common
     * with C++ and STDC++) use this.
     */
    .ARM.extab : ALIGN(4)
    {
        *(.ARM.extab* .gnu.linkonce.armextab.*)
    } > MFlash232
    __exidx_start = .;

    .ARM.exidx : ALIGN(4)
    {
        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
    } > MFlash232
    __exidx_end = .;

    _etext = .;


    /* MAIN DATA SECTION */


    .uninit_RESERVED : ALIGN(4)
    {
        KEEP(*(.bss.$RESERVED*))
        . = ALIGN(4) ;
        _end_uninit_RESERVED = .;
    } > Ram0_16_32_36


    /* Main DATA section (Ram0_16_32_36) */
    .data : ALIGN(4)
    {
       FILL(0xff)
       _data = . ;
       *(vtable)
       *(.ramfunc*)
       *(.data*)
       . = ALIGN(4) ;
       _edata = . ;
    } > Ram0_16_32_36 AT>MFlash232


    /* MAIN BSS SECTION */
    .bss : ALIGN(4)
    {
        _bss = .;
        *(.bss*)
        *(COMMON)
        . = ALIGN(4) ;
        _ebss = .;
        PROVIDE(end = .);
    } > Ram0_16_32_36


    /* DEFAULT NOINIT SECTION */
    .noinit (NOLOAD): ALIGN(4)
    {
        _noinit = .;
        *(.noinit*)
         . = ALIGN(4) ;
        _end_noinit = .;
    } > Ram0_16_32_36

    PROVIDE(_pvHeapStart = DEFINED(__user_heap_base) ? __user_heap_base : .);
    PROVIDE(_vStackTop = DEFINED(__user_stack_top) ? __user_stack_top : __top_Ram0_16_32_36 - 64);
}
0 Kudos
2 Replies

241 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pflieger on Thu Sep 03 06:58:30 MST 2015
OK, I see that v7.9.0 has a better way to make scripts. I'll upgrade.

By "0x00" I mean that
SystemCoreClock = 1000;
results in an attempt to write 1000 to address 0, and a hard fault. The map say one thing, the actual binary code has another thing.

int foo;                      // This ends up with a wrong address.
static int foo;            // This one will get a proper address in RAM.


AND...

My co-worker said, "is the code position independent?"
"Well, let's see..."
Turning OFF -fpic makes it link OK.

I think this is related to this thread:
https://www.lpcware.com/content/forum/bssinit-and-datainit-doesnt-work-fpic


So, the solution is to not use PIC. (someone else on the project was doing some experiments and checked it in)
0 Kudos

241 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Thu Sep 03 00:09:56 MST 2015
What do you actually mean by "coming up as 0x00" ?

Anyway it would be helpful if you could post the map file generated by the linker that goes with your linker script.

Also, can you add the "--verbose" option to

Project - Properties - C/C++ Build - Settings - MCU Linker - Miscellaneous - Other options


then do a rebuild and post the build log:

https://www.lpcware.com/content/faq/lpcxpresso/build-console

PS - you ought to be able to create a similar linker script via Managed Linker Scripts using a combination of the Memory Configuration Editor and some FreeMarker Linker Script Templates : https://www.lpcware.com/content/faq/lpcxpresso/freemarker-linker-script-templates

Regards,
LPCXpresso Support
0 Kudos