@@ -94,12 +94,9 @@ function(_add_target_variant_c_compile_link_flags)
94
94
endif ()
95
95
96
96
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} " )
103
100
endif ()
104
101
105
102
if ("${CFLAGS_SDK} " IN_LIST SWIFT_DARWIN_PLATFORMS)
@@ -389,8 +386,8 @@ function(_add_target_variant_link_flags)
389
386
MACCATALYST_BUILD_FLAVOR "${LFLAGS_MACCATALYST_BUILD_FLAVOR} " )
390
387
if ("${LFLAGS_SDK} " STREQUAL "LINUX" )
391
388
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" )
394
391
endif ()
395
392
elseif ("${LFLAGS_SDK} " STREQUAL "FREEBSD" )
396
393
list (APPEND link_libraries "pthread" )
@@ -417,8 +414,14 @@ function(_add_target_variant_link_flags)
417
414
list (APPEND result "-Wl,-Bsymbolic" )
418
415
elseif ("${LFLAGS_SDK} " STREQUAL "ANDROID" )
419
416
list (APPEND link_libraries "dl" "log" )
417
+ if ("${LFLAGS_ARCH} " STREQUAL "armv7" )
418
+ list (APPEND link_libraries "atomic" )
419
+ endif ()
420
420
# We need to add the math library, which is linked implicitly by libc++
421
421
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 ()
422
425
423
426
# link against the custom C++ library
424
427
swift_android_cxx_libraries_for_arch(${LFLAGS_ARCH} cxx_link_libraries)
@@ -428,11 +431,6 @@ function(_add_target_variant_link_flags)
428
431
list (APPEND link_libraries
429
432
${SWIFT_ANDROID_${LFLAGS_ARCH} _ICU_I18N}
430
433
${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 ()
436
434
else ()
437
435
# If lto is enabled, we need to add the object path flag so that the LTO code
438
436
# generator leaves the intermediate object file in a place where it will not
@@ -460,10 +458,17 @@ function(_add_target_variant_link_flags)
460
458
endif ()
461
459
462
460
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 ()
463
468
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" )
465
470
else ()
466
- list (APPEND result "-fuse-ld=${SWIFT_USE_LINKER } " )
471
+ list (APPEND result "-fuse-ld=${linker } " )
467
472
endif ()
468
473
endif ()
469
474
0 commit comments