From f1ff54a10b4abc248b0cfcc5d3c1ebbf534522c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thi=C3=A9baud=20Weksteen?= Date: Mon, 22 Mar 2021 14:24:54 +0100 Subject: [PATCH] rust: Drop libgcc dependency Rustc unstable option "link-native-libraries" is used to prevent the linkage of other libraries via the #[link] directive. Add a dependency to libclang_rt.builtins, similarly to cc. Bug: 141331117 Test: lunch aosp_crosshatch-userdebug; m Change-Id: I5c232291a5dd08a99e6a12a1295e30bb8e4fcaf1 --- rust/binary.go | 2 +- rust/bindgen.go | 2 +- rust/compiler.go | 8 ++++---- rust/config/global.go | 3 ++- rust/config/toolchain.go | 4 ++++ rust/library.go | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/rust/binary.go b/rust/binary.go index df489169b..dfe8744a1 100644 --- a/rust/binary.go +++ b/rust/binary.go @@ -87,7 +87,7 @@ func (binary *binaryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps { deps = binary.baseCompiler.compilerDeps(ctx, deps) if ctx.toolchain().Bionic() { - deps = bionicDeps(deps, Bool(binary.Properties.Static_executable)) + deps = bionicDeps(ctx, deps, Bool(binary.Properties.Static_executable)) if Bool(binary.Properties.Static_executable) { deps.CrtBegin = "crtbegin_static" } else { diff --git a/rust/bindgen.go b/rust/bindgen.go index db69e2337..bcc26b899 100644 --- a/rust/bindgen.go +++ b/rust/bindgen.go @@ -260,7 +260,7 @@ func NewRustBindgen(hod android.HostOrDeviceSupported) (*Module, *bindgenDecorat func (b *bindgenDecorator) SourceProviderDeps(ctx DepsContext, deps Deps) Deps { deps = b.BaseSourceProvider.SourceProviderDeps(ctx, deps) if ctx.toolchain().Bionic() { - deps = bionicDeps(deps, false) + deps = bionicDeps(ctx, deps, false) } deps.SharedLibs = append(deps.SharedLibs, b.ClangProperties.Shared_libs...) diff --git a/rust/compiler.go b/rust/compiler.go index 98ad7ad1b..200af9061 100644 --- a/rust/compiler.go +++ b/rust/compiler.go @@ -281,7 +281,7 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps { return deps } -func bionicDeps(deps Deps, static bool) Deps { +func bionicDeps(ctx DepsContext, deps Deps, static bool) Deps { bionicLibs := []string{} bionicLibs = append(bionicLibs, "liblog") bionicLibs = append(bionicLibs, "libc") @@ -294,9 +294,9 @@ func bionicDeps(deps Deps, static bool) Deps { deps.SharedLibs = append(deps.SharedLibs, bionicLibs...) } - //TODO(b/141331117) libstd requires libgcc on Android - deps.StaticLibs = append(deps.StaticLibs, "libgcc") - + if libRuntimeBuiltins := config.BuiltinsRuntimeLibrary(ctx.toolchain()); libRuntimeBuiltins != "" { + deps.StaticLibs = append(deps.StaticLibs, libRuntimeBuiltins) + } return deps } diff --git a/rust/config/global.go b/rust/config/global.go index 12f49728c..9208ddb69 100644 --- a/rust/config/global.go +++ b/rust/config/global.go @@ -53,6 +53,7 @@ var ( deviceGlobalRustFlags = []string{ "-C panic=abort", + "-Z link-native-libraries=no", } deviceGlobalLinkFlags = []string{ @@ -62,7 +63,7 @@ var ( // Override cc's --no-undefined-version to allow rustc's generated alloc functions "-Wl,--undefined-version", - "-Bdynamic", + "-Wl,-Bdynamic", "-nostdlib", "-Wl,--pack-dyn-relocs=android+relr", "-Wl,--use-android-relr-tags", diff --git a/rust/config/toolchain.go b/rust/config/toolchain.go index 9525c38aa..a769f121c 100644 --- a/rust/config/toolchain.go +++ b/rust/config/toolchain.go @@ -112,6 +112,10 @@ func (toolchainBase) LibclangRuntimeLibraryArch() string { return "" } +func BuiltinsRuntimeLibrary(t Toolchain) string { + return LibclangRuntimeLibrary(t, "builtins") +} + func LibFuzzerRuntimeLibrary(t Toolchain) string { return LibclangRuntimeLibrary(t, "fuzzer") } diff --git a/rust/library.go b/rust/library.go index 7ff13ec66..71fe1f538 100644 --- a/rust/library.go +++ b/rust/library.go @@ -404,7 +404,7 @@ func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps { deps = library.baseCompiler.compilerDeps(ctx, deps) if ctx.toolchain().Bionic() && (library.dylib() || library.shared()) { - deps = bionicDeps(deps, false) + deps = bionicDeps(ctx, deps, false) deps.CrtBegin = "crtbegin_so" deps.CrtEnd = "crtend_so" }