include/nuttx: Add link-time iterable sections infrastructure - #19927
Open
JorgeGzm wants to merge 1 commit into
Open
include/nuttx: Add link-time iterable sections infrastructure#19927JorgeGzm wants to merge 1 commit into
JorgeGzm wants to merge 1 commit into
Conversation
Add generic support for link-time registration of struct instances, modeled after the Zephyr STRUCT_SECTION_* mechanism: - include/nuttx/iterable_sections.h: STRUCT_SECTION_ITERABLE/FOREACH/ GET/COUNT macros placing instances in name-sorted linker sections delimited by _<type>_list_start/_end symbols. - include/nuttx/linker/iterable_sections.ld: ITERABLE_SECTION() macro emitting the KEEP + SORT_BY_NAME collection statements (linker scripts in ARCHSCRIPT are CPP-preprocessed). - include/nuttx/linker/common-rom.ld / common-ram.ld: central aggregators meant to be included by board linker scripts (inside .text and .data respectively). Subsystem blocks are registered here guarded by their Kconfig options, so the fragments expand to nothing on configurations that do not use them; the first registered block is the zbus message bus (CONFIG_ZBUS, from nuttx-apps), mirroring how the Zephyr common-rom.ld carries the per-subsystem guarded blocks. - Documentation/components/iterable_sections.rst. First user: the Zephyr zbus message bus port (apps/system/zbus in nuttx-apps); its board integration comes in a companion PR. Signed-off-by: Jorge Guzman <jorge.gzm@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds link-time registration of struct instances ("iterable
sections"), modeled after the Zephyr
STRUCT_SECTION_*mechanism: aninstance defined with
STRUCT_SECTION_ITERABLEin any compilation unitis 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.ldandcommon-rom.ld/common-ram.ld: central linker fragments. A boardopts in by adding two
#includelines to its linker script (they areCPP-preprocessed via
ARCHSCRIPT, with upstream precedent inqemu-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
references them yet, and the fragments are Kconfig-guarded no-ops).
static registration.
Testing
Host: Ubuntu 24.04.4 x86_64, arm-none-eabi-gcc 13.2.1 (GNU ld 2.41).
Target: linum-stm32h753bi (STM32H753BI).
linum-stm32h753bi:nshbuild: unchanged, no iterable sectionsin the map (no-op proof).
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 asCI): all checks pass.
sphinx-build -Won this branch alone: clean.