@@ -94,12 +94,9 @@ function(_add_target_variant_c_compile_link_flags)
9494 endif ()
9595
9696 if ("${CFLAGS_SDK} " STREQUAL "ANDROID" )
97- # lld can handle targeting the android build. However, if lld is not
98- # enabled, then fallback to the linker included in the android NDK.
99- if (NOT SWIFT_USE_LINKER STREQUAL "lld" )
100- swift_android_tools_path(${CFLAGS_ARCH} tools_path)
101- list (APPEND result "-B" "${tools_path} " )
102- endif ()
97+ # Make sure the Android NDK lld is used.
98+ swift_android_tools_path(${CFLAGS_ARCH} tools_path)
99+ list (APPEND result "-B" "${tools_path} " )
103100 endif ()
104101
105102 if ("${CFLAGS_SDK} " IN_LIST SWIFT_DARWIN_PLATFORMS)
@@ -389,8 +386,8 @@ function(_add_target_variant_link_flags)
389386 MACCATALYST_BUILD_FLAVOR "${LFLAGS_MACCATALYST_BUILD_FLAVOR} " )
390387 if ("${LFLAGS_SDK} " STREQUAL "LINUX" )
391388 list (APPEND link_libraries "pthread" "dl" )
392- if ("${SWIFT_HOST_VARIANT_ARCH } " MATCHES "armv6|armv7|i686" )
393- list (APPEND link_libraries PRIVATE "atomic" )
389+ if ("${LFLAGS_ARCH } " MATCHES "armv6|armv7|i686" )
390+ list (APPEND link_libraries "atomic" )
394391 endif ()
395392 elseif ("${LFLAGS_SDK} " STREQUAL "FREEBSD" )
396393 list (APPEND link_libraries "pthread" )
@@ -417,8 +414,14 @@ function(_add_target_variant_link_flags)
417414 list (APPEND result "-Wl,-Bsymbolic" )
418415 elseif ("${LFLAGS_SDK} " STREQUAL "ANDROID" )
419416 list (APPEND link_libraries "dl" "log" )
417+ if ("${LFLAGS_ARCH} " STREQUAL "armv7" )
418+ list (APPEND link_libraries "atomic" )
419+ endif ()
420420 # We need to add the math library, which is linked implicitly by libc++
421421 list (APPEND result "-lm" )
422+ if (NOT "${SWIFT_ANDROID_NDK_PATH} " STREQUAL "" )
423+ list (APPEND result "-resource-dir=${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH} _PATH}/../lib64/clang/${SWIFT_ANDROID_NDK_CLANG_VERSION} " )
424+ endif ()
422425
423426 # link against the custom C++ library
424427 swift_android_cxx_libraries_for_arch(${LFLAGS_ARCH} cxx_link_libraries)
@@ -428,11 +431,6 @@ function(_add_target_variant_link_flags)
428431 list (APPEND link_libraries
429432 ${SWIFT_ANDROID_${LFLAGS_ARCH} _ICU_I18N}
430433 ${SWIFT_ANDROID_${LFLAGS_ARCH} _ICU_UC})
431-
432- swift_android_libgcc_for_arch_cross_compile(${LFLAGS_ARCH} ${LFLAGS_ARCH} _LIB)
433- foreach (path IN LISTS ${LFLAGS_ARCH} _LIB)
434- list (APPEND library_search_directories ${path} )
435- endforeach ()
436434 else ()
437435 # If lto is enabled, we need to add the object path flag so that the LTO code
438436 # generator leaves the intermediate object file in a place where it will not
@@ -460,10 +458,17 @@ function(_add_target_variant_link_flags)
460458 endif ()
461459
462460 if (SWIFT_USE_LINKER AND NOT SWIFT_COMPILER_IS_MSVC_LIKE)
461+ # The linker is normally chosen based on the host, but the Android NDK only
462+ # uses lld now.
463+ if ("${LFLAGS_SDK} " STREQUAL "ANDROID" )
464+ set (linker "lld" )
465+ else ()
466+ set (linker "${SWIFT_USE_LINKER} " )
467+ endif ()
463468 if (CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
464- list (APPEND result "-fuse-ld=${SWIFT_USE_LINKER } .exe" )
469+ list (APPEND result "-fuse-ld=${linker } .exe" )
465470 else ()
466- list (APPEND result "-fuse-ld=${SWIFT_USE_LINKER } " )
471+ list (APPEND result "-fuse-ld=${linker } " )
467472 endif ()
468473 endif ()
469474
0 commit comments