Symlink prebuilt binaries on host.

This means binaries will run from their source location and look up
shared libs relative to there.

Test: m nothing
Test: Set up a prebuilt binary with shared libs, check that it can
  be executed during build, and check that its symlinks get updated
  when a shared lib is touched.
Bug: 145934348
Change-Id: I1a600c7163ce0ec34ee8caf0ffe87fef4feb3064
diff --git a/cc/prebuilt_test.go b/cc/prebuilt_test.go
index adb44bd..d94d59a 100644
--- a/cc/prebuilt_test.go
+++ b/cc/prebuilt_test.go
@@ -15,6 +15,7 @@
 package cc
 
 import (
+	"path/filepath"
 	"testing"
 
 	"android/soong/android"
@@ -271,3 +272,48 @@
 	shared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*Module)
 	assertString(t, shared.OutputFile().Path().Base(), "libbar.so")
 }
+
+func TestPrebuiltSymlinkedHostBinary(t *testing.T) {
+	ctx := testPrebuilt(t, `
+	cc_prebuilt_library_shared {
+		name: "libfoo",
+		device_supported: false,
+		host_supported: true,
+		target: {
+			linux_glibc_x86_64: {
+				srcs: ["linux_glibc_x86_64/lib64/libfoo.so"],
+			},
+		},
+	}
+
+	cc_prebuilt_binary {
+		name: "foo",
+		device_supported: false,
+		host_supported: true,
+		shared_libs: ["libfoo"],
+		target: {
+			linux_glibc_x86_64: {
+				srcs: ["linux_glibc_x86_64/bin/foo"],
+			},
+		},
+	}
+	`, map[string][]byte{
+		"libfoo.so": nil,
+		"foo":       nil,
+	})
+
+	fooRule := ctx.ModuleForTests("foo", "linux_glibc_x86_64").Rule("Symlink")
+	assertString(t, fooRule.Output.String(),
+		filepath.Join(buildDir, ".intermediates/foo/linux_glibc_x86_64/foo"))
+	assertString(t, fooRule.Args["fromPath"], "$$PWD/linux_glibc_x86_64/bin/foo")
+
+	var libfooDep android.Path
+	for _, dep := range fooRule.Implicits {
+		if dep.Base() == "libfoo.so" {
+			libfooDep = dep
+			break
+		}
+	}
+	assertString(t, libfooDep.String(),
+		filepath.Join(buildDir, ".intermediates/libfoo/linux_glibc_x86_64_shared/libfoo.so"))
+}