Skip to content

gdb.rocm: replace hipcc with amdclang++ as the HIP compiler#62

Open
spatrang wants to merge 7 commits intoamd-stagingfrom
users/spatrang/replace-hipcc-with-amdclang
Open

gdb.rocm: replace hipcc with amdclang++ as the HIP compiler#62
spatrang wants to merge 7 commits intoamd-stagingfrom
users/spatrang/replace-hipcc-with-amdclang

Conversation

@spatrang
Copy link
Copy Markdown

@spatrang spatrang commented Apr 8, 2026

Motivation
The GDB testsuite was using hipcc for compiler discovery, naming conventions, and documentation examples, even though the underlying binary had already shifted to amdclang++. This PR completes the migration by replacing all hipcc references with amdclang++ throughout the testsuite infrastructure, documentation, and test files.

Technical Details
Compiler discovery and flags (lib/future.exp, lib/gdb.exp):

Compiler search now looks for amdclang++ in $ROCM_PATH/llvm/bin/ instead of hipcc in $ROCM_PATH/bin/.
Added HIP_COMPILER_FOR_TARGET as the primary env var override (HIPCC_FOR_TARGET still accepted as fallback).
Added conditional -x hip / --hip-link flags: -x hip is only passed when compiling source files (not when linking .o files, which would cause parse errors), and --hip-link is only passed when producing executables.
Naming renames (lib/rocm.exp, boards/hip.exp):

allow_hipcc_tests → allow_hip_tests
gdb_find_hipcc / find_hipcc → gdb_find_hip_compiler / find_hip_compiler
All old names preserved as backwards-compat aliases.
Documentation (gdb/doc/gdb.texinfo):

Example compilation command updated from hipcc -O0 -g ... to amdclang++ -x hip --hip-link -O0 -g ....
Test files (74 .exp files in gdb.rocm/ and gdb.perf/):

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR completes the ROCm/HIP testsuite migration from hipcc to amdclang++ by updating compiler discovery, build flag handling, naming, and test/doc references to align with the current ROCm toolchain.

Changes:

  • Switch HIP compiler discovery to amdclang++ (with HIP_COMPILER_FOR_TARGET override and HIPCC_FOR_TARGET fallback) and keep backward-compatible aliases.
  • Update HIP compilation/linking flags to correctly apply -x hip only when compiling sources and --hip-link only when producing executables.
  • Rename testsuite gating helpers (allow_hipcc_testsallow_hip_tests) and update testcases and documentation accordingly (with compatibility aliases retained).

Reviewed changes

Copilot reviewed 79 out of 79 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
gdb/testsuite/lib/rocm.exp Renames HIP gating proc to allow_hip_tests and keeps allow_hipcc_tests as a compatibility alias.
gdb/testsuite/lib/gdb.exp Updates HIP compile/link flag handling for amdclang++ (-x hip / --hip-link) and related comments.
gdb/testsuite/lib/future.exp Switches HIP compiler discovery to amdclang++, adds HIP_COMPILER_FOR_TARGET, and introduces new/compat proc names.
gdb/testsuite/gdb.rocm/watchpoint-basic.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/watchpoint-at-end-of-shader.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/watch-gpu-global-from-host.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/update-thread-list.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/until-tests.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/unaligned-memory-access.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/step-schedlock-spurious-waves.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/step-over-kernel-exit.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/static-global.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/simple.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/simple-outside-debugger.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/show-info.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/shared-memory.exp Updates require gate to allow_hip_tests (and keeps python requirement).
gdb/testsuite/gdb.rocm/scheduler-locking.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/runtime-core.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/resume-exception.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/register-watchpoint.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/program-execution.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/precise-memory.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/precise-memory-warning-watchpoint.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/precise-memory-warning-sigsegv.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/precise-memory-multi-inferiors.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/precise-memory-fork.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/precise-memory-exec.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/ocp_mx.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/nonstop-mode.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/nonstop-displaced.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/names.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/multi-inferior-run-spurious-waves.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/multi-inferior-gpu.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/multi-inferior-fork.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/mi-lanes.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/mi-attach.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/mi-aspace.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/load-core-remote-system.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/line-breakpoint-in-kernel.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/lane-pc-vega20.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/lane-info.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/lane-execution.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/instruction-stepping-commands.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/info-sharedlibrary.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/info-dispatches.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/illegal-insn-sigill.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/hip-builtin-variables.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/hip-builtin-completions.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/generic-address.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/gcore-after-attach.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/fork-exec-non-gpu-to-gpu.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/fork-exec-gpu-to-non-gpu.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/finish.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/exec-bit-extract.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/displaced-stepping.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/disassemble.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/devicecode-breakpoint.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/device-interrupt.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/device-barrier.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/device-attach.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/detach-while-breakpoints-inserted.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/deref-scoped-pointer.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/deep-stack.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/debugtrap.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/corefile.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/core-no-read-special-files.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/convenience_variables.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/continue-over-kernel-exit.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/breakpoint-after-exit.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/break-kernel-no-debug-info.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/branch-fault.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/bit-extract.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/aspace-watchpoint.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/aspace-user-input.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/alu-exceptions.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.rocm/addr-bp-gpu-no-deb-info.exp Updates require gate to allow_hip_tests.
gdb/testsuite/gdb.perf/rocm-break-cond-false.exp Updates require gate to allow_hip_tests for the perf testcase.
gdb/testsuite/boards/hip.exp Updates HIP board config to use find_hip_compiler, renames allow proc, and adjusts amdclang++ detection.
gdb/doc/gdb.texinfo Updates documentation example command line to amdclang++ -x hip --hip-link ....

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gdb/testsuite/lib/future.exp Outdated
Comment thread gdb/testsuite/lib/rocm.exp Outdated
@spatrang spatrang force-pushed the users/spatrang/replace-hipcc-with-amdclang branch from 19d5312 to 3635e5f Compare April 8, 2026 08:39
@spatrang spatrang requested a review from Copilot April 8, 2026 08:39
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 81 out of 81 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gdb/testsuite/lib/future.exp
Copy link
Copy Markdown
Collaborator

