Skip to content

Commit 4204fd1

Browse files
committed
[llvm-libgcc] Fix symlink path for libcc when LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is unset
current logic fails when LLVM_ENABLE_PER_TARGET_RUNTIME_DIR = OFF and it ends up with symlinks e.g. libgcc.a -> ..//usr/lib/clang/21.1.4/lib/linux/libclang_rt.builtins.a the real library is at ../lib/clang/21.1.4/lib/linux/libclang_rt.builtins-aarch64.a The relative path is incorrect and its missing to add -arch suffix as well. So we make checks a bit more explicit to cover this case. The symlink for libgcc_so.1.0 is made to point to libunwind.so which is functionally correct but it fails some linux distro packaging complain because libunwind.so is made part of -dev package but libgcc_so.1.0 ends up in the real package, and creates an unneeded package -> dev dependency create the symlink to point to libunwind.so.1 instead then the boundaries of packaging are not crossed and all is well. Signed-off-by: Khem Raj <[email protected]>
1 parent e980458 commit 4204fd1

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

llvm-libgcc/CMakeLists.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,21 @@ target_link_libraries(unwind_shared PUBLIC
124124
#===============================================================================
125125

126126
get_compiler_rt_install_dir(${COMPILER_RT_DEFAULT_TARGET_ARCH} install_dir_builtins)
127+
128+
# Drop a leading "lib/" if present so we don't duplicate lib/lib
127129
string(REGEX REPLACE "^lib/" "" install_dir_builtins "${install_dir_builtins}")
128-
string(FIND "${install_dir_builtins}" "clang" install_path_contains_triple)
129-
if(install_path_contains_triple EQUAL -1)
130+
131+
# Decide based on the actual CMake option, not on guessing from the path.
132+
if (NOT LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
133+
# Flat-ish layout, e.g. usr/lib/clang/21.1.4/lib/linux/
134+
# Libraries are named libclang_rt.builtins-<arch>.a
130135
set(builtins_suffix "-${COMPILER_RT_DEFAULT_TARGET_ARCH}")
136+
# Do NOT prepend "../"
131137
else()
138+
# Per-target layout, e.g.
139+
# usr/lib/clang/21.1.4/lib/aarch64-unknown-linux-gnu/
140+
# Libraries are just libclang_rt.builtins.a
141+
set(builtins_suffix "")
132142
string(PREPEND install_dir_builtins "../")
133143
endif()
134144
set(LLVM_LIBGCC_COMPILER_RT ${install_dir_builtins}/libclang_rt.builtins${builtins_suffix}.a)
@@ -137,7 +147,7 @@ add_custom_target(llvm-libgcc ALL
137147
DEPENDS unwind_shared unwind_static clang_rt.builtins-${COMPILER_RT_DEFAULT_TARGET_ARCH}
138148
COMMAND ${CMAKE_COMMAND} -E create_symlink ${LLVM_LIBGCC_COMPILER_RT} libgcc.a
139149
COMMAND ${CMAKE_COMMAND} -E create_symlink libunwind.a libgcc_eh.a
140-
COMMAND ${CMAKE_COMMAND} -E create_symlink libunwind.so libgcc_s.so.1.0
150+
COMMAND ${CMAKE_COMMAND} -E create_symlink libunwind.so.1 libgcc_s.so.1.0
141151
COMMAND ${CMAKE_COMMAND} -E create_symlink libgcc_s.so.1.0 libgcc_s.so.1
142152
COMMAND ${CMAKE_COMMAND} -E create_symlink libgcc_s.so.1 libgcc_s.so
143153
)

0 commit comments

Comments
 (0)