[llvm] r355513 - [PowerPC] Add secure plt support for TLS symbols
Strahinja Petrovic via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 6 07:00:11 PST 2019
Author: spetrovic
Date: Wed Mar 6 07:00:10 2019
New Revision: 355513
URL: http://llvm.org/viewvc/llvm-project?rev=355513&view=rev
Log:
[PowerPC] Add secure plt support for TLS symbols
This patch supports secure plt mode for TLS symbols.
Differential Revision: https://reviews.llvm.org/D45520
Added:
llvm/trunk/test/CodeGen/PowerPC/ppc32-secure-plt-tls.ll
Modified:
llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp
llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
llvm/trunk/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
Modified: llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp?rev=355513&r1=355512&r2=355513&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp Wed Mar 6 07:00:10 2019
@@ -444,13 +444,22 @@ void PPCInstPrinter::printTLSCall(const
// 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
Modified: llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp?rev=355513&r1=355512&r2=355513&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp Wed Mar 6 07:00:10 2019
@@ -472,8 +472,14 @@ void PPCAsmPrinter::EmitTlsCall(const Ma
if (!Subtarget->isPPC64() && !Subtarget->isDarwin() &&
isPositionIndependent())
Kind = MCSymbolRefExpr::VK_PLT;
- const MCSymbolRefExpr *TlsRef =
+ const MCExpr *TlsRef =
MCSymbolRefExpr::create(TlsGetAddr, Kind, OutContext);
+
+ // Add 32768 offset to the symbol so we follow up the latest GOT/PLT ABI.
+ 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);
Modified: llvm/trunk/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCISelDAGToDAG.cpp?rev=355513&r1=355512&r2=355513&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCISelDAGToDAG.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCISelDAGToDAG.cpp Wed Mar 6 07:00:10 2019
@@ -4353,7 +4353,20 @@ void PPCDAGToDAGISel::Select(SDNode *N)
if (trySETCC(N))
return;
break;
-
+ // These nodes will be transformed into GETtlsADDR32 node, which
+ // later becomes BL_TLS __tls_get_addr(sym at tlsgd)@PLT
+ 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;
+ // Attach global base pointer on GETtlsADDR32 node in order to
+ // generate secure plt code for TLS symbols.
+ getGlobalBaseReg();
+ }
+ break;
case PPCISD::CALL: {
const Module *M = MF->getFunction().getParent();
Added: llvm/trunk/test/CodeGen/PowerPC/ppc32-secure-plt-tls.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/ppc32-secure-plt-tls.ll?rev=355513&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/PowerPC/ppc32-secure-plt-tls.ll (added)
+++ llvm/trunk/test/CodeGen/PowerPC/ppc32-secure-plt-tls.ll Wed Mar 6 07:00:10 2019
@@ -0,0 +1,18 @@
+; 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-NEXT: bl .L{{.*}}
+; SECURE-PLT-TLS: bl __tls_get_addr(a at tlsgd)@PLT+32768
\ No newline at end of file
More information about the llvm-commits
mailing list