[PATCH] D60429: [AArch64][PowerPC][Driver] Allow setting crypto feature through -mcrypto.
tcwang created this revision. tcwang added a project: LLVM. Herald added subscribers: llvm-commits, cfe-commits, jsji, MaskRay, kbarton, kristof.beyls, arichardson, javed.absar, nemanjai, emaste. Herald added a reviewer: espindola. Herald added a project: clang. This enables -mcrypto and -mno-crypto to enable/disable crypto feature to Clang. Before this change, -m(no-)crypto is exclusively for Power8. We want to add this feature to ARM/AArch64 as well. With -mcrypto is specified, +crypto will be passed as a feature to ARM/AArch64/Power8, and -mno-cypto will pass -crypto. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D60429 Files: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Arch/AArch64.cpp clang/lib/Driver/ToolChains/Arch/ARM.cpp clang/lib/Driver/ToolChains/Arch/PPC.cpp clang/lib/Driver/ToolChains/Arch/PPC.h clang/test/Driver/aarch64-crypto.c clang/test/Driver/armv8-crypto.c lld/ELF/CallGraphSort.cpp lld/ELF/Config.h lld/ELF/Driver.cpp lld/ELF/Options.td lld/test/ELF/cgprofile-print.s lld/test/ELF/cgprofile-reproduce.s Index: lld/test/ELF/cgprofile-reproduce.s === --- /dev/null +++ lld/test/ELF/cgprofile-reproduce.s @@ -0,0 +1,42 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "A B 5" > %t.call_graph +# RUN: echo "B C 50" >> %t.call_graph +# RUN: echo "C D 40" >> %t.call_graph +# RUN: echo "D B 10" >> %t.call_graph +# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t2 --print-symbol-order=%t3 +# RUN: ld.lld -e A %t --symbol-ordering-file %t3 -o %t2 +# RUN: llvm-readobj -symbols %t2 | FileCheck %s + +# CHECK: Name: A +# CHECK-NEXT: Value: 0x201003 +# CHECK: Name: B +# CHECK-NEXT: Value: 0x201000 +# CHECK: Name: C +# CHECK-NEXT: Value: 0x201001 +# CHECK: Name: D +# CHECK-NEXT: Value: 0x201002 + +.section.text.A,"ax",@progbits +.globl A +A: + nop + +.section.text.B,"ax",@progbits +.globl B +B: + nop + +.section.text.C,"ax",@progbits +.globl C +C: + nop + +.section.text.D,"ax",@progbits +.globl D +D: + nop + + + Index: lld/test/ELF/cgprofile-print.s === --- /dev/null +++ lld/test/ELF/cgprofile-print.s @@ -0,0 +1,37 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: echo "A B 5" > %t.call_graph +# RUN: echo "B C 50" >> %t.call_graph +# RUN: echo "C D 40" >> %t.call_graph +# RUN: echo "D B 10" >> %t.call_graph +# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t2 --print-symbol-order=%t3 +# RUN: FileCheck %s --input-file %t3 + +# CHECK: B +# CHECK-NEXT: C +# CHECK-NEXT: D +# CHECK-NEXT: A + +.section.text.A,"ax",@progbits +.globl A +A: + nop + +.section.text.B,"ax",@progbits +.globl B +B: + nop + +.section.text.C,"ax",@progbits +.globl C +C: + nop + +.section.text.D,"ax",@progbits +.globl D +D: + nop + + + Index: lld/ELF/Options.td === --- lld/ELF/Options.td +++ lld/ELF/Options.td @@ -274,6 +274,10 @@ "List identical folded sections", "Do not list identical folded sections (default)">; +defm print_symbol_order: + Eq<"print-symbol-order", + "Print a symbol order specified by --call-graph-ordering-file into the speficied file">; + def pop_state: F<"pop-state">, HelpText<"Undo the effect of -push-state">; Index: lld/ELF/Driver.cpp === --- lld/ELF/Driver.cpp +++ lld/ELF/Driver.cpp @@ -828,6 +828,8 @@ Args.hasFlag(OPT_print_icf_sections, OPT_no_print_icf_sections, false); Config->PrintGcSections = Args.hasFlag(OPT_print_gc_sections, OPT_no_print_gc_sections, false); + Config->PrintSymbolOrder = + Args.getLastArgValue(OPT_print_symbol_order); Config->Rpath = getRpath(Args); Config->Relocatable = Args.hasArg(OPT_relocatable); Config->SaveTemps = Args.hasArg(OPT_save_temps); Index: lld/ELF/Config.h === --- lld/ELF/Config.h +++ lld/ELF/Config.h @@ -101,6 +101,7 @@ llvm::StringRef OptRemarksFilename; llvm::StringRef OptRemarksPasses; llvm::StringRef ProgName; + llvm::StringRef PrintSymbolOrder; llvm::StringRef SoName; llvm::StringRef Sysroot; llvm::StringRef ThinLTOCacheDir; Index: lld/ELF/CallGraphSort.cpp === --- lld/ELF/CallGraphSort.cpp +++ lld/ELF/CallGraphSort.cpp @@ -226,6 +226,26 @@ for (int SecIndex : C.Sections) OrderMap[Sections[SecIndex]] = CurOrder++; + if (!Config->PrintSymbolOrder.empty()) { +std::error_code EC; +raw_fd_ostream OS(Config->PrintSymbolOrder, EC, sys::fs::F_None); +if (EC) { + error("cannot open " + Config->PrintSymbolOrder + ": " + EC.message()); +
[PATCH] D60472: [AArch64][PowerPC][Driver] Allow setting crypto feature through -mcrypto.
tcwang created this revision. Herald added subscribers: cfe-commits, jsji, kbarton, kristof.beyls, javed.absar, nemanjai. Herald added a project: clang. tcwang added reviewers: kristof.beyls, dlj, manojgupta. This patch enhances Clang flags -mcrypto and -mno-crypto to enable/disable crypto feature. Before this change, -m(no-)crypto is exclusively for Power8. We want to add this feature to ARM/AArch64 as well. With -mcrypto is specified, '+crypto' will be passed as a target feature to ARM/AArch64/Power8, and -mno-cypto will remove target feature '-crypto'. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D60472 Files: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Arch/AArch64.cpp clang/lib/Driver/ToolChains/Arch/ARM.cpp clang/lib/Driver/ToolChains/Arch/PPC.cpp clang/lib/Driver/ToolChains/Arch/PPC.h clang/test/Driver/aarch64-crypto.c clang/test/Driver/armv8-crypto.c Index: clang/test/Driver/armv8-crypto.c === --- /dev/null +++ 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" Index: clang/test/Driver/aarch64-crypto.c === --- /dev/null +++ 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" Index: clang/lib/Driver/ToolChains/Arch/PPC.h === --- clang/lib/Driver/ToolChains/Arch/PPC.h +++ 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, Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp === --- clang/lib/Driver/ToolChains/Arch/PPC.cpp +++ 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; +} Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp === --- clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ 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 || Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp === --- clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ 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"); Index: clang/include/clang/Driver/Options.td =
[PATCH] D60472: [AArch64][PowerPC][Driver] Allow setting crypto feature through -mcrypto for ARM/AArch64
tcwang marked 4 inline comments as done. tcwang added inline comments. Comment at: clang/lib/Driver/ToolChains/Arch/AArch64.cpp:192 + // En/disable crypto + if (Arg *A = Args.getLastArg(options::OPT_mcrypto, options::OPT_mnocrypto, + options::OPT_mgeneral_regs_only)) { manojgupta wrote: > I believe this should be merged with the code for OPT_mgeneral_regs_only > otherwise the next if statement for mgeneral-regs-only would force > "-crypto" . > > if (A->getOption().matches(OPT_mgeneral_regs_only))) > ..// disable crypto, neon etc. > else if (A->getOption().matches(options::OPT_mcrypto)) > // enable crypto > ... > > Please also add tests when mgeneral-regs-only is specified with "-mcrypto" > before/after. Understand. My question of the logic is that if -mgeneral-regs-only comes before -mcrypto, do we want to set "-fp-armv8" "-neon" or not? In other words, if -mcrypto comes after -mgeneral-regs-only, does it only override '+crypto' or override all the three features? I'll change the logic and add tests after making sure what we really want to do. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60472/new/ https://reviews.llvm.org/D60472 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D60472: [AArch64][PowerPC][Driver] Allow setting crypto feature through -mcrypto for ARM/AArch64
tcwang updated this revision to Diff 194371. tcwang marked an inline comment as done. tcwang added a comment. Fix some comments. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60472/new/ https://reviews.llvm.org/D60472 Files: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Arch/AArch64.cpp clang/lib/Driver/ToolChains/Arch/ARM.cpp clang/lib/Driver/ToolChains/Arch/PPC.cpp clang/lib/Driver/ToolChains/Arch/PPC.h clang/test/Driver/aarch64-crypto.c clang/test/Driver/armv8-crypto.c Index: clang/test/Driver/armv8-crypto.c === --- /dev/null +++ clang/test/Driver/armv8-crypto.c @@ -0,0 +1,18 @@ +// 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" + +// RUN: %clang -target armv8 -mcrypto -msoft-float -### %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-V8-CRYPTO-BEFORE-SOFT-FLOAT < %t %s +// CHECK-V8-CRYPTO-BEFORE-SOFT-FLOAT: "-target-feature" "-crypto" +// CHECK-V8-CRYPTO-BEFORE-SOFT-FLOAT-NOT: "-target-feature" "+crypto" + +// RUN: %clang -target armv8 -msoft-float -mcrypto -### %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-V8-CRYPTO-AFTER-SOFT-FLOAT < %t %s +// CHECK-V8-CRYPTO-AFTER-SOFT-FLOAT: "-target-feature" "-crypto" +// CHECK-V8-CRYPTO-AFTER-SOFT-FLOAT-NOT: "-target-feature" "+crypto" Index: clang/test/Driver/aarch64-crypto.c === --- /dev/null +++ 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" Index: clang/lib/Driver/ToolChains/Arch/PPC.h === --- clang/lib/Driver/ToolChains/Arch/PPC.h +++ 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, Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp === --- clang/lib/Driver/ToolChains/Arch/PPC.cpp +++ 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; +} Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp === --- clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ 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 || Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp === --- clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ 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(o