From 186607f80d441d8dc65ae9612304149bd9451a9a Mon Sep 17 00:00:00 2001 From: Bryan Chan Date: Wed, 11 Jun 2025 17:58:39 -0400 Subject: [PATCH] [Driver] Add options to control workaround for Cortex-A53 Erratum 843419 Implement the -mfix-cortex-a53-843419 and -mno-fix-cortex-a53-843419 options, which have been introduced to GCC to allow the user to control the workaround for the erratum. If the option is enabled (which is the default, unchanged by this patch), Clang passes --fix-cortex-a53-843419 to the linker when it cannot ensure that the target is not a Cortex A53, otherwise it doesn't. See https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html#index-mfix-cortex-a53-843419 for information on the GCC options. Signed-off-by: Bryan Chan --- clang/include/clang/Driver/Options.td | 10 ++++++++-- clang/lib/Driver/ToolChains/Fuchsia.cpp | 4 +++- clang/lib/Driver/ToolChains/Gnu.cpp | 4 +++- clang/test/Driver/android-link.cpp | 12 ++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 6f3a3cb8d6d9..c9c2182e12cd 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3574,10 +3574,16 @@ def mno_fix_cortex_a72_aes_1655431 : Flag<["-"], "mno-fix-cortex-a72-aes-1655431 Alias; def mfix_cortex_a53_835769 : Flag<["-"], "mfix-cortex-a53-835769">, Group, - HelpText<"Workaround Cortex-A53 erratum 835769 (AArch64 only)">; + HelpText<"Work around Cortex-A53 erratum 835769 (AArch64 only)">; def mno_fix_cortex_a53_835769 : Flag<["-"], "mno-fix-cortex-a53-835769">, Group, - HelpText<"Don't workaround Cortex-A53 erratum 835769 (AArch64 only)">; + HelpText<"Don't work around Cortex-A53 erratum 835769 (AArch64 only)">; +def mfix_cortex_a53_843419 : Flag<["-"], "mfix-cortex-a53-843419">, + Group, + HelpText<"Work around Cortex-A53 erratum 843419 (AArch64 only)">; +def mno_fix_cortex_a53_843419 : Flag<["-"], "mno-fix-cortex-a53-843419">, + Group, + HelpText<"Don't work around Cortex-A53 erratum 843419 (AArch64 only)">; def mmark_bti_property : Flag<["-"], "mmark-bti-property">, Group, HelpText<"Add .note.gnu.property with BTI to assembly files (AArch64 only)">; diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp index d63c69c63b1f..c8411e60443c 100644 --- a/clang/lib/Driver/ToolChains/Fuchsia.cpp +++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp @@ -86,7 +86,9 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("--hash-style=gnu"); } - if (ToolChain.getArch() == llvm::Triple::aarch64) { + if (ToolChain.getArch() == llvm::Triple::aarch64 && + Args.hasFlag(options::OPT_mfix_cortex_a53_843419, + options::OPT_mno_fix_cortex_a53_843419, true)) { std::string CPU = getCPUName(D, Args, Triple); if (CPU.empty() || CPU == "generic" || CPU == "cortex-a53") CmdArgs.push_back("--fix-cortex-a53-843419"); diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index a1f74db8bc50..8fd5ae96d62c 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -454,7 +454,9 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, // Most Android ARM64 targets should enable the linker fix for erratum // 843419. Only non-Cortex-A53 devices are allowed to skip this flag. - if (Arch == llvm::Triple::aarch64 && (isAndroid || isOHOSFamily)) { + if (Arch == llvm::Triple::aarch64 && (isAndroid || isOHOSFamily) && + Args.hasFlag(options::OPT_mfix_cortex_a53_843419, + options::OPT_mno_fix_cortex_a53_843419, true)) { std::string CPU = getCPUName(D, Args, Triple); if (CPU.empty() || CPU == "generic" || CPU == "cortex-a53") CmdArgs.push_back("--fix-cortex-a53-843419"); diff --git a/clang/test/Driver/android-link.cpp b/clang/test/Driver/android-link.cpp index fa9cbc5d0c7a..108f8140b54a 100644 --- a/clang/test/Driver/android-link.cpp +++ b/clang/test/Driver/android-link.cpp @@ -16,10 +16,22 @@ // RUN: FileCheck -check-prefix=CORTEX-A57 < %t %s // // RUN: %clang -target aarch64-none-linux-android \ +// RUN: -mno-fix-cortex-a53-843419 \ +// RUN: -### -v %s 2> %t +// RUN: FileCheck -check-prefix=OVERRIDDEN < %t %s +// +// RUN: %clang -target aarch64-none-linux-android \ +// RUN: -mno-fix-cortex-a53-843419 -mfix-cortex-a53-843419 \ +// RUN: -### -v %s 2> %t +// RUN: FileCheck -check-prefix=OVERRIDDEN2 < %t %s +// +// RUN: %clang -target aarch64-none-linux-android \ // RUN: -### -v %s 2> %t // RUN: FileCheck -check-prefix=MAX-PAGE-SIZE < %t %s // // GENERIC-ARM: --fix-cortex-a53-843419 // CORTEX-A53: --fix-cortex-a53-843419 // CORTEX-A57-NOT: --fix-cortex-a53-843419 +// OVERRIDDEN-NOT: --fix-cortex-a53-843419 +// OVERRIDDEN2: --fix-cortex-a53-843419 // MAX-PAGE-SIZE: "-z" "max-page-size=4096" -- Gitee