OSDN Git Service

Link to system namespace using stub libraries
authorKiyoung Kim <kiyoungkim@google.com>
Mon, 13 Jan 2020 02:44:05 +0000 (11:44 +0900)
committerKiyoung Kim <kiyoungkim@google.com>
Tue, 28 Jan 2020 06:29:45 +0000 (15:29 +0900)
As stub libraries list is generated, linkerconfig can use this to
generalize list of libraries linked to system namespace from other
(usually APEX) libraries.

Bug: 147210213
Test: m -j passed && Cuttlefish succeeded to boot
Change-Id: I350390a023c0d186da11844152b51b06ace60e8a

contents/common/system_links.cc
contents/namespace/conscrypt.cc
contents/namespace/cronet.cc
contents/namespace/media.cc
contents/namespace/neuralnetworks.cc
contents/namespace/resolv.cc
contents/namespace/runtime.cc
contents/tests/backward_compatibility/testbase.h
contents/tests/configuration/include/mockenv.h
generator/variableloader.cc

index 0c00af3..ecca2e4 100644 (file)
  * limitations under the License.
  */
 
-#include "linkerconfig/common.h"
-
 #include <string>
 
+#include "linkerconfig/common.h"
 #include "linkerconfig/context.h"
 #include "linkerconfig/section.h"
 
@@ -33,11 +32,7 @@ void AddStandardSystemLinks(const Context& ctx, Section* section) {
   section->ForEachNamespaces([system_ns_name](Namespace& ns) {
     if (ns.GetName() != system_ns_name) {
       ns.GetLink(system_ns_name)
-          .AddSharedLib({"libc.so",
-                         "libm.so",
-                         "libdl.so",
-                         "liblog.so",
-                         "@{SANITIZER_RUNTIME_LIBRARIES}"});
+          .AddSharedLib("@{STUB_LIBRARIES}", "@{SANITIZER_RUNTIME_LIBRARIES}");
     }
   });
 }
index ae11df2..0356ed2 100644 (file)
@@ -37,7 +37,6 @@ Namespace BuildConscryptNamespace([[maybe_unused]] const Context& ctx) {
   ns.AddSearchPath("/apex/com.android.conscrypt/${LIB}", AsanPath::SAME_PATH);
   ns.AddPermittedPath("/system/${LIB}");
   ns.GetLink("art").AddSharedLib("libandroidio.so");
-  ns.GetLink(ctx.GetSystemNamespaceName()).AddSharedLib("liblog.so");
 
   return ns;
 }
index 26ff47c..97aea10 100644 (file)
@@ -32,9 +32,6 @@ Namespace BuildCronetNamespace([[maybe_unused]] const Context& ctx) {
   ns.AddSearchPath("/apex/com.android.cronet/${LIB}", AsanPath::SAME_PATH);
   ns.AddPermittedPath("/system/${LIB}");
 
-  ns.GetLink(ctx.GetSystemNamespaceName())
-      .AddSharedLib(
-          "libandroid.so", "libc.so", "libdl.so", "libm.so", "liblog.so");
   return ns;
 }
 }  // namespace contents
index 63b3029..4d45b04 100644 (file)
@@ -27,48 +27,15 @@ using android::linkerconfig::modules::AsanPath;
 using android::linkerconfig::modules::Link;
 using android::linkerconfig::modules::Namespace;
 
-namespace {
-const std::vector<std::string> kLibsFromDefaultLegacy = {"libandroid.so",
-                                                         "libbinder_ndk.so",
-                                                         "libcgrouprc.so",
-                                                         "liblog.so",
-                                                         "libmediametrics.so",
-                                                         "libmediandk.so",
-                                                         "libvndksupport.so"};
-
-const std::vector<std::string> kLibsFromDefault = {"@{LLNDK_LIBRARIES_VENDOR}",
-                                                   "libbinder_ndk.so",
-                                                   "libmediametrics.so"};
-
-const std::vector<std::string> kLibsFromDefaultSystem = {"libcgrouprc.so"};
-}  // namespace
-
 namespace android {
 namespace linkerconfig {
 namespace contents {
 Namespace BuildMediaNamespace([[maybe_unused]] const Context& ctx) {
-  bool is_legacy = ctx.IsLegacyConfig();
-  bool is_vndklite = ctx.IsVndkliteConfig();
-  bool is_system_section = ctx.IsSystemSection();
-
   Namespace ns("media", /*is_isolated=*/true, /*is_visible=*/true);
   ns.AddSearchPath("/apex/com.android.media/${LIB}", AsanPath::SAME_PATH);
   ns.AddPermittedPath("/system/${LIB}");
-  ns.AddPermittedPath(
-      "/apex/com.android.media/${LIB}/extractors",
-      (is_legacy || is_vndklite) ? AsanPath::NONE : AsanPath::SAME_PATH);
-
-  Link& system_link = ns.GetLink(ctx.GetSystemNamespaceName());
-  if (is_legacy) {
-    system_link.AddSharedLib(kLibsFromDefaultLegacy);
-  } else {
-    system_link.AddSharedLib(kLibsFromDefault);
-    if (is_system_section && !is_vndklite) {
-      system_link.AddSharedLib(kLibsFromDefaultSystem);
-    }
-  }
-
-  ns.GetLink("neuralnetworks").AddSharedLib("libneuralnetworks.so");
+  ns.AddPermittedPath("/apex/com.android.media/${LIB}/extractors",
+                      AsanPath::SAME_PATH);
 
   return ns;
 }
index f79fb32..2638b86 100644 (file)
@@ -33,13 +33,6 @@ Namespace BuildNeuralNetworksNamespace([[maybe_unused]] const Context& ctx) {
                    AsanPath::SAME_PATH);
   ns.AddPermittedPath("/system/${LIB}");
 
-  ns.GetLink(ctx.GetSystemNamespaceName())
-      .AddSharedLib({"libcgrouprc.so",
-                     "liblog.so",
-                     "libnativewindow.so",
-                     "libneuralnetworks_packageinfo.so",
-                     "libvndksupport.so"});
-
   return ns;
 }
 }  // namespace contents
index 217bc2e..545f5d9 100644 (file)
@@ -32,8 +32,6 @@ Namespace BuildResolvNamespace([[maybe_unused]] const Context& ctx) {
   ns.AddSearchPath("/apex/com.android.resolv/${LIB}", AsanPath::SAME_PATH);
   ns.AddPermittedPath("/system/${LIB}");
 
-  ns.GetLink(ctx.GetSystemNamespaceName()).AddSharedLib({"libbinder_ndk.so"});
-
   return ns;
 }
 }  // namespace contents
