Skip to content

Commit

Permalink
show a warning when -Csoft-float is used on a non-eabihf target
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Sep 2, 2024
1 parent 9b82580 commit 45ddafa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_llvm/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ codegen_llvm_sanitizer_memtag_requires_mte =
codegen_llvm_serialize_module = failed to serialize module {$name}
codegen_llvm_serialize_module_with_llvm_err = failed to serialize module {$name}: {$llvm_err}
codegen_llvm_soft_float_ignored =
`-Csoft-float` is ignored on this target; it only has an effect on `*eabihf` targets
codegen_llvm_symbol_already_defined =
symbol `{$symbol_name}` is already defined
Expand Down
14 changes: 12 additions & 2 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::back::profiling::{
selfprofile_after_pass_callback, selfprofile_before_pass_callback, LlvmSelfProfiler,
};
use crate::errors::{
CopyBitcode, FromLlvmDiag, FromLlvmOptimizationDiag, LlvmError, UnknownCompression,
self, CopyBitcode, FromLlvmDiag, FromLlvmOptimizationDiag, LlvmError, UnknownCompression,
WithLlvmError, WriteBytecode,
};
use crate::llvm::diagnostic::OptimizationDiagnosticKind;
Expand Down Expand Up @@ -185,7 +185,17 @@ 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 {
// 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.
if sess.opts.cg.soft_float {
sess.dcx().emit_warn(errors::SoftFloatIgnored);
}
// 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
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_llvm/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,7 @@ pub(crate) struct InvalidTargetFeaturePrefix<'a> {
pub(crate) struct FixedX18InvalidArch<'a> {
pub arch: &'a str,
}

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

0 comments on commit 45ddafa

Please sign in to comment.