JorgeGzm opened a new pull request, #19927:
URL: https://github.com/apache/nuttx/pull/19927
## Summary
This PR adds **link-time registration of struct instances** ("iterable
sections"), modeled after the Zephyr `STRUCT_SECTION_*` mechanism: an
instance defined with `STRUCT_SECTION_ITERABLE` in any compilation unit
is collected by the linker into a contiguous, name-sorted array that can
be iterated like a plain C array. No runtime registration calls, no
central list to maintain, zero RAM overhead for the registry.
- `include/nuttx/iterable_sections.h`: the C API
(`STRUCT_SECTION_ITERABLE/FOREACH/GET/COUNT`).
- `include/nuttx/linker/iterable_sections.ld` and
`common-rom.ld`/`common-ram.ld`: central linker fragments. A board
opts in by adding two `#include` lines to its linker script (they are
CPP-preprocessed via `ARCHSCRIPT`, with upstream precedent in
qemu-armv7a and nRF52/91 boards). Each subsystem block inside the
fragments is guarded by its Kconfig option, so they expand to nothing
on configurations that do not use them: a **no-op** for every existing
board and config.
- `Documentation/components/iterable_sections.rst`: full documentation,
including how to add a new iterable type.
In the future, a common include of these fragments by the board linker
scripts can be considered: beyond the zbus port that uses this mechanism
today, it would open the same advantage to other routines that need
static registries (driver tables, init sequences, test registration),
with no per-board work.
Split out of #19916 (first user: the zbus message bus port,
apache/nuttx-apps#3743).
## Impact
- **Existing boards/configs: none** (new files only; nothing in-tree
references them yet, and the fragments are Kconfig-guarded no-ops).
- **Users:** new documented component for any subsystem that needs
static registration.
- **Security / compatibility:** no runtime code.
## Testing
Host: Ubuntu 24.04.4 x86_64, arm-none-eabi-gcc 13.2.1 (GNU ld 2.41).
Target: linum-stm32h753bi (STM32H753BI).
- Stock `linum-stm32h753bi:nsh` build: unchanged, no iterable sections
in the map (no-op proof).
- Full stack with the zbus companion PRs on hardware: the linker
collects the three zbus sections name-sorted in flash and the 16-test
zbus cmocka suite passes twice in the same boot (logs in the companion
PRs).
- `tools/checkpatch.sh -c -u -m -g` (nxstyle + codespell, same flags as
CI): all checks pass. `sphinx-build -W` on this branch alone: clean.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]