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/apex/apex.go b/apex/apex.go
index 1d50cee..b324644 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -492,6 +492,19 @@
if !cc.Arch().Native {
dirInApex = filepath.Join(dirInApex, cc.Arch().ArchType.String())
}
+ switch cc.Name() {
+ case "libc", "libm", "libdl":
+ // Special case for bionic libs. This is to prevent the bionic libs
+ // from being included in the search path /apex/com.android.apex/lib.
+ // This exclusion is required because bionic libs in the runtime APEX
+ // are available via the legacy paths /system/lib/libc.so, etc. By the
+ // init process, the bionic libs in the APEX are bind-mounted to the
+ // legacy paths and thus will be loaded into the default linker namespace.
+ // If the bionic libs are directly in /apex/com.android.apex/lib then
+ // the same libs will be again loaded to the runtime linker namespace,
+ // which will result double loading of bionic libs that isn't supported.
+ dirInApex = filepath.Join(dirInApex, "bionic")
+ }
fileToCopy = cc.OutputFile().Path()
return