Skip to content

Conversation

@iabdalkader
Copy link
Contributor

ld seems to treat quotes in section names as literal characters, which makes it fail to match section names outputted by this script. This fix replaces quoted section names with a wildcard, which matches the section correctly.

Context: I'm trying to relocate the kernel heap to another SRAM, using CONFIG_CODE_DATA_RELOCATION. In CMakeLists.txt I have the following:

zephyr_code_relocate(FILES ${ZEPHYR_BASE}/kernel/mempool.c LOCATION SRAM2_BSS_NOINIT)

The generated linker scripts seems to have the right section in SRAM2. Note that the section name is quoted:

 .sram2_noinit_reloc (NOLOAD) :
        {
                . = ALIGN(4);
                KEEP(*mempool.c.obj(.noinit."WEST_TOPDIR/zephyr/kernel/mempool.c".kheap_buf__system_heap))
                . = ALIGN(4);
 } > SRAM2 AT > SRAM2

In the final elf, the section is empty because ld fails to match it:

  .sram2_noinit_reloc
                  0x0000000030020000        0x0
                  0x0000000030020000                . = ALIGN (0x4)
   *mempool.c.obj(SORT_BY_ALIGNMENT(.noinit.) SORT_BY_ALIGNMENT(WEST_TOPDIR/zephyr/kernel/mempool.c)

With this patch:

.sram2_noinit_reloc
                0x0000000030020000    0x20000
                0x0000000030020000                . = ALIGN (0x4)
 *mempool.c.obj(SORT_BY_ALIGNMENT(.noinit.*.kheap_buf__system_heap))
 .noinit."WEST_TOPDIR/zephyr/kernel/mempool.c".kheap_buf__system_heap

ld seems to treat quotes in section names as literal characters, which
makes it fail to match section names outputted by this script. For example,
the following section name, generated with CONFIG_CODE_DATA_RELOCATION to
relocate noinit section, fails to match the section, causing it to Not be
relocated:

KEEP(*file.c.obj(.noinit."WEST_TOPDIR/path/file.c".symbol))

This fix replaces quoted section names with a wildcard, which matches
the section correctly.

Signed-off-by: Ibrahim Abdalkader <[email protected]>
@iabdalkader iabdalkader force-pushed the fix_reloc_section_name branch from e0c5902 to 0c914f6 Compare November 28, 2025 15:39
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants