Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
use rustc_session::diagnostics::feature_err;
use rustc_span::{Span, Symbol, edit_distance, sym};
use rustc_target::spec::{Arch, SanitizerSet};
use rustc_target::spec::{Arch, Os, SanitizerSet};
use rustc_target::target_features::{RUSTC_SPECIFIC_FEATURES, Stability};
use smallvec::SmallVec;

Expand Down Expand Up @@ -451,6 +451,18 @@ pub fn target_spec_to_backend_features<'a>(
extend_backend_features("ptx70", true);
}

// When targetting aarch64 Fuchsia, the +fix-cortex-a53-835769 should be applied by default
// whenever using the generic (armv8-a) CPU. This matches Clang's behavior for aarch64 Fuchsia.
if sess.target.os == Os::Fuchsia
&& sess.target.arch == Arch::AArch64
&& matches!(
sess.opts.cg.target_cpu.as_deref().unwrap_or(&sess.target.cpu),
"generic" | "cortex-a53"
)
{
extend_backend_features("fix-cortex-a53-835769", true);

@RalfJung RalfJung Sep 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hack (wtf is even going on there) looks LLVM-specific but the file you put it in is also used for other backends.

View changes since the review

}

// Compute implied features
parse_rust_feature_list(
sess,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::spec::{
pub(crate) fn target() -> Target {
let mut base = base::fuchsia::opts();
base.cpu = "generic".into();
base.features = "+v8a,+crc,+aes,+sha2,+neon,+fix-cortex-a53-835769".into();
base.features = "+v8a,+crc,+aes,+sha2,+neon".into();
base.max_atomic_width = Some(128);
base.stack_probes = StackProbeType::Inline;
base.supported_sanitizers = SanitizerSet::ADDRESS
Expand Down
13 changes: 12 additions & 1 deletion tests/codegen-llvm/aarch64-fuchsia-target-features.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
//@ add-minicore
//@ revisions: DEFAULT GENERIC A53 A73 A73_ENABLE DEFAULT_DISABLE
//@ compile-flags: --crate-type=rlib --target=aarch64-unknown-fuchsia
//@ needs-llvm-components: aarch64
//@ [GENERIC] compile-flags: -C target-cpu=generic
//@ [A53] compile-flags: -C target-cpu=cortex-a53
//@ [A73] compile-flags: -C target-cpu=cortex-a73
//@ [A73_ENABLE] compile-flags: -C target-cpu=cortex-a73 -C target-feature=+fix-cortex-a53-835769
//@ [DEFAULT_DISABLE] compile-flags: -C target-feature=-fix-cortex-a53-835769

// CHECK: attributes #0 = { {{.*}}"target-features"="{{.*}}+fix-cortex-a53-835769{{.*}}" }
// DEFAULT: attributes #0 = { {{.*}}"target-features"="{{.*}}+fix-cortex-a53-835769{{.*}}" }
// GENERIC: attributes #0 = { {{.*}}"target-features"="{{.*}}+fix-cortex-a53-835769{{.*}}" }
// A53: attributes #0 = { {{.*}}"target-features"="{{.*}}+fix-cortex-a53-835769{{.*}}" }
// A73-NOT: fix-cortex-a53-835769
// A73_ENABLE: attributes #0 = { {{.*}}"target-features"="{{.*}}+fix-cortex-a53-835769{{.*}}" }
// DEFAULT_DISABLE: attributes #0 = { {{.*}}"target-features"="{{.*}}-fix-cortex-a53-835769" }

#![feature(no_core, lang_items)]
#![no_core]
Expand Down
Loading