From fe605e14ee71dae43d384968fffd3aea7ac53bba Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Sun, 23 Jan 2022 20:46:16 -0800 Subject: [PATCH] Support multiple crtbegin and crtend dependencies Musl libc with an embedded linker uses multiple crtbegin dependencies, convert rust's CrtBegin and CrtEnd to lists. Bug: 190084016 Test: m USE_HOST_MUSL=true host-native Change-Id: Ie843801e87b1f38ace84502d9e4f938a92ec1fa2 --- rust/binary.go | 6 +++--- rust/builder.go | 9 ++++----- rust/library.go | 4 ++-- rust/rust.go | 18 +++++++++--------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/rust/binary.go b/rust/binary.go index db91ccb9a..5d9b0a67b 100644 --- a/rust/binary.go +++ b/rust/binary.go @@ -95,11 +95,11 @@ func (binary *binaryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps { if ctx.toolchain().Bionic() { deps = bionicDeps(ctx, deps, Bool(binary.Properties.Static_executable)) if Bool(binary.Properties.Static_executable) { - deps.CrtBegin = "crtbegin_static" + deps.CrtBegin = []string{"crtbegin_static"} } else { - deps.CrtBegin = "crtbegin_dynamic" + deps.CrtBegin = []string{"libc_musl_crtbegin_dynamic"} } - deps.CrtEnd = "crtend_android" + deps.CrtEnd = []string{"libc_musl_crtend"} } return deps diff --git a/rust/builder.go b/rust/builder.go index a7efc282a..cfb9fe1e9 100644 --- a/rust/builder.go +++ b/rust/builder.go @@ -246,9 +246,8 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl implicits = append(implicits, deps.SharedLibDeps...) implicits = append(implicits, deps.srcProviderFiles...) - if deps.CrtBegin.Valid() { - implicits = append(implicits, deps.CrtBegin.Path(), deps.CrtEnd.Path()) - } + implicits = append(implicits, deps.CrtBegin...) + implicits = append(implicits, deps.CrtEnd...) if len(deps.SrcDeps) > 0 { moduleGenDir := ctx.RustModule().compiler.CargoOutDir() @@ -318,8 +317,8 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl "rustcFlags": strings.Join(rustcFlags, " "), "linkFlags": strings.Join(linkFlags, " "), "libFlags": strings.Join(libFlags, " "), - "crtBegin": deps.CrtBegin.String(), - "crtEnd": deps.CrtEnd.String(), + "crtBegin": strings.Join(deps.CrtBegin.Strings(), " "), + "crtEnd": strings.Join(deps.CrtEnd.Strings(), " "), "envVars": strings.Join(envVars, " "), }, }) diff --git a/rust/library.go b/rust/library.go index bb2e83fdb..9d79c53f2 100644 --- a/rust/library.go +++ b/rust/library.go @@ -428,8 +428,8 @@ func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps { if ctx.toolchain().Bionic() && (library.dylib() || library.shared()) { deps = bionicDeps(ctx, deps, false) - deps.CrtBegin = "crtbegin_so" - deps.CrtEnd = "crtend_so" + deps.CrtBegin = []string{"crtbegin_so"} + deps.CrtEnd = []string{"crtend_so"} } return deps diff --git a/rust/rust.go b/rust/rust.go index cba92c33f..ee573fa43 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -393,7 +393,7 @@ type Deps struct { DataLibs []string DataBins []string - CrtBegin, CrtEnd string + CrtBegin, CrtEnd []string } type PathDeps struct { @@ -419,8 +419,8 @@ type PathDeps struct { depGeneratedHeaders android.Paths depSystemIncludePaths android.Paths - CrtBegin android.OptionalPath - CrtEnd android.OptionalPath + CrtBegin android.Paths + CrtEnd android.Paths // Paths to generated source files SrcDeps android.Paths @@ -1214,9 +1214,9 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) case depTag == cc.CrtBeginDepTag: - depPaths.CrtBegin = linkObject + depPaths.CrtBegin = append(depPaths.CrtBegin, linkObject.Path()) case depTag == cc.CrtEndDepTag: - depPaths.CrtEnd = linkObject + depPaths.CrtEnd = append(depPaths.CrtEnd, linkObject.Path()) } // Make sure these dependencies are propagated @@ -1422,13 +1422,13 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...) crtVariations := cc.GetCrtVariations(ctx, mod) - if deps.CrtBegin != "" { + for _, crt := range deps.CrtBegin { actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, - cc.RewriteSnapshotLib(deps.CrtBegin, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects)) + cc.RewriteSnapshotLib(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects)) } - if deps.CrtEnd != "" { + for _, crt := range deps.CrtEnd { actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, - cc.RewriteSnapshotLib(deps.CrtEnd, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects)) + cc.RewriteSnapshotLib(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects)) } if mod.sourceProvider != nil {