Skip to content

Commit 36997de

Browse files
ibirnbaumfabiobaltieri
authored andcommitted
arch: aarch32: place .bss, .noinit sections at the end of the binary
This is a follow up to #53262, which still lacked the adjustment of the .noinit section's position within the binary by the time the PR went stale. Adjust the linker command file so that the .bss and .noinit sections are placed at the end of the resulting binary. Until now, those sections have been located somewhere in the middle of the binary, so that the inclusion of structures like statically defined heaps or large zero- initialized arrays reflected 1:1 in the resulting binary's size. Even for a stripped binary, such data was included in full as the linker couldn't omit it due to subsequent sections within the binary. This fix has been tested with a 32 MB statically allocated heap and a 32 MB uint8 zero-initialized array. Both structures are clearly identifyable in the memory consumption statistics, however, the final binary's size is unaffected by their inclusion. Signed-off-by: Immo Birnbaum <[email protected]>
1 parent d36697a commit 36997de

File tree

1 file changed

+32
-30
lines changed
  • include/zephyr/arch/arm/aarch32/cortex_a_r/scripts

1 file changed

+32
-30
lines changed

include/zephyr/arch/arm/aarch32/cortex_a_r/scripts/linker.ld

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
#endif
2727
#define RAMABLE_REGION RAM
2828

29+
/* section alignment directive, valid only if not running in XIP mode */
30+
#ifndef CONFIG_XIP
31+
#define SECTION_ALIGN ALIGN(_region_min_align)
32+
#else
33+
#define SECTION_ALIGN
34+
#endif
35+
2936
#if !defined(CONFIG_XIP) && (CONFIG_FLASH_SIZE == 0)
3037
#define ROM_ADDR RAM_ADDR
3138
#else
@@ -73,8 +80,6 @@ _region_min_align = 4;
7380
. = ALIGN(_region_min_align)
7481
#endif
7582

76-
#define BSS_ALIGN ALIGN(_region_min_align)
77-
7883
MEMORY
7984
{
8085
FLASH (rx) : ORIGIN = ROM_ADDR, LENGTH = ROM_SIZE
@@ -266,35 +271,10 @@ SECTIONS
266271
_app_smem_rom_start = LOADADDR(_APP_SMEM_SECTION_NAME);
267272
#endif /* CONFIG_USERSPACE */
268273

269-
SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD), BSS_ALIGN)
270-
{
271-
/*
272-
* For performance, BSS section is assumed to be 4 byte aligned and
273-
* a multiple of 4 bytes
274-
*/
275-
. = ALIGN(4);
276-
__bss_start = .;
277-
__kernel_ram_start = .;
278-
279-
*(.bss)
280-
*(".bss.*")
281-
*(COMMON)
282-
*(".kernel_bss.*")
283-
284-
#ifdef CONFIG_CODE_DATA_RELOCATION
285-
#include <linker_sram_bss_relocate.ld>
286-
#endif
287-
288-
/*
289-
* As memory is cleared in words only, it is simpler to ensure the BSS
290-
* section ends on a 4 byte boundary. This wastes a maximum of 3 bytes.
291-
*/
292-
__bss_end = ALIGN(4);
293-
} GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)
294-
295-
#include <zephyr/linker/common-noinit.ld>
274+
. = ALIGN(_region_min_align);
275+
__kernel_ram_start = .;
296276

297-
SECTION_DATA_PROLOGUE(_DATA_SECTION_NAME,,)
277+
SECTION_DATA_PROLOGUE(_DATA_SECTION_NAME,,SECTION_ALIGN)
298278
{
299279
__data_region_start = .;
300280
__data_start = .;
@@ -328,7 +308,29 @@ SECTIONS
328308
#include <snippets-data-sections.ld>
329309

330310
__data_region_end = .;
311+
. = ALIGN(_region_min_align);
312+
313+
SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD), SECTION_ALIGN)
314+
{
315+
__bss_start = .;
316+
317+
*(.bss)
318+
*(".bss.*")
319+
*(COMMON)
320+
*(".kernel_bss.*")
331321

322+
#ifdef CONFIG_CODE_DATA_RELOCATION
323+
#include <linker_sram_bss_relocate.ld>
324+
#endif
325+
326+
/*
327+
* As memory is cleared in words only, it is simpler to ensure the BSS
328+
* section ends on a 4 byte boundary. This wastes a maximum of 3 bytes.
329+
*/
330+
__bss_end = ALIGN(4);
331+
} GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)
332+
333+
#include <zephyr/linker/common-noinit.ld>
332334

333335
/* Define linker symbols */
334336

0 commit comments

Comments
 (0)