@@ -522,12 +522,20 @@ void PPCAsmPrinter::LowerPATCHPOINT(StackMaps &SM, const MachineInstr &MI) {
522
522
EmitToStreamer (*OutStreamer, MCInstBuilder (PPC::NOP));
523
523
}
524
524
525
+ // / This helper function creates the TlsGetAddr MCSymbol for AIX. We will
526
+ // / create the csect and use the qual-name symbol instead of creating just the
527
+ // / external symbol.
528
+ static MCSymbol *createMCSymbolForTlsGetAddr (MCContext &Ctx) {
529
+ return Ctx
530
+ .getXCOFFSection (" .__tls_get_addr" , SectionKind::getText (),
531
+ XCOFF::CsectProperties (XCOFF::XMC_PR, XCOFF::XTY_ER))
532
+ ->getQualNameSymbol ();
533
+ }
534
+
525
535
// / EmitTlsCall -- Given a GETtls[ld]ADDR[32] instruction, print a
526
536
// / call to __tls_get_addr to the current output stream.
527
537
void PPCAsmPrinter::EmitTlsCall (const MachineInstr *MI,
528
538
MCSymbolRefExpr::VariantKind VK) {
529
- StringRef Name = Subtarget->isAIXABI () ? " .__tls_get_addr" : " __tls_get_addr" ;
530
- MCSymbol *TlsGetAddr = OutContext.getOrCreateSymbol (Name);
531
539
MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_None;
532
540
unsigned Opcode = PPC::BL8_NOP_TLS;
533
541
@@ -558,13 +566,15 @@ void PPCAsmPrinter::EmitTlsCall(const MachineInstr *MI,
558
566
assert (MI->getOperand (2 ).isReg () &&
559
567
MI->getOperand (2 ).getReg () == VarOffsetReg &&
560
568
" GETtls[ld]ADDR[32] must read GPR4" );
561
- MCSymbol *TlsGetAddrA = OutContext. getOrCreateSymbol (Name );
569
+ MCSymbol *TlsGetAddr = createMCSymbolForTlsGetAddr (OutContext );
562
570
const MCExpr *TlsRef = MCSymbolRefExpr::create (
563
- TlsGetAddrA , MCSymbolRefExpr::VK_None, OutContext);
571
+ TlsGetAddr , MCSymbolRefExpr::VK_None, OutContext);
564
572
EmitToStreamer (*OutStreamer, MCInstBuilder (PPC::BLA).addExpr (TlsRef));
565
573
return ;
566
574
}
567
575
576
+ MCSymbol *TlsGetAddr = OutContext.getOrCreateSymbol (" __tls_get_addr" );
577
+
568
578
if (Subtarget->is32BitELFABI () && isPositionIndependent ())
569
579
Kind = MCSymbolRefExpr::VK_PLT;
570
580
@@ -673,10 +683,12 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
673
683
};
674
684
auto GetVKForMO = [&](const MachineOperand &MO) {
675
685
// For GD TLS access on AIX, we have two TOC entries for the symbol (one for
676
- // the offset and the other for the region handle). They are differentiated
677
- // by the presence of the PPCII::MO_TLSGD_FLAG.
678
- if (IsAIX && (MO.getTargetFlags () & PPCII::MO_TLSGD_FLAG))
679
- return MCSymbolRefExpr::VariantKind::VK_PPC_TLSGD;
686
+ // the variable offset and the other for the region handle). They are
687
+ // differentiated by MO_TLSGD_FLAG and MO_TLSGDM_FLAG.
688
+ if (MO.getTargetFlags () & PPCII::MO_TLSGDM_FLAG)
689
+ return MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSGDM;
690
+ if (MO.getTargetFlags () & PPCII::MO_TLSGD_FLAG)
691
+ return MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSGD;
680
692
return MCSymbolRefExpr::VariantKind::VK_None;
681
693
};
682
694
@@ -2232,9 +2244,22 @@ void PPCAIXAsmPrinter::emitEndOfAsmFile(Module &M) {
2232
2244
static_cast <PPCTargetStreamer *>(OutStreamer->getTargetStreamer ());
2233
2245
2234
2246
for (auto &I : TOC) {
2235
- // Setup the csect for the current TC entry.
2236
- MCSectionXCOFF *TCEntry = cast<MCSectionXCOFF>(
2237
- getObjFileLowering ().getSectionForTOCEntry (I.first .first , TM));
2247
+ MCSectionXCOFF *TCEntry;
2248
+ // Setup the csect for the current TC entry. If the variant kind is
2249
+ // VK_PPC_AIX_TLSGDM the entry represents the region handle, we create a
2250
+ // new symbol to prefix the name with a dot.
2251
+ if (I.first .second == MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSGDM) {
2252
+ SmallString<128 > Name;
2253
+ StringRef Prefix = " ." ;
2254
+ Name += Prefix;
2255
+ Name += I.first .first ->getName ();
2256
+ MCSymbol *S = OutContext.getOrCreateSymbol (Name);
2257
+ TCEntry = cast<MCSectionXCOFF>(
2258
+ getObjFileLowering ().getSectionForTOCEntry (S, TM));
2259
+ } else {
2260
+ TCEntry = cast<MCSectionXCOFF>(
2261
+ getObjFileLowering ().getSectionForTOCEntry (I.first .first , TM));
2262
+ }
2238
2263
OutStreamer->SwitchSection (TCEntry);
2239
2264
2240
2265
OutStreamer->emitLabel (I.second );
@@ -2317,7 +2342,7 @@ void PPCAIXAsmPrinter::emitInstruction(const MachineInstr *MI) {
2317
2342
case PPC::GETtlsADDR32AIX: {
2318
2343
// The reference to .__tls_get_addr is unknown to the assembler
2319
2344
// so we need to emit an external symbol reference.
2320
- MCSymbol *TlsGetAddr = OutContext. getOrCreateSymbol ( " .__tls_get_addr " );
2345
+ MCSymbol *TlsGetAddr = createMCSymbolForTlsGetAddr (OutContext );
2321
2346
ExtSymSDNodeSymbols.insert (TlsGetAddr);
2322
2347
break ;
2323
2348
}
0 commit comments