@lumachad lumachad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks mostly good to me. Made some comments about small adjustments.

Comment thread gdb/doc/gdb.texinfo
Comment thread gdb/testsuite/boards/hip.exp Outdated
Comment thread gdb/testsuite/boards/hip.exp Outdated
Comment thread gdb/testsuite/boards/hip.exp Outdated
Comment thread gdb/testsuite/lib/future.exp Outdated
Comment thread gdb/testsuite/lib/gdb.exp Outdated
Comment thread gdb/testsuite/lib/rocm.exp Outdated
Copy link
Copy Markdown
Collaborator

@lancesix lancesix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only skimmed thought the patch at this point. Note that some of what you are touching comes from upstream, and we might want to land the changes there as well. I'd probably advise for having this changed upstream first, then we can import it into amd-staging.

@lumachad
Copy link
Copy Markdown
Collaborator

lumachad commented Apr 8, 2026

I agree with upstreaming. We should keep the PR open for reviews and validation. Once we're happy with it, we can take it upstream, wait for approval and pick this up again, then close the PR.

@palves
Copy link
Copy Markdown
Collaborator

palves commented Apr 8, 2026

Another point is making sure this works on the Windows HIP SDK too. The compiler tool name and paths may be different there IIRC.

The boards/hip.exp changes need to be tested with --target_board=hip. A smoke test of running a few testcases like for example gdb.base/break.exp, instead of the full testsuite, is probably enough.

@spatrang spatrang force-pushed the users/spatrang/replace-hipcc-with-amdclang branch from 3635e5f to f938e5f Compare April 9, 2026 07:08
@spatrang spatrang force-pushed the users/spatrang/replace-hipcc-with-amdclang branch from f938e5f to 12dad2a Compare April 9, 2026 12:34
@spatrang spatrang marked this pull request as ready for review April 16, 2026 12:00
@spatrang spatrang requested a review from a team as a code owner April 16, 2026 12:00
Comment thread gdb/testsuite/lib/gdb.exp Outdated
Comment thread gdb/testsuite/lib/gdb.exp Outdated
Comment thread gdb/testsuite/lib/gdb.exp Outdated
Comment thread gdb/testsuite/lib/gdb.exp Outdated
Comment thread gdb/testsuite/lib/future.exp Outdated
- Remove HIPCC_FOR_TARGET support entirely since hipcc is incompatible
  with the new -x hip / --hip-link flags added for amdclang++.
- Stop skipping -fdiagnostics-color for HIP compilation since
  amdclang++ supports it, keeping escape sequences out of gdb.log.
- Remove outdated comments that described hipcc-specific behavior
  no longer applicable to amdclang++.
- Update unbuffered mode .o reordering comment to reflect that
  the workaround relies on the conditional -x hip logic in
  gdb_compile, not on file ordering.
@palves
Copy link
Copy Markdown
Collaborator

palves commented Apr 17, 2026

