Index: include/llvm/CodeGen/CommandFlags.h =================================================================== --- include/llvm/CodeGen/CommandFlags.h +++ include/llvm/CodeGen/CommandFlags.h @@ -58,7 +58,9 @@ clEnumValN(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"))); static inline Optional getRelocModel() { if (RelocModel.getNumOccurrences()) { 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/Target/TargetMachine.h =================================================================== --- include/llvm/Target/TargetMachine.h +++ include/llvm/Target/TargetMachine.h @@ -199,6 +199,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: lib/Target/TargetMachine.cpp =================================================================== --- lib/Target/TargetMachine.cpp +++ lib/Target/TargetMachine.cpp @@ -51,7 +51,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. @@ -166,7 +167,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: 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);