[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

Felix via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 24 18:33:19 PDT 2023


================
@@ -3412,13 +3416,23 @@ SDValue PPCTargetLowering::LowerGlobalTLSAddressAIX(SDValue Op,
     return DAG.getNode(PPCISD::ADD_TLS, dl, PtrVT, TLSReg, VariableOffset);
   }
 
-  // Only Local-Exec, Initial-Exec and General-Dynamic TLS models are currently
-  // supported models. If Local- or Initial-exec are not possible or specified,
-  // all GlobalTLSAddress nodes are lowered using the general-dynamic model.
-  // We need to generate two TOC entries, one for the variable offset, one for
-  // the region handle. The global address for the TOC entry of the region
-  // handle is created with the MO_TLSGDM_FLAG flag and the global address
-  // for the TOC entry of the variable offset is created with MO_TLSGD_FLAG.
+  if (Model == TLSModel::LocalDynamic) {
+    // For local-dynamic on AIX, we need to generate two TOC entries, one for
+    // the variable offset, the other for the module handle. The module handle
+    // is encapsulated inside the TLSLD_AIX pseudo node, and will be expanded by
+    // PPCTLSDynamicCall.
+    SDValue VariableOffsetTGA =
+        DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, PPCII::MO_TLSLD_FLAG);
+    SDValue VariableOffset = getTOCEntry(DAG, dl, VariableOffsetTGA);
----------------
orcguru wrote:

I still didn't figure out how to remove the strange function.

The way I tried was getOrCreate ExternalLinkage GV named "_$TLSML", and call getTOCEntry on that GV. However there will be a symbol table entry for the symbol, but we don't want that.

For asm mode, I can add hack in MCAsmStreamer::emitXCOFFSymbolLinkageWithVisibility to do not emit the ".extern _Renamed..5f24__TLSML; rename _Renamed..5f24__TLSML ......".

For obj mode, things are more complex, and I'm not able to cleanly remove the symbol table entry without by using hack approach.

https://github.com/llvm/llvm-project/pull/66316


More information about the cfe-commits mailing list