From d48fe734cd052d08be02d4d847438795cd63c894 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 23 Sep 2020 20:37:24 -0700 Subject: [PATCH 1/2] Fix prebuilt library stubs There were multiple stacked issues with prebuilt library stubs that cancelled eachother out. Prebuilts were never considered to be DirectlyInAnyApex by the AndroidMk logic to handle stubs libraries because it looked it up in the global list of modules in apexes using the name with the "prebuilt_" prefix. Fixing that to use ctx.BaseModuleName() exposed a second issue, that stubs variants for prebuilt libraries were never created, so there was no latest version to expose to Make. Making the *prebuiltLibraryLinker type work with all of the methods that handle stubs should really be done with an interface and methods implemented on *libraryDecorator, but that would also cause other types like that embed libraryDecorator to participate in stubs that may trigger more issues. I'd like to replace those methods anyways, so just manually handle *prebuiltLibraryLinker for now. Test: m checkbuild Change-Id: I1267ee01659ad9ab11d75318c6c6bdbf8f72a061 --- cc/androidmk.go | 4 ++-- cc/cc.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/cc/androidmk.go b/cc/androidmk.go index 4f149af85..d92fabc0d 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -33,7 +33,7 @@ var ( ) type AndroidMkContext interface { - Name() string + BaseModuleName() string Target() android.Target subAndroidMk(*android.AndroidMkEntries, interface{}) Arch() android.Arch @@ -278,7 +278,7 @@ func (library *libraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries }) } if len(library.Properties.Stubs.Versions) > 0 && - android.DirectlyInAnyApex(ctx, ctx.Name()) && !ctx.InRamdisk() && !ctx.InRecovery() && !ctx.UseVndk() && + android.DirectlyInAnyApex(ctx, ctx.BaseModuleName()) && !ctx.InRamdisk() && !ctx.InRecovery() && !ctx.UseVndk() && !ctx.static() { if library.buildStubs() && library.isLatestStubVersion() { // reference the latest version via its name without suffix when it is provided by apex diff --git a/cc/cc.go b/cc/cc.go index a813428f5..0718ee6e3 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -740,6 +740,9 @@ func (c *Module) StubsVersions() []string { if library, ok := c.linker.(*libraryDecorator); ok { return library.Properties.Stubs.Versions } + if library, ok := c.linker.(*prebuiltLibraryLinker); ok { + return library.Properties.Stubs.Versions + } } panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName())) } @@ -749,6 +752,9 @@ func (c *Module) CcLibrary() bool { if _, ok := c.linker.(*libraryDecorator); ok { return true } + if _, ok := c.linker.(*prebuiltLibraryLinker); ok { + return true + } } return false } @@ -774,6 +780,14 @@ func (c *Module) SetBuildStubs() { c.Properties.PreventInstall = true return } + if library, ok := c.linker.(*prebuiltLibraryLinker); ok { + library.MutatedProperties.BuildStubs = true + c.Properties.HideFromMake = true + c.sanitize = nil + c.stl = nil + c.Properties.PreventInstall = true + return + } if _, ok := c.linker.(*llndkStubDecorator); ok { c.Properties.HideFromMake = true return @@ -787,6 +801,9 @@ func (c *Module) BuildStubs() bool { if library, ok := c.linker.(*libraryDecorator); ok { return library.buildStubs() } + if library, ok := c.linker.(*prebuiltLibraryLinker); ok { + return library.buildStubs() + } } panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName())) } @@ -796,6 +813,10 @@ func (c *Module) SetAllStubsVersions(versions []string) { library.MutatedProperties.AllStubsVersions = versions return } + if library, ok := c.linker.(*prebuiltLibraryLinker); ok { + library.MutatedProperties.AllStubsVersions = versions + return + } if llndk, ok := c.linker.(*llndkStubDecorator); ok { llndk.libraryDecorator.MutatedProperties.AllStubsVersions = versions return @@ -806,6 +827,9 @@ func (c *Module) AllStubsVersions() []string { if library, ok := c.linker.(*libraryDecorator); ok { return library.MutatedProperties.AllStubsVersions } + if library, ok := c.linker.(*prebuiltLibraryLinker); ok { + return library.MutatedProperties.AllStubsVersions + } if llndk, ok := c.linker.(*llndkStubDecorator); ok { return llndk.libraryDecorator.MutatedProperties.AllStubsVersions } @@ -818,6 +842,10 @@ func (c *Module) SetStubsVersion(version string) { library.MutatedProperties.StubsVersion = version return } + if library, ok := c.linker.(*prebuiltLibraryLinker); ok { + library.MutatedProperties.StubsVersion = version + return + } if llndk, ok := c.linker.(*llndkStubDecorator); ok { llndk.libraryDecorator.MutatedProperties.StubsVersion = version return @@ -831,6 +859,9 @@ func (c *Module) StubsVersion() string { if library, ok := c.linker.(*libraryDecorator); ok { return library.MutatedProperties.StubsVersion } + if library, ok := c.linker.(*prebuiltLibraryLinker); ok { + return library.MutatedProperties.StubsVersion + } if llndk, ok := c.linker.(*llndkStubDecorator); ok { return llndk.libraryDecorator.MutatedProperties.StubsVersion } @@ -1073,6 +1104,8 @@ func (c *Module) getVndkExtendsModuleName() string { func (c *Module) IsStubs() bool { if library, ok := c.linker.(*libraryDecorator); ok { return library.buildStubs() + } else if library, ok := c.linker.(*prebuiltLibraryLinker); ok { + return library.buildStubs() } else if _, ok := c.linker.(*llndkStubDecorator); ok { return true } @@ -1930,6 +1963,11 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { buildStubs = true } } + if library, ok := c.linker.(*prebuiltLibraryLinker); ok { + if library.buildStubs() { + buildStubs = true + } + } } rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string { From e7257d2019602ad9f810f1da31fc4f6ecd7db384 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 24 Sep 2020 09:56:18 -0700 Subject: [PATCH 2/2] Add version dependencies to sanitizer runtime dependencies The hwasan runtime has stubs, make the function to add all version variants of a shared library available to the sanitizer mutator. Test: m checkbuild Change-Id: Ie4124022140f8520834d7bf7b59f0499cd381083 --- cc/cc.go | 72 ++++++++++++++++++++++++++++++-------------------- cc/sanitize.go | 2 +- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/cc/cc.go b/cc/cc.go index 0718ee6e3..caefea4f6 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -1863,6 +1863,42 @@ func GetCrtVariations(ctx android.BottomUpMutatorContext, } } +func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext, + variations []blueprint.Variation, depTag libraryDependencyTag, name, version string, far bool) { + + variations = append([]blueprint.Variation(nil), variations...) + + if version != "" && VersionVariantAvailable(c) { + // Version is explicitly specified. i.e. libFoo#30 + variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version}) + depTag.explicitlyVersioned = true + } + var deps []blueprint.Module + if far { + deps = ctx.AddFarVariationDependencies(variations, depTag, name) + } else { + deps = ctx.AddVariationDependencies(variations, depTag, name) + } + + // If the version is not specified, add dependency to all stubs libraries. + // The stubs library will be used when the depending module is built for APEX and + // the dependent module is not in the same APEX. + if version == "" && VersionVariantAvailable(c) { + if dep, ok := deps[0].(*Module); ok { + for _, ver := range dep.AllStubsVersions() { + // Note that depTag.ExplicitlyVersioned is false in this case. + versionVariations := append(variations, + blueprint.Variation{Mutator: "version", Variation: ver}) + if far { + ctx.AddFarVariationDependencies(versionVariations, depTag, name) + } else { + ctx.AddVariationDependencies(versionVariations, depTag, name) + } + } + } + } +} + func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { if !c.Enabled() { return @@ -2056,32 +2092,6 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)) } - addSharedLibDependencies := func(depTag libraryDependencyTag, name string, version string) { - var variations []blueprint.Variation - variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"}) - if version != "" && VersionVariantAvailable(c) { - // Version is explicitly specified. i.e. libFoo#30 - variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version}) - depTag.explicitlyVersioned = true - } - deps := actx.AddVariationDependencies(variations, depTag, name) - - // If the version is not specified, add dependency to all stubs libraries. - // The stubs library will be used when the depending module is built for APEX and - // the dependent module is not in the same APEX. - if version == "" && VersionVariantAvailable(c) { - if dep, ok := deps[0].(*Module); ok { - for _, ver := range dep.AllStubsVersions() { - // Note that depTag.ExplicitlyVersioned is false in this case. - ctx.AddVariationDependencies([]blueprint.Variation{ - {Mutator: "link", Variation: "shared"}, - {Mutator: "version", Variation: ver}, - }, depTag, name) - } - } - } - } - // shared lib names without the #version suffix var sharedLibNames []string @@ -2098,7 +2108,10 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { name, version := StubsLibNameAndVersion(lib) sharedLibNames = append(sharedLibNames, name) - addSharedLibDependencies(depTag, name, version) + variations := []blueprint.Variation{ + {Mutator: "link", Variation: "shared"}, + } + c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, name, version, false) } for _, lib := range deps.LateSharedLibs { @@ -2109,7 +2122,10 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { continue } depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency} - addSharedLibDependencies(depTag, lib, "") + variations := []blueprint.Variation{ + {Mutator: "link", Variation: "shared"}, + } + c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, lib, "", false) } actx.AddVariationDependencies([]blueprint.Variation{ diff --git a/cc/sanitize.go b/cc/sanitize.go index 8c3e97af3..43198c16e 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -1040,7 +1040,7 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) { if c.Device() { variations = append(variations, c.ImageVariation()) } - mctx.AddFarVariationDependencies(variations, depTag, runtimeLibrary) + c.addSharedLibDependenciesWithVersions(mctx, variations, depTag, runtimeLibrary, "", true) } // static lib does not have dependency to the runtime library. The // dependency will be added to the executables or shared libs using