Skip to content

Conversation

@mandlebug
Copy link
Member

Disables -mrop-protect option for the elfv1 ABI. Tests both a target where this ABI is the default and a target where we explicitly have to set the ABI to elfv1.

@mandlebug mandlebug requested review from RolandF77 and amy-kwan May 14, 2025 18:56
@mandlebug mandlebug self-assigned this May 14, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:PowerPC clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 14, 2025
@llvmbot
Copy link
Member

llvmbot commented May 14, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-powerpc

Author: Sean Fertile (mandlebug)

Changes

Disables -mrop-protect option for the elfv1 ABI. Tests both a target where this ABI is the default and a target where we explicitly have to set the ABI to elfv1.


Full diff: https://github.com/llvm/llvm-project/pull/139947.diff

2 Files Affected:

  • (modified) clang/lib/Basic/Targets/PPC.cpp (+6)
  • (modified) clang/test/Driver/ppc-mrop-protection-support-check.c (+13)
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index e6ef0ecc526ba..0cb43a24c8aff 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -685,6 +685,12 @@ bool PPCTargetInfo::initFeatureMap(
       return false;
     }
 
+    if (ABI == "elfv1") {
+      Diags.Report(diag::err_unsupported_abi_for_opt)
+          << "-mrop-protect" << "elfv2";
+      return false;
+    }
+
     if (!(ArchDefs & ArchDefinePwr8)) {
       // We can turn on ROP Protect on Power 8 and above.
       Diags.Report(diag::err_opt_not_valid_with_opt) << "-mrop-protect" << CPU;
diff --git a/clang/test/Driver/ppc-mrop-protection-support-check.c b/clang/test/Driver/ppc-mrop-protection-support-check.c
index f500e9e3e510c..34db142ef6796 100644
--- a/clang/test/Driver/ppc-mrop-protection-support-check.c
+++ b/clang/test/Driver/ppc-mrop-protection-support-check.c
@@ -6,11 +6,23 @@
 // RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
 // RUN:   -mcpu=pwr7 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=NOROP
 
+// RUN: not %clang -target powerpc64-unknown-linux-gnu -fsyntax-only \
+// RUN:   -mcpu=power8 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=ELFV1
+// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
+// RUN:   -mcpu=power8 -mrop-protect -mabi=elfv1 %s 2>&1 | \
+// RUN:   FileCheck %s --check-prefix=ELFV1
+
 // RUN: not %clang -target powerpc-unknown-linux -fsyntax-only \
 // RUN: -mcpu=pwr8 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=32BIT
 // RUN: not %clang -target powerpc-unknown-aix -fsyntax-only \
 // RUN: -mcpu=pwr8 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=32BIT
 
+#ifdef __ROP_PROTECT__
+#if defined(__CALL_ELF) && __CALL_ELF == 1
+#error "ROP protection not supported with 64-bit elfv1 abi"
+#endif
+#endif
+
 #ifdef __ROP_PROTECT__
 static_assert(false, "ROP Protect enabled");
 #endif
@@ -20,3 +32,4 @@ static_assert(false, "ROP Protect enabled");
 // NOROP: option '-mrop-protect' cannot be specified with
 
 // 32BIT: option '-mrop-protect' cannot be specified on this target
+// ELFV1: '-mrop-protect' can only be used with the 'elfv2' ABI

@llvmbot
Copy link
Member

llvmbot commented May 14, 2025

@llvm/pr-subscribers-clang-driver

Author: Sean Fertile (mandlebug)

Changes

Disables -mrop-protect option for the elfv1 ABI. Tests both a target where this ABI is the default and a target where we explicitly have to set the ABI to elfv1.


Full diff: https://github.com/llvm/llvm-project/pull/139947.diff

2 Files Affected:

  • (modified) clang/lib/Basic/Targets/PPC.cpp (+6)
  • (modified) clang/test/Driver/ppc-mrop-protection-support-check.c (+13)
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index e6ef0ecc526ba..0cb43a24c8aff 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -685,6 +685,12 @@ bool PPCTargetInfo::initFeatureMap(
       return false;
     }
 
+    if (ABI == "elfv1") {
+      Diags.Report(diag::err_unsupported_abi_for_opt)
+          << "-mrop-protect" << "elfv2";
+      return false;
+    }
+
     if (!(ArchDefs & ArchDefinePwr8)) {
       // We can turn on ROP Protect on Power 8 and above.
       Diags.Report(diag::err_opt_not_valid_with_opt) << "-mrop-protect" << CPU;
diff --git a/clang/test/Driver/ppc-mrop-protection-support-check.c b/clang/test/Driver/ppc-mrop-protection-support-check.c
index f500e9e3e510c..34db142ef6796 100644
--- a/clang/test/Driver/ppc-mrop-protection-support-check.c
+++ b/clang/test/Driver/ppc-mrop-protection-support-check.c
@@ -6,11 +6,23 @@
 // RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
 // RUN:   -mcpu=pwr7 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=NOROP
 
+// RUN: not %clang -target powerpc64-unknown-linux-gnu -fsyntax-only \
+// RUN:   -mcpu=power8 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=ELFV1
+// RUN: not %clang -target powerpc64le-unknown-linux-gnu -fsyntax-only \
+// RUN:   -mcpu=power8 -mrop-protect -mabi=elfv1 %s 2>&1 | \
+// RUN:   FileCheck %s --check-prefix=ELFV1
+
 // RUN: not %clang -target powerpc-unknown-linux -fsyntax-only \
 // RUN: -mcpu=pwr8 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=32BIT
 // RUN: not %clang -target powerpc-unknown-aix -fsyntax-only \
 // RUN: -mcpu=pwr8 -mrop-protect %s 2>&1 | FileCheck %s --check-prefix=32BIT
 
+#ifdef __ROP_PROTECT__
+#if defined(__CALL_ELF) && __CALL_ELF == 1
+#error "ROP protection not supported with 64-bit elfv1 abi"
+#endif
+#endif
+
 #ifdef __ROP_PROTECT__
 static_assert(false, "ROP Protect enabled");
 #endif
@@ -20,3 +32,4 @@ static_assert(false, "ROP Protect enabled");
 // NOROP: option '-mrop-protect' cannot be specified with
 
 // 32BIT: option '-mrop-protect' cannot be specified on this target
+// ELFV1: '-mrop-protect' can only be used with the 'elfv2' ABI

@RolandF77
Copy link
Collaborator

Fails test.

The preprocessor init check was failing becuase of using rop-protect
with the default ABI which is ELFV1 for powerpc64. Also removed 2 of the
run lines as they only differ in the cpu level.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:PowerPC clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants