2024-01-21 12:04 AM
Hi guys,
I have a weird problem with armgcc and the linker files. I took the linker file provided by st and extended it by external ram and two more sections for bss and data placed in external ram.
Now this is the relevant snippet out of the linker file:
_MEM_LD_DATA_EXT_LOAD = LOADADDR(.external_data);
.external_data :
{
. = ALIGN(4);
_MEM_LD_DATA_EXT_START = .;
*(.external_data)
INCLUDE custom_sections_data.ld
. = ALIGN(4);
_MEM_LD_DATA_EXT_END = .;
} >ERAM AT> FLASH
. = ALIGN(4);
.external_bss :
{
_MEM_LD_BSS_EXT_START = .;
*(.external_bss)
INCLUDE custom_sections_bss.ld
. = ALIGN(4);
_MEM_LD_BSS_EXT_END = .;
} >ERAM
_MEM_LD_DATA_LOAD = LOADADDR(.data);
.data :
{
. = ALIGN(4);
_MEM_LD_DATA_START = .;
*(.data);
*(.data*);
*(.RamFunc);
*(.RamFunc*);
. = ALIGN(4);
_MEM_LD_DATA_END = .;
} >RAM AT> FLASH
. = ALIGN(4);
.bss :
{
_MEM_LD_BSS_START = .;
*(.bss);
*(.bss*);
*(COMMON);
. = ALIGN(4);
_MEM_LD_BSS_END = .;
} >RAM
._user_heap_stack :
{
. = ALIGN(8);
PROVIDE(end = .);
PROVIDE(_end = .);
. = . + _MEM_HEAP_SIZE;
. = . + _MEM_STACK_SIZE;
. = ALIGN(8);
} >RAM
This is the output of objdump on the elf file:
Sections:
Idx Name Size VMA LMA File off Algn
0 .flash_version 00000200 08040000 08040000 00001000 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .isr_vector 000002cc 08040400 08040400 00001400 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .exflash_version_info 00000200 90000000 90000000 00050000 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .external_rodata 00000000 90000400 90000400 00050200 2**0
CONTENTS
4 .external_text 00000000 90000400 90000400 00050200 2**0
CONTENTS
5 .text 00026f9c 08040700 08040700 00001700 2**6
CONTENTS, ALLOC, LOAD, READONLY, CODE
6 .rodata 00012068 080676a0 080676a0 000286a0 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
7 .extra 00000000 08079708 08079708 00050200 2**0
CONTENTS
8 .ARM 00000008 08079708 08079708 0003a708 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
9 .preinit_array 00000000 08079710 08079710 00050200 2**0
CONTENTS, ALLOC, LOAD, DATA
10 .init_array 00000008 08079710 08079710 0003a710 2**2
CONTENTS, ALLOC, LOAD, DATA
11 .fini_array 00000004 08079718 08079718 0003a718 2**2
CONTENTS, ALLOC, LOAD, DATA
12 .ARM.attributes 0000002e 00000000 00000000 00050200 2**0
CONTENTS, READONLY
13 .external_data 00002710 c0000000 0807971c 0003b000 2**2
CONTENTS, ALLOC, LOAD, DATA
14 .external_bss 00007530 c0002710 0807be2c 0003d710 2**2
CONTENTS, ALLOC, LOAD, DATA
15 .data 0000a424 24000000 0808335c 00045000 2**3
CONTENTS, ALLOC, LOAD, DATA
16 .bss 000359b0 2400a428 0808d780 0004f428 2**3
ALLOC
17 ._user_heap_stack 00006000 2403fdd8 0808d780 0004fdd8 2**0
ALLOC
18 .debug_frame 0000b820 00000000 00000000 00050230 2**2
CONTENTS, READONLY, DEBUGGING, OCTETS
19 .debug_info 00068029 00000000 00000000 0005ba50 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
20 .debug_abbrev 0000e817 00000000 00000000 000c3a79 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
21 .debug_aranges 00003830 00000000 00000000 000d2290 2**3
CONTENTS, READONLY, DEBUGGING, OCTETS
22 .debug_ranges 000042e0 00000000 00000000 000d5ac0 2**3
CONTENTS, READONLY, DEBUGGING, OCTETS
23 .debug_macro 0003bc2c 00000000 00000000 000d9da0 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
24 .debug_line 000581b2 00000000 00000000 001159cc 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
25 .debug_str 0010fd01 00000000 00000000 0016db7e 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
26 .comment 00000044 00000000 00000000 0027d87f 2**0
CONTENTS, READONLY
27 .debug_loc 00038592 00000000 00000000 0027d8c3 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
28 .debug_line_str 000001ec 00000000 00000000 002b5e55 2**0
CONTENTS, READONLY, DEBUGGING, OCTETS
and this is a section from the map file:
.external_data 0xc0000000 0x2710 load address 0x0807971c
0xc0000000 . = ALIGN (0x4)
0xc0000000 _MEM_LD_DATA_EXT_START = .
*(.external_data)
.external_data
0xc0000000 0x2710 main.c.obj
0xc0002710 . = ALIGN (0x4)
0xc0002710 _MEM_LD_DATA_EXT_END = .
0xc0002710 . = ALIGN (0x4)
.external_bss 0xc0002710 0x7530 load address 0x0807be2c
0xc0002710 _MEM_LD_BSS_EXT_START = .
*(.external_bss)
.external_bss 0xc0002710 0x7530 main.c.obj
0xc0009c40 . = ALIGN (0x4)
0xc0009c40 _MEM_LD_BSS_EXT_END = .
0x0808335c _MEM_LD_DATA_LOAD = LOADADDR (.data)
.data 0x24000000 0xa424 load address 0x0808335c
0x24000000 . = ALIGN (0x4)
0x24000000 _MEM_LD_DATA_START = .
*(.data)
*(.data*)
....
.bss 0x2400a428 0x359b0 load address 0x0808d780
0x2400a428 _MEM_LD_BSS_START = .
*(.bss)
*(.bss*)
._user_heap_stack 0x2403fdd8 0x6000 load address 0x0808d780
0x2403fdd8 . = ALIGN (0x8)
[!provide] PROVIDE (end = .)
0x2403fdd8 PROVIDE (_end = .)
0x24041dd8 . = (. + _MEM_HEAP_SIZE)
*fill* 0x2403fdd8 0x2000
0x24045dd8 . = (. + _MEM_STACK_SIZE)
*fill* 0x24041dd8 0x4000
Now there are several weird behaviours and problems that i do not understand.
The sections .external_bss, .bss and ._user_heap_stack all do have a load address in the FLASH but only .data and .external_data should have.
This seems to be rather cosmetic - the real problem is .external_bss which really takes space in FLASH as well as .external_data despite it shouldn't.
If I switch places for .external_data and .external_bss sections like so, that does not happen - and I don't understand why:
. = ALIGN(4);
.external_bss :
{
_MEM_LD_BSS_EXT_START = .;
*(.external_bss)
INCLUDE custom_sections_bss.ld
. = ALIGN(4);
_MEM_LD_BSS_EXT_END = .;
} >ERAM
_MEM_LD_DATA_EXT_LOAD = LOADADDR(.external_data);
.external_data :
{
. = ALIGN(4);
_MEM_LD_DATA_EXT_START = .;
*(.external_data)
INCLUDE custom_sections_data.ld
. = ALIGN(4);
_MEM_LD_DATA_EXT_END = .;
} >ERAM AT> FLASH
2024-01-21 06:32 AM
AFAIK, in gcc, if section attribute is used for data, the data is treated as .data, not as .bss (even if it is not initialized or zero-initialized).