-
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
rustc: Update wasm32 support for LLVM 9 #62809
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
cc @nikic |
I've updated this as well with the necessary support to configure |
This comment has been minimized.
This comment has been minimized.
b307ccc
to
c696d57
Compare
This comment has been minimized.
This comment has been minimized.
} else { | ||
// stubbed out because no functions actually access these intrinsics | ||
// unless atomics are enabled | ||
MY_ID |
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.
What is the reason for using a compare_exchange loop here, rather than an atomic increment (something like MY_ID = NEXT_ID.fetch_add(1, SeqCst)
)? Is this not supported by wasm?
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.
While perhaps slightly overzealous, the thinking here is that if the counter everything should deterministically panic, as opposed to only one thread deterministically panicking but others continuing.
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.
I see. Maybe this is a nice opportunity to use the unstable fetch_update
API, something like:
MY_ID = match NEXT_ID.fetch_update(|cur| cur.overflowing_add(1), SeqCst, SeqCst) {
Some(id) => id + 1,
Err(_) => crate::arch::wasm32::unreachable(),
}
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 good point! I think I'd prefer to avoid picking up an unstable feature for this since it's relatively minor, but I refactored a bit with your suggestion to use checked arithmetic which I think is better than what was there already!
This comment has been minimized.
This comment has been minimized.
This commit brings in a number of minor updates for rustc's support for the wasm target which has changed in the LLVM 9 update. Notable updates include: * The compiler now no longer manually inserts the `producers` section, instead relying on LLVM to do so. LLVM uses the `llvm.ident` metadata for the `processed-by` directive (which is now emitted on the wasm target in this PR) and it uses debuginfo to figure out what `language` to put in the `producers` section. * Threaded WebAssembly code now requires different flags to be passed with LLD. In LLD we now pass: * `--shared-memory` - required since objects are compiled with atomics. This also means that the generated memory will be marked as `shared`. * `--max-memory=1GB` - required with the `--shared-memory` argument since shared memories in WebAssembly must have a maximum size. The 1GB number is intended to be a conservative estimate for rustc, but it should be overridable with `-C link-arg` if necessary. * `--passive-segments` - this has become the default for multithreaded memory, but when compiling a threaded module all data segments need to be marked as passive to ensure they don't re-initialize memory for each thread. This will also cause LLD to emit a synthetic function to initialize memory which users will have to arrange to call. * The `__heap_base` and `__data_end` globals are explicitly exported since they're now hidden by default due to the `--export` flags we pass to LLD.
c696d57
to
c9529d8
Compare
Sorry to bother y'all again, but I'm not sure who's best to review this? @rust-lang/compiler would y'all be ok helping me find a reviewer for this? |
r? @nikic I'll review a bit later today... |
This comment has been minimized.
This comment has been minimized.
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.
r=me with the wrapping issue fixed.
I'm not familiar with wasm linking details, but it looks reasonable :)
} else { | ||
// stubbed out because no functions actually access these intrinsics | ||
// unless atomics are enabled | ||
MY_ID |
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.
I see. Maybe this is a nice opportunity to use the unstable fetch_update
API, something like:
MY_ID = match NEXT_ID.fetch_update(|cur| cur.overflowing_add(1), SeqCst, SeqCst) {
Some(id) => id + 1,
Err(_) => crate::arch::wasm32::unreachable(),
}
c9529d8
to
eb9090f
Compare
This commit moves `thread_local!` on WebAssembly targets to using the `#[thread_local]` attribute in LLVM. This was recently implemented upstream and is [in the process of being documented][dox]. This change only takes affect if modules are compiled with `+atomics` which is currently unstable and a pretty esoteric method of compiling wasm artifacts. This "new power" of the wasm toolchain means that the old `wasm-bindgen-threads` feature of the standard library can be removed since it should now be possible to create a fully functioning threaded wasm module without intrusively dealing with libstd symbols or intrinsics. Yay! [dox]: WebAssembly/tool-conventions#116
eb9090f
to
dc50a63
Compare
@bors: r=nikic |
📌 Commit dc50a63 has been approved by |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
rustc: Update wasm32 support for LLVM 9 This commit brings in a number of minor updates for rustc's support for the wasm target which has changed in the LLVM 9 update. Notable updates include: * The compiler now no longer manually inserts the `producers` section, instead relying on LLVM to do so. LLVM uses the `llvm.ident` metadata for the `processed-by` directive (which is now emitted on the wasm target in this PR) and it uses debuginfo to figure out what `language` to put in the `producers` section. * Threaded WebAssembly code now requires different flags to be passed with LLD. In LLD we now pass: * `--shared-memory` - required since objects are compiled with atomics. This also means that the generated memory will be marked as `shared`. * `--max-memory=1GB` - required with the `--shared-memory` argument since shared memories in WebAssembly must have a maximum size. The 1GB number is intended to be a conservative estimate for rustc, but it should be overridable with `-C link-arg` if necessary. * `--passive-segments` - this has become the default for multithreaded memory, but when compiling a threaded module all data segments need to be marked as passive to ensure they don't re-initialize memory for each thread. This will also cause LLD to emit a synthetic function to initialize memory which users will have to arrange to call. * The `__heap_base` and `__data_end` globals are explicitly exported since they're now hidden by default due to the `--export` flags we pass to LLD.
Rollup of 4 pull requests Successful merges: - #62550 (Implement RFC 2707 + Parser recovery for range patterns) - #62759 (Actually add rustc-guide to toolstate, don't fail builds for the guide) - #62809 (rustc: Update wasm32 support for LLVM 9) - #62974 (bump crossbeam-epoch dependency) Failed merges: r? @ghost
⌛ Testing commit dc50a63 with merge e14bb100ce50095b35791513814b3cbdd10ea862... |
rustc: Update wasm32 support for LLVM 9 This commit brings in a number of minor updates for rustc's support for the wasm target which has changed in the LLVM 9 update. Notable updates include: * The compiler now no longer manually inserts the `producers` section, instead relying on LLVM to do so. LLVM uses the `llvm.ident` metadata for the `processed-by` directive (which is now emitted on the wasm target in this PR) and it uses debuginfo to figure out what `language` to put in the `producers` section. * Threaded WebAssembly code now requires different flags to be passed with LLD. In LLD we now pass: * `--shared-memory` - required since objects are compiled with atomics. This also means that the generated memory will be marked as `shared`. * `--max-memory=1GB` - required with the `--shared-memory` argument since shared memories in WebAssembly must have a maximum size. The 1GB number is intended to be a conservative estimate for rustc, but it should be overridable with `-C link-arg` if necessary. * `--passive-segments` - this has become the default for multithreaded memory, but when compiling a threaded module all data segments need to be marked as passive to ensure they don't re-initialize memory for each thread. This will also cause LLD to emit a synthetic function to initialize memory which users will have to arrange to call. * The `__heap_base` and `__data_end` globals are explicitly exported since they're now hidden by default due to the `--export` flags we pass to LLD.
@bors retry rolled up. |
Rollup of 6 pull requests Successful merges: - #62809 (rustc: Update wasm32 support for LLVM 9) - #63055 (Various cleanups to save analysis) - #63076 (Miri: fix determining size of an "extra function" allocation) - #63077 (cleanup: Remove some language features related to built-in macros) - #63086 (Ignore test cases that are not supported by vxWorks) - #63092 (Update `impl Trait` gate issues) Failed merges: r? @ghost
This commit brings in a number of minor updates for rustc's support for
the wasm target which has changed in the LLVM 9 update. Notable updates
include:
The compiler now no longer manually inserts the
producers
section,instead relying on LLVM to do so. LLVM uses the
llvm.ident
metadatafor the
processed-by
directive (which is now emitted on the wasmtarget in this PR) and it uses debuginfo to figure out what
language
to put in the
producers
section.Threaded WebAssembly code now requires different flags to be passed
with LLD. In LLD we now pass:
--shared-memory
- required since objects are compiled withatomics. This also means that the generated memory will be marked as
shared
.--max-memory=1GB
- required with the--shared-memory
argumentsince shared memories in WebAssembly must have a maximum size. The
1GB number is intended to be a conservative estimate for rustc, but
it should be overridable with
-C link-arg
if necessary.--passive-segments
- this has become the default for multithreadedmemory, but when compiling a threaded module all data segments need
to be marked as passive to ensure they don't re-initialize memory
for each thread. This will also cause LLD to emit a synthetic
function to initialize memory which users will have to arrange to
call.
__heap_base
and__data_end
globals are explicitly exportedsince they're now hidden by default due to the
--export
flags wepass to LLD.