[lld] [lld][LoongArch] Support TLSDESC GD/LD to IE/LE (PR #123715)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 17 21:39:54 PDT 2025


================
@@ -1453,7 +1459,17 @@ unsigned RelocationScanner::handleTlsRelocation(RelExpr expr, RelType type,
     // label, so TLSDESC=>IE will be categorized as R_RELAX_TLS_GD_TO_LE. We fix
     // the categorization in RISCV::relocateAllosec->
     if (sym.isPreemptible) {
-      sym.setFlags(NEEDS_TLSGD_TO_IE);
+      // In LoongArch, TLSDESC code sequences share relocations
+      // R_LARCH_TLS_DESC_PC_HI20 and R_LARCH_TLS_DESC_PC_LO12 in
+      // normal/medium/extreme code model. Since the extreme code model cannot
+      // be optimized to IE/LE, the flag NEEDS_TLSGD_TO_IE added previously
+      // needs to be cleared.
+      // In extreme code model, R_LARCH_TLS_DESC64_LO20 and
+      // R_LARCH_TLS_DESC64_HI12 will set NEEDS_TLSDESC flag.
+      if (ctx.arg.emachine == EM_LOONGARCH && sym.hasFlag(NEEDS_TLSDESC))
+        sym.clearFlags(NEEDS_TLSGD_TO_IE);
----------------
MaskRay wrote:

The extreme model might be similar to large model in other targets. As you probably implied the performance likely doesn't matter. We should not optimize for it at the expense of linker complexity.

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


More information about the llvm-commits mailing list