Skip to content

Commit

Permalink
arch: arm: cortex_m: Move bss/noinit sections to the end of linker sc…
Browse files Browse the repository at this point in the history
…ript

This results in a smaller binary with CONFIG_XIP=n as these NOLOAD
sections can be excluded.

bss/noinit have been included in CONFIG_XIP=n binaries by default since
c107827. This also occurs if using
iterable sections or adding code/data to ITCM/DTCM sections.
Moving bss/noinit to the end of the linker file should ensure they are
always excluded

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
  • Loading branch information
gramsay0 authored and kartben committed Dec 23, 2024
1 parent 27615a7 commit b1c678f
Showing 1 changed file with 54 additions and 54 deletions.
108 changes: 54 additions & 54 deletions include/zephyr/arch/arm/cortex_m/scripts/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -346,56 +346,6 @@ SECTIONS

__data_region_end = .;

#ifndef CONFIG_USERSPACE
SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),)
{
/*
* For performance, BSS section is assumed to be 4 byte aligned and
* a multiple of 4 bytes
*/
. = ALIGN(4);
__bss_start = .;
__kernel_ram_start = .;

*(.bss)
*(".bss.*")
*(COMMON)
*(".kernel_bss.*")

#ifdef CONFIG_CODE_DATA_RELOCATION
#include <linker_sram_bss_relocate.ld>
#endif

/*
* As memory is cleared in words only, it is simpler to ensure the BSS
* section ends on a 4 byte boundary. This wastes a maximum of 3 bytes.
*/
__bss_end = ALIGN(4);
} GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)

SECTION_PROLOGUE(_NOINIT_SECTION_NAME,(NOLOAD),)
{
/*
* This section is used for non-initialized objects that
* will not be cleared during the boot process.
*/
*(.noinit)
*(".noinit.*")
*(".kernel_noinit.*")

/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function.
*/
#include <snippets-noinit.ld>

} GROUP_NOLOAD_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)
#endif /* CONFIG_USERSPACE */

/* Define linker symbols */

__kernel_ram_end = RAM_ADDR + RAM_SIZE;
__kernel_ram_size = __kernel_ram_end - __kernel_ram_start;

#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay)
GROUP_START(ITCM)

Expand Down Expand Up @@ -463,10 +413,6 @@ GROUP_END(DTCM)
*/
#include <snippets-sections.ld>

#include <zephyr/linker/ram-end.ld>

GROUP_END(RAMABLE_REGION)

#include <zephyr/linker/debug-sections.ld>

/DISCARD/ : { *(.note.GNU-stack) }
Expand Down Expand Up @@ -503,4 +449,58 @@ SECTION_PROLOGUE(.last_section,,)
* calculate this value here. */
_flash_used = LOADADDR(.last_section) + SIZEOF(.last_section) - __rom_region_start;

#ifndef CONFIG_USERSPACE
SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),)
{
/*
* For performance, BSS section is assumed to be 4 byte aligned and
* a multiple of 4 bytes
*/
. = ALIGN(4);
__bss_start = .;
__kernel_ram_start = .;

*(.bss)
*(".bss.*")
*(COMMON)
*(".kernel_bss.*")

#ifdef CONFIG_CODE_DATA_RELOCATION
#include <linker_sram_bss_relocate.ld>
#endif

/*
* As memory is cleared in words only, it is simpler to ensure the BSS
* section ends on a 4 byte boundary. This wastes a maximum of 3 bytes.
*/
__bss_end = ALIGN(4);
} GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)

SECTION_PROLOGUE(_NOINIT_SECTION_NAME,(NOLOAD),)
{
/*
* This section is used for non-initialized objects that
* will not be cleared during the boot process.
*/
*(.noinit)
*(".noinit.*")
*(".kernel_noinit.*")

/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function.
*/
#include <snippets-noinit.ld>

} GROUP_NOLOAD_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)
#endif /* CONFIG_USERSPACE */

/* Define linker symbols */

__kernel_ram_end = RAM_ADDR + RAM_SIZE;
__kernel_ram_size = __kernel_ram_end - __kernel_ram_start;

#include <zephyr/linker/ram-end.ld>

GROUP_END(RAMABLE_REGION)

}

0 comments on commit b1c678f

Please sign in to comment.