From 73cae7f52ca63003efc257944923f861d7613275 Mon Sep 17 00:00:00 2001 From: Patryk Duda Date: Thu, 29 Jun 2023 18:37:31 +0200 Subject: [PATCH] clang: Use rtlib provided by compiler instead of hardcoding libgcc Clang provides runtime library `libclang_rt.builtins..a` but `libgcc.a` is also supported. The compiler can provide full path to the selected library using the `--print-libgcc-file-name` option, for example: ``` /usr/lib64/clang/17/lib/baremetal/libclang_rt.builtins-armv7m.a ``` If `--rtlib=libgcc` option is provided, clang will also provide appropriate path. This patch replaces hardcoded `libgcc` with library name extracted from path, so we are compatible with both libraries. Signed-off-by: Patryk Duda --- cmake/compiler/clang/target.cmake | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmake/compiler/clang/target.cmake b/cmake/compiler/clang/target.cmake index 9d88a993e28e5c7..66fa2d1e3f778bb 100644 --- a/cmake/compiler/clang/target.cmake +++ b/cmake/compiler/clang/target.cmake @@ -58,16 +58,16 @@ if(NOT "${ARCH}" STREQUAL "posix") # This libgcc code is partially duplicated in compiler/*/target.cmake execute_process( COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} --print-libgcc-file-name - OUTPUT_VARIABLE LIBGCC_FILE_NAME + OUTPUT_VARIABLE RTLIB_FILE_NAME OUTPUT_STRIP_TRAILING_WHITESPACE ) - get_filename_component(LIBGCC_DIR ${LIBGCC_FILE_NAME} DIRECTORY) + get_filename_component(RTLIB_DIR ${RTLIB_FILE_NAME} DIRECTORY) + get_filename_component(RTLIB_NAME_WITH_PREFIX ${RTLIB_FILE_NAME} NAME_WLE) + string(REPLACE lib "" RTLIB_NAME ${RTLIB_NAME_WITH_PREFIX}) - list(APPEND LIB_INCLUDE_DIR "-L\"${LIBGCC_DIR}\"") - if(LIBGCC_DIR) - list(APPEND TOOLCHAIN_LIBS gcc) - endif() + list(APPEND LIB_INCLUDE_DIR -L${RTLIB_DIR}) + list(APPEND TOOLCHAIN_LIBS ${RTLIB_NAME}) list(APPEND CMAKE_REQUIRED_FLAGS -nostartfiles -nostdlib ${isystem_include_flags}) string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")