The boards/hip.exp changes need to be tested with --target_board=hip. A smoke test of running a few testcases like for example gdb.base/break.exp, instead of the full testsuite, is probably enough.

Please make sure you test this. I tried it now with:

$ make check RUNTESTFLAGS="--target_board=hip" TESTS="gdb.base/break.exp"

and that fails with:

gdb compile failed, /home/pedro/rocm/gdb/build/gdb/testsuite/../../../src/gdb/testsuite/lib/hip/hip-test-wrapper.cc:24:10: fatal error: 
      'hip/hip_runtime.h' file not found
   24 | #include <hip/hip_runtime.h>
      |          ^~~~~~~~~~~~~~~~~~~
1 error generated.

                === gdb Summary ===

# of untested testcases         1

Without your patch, it compiles OK. (It then fails for other unrelated reasons.)

@spatrang
Copy link
Copy Markdown
Author

The boards/hip.exp changes need to be tested with --target_board=hip. A smoke test of running a few testcases like for example gdb.base/break.exp, instead of the full testsuite, is probably enough.

Please make sure you test this. I tried it now with:

$ make check RUNTESTFLAGS="--target_board=hip" TESTS="gdb.base/break.exp"

and that fails with:

gdb compile failed, /home/pedro/rocm/gdb/build/gdb/testsuite/../../../src/gdb/testsuite/lib/hip/hip-test-wrapper.cc:24:10: fatal error: 
      'hip/hip_runtime.h' file not found
   24 | #include <hip/hip_runtime.h>
      |          ^~~~~~~~~~~~~~~~~~~
1 error generated.

                === gdb Summary ===

# of untested testcases         1

Without your patch, it compiles OK. (It then fails for other unrelated reasons.)

Fixed. The --target_board=hip path broke because amdclang++ (unlike hipcc) doesn't automatically discover the HIP headers -- it needs --rocm-path to locate them. Added --rocm-path=$rocm_path to the board's compilation flags, along with the -x hip / --hip-link split (compile vs link). Tested with make check RUNTESTFLAGS="--target_board=hip" TESTS="gdb.base/break.exp" -- compilation succeeds, zero hip_runtime.h errors.

