include/nuttx: Add link-time iterable sections infrastructure

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/DECLARE/
  FOREACH/GET/COUNT macros placing instances in name-sorted linker
  sections delimited by _<type>_list_start/_end symbols (attributes
  through the nuttx/compiler.h macros; FOREACH takes a caller-declared
  iterator, like list_for_every_entry).
- 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); subsystems register their sections
  here guarded by their Kconfig options, so the fragments expand to
  nothing on configurations that do not use them.
- CONFIG_ITERABLE_SECTIONS_LINKER_INSERT + include/nuttx/linker/
  common-insert.ld (added before the board script by tools/Config.mk and
  by the top-level CMakeLists.txt): optional zero-touch mode that
  supplements the board script through GNU ld INSERT AFTER, collecting
  the subsystems' ITERABLE_SECTION blocks in one output section; the
  common-rom.ld/common-ram.ld fragments expand to nothing in that mode.
  See the option help for the constraints.
- 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 commit is contained in:
Jorge Guzman 2026-08-21 14:24:11 -03:00 committed by Xiang Xiao
parent 71610ddac0
commit 7cd511fed2
10 changed files with 531 additions and 0 deletions

View file

@ -861,3 +861,17 @@ LOWERMAP = A a B b C c D d E e F f G g H h I i J j K k L l M m N n O o P p Q q R
UPPER_CASE = $(call ULMAP,$(UPPERMAP),$(1))
LOWER_CASE = $(call ULMAP,$(LOWERMAP),$(1))
# Iterable sections "zero-touch" mode: supplement the board linker script
# with the central INSERT fragment (include/nuttx/linker/common-insert.ld,
# which collects the per-subsystem iterable sections) instead of requiring
# the board script to include common-rom.ld.
#
# The fragment is added through ARCHSCRIPT (not EXTRALINKCMDS) because GNU
# ld requires the INSERT script to come BEFORE the script that defines the
# target section on the command line; this file is included by the board
# Make.defs before it appends its own script, so the fragment lands first.
ifeq ($(CONFIG_ITERABLE_SECTIONS_LINKER_INSERT),y)
ARCHSCRIPT += $(TOPDIR)$(DELIM)include$(DELIM)nuttx$(DELIM)linker$(DELIM)common-insert.ld
endif