boards/sim: skip -no-pie on HOST_ARM64 to fix sim:nsh link on aarch64…#18888
Open
cjj66619 wants to merge 1 commit into
Open
boards/sim: skip -no-pie on HOST_ARM64 to fix sim:nsh link on aarch64…#18888cjj66619 wants to merge 1 commit into
cjj66619 wants to merge 1 commit into
Conversation
… host
boards/sim/sim/sim/scripts/Make.defs adds `-no-pie` to ARCHCFLAGS /
ARCHPICFLAGS / LDFLAGS for every 64-bit non-Mac sim build. The
original comment ("To compile 64-bit Sim, adding no-pie is necessary
to prevent linking errors but this may cause other issues on
Ubuntu 20.") already flagged the workaround as fragile.
On HOST_ARM64 the option is in fact actively harmful. When gcc is
asked to produce a non-PIE executable on aarch64 it switches the
libgcc resolution path from the dynamic library
`libgcc_s.so.1` to the static archive `libgcc_s.a`. Ubuntu's
arm64 toolchain (and Debian / Raspbian arm64) **does not ship**
`libgcc_s.a` (only `libgcc_s.so.1`), so the link aborts with:
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lgcc_s (push-state / as-needed both fail)
collect2: error: ld returned 1 exit status
`ld --verbose` shows ld searching 20+ paths for `libgcc_s.a`,
finding only `libgcc_s.so` (a linker script pointing at
`libgcc_s.so.1`) which is invalid in non-PIE mode.
x86_64 Linux is unaffected because Ubuntu ships the static
`libgcc_s.a` (or a compatible static-fallback library) in its
amd64 libgcc-N-dev packaging. macOS, Windows and Cygwin go
through completely different code paths and never reach this
branch.
Extend the existing `else ifeq ($(CONFIG_HOST_MACOS),)` exclusion
to also cover HOST_ARM64 by concatenating the two variables in the
condition: `else ifeq ($(CONFIG_HOST_MACOS)$(CONFIG_HOST_ARM64),)`.
The condition is true only when both variables are empty (i.e. on
a 64-bit non-macOS non-aarch64 Linux host), so aarch64 hosts fall
through to gcc's default PIE-aware link path, which works
correctly. This concatenation idiom matches the style already
used elsewhere in the file (suggested by @xiaoxiang781216 in
review). The default text-segment placement
`-Ttext-segment=0x40000000` and `-Wl,--gc-sections` (set in the
common LDFLAGS just above this block) are honored regardless of
PIE / non-PIE.
Verified on NVIDIA Jetson Orin (Ubuntu 20.04 L4T, GCC 9.4) and
Raspberry Pi 4B (Debian 13 trixie, GCC 14.2):
$ ./build.sh sim:nsh -j$(nproc)
$ ./nuttx
NuttShell (NSH)
nsh> ostest
... [38 user_main stages, 14 PASS, 0 FAIL] ...
ostest_main: Exiting with status 0
x86_64 Linux behaviour is unchanged (the concatenation is empty
there, so the block is taken exactly as before).
Companion patch: arch/sim: rename nuttx libc memchr to avoid host
glibc collision (independent fix needed on the same aarch64 hosts).
Signed-off-by: Jinji Cui <113000688+cjj66619@users.noreply.github.com>
xiaoxiang781216
approved these changes
May 17, 2026
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.
… host
boards/sim: skip -no-pie on HOST_ARM64 to fix sim:nsh link on aarch64 host
boards/sim/sim/sim/scripts/Make.defs adds
-no-pieto ARCHCFLAGS / ARCHPICFLAGS / LDFLAGS for every 64-bit non-Mac sim build. The original comment ("To compile 64-bit Sim, adding no-pie is necessary to prevent linking errors but this may cause other issues on Ubuntu 20.") already flagged the workaround as fragile.On HOST_ARM64 the option is in fact actively harmful. When gcc is asked to produce a non-PIE executable on aarch64 it switches the libgcc resolution path from the dynamic library
libgcc_s.so.1to the static archivelibgcc_s.a. Ubuntu's arm64 toolchain (and Debian / Raspbian arm64) does not shiplibgcc_s.a(onlylibgcc_s.so.1), so the link aborts with:ld --verboseshows ld searching 20+ paths forlibgcc_s.a, finding onlylibgcc_s.so(a linker script pointing atlibgcc_s.so.1) which is invalid in non-PIE mode.x86_64 Linux is unaffected because Ubuntu ships the static
libgcc_s.a(or a compatible static-fallback library) in its amd64 libgcc-N-dev packaging. macOS, Windows and Cygwin go through completely different code paths and never reach this branch.Gate the existing
-no-pieblock withifneq ($(CONFIG_HOST_ARM64),y)so aarch64 hosts fall through to gcc's default PIE-aware link path, which works correctly. The default text-segment placement-Ttext-segment=0x40000000and-Wl,--gc-sections(set in the common LDFLAGS just above this block) are honored regardless of PIE / non-PIE.Verified on NVIDIA Jetson Orin (Ubuntu 20.04 L4T, GCC 9.4) and Raspberry Pi 4B (Debian 13 trixie, GCC 14.2):
$ ./build.sh sim:nsh -j$(nproc)
$ ./nuttx
NuttShell (NSH)
nsh> ostest
... [38 user_main stages, 14 PASS, 0 FAIL] ...
ostest_main: Exiting with status 0
x86_64 Linux behaviour is unchanged (the
ifneqis false there, so the block is taken exactly as before).Companion patch: arch/sim: rename nuttx libc memchr to avoid host glibc collision (independent fix needed on the same aarch64 hosts).
Summary
boards/sim/sim/sim/scripts/Make.defsunconditionally adds-no-pie/-Wl,-no-pieto every 64-bit non-macOS sim build (line 322-328). The block's own comment already flags it as fragile: "To compile 64-bit Sim, adding no-pie is necessary to prevent linking errors but this may cause other issues on Ubuntu 20." On Ubuntu / Debian aarch64 hosts this workaround is in fact actively broken — the build cannot link because gcc switches to looking for the staticlibgcc_s.alibrary which the Ubuntu/Debian arm64 toolchain does not ship.This PR gates the existing
-no-pieblock on!CONFIG_HOST_ARM64, restoring sim:nsh build / run capability on aarch64 Linux hosts. x86_64 behaviour is byte-identical.Impact
sim:nsh,sim:nsh2,sim:smp,sim:bluetooth,sim:binder,sim:matter, ...) on a Linux aarch64 host.Root Cause
Make.defs:322-328addsARCHCFLAGS += -no-pie,ARCHPICFLAGS += -no-pie,LDFLAGS += -Wl,-no-piewhenever (a) sim is 64-bit, (b) host is not macOS.-no-piecauses gcc's collect2 spec to inject the libgcc resolution from the non-PIE branch of the spec — which on aarch64 attempts to link against the staticlibgcc_s.a.libgcc_s.so.1) and a linker-script alias (/usr/lib/gcc/aarch64-linux-gnu/9/libgcc_s.so→GROUP ( libgcc_s.so.1 -lgcc )). There is nolibgcc_s.a.cannot find -lgcc_safter ld searches 20+ standard paths.Same
cccommand without-Wl,-no-piesucceeds and produces a valid PIE executable.Fix
Wrap the existing 3-line block in
ifneq ($(CONFIG_HOST_ARM64),y), with a comment explaining the aarch64-host packaging mismatch:After the patch aarch64 hosts fall through to gcc's default PIE link path, which works correctly. The default text-segment placement
-Ttext-segment=0x40000000and-Wl,--gc-sections(set in the common LDFLAGS above) are honored regardless of PIE / non-PIE.Test results
sim:nshclean build, NSH prompt, 18.2 ms median boot,ostest38 stages PASSostest38 stages PASSifneqis false → block taken unchanged → behaviour byte-identicalDetailed reproduction log + ld trace + bytecount diff in
test-report.md.Companion patch
This patch alone is not sufficient to build
sim:nshon Ubuntu aarch64 hosts; thenuttx.rellink also collides on the unrenamed nuttx-libcmemchr. See companion PR:arch/sim: rename nuttx libc memchr to avoid host glibc collision(single-line addition toarch/sim/src/nuttx-names.in).The two PRs are independently mergeable — each fix is a strict subset narrowing of an existing failure mode — but on aarch64 hosts you need both to get a working sim binary.
checkpatch
tools/checkpatch.sh -f boards/sim/sim/sim/scripts/Make.defs→ ✔️ All checks pass.