[v4,6/9] RISC-V: Move STATIC_TLS handling into record_tls_type.

Message ID 20240220175556.304692-7-ishitatsuyuki@gmail.com
State Unresolved
Headers
Series RISC-V: Implement TLS Descriptors. |

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

Tatsuyuki Ishi Feb. 20, 2024, 5:55 p.m. UTC
  bfd/Changelog:
	* elfnn-riscv.c (riscv_elf_record_tls_type): Add bfd_link_info
	parameter and move code from below.
	(riscv_elf_check_relocs): Move STATIC_TLS handling into
	riscv_elf_record_tls_type.
	Add missing early return in the R_RISCV_TPREL_HI20 case.
---
 bfd/elfnn-riscv.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
  

Patch

diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 16394110c6a..1594856ccef 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -663,12 +663,14 @@  riscv_elf_copy_indirect_symbol (struct bfd_link_info *info,
 }
 
 static bool
-riscv_elf_record_tls_type (bfd *abfd, struct elf_link_hash_entry *h,
+riscv_elf_record_tls_type (bfd *abfd, struct bfd_link_info *info,
+			   struct elf_link_hash_entry *h,
 			   unsigned long symndx, char tls_type)
 {
   char *new_tls_type = &_bfd_riscv_elf_tls_type (abfd, h, symndx);
 
   *new_tls_type |= tls_type;
+
   if ((*new_tls_type & GOT_NORMAL) && (*new_tls_type & ~GOT_NORMAL))
     {
       (*_bfd_error_handler)
@@ -676,6 +678,10 @@  riscv_elf_record_tls_type (bfd *abfd, struct elf_link_hash_entry *h,
 	 abfd, h ? h->root.root.string : "<local>");
       return false;
     }
+
+  if ((*new_tls_type & GOT_TLS_IE) && bfd_link_dll (info))
+    info->flags |= DF_STATIC_TLS;
+
   return true;
 }
 
@@ -839,27 +845,29 @@  riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
 	{
 	case R_RISCV_TLS_GD_HI20:
 	  if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx)
-	      || !riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_TLS_GD))
+	      || !riscv_elf_record_tls_type (abfd, info, h, r_symndx,
+					     GOT_TLS_GD))
 	    return false;
 	  break;
 
 	case R_RISCV_TLS_GOT_HI20:
-	  if (bfd_link_dll (info))
-	    info->flags |= DF_STATIC_TLS;
 	  if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx)
-	      || !riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_TLS_IE))
+	      || !riscv_elf_record_tls_type (abfd, info, h, r_symndx,
+					     GOT_TLS_IE))
 	    return false;
 	  break;
 
 	case R_RISCV_GOT_HI20:
 	  if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx)
-	      || !riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_NORMAL))
+	      || !riscv_elf_record_tls_type (abfd, info, h, r_symndx,
+					     GOT_NORMAL))
 	    return false;
 	  break;
 
 	case R_RISCV_TLSDESC_HI20:
 	  if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx)
-	      || !riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_TLSDESC))
+	      || !riscv_elf_record_tls_type (abfd, info, h, r_symndx,
+					     GOT_TLSDESC))
 	    return false;
 	  break;
 
@@ -949,8 +957,9 @@  riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
 	  /* This is not allowed in the pic, but okay in pie.  */
 	  if (!bfd_link_executable (info))
 	    return bad_static_reloc (abfd, r_type, h);
-	  if (h != NULL)
-	    riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_TLS_LE);
+	  if (h != NULL
+	      && !riscv_elf_record_tls_type (abfd, info, h, r_symndx, GOT_TLS_LE))
+	    return false;
 	  break;
 
 	case R_RISCV_HI20: