You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ky...@apache.org on 2019/08/30 06:39:52 UTC

[incubator-weex] branch master updated: [Android] Support for ASAN (#2862)

This is an automated email from the ASF dual-hosted git repository.

kyork pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git


The following commit(s) were added to refs/heads/master by this push:
     new 59f1ee0  [Android] Support for ASAN (#2862)
59f1ee0 is described below

commit 59f1ee0cb08ba8741c958119488ca0b35586f0d3
Author: katherine95s <51...@users.noreply.github.com>
AuthorDate: Fri Aug 30 14:39:46 2019 +0800

    [Android] Support for ASAN (#2862)
---
 android/sdk/build.gradle | 46 +++++++++++++++++++++++++++++++++++++++++++---
 scripts/wrap.sh          | 11 +++++++++++
 2 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/android/sdk/build.gradle b/android/sdk/build.gradle
index e183968..48e331c 100755
--- a/android/sdk/build.gradle
+++ b/android/sdk/build.gradle
@@ -151,6 +151,9 @@ android {
                         '-DANDROID_PROJECT_DIR=' + "${android_project_dir}",
                         '-DENABLE_ASAN=false',
                         '-DBUILD_RUNTIME_API='+"${buildRuntimeApi}"
+                if(project.hasProperty('enableASan') && "true" == project.getProperty('enableASan')) {
+                    cppFlags "-fsanitize=address -fno-omit-frame-pointer"
+                }
             }
         }
     }
@@ -264,11 +267,10 @@ if(file('../license/LICENSE').exists()){
     }
     preBuild.dependsOn licenseFormat
 }
-
+def ndkDir = ''
 task checkNdkVersion() {
     def rootDir = project.rootDir
     def localProperties = new File(rootDir, "local.properties")
-    def ndkDir = ''
     if (localProperties.exists()) {
         Properties properties = new Properties()
         localProperties.withInputStream { instr ->
@@ -360,7 +362,45 @@ artifactory {
         }
     }
 }
-
+def asanAbi = project.hasProperty('asanAbi') ? project.getProperty('asanAbi') : 'arm64-v8a'
+task clearASanLibs(type: Delete){
+    delete project.android.sourceSets.main.resources.srcDirs
+    delete fileTree(project.android.sourceSets.main.jniLibs.srcDirs[-1]) {
+        include '**/libclang_rt.asan-*-android.so'
+    }
+}
+task copyWrapScript(type: Copy,dependsOn: clearASanLibs) {
+    if(project.hasProperty('enableASan') && "true" == project.getProperty('enableASan')) {
+        from '../../scripts/wrap.sh'
+        into new File(project.android.sourceSets.main.resources.srcDirs[-1], "lib")
+        eachFile {
+            it.path = "${asanAbi}/${it.name}"
+        }
+    }
+}
+task copyASanLib(type: Copy,dependsOn: copyWrapScript){
+    if(project.hasProperty('enableASan') && "true" == project.getProperty('enableASan')) {
+        def ndkPath = ndkDir == '' ? System.getenv("ANDROID_NDK_HOME"):ndkDir
+        def dir = ndkPath + '/toolchains/llvm/prebuilt/'
+        def renamedAbi = asanAbi
+        if (asanAbi == "armeabi-v7a" || asanAbi == "armeabi")
+            renamedAbi = "arm"
+        if (asanAbi == "arm64-v8a")
+            renamedAbi = "aarch64"
+        if (asanAbi == "x86")
+            renamedAbi = "i686"
+        new File(dir).eachFileRecurse { file ->
+            if (file.name == 'libclang_rt.asan-' + renamedAbi + '-android.so')
+                from file.absolutePath
+                into project.android.sourceSets.main.jniLibs.srcDirs[-1]
+                eachFile {
+                    it.path = "${asanAbi}/${it.name}"
+                }
+            includeEmptyDirs = false
+        }
+    }
+}
+preBuild.dependsOn copyASanLib
 
 afterEvaluate { project ->
     transformNativeLibsWithStripDebugSymbolForRelease << {
diff --git a/scripts/wrap.sh b/scripts/wrap.sh
new file mode 100644
index 0000000..2b0dfbe
--- /dev/null
+++ b/scripts/wrap.sh
@@ -0,0 +1,11 @@
+#!/system/bin/sh
+HERE="$(cd "$(dirname "$0")" && pwd)"
+export ASAN_OPTIONS=log_to_syslog=false,allow_user_segv_handler=1,use_sigaltstack=0
+ASAN_LIB=$(ls $HERE/libclang_rt.asan-*-android.so)
+if [ -f "$HERE/libc++_shared.so" ]; then
+    # Workaround for https://github.com/android-ndk/ndk/issues/988.
+    export LD_PRELOAD="$ASAN_LIB $HERE/libc++_shared.so"
+else
+    export LD_PRELOAD="$ASAN_LIB"
+fi
+"$@"