arch/sim: rename nuttx libc memchr to avoid host glibc collision#18887
Open
cjj66619 wants to merge 1 commit into
Open
arch/sim: rename nuttx libc memchr to avoid host glibc collision#18887cjj66619 wants to merge 1 commit into
cjj66619 wants to merge 1 commit into
Conversation
The sim/src/nuttx-names.in symbol-rename list is the mechanism that
keeps every nuttx libc function used inside nuttx.rel from clashing
with the same-named function in host glibc when the sim executable
is finally linked. The list already covers ~200 symbols (memcpy,
strlen, strcat, strchr, ...) but memchr was missing.
On x86_64 Linux hosts the omission has no visible effect because
host glibc dispatches memchr through an IFUNC resolver
(__memchr_ifunc) that the static libc.a path does not eagerly pull
in for typical sim links. On HOST_ARM64 (Ubuntu 20.04 aarch64,
glibc 2.31 .. 2.41), however, the final cc/ld invocation in the
sim Makefile drags libc.a(memchr.o) into the link, which then
collides with nuttx libc's lib_memchr.o that has already been
folded into nuttx.rel:
/usr/bin/ld: /usr/lib/gcc/aarch64-linux-gnu/9/../../../aarch64-linux-gnu/libc.a(memchr.o):
in function `__memchr_ifunc':
(.text+0x0): multiple definition of `memchr';
nuttx.rel:libs/libc/string/lib_memchr.c:55: first defined here
Add memchr to the rename list (placed in alphabetical position
between malloc_usable_size and memcpy). After this fix sim:nsh
builds cleanly on aarch64 Linux hosts (verified on NVIDIA Jetson
Orin L4T Ubuntu 20.04 + Raspberry Pi 4B Debian 13 trixie). The
behaviour on x86_64 / macOS / Cygwin hosts is unchanged because
those targets either never hit the collision or use the
underscore-prefixed variant gated by NXSYMBOLS macro definition
in the same file (lines 26-31).
Signed-off-by: Jinji Cui <113000688+cjj66619@users.noreply.github.com>
xiaoxiang781216
approved these changes
May 16, 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.
The sim/src/nuttx-names.in symbol-rename list is the mechanism that keeps every nuttx libc function used inside nuttx.rel from clashing with the same-named function in host glibc when the sim executable is finally linked. The list already covers ~200 symbols (memcpy, strlen, strcat, strchr, ...) but memchr was missing.
On x86_64 Linux hosts the omission has no visible effect because host glibc dispatches memchr through an IFUNC resolver (__memchr_ifunc) that the static libc.a path does not eagerly pull in for typical sim links. On HOST_ARM64 (Ubuntu 20.04 aarch64, glibc 2.31 .. 2.41), however, the final cc/ld invocation in the sim Makefile drags libc.a(memchr.o) into the link, which then collides with nuttx libc's lib_memchr.o that has already been folded into nuttx.rel:
Add memchr to the rename list (placed in alphabetical position between malloc_usable_size and memcpy). After this fix sim:nsh builds cleanly on aarch64 Linux hosts (verified on NVIDIA Jetson Orin L4T Ubuntu 20.04 + Raspberry Pi 4B Debian 13 trixie). The behaviour on x86_64 / macOS / Cygwin hosts is unchanged because those targets either never hit the collision or use the underscore-prefixed variant gated by NXSYMBOLS macro definition in the same file (lines 26-31).
Summary
arch/sim/src/nuttx-names.inis the rename-list that prevents nuttx libc symbols (folded intonuttx.rel) from clashing with the same-named symbols pulled in from host glibc during the final sim link. The list already covers ~200 symbols (memcpy,strlen,strcat,strchr, ...) butmemchris missing, causing the sim build to fail with a multiple-definition error on Linux aarch64 hosts.Impact
sim:nsh,sim:nsh2,sim:smp,sim:bluetooth,sim:binder,sim:matterand any other sim defconfig that includes nuttx libc on an aarch64 Linux host.memchrthrough an IFUNC resolver placed in a different static-archive section.Root Cause
libs/libc/string/Make.defs:58unconditionally compileslib_memchr.c.arch/sim/src/Makefile:436-439foldslib_memchr.ointonuttx.rel.arch/sim/src/Makefile:441rewrites symbols innuttx.relviaobjcopy --redefine-syms=nuttx-names.dat— butnuttx-names.inhas noNXSYMBOLS(memchr), so nuttx'smemchrkeeps its original name.arch/sim/src/Makefile:464-465runs the finalcc ... nuttx.rel ... -lc .... gcc on aarch64 Linux pulls inlibc.a(memchr.o)(__memchr_ifunc), which collides with nuttx's ownmemchr:Fix
Single-line addition (between
malloc_usable_sizeandmemcpy, preserving alphabetical order):After preprocessing this expands to either
memchr NXmemchr(Linux) or_memchr _NXmemchr(macOS / Cygwin decorated), matching the existing convention.Test results
Verified on:
sim:nshclean build + NSH prompt +ostest38 stages PASSostest_main: Exiting with status 0on both platforms. Detailed reproduction log + bytecount diff intest-report.md.Companion patch
This patch alone is not sufficient to build
sim:nshon Ubuntu aarch64 hosts. A second small fix inboards/sim/sim/sim/scripts/Make.defs(gate the existing-no-pieblock on!CONFIG_HOST_ARM64) is also required. See companion PR:boards/sim: skip -no-pie on HOST_ARM64 to fix sim:nsh link on aarch64 host.The two PRs are independently mergeable, but on aarch64 you need both to get a working sim binary.
checkpatch
tools/checkpatch.sh -f arch/sim/src/nuttx-names.in→ ✔️ All checks pass.