-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
wasm: Store rlib metadata in wasm object files #120588
Conversation
r? @wesleywiser (rustbot has picked a reviewer for you, use r? to override) |
Is it possible to integrate this in create_object_file using the object crate? I believe it supports wasm as well. |
#119286 will show it. |
The object crate only supports parsing wasm, not emitting it. It also doesn't support relocatable wasm object files, only linked wasm modules. For this particular case it may still work as nothing is encoded in the linking section anyway. |
f377387
to
513258b
Compare
Oh good point, I did not know!
Ah yes this appears to be the case. It also looks like the support in I'll also add some notes in the documentation about this for the writing half. |
269b361
to
587c865
Compare
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
This comment has been minimized.
This comment has been minimized.
587c865
to
43c0d38
Compare
I've pushed an update to tidy checks to allow |
The list of allowed third-party dependencies may have been modified! You must ensure that any new dependencies have compatible licenses before merging. |
src/tools/tidy/src/deps.rs
Outdated
@@ -15,6 +15,7 @@ const LICENSES: &[&str] = &[ | |||
"Apache-2.0 / MIT", | |||
"Apache-2.0 OR MIT", | |||
"Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT", // wasi license | |||
"Apache-2.0 WITH LLVM-exception", // wasmparser license |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding the license here, could you add an exception for this crate?
rust/src/tools/tidy/src/deps.rs
Line 78 in 43c0d38
const EXCEPTIONS: ExceptionList = &[ |
Sorry to be nitpicky but I think this would help prevent us from depending on more Apache 2 only code without realizing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no that definitely makes sense. I've moved it down there.
One point though is that I had to add an extra exception to the runtime checks loop. The object
dependency is shared between rustc/libstd and the code here "isn't smart enough" to determine that libstd doesn't actually depend on wasmparser
where rustc does, so I added some comments to that effect.
I'm also going to talk to some folks to try to get wasmparser relicensed with Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT
which should resolve these concerns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and the code here "isn't smart enough" to determine that libstd doesn't actually depend on wasmparser where rustc does
Yet another thing that would be fixed by moving library/ to a separate cargo workspace...
43c0d38
to
74481b3
Compare
Thanks Alex! @bors r+ |
Instead substitute this with `AtomicUsize` which panics on overflow to catch any possible issues on 32-bit platforms. This is motivated by rust-lang/rust#120588 which is pulling `wasmparser` into the Rust compiler and `AtomicU64` is not available on all the platforms the compiler itself is built for. I plan on backporting this to the `0.118.x` release track as well which is what's used by the `object` crate currently to avoid the need for a whole bunch of cascading updates.
Instead substitute this with `AtomicUsize` which panics on overflow to catch any possible issues on 32-bit platforms. This is motivated by rust-lang/rust#120588 which is pulling `wasmparser` into the Rust compiler and `AtomicU64` is not available on all the platforms the compiler itself is built for. I plan on backporting this to the `0.118.x` release track as well which is what's used by the `object` crate currently to avoid the need for a whole bunch of cascading updates.
Instead substitute this with `AtomicUsize` which panics on overflow to catch any possible issues on 32-bit platforms. This is motivated by rust-lang/rust#120588 which is pulling `wasmparser` into the Rust compiler and `AtomicU64` is not available on all the platforms the compiler itself is built for. I plan on backporting this to the `0.118.x` release track as well which is what's used by the `object` crate currently to avoid the need for a whole bunch of cascading updates.
Instead substitute this with `AtomicUsize` which panics on overflow to catch any possible issues on 32-bit platforms. This is motivated by rust-lang/rust#120588 which is pulling `wasmparser` into the Rust compiler and `AtomicU64` is not available on all the platforms the compiler itself is built for. I plan on backporting this to the `0.118.x` release track as well which is what's used by the `object` crate currently to avoid the need for a whole bunch of cascading updates.
4f3348d
to
47bb0de
Compare
For that failure bytecodealliance/wasm-tools#1412 was applied to the |
Could I perhaps ping this to request a re-queue with bors? |
The goal of this commit is to remove warnings using LLVM tip-of-tree `wasm-ld`. In llvm/llvm-project#78658 the `wasm-ld` LLD driver no longer looks at archive indices and instead looks at all the objects in archives. Previously `lib.rmeta` files were simply raw rustc metadata bytes, not wasm objects, meaning that `wasm-ld` would emit a warning indicating so. WebAssembly targets previously passed `--fatal-warnings` to `wasm-ld` by default which meant that if Rust were to update to LLVM 18 then all wasm targets would not work. This immediate blocker was resolved in rust-lang#120278 which removed `--fatal-warnings` which enabled a theoretical update to LLVM 18 for wasm targets. This current state is ok-enough for now because rustc squashes all linker output by default if it doesn't fail. This means, for example, that rustc squashes all the linker warnings coming out of `wasm-ld` about `lib.rmeta` files with LLVM 18. This again isn't a pressing issue because the information is all hidden, but it runs the risk of being annoying if another linker error were to happen and then the output would have all these unrelated warnings that couldn't be fixed. Thus, this PR comes into the picture. The goal of this PR is to resolve these warnings by using the WebAssembly object file format on wasm targets instead of using raw rustc metadata. When I first implemented the rlib-in-objects scheme in rust-lang#84449 I remember either concluding that `wasm-ld` would either include the metadata in the output or I thought we didn't have to do anything there at all. I think I was wrong on both counts as `wasm-ld` does not include the metadata in the final output unless the object is referenced and we do actually need to do something to resolve these warnings. This PR updates the object file format containing rustc metadata on WebAssembly targets to be an actual WebAssembly file. This enables the `wasm` feature of the `object` crate to be able to read the custom section in the same manner as other platforms, but currently `object` doesn't support writing wasm object files so a handwritten encoder is used instead. The only caveat I know of with this is that if `wasm-ld` does indeed look at the object file then the metadata will be included in the final output. I believe the only thing that could cause that at this time is `--whole-archive` which I don't think is passed for rlibs. I would clarify that I'm not 100% certain about this, however.
47bb0de
to
6181f3a
Compare
@bors r=wesleywiser,bjorn3 |
☀️ Test successful - checks-actions |
Finished benchmarking commit (7168c13): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 640.751s -> 651.363s (1.66%) |
My best guess as to the source of the regression is that the |
@alexcrichton I'm doing perf triage. Unfortunately, the regression here is significant enough to warrant some thought. The main concern are the regressions in the hello-world primary benchmark which has admittedly been a bit noisy lately. However, the regressions here do appear to be legitimate when compared to historical data. The self profile comparison's on the results page don't really show anything conclusive either. 2 possible steps forward:
|
Sounds good! I'll give the local testing a spin soon and failing that open a PR for a revert and measure that. |
Ok I've done local profiling and the results have yielded:
This gives rise to another hypothesis. I do not know the intricacies of the dynamic loader on Linux, but I can say for certain that on the previous commit before this PR librustc_driver had 14293 symbols (as reported by So my hypothesis is that this is because I think it's probably safe to say that this isn't noise. As for what to do:
Or something else, happy to do what y'all think is best here! I'm also happy to take this discussion to Zulip as well. |
The goal of this commit is to remove warnings using LLVM tip-of-tree
wasm-ld
. In llvm/llvm-project#78658 thewasm-ld
LLD driver no longer looks at archive indices and instead looks at all the objects in archives. Previouslylib.rmeta
files were simply raw rustc metadata bytes, not wasm objects, meaning thatwasm-ld
would emit a warning indicating so.WebAssembly targets previously passed
--fatal-warnings
towasm-ld
by default which meant that if Rust were to update to LLVM 18 then all wasm targets would not work. This immediate blocker was resolved in #120278 which removed--fatal-warnings
which enabled a theoretical update to LLVM 18 for wasm targets. This current state is ok-enough for now because rustc squashes all linker output by default if it doesn't fail. This means, for example, that rustc squashes all the linker warnings coming out ofwasm-ld
aboutlib.rmeta
files with LLVM 18. This again isn't a pressing issue because the information is all hidden, but it runs the risk of being annoying if another linker error were to happen and then the output would have all these unrelated warnings that couldn't be fixed.Thus, this PR comes into the picture. The goal of this PR is to resolve these warnings by using the WebAssembly object file format on wasm targets instead of using raw rustc metadata. When I first implemented the rlib-in-objects scheme in #84449 I remember either concluding that
wasm-ld
would either include the metadata in the output or I thought we didn't have to do anything there at all. I think I was wrong on both counts aswasm-ld
does not include the metadata in the final output unless the object is referenced and we do actually need to do something to resolve these warnings.This PR updates the object file format containing rustc metadata on WebAssembly targets to be an actual WebAssembly file. To avoid bringing in any new dependencies I've opted to hand-code this encoding at this time. If the object gets more complicated though it'd probably be best to pull in
wasmparser
andwasm-encoder
. For now though there's two adjacent functions reading/writing wasm.The only caveat I know of with this is that if
wasm-ld
does indeed look at the object file then the metadata will be included in the final output. I believe the only thing that could cause that at this time is--whole-archive
which I don't think is passed for rlibs. I would clarify that I'm not 100% certain about this, however.