Skip to content

Commit 4ac8e90

Browse files
authored
[PPC] Disable rop-protect for 32-bit OS targets. (#139619)
The instructions are not supported on either 32-bit ELF (due to no redzone) or 32-bit AIX due to the instructions always using the full 64-bit width of the register inputs.
1 parent 441d382 commit 4ac8e90

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,17 @@ bool PPCTargetInfo::initFeatureMap(
679679
}
680680
}
681681

682-
if (!(ArchDefs & ArchDefinePwr8) &&
683-
llvm::is_contained(FeaturesVec, "+rop-protect")) {
684-
// We can turn on ROP Protect on Power 8 and above.
685-
Diags.Report(diag::err_opt_not_valid_with_opt) << "-mrop-protect" << CPU;
686-
return false;
682+
if (llvm::is_contained(FeaturesVec, "+rop-protect")) {
683+
if (PointerWidth == 32) {
684+
Diags.Report(diag::err_opt_not_valid_on_target) << "-mrop-protect";
685+
return false;
686+
}
687+
688+
if (!(ArchDefs & ArchDefinePwr8)) {
689+
// We can turn on ROP Protect on Power 8 and above.
690+
Diags.Report(diag::err_opt_not_valid_with_opt) << "-mrop-protect" << CPU;
691+
return false;
692+
}
687693
}
688694

689695
if (!(ArchDefs & ArchDefinePwr8) &&

clang/test/Driver/ppc-mrop-protection-support-check.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
1717
// RUN: -mcpu=power7 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=NOROP
1818

19+
// RUN: not %clang -target powerpc-unknown-linux -fsyntax-only \
20+
// RUN: -mcpu=pwr8 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=32BIT
21+
// RUN: not %clang -target powerpc-unknown-aix -fsyntax-only \
22+
// RUN: -mcpu=pwr8 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=32BIT
23+
1924
#ifdef __ROP_PROTECT__
2025
static_assert(false, "ROP Protect enabled");
2126
#endif
@@ -24,3 +29,4 @@ static_assert(false, "ROP Protect enabled");
2429
// HASROP-NOT: option '-mrop-protect' cannot be specified with
2530
// NOROP: option '-mrop-protect' cannot be specified with
2631

32+
// 32BIT: option '-mrop-protect' cannot be specified on this target

0 commit comments

Comments
 (0)