env/corellium/android/files: fix testcshared tests on android/arm

Tweak the compiler wrapper to find liblog.so.

Before this change:

--- FAIL: TestExportedSymbols (19.77s)
    cshared_test.go:325: command failed: [/data/data/com.termux/files/home/clangwrap -fPIC -marm -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/data/data/com.termux/files/home/tmpdir/workdir-host-android-arm64-corellium-android/tmp/go-build149321221=/tmp/go-build -gno-record-gcc-switches -pie -I pkg/android_arm -I /data/data/com.termux/files/home/tmpdir/workdir-host-android-arm64-corellium-android/tmp/cshared_test050295299/pkg/android_arm_testcshared_shared/testcshared -o testp0 main0.c libgo.a]
        exit status 1
        /data/data/com.termux/files/usr/bin/ld: warning: liblog.so, needed by libgo.a, not found (try using -rpath or -rpath-link)
        /data/data/com.termux/files/usr/bin/ld: libgo.a: undefined reference to `__android_log_vprint'
        clang-9: error: linker command failed with exit code 1 (use -v to see invocation)

While here, change a hardcoded sleep wait with a proper check.

Change-Id: I2a3db47b9d2fb10f2d4376c4de33bd6badb1eb01
Reviewed-on: https://go-review.googlesource.com/c/build/+/207279
Run-TryBot: Elias Naur <mail@eliasnaur.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/env/corellium/android/files/clangwrap.go b/env/corellium/android/files/clangwrap.go
index 7e00be8..7f17c48 100644
--- a/env/corellium/android/files/clangwrap.go
+++ b/env/corellium/android/files/clangwrap.go
@@ -14,7 +14,7 @@
 	cmd := exec.Command("clang")
 	if os.Getenv("GOARCH") == "arm" {
 		pref := os.Getenv("PREFIX")
-		cmd.Args = append(cmd.Args, "-target", "armv7a-linux-androideabi", "-Qunused-arguments", "-L"+pref+"/../home/arm-linux-androideabi/lib", "-B"+pref+"/../home/arm-linux-androideabi/lib")
+		cmd.Args = append(cmd.Args, "-target", "armv7a-linux-androideabi", "-Qunused-arguments", "-Wl,-rpath-link="+pref+"/../home/arm-linux-androideabi/lib", "-L"+pref+"/../home/arm-linux-androideabi/lib", "-B"+pref+"/../home/arm-linux-androideabi/lib")
 	}
 	cmd.Args = append(cmd.Args, args...)
 	cmd.Stdout = os.Stdout
diff --git a/env/corellium/android/install.sh b/env/corellium/android/install.sh
index aafb80f..8c227dd 100755
--- a/env/corellium/android/install.sh
+++ b/env/corellium/android/install.sh
@@ -10,18 +10,22 @@
 curl -o com.termux.boot.apk "https://f-droid.org/repo/com.termux.boot_7.apk"
 
 adb install com.termux.apk
+
+# Run Termux to set up filesystem.
+adb shell monkey -p com.termux -c android.intent.category.LAUNCHER 1
+
 adb install com.termux.boot.apk
 
 # Run boot app once to enable run-on-boot.
 adb shell monkey -p com.termux.boot -c android.intent.category.LAUNCHER 1
 
-# Run Termux to set up filesystem.
-adb shell monkey -p com.termux -c android.intent.category.LAUNCHER 1
+adb root
 
 # Wait for the Termux filesystem.
-sleep 5
+while adb shell ls /data/data/com.termux/files > /dev/null ; [ $? -ne 0 ]; do
+	sleep 1
+done
 
-adb root
 adb push buildkey /data/data/com.termux/files/home/.gobuildkey-host-android-arm64-corellium-android
 adb push files/exec.sh /data/data/com.termux
 adb push files/clangwrap.go /data/data/com.termux/files/home