Skip to content

[CMake] LLVM_HOST_TRIPLE cross compilation ignores CMAKE_SHARED_LINKER_FLAGS #85504

Open
@MaskRay

Description

@MaskRay

I am trying a cross compilation (-DLLVM_HOST_TRIPLE=x86_64-linux-musl). It seems that shared object links (e.g. lib/LLVMHello.so, unittests/Support/DynamicLibrary/PipSqueak.so) do not respect CMAKE_SHARED_LINKER_FLAGS.

If I use LLVM_USE_SPLIT_DWARF=on, a DSO link does not pick up -fuse-ld=lld and will fail due to GNU ld not supporting --gdb-index

MUSL=$HOME/Dev/musl-cross-make
cmake -GNinja -Sllvm -B/tmp/out/musl -DCMAKE_BUILD_TYPE=Debug -DLLVM_USE_SPLIT_DWARF=on -DCMAKE_C_COMPILER=~/Stable/bin/clang -DCMAKE_CXX_COMPILER=~/Stable/bin/clang++ -DCMAKE_{C,CXX}_FLAGS="--target=x86_64-linux-musl --sysroot=$MUSL/output/x86_64-linux-musl --gcc-install-dir=$MUSL/output/lib/gcc/x86_64-linux-musl/9.4.0" -DCMAKE_{EXE,SHARED}_LINKER_FLAGS="-fuse-ld=lld -Wl,--dynamic-linker=$MUSL/output/x86_64-linux-musl/lib/libc.so -Wl,-rpath=$MUSL/output/x86_64-linux-musl/lib" -DLLVM_NATIVE_TOOL_DIR=/tmp/Rel/bin -DLLVM_HOST_TRIPLE=x86_64-linux-musl -DLLVM_TARGETS_TO_BUILD=host -DLLVM_ENABLE_PROJECTS='clang;lld'
ninja -C /tmp/out/musl lib/LLVMHello.so # musl-cross-make/output/lib/gcc/x86_64-linux-musl/9.4.0/../../../../x86_64-linux-musl/bin/ld: unrecognized option '--gdb-index'

As a workaround, I can add -fuse-ld=lld -w to CFLAGS instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cmakeBuild system in general and CMake in particular

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions