Skip to content

Commit 119b7fe

Browse files
committed
arch: arm: cortex_m: Move bss/noinit sections to the end of linker script
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 <[email protected]>
1 parent d78a942 commit 119b7fe

File tree

1 file changed

+54
-54
lines changed
  • include/zephyr/arch/arm/cortex_m/scripts

1 file changed

+54
-54
lines changed

include/zephyr/arch/arm/cortex_m/scripts/linker.ld

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -353,56 +353,6 @@ SECTIONS
353353

354354
__data_region_end = .;
355355

356-
#ifndef CONFIG_USERSPACE
357-
SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),)
358-
{
359-
/*
360-
* For performance, BSS section is assumed to be 4 byte aligned and
361-
* a multiple of 4 bytes
362-
*/
363-
. = ALIGN(4);
364-
__bss_start = .;
365-
__kernel_ram_start = .;
366-
367-
*(.bss)
368-
*(".bss.*")
369-
*(COMMON)
370-
*(".kernel_bss.*")
371-
372-
#ifdef CONFIG_CODE_DATA_RELOCATION
373-
#include <linker_sram_bss_relocate.ld>
374-
#endif
375-
376-
/*
377-
* As memory is cleared in words only, it is simpler to ensure the BSS
378-
* section ends on a 4 byte boundary. This wastes a maximum of 3 bytes.
379-
*/
380-
__bss_end = ALIGN(4);
381-
} GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)
382-
383-
SECTION_PROLOGUE(_NOINIT_SECTION_NAME,(NOLOAD),)
384-
{
385-
/*
386-
* This section is used for non-initialized objects that
387-
* will not be cleared during the boot process.
388-
*/
389-
*(.noinit)
390-
*(".noinit.*")
391-
*(".kernel_noinit.*")
392-
393-
/* Located in generated directory. This file is populated by the
394-
* zephyr_linker_sources() Cmake function.
395-
*/
396-
#include <snippets-noinit.ld>
397-
398-
} GROUP_NOLOAD_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)
399-
#endif /* CONFIG_USERSPACE */
400-
401-
/* Define linker symbols */
402-
403-
__kernel_ram_end = RAM_ADDR + RAM_SIZE;
404-
__kernel_ram_size = __kernel_ram_end - __kernel_ram_start;
405-
406356
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay)
407357
GROUP_START(ITCM)
408358

@@ -470,10 +420,6 @@ GROUP_END(DTCM)
470420
*/
471421
#include <snippets-sections.ld>
472422

473-
#include <zephyr/linker/ram-end.ld>
474-
475-
GROUP_END(RAMABLE_REGION)
476-
477423
#include <zephyr/linker/debug-sections.ld>
478424

479425
/DISCARD/ : { *(.note.GNU-stack) }
@@ -510,4 +456,58 @@ SECTION_PROLOGUE(.last_section,,)
510456
* calculate this value here. */
511457
_flash_used = LOADADDR(.last_section) + SIZEOF(.last_section) - __rom_region_start;
512458

459+
#ifndef CONFIG_USERSPACE
460+
SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),)
461+
{
462+
/*
463+
* For performance, BSS section is assumed to be 4 byte aligned and
464+
* a multiple of 4 bytes
465+
*/
466+
. = ALIGN(4);
467+
__bss_start = .;
468+
__kernel_ram_start = .;
469+
470+
*(.bss)
471+
*(".bss.*")
472+
*(COMMON)
473+
*(".kernel_bss.*")
474+
475+
#ifdef CONFIG_CODE_DATA_RELOCATION
476+
#include <linker_sram_bss_relocate.ld>
477+
#endif
478+
479+
/*
480+
* As memory is cleared in words only, it is simpler to ensure the BSS
481+
* section ends on a 4 byte boundary. This wastes a maximum of 3 bytes.
482+
*/
483+
__bss_end = ALIGN(4);
484+
} GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)
485+
486+
SECTION_PROLOGUE(_NOINIT_SECTION_NAME,(NOLOAD),)
487+
{
488+
/*
489+
* This section is used for non-initialized objects that
490+
* will not be cleared during the boot process.
491+
*/
492+
*(.noinit)
493+
*(".noinit.*")
494+
*(".kernel_noinit.*")
495+
496+
/* Located in generated directory. This file is populated by the
497+
* zephyr_linker_sources() Cmake function.
498+
*/
499+
#include <snippets-noinit.ld>
500+
501+
} GROUP_NOLOAD_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)
502+
#endif /* CONFIG_USERSPACE */
503+
504+
/* Define linker symbols */
505+
506+
__kernel_ram_end = RAM_ADDR + RAM_SIZE;
507+
__kernel_ram_size = __kernel_ram_end - __kernel_ram_start;
508+
509+
#include <zephyr/linker/ram-end.ld>
510+
511+
GROUP_END(RAMABLE_REGION)
512+
513513
}

0 commit comments

Comments
 (0)