[v1] aarch64: Fix assembler internal error for %dtprel relocations

Message ID 20260706094728.1788418-1-srinath.parvathaneni@arm.com
State Committed
Headers
Series [v1] aarch64: Fix assembler internal error for %dtprel relocations |

Checks

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

Commit Message

Srinath Parvathaneni July 6, 2026, 9:47 a.m. UTC
  From: Srinath Parvathaneni <srinath.parvathaneni@arm.com>

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.

The simplest reproducer (tsan_interceptors_posix-bad.s from libsanitizer/tsan)
is 50k lines and I'm avoid attaching that hugh testfile to this patch.

gas/
	PR binutils/34357
	* config/tc-aarch64.c (s_aarch64_cons) : Fix the storage order for
	DTPREL.

Regression tested on aarch64-linux-gnu and found no regressions.

Ok for master?

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

Comments

Alan Modra July 6, 2026, 10:03 a.m. UTC | #1
On Mon, Jul 06, 2026 at 09:47:28AM +0000, srinath.parvathaneni@arm.com wrote:
> From: Srinath Parvathaneni <srinath.parvathaneni@arm.com>
> 
> 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.
> 
> The simplest reproducer (tsan_interceptors_posix-bad.s from libsanitizer/tsan)
> is 50k lines and I'm avoid attaching that hugh testfile to this patch.
> 
> gas/
> 	PR binutils/34357
> 	* config/tc-aarch64.c (s_aarch64_cons) : Fix the storage order for
> 	DTPREL.
> 
> Regression tested on aarch64-linux-gnu and found no regressions.
> 
> Ok for master?

OK, looks good.

> Regards,
> Srinath
> ---
>  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"));
> -- 
> 2.43.0
  

Patch

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