From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7867) id 9B19F3846074; Thu, 25 Apr 2024 01:25:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B19F3846074 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1714008340; bh=Xy+Iczxhyh0dOwPn1FN72dG7UhqZmzhxf+PuF+42puY=; h=From:To:Subject:Date:From; b=D9oOWIHjuzOoDlY+veFR6SYns5g74IhD7Kyns60SqjsD4UBK+woIn9N7J2hxGECPG r4UJpmfMIXs7vuD7keTwB3MI0XxdnOOjfdvNVaFMaZqRAyuOf8eIBVlpFOZFazf9X/ EbbpesSuJ2ylelH35rigOy0wY5sq50bmWjDlqbCI= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: liu & zhensong To: binutils-cvs@sourceware.org Subject: [binutils-gdb] LoongArch: The symbol got type can only be obtained after initialization X-Act-Checkin: binutils-gdb X-Git-Author: Lulu Cai X-Git-Refname: refs/heads/master X-Git-Oldrev: 59462de44399d4db57fa12b75108caec578b816a X-Git-Newrev: b221bff7c7ca20d961a7e6b663a545384054a5be Message-Id: <20240425012540.9B19F3846074@sourceware.org> Date: Thu, 25 Apr 2024 01:25:40 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Db221bff7c7ca= 20d961a7e6b663a545384054a5be commit b221bff7c7ca20d961a7e6b663a545384054a5be Author: Lulu Cai Date: Fri Apr 19 10:24:52 2024 +0800 LoongArch: The symbol got type can only be obtained after initialization =20 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_UNKN= OWN. Diff: --- bfd/elfnn-loongarch.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c index 7b493f6f05b..fe780e39610 100644 --- a/bfd/elfnn-loongarch.c +++ b/bfd/elfnn-loongarch.c @@ -683,7 +683,14 @@ loongarch_can_trans_tls (bfd *input_bfd, if (! IS_LOONGARCH_TLS_TRANS_RELOC (r_type)) return false; =20 - symbol_tls_type =3D _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 =3D GOT_UNKNOWN; + if (_bfd_loongarch_elf_local_got_tls_type (input_bfd) || h) + symbol_tls_type =3D _bfd_loongarch_elf_tls_type (input_bfd, h, r_symnd= x); + reloc_got_type =3D loongarch_reloc_got_type (r_type); =20 if (symbol_tls_type =3D=3D GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_typ= e))