[PATCH] D45520: [PowerPC] add secure plt support for TLS symbols
Strahinja Petrovic via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 11 07:59:11 PDT 2018
spetrovic created this revision.
spetrovic added reviewers: jhibbits, joerg, nemanjai.
Herald added subscribers: llvm-commits, kbarton.
This patch supports secure plt mode for TLS symbols, it's extension for https://reviews.llvm.org/D42112.
Repository:
rL LLVM
https://reviews.llvm.org/D45520
Files:
lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp
lib/Target/PowerPC/PPCAsmPrinter.cpp
lib/Target/PowerPC/PPCISelDAGToDAG.cpp
test/CodeGen/PowerPC/ppc32-secure-plt-tls.ll
Index: test/CodeGen/PowerPC/ppc32-secure-plt-tls.ll
===================================================================
--- test/CodeGen/PowerPC/ppc32-secure-plt-tls.ll
+++ test/CodeGen/PowerPC/ppc32-secure-plt-tls.ll
@@ -0,0 +1,17 @@
+; RUN: llc < %s -mtriple=powerpc-unknown-linux-gnu -mattr=+secure-plt -relocation-model=pic | FileCheck -check-prefix=SECURE-PLT-TLS %s
+
+ at a = thread_local local_unnamed_addr global i32 6, align 4
+define i32 @main() local_unnamed_addr #0 {
+entry:
+ %0 = load i32, i32* @a, align 4
+ ret i32 %0
+}
+
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 7, !"PIC Level", i32 2}
+
+; SECURE-PLT-TLS: mflr 30
+; SECURE-PLT-TLS-NEXT: addis 30, 30, .LTOC-.L0$pb at ha
+; SECURE-PLT-TLS-NEXT: addi 30, 30, .LTOC-.L0$pb at l
+; SECURE-PLT-TLS: bl __tls_get_addr(a at tlsgd)@PLT+32768
\ No newline at end of file
Index: lib/Target/PowerPC/PPCISelDAGToDAG.cpp
===================================================================
--- lib/Target/PowerPC/PPCISelDAGToDAG.cpp
+++ lib/Target/PowerPC/PPCISelDAGToDAG.cpp
@@ -4008,7 +4008,17 @@
if (trySETCC(N))
return;
break;
+ case PPCISD::ADDI_TLSLD_L_ADDR:
+ case PPCISD::ADDI_TLSGD_L_ADDR: {
+ const Module *Mod = MF->getFunction().getParent();
+ if (PPCLowering->getPointerTy(CurDAG->getDataLayout()) != MVT::i32 ||
+ !PPCSubTarget->isSecurePlt() || !PPCSubTarget->isTargetELF() ||
+ Mod->getPICLevel() == PICLevel::SmallPIC)
+ break;
+ getGlobalBaseReg();
+ }
+ break;
case PPCISD::CALL: {
const Module *M = MF->getFunction().getParent();
Index: lib/Target/PowerPC/PPCAsmPrinter.cpp
===================================================================
--- lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -487,8 +487,12 @@
if (!Subtarget->isPPC64() && !Subtarget->isDarwin() &&
isPositionIndependent())
Kind = MCSymbolRefExpr::VK_PLT;
- const MCSymbolRefExpr *TlsRef =
+ const MCExpr *TlsRef =
MCSymbolRefExpr::create(TlsGetAddr, Kind, OutContext);
+ if (Kind == MCSymbolRefExpr::VK_PLT && Subtarget->isSecurePlt())
+ TlsRef = MCBinaryExpr::createAdd(TlsRef,
+ MCConstantExpr::create(32768, OutContext),
+ OutContext);
const MachineOperand &MO = MI->getOperand(2);
const GlobalValue *GValue = MO.getGlobal();
MCSymbol *MOSymbol = getSymbol(GValue);
Index: lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp
===================================================================
--- lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp
+++ lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp
@@ -442,13 +442,22 @@
// On PPC64, VariantKind is VK_None, but on PPC32, it's VK_PLT, and it must
// come at the _end_ of the expression.
const MCOperand &Op = MI->getOperand(OpNo);
- const MCSymbolRefExpr &refExp = cast<MCSymbolRefExpr>(*Op.getExpr());
- O << refExp.getSymbol().getName();
+ const MCSymbolRefExpr *refExp = nullptr;
+ const MCConstantExpr *constExp = nullptr;
+ if (const MCBinaryExpr *BinExpr = dyn_cast<MCBinaryExpr>(Op.getExpr())) {
+ refExp = cast<MCSymbolRefExpr>(BinExpr->getLHS());
+ constExp = cast<MCConstantExpr>(BinExpr->getRHS());
+ } else
+ refExp = cast<MCSymbolRefExpr>(Op.getExpr());
+
+ O << refExp->getSymbol().getName();
O << '(';
printOperand(MI, OpNo+1, O);
O << ')';
- if (refExp.getKind() != MCSymbolRefExpr::VK_None)
- O << '@' << MCSymbolRefExpr::getVariantKindName(refExp.getKind());
+ if (refExp->getKind() != MCSymbolRefExpr::VK_None)
+ O << '@' << MCSymbolRefExpr::getVariantKindName(refExp->getKind());
+ if (constExp != nullptr)
+ O << '+' << constExp->getValue();
}
/// showRegistersWithPercentPrefix - Check if this register name should be
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45520.142010.patch
Type: text/x-patch
Size: 3808 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180411/efe596ab/attachment.bin>
More information about the llvm-commits
mailing list