@@ -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)
@@ -405,8 +402,8 @@ function(_add_target_variant_link_flags)
405402 MACCATALYST_BUILD_FLAVOR "${LFLAGS_MACCATALYST_BUILD_FLAVOR} " )
406403 if ("${LFLAGS_SDK} " STREQUAL "LINUX" )
407404 list (APPEND link_libraries "pthread" "dl" )
408- if ("${SWIFT_HOST_VARIANT_ARCH } " MATCHES "armv6|armv7|i686" )
409- list (APPEND link_libraries PRIVATE "atomic" )
405+ if ("${LFLAGS_ARCH } " MATCHES "armv6|armv7|i686" )
406+ list (APPEND link_libraries "atomic" )
410407 endif ()
411408 elseif ("${LFLAGS_SDK} " STREQUAL "FREEBSD" )
412409 list (APPEND link_libraries "pthread" )
@@ -433,8 +430,14 @@ function(_add_target_variant_link_flags)
433430 list (APPEND result "-Wl,-Bsymbolic" )
434431 elseif ("${LFLAGS_SDK} " STREQUAL "ANDROID" )
435432 list (APPEND link_libraries "dl" "log" )
433+ if ("${LFLAGS_ARCH} " STREQUAL "armv7" )
434+ list (APPEND link_libraries "atomic" )
435+ endif ()
436436 # We need to add the math library, which is linked implicitly by libc++
437437 list (APPEND result "-lm" )
438+ if (NOT "${SWIFT_ANDROID_NDK_PATH} " STREQUAL "" )
439+ list (APPEND result "-resource-dir=${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH} _PATH}/../lib64/clang/${SWIFT_ANDROID_NDK_CLANG_VERSION} " )
440+ endif ()
438441
439442 # link against the custom C++ library
440443 swift_android_cxx_libraries_for_arch(${LFLAGS_ARCH} cxx_link_libraries)
@@ -444,11 +447,6 @@ function(_add_target_variant_link_flags)
444447 list (APPEND link_libraries
445448 ${SWIFT_ANDROID_${LFLAGS_ARCH} _ICU_I18N}
446449 ${SWIFT_ANDROID_${LFLAGS_ARCH} _ICU_UC})
447-
448- swift_android_libgcc_for_arch_cross_compile(${LFLAGS_ARCH} ${LFLAGS_ARCH} _LIB)
449- foreach (path IN LISTS ${LFLAGS_ARCH} _LIB)
450- list (APPEND library_search_directories ${path} )
451- endforeach ()
452450 else ()
453451 # If lto is enabled, we need to add the object path flag so that the LTO code
454452 # generator leaves the intermediate object file in a place where it will not
@@ -476,10 +474,17 @@ function(_add_target_variant_link_flags)
476474 endif ()
477475
478476 if (SWIFT_USE_LINKER AND NOT SWIFT_COMPILER_IS_MSVC_LIKE)
477+ # The linker is normally chosen based on the host, but the Android NDK only
478+ # uses lld now.
479+ if ("${LFLAGS_SDK} " STREQUAL "ANDROID" )
480+ set (linker "lld" )
481+ else ()
482+ set (linker "${SWIFT_USE_LINKER} " )
483+ endif ()
479484 if (CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
480- list (APPEND result "-fuse-ld=${SWIFT_USE_LINKER } .exe" )
485+ list (APPEND result "-fuse-ld=${linker } .exe" )
481486 else ()
482- list (APPEND result "-fuse-ld=${SWIFT_USE_LINKER } " )
487+ list (APPEND result "-fuse-ld=${linker } " )
483488 endif ()
484489 endif ()
485490
0 commit comments