Skip to content

Commit

Permalink
[PowerPC] Change option to mrop-protect
Browse files Browse the repository at this point in the history
In order to have the same option on power PC LLVM and power PC gcc
the option will be changed from -mrop-protection to -mrop-protect.

The feature will be off by default and turned on when the option is used.

Reviewed By: lei, amyk

Differential Revision: https://reviews.llvm.org/D99185
  • Loading branch information
stefanp-ibm committed Mar 24, 2021
1 parent f8a850c commit 0e4f5f3
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 45 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -3245,7 +3245,7 @@ def mno_longcall : Flag<["-"], "mno-longcall">,
Group<m_ppc_Features_Group>;
def mmma: Flag<["-"], "mmma">, Group<m_ppc_Features_Group>;
def mno_mma: Flag<["-"], "mno-mma">, Group<m_ppc_Features_Group>;
def mrop_protection : Flag<["-"], "mrop-protection">,
def mrop_protect : Flag<["-"], "mrop-protect">,
Group<m_ppc_Features_Group>;
def maix_struct_return : Flag<["-"], "maix-struct-return">,
Group<m_Group>, Flags<[CC1Option]>,
Expand Down
20 changes: 10 additions & 10 deletions clang/lib/Basic/Targets/PPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ bool PPCTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
PairedVectorMemops = true;
} else if (Feature == "+mma") {
HasMMA = true;
} else if (Feature == "+rop-protection") {
HasROPProtection = true;
} else if (Feature == "+rop-protect") {
HasROPProtect = true;
}
// TODO: Finish this list and add an assert that we've handled them
// all.
Expand Down Expand Up @@ -195,8 +195,8 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
Builder.defineMacro("__POWER9_VECTOR__");
if (HasMMA)
Builder.defineMacro("__MMA__");
if (HasROPProtection)
Builder.defineMacro("__ROP_PROTECTION__");
if (HasROPProtect)
Builder.defineMacro("__ROP_PROTECT__");
if (HasP10Vector)
Builder.defineMacro("__POWER10_VECTOR__");
if (HasPCRelativeMemops)
Expand Down Expand Up @@ -325,8 +325,8 @@ bool PPCTargetInfo::initFeatureMap(
.Case("pwr8", true)
.Default(false);

// ROP Protection is off by default.
Features["rop-protection"] = false;
// ROP Protect is off by default.
Features["rop-protect"] = false;

Features["spe"] = llvm::StringSwitch<bool>(CPU)
.Case("8548", true)
Expand Down Expand Up @@ -365,9 +365,9 @@ bool PPCTargetInfo::initFeatureMap(
}

if (!(ArchDefs & ArchDefinePwr8) &&
llvm::find(FeaturesVec, "+rop-protection") != FeaturesVec.end()) {
// We can turn on ROP Protection on Power 8 and above.
Diags.Report(diag::err_opt_not_valid_with_opt) << "-mrop-protection" << CPU;
llvm::find(FeaturesVec, "+rop-protect") != FeaturesVec.end()) {
// We can turn on ROP Protect on Power 8 and above.
Diags.Report(diag::err_opt_not_valid_with_opt) << "-mrop-protect" << CPU;
return false;
}

Expand Down Expand Up @@ -409,7 +409,7 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
.Case("pcrelative-memops", HasPCRelativeMemops)
.Case("spe", HasSPE)
.Case("mma", HasMMA)
.Case("rop-protection", HasROPProtection)
.Case("rop-protect", HasROPProtect)
.Default(false);
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/Targets/PPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
// Target cpu features.
bool HasAltivec = false;
bool HasMMA = false;
bool HasROPProtection = false;
bool HasROPProtect = false;
bool HasVSX = false;
bool HasP8Vector = false;
bool HasP8Crypto = false;
Expand Down
26 changes: 13 additions & 13 deletions clang/test/Driver/ppc-mrop-protection-support-check.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
// RUN: -mcpu=pwr10 -mrop-protection %s 2>&1 | FileCheck %s --check-prefix=HASROP
// RUN: -mcpu=pwr10 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=HASROP
// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
// RUN: -mcpu=power10 -mrop-protection %s 2>&1 | FileCheck %s --check-prefix=HASROP
// RUN: -mcpu=power10 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=HASROP
// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
// RUN: -mcpu=pwr9 -mrop-protection %s 2>&1 | FileCheck %s --check-prefix=HASROP
// RUN: -mcpu=pwr9 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=HASROP
// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
// RUN: -mcpu=power9 -mrop-protection %s 2>&1 | FileCheck %s --check-prefix=HASROP
// RUN: -mcpu=power9 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=HASROP
// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
// RUN: -mcpu=pwr8 -mrop-protection %s 2>&1 | FileCheck %s --check-prefix=HASROP
// RUN: -mcpu=pwr8 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=HASROP
// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
// RUN: -mcpu=power8 -mrop-protection %s 2>&1 | FileCheck %s --check-prefix=HASROP
// RUN: -mcpu=power8 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=HASROP

// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
// RUN: -mcpu=pwr7 -mrop-protection %s 2>&1 | FileCheck %s --check-prefix=NOROP
// RUN: -mcpu=pwr7 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=NOROP
// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
// RUN: -mcpu=power7 -mrop-protection %s 2>&1 | FileCheck %s --check-prefix=NOROP
// RUN: -mcpu=power7 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=NOROP

#ifdef __ROP_PROTECTION__
static_assert(false, "ROP Protection enabled");
#ifdef __ROP_PROTECT__
static_assert(false, "ROP Protect enabled");
#endif

// HASROP: ROP Protection enabled
// HASROP-NOT: option '-mrop-protection' cannot be specified with
// NOROP: option '-mrop-protection' cannot be specified with
// HASROP: ROP Protect enabled
// HASROP-NOT: option '-mrop-protect' cannot be specified with
// NOROP: option '-mrop-protect' cannot be specified with

20 changes: 10 additions & 10 deletions clang/test/Preprocessor/init-ppc64.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@
// PPCPWR8-NOT:#define _ARCH_PWR6X 1
// PPCPWR8:#define _ARCH_PWR7 1
// PPCPWR8:#define _ARCH_PWR8 1
// PPCPWR8-NOT:#define __ROP_PROTECTION__ 1
// PPCPWR8-NOT:#define __ROP_PROTECT__ 1
//
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-cpu power8 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPCPOWER8 %s
//
Expand All @@ -584,7 +584,7 @@
// PPCPOWER8-NOT:#define _ARCH_PWR6X 1
// PPCPOWER8:#define _ARCH_PWR7 1
// PPCPOWER8:#define _ARCH_PWR8 1
// PPCPOWER8-NOT:#define __ROP_PROTECTION__ 1
// PPCPOWER8-NOT:#define __ROP_PROTECT__ 1
//
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-cpu pwr9 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPCPWR9 %s
//
Expand All @@ -599,7 +599,7 @@
// PPCPWR9-NOT:#define _ARCH_PWR6X 1
// PPCPWR9:#define _ARCH_PWR7 1
// PPCPWR9:#define _ARCH_PWR9 1
// PPCPWR9-NOT:#define __ROP_PROTECTION__ 1
// PPCPWR9-NOT:#define __ROP_PROTECT__ 1
//
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-cpu power9 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPCPOWER9 %s
//
Expand All @@ -614,7 +614,7 @@
// PPCPOWER9-NOT:#define _ARCH_PWR6X 1
// PPCPOWER9:#define _ARCH_PWR7 1
// PPCPOWER9:#define _ARCH_PWR9 1
// PPCPOWER9-NOT:#define __ROP_PROTECTION__ 1
// PPCPOWER9-NOT:#define __ROP_PROTECT__ 1
//
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-cpu pwr10 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPCPOWER10 %s
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-cpu power10 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPCPOWER10 %s
Expand All @@ -634,7 +634,7 @@
// PPCPOWER10:#define _ARCH_PWR9 1
// PPCPOWER10:#define __MMA__ 1
// PPCPOWER10:#define __PCREL__ 1
// PPCPOWER10-NOT:#define __ROP_PROTECTION__ 1
// PPCPOWER10-NOT:#define __ROP_PROTECT__ 1
//
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-cpu future -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPCFUTURE %s
//
Expand All @@ -654,15 +654,15 @@
// PPCFUTURE:#define _ARCH_PWR_FUTURE 1
// PPCFUTURE:#define __MMA__ 1
// PPCFUTURE:#define __PCREL__ 1
// PPCFUTURE-NOT:#define __ROP_PROTECTION__ 1
// PPCFUTURE-NOT:#define __ROP_PROTECT__ 1
//
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-feature +mma -target-cpu power10 -fno-signed-char < /dev/null | FileCheck -check-prefix PPC-MMA %s
// PPC-MMA:#define __MMA__ 1
//
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-feature +rop-protection -target-cpu power10 -fno-signed-char < /dev/null | FileCheck -check-prefix PPC-ROP %s
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-feature +rop-protection -target-cpu power9 -fno-signed-char < /dev/null | FileCheck -check-prefix PPC-ROP %s
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-feature +rop-protection -target-cpu power8 -fno-signed-char < /dev/null | FileCheck -check-prefix PPC-ROP %s
// PPC-ROP:#define __ROP_PROTECTION__ 1
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-feature +rop-protect -target-cpu power10 -fno-signed-char < /dev/null | FileCheck -check-prefix PPC-ROP %s
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-feature +rop-protect -target-cpu power9 -fno-signed-char < /dev/null | FileCheck -check-prefix PPC-ROP %s
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-feature +rop-protect -target-cpu power8 -fno-signed-char < /dev/null | FileCheck -check-prefix PPC-ROP %s
// PPC-ROP:#define __ROP_PROTECT__ 1
//
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-none-none -target-feature +float128 -target-cpu power9 -fno-signed-char < /dev/null | FileCheck -check-prefix PPC-FLOAT128 %s
// PPC-FLOAT128:#define __FLOAT128__ 1
Expand Down
9 changes: 4 additions & 5 deletions llvm/lib/Target/PowerPC/PPC.td
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ def FeatureMMA : SubtargetFeature<"mma", "HasMMA", "true",
"Enable MMA instructions",
[FeatureP8Vector, FeatureP9Altivec,
FeaturePairedVectorMemops]>;
def FeatureROPProtection :
SubtargetFeature<"rop-protection", "HasROPProtection", "false",
"Add ROP protection">;
def FeatureROPProtect :
SubtargetFeature<"rop-protect", "HasROPProtect", "true",
"Add ROP protect">;

def FeaturePredictableSelectIsExpensive :
SubtargetFeature<"predictable-select-expensive",
Expand Down Expand Up @@ -323,8 +323,7 @@ def ProcessorFeatures {
FeatureDirectMove,
FeatureICBT,
FeaturePartwordAtomic,
FeaturePredictableSelectIsExpensive,
FeatureROPProtection
FeaturePredictableSelectIsExpensive
];

list<SubtargetFeature> P8SpecificFeatures = [FeatureAddiLoadFusion,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/PowerPC/PPCSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void PPCSubtarget::initializeEnvironment() {
HasP9Vector = false;
HasP9Altivec = false;
HasMMA = false;
HasROPProtection = false;
HasROPProtect = false;
HasP10Vector = false;
HasPrefixInstrs = false;
HasPCRelativeMemops = false;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/PowerPC/PPCSubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class PPCSubtarget : public PPCGenSubtargetInfo {
bool HasPrefixInstrs;
bool HasPCRelativeMemops;
bool HasMMA;
bool HasROPProtection;
bool HasROPProtect;
bool HasFCPSGN;
bool HasFSQRT;
bool HasFRE, HasFRES, HasFRSQRTE, HasFRSQRTES;
Expand Down Expand Up @@ -274,7 +274,7 @@ class PPCSubtarget : public PPCGenSubtargetInfo {
bool hasPrefixInstrs() const { return HasPrefixInstrs; }
bool hasPCRelativeMemops() const { return HasPCRelativeMemops; }
bool hasMMA() const { return HasMMA; }
bool hasROPProtection() const { return HasROPProtection; }
bool hasROPProtect() const { return HasROPProtect; }
bool pairedVectorMemops() const { return PairedVectorMemops; }
bool hasMFOCRF() const { return HasMFOCRF; }
bool hasISEL() const { return HasISEL; }
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/PowerPC/future-check-features.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; RUN: llc -mattr=pcrelative-memops,prefix-instrs,paired-vector-memops,mma,rop-protection \
; RUN: llc -mattr=pcrelative-memops,prefix-instrs,paired-vector-memops,mma,rop-protect \
; RUN: -verify-machineinstrs -mtriple=powerpc64le-unknown-unknown \
; RUN: -ppc-asm-full-reg-names %s -o - 2>&1 | FileCheck %s
; RUN: llc -mattr=pcrelative-memops,prefix-instrs,paired-vector-memops,mma,rop-protection \
; RUN: llc -mattr=pcrelative-memops,prefix-instrs,paired-vector-memops,mma,rop-protect \
; RUN: -verify-machineinstrs -mtriple=powerpc64-unknown-unknown \
; RUN: -ppc-asm-full-reg-names %s -o - 2>&1 | FileCheck %s

Expand Down

0 comments on commit 0e4f5f3

Please sign in to comment.