Skip to content

Conversation

@mrjimenez
Copy link
Contributor

zephyr_code_relocate() was not working for .noinit sections. In particular, it was not relocating network buffers to other RAM areas.

The __noinit macro was using quoted strings in the created section names like: .noinit."WEST_TOPDIR/path/file.c".symbol with embedded quotes.

GNU ld's KEEP() directive parses quoted strings as separate tokens, causing pattern matching to fail and preventing .noinit sections from being relocated to the target memory region.

The solution was to change the __noinit macro to avoid using double quotes to generate clean section names like .noinit.WEST_TOPDIR/path/file.c.symbol.

@pdgendt
Copy link
Contributor

pdgendt commented Dec 1, 2025

Possibly related #100221

@mrjimenez
Copy link
Contributor Author

Possibly related #100221

It is the same issue, but he has a different solution.

With my patch, I get this:

.dsram2_noinit_reloc
                0x00000000300007b0     0x4eac
                0x00000000300007b0                . = ALIGN (0x4)
 *net_pkt.c.obj(SORT_BY_ALIGNMENT(.noinit.WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c.0))
 .noinit.WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c.0
                0x00000000300007b0      0x508 zephyr/subsys/net/ip/libsubsys__net__ip.a(net_pkt.c.obj)
 *net_pkt.c.obj(SORT_BY_ALIGNMENT(.noinit.WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c.1))
 .noinit.WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c.1
                0x0000000030000cb8     0x1700 zephyr/subsys/net/ip/libsubsys__net__ip.a(net_pkt.c.obj)
 *net_pkt.c.obj(SORT_BY_ALIGNMENT(.noinit.WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c.2))
 .noinit.WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c.2
                0x00000000300023b8      0x2d8 zephyr/subsys/net/ip/libsubsys__net__ip.a(net_pkt.c.obj)
 *net_pkt.c.obj(SORT_BY_ALIGNMENT(.noinit.WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c.3))
 .noinit.WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c.3
                0x0000000030002690      0xd00 zephyr/subsys/net/ip/libsubsys__net__ip.a(net_pkt.c.obj)
 *net_pkt.c.obj(SORT_BY_ALIGNMENT(.noinit.WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c.k_mem_slab_buf_rx_pkts))
 .noinit.WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c.k_mem_slab_buf_rx_pkts
                0x0000000030003390     0x1a90 zephyr/subsys/net/ip/libsubsys__net__ip.a(net_pkt.c.obj)
                0x0000000030003390                _k_mem_slab_buf_rx_pkts
 *net_pkt.c.obj(SORT_BY_ALIGNMENT(.noinit.WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c.k_mem_slab_buf_tx_pkts))
 .noinit.WEST_TOPDIR/zephyr/subsys/net/ip/net_pkt.c.k_mem_slab_buf_tx_pkts
                0x0000000030004e20      0x83c zephyr/subsys/net/ip/libsubsys__net__ip.a(net_pkt.c.obj)
                0x0000000030004e20                _k_mem_slab_buf_tx_pkts
                0x000000003000565c                . = ALIGN (0x4)
                0x000000003000565c                __dsram2_noinit_reloc_end = .
                0x00000000300007b0                __dsram2_noinit_reloc_start = ADDR (.dsram2_noinit_reloc)
                0x0000000000004eac                __dsram2_noinit_reloc_size = (__dsram2_noinit_reloc_end - __dsram2_noinit_reloc_start)

This patch just formats the section_tags.h file before the real
patch, otherwise the changes would be hard to read.

Signed-off-by: Marcelo Roberto Jimenez <marcelo.jimenez@gmail.com>
zephyr_code_relocate() was not working for .noinit sections. In
particular, it was not relocating network buffers to other RAM
areas.

The __noinit macro was using quoted strings in the created section
names like:

.noinit."WEST_TOPDIR/path/file.c".symbol

with embedded quotes.

GNU ld's KEEP() directive parses quoted strings as separate tokens,
causing pattern matching to fail and preventing .noinit sections
from being relocated to the target memory region.

The solution was to change the __noinit macro to avoid using double
quotes to generate clean section names like:

.noinit.WEST_TOPDIR/path/file.c.symbol

Signed-off-by: Marcelo Roberto Jimenez <marcelo.jimenez@gmail.com>
@sonarqubecloud
Copy link

@iabdalkader
Copy link
Contributor

This is probably a better fix than mine. I hope that either one gets merged soon, as we're running out of RAM too and must move things around.

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.

5 participants