This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 0178ceab192626b9f3545ce3263d9ab02435c345 Author: anjiahao <[email protected]> AuthorDate: Wed Jul 15 16:10:08 2026 +0800 elf:use elf symbol to parse attribute 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]> --- binfmt/elf.c | 53 ++++++++++++++++++++++++++++++++++++++- cmake/nuttx_add_application.cmake | 28 ++++++++++++++++++++- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/binfmt/elf.c b/binfmt/elf.c index cfe146cb26e..fc896300538 100644 --- a/binfmt/elf.c +++ b/binfmt/elf.c @@ -98,6 +98,7 @@ static int elf_loadbinary(FAR struct binary_s *binp, int nexports) { struct mod_loadinfo_s loadinfo; + Elf_Sym sym; int ret; binfo("Loading file: %s\n", filename); @@ -173,7 +174,57 @@ static int elf_loadbinary(FAR struct binary_s *binp, /* Return the load information */ - binp->stacksize = CONFIG_ELF_STACKSIZE; + ret = libelf_findsymbol(&loadinfo, "nx_stacksize", &sym); + if (ret == 0) + { + binp->stacksize = sym.st_value; + } + else + { + binp->stacksize = CONFIG_ELF_STACKSIZE; + } + + ret = libelf_findsymbol(&loadinfo, "nx_priority", &sym); + if (ret == 0) + { + binp->priority = sym.st_value; + } + else + { + binp->priority = SCHED_PRIORITY_DEFAULT; + } + +#ifdef CONFIG_SCHED_USER_IDENTITY + ret = libelf_findsymbol(&loadinfo, "nx_uid", &sym); + if (ret == 0) + { + binp->uid = sym.st_value; + } + else + { + binp->uid = 0; + } + + ret = libelf_findsymbol(&loadinfo, "nx_gid", &sym); + if (ret == 0) + { + binp->gid = sym.st_value; + } + else + { + binp->gid = 0; + } + + ret = libelf_findsymbol(&loadinfo, "nx_mode", &sym); + if (ret == 0) + { + binp->mode = sym.st_value; + } + else + { + binp->mode = 0; + } +#endif /* Add the ELF allocation to the alloc[] only if there is no address * environment. If there is an address environment, it will automatically diff --git a/cmake/nuttx_add_application.cmake b/cmake/nuttx_add_application.cmake index c0b147452a3..7e26894ed18 100644 --- a/cmake/nuttx_add_application.cmake +++ b/cmake/nuttx_add_application.cmake @@ -147,6 +147,31 @@ function(nuttx_add_application) if(NOT "${CMAKE_LD}" MATCHES "gcc$") set(USE_LINKER True) endif() + if(STACKSIZE) + set(SYMBOL_STACKSIZE $<$<NOT:$<BOOL:${USE_LINKER}>>:-Wl,>--defsym + nx_stacksize=${STACKSIZE}) + endif() + if(PRIORITY) + if(PRIORITY STREQUAL "SCHED_PRIORITY_DEFAULT") + set(PRIORITY "0") + endif() + set(SYMBOL_PRIORITY $<$<NOT:$<BOOL:${USE_LINKER}>>:-Wl,>--defsym + nx_priority=${PRIORITY}) + endif() + if(CONFIG_SCHED_USER_IDENTITY) + if(UID) + set(SYMBOL_UID $<$<NOT:$<BOOL:${USE_LINKER}>>:-Wl,>--defsym + nx_uid=${UID}) + endif() + if(GID) + set(SYMBOL_GID $<$<NOT:$<BOOL:${USE_LINKER}>>:-Wl,>--defsym + nx_gid=${GID}) + endif() + if(MODE) + set(SYMBOL_MODE $<$<NOT:$<BOOL:${USE_LINKER}>>:-Wl,>--defsym + nx_mode=${MODE}) + endif() + endif() add_custom_command( TARGET ${TARGET} POST_BUILD @@ -158,7 +183,8 @@ function(nuttx_add_application) # add global ELF link option if m&kernel link $<$<OR:$<BOOL:${KERNEL_ELF_MODE}>,$<BOOL:${LOADABLE_ELF_MODE}>>:$<TARGET_PROPERTY:nuttx_global,NUTTX_ELF_APP_LINK_OPTIONS>> # add local link option last - ${LINK_FLAGS} + ${LINK_FLAGS} ${SYMBOL_STACKSIZE} ${SYMBOL_PRIORITY} ${SYMBOL_UID} + ${SYMBOL_GID} ${SYMBOL_MODE} # link startup obj if m&kernel link $<$<AND:$<TARGET_EXISTS:STARTUP_OBJS>,$<NOT:$<BOOL:${DYNLIB_ELF_MODE}>>>:$<TARGET_OBJECTS:STARTUP_OBJS>> $<$<NOT:$<BOOL:${USE_LINKER}>>:-Wl,>--start-group
