Linker ignores bss section AT/AT>

Bug #1905720 reported by Sivert on 2020-11-26
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
Undecided
Unassigned

Bug Description

When modifying the linker script to allocate space for .bss in "flash" with AT>, in the same way as you'd normally do for .data et al., the .bss section still does not allocate space in "flash":

Linker script excerpt:
    8 MEMORY
    9 {
   10 flash (rx) : ORIGIN = 0x08000000, LENGTH = 64K
   11 sram (rwx) : ORIGIN = 0x20000000, LENGTH = 8K
   12 }
...
   77 .bss : {
   78 PROVIDE(__bss_low = .);
   79 *(.bss)
   80 *(.bss*)
   81 *(COMMON)
   82 PROVIDE(__bss_high = .);
   83 } > sram AT> flash
   84
   85 PROVIDE(__bss_loadLow = LOADADDR(.bss));
   86 PROVIDE(__bss_loadHigh = LOADADDR(.bss) + SIZEOF(.bss));
   87
   88 .data : {
   89 PROVIDE(__data_low = .);
   90 *(.data*) /* Read-write initialized data */
   91 PROVIDE(__data_high = .);
   92 } > sram AT> flash
   93
   94 PROVIDE(__data_loadLow = LOADADDR(.data));
   95 PROVIDE(__data_loadHigh = LOADADDR(.data) + SIZEOF(.data));

From this, you'd expect .bss and .data to have similar allocation, however `arm-none-eabi-objdump -x bin.elf` shows:

   31 4 .bss 00000064 20000000 08000104 00020000 2**2
   32 ALLOC
   33 5 .data 00000064 20000064 08000104 00020064 2**2
   34 CONTENTS, ALLOC, LOAD, DATA

I.e. no space was allocated for .bss in flash.

Please find attached a testcase with source code and a prebuilt binary `bss-test.elf` as well as its objdump -x output in `bss-test.objdump`

The used build command is:
`arm-none-eabi-gcc -g -mcpu=cortex-m0 -mthumb -nostartfiles -Tcm0-AS.ld main.c cm0-vectors.c -o bss-test.elf`

Release version: 9-2019-q4-major) 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]
Rebuild/binary package: binary package
Host machine: Ubuntu 18.04
Error/warnings: none

ps. I know this is not the typical way to allocate uninitialized variables, but I have a specific use case where controlling the allocation for .bss is necessary. I do also have a workaround where I just allocate an empty section of size SIZEOF(.bss) in flash to create the desired allocation.

Sivert (sivertsliper) wrote :
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Bug attachments