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

Stephen Crane via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 25 15:33:02 PDT 2018


rinon updated this revision to Diff 167012.
rinon added a comment.
Herald added a subscriber: kristina.

Rebase


Repository:
  rL LLVM

https://reviews.llvm.org/D37580

Files:
  include/llvm/CodeGen/CommandFlags.inc
  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
@@ -279,6 +279,8 @@
       OptRemarksWithHotness = true;
     } else if (opt.startswith("stats-file=")) {
       stats_file = opt.substr(strlen("stats-file="));
+    } 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
@@ -329,15 +331,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
@@ -43,7 +43,8 @@
 TargetMachine::~TargetMachine() = default;
 
 bool TargetMachine::isPositionIndependent() const {
-  return getRelocationModel() == Reloc::PIC_;
+  return getRelocationModel() == Reloc::PIC_ ||
+         getRelocationModel() == Reloc::PIP;
 }
 
 /// Reset the target options based on the function's attributes.
@@ -211,7 +212,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
@@ -224,6 +224,9 @@
     return Options.FunctionSections;
   }
 
+  /// Return true if Pagerando is enabled on this target.
+  bool isPagerando() const { return getRelocationModel() == Reloc::PIP; }
+
   /// 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.inc
===================================================================
--- include/llvm/CodeGen/CommandFlags.inc
+++ include/llvm/CodeGen/CommandFlags.inc
@@ -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.167012.patch
Type: text/x-patch
Size: 3889 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180925/1a3d6371/attachment.bin>


More information about the llvm-commits mailing list