Ping!! ________________________________ From: [email protected] <[email protected]> Sent: 18 June 2026 10:52 To: [email protected] <[email protected]> Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; Alice Carlotti <[email protected]>; Alex Coplan <[email protected]>; Srinath Parvathaneni <[email protected]> Subject: [PATCH v4] [GCC] aarch64: Fix tls debuginfo missing location info [PR97344]
From: Srinath Parvathaneni <[email protected]> Change v3->v4: * Guard aarch64_output_dwarf_dtprel function definition with a macro. * Correct the conditional check in check_effective_target_aarch64_gas_has_dtprel_reloc * Add ABI link to cover letter. ----------------------------- Changes v2->v3: * For size != 8, replaced gcc_assert with error string in aarch64_output_dwarf_dtprel. * Fix format specifiers in the pr97344.c. ------------------------------ Changes v1 ? v2: * Added a check in gcc/configure.ac to apply the patch only if the assembler supports DTPREL relocations. * Added a target check to verify whether the assembler supports ".xword %dtprel(symbol)". ------------------------------ Hi, This patch fixes the missing debuginfo for the TLS variables by emitting ".xword %dtprel(symbol)" along with DW_AT_location in .debug_info section. Support for the assembler directive ".xword %dtprel(symbol)" was recently introduced. To prevent assembler errors when building GCC with older versions of binutils, the patch adds a configure check that skips these changes if the assembler does not support ".xword %dtprel(symbol)". Related ABI changes are proposed here [1]. [1] https://github.com/ARM-software/abi-aa/pull/330 Regression tested on aarch64-linux-gnu and found no regressions. Ok for trunk ? And also to other GCC version? Regards, Srinath gcc/ChangeLog: PR target/97344 * config.in: Re-generate. * config/aarch64/aarch64.cc (aarch64_output_dwarf_dtprel): Define function. (TARGET_ASM_OUTPUT_DWARF_DTPREL): Define macro. * configure: Re-generate. * configure.ac: Add assemler check for dtprel relocation. gcc/testsuite/ChangeLog: PR target/97344 * gcc.target/aarch64/pr97344.c: New test. * lib/target-supports.exp (aarch64_gas_has_dtprel_reloc): Add new target check. --- gcc/config.in | 6 ++++ gcc/config/aarch64/aarch64.cc | 25 ++++++++++++++++ gcc/configure | 34 ++++++++++++++++++++++ gcc/configure.ac | 6 ++++ gcc/testsuite/gcc.target/aarch64/pr97344.c | 26 +++++++++++++++++ gcc/testsuite/lib/target-supports.exp | 11 +++++++ 6 files changed, 108 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/pr97344.c diff --git a/gcc/config.in b/gcc/config.in index a4fd5e0c108..a52bb0e56c6 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -446,6 +446,12 @@ #endif +/* Define if your assembler supports DTPREL relocation. */ +#ifndef USED_FOR_TARGET +#undef HAVE_AS_DTPREL_RELOC +#endif + + /* Define if your assembler supports dwarf2 .file/.loc directives, and preserves file table indices exactly as given. */ #ifndef USED_FOR_TARGET diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 42e56512c61..550512f588e 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -1566,6 +1566,26 @@ aarch64_debugger_regno (unsigned regno) return DWARF_FRAME_REGISTERS; } +#if defined(HAVE_AS_TLS) && defined(HAVE_AS_DTPREL_RELOC) +/* Implementation of TARGET_ASM_OUTPUT_DWARF_DTPREL. */ +static void +aarch64_output_dwarf_dtprel (FILE *f, int size, rtx x) +{ + /* The AArch64 ABI defines static DTPREL relocations only for 8-byte (.xword) + DWARF entries. For any other size there is no valid dtprel(symbol) + encoding and rejecting the request. */ + if (size != 8) + { + error ("unsupported size %d for DTPREL relocation, allowed: 8", size); + return; + } + fputs ("\t.xword\t", f); + fputs ("%dtprel(", f); + output_addr_const (f, x); + fputs (")", f); +} +#endif + /* Implement TARGET_DWARF_FRAME_REG_MODE. */ static machine_mode aarch64_dwarf_frame_reg_mode (int regno) @@ -33993,6 +34013,11 @@ aarch64_libgcc_floating_mode_supported_p #undef TARGET_DWARF_FRAME_REG_MODE #define TARGET_DWARF_FRAME_REG_MODE aarch64_dwarf_frame_reg_mode +#if defined(HAVE_AS_TLS) && defined(HAVE_AS_DTPREL_RELOC) +#undef TARGET_ASM_OUTPUT_DWARF_DTPREL +#define TARGET_ASM_OUTPUT_DWARF_DTPREL aarch64_output_dwarf_dtprel +#endif + #undef TARGET_OUTPUT_CFI_DIRECTIVE #define TARGET_OUTPUT_CFI_DIRECTIVE aarch64_output_cfi_directive diff --git a/gcc/configure b/gcc/configure index 735b654e1d0..ab77b190032 100755 --- a/gcc/configure +++ b/gcc/configure @@ -28841,6 +28841,40 @@ if test $gcc_cv_as_aarch64_aeabi_build_attributes = yes; then $as_echo "#define HAVE_AS_AEABI_BUILD_ATTRIBUTES 1" >>confdefs.h +fi + + # Check if we have binutils support for DTPREL relocation. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for support of DTPREL relocation" >&5 +$as_echo_n "checking assembler for support of DTPREL relocation... " >&6; } +if ${gcc_cv_as_aarch64_dtprel_relocation+:} false; then : + $as_echo_n "(cached) " >&6 +else + gcc_cv_as_aarch64_dtprel_relocation=no + if test x"$gcc_cv_as" != x; then + $as_echo ' + .xword %dtprel(expr) + ' > conftest.s + if { ac_try='$gcc_cv_as $gcc_cv_as_flags -o conftest.o conftest.s >&5' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } + then + gcc_cv_as_aarch64_dtprel_relocation=yes + else + echo "configure: failed program was" >&5 + cat conftest.s >&5 + fi + rm -f conftest.o conftest.s + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_aarch64_dtprel_relocation" >&5 +$as_echo "$gcc_cv_as_aarch64_dtprel_relocation" >&6; } +if test $gcc_cv_as_aarch64_dtprel_relocation = yes; then + +$as_echo "#define HAVE_AS_DTPREL_RELOC 1" >>confdefs.h + fi # Enable Branch Target Identification Mechanism and Return Address diff --git a/gcc/configure.ac b/gcc/configure.ac index 4360cb95566..c2d27dfdfc4 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -4562,6 +4562,12 @@ case "$target" in .aeabi_attribute Tag_Feature_GCS, 1 ],,[AC_DEFINE(HAVE_AS_AEABI_BUILD_ATTRIBUTES, 1, [Define if your assembler supports AEABI build attributes.])]) + # Check if we have binutils support for DTPREL relocation. + gcc_GAS_CHECK_FEATURE([support of DTPREL relocation], gcc_cv_as_aarch64_dtprel_relocation,, + [ + .xword %dtprel(expr) + ],,[AC_DEFINE(HAVE_AS_DTPREL_RELOC, 1, + [Define if your assembler supports DTPREL relocation.])]) # Enable Branch Target Identification Mechanism and Return Address # Signing by default. AC_ARG_ENABLE(standard-branch-protection, diff --git a/gcc/testsuite/gcc.target/aarch64/pr97344.c b/gcc/testsuite/gcc.target/aarch64/pr97344.c new file mode 100644 index 00000000000..ff00e6d1b20 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr97344.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target aarch64_gas_has_dtprel_reloc } */ +/* { dg-options "-O0 -g" } */ + +#include <stdio.h> + +__thread unsigned long rage = 1; +__thread unsigned long ire = 2; + +void* +increase_rage() +{ + ++rage; + ++ire; + printf ("Rage counter for: %lu/%lu\n", rage, ire); +} + +int +main () +{ + increase_rage(); + printf ("Rage counter %lu/%lu\n", rage, ire); +} + +/* { dg-final { scan-assembler ".xword\t%dtprel\\(rage\\)" } } */ +/* { dg-final { scan-assembler ".xword\t%dtprel\\(ire\\)" } } */ diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 668434e933f..a66c1a6d7c6 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -12871,6 +12871,17 @@ proc check_effective_target_aarch64_gas_has_build_attributes { } { }] } +# Return 1 if Gas supports DTPREL Relocation on AArch64 target +proc check_effective_target_aarch64_gas_has_dtprel_reloc { } { + if { ![istarget aarch64*-*-*] || ![check_effective_target_tls_native] } { + return 0 + } + return [check_no_compiler_messages aarch64_gas_has_dtprel_reloc object { + /* Assembly */ + .xword %dtprel(expr) + }] +} + # Create functions to check that the AArch64 assembler supports the # various architecture extensions via the .arch_extension pseudo-op. -- 2.43.0
