llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver
Author: Talha Can Havadar (talhaHavadar)
<details>
<summary>Changes</summary>
## Summary
On Debian and derivatives (Ubuntu, Mint, Pop!_OS), the ROCm runtime is
installed under `/usr/lib/<multiarch-triple>/` rather than `/usr/lib/`.
`RocmInstallationDetector::detectHIPRuntime()` currently sets
`LibPath = <install>/lib` unconditionally, so
`Linux::addOffloadRTLibs()` emits an absolute
`<lib>/libamdhip64.so` path that does not exist and the link fails.
This patch probes `<LibPath>/<triple>/libamdhip64.so` after
computing
`LibPath` and extends `LibPath` with the triple subdirectory when the
probe succeeds. The change is guarded by `FS.exists()`, so
non-multiarch layouts (Fedora, Arch, `/opt/rocm`) fall through
unchanged.
## Reproduction (before this PR)
On Ubuntu 26.10 with `libamdhip64-dev` installed
(`libamdhip64.so` shipped at `/usr/lib/x86_64-linux-gnu/`):
```sh
cat > /tmp/hello.hip <<'END'
#include <hip/hip_runtime.h>
int main() { return 0; }
END
clang++ -x hip --offload-arch=gfx900 /tmp/hello.hip -lamdhip64 -o /tmp/hello
```
```
ld.lld: error: cannot open /usr/lib/libamdhip64.so: No such file or directory
clang-linker-wrapper: error: 'ld.lld' failed
clang++: error: linker command failed with exit code 1
```
With this patch, `<lib>/x86_64-linux-gnu/libamdhip64.so` is picked up
and the link succeeds.
## Impact
Fixes every HIP link on Debian, Ubuntu, and derivatives (Mint,
Pop!_OS, etc.) using the system `libamdhip64-dev`. Non-multiarch
layouts (Fedora, Arch, `/opt/rocm`) are unaffected: the new codepath
is only entered when `<lib>/<triple>/libamdhip64.so` actually
exists.
All three consumers of `getLibPath()` are corrected:
- `Linux::addOffloadRTLibs` — the absolute path resolves to a real
file.
- The `-L` search path added for HIP points at the correct directory.
- `-rpath` (opt-in via `-frtlib-add-rpath`) bakes the correct path.
`MSVC.cpp` is unaffected — the Windows layout does not use multiarch.
## Test plan
`clang/test/Driver/hip-multiarch-libs-linux.hip` covers both:
- A fake ROCm root with `lib/x86_64-linux-gnu/libamdhip64.so` present:
the driver emits the multiarch path and a `-L` that points at the
multiarch dir.
- The existing `Inputs/rocm` tree (no multiarch subdir): the driver
falls back to `<rocm>/lib/libamdhip64.so`.
## Notes
Reported downstream at
https://github.com/ROCm/llvm-project/issues/3169 — @<!-- -->lamb-j asked me
to send the fix here for review.
---
Full diff: https://github.com/llvm/llvm-project/pull/207624.diff
2 Files Affected:
- (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (+10)
- (added) clang/test/Driver/hip-multiarch-libs-linux.hip (+33)
``````````diff
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 032c108d3d10d..9fcb309a087ea 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -457,6 +457,16 @@ void RocmInstallationDetector::detectHIPRuntime() {
llvm::sys::path::append(IncludePath, "include");
LibPath = InstallPath;
llvm::sys::path::append(LibPath, "lib");
+ // Debian multiarch: prefer <lib>/<triple> when libamdhip64.so lives
+ // there, so both the absolute path emitted by Linux::addOffloadRTLibs
+ // and the -L flag resolve to a real file. Guarded by FS.exists() so
+ // non-multiarch layouts (Fedora, Arch, /opt/rocm, etc.) fall through
+ // unchanged.
+ SmallString<0> MultiArchProbe = LibPath;
+ llvm::sys::path::append(MultiArchProbe, D.getTargetTriple(),
+ "libamdhip64.so");
+ if (FS.exists(MultiArchProbe))
+ llvm::sys::path::append(LibPath, D.getTargetTriple());
SharePath = InstallPath;
llvm::sys::path::append(SharePath, "share");
diff --git a/clang/test/Driver/hip-multiarch-libs-linux.hip
b/clang/test/Driver/hip-multiarch-libs-linux.hip
new file mode 100644
index 0000000000000..d835bb7f70e38
--- /dev/null
+++ b/clang/test/Driver/hip-multiarch-libs-linux.hip
@@ -0,0 +1,33 @@
+// UNSUPPORTED: system-windows
+
+// Test that Debian-style multiarch layouts, in which libamdhip64.so is
+// installed under <rocm>/lib/<triple>/ rather than <rocm>/lib/, are
+// detected by the driver and reflected in the linker command line.
+
+// RUN: touch %t.o
+
+// Build a fake ROCm tree that mimics a Debian multiarch layout:
+// <rocm>/bin/.hipVersion signals a valid HIP install,
+// <rocm>/lib/x86_64-linux-gnu/libamdhip64.so is the runtime the driver
+// must find.
+// RUN: rm -rf %t.rocm.multiarch
+// RUN: mkdir -p %t.rocm.multiarch/bin
+// RUN: mkdir -p %t.rocm.multiarch/lib/x86_64-linux-gnu
+// RUN: cp %S/Inputs/rocm/bin/.hipVersion %t.rocm.multiarch/bin/.hipVersion
+// RUN: touch %t.rocm.multiarch/lib/x86_64-linux-gnu/libamdhip64.so
+
+// RUN: %clang -### --hip-link --target=x86_64-linux-gnu \
+// RUN: --rocm-path=%t.rocm.multiarch %t.o 2>&1 \
+// RUN: | FileCheck -check-prefixes=MULTIARCH %s
+
+// MULTIARCH: "{{.*/lib/x86_64-linux-gnu/libamdhip64.so}}"
+// MULTIARCH: "-L{{.*/lib/x86_64-linux-gnu}}"
+
+// Sanity check: when libamdhip64.so is *not* under lib/<triple>/, the
+// driver falls back to <rocm>/lib/ so non-Debian layouts are unchanged.
+// RUN: %clang -### --hip-link --target=x86_64-linux-gnu \
+// RUN: --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
+// RUN: | FileCheck -check-prefixes=FLAT %s
+
+// FLAT: "{{.*/Inputs/rocm/lib/libamdhip64.so}}"
+// FLAT-NOT: "{{.*/Inputs/rocm/lib/x86_64-linux-gnu/libamdhip64.so}}"
``````````
</details>
https://github.com/llvm/llvm-project/pull/207624
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits