Add stubs variants for bionic libs

Bionic libs are part of the runtime APEX (com.android.runtime). In order
to be able to update the runtime APEX independetly from the platform, we
have to prevent things outside of the APEX from using bionic symbols
that are not guaranteed to be stable. Otherwise, platform could break
when a symbol is removed from the libs via the APEX update.

To achive this goal, this change adds stubs variant to the bionic libs.
With this, things outside of the runtime APEX (i.e. other APEXes and the
platform) are built with the stubs variants that provide only the
symbols that are guaranteed to be stable.

The set of symbols are basically the same as the symbols available to
NDK clients. However, there are a few additional symbols that are not
available for NDK but should be made available for platform components.
They are marked with "# apex" tag. Symbols with that tag are not exposed
to apps (via NDK stubs) or vendors (via LLNDK stubs).

Note that the stubs is a build-time only artifact. It is used just to
break the build when private symbols are used outside of the runtime
APEX. At runtime, the real library in the APEX is used.

Bug: 120266448
Test: m
Test: m bionic-unit-tests
Change-Id: I7b8d75830c81d7d7d54e2fca21a85b3417531b47
diff --git a/libc/Android.bp b/libc/Android.bp
index 3e607f6..4f371af 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -1605,6 +1605,11 @@
             version_script: ":libc.x86_64.map",
         },
     },
+
+    stubs: {
+        symbol_file: "libc.map.txt",
+        versions: ["10000"],
+    },
 }
 
 genrule {
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index 4b8463f..e8809df 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -1450,16 +1450,36 @@
     android_fdsan_close_with_tag;
     android_fdsan_create_owner_tag;
     android_fdsan_exchange_owner_tag;
+    android_fdsan_get_error_level;
     android_fdsan_get_owner_tag;
     android_fdsan_get_tag_type;
     android_fdsan_get_tag_value;
-    android_fdsan_get_error_level;
     android_fdsan_set_error_level;
     android_get_device_api_level;
     getloadavg;
     pthread_sigqueue;
     reallocarray;
     timespec_get;
+
+    # Used by libselinux
+    __system_properties_init; # apex
+
+    # Used by libmemunreachable
+    malloc_backtrace; # apex
+    malloc_disable; # apex
+    malloc_enable; # apex
+    malloc_iterate; # apex
+
+    # Used by libmediautils
+    write_malloc_leak_info; # apex
+    free_malloc_leak_info; # apex
+    get_malloc_leak_info; # apex
+
+    # Used by libandroid_net
+    android_getaddrinfofornet; # apex
+
+    # Used by libandroid_runtime
+    gMallocLeakZygoteChild; # apex
 } LIBC_P;
 
 LIBC_PRIVATE {
@@ -1639,7 +1659,6 @@
     _Unwind_VRS_Get; # arm
     _Unwind_VRS_Pop; # arm
     _Unwind_VRS_Set; # arm
-    android_getaddrinfofornet;
     android_getaddrinfofornetcontext;
     android_gethostbyaddrfornet;
     android_gethostbyaddrfornetcontext;
@@ -1654,12 +1673,9 @@
     dlmalloc_inspect_all; # arm x86 mips
     dlmalloc_trim; # arm x86 mips
     dlmalloc_usable_size; # arm x86 mips
-    free_malloc_leak_info;
     ftime; # arm x86 mips
-    get_malloc_leak_info;
     getdents; # arm x86 mips
     getdtablesize; # arm x86 mips
-    gMallocLeakZygoteChild;
     index; # arm x86 mips
     issetugid; # arm x86 mips
     memswap; # arm x86 mips
@@ -1677,7 +1693,6 @@
     tkill; # arm x86 mips
     wait3; # arm x86 mips
     wcswcs; # arm x86 mips
-    write_malloc_leak_info;
 } LIBC_Q;
 
 LIBC_DEPRECATED {
@@ -1687,9 +1702,8 @@
 
 LIBC_PLATFORM {
   global:
-    __system_properties_init;
-    __system_property_area__; # var
     __system_property_add;
+    __system_property_area__; # var
     __system_property_area_init;
     __system_property_set_filename;
     __system_property_update;
@@ -1697,8 +1711,4 @@
     android_net_res_stats_get_info_for_net;
     android_net_res_stats_aggregate;
     android_net_res_stats_get_usable_servers;
-    malloc_backtrace;
-    malloc_disable;
-    malloc_enable;
-    malloc_iterate;
 } LIBC_Q;
diff --git a/libdl/Android.bp b/libdl/Android.bp
index c4078a0..262da6c 100644
--- a/libdl/Android.bp
+++ b/libdl/Android.bp
@@ -100,6 +100,11 @@
     sanitize: {
         never: true,
     },
+
+    stubs: {
+        symbol_file: "libdl.map.txt",
+        versions: ["10000"],
+    },
 }
 
 ndk_library {
diff --git a/libdl/libdl.map.txt b/libdl/libdl.map.txt
index c5d1be4..1514827 100644
--- a/libdl/libdl.map.txt
+++ b/libdl/libdl.map.txt
@@ -41,15 +41,19 @@
     __cfi_slowpath_diag;
 } LIBC_N;
 
+LIBC_Q { # introduced=29
+  global:
+    android_create_namespace; # apex
+    android_dlwarning; # apex
+    android_get_LD_LIBRARY_PATH; # apex
+    android_get_exported_namespace; # apex
+    android_init_anonymous_namespace; # apex
+    android_link_namespaces; # apex
+    android_set_application_target_sdk_version; # apex
+} LIBC_OMR1;
+
 LIBC_PLATFORM {
   global:
     __cfi_init;
-    android_dlwarning;
-    android_set_application_target_sdk_version;
-    android_get_LD_LIBRARY_PATH;
     android_update_LD_LIBRARY_PATH;
-    android_init_anonymous_namespace;
-    android_create_namespace;
-    android_link_namespaces;
-    android_get_exported_namespace;
-} LIBC_OMR1;
+} LIBC_Q;
diff --git a/libm/Android.bp b/libm/Android.bp
index 2463dfb..28cf1fd 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -510,6 +510,11 @@
 
     // TODO(ivanlozano): Remove after b/118321713
     xom: false,
+
+    stubs: {
+        symbol_file: "libm.map.txt",
+        versions: ["10000"],
+    },
 }
 
 ndk_library {
diff --git a/tests/Android.bp b/tests/Android.bp
index 899fc66..90167d1 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -42,6 +42,7 @@
     sanitize: {
         never: true,
     },
+    bootstrap: true,
 }
 
 // -----------------------------------------------------------------------------