[binutils-gdb] gdb/hip: Prepare for DWARF-assembler-based HIP testcases

Pedro Alves via Gdb-cvs <[email protected]> Thu, 9 Jul 2026 14:00:58 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b43c744924b3f5df3677dbe97d12608e63ca5a4d

commit b43c744924b3f5df3677dbe97d12608e63ca5a4d
Author: Pedro Alves <[email protected]>
Date:   Fri Oct 3 17:45:39 2025 +0100

    gdb/hip: Prepare for DWARF-assembler-based HIP testcases
    
    Compiling a testcase with debug info (by passing passing "debug" as
    gdb_compile option) has the effect of passing -g to the compiler.  -g
    in turn enables an LLVM option that is essential for debugging:
    '-mllvm -amdgpu-spill-cfi-saved-regs'.
    
    That option affects code generation, and some features of the DWARF
    assembler machinery rely on code generated by the compiler without -g
    to be the exact same as the code generated with -g.
    
    This patch addresses that by always compiling with the LLVM option
    that -g would enable.
    
    Approved-by: Lancelot Six <[email protected]> (amdgpu)
    Change-Id: I64a938edf97c85d0ea9fc34b37071daa560de7e7

Diff:
---
 gdb/testsuite/lib/gdb.exp | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index a19e8ba6729..a40c87c6727 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -6745,11 +6745,35 @@ proc gdb_compile {source dest type options} {
 	lappend new_options "early_flags=-fno-stack-protector"
     }
 
-    # hipcc defaults to -O2, so add -O0 to early flags for the hip language.
-    # If "optimize" is also requested, another -O flag (e.g. -O2) will be added
-    # to the flags, overriding this -O0.
     if {[lsearch -exact $options hip] != -1} {
-	lappend new_options "early_flags=-O0"
+	# The -g option enables an LLVM option that is essential for
+	# debugging (-mllvm -amdgpu-spill-cfi-saved-regs), but that
+	# unfortunately also affects code generation.  We don't want
+	# to hardcode -g here though, because some tests want to test
+	# debugging without debug info, and yet others want to compile
+	# their binary without debug info or with -gline-info-only,
+	# and then use the DWARF assembler to generate their own debug
+	# info.  Some features of the DWARF assembler rely on nodebug
+	# and debug binaries having the exact same generated code, so,
+	# explicitly compile with the LLVM option that -g would
+	# enable, and leave adding -g to the testcase, via the "debug"
+	# option, as normal.
+	#
+	# Disable -Wunused-command-line-argument to avoid warnings
+	# like:
+	#
+	#  clang: warning: argument unused during compilation: \
+	#    '-mllvm=-amdgpu-spill-cfi-saved-regs' [-Wunused-command-line-argument]
+	#
+	# These happen when we're compiling an executable _and_ all
+	# the input files are .o files, like: hipcc foo.o -o foo ...
+	#
+	# HIPCC defaults to -O2, so add -O0 to early flags for the HIP
+	# language.  If "optimize" is also requested, another -O flag
+	# (e.g. -O2) will be added to the flags, overriding this -O0.
+	lappend new_options "early_flags=-O0\
+			     -mllvm=-amdgpu-spill-cfi-saved-regs\
+			     -Wno-unused-command-line-argument"
     }
 
     # Because we link with libraries using their basename, we may need