[rustc 1.77] error: shared reference of mutable static is discouraged
Categories
(Core :: Gecko Profiler, defect)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox124 | --- | fixed |
People
(Reporter: glandium, Assigned: canova)
References
Details
Attachments
(1 file)
[task 2024-01-30T06:21:02.603Z] 06:21:02 INFO - error: shared reference of mutable static is discouraged
[task 2024-01-30T06:21:02.604Z] 06:21:02 INFO - --> tools/profiler/rust-api/src/profiler_state.rs:76:46
[task 2024-01-30T06:21:02.604Z] 06:21:02 INFO - |
[task 2024-01-30T06:21:02.605Z] 06:21:02 INFO - 76 | unsafe { mem::transmute::<_, &AtomicU32>(&detail::RacyFeatures_sActiveAndFeatures) }
[task 2024-01-30T06:21:02.605Z] 06:21:02 INFO - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ shared reference of mutable static
[task 2024-01-30T06:21:02.605Z] 06:21:02 INFO - |
[task 2024-01-30T06:21:02.606Z] 06:21:02 INFO - = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
[task 2024-01-30T06:21:02.606Z] 06:21:02 INFO - = note: reference of mutable static is a hard error from 2024 edition
[task 2024-01-30T06:21:02.607Z] 06:21:02 INFO - = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
[task 2024-01-30T06:21:02.607Z] 06:21:02 INFO - = note: `-D static-mut-ref` implied by `-D warnings`
[task 2024-01-30T06:21:02.607Z] 06:21:02 INFO - = help: to override `-D warnings` add `#[allow(static_mut_ref)]`
[task 2024-01-30T06:21:02.607Z] 06:21:02 INFO - help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
[task 2024-01-30T06:21:02.608Z] 06:21:02 INFO - |
[task 2024-01-30T06:21:02.608Z] 06:21:02 INFO - 76 | unsafe { mem::transmute::<_, &AtomicU32>(addr_of!(detail::RacyFeatures_sActiveAndFeatures)) }
[task 2024-01-30T06:21:02.608Z] 06:21:02 INFO - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[task 2024-01-30T06:21:02.608Z] 06:21:02 INFO - [swgl 0.1.0] exit status: 0
[task 2024-01-30T06:21:02.608Z] 06:21:02 INFO - error: could not compile `gecko-profiler` (lib) due to 1 previous error
| Reporter | ||
Comment 1•2 years ago
|
||
(This is when building with current rust nightly (1.77))
| Reporter | ||
Updated•2 years ago
|
| Assignee | ||
Comment 2•2 years ago
|
||
Thanks for filing! Looking into it now.
| Assignee | ||
Comment 3•2 years ago
|
||
This variable is an atomic variable here:
https://searchfox.org/mozilla-central/rev/2a867dd1ab015c3ef24b774a57709fb3b3dc4961/tools/profiler/core/platform.cpp#1631
We are getting this C++ atomic variable here directly instead of using FFIs
because this is much faster and this function has to be as fast as possible
(because it will be used before adding each marker to make sure the profiler is
running.). It's used by is_active and can_accept_markers functions above
this file.
It looks like Rust 1.77 starts to give some warnings/errors for these cases
where we have shared references. This should be safe for us, because we already
know that this function can be racy. So this is something we considered and
decided that it's better to be faster.
Updated•2 years ago
|
Updated•2 years ago
|
Comment 5•2 years ago
|
||
| bugherder | ||
Description
•