[PATCH] D37580: Add Position Independent Pages (PIP) relocation model

Stephen Crane via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 18 18:28:18 PST 2018


rinon updated this revision to Diff 130533.
rinon added a comment.

Rebase


Repository:
  rL LLVM

https://reviews.llvm.org/D37580

Files:
  include/llvm/CodeGen/CommandFlags.def
  include/llvm/Support/CodeGen.h
  include/llvm/Target/TargetMachine.h
  lib/Target/TargetMachine.cpp
  tools/gold/gold-plugin.cpp


Index: tools/gold/gold-plugin.cpp
===================================================================
--- tools/gold/gold-plugin.cpp
+++ tools/gold/gold-plugin.cpp
@@ -246,6 +246,8 @@
       sample_profile= opt.substr(strlen("sample-profile="));
     } else if (opt == "new-pass-manager") {
       new_pass_manager = true;
+    } else if (opt == "pagerando") {
+      RelocationModel = Reloc::PIP;
     } else {
       // Save this option to pass to the code generator.
       // ParseCommandLineOptions() expects argv[0] to be program name. Lazily
@@ -295,15 +297,15 @@
         break;
       case LDPO_DYN: // .so
         IsExecutable = false;
-        RelocationModel = Reloc::PIC_;
+        RelocationModel = RelocationModel ? RelocationModel : Reloc::PIC_;
         break;
       case LDPO_PIE: // position independent executable
         IsExecutable = true;
-        RelocationModel = Reloc::PIC_;
+        RelocationModel = RelocationModel ? RelocationModel : Reloc::PIC_;
         break;
       case LDPO_EXEC: // .exe
         IsExecutable = true;
-        RelocationModel = Reloc::Static;
+        RelocationModel = RelocationModel ? RelocationModel : Reloc::Static;
         break;
       default:
         message(LDPL_ERROR, "Unknown output file type %d", tv->tv_u.tv_val);
Index: lib/Target/TargetMachine.cpp
===================================================================
--- lib/Target/TargetMachine.cpp
+++ lib/Target/TargetMachine.cpp
@@ -49,7 +49,8 @@
 }
 
 bool TargetMachine::isPositionIndependent() const {
-  return getRelocationModel() == Reloc::PIC_;
+  return getRelocationModel() == Reloc::PIC_ ||
+         getRelocationModel() == Reloc::PIP;
 }
 
 /// \brief Reset the target options based on the function's attributes.
@@ -188,7 +189,7 @@
 TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const {
   bool IsPIE = GV->getParent()->getPIELevel() != PIELevel::Default;
   Reloc::Model RM = getRelocationModel();
-  bool IsSharedLibrary = RM == Reloc::PIC_ && !IsPIE;
+  bool IsSharedLibrary = (RM == Reloc::PIC_ || RM == Reloc::PIP) && !IsPIE;
   bool IsLocal = shouldAssumeDSOLocal(*GV->getParent(), GV);
 
   TLSModel::Model Model;
Index: include/llvm/Target/TargetMachine.h
===================================================================
--- include/llvm/Target/TargetMachine.h
+++ include/llvm/Target/TargetMachine.h
@@ -202,6 +202,9 @@
     return Options.FunctionSections;
   }
 
+  /// Return true if Pagerando is enabled on this target.
+  bool isPagerando() const { return getRelocationModel() == Reloc::PIP; }
+
   /// \brief Get a \c TargetIRAnalysis appropriate for the target.
   ///
   /// This is used to construct the new pass manager's target IR analysis pass,
Index: include/llvm/Support/CodeGen.h
===================================================================
--- include/llvm/Support/CodeGen.h
+++ include/llvm/Support/CodeGen.h
@@ -19,7 +19,7 @@
 
   // Relocation model types.
   namespace Reloc {
-  enum Model { Static, PIC_, DynamicNoPIC, ROPI, RWPI, ROPI_RWPI };
+  enum Model { Static, PIC_, DynamicNoPIC, ROPI, RWPI, ROPI_RWPI, PIP };
   }
 
   // Code model types.
Index: include/llvm/CodeGen/CommandFlags.def
===================================================================
--- include/llvm/CodeGen/CommandFlags.def
+++ include/llvm/CodeGen/CommandFlags.def
@@ -55,7 +55,9 @@
             Reloc::RWPI, "rwpi",
             "Read-write data relocatable, accessed relative to static base"),
         clEnumValN(Reloc::ROPI_RWPI, "ropi-rwpi",
-                   "Combination of ropi and rwpi")));
+                   "Combination of ropi and rwpi"),
+        clEnumValN(Reloc::PIP, "pip",
+                   "Position independent pages for Pagerando")));
 
 LLVM_ATTRIBUTE_UNUSED static Optional<Reloc::Model> getRelocModel() {
   if (RelocModel.getNumOccurrences()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37580.130533.patch
Type: text/x-patch
Size: 3860 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180119/9f8dc914/attachment.bin>


More information about the llvm-commits mailing list