Rename non-stubs variant of a lib if it is included in APEX
If a lib is directly included in an APEX (via native_shared_libs
property) and the lib has stubs (via stubs.versions property), then the
ordinary non-stubs variant of the library is renamed to
<libname>.bootstrap in the makefile. At the same time, the stubs variant
of the lib becomes visible and it's name is <libname>.
This ensures that modules in Android.mk build against the stubs
variant thus preventing them from using private APIs in the lib.
The non-stubs variant, however, is used if the module explicitly has
set the new 'bootstrap' property to true. This is useful for building
some early binaries (such as init and vold) which need to run before
APEXes are activated. Since they can't use the bionic libs from the
runtime APEX, they should use the bionic libs left in the system
partition which is called the boostrap bionic.
Bug: 120266448
Test: m
Test: m with https://android-review.googlesource.com/c/platform/bionic/+/849044
Change-Id: I882b8aeb5b29460f07b4424e4f8eb844d6c9a9b0
diff --git a/cc/androidmk.go b/cc/androidmk.go
index 82feec8..7844756 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -29,9 +29,12 @@
)
type AndroidMkContext interface {
+ Name() string
Target() android.Target
subAndroidMk(*android.AndroidMkData, interface{})
useVndk() bool
+ static() bool
+ inRecovery() bool
}
type subAndroidMkProvider interface {
@@ -59,8 +62,12 @@
ret := android.AndroidMkData{
OutputFile: c.outputFile,
- Required: append(c.Properties.AndroidMkRuntimeLibs, c.Properties.ApexesProvidingSharedLibs...),
- Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
+ // TODO(jiyong): add the APEXes providing shared libs to the required modules
+ // Currently, adding c.Properties.ApexesProvidingSharedLibs is causing multiple
+ // runtime APEXes (com.android.runtime.debug|release) to be installed. And this
+ // is breaking some older devices (like marlin) where system.img is small.
+ Required: c.Properties.AndroidMkRuntimeLibs,
+ Include: "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
Extra: []android.AndroidMkExtraFunc{
func(w io.Writer, outputFile android.Path) {
@@ -172,13 +179,23 @@
}
})
- if library.shared() {
+ if library.shared() && !library.buildStubs() {
ctx.subAndroidMk(ret, library.baseInstaller)
} else {
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
+ if library.buildStubs() {
+ fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
+ }
})
}
+
+ if len(library.Properties.Stubs.Versions) > 0 && android.DirectlyInAnyApex(ctx.Name()) &&
+ !ctx.inRecovery() && !ctx.useVndk() && !ctx.static() {
+ if !library.buildStubs() {
+ ret.SubName = ".bootstrap"
+ }
+ }
}
func (object *objectLinker) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
diff --git a/cc/cc.go b/cc/cc.go
index ce28a3b..85e3a67 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -201,6 +201,10 @@
Recovery_available *bool
InRecovery bool `blueprint:"mutated"`
+
+ // Allows this module to use non-APEX version of libraries. Useful
+ // for building binaries that are started before APEXes are activated.
+ Bootstrap *bool
}
type VendorProperties struct {
@@ -250,6 +254,8 @@
isPgoCompile() bool
useClangLld(actx ModuleContext) bool
isApex() bool
+ hasStubsVariants() bool
+ isStubs() bool
}
type ModuleContext interface {
@@ -676,6 +682,14 @@
return ctx.mod.ApexName() != ""
}
+func (ctx *moduleContextImpl) hasStubsVariants() bool {
+ return ctx.mod.HasStubsVariants()
+}
+
+func (ctx *moduleContextImpl) isStubs() bool {
+ return ctx.mod.IsStubs()
+}
+
func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
return &Module{
hod: hod,
@@ -855,6 +869,18 @@
return
}
c.outputFile = android.OptionalPathForPath(outputFile)
+
+ // If a lib is directly included in any of the APEXes, unhide the stubs
+ // variant having the latest version gets visible to make. In addition,
+ // the non-stubs variant is renamed to <libname>.bootstrap. This is to
+ // force anything in the make world to link against the stubs library.
+ // (unless it is explicitly referenced via .bootstrap suffix or the
+ // module is marked with 'bootstrap: true').
+ if c.HasStubsVariants() && android.DirectlyInAnyApex(ctx.baseModuleName()) &&
+ !c.inRecovery() && !c.useVndk() && !c.static() && c.IsStubs() {
+ c.Properties.HideFromMake = false // unhide
+ // Note: this is still non-installable
+ }
}
if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
@@ -1446,8 +1472,8 @@
// If not building for APEX, use stubs only when it is from
// an APEX (and not from platform)
useThisDep = (depInPlatform != depIsStubs)
- if c.inRecovery() {
- // However, for recovery modules, since there is no APEX there,
+ if c.inRecovery() || Bool(c.Properties.Bootstrap) {
+ // However, for recovery or bootstrap modules,
// always link to non-stub variant
useThisDep = !depIsStubs
}