From 4629f7c886319be116eab6d0d6bcdfa6872d7ac7 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 14 Apr 2023 17:36:51 -0700 Subject: [PATCH] Pass -Wl,--as-needed when linking Rust binaries. aosp/2518976 revealed a pre-existing bug, which was that some Rust test targets did not have all of their shared library dependencies packaged in the host-unit-tests.zip file. Conveniently enough, these targets did not actually depend on any of the symbols in the missing shared libraries, so their DT_NEEDED entries were being removed by the --as-needed flag being passed to the linker by rustc. This flag was dropped when we switched to running the link command directly, causing the DT_NEEDED entries to reappear and leading to runtime failures for these test binaries. Although we could fix the issue that prevented these (unused) dependencies from being packaged, there wouldn't be much point in doing so because we already know that they aren't needed. So for now, let's return to the status quo and keep passing --as-needed to the linker. Bug: 278168700 Change-Id: Iae103803983240fa14cdbc2ff0d8ffb4329c6024 --- rust/config/global.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/config/global.go b/rust/config/global.go index 88949386c..2d1f0c1f9 100644 --- a/rust/config/global.go +++ b/rust/config/global.go @@ -104,7 +104,7 @@ func init() { pctx.ImportAs("cc_config", "android/soong/cc/config") pctx.StaticVariable("RustLinker", "${cc_config.ClangBin}/clang++") - pctx.StaticVariable("RustLinkerArgs", "") + pctx.StaticVariable("RustLinkerArgs", "-Wl,--as-needed") pctx.StaticVariable("DeviceGlobalLinkFlags", strings.Join(deviceGlobalLinkFlags, " "))