Skip to content

cmake: Omit default priority ELF symbol. - #19548

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
casaroli:fix/cmake-application-elf-default-priority
Jul 27, 2026
Merged

cmake: Omit default priority ELF symbol.#19548
xiaoxiang781216 merged 1 commit into
apache:masterfrom
casaroli:fix/cmake-application-elf-default-priority

Conversation

@casaroli

@casaroli casaroli commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

nuttx_add_application() translates SCHED_PRIORITY_DEFAULT into a zero-valued nx_priority linker symbol for CMake-built ELF applications. Priority zero is invalid for a runnable application task; on assertion-enabled targets, launching such an application triggers the scheduler priority assertion.

Do not emit nx_priority when an application selects SCHED_PRIORITY_DEFAULT. The ELF loader already uses its scheduler default when the symbol is absent. Explicit numeric priorities continue to be emitted unchanged.

This is the CMake companion to apache/nuttx-apps#3667, which makes the corresponding correction for Make-built application ELFs. Together they replace the need for the broader ELF-loader workaround proposed in #19537.

Impact

  • Feature/API/ABI: No new feature or API/ABI change.
  • Users: No user action required. CMake-built applications using SCHED_PRIORITY_DEFAULT receive the existing scheduler default instead of an invalid priority-zero ELF attribute.
  • Build: CMake kernel/loadable-ELF link metadata changes only. Applications with explicit numeric priorities are unchanged.
  • Hardware/architecture: None; the CMake helper is architecture-independent.
  • Documentation: No update required; behavior now matches the existing ELF-loader default semantics.
  • Security: No security impact.
  • Compatibility: Improves compatibility with the loader's default-priority behavior. It does not alter explicitly configured numeric priorities.

Testing

Host: Fedora Linux x86_64; CMake 4.3.0; Ninja 1.13.2; xPack riscv-none-elf-gcc 14.2.0.

Target configuration: rv-virt:knsh64 (RISC-V 64-bit kernel ELF build).

Commands:

cmake -S nuttx -B cmake-knsh64 -G Ninja -DBOARD_CONFIG=rv-virt:knsh64
ninja -C cmake-knsh64 -t commands ELF_ostest
ninja -C cmake-knsh64 -t commands ELF_getprime
./tools/checkpatch.sh -f cmake/nuttx_add_application.cmake

After this change, the generated ostest link command contains no nx_priority definition:

riscv-none-elf-ld ... -o .../bin_debug/ostest

The explicit numeric-priority regression check is retained:

riscv-none-elf-ld ... --defsym nx_priority=50 ... -o .../bin_debug/getprime

A generated-build-tree search found no --defsym nx_priority=0. ./tools/checkpatch.sh -f cmake/nuttx_add_application.cmake and git diff --check pass.

The full CMake/Ninja rv-virt:knsh64 build could not complete on this host because CMake invokes this xPack toolchain's riscv-none-elf-ld with its default 32-bit emulation while the target objects are 64-bit:

target emulation `elf64-littleriscv' does not match `elf32-littleriscv'

This is unrelated to the priority change. No physical-hardware runtime validation is available in this workspace, so this PR is marked draft pending that validation.

PR verification self-check

  • This PR introduces one focused CMake build-system correction.
  • All required description fields are updated.
  • The commit follows the Contributing Guidelines, including Assisted-by and human sign-off trailers.
  • This PR is a work in progress pending hardware build/runtime validation.
  • This PR is ready for review and can be safely merged.

nuttx_add_application() encoded SCHED_PRIORITY_DEFAULT as a zero-valued nx_priority linker symbol. A zero priority is invalid for a runnable ELF application task.

Do not emit nx_priority for the symbolic default. When the symbol is absent, the ELF loader retains its scheduler default. Continue emitting nx_priority for explicit numeric priorities.

Companion to apache/nuttx-apps#3667.

Assisted-by: Zed:GPT-5.6 Terra

Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@casaroli

Copy link
Copy Markdown
Contributor Author

Companion PR: apache/nuttx-apps#3667 fixes the same default-priority ELF encoding in the Make build path. This PR covers the CMake path.

@github-actions github-actions Bot added Area: Build system Size: XS The size of the change in this PR is very small labels Jul 27, 2026
@casaroli

Copy link
Copy Markdown
Contributor Author

@xiaoxiang781216

@casaroli
casaroli marked this pull request as ready for review July 27, 2026 01:51
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@anchao anchao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@xiaoxiang781216
xiaoxiang781216 merged commit 7eb9bb0 into apache:master Jul 27, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Build system Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants