]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
LoongArch: The symbol got type can only be obtained after initialization
authorLulu Cai <cailulu@loongson.cn>
Fri, 19 Apr 2024 02:24:52 +0000 (10:24 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Thu, 24 Oct 2024 02:06:20 +0000 (10:06 +0800)
When scanning relocations and determining whether TLS type transition is
possible, it will try to obtain the symbol got type. If the symbol got
type record has not yet been allocated space and initialized, it will
cause ld to crash. So when uninitialized, the symbol is set to GOT_UNKNOWN.

(cherry picked from commit b221bff7c7ca20d961a7e6b663a545384054a5be)

bfd/elfnn-loongarch.c

index b6e62f0f7950ee5c780a2c131725db7619b25518..08a4357d4b943a53e3adbb74e1fa6f3e6e217068 100644 (file)
@@ -656,7 +656,14 @@ loongarch_can_trans_tls (bfd *input_bfd,
          && ELFNN_R_TYPE (rel[1].r_info) == R_LARCH_RELAX))
     return false;
 
-  symbol_tls_type = _bfd_loongarch_elf_tls_type (input_bfd, h, r_symndx);
+  /* Obtaining tls got type here may occur before
+     loongarch_elf_record_tls_and_got_reference, so it is necessary
+     to ensure that tls got type has been initialized, otherwise it
+     is set to GOT_UNKNOWN.  */
+  symbol_tls_type = GOT_UNKNOWN;
+  if (_bfd_loongarch_elf_local_got_tls_type (input_bfd) || h)
+    symbol_tls_type = _bfd_loongarch_elf_tls_type (input_bfd, h, r_symndx);
+
   reloc_got_type = loongarch_reloc_got_type (r_type);
 
   if (symbol_tls_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type))