@@ -94,9 +94,12 @@ function(_add_target_variant_c_compile_link_flags)
9494 endif ()
9595
9696 if ("${CFLAGS_SDK} " STREQUAL "ANDROID" )
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} " )
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 ()
100103 endif ()
101104
102105 if ("${CFLAGS_SDK} " IN_LIST SWIFT_DARWIN_PLATFORMS)
@@ -402,8 +405,8 @@ function(_add_target_variant_link_flags)
402405 MACCATALYST_BUILD_FLAVOR "${LFLAGS_MACCATALYST_BUILD_FLAVOR} " )
403406 if ("${LFLAGS_SDK} " STREQUAL "LINUX" )
404407 list (APPEND link_libraries "pthread" "dl" )
405- if ("${LFLAGS_ARCH } " MATCHES "armv6|armv7|i686" )
406- list (APPEND link_libraries "atomic" )
408+ if ("${SWIFT_HOST_VARIANT_ARCH } " MATCHES "armv6|armv7|i686" )
409+ list (APPEND link_libraries PRIVATE "atomic" )
407410 endif ()
408411 elseif ("${LFLAGS_SDK} " STREQUAL "FREEBSD" )
409412 list (APPEND link_libraries "pthread" )
@@ -430,14 +433,8 @@ function(_add_target_variant_link_flags)
430433 list (APPEND result "-Wl,-Bsymbolic" )
431434 elseif ("${LFLAGS_SDK} " STREQUAL "ANDROID" )
432435 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 ()
441438
442439 # link against the custom C++ library
443440 swift_android_cxx_libraries_for_arch(${LFLAGS_ARCH} cxx_link_libraries)
@@ -447,6 +444,11 @@ function(_add_target_variant_link_flags)
447444 list (APPEND link_libraries
448445 ${SWIFT_ANDROID_${LFLAGS_ARCH} _ICU_I18N}
449446 ${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 ()
450452 else ()
451453 # If lto is enabled, we need to add the object path flag so that the LTO code
452454 # generator leaves the intermediate object file in a place where it will not
@@ -474,17 +476,10 @@ function(_add_target_variant_link_flags)
474476 endif ()
475477
476478 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 ()
484479 if (CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
485- list (APPEND result "-fuse-ld=${linker } .exe" )
480+ list (APPEND result "-fuse-ld=${SWIFT_USE_LINKER } .exe" )
486481 else ()
487- list (APPEND result "-fuse-ld=${linker } " )
482+ list (APPEND result "-fuse-ld=${SWIFT_USE_LINKER } " )
488483 endif ()
489484 endif ()
490485
0 commit comments