Support multiple CrtBegin and CrtEnd files

Host bionic will use multiple files for CrtBegin, make CrtBegin and
CrtEnd Paths instead of OptionalPath.

Test: go test ./build/soong/cc/...
Change-Id: Ie2e954cd87808a903617696da443009f6173e312
This commit is contained in:
Colin Cross 2021-06-11 18:00:04 -07:00
parent 009f3df380
commit c465efd5d4
4 changed files with 20 additions and 21 deletions

View file

@ -149,11 +149,11 @@ func (binary *binaryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
if ctx.toolchain().Bionic() {
if !Bool(binary.baseLinker.Properties.Nocrt) {
if binary.static() {
deps.CrtBegin = "crtbegin_static"
deps.CrtBegin = []string{"crtbegin_static"}
} else {
deps.CrtBegin = "crtbegin_dynamic"
deps.CrtBegin = []string{"crtbegin_dynamic"}
}
deps.CrtEnd = "crtend_android"
deps.CrtEnd = []string{"crtend_android"}
}
if binary.static() {

View file

@ -730,9 +730,9 @@ func transformObjToStaticLib(ctx android.ModuleContext,
// Generate a rule for compiling multiple .o files, plus static libraries, whole static libraries,
// and shared libraries, to a shared library (.so) or dynamic executable
func transformObjToDynamicBinary(ctx android.ModuleContext,
objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps android.Paths,
crtBegin, crtEnd android.OptionalPath, groupLate bool, flags builderFlags,
outputFile android.WritablePath, implicitOutputs android.WritablePaths, validations android.WritablePaths) {
objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps, crtBegin, crtEnd android.Paths,
groupLate bool, flags builderFlags, outputFile android.WritablePath,
implicitOutputs android.WritablePaths, validations android.WritablePaths) {
ldCmd := "${config.ClangBin}/clang++"
@ -779,18 +779,17 @@ func transformObjToDynamicBinary(ctx android.ModuleContext,
deps = append(deps, staticLibs...)
deps = append(deps, lateStaticLibs...)
deps = append(deps, wholeStaticLibs...)
if crtBegin.Valid() {
deps = append(deps, crtBegin.Path(), crtEnd.Path())
}
deps = append(deps, crtBegin...)
deps = append(deps, crtEnd...)
rule := ld
args := map[string]string{
"ldCmd": ldCmd,
"crtBegin": crtBegin.String(),
"crtBegin": strings.Join(crtBegin.Strings(), " "),
"libFlags": strings.Join(libFlagsList, " "),
"extraLibFlags": flags.extraLibFlags,
"ldFlags": flags.globalLdFlags + " " + flags.localLdFlags,
"crtEnd": crtEnd.String(),
"crtEnd": strings.Join(crtEnd.Strings(), " "),
}
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_CXX_LINKS") {
rule = ldRE

View file

@ -126,7 +126,7 @@ type Deps struct {
ReexportGeneratedHeaders []string
CrtBegin, CrtEnd string
CrtBegin, CrtEnd []string
// Used for host bionic
LinkerFlagsFile string
@ -177,7 +177,7 @@ type PathDeps struct {
ReexportedDeps android.Paths
// Paths to crt*.o files
CrtBegin, CrtEnd android.OptionalPath
CrtBegin, CrtEnd android.Paths
// Path to the file container flags to use with the linker
LinkerFlagsFile android.OptionalPath
@ -2246,13 +2246,13 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
crtVariations := GetCrtVariations(ctx, c)
actx.AddVariationDependencies(crtVariations, objDepTag, deps.ObjFiles...)
if deps.CrtBegin != "" {
for _, crt := range deps.CrtBegin {
actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
RewriteSnapshotLib(deps.CrtBegin, GetSnapshot(c, &snapshotInfo, actx).Objects))
RewriteSnapshotLib(crt, GetSnapshot(c, &snapshotInfo, actx).Objects))
}
if deps.CrtEnd != "" {
for _, crt := range deps.CrtEnd {
actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
RewriteSnapshotLib(deps.CrtEnd, GetSnapshot(c, &snapshotInfo, actx).Objects))
RewriteSnapshotLib(crt, GetSnapshot(c, &snapshotInfo, actx).Objects))
}
if deps.LinkerFlagsFile != "" {
actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
@ -2878,9 +2878,9 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
case objDepTag:
depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
case CrtBeginDepTag:
depPaths.CrtBegin = linkFile
depPaths.CrtBegin = append(depPaths.CrtBegin, linkFile.Path())
case CrtEndDepTag:
depPaths.CrtEnd = linkFile
depPaths.CrtEnd = append(depPaths.CrtEnd, linkFile.Path())
case dynamicLinkerDepTag:
depPaths.DynamicLinker = linkFile
}

View file

@ -1112,8 +1112,8 @@ func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, library.StaticProperties.Static.Export_static_lib_headers...)
} else if library.shared() {
if ctx.toolchain().Bionic() && !Bool(library.baseLinker.Properties.Nocrt) {
deps.CrtBegin = "crtbegin_so"
deps.CrtEnd = "crtend_so"
deps.CrtBegin = []string{"crtbegin_so"}
deps.CrtEnd = []string{"crtend_so"}
}
deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.SharedProperties.Shared.Whole_static_libs...)
deps.StaticLibs = append(deps.StaticLibs, library.SharedProperties.Shared.Static_libs...)