--- /clang/lib/Basic/CMakeLists.txt +++ /clang/lib/Basic/CMakeLists.txt @@ -110,3 +110,23 @@ omp_gen ) +# libclangBasic compiled by GCC at least on 32-bit PowerPC may contain reference +# to __atomic_load_8. +# Link against library libatomic provided by GCC. +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # Use options --push-state, --as-needed and --pop-state if linker is known + # to support them. + # Use single option -Wl of compiler driver to avoid incorrect re-ordering + # of options by CMake. + if (LLVM_LINKER_IS_GNULD OR LLVM_LINKER_IS_GOLD OR LLVM_LINKER_IS_LLD OR LLVM_LINKER_IS_MOLD) + target_link_libraries(clangBasic + PRIVATE + "-Wl,--push-state,--as-needed,-latomic,--pop-state" + ) + else() + target_link_libraries(clangBasic + PRIVATE + atomic + ) + endif() +endif()