public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
From: liu & zhensong <liuzhensong@sourceware.org>
To: binutils-cvs@sourceware.org
Subject: [binutils-gdb] LoongArch: The symbol got type can only be obtained after initialization
Date: Thu, 25 Apr 2024 01:25:40 +0000 (GMT)	[thread overview]
Message-ID: <20240425012540.9B19F3846074@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b221bff7c7ca20d961a7e6b663a545384054a5be

commit b221bff7c7ca20d961a7e6b663a545384054a5be
Author: Lulu Cai <cailulu@loongson.cn>
Date:   Fri Apr 19 10:24:52 2024 +0800

    LoongArch: The symbol got type can only be obtained after initialization
    
    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.

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;
 
-  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))

                 reply	other threads:[~2024-04-25  1:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240425012540.9B19F3846074@sourceware.org \
    --to=liuzhensong@sourceware.org \
    --cc=binutils-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).