Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions compiler/rustc_target/src/spec/base/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ pub(crate) fn options() -> TargetOptions {
// stack overflow will be guaranteed to trap as it underflows instead of
// corrupting static data.
concat!($prefix, "--stack-first"),
// FIXME we probably shouldn't pass this but instead pass an explicit list
// of symbols we'll allow to be undefined. We don't currently have a
// mechanism of knowing, however, which symbols are intended to be imported
// from the environment and which are intended to be imported from other
// objects linked elsewhere. This is a coarse approximation but is sure to
// hide some bugs and frustrate someone at some point, so we should ideally
// work towards a world where we can explicitly list symbols that are
// supposed to be imported and have all other symbols generate errors if
// they remain undefined.
concat!($prefix, "--allow-undefined"),
// LLD only implements C++-like demangling, which doesn't match our own
// mangling scheme. Tell LLD to not demangle anything and leave it up to
// us to demangle these symbols later. Currently rustc does not perform
Expand Down
2 changes: 2 additions & 0 deletions tests/run-make/wasm-stringify-ints-small/foo.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#![crate_type = "cdylib"]

#[link(wasm_import_module = "the-world")]
extern "C" {
fn observe(ptr: *const u8, len: usize);
}

macro_rules! s {
( $( $f:ident -> $t:ty );* $(;)* ) => {
$(
#[link(wasm_import_module = "the-world")]
extern "C" {
fn $f() -> $t;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/run-make/wasm-unexpected-features/foo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ unsafe extern "Rust" {
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
}

#[rustc_std_internal_symbol]
pub unsafe fn __rdl_alloc_error_handler(_size: usize, _align: usize) -> ! {
loop {}
}

#[used]
static mut BUF: [u8; 1024] = [0; 1024];

Expand Down
1 change: 1 addition & 0 deletions tests/ui/linking/executable-no-mangle-strip.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ run-pass
//@ ignore-windows-gnu: only statics marked with used can be GC-ed on windows-gnu
//@ ignore-wasm: wasm, for better or worse, exports all #[no_mangle]
Copy link
Copy Markdown
Member

@mati865 mati865 Apr 2, 2026

Choose a reason for hiding this comment

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

Pardon me if this was already discussed, but I couldn't find it in this thread.

I don't see how this comment relates to removal of --allow-undefined. I'm not familiar with WASM linkers (yet), but I don't see how forbidding undefined symbols should affect exports.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This test, with this PR, fails on wasm with:

running 1 tests

[ui] tests/ui/linking/executable-no-mangle-strip.rs ... F


failures:

---- [ui] tests/ui/linking/executable-no-mangle-strip.rs stdout ----

error: test compilation failed although it shouldn't!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/home/alex/code/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" "/home/alex/code/rust/tests/ui/linking/executable-no-mangle-strip.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/home/alex/.cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/home/alex/code/rust/vendor" "--sysroot" "/home/alex/code/rust/build/x86_64-unknown-linux-gnu/stage1" "--target=wasm32-wasip1" "--check-cfg" "cfg(test,FALSE)" "-O" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "-o" "/home/alex/code/rust/build/x86_64-unknown-linux-gnu/test/ui/linking/executable-no-mangle-strip/a.wasm" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/home/alex/code/rust/build/wasm32-wasip1/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: linking with `rust-lld` failed: exit status: 1
   |
   = note:  "rust-lld" "-flavor" "wasm" "--export" "__main_void" "--export" "function_marked_with_no_mangle" "-z" "stack-size=1048576" "--stack-first" "--no-demangle" "<sysroot>/lib/rustlib/wasm32-wasip1/lib/self-contained/crt1-command.o" "<2 object files omitted>" "<sysroot>/lib/rustlib/wasm32-wasip1/lib/{libpanic_abort-*,libstd-*,libwasi-*,libcfg_if-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,liblibc-*}.rlib" "-l" "c" "<sysroot>/lib/rustlib/wasm32-wasip1/lib/{librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-L" "/home/alex/code/rust/build/wasm32-wasip1/native/rust-test-helpers" "-L" "<sysroot>/lib/rustlib/wasm32-wasip1/lib/self-contained" "-o" "/home/alex/code/rust/build/x86_64-unknown-linux-gnu/test/ui/linking/executable-no-mangle-strip/a.wasm" "--gc-sections" "-O3" "--strip-debug"
   = note: some arguments are omitted. use `--verbose` to show all linker arguments
   = note: rust-lld: error: /home/alex/code/rust/build/x86_64-unknown-linux-gnu/test/ui/linking/executable-no-mangle-strip/a.executable_no_mangle_strip.4e0277abecc73a6b-cgu.0.rcgu.o: undefined symbol: THIS_SYMBOL_SHOULD_BE_UNDEFINED


error: aborting due to 1 previous error
------------------------------------------

---- [ui] tests/ui/linking/executable-no-mangle-strip.rs stdout end ----

failures:
    [ui] tests/ui/linking/executable-no-mangle-strip.rs

Notably function_marked_with_no_mangle is exported from the binary (via --export function_marked_with_no_mangle) which causes the undefined symbol here to be an error.

My understanding for the cause of this is the limit_rdylib_exports target spec option. That's false on wasm but true on most other targets. I forget the reason why it's different, however, and would have to dig in to understand better. That's at least why it's here though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fair enough, thanks for the explanation!


// Regression test for <https://github.com/rust-lang/rust/issues/139744>.
// Functions in the binary marked with no_mangle should be GC-ed if they
Expand Down
Loading