Unlike hipcc, amdclang++ doesn't auto-discover HIP headers, so the
board failed to compile hip-test-wrapper.cc (hip/hip_runtime.h
@spatrang
Copy link
Copy Markdown
Author

The boards/hip.exp changes need to be tested with --target_board=hip. A smoke test of running a few testcases like for example gdb.base/break.exp, instead of the full testsuite, is probably enough.

Please make sure you test this. I tried it now with:

$ make check RUNTESTFLAGS="--target_board=hip" TESTS="gdb.base/break.exp"

and that fails with:

gdb compile failed, /home/pedro/rocm/gdb/build/gdb/testsuite/../../../src/gdb/testsuite/lib/hip/hip-test-wrapper.cc:24:10: fatal error: 
      'hip/hip_runtime.h' file not found
   24 | #include <hip/hip_runtime.h>
      |          ^~~~~~~~~~~~~~~~~~~
1 error generated.

                === gdb Summary ===

# of untested testcases         1

Without your patch, it compiles OK. (It then fails for other unrelated reasons.)

@palves
Implemented your suggestion -- for HIP, gdb_compile now pre-compiles each .cpp/.c source to its own .o before the final link step, mirroring the pattern boards/hip.exp already uses. In the unbuffered-mode handler, we now:

Loop over $source and recursively call gdb_compile to produce a .o for each source file (with -x hip, since they're sources)
Append set_unbuffered_mode.o to the now all-.o source list
Strip -x hip from early_flags for the final link (since we only have .o inputs)
Verified with your hack (if { 1 || ...): before the fix, set_unbuffered_mode-hip.o:1:1: error: expected unqualified-id reproduced exactly as you reported. After the fix, the final link becomes amdclang++ --hip-link -O0 ... device_enumerator.cpp.hip.o set_unbuffered_mode-hip.o ... -o device_enumerator.x (only .o inputs, no -x hip) and succeeds

…nputs

When gdb_compile links a HIP executable with unbuffered-mode support,
it used to mix source files (.cpp/.c) and set_unbuffered_mode.o in a
single amdclang++ invocation. With -x hip in early_flags, amdclang++
tried to parse the .o as HIP source and failed with expected
Comment thread gdb/testsuite/lib/gdb.exp Outdated
@palves
Copy link
Copy Markdown
Collaborator

palves commented Apr 22, 2026

Fixed. The --target_board=hip path broke because amdclang++ (unlike hipcc) doesn't automatically discover the HIP headers -- it needs --rocm-path to locate them. Added --rocm-path=$rocm_path to the board's compilation flags, along with the -x hip / --hip-link split (compile vs link). Tested with make check RUNTESTFLAGS="--target_board=hip" TESTS="gdb.base/break.exp" -- compilation succeeds, zero hip_runtime.h errors.

I'm confused. When running the normal gdb.rocm/ tests, I don't see "--rocm-path" passed to amdclang++. Why is it needed here, and not there?

Comment thread gdb/testsuite/lib/gdb.exp Outdated
Comment thread gdb/testsuite/lib/gdb.exp
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 81 out of 81 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gdb/testsuite/lib/future.exp
Comment thread gdb/testsuite/lib/gdb.exp Outdated
@lumachad
Copy link
Copy Markdown
Collaborator

Bringing this up here. @amd-shahab was asking questions on finding llvm-dwarfdump on a CI system. I think we should take the opportunity to make the tools search order correct in these changes (or a separate patch if desired).

See my previous comment here: #62 (comment).

I think we should honor PATH first. Then if ROCM_PATH is set, we go look for tools there. Then if everything fails, we search some hardcoded /opt/rocm path.

- Generalize the -x hip / .o mixing fix: pre-compile each source
  to its own .o at the top of gdb_compile, then recurse with an
  all-.o source list.  Fixes "expected unqualified-id" errors
  when amdclang++ sees -x hip applied to .o inputs.

- Pass --rocm-path explicitly in HIP flags (both lib/gdb.exp and
  boards/hip.exp) so amdclang++ can locate HIP headers/libs
  regardless of how it is invoked.

- Drop -fdiagnostics-color skip for HIP; amdclang++ supports it.

- Remove HIPCC_FOR_TARGET support; hipcc is incompatible with
  the new -x hip / --hip-link flags.

- Fix stale comments and a spurious empty line.
@spatrang spatrang force-pushed the users/spatrang/replace-hipcc-with-amdclang branch from ed95b99 to dff4717 Compare April 23, 2026 08:39
Comment thread gdb/testsuite/lib/gdb.exp Outdated
@palves
Copy link
Copy Markdown
Collaborator

palves commented Apr 23, 2026

Bringing this up here. @amd-shahab was asking questions on finding llvm-dwarfdump on a CI system. I think we should take the opportunity to make the tools search order correct in these changes (or a separate patch if desired).

See my previous comment here: #62 (comment).

I think we should honor PATH first. Then if ROCM_PATH is set, we go look for tools there. Then if everything fails, we search some hardcoded /opt/rocm path.

I agree we should look into this, though I'd prefer if any changes to the search path order was done in a separate patch. We have a little mess here, with search orders different for different tools. E.g., "${rocm_path}/llvm/bin/clang-offload-bundler" in rocm.exp (which now misses the leading lib/), Shahab's patch that searches PATH first, the searches for all the different tools lib/future.exp which search PATH last.

@lumachad
Copy link
Copy Markdown
Collaborator

Bringing this up here. @amd-shahab was asking questions on finding llvm-dwarfdump on a CI system. I think we should take the opportunity to make the tools search order correct in these changes (or a separate patch if desired).
See my previous comment here: #62 (comment).
I think we should honor PATH first. Then if ROCM_PATH is set, we go look for tools there. Then if everything fails, we search some hardcoded /opt/rocm path.

I agree we should look into this, though I'd prefer if any changes to the search path order was done in a separate patch. We have a little mess here, with search orders different for different tools. E.g., "${rocm_path}/llvm/bin/clang-offload-bundler" in rocm.exp (which now misses the leading lib/), Shahab's patch that searches PATH first, the searches for all the different tools lib/future.exp which search PATH last.

Agreed. We need a separate change to clean this all up to use a single approach throughout.

Use indexed temp filename for pre-compiled HIP .o to avoid basename
collisions, and unify the set_unbuffered_mode handler to use the
ldflags= path for HIP too.
Comment thread gdb/testsuite/lib/future.exp Outdated
Comment thread gdb/testsuite/lib/future.exp Outdated
Comment thread gdb/testsuite/lib/gdb.exp
Comment thread gdb/testsuite/lib/gdb.exp
Per PR review: /opt/rocm fallback is orthogonal to the migration
and can override PATH; find_hipcc aliasing to amdclang++ would
hide breakage since it isn't a drop-in for hipcc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants