]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/hip: Prepare for DWARF-assembler-based HIP testcases
authorPedro Alves <pedro@palves.net>
Fri, 3 Oct 2025 16:45:39 +0000 (17:45 +0100)
committerPedro Alves <pedro@palves.net>
Thu, 9 Jul 2026 13:59:43 +0000 (14:59 +0100)
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 <lancelot.six@amd.com> (amdgpu)
Change-Id: I64a938edf97c85d0ea9fc34b37071daa560de7e7

gdb/testsuite/lib/gdb.exp

index a19e8ba6729862d9b2b1e35954a3f9eaf2bb7ff1..a40c87c67279d10d5f4af972a9c95f96b3f83e39 100644 (file)
@@ -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