diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2215,10 +2215,10 @@ Group; def mno_power9_vector : Flag<["-"], "mno-power9-vector">, Group; -def mpower8_crypto : Flag<["-"], "mcrypto">, - Group; -def mnopower8_crypto : Flag<["-"], "mno-crypto">, - Group; +def mcrypto : Flag<["-"], "mcrypto">, Group, + HelpText<"Add use of cryptographic instructions (ARM/PowerPC only)">; +def mnocrypto : Flag<["-"], "mno-crypto">, Group, + HelpText<"Disallow use of cryptographic instructions (ARM/PowerPC only)">; def mdirect_move : Flag<["-"], "mdirect-move">, Group; def mnodirect_move : Flag<["-"], "mno-direct-move">, diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp --- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp @@ -188,6 +188,15 @@ if (!success) D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args); + // En/disable crypto + if (Arg *A = Args.getLastArg(options::OPT_mcrypto, options::OPT_mnocrypto, + options::OPT_mgeneral_regs_only)) { + if (A->getOption().matches(options::OPT_mcrypto)) + Features.push_back("+crypto"); + else + Features.push_back("-crypto"); + } + if (Args.getLastArg(options::OPT_mgeneral_regs_only)) { Features.push_back("-fp-armv8"); Features.push_back("-crypto"); diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp b/clang/lib/Driver/ToolChains/Arch/ARM.cpp --- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp @@ -448,6 +448,14 @@ Features.push_back("-crc"); } + // En/disable crypto + if (Arg *A = Args.getLastArg(options::OPT_mcrypto, options::OPT_mnocrypto)) { + if (A->getOption().matches(options::OPT_mcrypto) && ABI != arm::FloatABI::Soft) + Features.push_back("+crypto"); + else + Features.push_back("-crypto"); + } + // For Arch >= ARMv8.0: crypto = sha2 + aes // FIXME: this needs reimplementation after the TargetParser rewrite if (ArchName.find_lower("armv8a") != StringRef::npos || diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.h b/clang/lib/Driver/ToolChains/Arch/PPC.h --- a/clang/lib/Driver/ToolChains/Arch/PPC.h +++ b/clang/lib/Driver/ToolChains/Arch/PPC.h @@ -22,6 +22,8 @@ bool hasPPCAbiArg(const llvm::opt::ArgList &Args, const char *Value); +bool hasCryptoFeatureEnabled(const llvm::opt::ArgList &Args); + enum class FloatABI { Invalid, Soft, diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp b/clang/lib/Driver/ToolChains/Arch/PPC.cpp --- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp +++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp @@ -109,6 +109,9 @@ ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Triple, Args); if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt) Features.push_back("+secure-plt"); + + if (ppc::hasCryptoFeatureEnabled(Args)) + Features.push_back("+crypto"); } ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver &D, const llvm::Triple &Triple, @@ -154,3 +157,10 @@ Arg *A = Args.getLastArg(options::OPT_mabi_EQ); return A && (A->getValue() == StringRef(Value)); } + +bool ppc::hasCryptoFeatureEnabled(const ArgList &Args) { + if (Arg *A = Args.getLastArg(options::OPT_mcrypto, options::OPT_mnocrypto)) + if (A->getOption().matches(options::OPT_mcrypto)) + return true; + return false; +} diff --git a/clang/test/Driver/aarch64-crypto.c b/clang/test/Driver/aarch64-crypto.c new file mode 100644 --- /dev/null +++ b/clang/test/Driver/aarch64-crypto.c @@ -0,0 +1,8 @@ +// REQUIRES: aarch64-registered-target +// RUN: %clang -target aarch64 -mcrypto -### %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-AARCH64-CRYPTO < %t %s +// CHECK-AARCH64-CRYPTO: "-target-feature" "+crypto" + +// RUN: %clang -target aarch64 -mno-crypto -### %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-AARCH64-NOCRYPTO < %t %s +// CHECK-AARCH64-NOCRYPTO: "-target-feature" "-crypto" diff --git a/clang/test/Driver/armv8-crypto.c b/clang/test/Driver/armv8-crypto.c new file mode 100644 --- /dev/null +++ b/clang/test/Driver/armv8-crypto.c @@ -0,0 +1,8 @@ +// REQUIRES: arm-registered-target +// RUN: %clang -target armv8 -mcrypto -mhard-float -### %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-V8-CRYPTO < %t %s +// CHECK-V8-CRYPTO: "-target-feature" "+crypto" + +// RUN: %clang -target armv8 -mno-crypto -mhard-float -### %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-V8-NOCRYPTO < %t %s +// CHECK-V8-NOCRYPTO: "-target-feature" "-crypto"