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 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 @@ -225,6 +225,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: lib/Target/TargetMachine.cpp =================================================================== --- lib/Target/TargetMachine.cpp +++ lib/Target/TargetMachine.cpp @@ -48,7 +48,8 @@ } 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. @@ -207,7 +208,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 @@ -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);