[PATCH] D151335: [AIX][TLS] Generate .extern and .ref references to __tls_get_addr for local-exec accesses.

Digger Lin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 9 10:36:55 PDT 2023

DiggerLin added inline comments.

Comment at: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp:2863
+  for (auto &I : TOC) {
+    // Add a single .ref reference to __tls_get_addr[DS] for the local-exec TLS
if  there is not a  __thread variable or   there is not  local exec mode, the loop will go over all the TC entries(the TC entries maybe a large number). if it is not  efficient. 

can we add a new data number "//bool hasRefGetTLSAddr//"  for PPCAsmPrinter.  ?

and set the  "hasRefGetTLSAddr" in the lambda function 
auto GetVKForMO = [&](const MachineOperand &MO)  or other place ?

for example , change your code in the patch D149722 to 

auto GetVKForMO = [&](const MachineOperand &MO) {
    // For TLS local-exec accesses on AIX, we have one TOC entry for the symbol
    // (with the variable offset), which is differentiated by MO_TPREL_FLAG.
    if (MO.getTargetFlags() & PPCII::MO_TPREL_FLAG) {
      // TODO: Update the query and the comment above to add a check for initial
      // exec when this TLS model is supported on AIX in the future, as both
      // local-exec and initial-exec can use MO_TPREL_FLAG.
      assert(MO.isGlobal() && "Only expecting a global MachineOperand here!\n");
      TLSModel::Model Model = TM.getTLSModel(MO.getGlobal());
      if (Model == TLSModel::LocalExec) {

        hasRefGetTLSAddr =true;

        return MCSymbolRefExpr::VariantKind::VK_PPC_AIX_TLSLE;
      llvm_unreachable("Only expecting local-exec accesses!");

and change the code here to 

if (hasRefGetTLSAddr )  {
   MCSymbol *TlsGetAddrDescriptor =
          createMCSymbolForTlsGetAddr(OutContext, XCOFF::XMC_DS);


for (MCSymbol *Sym : ExtSymSDNodeSymbols)
    OutStreamer->emitSymbolAttribute(Sym, MCSA_Extern);

  rG LLVM Github Monorepo



More information about the llvm-commits mailing list