[nvx] E: Cut over to nvx-crt0 startup crate#25
Open
esaurez wants to merge 1 commit into
Open
Conversation
Completes PR-11 by moving the executable startup code (`_do_start` / `_start` / `c_trampoline` / ARGC/ARGV / `environ` / `__nanvix_env_init` invocation / argp/envp parsing) out of `nvx` exclusively into the `nvx-crt0` crate that was added in PR-11a (#24). After this commit: - `libposix.a` no longer contains `_start` / `_do_start` / `main` UND, so it is safe to embed in `.so` shared objects. - `libnvx_crt0.a` becomes the sole provider of those symbols and must be linked (under `--whole-archive`) into every guest executable. - The ad-hoc `objcopy --weaken-symbol=main` post-link hook (the `POST_STATICLIB_HOOK_posix` macro in `build/make/generic-guest-staticlibs.mk`) is no longer required and is removed. What changed: - `src/libs/nvx` trimmed to `pub mod pie` + `pub fn init()` / `pub fn cleanup()` + panic handler. Removed default `staticlib` / `standalone` features that previously gated the startup code. Module-level docs point readers to `nvx-crt0`. - `src/libs/posix`: dropped `staticlib = ["nvx/staticlib"]` feature and the corresponding `staticlib` default. `pwd` / `utime` / `sys::ioctl` `#[cfg(all(syscall, staticlib))]` simplified to `#[cfg(syscall)]` (same effective behaviour: `syscall` was always on whenever `staticlib` was). - 29 Rust no_std guest binaries (benchmarks / daemons / tests / hello) now declare `nvx-crt0 = { workspace = true, features = ["rust-main"] }` plus the matching log-level feature forwarding (`trace` / `debug` / `info` / `warn` / `error` / `panic`). Each `main.rs` adds `extern crate nvx_crt0;` so the static lib is force-loaded. - 5 binaries that read the kernel argv blob directly migrated from `nvx::ARGC` / `nvx::ARGV` to `nvx_crt0::ARGC` / `nvx_crt0::ARGV`. - 3 binaries that pulled `nvx/standalone` (mount-bench / mount-test / mount-multipart-test) dropped that feature -- standalone-mode gating now lives entirely in the application crate. - `build/make/generic-guest-staticlibs.mk`: dropped `staticlib` from the default `GUEST_STATICLIB_FEATURES` and deleted `POST_STATICLIB_HOOK_posix` plus both call sites. Validated end-to-end: - `hello-c` (single ELF, multi-process mode) prints expected output. - `hello-cpp` (libstdc++ static ctors + `_init`/`_fini`) works. - `envtest` (argv / environ / getenv) works. - `hello-c` in standalone+ramfs mode works. - CPython hello + lxml + HTTP-server smoke tests PASS in standalone mode (483 ms hello execution) when paired with PR-11b-cpython (esaurez/cpython#2) which adds $(LIBNVX_CRT0) to python.elf's LIBS. See dependency note below. IMPORTANT downstream dependency: After this commit, any C executable that previously relied on `libposix.a`'s `_start` MUST be relinked against `libnvx_crt0.a` under `--whole-archive`. Without it, the link silently succeeds (no undefined-reference error) because `libc.a` ships a WEAK fallback `_start` from newlib -- but the resulting binary hangs at runtime, as the newlib default `_start` does not understand Nanvix's process-spawn trap-frame layout. The matching CPython change is PR-11b-cpython (esaurez/cpython#2, stacked on esaurez/cpython#1 / PR-10). Stacked on PR-11a (#24). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
[nvx] E: Cut over to nvx-crt0 startup crate
Completes PR-11 by moving the executable startup code (
_do_start/_start/c_trampoline/ ARGC/ARGV /environ/__nanvix_env_initinvocation / argp/envp parsing) out ofnvxexclusively into thenvx-crt0crate that was added in PR-11a (#24).After this commit:
libposix.ano longer contains_start/_do_start/mainUND, so it is safe to embed in.soshared objects.libnvx_crt0.abecomes the sole provider of those symbols and must be linked (under--whole-archive) into every guest executable.objcopy --weaken-symbol=mainpost-link hook (thePOST_STATICLIB_HOOK_posixmacro inbuild/make/generic-guest-staticlibs.mk) is no longer required and is removed.What changed:
src/libs/nvxtrimmed topub mod pie+pub fn init()/pub fn cleanup()+ panic handler. Removed defaultstaticlib/standalonefeatures that previously gated the startup code. Module-level docs point readers tonvx-crt0.src/libs/posix: droppedstaticlib = ["nvx/staticlib"]feature and the correspondingstaticlibdefault.pwd/utime/sys::ioctl#[cfg(all(syscall, staticlib))]simplified to#[cfg(syscall)](same effective behaviour:syscallwas always on wheneverstaticlibwas).nvx-crt0 = { workspace = true, features = ["rust-main"] }plus the matching log-level feature forwarding (trace/debug/info/warn/error/panic). Eachmain.rsaddsextern crate nvx_crt0;so the static lib is force-loaded.nvx::ARGC/nvx::ARGVtonvx_crt0::ARGC/nvx_crt0::ARGV.nvx/standalone(mount-bench / mount-test / mount-multipart-test) dropped that feature — standalone-mode gating now lives entirely in the application crate.build/make/generic-guest-staticlibs.mk: droppedstaticlibfrom the defaultGUEST_STATICLIB_FEATURESand deletedPOST_STATICLIB_HOOK_posixplus both call sites.Validated end-to-end:
hello-c(single ELF, multi-process mode) prints expected output.hello-cpp(libstdc++ static ctors +_init/_fini) works.envtest(argv / environ / getenv) works.hello-cin standalone+ramfs mode works.$(LIBNVX_CRT0)to python.elf's LIBS. See dependency note below.IMPORTANT downstream dependency:
After this commit, any C executable that previously relied on
libposix.a's_startMUST be relinked againstlibnvx_crt0.aunder--whole-archive. Without it, the link silently succeeds (no undefined-reference error) becauselibc.aships a WEAK fallback_startfrom newlib — but the resulting binary hangs at runtime, as the newlib default_startdoes not understand Nanvix's process-spawn trap-frame layout. The matching CPython change is PR-11b-cpython (esaurez/cpython#2, stacked on esaurez/cpython#1 / PR-10).Stacked on PR-11a (#24).
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com