[binutils-gdb] aarch64: Fix assembler internal error for %dtprel relocations

SRINATH PARVATHANENI via Binutils-cvs <[email protected]> Mon, 6 Jul 2026 11:41:33 +0000 (GMT)
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ce7445a94150ba6137cb29abcb879995570fe640

commit ce7445a94150ba6137cb29abcb879995570fe640
Author: Srinath Parvathaneni <[email protected]>
Date:   Mon Jul 6 11:41:08 2026 +0000

    aarch64: Fix assembler internal error for %dtprel relocations
    
    The current implementation creates the DTPREL fixup before reserving
    the storage for the corresponding ".xword". GCC's "%dtprel" support
    for TLS DWARF debug information exposed this during an AArch64 bootstrap,
    where the libsanitizer/tsan DWARF layout places the DTPREL fixup at a
    frag boundary. Reserving the storage before creating the fixup avoids
    this corner case.
    
    gas/
            PR binutils/34357
            * config/tc-aarch64.c (s_aarch64_cons) : Fix the storage order for
            DTPREL.

Diff:
---
 gas/config/tc-aarch64.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index 715df4de4bf..2da5139d8af 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -2244,15 +2244,13 @@ s_aarch64_cons (int nbytes)
 		  return;
 		}
 
-	      addressT where = frag_now_fix ();
-	      fix_new_exp (frag_now, where, nbytes, &exp, 0,
-			   BFD_RELOC_AARCH64_TLS_DTPREL);
-
 	      char *dest = frag_more (nbytes);
 	      memset (dest, 0, nbytes);
+
+	      fix_new_exp (frag_now, dest - frag_now->fr_literal, nbytes,
+			   &exp, 0, BFD_RELOC_AARCH64_TLS_DTPREL);
 	      continue;
 	    }
-
 	  else
 	    {
 	      as_bad (_("unknown relocation operator"));