summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkettenis <kettenis@openbsd.org>2020-04-04 09:54:04 +0000
committerkettenis <kettenis@openbsd.org>2020-04-04 09:54:04 +0000
commit3159fc8f233e5ccb749cd05b58cf5b93b8f45263 (patch)
tree131142a3b6f2cf2b32a06a8ce1e0355fff9c0107
parentPrevent shadowing of local variable by the EV_SET() macro. (diff)
downloadwireguard-openbsd-3159fc8f233e5ccb749cd05b58cf5b93b8f45263.tar.xz
wireguard-openbsd-3159fc8f233e5ccb749cd05b58cf5b93b8f45263.zip
Fix "small pic" secure plt support.
ok mortimer@
-rw-r--r--gnu/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp9
-rw-r--r--gnu/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp7
-rw-r--r--gnu/llvm/lib/Target/PowerPC/PPCMCInstLower.cpp4
3 files changed, 12 insertions, 8 deletions
diff --git a/gnu/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/gnu/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 04aa3c9b1e2..82e18cef984 100644
--- a/gnu/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/gnu/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -575,14 +575,19 @@ void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) {
// Transform %rd = UpdateGBR(%rt, %ri)
// Into: lwz %rt, .L0$poff - .L0$pb(%ri)
// add %rd, %rt, %ri
- // or into (if secure plt mode is on):
+ // or into (-msecure-plt -fpic):
+ // addis r30, r30, _GLOBAL_OFFSET_TABLE_ - .L0$pb@ha
+ // addi r30, r30, _GLOBAL_OFFSET_TABLE_ - .L0$pb@l
+ // or into (-msecure-plt -fPIC):
// addis r30, r30, .LTOC - .L0$pb@ha
// addi r30, r30, .LTOC - .L0$pb@l
// Get the offset from the GOT Base Register to the GOT
LowerPPCMachineInstrToMCInst(MI, TmpInst, *this, isDarwin);
if (Subtarget->isSecurePlt() && isPositionIndependent() ) {
unsigned PICR = TmpInst.getOperand(0).getReg();
- MCSymbol *LTOCSymbol = OutContext.getOrCreateSymbol(StringRef(".LTOC"));
+ StringRef Name = (PL == PICLevel::SmallPIC ?
+ "_GLOBAL_OFFSET_TABLE_" : ".LTOC");
+ MCSymbol *LTOCSymbol = OutContext.getOrCreateSymbol(Name);
const MCExpr *PB =
MCSymbolRefExpr::create(MF->getPICBaseSymbol(),
OutContext);
diff --git a/gnu/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp b/gnu/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
index 70e9049a2ab..a301ac1e6bb 100644
--- a/gnu/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
+++ b/gnu/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
@@ -412,7 +412,8 @@ SDNode *PPCDAGToDAGISel::getGlobalBaseReg() {
if (PPCLowering->getPointerTy(CurDAG->getDataLayout()) == MVT::i32) {
if (PPCSubTarget->isTargetELF()) {
GlobalBaseReg = PPC::R30;
- if (M->getPICLevel() == PICLevel::SmallPIC) {
+ if (M->getPICLevel() == PICLevel::SmallPIC &&
+ !PPCSubTarget->isSecurePlt()) {
BuildMI(FirstMBB, MBBI, dl, TII.get(PPC::MoveGOTtoLR));
BuildMI(FirstMBB, MBBI, dl, TII.get(PPC::MFLR), GlobalBaseReg);
MF->getInfo<PPCFunctionInfo>()->setUsesPICBase(true);
@@ -4356,11 +4357,9 @@ void PPCDAGToDAGISel::Select(SDNode *N) {
break;
case PPCISD::CALL: {
- const Module *M = MF->getFunction().getParent();
-
if (PPCLowering->getPointerTy(CurDAG->getDataLayout()) != MVT::i32 ||
(!TM.isPositionIndependent() || !PPCSubTarget->isSecurePlt()) ||
- !PPCSubTarget->isTargetELF() || M->getPICLevel() == PICLevel::SmallPIC)
+ !PPCSubTarget->isTargetELF())
break;
SDValue Op = N->getOperand(1);
diff --git a/gnu/llvm/lib/Target/PowerPC/PPCMCInstLower.cpp b/gnu/llvm/lib/Target/PowerPC/PPCMCInstLower.cpp
index e731c0bc0c2..1d860448de5 100644
--- a/gnu/llvm/lib/Target/PowerPC/PPCMCInstLower.cpp
+++ b/gnu/llvm/lib/Target/PowerPC/PPCMCInstLower.cpp
@@ -114,9 +114,9 @@ static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol,
const PPCSubtarget *Subtarget = &(MF->getSubtarget<PPCSubtarget>());
const TargetMachine &TM = Printer.TM;
const MCExpr *Expr = MCSymbolRefExpr::create(Symbol, RefKind, Ctx);
- // -msecure-plt option works only in PIC mode. If secure plt mode
- // is on add 32768 to symbol.
+ // For -msecure-plt -fPIC, add 32768 to the symbol.
if (Subtarget->isSecurePlt() && TM.isPositionIndependent() &&
+ MF->getFunction().getParent()->getPICLevel() == PICLevel::BigPIC &&
MO.getTargetFlags() == PPCII::MO_PLT)
Expr = MCBinaryExpr::createAdd(Expr,
MCConstantExpr::create(32768, Ctx),