PR 34165 aarch64 assertion fail and segv

Message ID akTVYb32aOjEDV8W@squeak.grove.modra.org
State Committed
Headers
Series PR 34165 aarch64 assertion fail and segv |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_check--master-arm fail Patch failed to apply

Commit Message

Alan Modra July 1, 2026, 8:52 a.m. UTC
  I'm going to apply this as a fix for pr34165.  It fixes the segv and
results in a zero .got entry for the weak undefined tls syms, the same
as x86.

It seems to me that weak undefined and tls don't work together very
well, as the address of such a sym includes the thread pointer.  So
I don't think there is a reliable machine independent way to test
whether the sym is defined.

	* elfnn-aarch64.c (dtpoff_base, tpoff_base): Don't assert that
	tls_sec is non-NULL, return zero instead.
  

Patch

diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index ffca9048e65..cbd4abea122 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -5396,8 +5396,8 @@  aarch64_tls_transition (bfd *input_bfd,
 static bfd_vma
 dtpoff_base (struct bfd_link_info *info)
 {
-  /* If tls_sec is NULL, we should have signalled an error already.  */
-  BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
+  if (elf_hash_table (info)->tls_sec == NULL)
+    return 0;
   return elf_hash_table (info)->tls_sec->vma;
 }
 
@@ -5409,8 +5409,8 @@  tpoff_base (struct bfd_link_info *info)
 {
   struct elf_link_hash_table *htab = elf_hash_table (info);
 
-  /* If tls_sec is NULL, we should have signalled an error already.  */
-  BFD_ASSERT (htab->tls_sec != NULL);
+  if (htab->tls_sec == NULL)
+    return 0;
 
   bfd_vma base = align_power ((bfd_vma) TCB_SIZE,
 			      htab->tls_sec->alignment_power);