From e45ddc8955b84c6ef92c42e96642cc6e09b92073 Mon Sep 17 00:00:00 2001 From: John Holdsworth Date: Tue, 23 May 2017 01:47:07 +0100 Subject: [PATCH 1/9] Ensure fatalError message logged on Android --- stdlib/public/runtime/Errors.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/stdlib/public/runtime/Errors.cpp b/stdlib/public/runtime/Errors.cpp index 2ccd48bebfe52..1b579964c8172 100644 --- a/stdlib/public/runtime/Errors.cpp +++ b/stdlib/public/runtime/Errors.cpp @@ -50,6 +50,10 @@ #include #endif +#ifdef __ANDROID__ +#include +#endif + namespace FatalErrorFlags { enum: uint32_t { ReportBacktrace = 1 << 0 @@ -231,6 +235,9 @@ reportNow(uint32_t flags, const char *message) #ifdef __APPLE__ asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", message); #endif +#ifdef __ANDROID__ + __android_log_print(ANDROID_LOG_ERROR, "Swift", "%s", message); +#endif #if SWIFT_SUPPORTS_BACKTRACE_REPORTING if (flags & FatalErrorFlags::ReportBacktrace) { fputs("Current stack trace:\n", stderr); From d600e7581d6368c74cfcd9d92948ab6677fe155f Mon Sep 17 00:00:00 2001 From: John Holdsworth Date: Tue, 30 May 2017 20:16:40 +0100 Subject: [PATCH 2/9] Use #elif --- stdlib/public/runtime/Errors.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/stdlib/public/runtime/Errors.cpp b/stdlib/public/runtime/Errors.cpp index 1b579964c8172..c50035632ac92 100644 --- a/stdlib/public/runtime/Errors.cpp +++ b/stdlib/public/runtime/Errors.cpp @@ -46,11 +46,9 @@ #include #endif -#ifdef __APPLE__ +#if defined(__APPLE__) #include -#endif - -#ifdef __ANDROID__ +#elif defined(__ANDROID__) #include #endif @@ -232,11 +230,10 @@ reportNow(uint32_t flags, const char *message) #else write(STDERR_FILENO, message, strlen(message)); #endif -#ifdef __APPLE__ +#if defined(__APPLE__) asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", message); -#endif -#ifdef __ANDROID__ - __android_log_print(ANDROID_LOG_ERROR, "Swift", "%s", message); +#elif defined(__ANDROID__) + __android_log_print(ANDROID_LOG_FATAL, "SwiftRuntime", "%s", message); #endif #if SWIFT_SUPPORTS_BACKTRACE_REPORTING if (flags & FatalErrorFlags::ReportBacktrace) { From c7ea92a28096973f175828dee8d41a618cec21c8 Mon Sep 17 00:00:00 2001 From: John Holdsworth Date: Tue, 30 May 2017 22:26:30 +0100 Subject: [PATCH 3/9] Cmake changes for -llog and -latomic --- cmake/modules/AddSwift.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index 5dd80da545ea7..6fb104e6162ad 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -359,9 +359,10 @@ function(_add_variant_link_flags) endif() elseif("${LFLAGS_SDK}" STREQUAL "ANDROID") list(APPEND result - "-ldl" + "-ldl" "-llog" "-latomic" "${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so") list(APPEND library_search_directories + "${SWIFT_ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/lib/armv7-a" "${SWIFT_ANDROID_PREBUILT_PATH}/lib/gcc/arm-linux-androideabi/${SWIFT_ANDROID_NDK_GCC_VERSION}.x") else() # If lto is enabled, we need to add the object path flag so that the LTO code From 0ab8788cc83f9f831317a411b65c286385fd9342 Mon Sep 17 00:00:00 2001 From: John Holdsworth Date: Tue, 30 May 2017 23:16:58 +0100 Subject: [PATCH 4/9] Cmake changes for -llog and -latomic II --- cmake/modules/AddSwift.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index 6fb104e6162ad..521d2ab99a146 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -362,7 +362,7 @@ function(_add_variant_link_flags) "-ldl" "-llog" "-latomic" "${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so") list(APPEND library_search_directories - "${SWIFT_ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/lib/armv7-a" + "${SWIFT_ANDROID_PREBUILT_PATH}/arm-linux-androideabi/lib/armv7-a" "${SWIFT_ANDROID_PREBUILT_PATH}/lib/gcc/arm-linux-androideabi/${SWIFT_ANDROID_NDK_GCC_VERSION}.x") else() # If lto is enabled, we need to add the object path flag so that the LTO code From 32bd9f1e49ffecf2fafa0e950a51f7f7e975afdd Mon Sep 17 00:00:00 2001 From: John Holdsworth Date: Thu, 1 Jun 2017 01:25:55 +0100 Subject: [PATCH 5/9] Cmake changes for -llog and -latomic III --- cmake/modules/AddSwift.cmake | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index 521d2ab99a146..eb449199466b1 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -1505,6 +1505,12 @@ function(add_swift_library name) if("${lib}" STREQUAL "ICU_UC") list(APPEND swiftlib_private_link_libraries_targets "${SWIFT_${sdk}_ICU_UC}") + // temporary fix for atomic needing to be + // after object files for libswiftCore.so + if("${sdk}" STREQUAL "ANDROID") + list(APPEND swiftlib_private_link_libraries_targets + "-latomic") + endif() elseif("${lib}" STREQUAL "ICU_I18N") list(APPEND swiftlib_private_link_libraries_targets "${SWIFT_${sdk}_ICU_I18N}") From b5bd098d235a2f1128d271dd85692cfd47b81195 Mon Sep 17 00:00:00 2001 From: John Holdsworth Date: Thu, 1 Jun 2017 01:35:55 +0100 Subject: [PATCH 6/9] Cmake changes for -llog and -latomic IV --- cmake/modules/AddSwift.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index eb449199466b1..6b15f601be0a3 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -1505,8 +1505,8 @@ function(add_swift_library name) if("${lib}" STREQUAL "ICU_UC") list(APPEND swiftlib_private_link_libraries_targets "${SWIFT_${sdk}_ICU_UC}") - // temporary fix for atomic needing to be - // after object files for libswiftCore.so + # temporary fix for atomic needing to be + # after object files for libswiftCore.so if("${sdk}" STREQUAL "ANDROID") list(APPEND swiftlib_private_link_libraries_targets "-latomic") From 304f556f5d438b217a3c7d7fd485ad7fe8166521 Mon Sep 17 00:00:00 2001 From: John Holdsworth Date: Thu, 1 Jun 2017 01:53:29 +0100 Subject: [PATCH 7/9] Cmake changes for -llog and -latomic V --- cmake/modules/AddSwift.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index 6b15f601be0a3..eae85ea302804 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -359,7 +359,7 @@ function(_add_variant_link_flags) endif() elseif("${LFLAGS_SDK}" STREQUAL "ANDROID") list(APPEND result - "-ldl" "-llog" "-latomic" + "-ldl" "-llog" "-latomic" "-licudata" "-licui18n" "-licuuc" "${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so") list(APPEND library_search_directories "${SWIFT_ANDROID_PREBUILT_PATH}/arm-linux-androideabi/lib/armv7-a" From 8248322be00e718714295b13d35c632ea76f46c3 Mon Sep 17 00:00:00 2001 From: John Holdsworth Date: Sun, 4 Jun 2017 23:34:23 +0100 Subject: [PATCH 8/9] Remove cause of crash on Android --- stdlib/public/runtime/ImageInspectionELF.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stdlib/public/runtime/ImageInspectionELF.cpp b/stdlib/public/runtime/ImageInspectionELF.cpp index 54fb1230715b3..0e925e0aabc61 100644 --- a/stdlib/public/runtime/ImageInspectionELF.cpp +++ b/stdlib/public/runtime/ImageInspectionELF.cpp @@ -68,8 +68,12 @@ static SectionInfo getSectionInfo(const char *imageName, SectionInfo sectionInfo = { 0, nullptr }; void *handle = dlopen(imageName, RTLD_LAZY | RTLD_NOLOAD); if (!handle) { +#ifdef __ANDROID__ + return sectionInfo; +#else fatalError(/* flags = */ 0, "dlopen() failed on `%s': %s", imageName, dlerror()); +#endif } void *symbol = dlsym(handle, sectionName); if (symbol) { From ed38b57a48530dd5e0e0f2f311ca305ce3c7a040 Mon Sep 17 00:00:00 2001 From: John Holdsworth Date: Mon, 5 Jun 2017 01:59:47 +0100 Subject: [PATCH 9/9] Revert "Remove cause of crash on Android" This reverts commit 8248322be00e718714295b13d35c632ea76f46c3. --- stdlib/public/runtime/ImageInspectionELF.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stdlib/public/runtime/ImageInspectionELF.cpp b/stdlib/public/runtime/ImageInspectionELF.cpp index 0e925e0aabc61..54fb1230715b3 100644 --- a/stdlib/public/runtime/ImageInspectionELF.cpp +++ b/stdlib/public/runtime/ImageInspectionELF.cpp @@ -68,12 +68,8 @@ static SectionInfo getSectionInfo(const char *imageName, SectionInfo sectionInfo = { 0, nullptr }; void *handle = dlopen(imageName, RTLD_LAZY | RTLD_NOLOAD); if (!handle) { -#ifdef __ANDROID__ - return sectionInfo; -#else fatalError(/* flags = */ 0, "dlopen() failed on `%s': %s", imageName, dlerror()); -#endif } void *symbol = dlsym(handle, sectionName); if (symbol) {