From 85707de8c1fe31c180e9fa178a8d31c4a1051b9c Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Fri, 1 Dec 2023 14:21:13 +0900 Subject: [PATCH 1/2] Add cc_library.target.vendor.no_stubs This is to handle libz special case. libz has stubs but not an LLNDK. So, libz.vendor should be treated as non-stub-providing libraries and Vendor APEX should bundle it if it's used by its contents. libz will set no_stubs for vendor/product variants. Bug: 313806237 Test: go tests ./apex/... Change-Id: I10759d7073838909126f8bfe87654f11aa02fd32 --- apex/apex_test.go | 66 +++++++++++++++++++++++++++++++++++++++++++++++ cc/image.go | 10 +++++++ cc/library.go | 7 +++++ 3 files changed, 83 insertions(+) diff --git a/apex/apex_test.go b/apex/apex_test.go index af643a0a0..ab0c130a9 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -4705,6 +4705,72 @@ func TestTestApex(t *testing.T) { ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") } +func TestLibzVendorIsntStable(t *testing.T) { + ctx := testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + updatable: false, + binaries: ["mybin"], + } + apex { + name: "myvendorapex", + key: "myapex.key", + file_contexts: "myvendorapex_file_contexts", + vendor: true, + updatable: false, + binaries: ["mybin"], + } + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + cc_binary { + name: "mybin", + vendor_available: true, + system_shared_libs: [], + stl: "none", + shared_libs: ["libz"], + apex_available: ["//apex_available:anyapex"], + } + cc_library { + name: "libz", + vendor_available: true, + system_shared_libs: [], + stl: "none", + stubs: { + versions: ["28", "30"], + }, + target: { + vendor: { + no_stubs: true, + }, + }, + } + `, withFiles(map[string][]byte{ + "myvendorapex_file_contexts": nil, + })) + + // libz provides stubs for core variant. + { + ensureExactContents(t, ctx, "myapex", "android_common_myapex", []string{ + "bin/mybin", + }) + apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexManifestRule") + android.AssertStringEquals(t, "should require libz", apexManifestRule.Args["requireNativeLibs"], "libz.so") + } + // libz doesn't provide stubs for vendor variant. + { + ensureExactContents(t, ctx, "myvendorapex", "android_common_myvendorapex", []string{ + "bin/mybin", + "lib64/libz.so", + }) + apexManifestRule := ctx.ModuleForTests("myvendorapex", "android_common_myvendorapex").Rule("apexManifestRule") + android.AssertStringEquals(t, "should not require libz", apexManifestRule.Args["requireNativeLibs"], "") + } +} + func TestApexWithTarget(t *testing.T) { ctx := testApex(t, ` apex { diff --git a/cc/image.go b/cc/image.go index 239f1db37..4f36111ec 100644 --- a/cc/image.go +++ b/cc/image.go @@ -23,6 +23,8 @@ import ( "android/soong/android" "android/soong/snapshot" + + "github.com/google/blueprint/proptools" ) var _ android.ImageInterface = (*Module)(nil) @@ -622,6 +624,10 @@ func squashVendorSrcs(m *Module) { lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...) + + if lib.Properties.Target.Vendor.No_stubs { + proptools.Clear(&lib.Properties.Stubs) + } } } @@ -635,6 +641,10 @@ func squashProductSrcs(m *Module) { lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...) + + if lib.Properties.Target.Product.No_stubs { + proptools.Clear(&lib.Properties.Stubs) + } } } diff --git a/cc/library.go b/cc/library.go index d22bcec2d..719455c06 100644 --- a/cc/library.go +++ b/cc/library.go @@ -107,6 +107,13 @@ type LibraryProperties struct { Suffix *string `android:"arch_variant"` Header_abi_checker headerAbiCheckerProperties + + // Disable stubs for vendor/product variants + // This is a workaround to keep `stubs` only for "core" variant (not product/vendor). + // It would be nice if we could put `stubs` into a `target: { core: {} }` + // block but it's not supported in soong yet. This could be removed/simplified once we have + // a better syntax. + No_stubs bool } Platform struct { From 9582159c4d07fa1c277e4592f9a20143773693c0 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Fri, 1 Dec 2023 16:33:30 +0900 Subject: [PATCH 2/2] Generate vendor specific STUB_LIBRARIES When generating vendor/etc/linker.config.pb, STUB_LIBRARIES was used. Because it lists *all* libraries with stubs regardless of its install location (vendor or system), using it for vendor linker.config.pb doesn't make sense. Instead, use vendor-specific STUB_LIBRARIES, which is named SOONG_STUB_VENDOR_LIBRARIES. Bug: 313806237 Test: m (aosp_cf_x86_64_phone) Test: $OUT/vendor/etc/linker.config.pb not listing libz.so Change-Id: Icd0aaf92d9630c07f58c4739a9f0ac713516db43 --- cc/stub_library.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cc/stub_library.go b/cc/stub_library.go index 3a6d0aeaa..47c6cb9a1 100644 --- a/cc/stub_library.go +++ b/cc/stub_library.go @@ -27,7 +27,8 @@ func init() { } type stubLibraries struct { - stubLibraryMap map[string]bool + stubLibraryMap map[string]bool + stubVendorLibraryMap map[string]bool apiListCoverageXmlPaths []string } @@ -54,6 +55,9 @@ func (s *stubLibraries) GenerateBuildActions(ctx android.SingletonContext) { if IsStubTarget(m) { if name := getInstalledFileName(m); name != "" { s.stubLibraryMap[name] = true + if m.InVendor() { + s.stubVendorLibraryMap[name] = true + } } } if m.library != nil { @@ -67,13 +71,15 @@ func (s *stubLibraries) GenerateBuildActions(ctx android.SingletonContext) { func stubLibrariesSingleton() android.Singleton { return &stubLibraries{ - stubLibraryMap: make(map[string]bool), + stubLibraryMap: make(map[string]bool), + stubVendorLibraryMap: make(map[string]bool), } } func (s *stubLibraries) MakeVars(ctx android.MakeVarsContext) { // Convert stub library file names into Makefile variable. ctx.Strict("STUB_LIBRARIES", strings.Join(android.SortedKeys(s.stubLibraryMap), " ")) + ctx.Strict("SOONG_STUB_VENDOR_LIBRARIES", strings.Join(android.SortedKeys(s.stubVendorLibraryMap), " ")) // Export the list of API XML files to Make. sort.Strings(s.apiListCoverageXmlPaths)