From b881e324d260a5e1884e8f96f8e70c431a4e6855 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 10 May 2024 13:24:17 -0700 Subject: [PATCH] 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 --- cc/test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cc/test.go b/cc/test.go index 3a1a3af44..a96af31bb 100644 --- a/cc/test.go +++ b/cc/test.go @@ -359,6 +359,12 @@ func (test *testBinary) linkerDeps(ctx DepsContext, deps Deps) Deps { 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 }