Skip to content

Compile bug: Link error (R_X86_64_PC32 / R_X86_64_TPOFF32) in libllama-server-impl.so with Clang + LTO since #23462 #23581

Closed

Description

@demiquartz

Git commit

bb28c1f

Operating systems

Linux

GGML backends

HIP

Problem description & steps to reproduce

Description

A build regression was introduced in commit bb28c1fe2 (#23462) when compiling llama-server.

When internal libraries were changed from STATIC to SHARED, the embedded static assets (such as index_html) and thread_local variables inside the server implementation caused linker errors (ld.lld) when using Clang with -flto (Link Time Optimization). It seems that -fPIC or the appropriate TLS model is not being properly propagated to these embedded resources during the LTO phase under the new shared library structure.

Environment & Toolchain

  • Compiler: AOCC 5.1.0 (Clang-based)
  • Linker: ld.lld
  • CPU: AMD Ryzen 9 9950X
  • GPU: AMD Radeon RX 7900 XTX

First Bad Commit

bb28c1f

Compile command

UNIFIED_COMPILE_FLAGS='-march=native'
RELEASE_COMPILE_FLAGS='-DNDEBUG -O3 -zopt -fveclib=AMDLIBM -flto'
LINK_LIBRARIES='-Wl,--as-needed -lalm'

cmake -B build -G Ninja \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
    -DCMAKE_C_COMPILER=clang \
    -DCMAKE_C_FLAGS="$UNIFIED_COMPILE_FLAGS" \
    -DCMAKE_C_FLAGS_RELEASE="$RELEASE_COMPILE_FLAGS" \
    -DCMAKE_C_STANDARD_LIBRARIES="$LINK_LIBRARIES" \
    -DCMAKE_CXX_COMPILER=clang++ \
    -DCMAKE_CXX_FLAGS="$UNIFIED_COMPILE_FLAGS" \
    -DCMAKE_CXX_FLAGS_RELEASE="$RELEASE_COMPILE_FLAGS" \
    -DCMAKE_CXX_STANDARD_LIBRARIES="$LINK_LIBRARIES" \
    -DCMAKE_INSTALL_RPATH="\$ORIGIN;${AOCL_ROOT}/lib;${AOCC_INS_DIR}/lib" \
    -DCMAKE_PREFIX_PATH='/opt/rocm-7.2.2' \
    -DGGML_CUDA_FA_ALL_QUANTS=ON \
    -DGGML_CUDA_FORCE_MMQ=ON \
    -DGGML_HIP=ON \
    -DGPU_TARGETS=gfx1100 \
    -DMATH_LIBRARY='alm;m'

Relevant log output

FAILED: [code=1] bin/libllama-server-impl.so
: && /opt/AMD/aocc-compiler-5.1.0/bin/clang++ -fPIC -march=native -DNDEBUG -O3 -zopt -fveclib=AMDLIBM -flto  -shared -Xlinker --dependency-file=tools/server/CMakeFiles/llama-server-impl.dir/link.d -Wl,-soname,libllama-server-impl.so -o bin/libllama-server-impl.so tools/server/CMakeFiles/llama-server-impl.dir/server.cpp.o tools/server/CMakeFiles/llama-server-impl.dir/server-http.cpp.o tools/server/CMakeFiles/llama-server-impl.dir/server-models.cpp.o  -Wl,-rpath,"\$ORIGIN:/opt/AMD/aocl/aocl-linux-aocc-5.2.0/aocc/lib:/opt/AMD/aocc-compiler-5.1.0/lib"  tools/server/libserver-context.a  tools/ui/libllama-ui.a  vendor/cpp-httplib/libcpp-httplib.a  bin/libllama-common.so.0.0.9281  common/libllama-common-base.a  bin/libmtmd.so.0.0.9281  bin/libllama.so.0.0.9281  bin/libggml.so.0.12.0  bin/libggml-cpu.so.0.12.0  bin/libggml-hip.so.0.12.0  bin/libggml-base.so.0.12.0  /usr/lib/x86_64-linux-gnu/libssl.so  /usr/lib/x86_64-linux-gnu/libcrypto.so  -Wl,-rpath-link,/opt/rocm-7.2.2/lib -Wl,--as-needed -lalm && :
ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'index_html_len'; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by ld-temp.o

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol 'index_html'; recompile with -fPIC
>>> defined in lto.tmp
>>> referenced by ld-temp.o

ld.lld: error: relocation R_X86_64_TPOFF32 against generate_multipart_boundary[abi:cxx11]()::gen cannot be used with -shared
>>> defined in lto.tmp
>>> referenced by ld-temp.o

ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Activity

  1. aldehir commented on May 24, 2026

    @aldehir
    Contributor

    #23592 might resolve this, if you want to give that a try.

  2. demiquartz commented on May 24, 2026

    @demiquartz
    Author

    I just tested this PR in my environment and the build now passes successfully without any relocation errors.
    It completely resolved the issue. Thank you!

  3. linked a pull request that will close this issuecmake : fix ui build #23592on May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions