Commit f94f8534 authored by Amy Kwan's avatar Amy Kwan
Browse files

Revert "[AIX][TLS] Generate .extern and .ref references to __tls_get_addr for local-exec accesses."

This reverts commit f0b2f695.
The implementation is incorrect and breaks compiling local-exec programs.
parent e0094ac8
Loading
Loading
Loading
Loading
+5 −34
Original line number Diff line number Diff line
@@ -171,11 +171,6 @@ public:
    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);
@@ -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();
}

@@ -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!");
@@ -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);
+0 −7
Original line number Diff line number Diff line
@@ -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
+0 −7
Original line number Diff line number Diff line
@@ -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
+0 −7
Original line number Diff line number Diff line
@@ -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
+0 −7
Original line number Diff line number Diff line
@@ -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
Loading