From 95acdad3a53b8fa150b2b5d2cdc81aa6cbb2b75c Mon Sep 17 00:00:00 2001 From: Mark Caldwell Date: Mon, 1 Jun 2026 08:22:50 -0700 Subject: [PATCH] fix(cmake): build HIP backend with PIC so the static-lib PIE link succeeds CMAKE_POSITION_INDEPENDENT_CODE is only set inside the SD_BUILD_SHARED_LIBS branch. The HIP backend's default build is a static library, so it never gets PIC, and hipcc emits non-PIC objects for ggml-cuda.cu. On toolchains that default to PIE (Ubuntu 24.04, Fedora 40+, Debian 12+) the sd-cli link then fails: ld.lld: error: relocation R_X86_64_32 against `.rodata.str1.1` cannot be used when making a PIE object; recompile with -fPIE >>> defined in .../ggml-hip/.../ggml-cuda.cu.o Set CMAKE_POSITION_INDEPENDENT_CODE ON in the SD_HIPBLAS block so the device-stub objects are position-independent and the default-PIE link succeeds. Verified on an AMD RDNA4 (gfx1201) card under ROCm 7.0.2: -DSD_HIPBLAS=ON now links and runs with no extra flags (no -no-pie needed). Co-Authored-By: Claude Opus 4.8 (1M context) --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d6c03da3..2804bad46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,6 +125,12 @@ endif () if (SD_HIPBLAS) message("-- Use HIPBLAS as backend stable-diffusion") set(GGML_HIP ON) + # ggml-hip's device-stub objects must be position-independent, or the + # default-PIE sd-cli link fails with `relocation R_X86_64_32 ... cannot be + # used when making a PIE object` on distros that default to PIE + # (Ubuntu 24.04, Fedora 40+, Debian 12+). The shared-library branch below + # already sets this; the static build (the HIP default) did not. + set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif () if(SD_MUSA)