@@ -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)
@@ -407,8 +404,8 @@ function(_add_target_variant_link_flags)
407404 MACCATALYST_BUILD_FLAVOR "${LFLAGS_MACCATALYST_BUILD_FLAVOR} " )
408405 if ("${LFLAGS_SDK} " STREQUAL "LINUX" )
409406 list (APPEND link_libraries "pthread" "dl" )
410- if ("${SWIFT_HOST_VARIANT_ARCH } " MATCHES "armv6|armv7|i686" )
411- list (APPEND link_libraries PRIVATE "atomic" )
407+ if ("${LFLAGS_ARCH } " MATCHES "armv6|armv7|i686" )
408+ list (APPEND link_libraries "atomic" )
412409 endif ()
413410 elseif ("${LFLAGS_SDK} " STREQUAL "FREEBSD" )
414411 list (APPEND link_libraries "pthread" )
@@ -437,6 +434,9 @@ function(_add_target_variant_link_flags)
437434 list (APPEND link_libraries "dl" "log" )
438435 # We need to add the math library, which is linked implicitly by libc++
439436 list (APPEND result "-lm" )
437+ if (NOT "${SWIFT_ANDROID_NDK_PATH} " STREQUAL "" )
438+ list (APPEND result "-resource-dir=${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH} _PATH}/../lib64/clang/${SWIFT_ANDROID_NDK_CLANG_VERSION} " )
439+ endif ()
440440
441441 # link against the custom C++ library
442442 swift_android_cxx_libraries_for_arch(${LFLAGS_ARCH} cxx_link_libraries)
@@ -446,11 +446,6 @@ function(_add_target_variant_link_flags)
446446 list (APPEND link_libraries
447447 ${SWIFT_ANDROID_${LFLAGS_ARCH} _ICU_I18N}
448448 ${SWIFT_ANDROID_${LFLAGS_ARCH} _ICU_UC})
449-
450- swift_android_libgcc_for_arch_cross_compile(${LFLAGS_ARCH} ${LFLAGS_ARCH} _LIB)
451- foreach (path IN LISTS ${LFLAGS_ARCH} _LIB)
452- list (APPEND library_search_directories ${path} )
453- endforeach ()
454449 else ()
455450 # If lto is enabled, we need to add the object path flag so that the LTO code
456451 # generator leaves the intermediate object file in a place where it will not
@@ -478,10 +473,17 @@ function(_add_target_variant_link_flags)
478473 endif ()
479474
480475 if (SWIFT_USE_LINKER AND NOT SWIFT_COMPILER_IS_MSVC_LIKE)
476+ # The linker is normally chosen based on the host, but the Android NDK only
477+ # uses lld now.
478+ if ("${LFLAGS_SDK} " STREQUAL "ANDROID" )
479+ set (linker "lld" )
480+ else ()
481+ set (linker "${SWIFT_USE_LINKER} " )
482+ endif ()
481483 if (CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
482- list (APPEND result "-fuse-ld=${SWIFT_USE_LINKER } .exe" )
484+ list (APPEND result "-fuse-ld=${linker } .exe" )
483485 else ()
484- list (APPEND result "-fuse-ld=${SWIFT_USE_LINKER } " )
486+ list (APPEND result "-fuse-ld=${linker } " )
485487 endif ()
486488 endif ()
487489
0 commit comments