Add $ORIGIN to rpath for cc_test modules

cc_test modules can use data_libs to put shared libraries alongside
the test.  Add $ORIGIN to rpath so they can load them as DT_NEEDED
libraries or with dlopen.

Test: treehugger
Change-Id: I4227d16ff80e70dfecb481a2de6dd15af66348bc
diff --git a/cc/test.go b/cc/test.go
index 3a1a3af..a96af31 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -359,6 +359,12 @@
 func (test *testBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags {
 	flags = test.binaryDecorator.linkerFlags(ctx, flags)
 	flags = test.testDecorator.linkerFlags(ctx, flags)
+
+	// Add a default rpath to allow tests to dlopen libraries specified in data_libs.
+	// Host modules already get an rpath specified in linker.go.
+	if !ctx.Host() {
+		flags.Global.LdFlags = append(flags.Global.LdFlags, `-Wl,-rpath,\$$ORIGIN`)
+	}
 	return flags
 }