Skip to content

Commit

Permalink
clang: Use rtlib provided by compiler instead of hardcoding libgcc
Browse files Browse the repository at this point in the history
Clang provides runtime library `libclang_rt.builtins.<arch>.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 <pdk@semihalf.com>
  • Loading branch information
duda-patryk committed Jul 6, 2023
1 parent 4c15e72 commit 73cae7f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cmake/compiler/clang/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down

0 comments on commit 73cae7f

Please sign in to comment.