Skip to content

Commit 73ee721

Browse files
esaurezCopilot
andcommitted
[build] F: Use --allow-multiple-definition for libnvx_crt0 link
End-to-end validation surfaced a hard linker error in the original --whole-archive approach: libnvx_crt0.a and libposix.a both bundle the `sys` crate (Rust monomorphizes the FFI `__kcall_*` symbols into both archives), so --whole-archive on libnvx_crt0 produces "multiple definition of __kcall_*" errors against libposix. Switch to: -Wl,--allow-multiple-definition -Wl,--start-group $(wildcard $(SYSROOT_PATH)/lib/libnvx_crt0.a) libposix.a libc.a [libm.a] -Wl,--end-group With libnvx_crt0.a inside the start-group and ahead of libposix.a, the linker resolves the entry-point `_start` from libnvx_crt0 (strong T symbol) over newlib's weak `_start` fallback. The remaining __kcall_* duplicates from the two `sys` monomorphizations are byte-identical (same Rust source, same release profile, same compiler options) and silently coalesced by --allow-multiple-definition. The $(wildcard ...) trick preserves backward compatibility: on pre-PR-11b sysroots libnvx_crt0.a is absent, the wildcard expands to empty, and the link line collapses to the original behavior. Validated by building + running the test ELF via nanvixd.exe against a locally-built nanvix-dev sysroot that includes PR-11b. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent fbd0330 commit 73ee721

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,16 @@ export LIBC := $(NANVIX_TOOLCHAIN)/i686-nanvix/lib/libc.a
5959
# ELFs built against the new sysroot fall back to newlib's weak default
6060
# `_start` and hang at startup with no output.
6161
export LIBNVX_CRT0 := $(wildcard $(NANVIX_SYSROOT)/lib/libnvx_crt0.a)
62-
export LIBRARIES := -Wl,--whole-archive $(LIBNVX_CRT0) -Wl,--no-whole-archive \
63-
-Wl,--start-group $(LIBPOSIX) $(LIBC) -Wl,--end-group
62+
# --allow-multiple-definition: libnvx_crt0 and libposix both bundle the
63+
# `sys` crate (Rust FFI symbols `__kcall_*` are exported by both). Both
64+
# copies are byte-identical (same source, same release profile), so it
65+
# is safe to let the linker take whichever it sees first. See the
66+
# `libnvx_crt0-duplicates-sys-symbols` upstream issue for the proper fix.
67+
export LIBRARIES := -Wl,--allow-multiple-definition \
68+
-Wl,--start-group $(LIBNVX_CRT0) $(LIBPOSIX) $(LIBC) -Wl,--end-group
6469
export LIBCXX := $(NANVIX_TOOLCHAIN)/i686-nanvix/lib/libstdc++.a
65-
export LIBRARIES_CXX := -Wl,--whole-archive $(LIBNVX_CRT0) -Wl,--no-whole-archive \
66-
-Wl,--start-group $(LIBPOSIX) $(LIBC) $(LIBCXX) -Wl,--end-group
70+
export LIBRARIES_CXX := -Wl,--allow-multiple-definition \
71+
-Wl,--start-group $(LIBNVX_CRT0) $(LIBPOSIX) $(LIBC) $(LIBCXX) -Wl,--end-group
6772

6873
# Output directory for compiled binaries.
6974
export BINARIES_DIR ?= $(CURDIR)/../build

0 commit comments

Comments
 (0)