public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Fix local GOT and reloc size calculation for TLS.
@ 2023-08-17 18:05 Tatsuyuki Ishi
  0 siblings, 0 replies; only message in thread
From: Tatsuyuki Ishi @ 2023-08-17 18:05 UTC (permalink / raw)
  To: binutils; +Cc: rui314, ruiu, Tatsuyuki Ishi

The previous code did not account correctly for two cases:
* A TLS symbol can be referenced with multiple TLS types, in which case it
  only allocated the maximum slot size among the types, instead of the sum.
* TLS relocations are only needed for DLLs, unlike normal symbols which
  requires relocations for all PIE code.

Similar to the size calculation for global symbols, break up the
calculation into TLS and non-TLS symbols, and handle the two cases above
correctly.
---
No regression in binutils and gcc tests for rv64gc.

This contribution is made on behalf of Blue Whale Systems, which has
copyright assignment on file with the FSF.

 bfd/elfnn-riscv.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 09aa7be225e..02b46835cc7 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -1562,12 +1562,27 @@ riscv_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 	  if (*local_got > 0)
 	    {
 	      *local_got = s->size;
-	      s->size += RISCV_ELF_WORD_BYTES;
-	      if (*local_tls_type & GOT_TLS_GD)
-		s->size += RISCV_ELF_WORD_BYTES;
-	      if (bfd_link_pic (info)
-		  || (*local_tls_type & (GOT_TLS_GD | GOT_TLS_IE)))
-		srel->size += sizeof (ElfNN_External_Rela);
+	      if (*local_tls_type & (GOT_TLS_GD | GOT_TLS_IE))
+		{
+		  if (*local_tls_type & GOT_TLS_GD)
+		    {
+		      s->size += 2 * RISCV_ELF_WORD_BYTES;
+		      if (bfd_link_dll (info))
+			srel->size += sizeof (ElfNN_External_Rela);
+		    }
+		  if (*local_tls_type & GOT_TLS_IE)
+		    {
+		      s->size += RISCV_ELF_WORD_BYTES;
+		      if (bfd_link_dll (info))
+			srel->size += sizeof (ElfNN_External_Rela);
+		    }
+		}
+	      else
+		{
+		  s->size += RISCV_ELF_WORD_BYTES;
+		  if (bfd_link_pic (info))
+		    srel->size += sizeof (ElfNN_External_Rela);
+		}
 	    }
 	  else
 	    *local_got = (bfd_vma) -1;
-- 
2.41.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-17 18:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-17 18:05 [PATCH] RISC-V: Fix local GOT and reloc size calculation for TLS Tatsuyuki Ishi

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