Skip to content

Commit

Permalink
Revert "[AIX][TLS] Generate .extern and .ref references to __tls_get_…
Browse files Browse the repository at this point in the history
…addr for local-exec accesses."

This reverts commit f0b2f69.
The implementation is incorrect and breaks compiling local-exec programs.
  • Loading branch information
amy-kwan committed Sep 7, 2023
1 parent e0094ac commit f94f853
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 217 deletions.
39 changes: 5 additions & 34 deletions llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,6 @@ class PPCAsmPrinter : public AsmPrinter {
TOCType_EHBlock
};

// Controls whether or not to emit a .ref reference to __tls_get_addr.
// This is currently used for TLS models that do not generate calls to
// TLS functions, such as for the local-exec model on AIX 64-bit.
bool HasRefGetTLSAddr = false;

MCSymbol *lookUpOrCreateTOCEntry(const MCSymbol *Sym, TOCEntryType Type,
MCSymbolRefExpr::VariantKind Kind =
MCSymbolRefExpr::VariantKind::VK_None);
Expand Down Expand Up @@ -620,17 +615,12 @@ void PPCAsmPrinter::LowerPATCHPOINT(StackMaps &SM, const MachineInstr &MI) {
/// This helper function creates the TlsGetAddr MCSymbol for AIX. We will
/// create the csect and use the qual-name symbol instead of creating just the
/// external symbol.
static MCSymbol *
createMCSymbolForTlsGetAddr(MCContext &Ctx, unsigned MIOpc,
XCOFF::StorageMappingClass SMC = XCOFF::XMC_PR) {
StringRef SymName;
if (MIOpc == PPC::GETtlsTpointer32AIX)
SymName = ".__get_tpointer";
else
SymName = (SMC == XCOFF::XMC_DS) ? "__tls_get_addr" : ".__tls_get_addr";
static MCSymbol *createMCSymbolForTlsGetAddr(MCContext &Ctx, unsigned MIOpc) {
StringRef SymName =
MIOpc == PPC::GETtlsTpointer32AIX ? ".__get_tpointer" : ".__tls_get_addr";
return Ctx
.getXCOFFSection(SymName, SectionKind::getText(),
XCOFF::CsectProperties(SMC, XCOFF::XTY_ER))
XCOFF::CsectProperties(XCOFF::XMC_PR, XCOFF::XTY_ER))
->getQualNameSymbol();
}

Expand Down Expand Up @@ -842,11 +832,8 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
if (MO.getTargetFlags() & PPCII::MO_TPREL_FLAG) {
assert(MO.isGlobal() && "Only expecting a global MachineOperand here!\n");
TLSModel::Model Model = TM.getTLSModel(MO.getGlobal());
if (Model == TLSModel::LocalExec) {
if (IsPPC64)
HasRefGetTLSAddr = true;
if (Model == TLSModel::LocalExec)
return MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSLE;
}
if (Model == TLSModel::InitialExec)
return MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSIE;
llvm_unreachable("Only expecting local-exec or initial-exec accesses!");
Expand Down Expand Up @@ -2875,22 +2862,6 @@ bool PPCAIXAsmPrinter::doFinalization(Module &M) {
OutStreamer->doFinalizationAtSectionEnd(
OutStreamer->getContext().getObjectFileInfo()->getTextSection());

// Add a single .ref reference to __tls_get_addr[DS] for the local-exec TLS
// model on AIX 64-bit. For TLS models that do not generate calls to TLS
// functions, this reference to __tls_get_addr helps generate a linker error
// to an undefined symbol to __tls_get_addr, which indicates to the user that
// compiling with -pthread is required for programs that use TLS variables.
if (HasRefGetTLSAddr) {
// Specifically for 64-bit AIX, a load from the TOC is generated to load
// the variable offset needed for local-exec accesses.
MCSymbol *TlsGetAddrDescriptor =
createMCSymbolForTlsGetAddr(OutContext, PPC::GETtlsADDR64AIX,
XCOFF::XMC_DS);

ExtSymSDNodeSymbols.insert(TlsGetAddrDescriptor);
OutStreamer->emitXCOFFRefDirective(TlsGetAddrDescriptor);
}

for (MCSymbol *Sym : ExtSymSDNodeSymbols)
OutStreamer->emitSymbolAttribute(Sym, MCSA_Extern);
return PPCAsmPrinter::doFinalization(M);
Expand Down
7 changes: 0 additions & 7 deletions llvm/test/CodeGen/PowerPC/aix-tls-le-ldst-double.ll
Original file line number Diff line number Diff line change
Expand Up @@ -635,13 +635,6 @@ entry:
ret double %add
}

; (64-bit only) External symbol reference checks for __tls_get_addr[DS]

; SMALL64: .ref __tls_get_addr[DS]
; SMALL64: .extern __tls_get_addr[DS]
; LARGE64: .ref __tls_get_addr[DS]
; LARGE64: .extern __tls_get_addr[DS]

; TOC Entry Checks.

; SMALL64-LABEL: .toc
Expand Down
7 changes: 0 additions & 7 deletions llvm/test/CodeGen/PowerPC/aix-tls-le-ldst-float.ll
Original file line number Diff line number Diff line change
Expand Up @@ -635,13 +635,6 @@ entry:
ret float %add
}

; (64-bit only) External symbol reference checks for __tls_get_addr[DS]

; SMALL64: .ref __tls_get_addr[DS]
; SMALL64: .extern __tls_get_addr[DS]
; LARGE64: .ref __tls_get_addr[DS]
; LARGE64: .extern __tls_get_addr[DS]

; TOC Entry Checks.

; SMALL64-LABEL: .toc
Expand Down
7 changes: 0 additions & 7 deletions llvm/test/CodeGen/PowerPC/aix-tls-le-ldst-int.ll
Original file line number Diff line number Diff line change
Expand Up @@ -651,13 +651,6 @@ entry:
ret i32 %add
}

; (64-bit only) External symbol reference checks for __tls_get_addr[DS]

; SMALL64: .ref __tls_get_addr[DS]
; SMALL64: .extern __tls_get_addr[DS]
; LARGE64: .ref __tls_get_addr[DS]
; LARGE64: .extern __tls_get_addr[DS]

; TOC Entry Checks.

; SMALL64-LABEL: .toc
Expand Down
7 changes: 0 additions & 7 deletions llvm/test/CodeGen/PowerPC/aix-tls-le-ldst-longlong.ll
Original file line number Diff line number Diff line change
Expand Up @@ -707,13 +707,6 @@ entry:
ret i64 %add
}

; (64-bit only) External symbol reference checks for __tls_get_addr[DS]

; SMALL64: .ref __tls_get_addr[DS]
; SMALL64: .extern __tls_get_addr[DS]
; LARGE64: .ref __tls_get_addr[DS]
; LARGE64: .extern __tls_get_addr[DS]

; TOC Entry Checks.

; SMALL64-LABEL: .toc
Expand Down
Loading

0 comments on commit f94f853

Please sign in to comment.