-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
regression - nightly 2023-03-30 -> 2023-03-31 causes linker error when importing wasm_bindgen::JsValue in a proc_macro #111888
Comments
I forked You can find it here: https://github.com/finnbear/stylist-rs/tree/rustc (just run Here is a workaround for the crate: futursolo/stylist-rs#121 |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-high +T-compiler |
I already looked over this and was also mystified. I suppose I could take another look? I know almost completely nothing about wasm so I'm not hopeful. |
Builds fine:
Same linker error:
As a mitigation for the linker error, users may put this in their Cargo.toml (for the workspace!)
That only helps with the alignment checks, |
I can build the reproducer, unmodified, if I use LLD. [target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-Clink-arg=-fuse-ld=lld"] Or
https://borngeek.com/2009/3/13/gcc-dynamic-section-sizes-error/ suggests this might be a link order issue. That would explain why LLD is fine with the link, but GNU's linker isn't. Actually, that doesn't make much sense because our standard library is already at the end of the link. I'm out of ideas 🤷 I think this is somehow dependent on linker details that I don't know and I'm struggling to educate myself on. |
@JohnTheCoolingFan reported this same linker error from The errant symbol is #[no_mangle]
pub fn bz_internal_error(errcode: c_int) {
panic!("bz internal error: {}", errcode);
} This has the same sort of shape as the non-unwinding panics from the alignment checks and from the standard library UB-detecting assertions. searched nightlies: from nightly-2023-01-01 to nightly-2023-06-09 bisected with cargo-bisect-rustc v0.6.6Host triple: x86_64-unknown-linux-gnu cargo bisect-rustc --start 2023-01-01 --end 2023-06-09 --script script --regress=error So this bisects to a rollup then can't find the unrolled perf builds. Manual trials identifies #108017 as the source of the regression. |
A tiny update: it seems like this problem goes away if you use This was somewhat of a surprise. I need to investigate more to figure out what relevance the codegen unit partitioning has to do with this issue. If nothing else, it is a halfway decent fallback measure while we continue to investigate the problem. |
Wanted to add, that I also ran into this issue. For me, it also occurred while compiling a macro crate. I originally thought it was an issue with There was a bunch of weird behavior I encountered when trying to uncover the issue. The I didn't dive too deeply, but it seems like I was still encountering this issue even when I set the compiler to 1.67. (See this Github Actions build and associated commit: https://github.com/kurtbuilds/oasgen/actions/runs/5513164141 ) So it's possible that going to an old version simply hid the issue, but didn't actually pinpoint where the issue was introduced. Let me know if there's any other information I can provide to help isolate the issue. I've seemingly been able to work around the issue by using |
One MCVE for the stylist-macros build issue looks like this: Just a stylist-macros crate, with this # mcve-stylist/Cargo.toml
[package]
name = "mcve-stylist"
version = "0.1.0"
[lib]
proc-macro = true
[dependencies]
wasm-bindgen = "0.2.83" // mcve-stylist/src/lib.rs
extern crate wasm_bindgen; So now I'm switching gears to see if I reduce wasm_bindgen to something smaller, so that we can have a small set of crates to talk about on their own here. |
Okay got a pretty impressively tiny MCVE for wasm-bindgen too: # wasm-bindgen/Cargo.toml
[package]
name = "wasm-bindgen"
version = "0.2.87" // wasm-bindgen/src/lib.rs
#[no_mangle]
pub extern "C" fn __wbindgen_malloc(_size: usize, _align: usize) -> *mut u8 {
loop {}
}
#[no_mangle]
pub unsafe extern "C" fn __wbindgen_realloc(
_ptr: *mut u8,
_old_size: usize,
_new_size: usize,
_align: usize,
) -> *mut u8 {
loop {}
}
#[no_mangle]
pub unsafe extern "C" fn __wbindgen_free(_ptr: *mut u8, _size: usize, _align: usize) {
loop {}
}
#[no_mangle]
pub unsafe extern "C" fn __wbindgen_exn_store(_idx: u32) {
loop {}
} In case its not clear, this seems like a pretty simple example that should easily work out of the box. (The use of Still looking. Update: Wow, is it somehow |
#99978 may be relevant. That issue is about not mentioning Edit: For regular dylibs we mention all these symbols in |
As an addendum to this: #108017 (which was in a rollup, as mentioned) added the future-proofing safe-guard of adding In my own MCVE, when I add that link-arg, I find that the code did compile circa 1.63 even with that Update: oh, of course, it is almost certainly PR #99944 that injected the change in behavior mentioned in the previous paragraph. |
In m-c we're running into linking issues in `uniffi_macros`, where it's missing symbols coming from `uniffi_core`: /bin/ld: uniffi_foreign_executor_callback_set: undefined version: /bin/ld: failed to set dynamic section sizes: bad value That's most likely this issue on Rust: rust-lang/rust#111888 It's called out that this likely actually broke because of another PR: rust-lang/rust#99944 Despite this bug there's a bit of an issue in UniFFI to begin with: We're exporting `extern "C"` functions from a crate that is a dependency of some other crates, including `uniffi_macros`, and thus the symbols land in a part where they are not needed. However for `uniffi_meta` in particular we don't need much from `uniffi_core`, so for now we just copy the necessary bits to get it all working.
In m-c we're running into linking issues in `uniffi_macros`, where it's missing symbols coming from `uniffi_core`: /bin/ld: uniffi_foreign_executor_callback_set: undefined version: /bin/ld: failed to set dynamic section sizes: bad value That's most likely this issue on Rust: rust-lang/rust#111888 It's called out that this likely actually broke because of another PR: rust-lang/rust#99944 Despite this bug there's a bit of an issue in UniFFI to begin with: We're exporting `extern "C"` functions from a crate that is a dependency of some other crates, including `uniffi_macros`, and thus the symbols land in a part where they are not needed. However for `uniffi_meta` in particular we don't need much from `uniffi_core`, so for now we just copy the necessary bits to get it all working.
In m-c we're running into linking issues in `uniffi_macros`, where it's missing symbols coming from `uniffi_core`: /bin/ld: uniffi_foreign_executor_callback_set: undefined version: /bin/ld: failed to set dynamic section sizes: bad value That's most likely this issue on Rust: rust-lang/rust#111888 It's called out that this likely actually broke because of another PR: rust-lang/rust#99944 Despite this bug there's a bit of an issue in UniFFI to begin with: We're exporting `extern "C"` functions from a crate that is a dependency of some other crates, including `uniffi_macros`, and thus the symbols land in a part where they are not needed. However for `uniffi_meta` in particular we don't need much from `uniffi_core`, so for now we just copy the necessary bits to get it all working.
In m-c we're running into linking issues in `uniffi_macros`, where it's missing symbols coming from `uniffi_core`: /bin/ld: uniffi_foreign_executor_callback_set: undefined version: /bin/ld: failed to set dynamic section sizes: bad value That's most likely this issue on Rust: rust-lang/rust#111888 It's called out that this likely actually broke because of another PR: rust-lang/rust#99944 Despite this bug there's a bit of an issue in UniFFI to begin with: We're exporting `extern "C"` functions from a crate that is a dependency of some other crates, including `uniffi_macros`, and thus the symbols land in a part where they are not needed. However for `uniffi_meta` in particular we don't need much from `uniffi_core`, so for now we just copy the necessary bits to get it all working.
In m-c we're running into linking issues in `uniffi_macros`, where it's missing symbols coming from `uniffi_core`: /bin/ld: uniffi_foreign_executor_callback_set: undefined version: /bin/ld: failed to set dynamic section sizes: bad value That's most likely this issue on Rust: rust-lang/rust#111888 It's called out that this likely actually broke because of another PR: rust-lang/rust#99944 Despite this bug there's a bit of an issue in UniFFI to begin with: We're exporting `extern "C"` functions from a crate that is a dependency of some other crates, including `uniffi_macros`, and thus the symbols land in a part where they are not needed. However for `uniffi_meta` in particular we don't need much from `uniffi_core`, so for now we just copy the necessary bits to get it all working.
In m-c we're running into linking issues in `uniffi_macros`, where it's missing symbols coming from `uniffi_core`: /bin/ld: uniffi_foreign_executor_callback_set: undefined version: /bin/ld: failed to set dynamic section sizes: bad value That's most likely this issue on Rust: rust-lang/rust#111888 It's called out that this likely actually broke because of another PR: rust-lang/rust#99944 Despite this bug there's a bit of an issue in UniFFI to begin with: We're exporting `extern "C"` functions from a crate that is a dependency of some other crates, including `uniffi_macros`, and thus the symbols land in a part where they are not needed. However for `uniffi_meta` in particular we don't need much from `uniffi_core`, so for now we just copy the necessary bits to get it all working.
In m-c we're running into linking issues in `uniffi_macros`, where it's missing symbols coming from `uniffi_core`: /bin/ld: uniffi_foreign_executor_callback_set: undefined version: /bin/ld: failed to set dynamic section sizes: bad value That's most likely this issue on Rust: rust-lang/rust#111888 It's called out that this likely actually broke because of another PR: rust-lang/rust#99944 Despite this bug there's a bit of an issue in UniFFI to begin with: We're exporting `extern "C"` functions from a crate that is a dependency of some other crates, including `uniffi_macros`, and thus the symbols land in a part where they are not needed. However for `uniffi_meta` in particular we don't need much from `uniffi_core`, so for now we just copy the necessary bits to get it all working.
See related discussion in https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/linker.20errs.20from.20wasm.20exposed.20by.20mir.20align.20checks.20.23111888 (I have a branch with a commit that seems to fix this here: https://github.com/pnkfelix/rust/tree/dont-export-no-mangle-from-proc-macros-issue-99978 ; I hope to have a PR up today, once I get a regression test into place.) |
Notes for other investigators
(2023-07-19)
stylist-rs has been updated with a workaround, so the reproduction described below will need adapting (e.g. check out that repo from around futursolo/stylist-rs@fbd788f or earlier, since that will not include the workaround added in Mitigate linker error from Rust compiler futursolo/stylist-rs#123 )
This problem exhibits itself only with certain numbers of codegen-units. The default setting for codegen-units is host dependent (the default is chosen, in part, as a function of the number of cores the host has available, in order to parallelize the code-generation performed by LLVM). In my own experiments, the problem is masked (does not arise) for codegen-units={1,2,4,8}, and the problem does arise for codegen-units={16,32,64,128,256}. You are best off passing
-Ccodegen-units
explicit when investigating this, just to ward against that being an invisible factor in the experiments.(bug report follows below)
Code
I tried this code:
stylist-macros
I expected to see this happen:
cargo check
succeeds in debug mode.Instead, this happened:
cargo check
fails in debug mode.Version it worked on
Version with regression
Cargo bisect-rustc
*isn't immediately obvious why this change would cause the problem
searched nightlies: from nightly-2023-03-27 to nightly-2023-04-02
regressed nightly: nightly-2023-04-01
searched commit range: ec2f40c...5e1d329
regressed commit: 22a7a19
bisected with cargo-bisect-rustc v0.6.6
Host triple: x86_64-unknown-linux-gnu
Reproduce with:
The text was updated successfully, but these errors were encountered: