Skip to content

Commit d98922f

Browse files
committed
rust: add workaround for potential compiler bug
Apply workaround for a potential miscompilation bug: See - rust-embedded/cortex-m#503 - rust-lang/rust#118867 We have not observed any abnormal behavior even though we fulfil all the criteria to be affected (opt-level='z', thumbv7em-none-eabi target, Rust toolchain 1.74.0 being >= 1.73.0), but we apply the workaround just in case. This increases the binary size of the `make firmware` (Multi) build by 11568 at the time of adding this workaround. This can be removed again once the issue above is fixed and we have updated to a Rust toolchain that contains the fix. This workaround is one of three suggested alternatives. The other two are: - Downgrade the Rust toolchain - dismissed as it is harder to do, as it involves re-building the Docker image - Switch from opt-level='z' to opt-level='s' - this increases the binary size by 74416 bytes for the Multi, which is much more than the workaround in this commit.
1 parent 460c7bd commit d98922f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,19 @@ endif()
217217
# See https://github.com/rust-bitcoin/rust-secp256k1/tree/7c8270a8506e31731e540fab7ee1abde1f48314e/secp256k1-sys#linking-to-external-symbols
218218
set(RUSTFLAGS "${RUSTFLAGS} --cfg=rust_secp_no_symbol_renaming")
219219

220+
# Apply workaround for a potential miscompilation bug:
221+
# See
222+
# - https://github.com/rust-embedded/cortex-m/discussions/503
223+
# - https://github.com/rust-lang/rust/issues/118867
224+
# We have not observed any abnormal behavior even though we fulfil all the criteria to be affected
225+
# (opt-level='z', thumbv7em-none-eabi target, Rust toolchain 1.74.0 being >= 1.73.0), but we apply
226+
# the workaround just in case.
227+
#
228+
# This increases the binary size of the `make firmware` (Multi) build by 11568 at the time of
229+
# adding this workaround. This can be removed again once the issue above is fixed and we have
230+
# updated to a Rust toolchain that contains the fix.
231+
set(RUSTFLAGS "${RUSTFLAGS} -Cllvm-args=--enable-machine-outliner=never")
232+
220233
if(CMAKE_CROSSCOMPILING)
221234
set(RUST_TARGET_ARCH thumbv7em-none-eabi)
222235
set(RUST_TARGET_ARCH_DIR ${RUST_TARGET_ARCH})

0 commit comments

Comments
 (0)