index 288be38..011458e 100644 (file)
@@ -35,9 +35,6 @@ Namespace BuildRuntimeNamespace([[maybe_unused]] const Context& ctx) {
   ns.AddSearchPath("/apex/com.android.runtime/${LIB}", AsanPath::SAME_PATH);
   ns.AddPermittedPath("/system/${LIB}");
 
-  ns.GetLink(ctx.GetSystemNamespaceName())
-      .AddSharedLib("libc.so", "libdl.so", "libm.so", "liblog.so");
-
   return ns;
 }
 
index ccfed2e..1c466ae 100644 (file)
@@ -34,6 +34,8 @@ inline void MockVariables(std::string vndk_ver = "Q") {
                                                       "vndk_core_libraries");
   android::linkerconfig::modules::Variables::AddValue(
       "VNDK_USING_CORE_VARIANT_LIBRARIES", "vndk_using_core_variant_libraries");
+  android::linkerconfig::modules::Variables::AddValue("STUB_LIBRARIES",
+                                                      "stub_libraries");
 }
 
 inline void MockVnkdLite() {
index 8fce4b5..00cc508 100644 (file)
@@ -45,6 +45,8 @@ inline void MockGenericVariables() {
       "VNDK_CORE_LIBRARIES_PRODUCT", "vndk_core_libraries");
   android::linkerconfig::modules::Variables::AddValue(
       "VNDK_USING_CORE_VARIANT_LIBRARIES", "");
+  android::linkerconfig::modules::Variables::AddValue("STUB_LIBRARIES",
+                                                      "stub_libraries");
 }
 
 inline void MockVndkVersion(std::string vndk_version) {
index cda1ec7..9bfb5ef 100644 (file)
@@ -17,6 +17,7 @@
 #include "linkerconfig/variableloader.h"
 
 #include <android-base/result.h>
+#include <android-base/strings.h>
 #include <climits>
 #include <cstdlib>
 #include <cstring>
@@ -35,6 +36,39 @@ using android::linkerconfig::modules::Variables;
 namespace {
 using namespace android::linkerconfig::generator;
 
+// Stub libraries are list of libraries which has stub interface and installed
+// in system image so other partition and APEX modules can link to it.
+// TODO(b/147210213) : Generate this list on build and read from the file
+std::vector<std::string> stub_libraries = {
+    "libEGL.so",
+    "libGLESv1_CM.so",
+    "libGLESv2.so",
+    "libGLESv3.so",
+    "libRS.so",
+    "libaaudio.so",
+    "libandroid.so",
+    "libandroid_net.so",
+    "libbinder_ndk.so",
+    "libc.so",
+    "libcgrouprc.so",
+    "libclang_rt.asan-arm-android.so",
+    "libclang_rt.asan-i686-android.so",
+    "libclang_rt.asan-x86_64-android.so",
+    "libdl.so",
+    "libdl_android.so",
+    "libft2.so",
+    "liblog.so",
+    "libm.so",
+    "libmediametrics.so",
+    "libmediandk.so",
+    "libnativewindow.so",
+    "libneuralnetworks_packageinfo.so",
+    "libstatssocket.so",
+    "libsync.so",
+    "libvndksupport.so",
+    "libvulkan.so",
+};
+
 void LoadVndkVersionVariable() {
   Variables::AddValue("VENDOR_VNDK_VERSION", GetVendorVndkVersion());
   Variables::AddValue("PRODUCT_VNDK_VERSION", GetProductVndkVersion());
@@ -134,6 +168,9 @@ void LoadLibraryListVariables(const std::string& root) {
 
   Variables::AddValue("SANITIZER_RUNTIME_LIBRARIES",
                       GetLibrariesString(sanitizer_library_path));
+
+  Variables::AddValue("STUB_LIBRARIES",
+                      android::base::Join(stub_libraries, ':'));
 }
 }  // namespace