Repository navigation
Conversation
hipify-clang's RPATH is $ORIGIN/../lib, which resolves to <prefix>/lib. In the versioned ROCm packaging layout libLLVM is installed to <prefix>/lib/llvm/lib, so the binary cannot start: hipify-clang: error while loading shared libraries: libLLVM.so.23.0git: cannot open shared object file Append $ORIGIN/../lib/llvm/lib so both layouts resolve.
| set_target_properties(hipify-clang PROPERTIES INSTALL_RPATH "") | ||
| # Set RPATH for the binary. | ||
| set_target_properties(hipify-clang PROPERTIES LINK_FLAGS "-Wl,--enable-new-dtags -Wl,--rpath,\\$ORIGIN/../lib" ) | ||
| set_target_properties(hipify-clang PROPERTIES LINK_FLAGS "-Wl,--enable-new-dtags -Wl,--rpath,\\$ORIGIN/../lib:\\$ORIGIN/../lib/llvm/lib" ) |
There was a problem hiding this comment.
hipify-clang should be statically linked against LLVM and clang. Dynamic linking is undocumented and unsupported behavior.
There was a problem hiding this comment.
Static linking is not available in the configuration where this bug occurs.
TheRock sets LLVM_BUILD_LLVM_DYLIB ON / LLVM_LINK_LLVM_DYLIB ON unconditionally for Linux in compiler/pre_hook_amd-llvm.cmake, which is why the shipped ROCm 7.14 package contains libLLVM.so.23.0git (#2704). In that mode clang's static libraries carry a transitive dependency on libLLVM, so combining them with statically linked LLVM components reintroduces the ODR "duplicate cl::opt registered" failures that #1840 / #1873 fixed — which is exactly why hipify-clang links its LLVM components via LLVM_LINK_COMPONENTS today.
So making hipify-clang statically linked would require changing TheRock's LLVM build configuration first, which is outside this repository. This PR does not add or extend dynamic linking; it only corrects where the binary looks for the libLLVM it is already linked against, which is why it is scoped to the RPATH.
If you do want to pursue static linking against LLVM/clang, that looks like a separate piece of work spanning HIPIFY and TheRock — should I open an issue for it?
72f0dd3 to
b492315
Compare
Replace the hardcoded $ORIGIN/../lib/llvm/lib fallback with a derivation from LLVM_LIBRARY_DIRS relative to CMAKE_INSTALL_PREFIX, so the RPATH stays correct for whatever layout the consumed LLVM package reports instead of just the one layout observed so far. Directories outside the install prefix are skipped so no build-machine path leaks into the shipped binary. hipify-clang cannot be statically linked against LLVM/clang here: TheRock builds LLVM with LLVM_LINK_LLVM_DYLIB=ON on Linux unconditionally, and statically linking clang's libraries against a dylib-mode LLVM reintroduces the ODR "duplicate cl::opt registered" crash that ROCm#1840/ROCm#1873 fixed. Document that constraint inline so it isn't relitigated without the history.
b492315 to
2920d8b
Compare
LINK_FLAGS is a single unquoted string, so building "-Wl,--rpath,a:b" by hand breaks on any path containing a space, and a path containing ':' silently corrupts the entry list. Assigning LINK_FLAGS here also discarded the -Wl,-rpath-link (GNU ld) and -Wl,-z,origin (FreeBSD) flags that llvm_setup_rpath() appends from add_llvm_executable(). Use the INSTALL_RPATH target property instead: it is a real CMake list that CMake quotes and joins itself, and setting it replaces the value llvm_setup_rpath() installed, so the existing "clear it first" line is no longer needed. --enable-new-dtags moves to target_link_options() with the LINKER: prefix, which is additive rather than clobbering. Library dirs that cannot be represented are now reported rather than silently dropped: a dir outside CMAKE_INSTALL_PREFIX is omitted at STATUS level (keeping build-machine paths out of a redistributable binary; the build-tree binary still resolves libLLVM through the BUILD_RPATH llvm_setup_rpath() derives from LLVM_LIBRARY_DIR for that case), and a dir containing ':' is omitted with a warning. Verified the generated RPATH for in-prefix, out-of-prefix, space- and colon-containing library dirs; the space case now emits a correctly quoted entry where the previous LINK_FLAGS form split the argument.
Add $ORIGIN/../${CMAKE_INSTALL_LIBDIR} variants alongside the lib ones
(ROCm keeps LLVM under lib/llvm/lib even on lib64 distros), and only set
the $ORIGIN INSTALL_RPATH / --enable-new-dtags on non-Apple platforms.
LLVM lib dir to hipify-clang RPATH
Fixes #2704.
Problem
hipify-clangfrom the ROCm 7.14 packages cannot start, because itsRUNPATHdoes not include the directory that actually shipslibLLVM:$ORIGIN/../libresolves to<prefix>/lib, but in the versioned ROCm layout LLVM is installed one level deeper under<prefix>/lib/llvm/lib./opt/rocm/libis also not registered with the dynamic loader (ROCm/TheRock#6716), so there is no fallback and the failure is unconditional on a stock install.Change
Append
$ORIGIN/../lib/llvm/libto the RPATH. The original entry is kept first, so a flat layout that installslibLLVMdirectly into<prefix>/libcontinues to resolve exactly as before.Test
Building HIPIFY needs a full LLVM/Clang dev tree, so I verified the RPATH mechanism directly by reproducing the install layout (
bin/,lib/,lib/llvm/lib/) and linking a binary against a stand-in library placed wherelibLLVMactually ships:$ORIGIN/../lib$ORIGIN/../lib:$ORIGIN/../lib/llvm/libLD_LIBRARY_PATH$ORIGIN/../lib:$ORIGIN/../lib/llvm/lib, lib in../lib3 passed, 0 failed. The first row is a control: it must keep failing, otherwise the test would be vacuous.
Independently, adding only that directory to the search path is sufficient to make the shipped binary work:
Environment
Ubuntu 26.04, ROCm 7.14.0~pre3 (
amdrocm-hipify7.14) fromrepo.radeon.com/rocmradeon/apt/26.13, gfx1100.Note
Opened as a draft.
hipify-perlis unaffected (Perl script, no shared-library dependency). Related earlier fixes in this area: #678 and #1959.