[lld] [ELF] Fix TLSDESC=>IE when there is no TLS section (PR #98569)

Paul Kirth via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 11 17:47:54 PDT 2024


================
@@ -660,7 +660,12 @@ static int64_t getTlsTpOffset(const Symbol &s) {
     return s.getVA(0) + (tls->p_vaddr & (tls->p_align - 1)) - 0x7000;
   case EM_LOONGARCH:
   case EM_RISCV:
-    return s.getVA(0) + (tls->p_vaddr & (tls->p_align - 1));
+    // See the comment in handleTlsRelocation. For TLSDESC=>IE,
+    // R_RISCV_TLSDESC_{LOAD_LO12,ADD_LO12_I,CALL} also reach here. While
+    // `tls` may be null, the return value is ignored.
+    if (s.type != STT_TLS)
+      return 0;
+    return s.getVA(0) + (tls ? tls->p_vaddr & (tls->p_align - 1) : 0);
----------------
ilovepi wrote:

To make sure I follow the comment above correctly, we're adding `0` here in the case where `tls` is null, because its getting ignored, right?

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


More information about the llvm-commits mailing list