[PATCH] D44921: [PowerPC] Option for secure plt mode

Strahinja Petrovic via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 27 05:45:38 PDT 2018


spetrovic created this revision.
spetrovic added reviewers: jhibbits, nemanjai.
Herald added a subscriber: kbarton.

This patch enables option for secure plt mode in clang (-msecure-plt). This feature is supported in backend also (https://reviews.llvm.org/D42112).


https://reviews.llvm.org/D44921

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Arch/PPC.cpp
  lib/Driver/ToolChains/Arch/PPC.h
  test/Driver/ppc-features.cpp


Index: test/Driver/ppc-features.cpp
===================================================================
--- test/Driver/ppc-features.cpp
+++ test/Driver/ppc-features.cpp
@@ -22,6 +22,10 @@
 // RUN: %clang -target powerpc-unknown-linux-gnu %s -msoft-float -mhard-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-SOFTHARD %s
 // CHECK-SOFTHARD-NOT: "-target-feature" "-hard-float"
 
+// check -msecure-plt option for ppc32
+// RUN: %clang -target powerpc-unknown-linux-gnu -msecure-plt %s  -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-SECUREPLT %s
+// CHECK-SECUREPLT: "-target-feature" "+secure-plt"
+
 // check -mfloat-abi=x option
 // RUN: %clang -target powerpc-unknown-linux-gnu %s -mfloat-abi=x -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-ERRMSG %s
 // CHECK-ERRMSG: error: invalid float ABI '-mfloat-abi=x'
Index: lib/Driver/ToolChains/Arch/PPC.h
===================================================================
--- lib/Driver/ToolChains/Arch/PPC.h
+++ lib/Driver/ToolChains/Arch/PPC.h
@@ -29,10 +29,17 @@
   Hard,
 };
 
+enum class ReadGOTPtrMode {
+  Bss,
+  SecurePlt,
+};
+
 FloatABI getPPCFloatABI(const Driver &D, const llvm::opt::ArgList &Args);
 
 std::string getPPCTargetCPU(const llvm::opt::ArgList &Args);
 const char *getPPCAsmModeForCPU(StringRef Name);
+ReadGOTPtrMode getPPCReadGOTPtrMode(const Driver &D,
+	                                const llvm::opt::ArgList &Args);
 
 void getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple,
                           const llvm::opt::ArgList &Args,
Index: lib/Driver/ToolChains/Arch/PPC.cpp
===================================================================
--- lib/Driver/ToolChains/Arch/PPC.cpp
+++ lib/Driver/ToolChains/Arch/PPC.cpp
@@ -106,6 +106,17 @@
   ppc::FloatABI FloatABI = ppc::getPPCFloatABI(D, Args);
   if (FloatABI == ppc::FloatABI::Soft)
     Features.push_back("-hard-float");
+
+  ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Args);
+  if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
+    Features.push_back("+secure-plt");
+}
+
+ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver &D, const ArgList &Args) {
+  ppc::ReadGOTPtrMode ReadGOT = ppc::ReadGOTPtrMode::Bss;
+  if (Args.getLastArg(options::OPT_msecure_plt))
+    ReadGOT = ppc::ReadGOTPtrMode::SecurePlt;
+  return ReadGOT;
 }
 
 ppc::FloatABI ppc::getPPCFloatABI(const Driver &D, const ArgList &Args) {
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1938,6 +1938,7 @@
 def mno_altivec : Flag<["-"], "mno-altivec">, Group<m_ppc_Features_Group>;
 def mvsx : Flag<["-"], "mvsx">, Group<m_ppc_Features_Group>;
 def mno_vsx : Flag<["-"], "mno-vsx">, Group<m_ppc_Features_Group>;
+def msecure_plt : Flag<["-"], "msecure-plt">, Group<m_ppc_Features_Group>;
 def mpower8_vector : Flag<["-"], "mpower8-vector">,
     Group<m_ppc_Features_Group>;
 def mno_power8_vector : Flag<["-"], "mno-power8-vector">,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44921.139904.patch
Type: text/x-patch
Size: 3034 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180327/52da6b96/attachment.bin>


More information about the cfe-commits mailing list