← Back to Pull requests

[clang][Driver][HIP] Support Debian multiarch libamdhip64.so layout #208525

Open
talhaHavadar opened this pull request with 55 lines diff across 4 files
View on GitHub
talhaHavadar talhaHavadar commented on Jul 09, 2026 18:12 UTC
Author

On Debian and derivatives (Ubuntu, Mint, Pop!_OS), libamdhip64.so is installed under /usr/lib/<multiarch-triple>/ rather than /usr/lib/. As a result, RocmInstallationDetector::detectHIPRuntime() sets LibPath = <install>/lib and the driver then emits an absolute path (<lib>/libamdhip64.so) via Linux::addOffloadRTLibs that does not exist:

$ clang++ -x hip --offload-arch=gfx900 hello.hip -lamdhip64 -o 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

Fix this in Linux::addOffloadRTLibs, where the ToolChain (and therefore Linux::getMultiarchTriple()) is available: probe
<LibPath>/<multiarch-triple>/libamdhip64.so and, when the probe succeeds, extend the HIP lib path with the multiarch subdirectory before it is emitted. Using getMultiarchTriple() rather than the raw target triple matters — builds whose default triple carries -unknown- (e.g. x86_64-unknown-linux-gnu) still map to the correct Debian directory name (x86_64-linux-gnu). The probe is guarded by FS.exists() so non-multiarch layouts (Fedora, Arch, /opt/rocm) fall through unchanged.

Doing the adjustment once in Linux::addOffloadRTLibs keeps the fix in one place: the resulting HIPLibPath is then reused by every consumer that previously called RocmInstallation->getLibPath() directly:

the absolute libamdhip64.so path emitted for the linker,
the -L search path added for HIP, and
* -rpath (opt-in via -frtlib-add-rpath).

RocmInstallationDetector is left untouched, so MSVC.cpp — which uses getLibPath() but does not participate in Linux multiarch — is unaffected.

Reported at https://github.com/ROCm/llvm-project/issues/3169

Supersedes: https://github.com/llvm/llvm-project/pull/207624

Tool use disclosure (per LLVM AI Tool Policy)

The multiarch probe in AMDGPU.cpp was authored by me, the similar hunk
I already carry downstream in debian/patches/0010-fixing-rocm-path.patch
for the llvm-toolchain-rocm package. An AI tool (Claude, Anthropic)
was used to extract just the upstream-relevant hunk from that bundled
downstream patch (which also contains Debian-specific packaging paths
that do not belong upstream), to draft the commit message and this PR
description, and to write the lit test at
clang/test/Driver/hip-multiarch-libs-linux.hip. I reviewed all of
the above before posting, stand behind the change, and can answer
questions about any part of it during review.

Diff: 55 lines (+52 / -3) across 4 files Reviewer: lamb-j Review duration: 208050m
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.38) × (1 − Review Confidence (0.64)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.38 · 55 lines diff across 4 files
0.38
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.50 · 1 substantive comment(s)
0.50
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
63%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.241
Real PR Conversation Timeline
2 items
david-salinas david-salinas commented on code on Nov 25, 2026 04:59 UTC
Code Review
clang/lib/Driver/ToolChains/Linux.cpp:1
@@ -887,9 +887,27 @@ void Linux::addOffloadRTLibs(unsigned ActiveKinds, const ArgList &Args,
       Args.hasArg(options::OPT_no_hip_rt) || Args.hasArg(options::OPT_r))
     return;
 
+  // On Debian and derivatives, the ROCm runtime ships under
+  // <rocm>/lib/<multiarch-triple>/ (e.g. /usr/lib/x86_64-linux-gnu/) rather
+  // than <rocm>/lib/. Prefer the multiarch subdir when libamdhip64.so lives
+  // there, so the absolute path emitted below, the -L search path, and any
+  // -rpath all resolve to a real file. Non-multiarch layouts (Fedora, Arch,
+  // /opt/rocm, etc.) are unaffected: the probe short-circuits when the
+  // multiarch subdir does not contain libamdhip64.so.
+  SmallString<0> HIPLibPath;
+  if (ActiveKinds & Action::OFK_HIP) {
+    HIPLibPath = RocmInstallation->getLibPath();
+    std::string MultiarchTriple =
+        getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot);
+    SmallString<0> MultiarchProbe = HIPLibPath;
+    llvm::sys::path::append(MultiarchProbe, MultiarchTriple, "libamdhip64.so");
+    if (getVFS().exists(MultiarchProbe))
+      llvm::sys::path::append(HIPLibPath, MultiarchTriple);
+  }
+
   llvm::SmallVector<std::pair<StringRef, StringRef>> Libraries;
   if (ActiveKinds & Action::OFK_HIP)
-    Libraries.emplace_back(RocmInstallation->getLibPath(), "libamdhip64.so");
+    Libraries.emplace_back(HIPLibPath, "libamdhip64.so");

Small nit. Should we combine these two " if (ActiveKinds & Action::OFK_HIP)" statements? Line #898 and #909?

Reviewers
Assignees
talhaHavadar talhaHavadar
Labels
risk: low confidence: 63.9% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 38.5% (MEDIUM) · Higher = larger blast radius
38.5%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 63.9% · Lower = rushed or shallow review
63.9%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 13.9% · Safe to merge
13.9%