Skip to content

Commit 76b8975

Browse files
authored
[compiler-rt] Fix linking a standalone libatomic for MinGW (#74668)
Whenever linking with -nodefaultlibs for a MinGW target, we manually need to specify a bunch of libraries - listed in ${MINGW_LIBRARIES}; the same is already done for sanitizers and libunwind/libcxxabi/libcxx. Practically speaking, linking with -nodefaultlibs but manually passing the libraries in ${MINGW_LIBRARIES} restores most of the libraries that are linked by default, except for the potential compiler builtins and unwind library; i.e. it has essentially the same effect as linking with "--unwindlib=none -rtlib=none", except that -rtlib doesn't accept such a value. When building only compiler-rt/lib/builtins, not all of compiler-rt, ${MINGW_LIBRARIES} is unset - set it manually here for that case. This matches what is set in compiler-rt/cmake/config-ix.cmake, except that the builtins (libgcc or compiler-rt builtins) is omitted; the only use within lib/buitlins is for the standalone libatomic, which explicitly already links against the just-built builtins.
1 parent 6b0ed49 commit 76b8975

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

compiler-rt/lib/builtins/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
3838
include(UseLibtool)
3939
endif()
4040
include(AddCompilerRT)
41+
42+
if(MINGW)
43+
# Simplified version of what's set in cmake/config-ix.cmake; not including
44+
# builtins, which are linked separately.
45+
set(MINGW_LIBRARIES mingw32 moldname mingwex msvcrt advapi32 shell32
46+
user32 kernel32 mingw32 moldname mingwex msvcrt)
47+
endif()
4148
endif()
4249

4350
if (COMPILER_RT_STANDALONE_BUILD)
@@ -881,12 +888,14 @@ if(COMPILER_RT_BUILD_STANDALONE_LIBATOMIC)
881888
endif()
882889
foreach (arch ${BUILTIN_SUPPORTED_ARCH})
883890
if(CAN_TARGET_${arch})
891+
list(APPEND COMPILER_RT_LIBATOMIC_LINK_LIBS_${arch} clang_rt.builtins-${arch})
892+
append_list_if(MINGW "${MINGW_LIBRARIES}" COMPILER_RT_LIBATOMIC_LINK_LIBS_${arch})
884893
add_compiler_rt_runtime(clang_rt.atomic
885894
${BUILTIN_TYPE}
886895
ARCHS ${arch}
887896
SOURCES atomic.c
888897
LINK_FLAGS ${COMPILER_RT_LIBATOMIC_LINK_FLAGS}
889-
LINK_LIBS clang_rt.builtins-${arch}
898+
LINK_LIBS ${COMPILER_RT_LIBATOMIC_LINK_LIBS_${arch}}
890899
PARENT_TARGET builtins-standalone-atomic)
891900
endif()
892901
endforeach()

0 commit comments

Comments
 (0)