Skip to content

Commit

Permalink
deprecate -Csoft-float because it is unsound (and not fixable)
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Sep 3, 2024
1 parent 9b82580 commit f2c4e12
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,13 @@ pub(crate) fn target_machine_factory(
let reloc_model = to_llvm_relocation_model(sess.relocation_model());

let (opt_level, _) = to_llvm_opt_settings(optlvl);
let use_softfp = sess.opts.cg.soft_float;
let use_softfp = if sess.target.arch == "arm" && sess.target.abi == "eabihf" {
sess.opts.cg.soft_float
} else {
// `validate_commandline_args_with_session_available` has already warned about this being ignored.
// Let's make sure LLVM doesn't suddenly start using this flag on more targets.
false
};

let ffunction_sections =
sess.opts.unstable_opts.function_sections.unwrap_or(sess.target.function_sections);
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_session/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ session_embed_source_insufficient_dwarf_version = `-Zembed-source=y` requires at
session_embed_source_requires_debug_info = `-Zembed-source=y` requires debug information to be enabled
session_soft_float_deprecated =
`-Csoft-float` is unsound and deprecated; use a corresponding *eabi target instead
.note = it will be removed or ignored in a future version of Rust
session_soft_float_deprecated_issue = see issue #129893 <https://github.com/rust-lang/rust/issues/129893> for more information
session_soft_float_ignored =
`-Csoft-float` is ignored on this target; it only has an effect on *eabihf targets
.note = this may become a hard error in a future version of Rust
session_expr_parentheses_needed = parentheses are required to parse this as an expression
session_failed_to_create_profiler = failed to create profiler: {$err}
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_session/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,14 @@ pub(crate) struct FunctionReturnThunkExternRequiresNonLargeCodeModel;
pub(crate) struct FailedToCreateProfiler {
pub(crate) err: String,
}

#[derive(Diagnostic)]
#[diag(session_soft_float_ignored)]
#[note]
pub(crate) struct SoftFloatIgnored;

#[derive(Diagnostic)]
#[diag(session_soft_float_deprecated)]
#[note]
#[note(session_soft_float_deprecated_issue)]
pub(crate) struct SoftFloatDeprecated;
10 changes: 10 additions & 0 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,16 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
}
}
}

if sess.opts.cg.soft_float {
if sess.target.arch == "arm" && sess.target.abi == "eabihf" {
sess.dcx().emit_warn(errors::SoftFloatDeprecated);
} else {
// All `use_softfp` does is the equivalent of `-mfloat-abi` in GCC/clang, which only exists on ARM targets.
// We document this flag to only affect `*eabihf` targets, so let's show a warning for all other targets.
sess.dcx().emit_warn(errors::SoftFloatIgnored);
}
}
}

/// Holds data on the current incremental compilation session, if there is one.
Expand Down

0 comments on commit f2c4e12

Please sign in to comment.