binfmt: parse application stacksize/priority from ELF symbols#19440
Merged
Conversation
Add libelf_findsymbol() to locate a symbol in the ELF symbol table by name, reusing the existing libelf_findsymtab/libelf_readsym/libelf_symname helpers, and expose its prototype in include/nuttx/lib/elf.h. Signed-off-by: anjiahao <[email protected]>
Parse application attributes (stacksize, priority, and uid/gid/mode under CONFIG_SCHED_USER_IDENTITY) from absolute symbols (nx_stacksize, nx_priority, nx_uid, nx_gid, nx_mode) embedded in the ELF at link time, falling back to defaults when the symbols are absent. Signed-off-by: anjiahao <[email protected]>
posix_spawnattr_init() no longer pre-fills attr->stacksize and attr->priority (it leaves them zero, as memset already does). When a caller does not set them, the binary loader supplies them from the loaded ELF (binp->stacksize / binp->priority, parsed from the nx_* symbols), and nxtask_spawn_exec() falls back to the parent priority and CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE for the posix_spawn() function-task path. This lets an application's stack size and priority embedded as ELF symbols actually drive the spawned task, instead of being overridden by the spawnattr defaults. Signed-off-by: anjiahao <[email protected]>
5 tasks
xiaoxiang781216
approved these changes
Jul 15, 2026
jerpelea
approved these changes
Jul 15, 2026
|
Contributor
|
@raiden00pl nucleo-f302r8/ihm07m1_b16 is overflowing again, maybe we need to remove this board, end of life for NuttX on it. :-( |
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
as absolute ELF symbols (
nx_stacksize,nx_priority, andnx_uid/nx_gid/nx_modeunderCONFIG_SCHED_USER_IDENTITY) and readback by the binary loader at exec time, instead of always falling back
to
CONFIG_ELF_STACKSIZE/SCHED_PRIORITY_DEFAULT.libelf_findsymbol()(a name-based symbol lookup over the ELFsymbol table) in
libs/libc/elf/elf_symbols.cand declares it ininclude/nuttx/lib/elf.h;binfmt/elf.cuses it to populatestruct binary_s(binp->stacksize/priority/uid/gid/mode),falling back to the existing defaults when a symbol is absent.
cmake/nuttx_add_application.cmakeemits the--defsym nx_*flags atlink time.
posix_spawnattr_init()no longer pre-fillsattr->stacksizeandattr->priority(left at 0);nxtask_spawn_exec()fills the parentpriority and
CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZEwhen a caller doesnot set them. This stops the spawnattr defaults from overriding the
values parsed from the ELF, so the embedded symbols actually drive the
spawned task.
Impact
application attributes are parsed from ELF symbols and used by the
binary loader.
are optional; when absent the loader keeps using the existing defaults
(
CONFIG_ELF_STACKSIZE,SCHED_PRIORITY_DEFAULT).link now emits
--defsym nx_stacksize/nx_priority(andnx_uid/nx_gid/nx_modeunderCONFIG_SCHED_USER_IDENTITY); handled in thecompanion apps PR via
Application.mk.posix_spawnattr_init()callers that relied on the old stacksize/priority defaults still get them filled in by
nxtask_spawn_exec()/the binary loader, so observable defaults are unchanged; only apps that
embed the
nx_*symbols change behavior (they now honor their ownconfigured values).
heapsizeattribute from theoriginal implementation is intentionally not included (it depends on
the separate task-heap feature).
Testing
I confirm that changes are verified on local setup and works as intended:
qemu-armv7a:knsh(CONFIG_BUILD_KERNEL, CONFIG_ELF=y)./tools/configure.sh qemu-armv7a:knsh && make && make export(apps built separately and mounted via hostfs as
/system).qemu-system-arm -semihosting -M virt -m 1024 -nographic -kernel ./nuttxTesting logs before change (stock upstream/master nuttx; the
getprimeapp was built with
--defsym nx_stacksize=8192 --defsym nx_priority=50,but the symbol is not consulted, so the task uses the defaults — stack
4096, priority 100):
Testing logs after change (this PR; same
getprimeapp — the ELF symbolsnow drive the task: stack ≈ 8192, priority 50):
hello,ostest, and NSH itself continue to load and run; no regressionobserved on
knsh.PR verification Self-Check