OSDN Git Service

Add sphal and vndk namespaces to unrestricted
authorYiwei Zhang <zzyiwei@google.com>
Fri, 8 May 2020 18:21:33 +0000 (11:21 -0700)
committerYiwei Zhang <zzyiwei@google.com>
Mon, 11 May 2020 01:52:32 +0000 (18:52 -0700)
Binary executables compiled against libvulkan or libEGL/libGLES*
fundamentally depend on sphal libraries for their functionality. On
production builds, instead of building APKs, devs are always allowed to
use NDK toolchain to build binaries and push to /data/local/tmp to run.

Devs are doing such as to avoid issues with bundling resources,
extracting output, slower build times and flakier perf numbers. It's
also the preferred way for test factory which have cross-platform
devices, because they can automate the process using the same script if
using binary executables.

This change adds the sphal and vndk namespaces to unrestricted
configuration. This change also makes rs an optional namespace for sphal
namespace as it's only needed in system configuration. In addition, this
change has updated vndk namespace generation accordingly.

Bug: 156099573
Test: atest --test-mapping system/linkerconfig
Test: push a Vulkan binary to /data/local/tmp and run
Change-Id: Id09dbcf2ab33a599960f471cbc1b142b6d3eaa1a

contents/context/context.cc
contents/include/linkerconfig/context.h
contents/namespace/sphal.cc
contents/namespace/vndk.cc
contents/section/unrestricted.cc

index 3ec30a4..7281c57 100644 (file)
@@ -42,6 +42,10 @@ bool Context::IsProductSection() const {
   return current_section_ == SectionType::Product;
 }
 
+bool Context::IsUnrestrictedSection() const {
+  return current_section_ == SectionType::Unrestricted;
+}
+
 bool Context::IsDefaultConfig() const {
   return current_linkerconfig_type_ == LinkerConfigType::Default;
 }
index 02b1d96..6eb1de1 100644 (file)
@@ -34,6 +34,7 @@ enum class SectionType {
   System,
   Vendor,
   Product,
+  Unrestricted,
   Other,
 };
 
@@ -54,6 +55,7 @@ class Context : public modules::BaseContext {
   bool IsSystemSection() const;
   bool IsVendorSection() const;
   bool IsProductSection() const;
+  bool IsUnrestrictedSection() const;
 
   bool IsDefaultConfig() const;
   bool IsLegacyConfig() const;
@@ -88,4 +90,4 @@ std::string Var(const std::string& name, const std::string& default_value);
 
 }  // namespace contents
 }  // namespace linkerconfig
-}  // namespace android
\ No newline at end of file
+}  // namespace android
index 2627788..70a8c2a 100644 (file)
@@ -63,7 +63,9 @@ Namespace BuildSphalNamespace([[maybe_unused]] const Context& ctx) {
     // Only libs listed here can be used. Order is important here as the
     // namespaces are tried in this order. rs should be before vndk because both
     // are capable of loading libRS_internal.so
-    ns.GetLink("rs").AddSharedLib("libRS_internal.so");
+    if (ctx.IsSystemSection()) {
+      ns.GetLink("rs").AddSharedLib("libRS_internal.so");
+    }
     ns.GetLink(ctx.GetSystemNamespaceName())
         .AddSharedLib(Var("LLNDK_LIBRARIES_VENDOR", ""));
     ns.GetLink("vndk").AddSharedLib(
index ef390b8..452abb1 100644 (file)
@@ -27,25 +27,29 @@ namespace linkerconfig {
 namespace contents {
 Namespace BuildVndkNamespace([[maybe_unused]] const Context& ctx,
                              VndkUserPartition vndk_user) {
-  bool is_system_section = ctx.IsSystemSection() || ctx.IsApexBinaryConfig();
+  bool is_system_or_unrestricted_section = ctx.IsSystemSection() ||
+                                           ctx.IsApexBinaryConfig() ||
+                                           ctx.IsUnrestrictedSection();
   bool is_vndklite = ctx.IsVndkliteConfig();
   // In the system section, we need to have an additional vndk namespace for
   // product apps. We must have a different name "vndk_product" for this
   // namespace. "vndk_product" namespace is used only from the native_loader for
   // product apps.
   const char* name;
-  if (is_system_section && vndk_user == VndkUserPartition::Product) {
+  if (is_system_or_unrestricted_section &&
+      vndk_user == VndkUserPartition::Product) {
     name = "vndk_product";
   } else {
     name = "vndk";
   }
 
-  // Isolated but visible when used in the [system] section to allow links to be
-  // created at runtime, e.g. through android_link_namespaces in
-  // libnativeloader. Otherwise it isn't isolated, so visibility doesn't matter.
+  // Isolated but visible when used in the [system] or [unrestricted] section to
+  // allow links to be created at runtime, e.g. through android_link_namespaces
+  // in libnativeloader. Otherwise it isn't isolated, so visibility doesn't
+  // matter.
   Namespace ns(name,
-               /*is_isolated=*/is_system_section,
-               /*is_visible=*/is_system_section);
+               /*is_isolated=*/is_system_or_unrestricted_section,
+               /*is_visible=*/is_system_or_unrestricted_section);
 
   std::vector<std::string> lib_paths;
   std::vector<std::string> vndk_paths;
@@ -61,14 +65,15 @@ Namespace BuildVndkNamespace([[maybe_unused]] const Context& ctx,
 
   for (const auto& lib_path : lib_paths) {
     ns.AddSearchPath(lib_path + "vndk-sp", AsanPath::WITH_DATA_ASAN);
-    if (!is_system_section) {
+    if (!is_system_or_unrestricted_section) {
       ns.AddSearchPath(lib_path + "vndk", AsanPath::WITH_DATA_ASAN);
     }
   }
   ns.AddSearchPath("/apex/com.android.vndk.v" + vndk_version + "/${LIB}",
                    AsanPath::SAME_PATH);
 
-  if (is_system_section && vndk_user == VndkUserPartition::Vendor) {
+  if (is_system_or_unrestricted_section &&
+      vndk_user == VndkUserPartition::Vendor) {
     // It is for vendor sp-hal
     ns.AddPermittedPath("/odm/${LIB}/hw", AsanPath::WITH_DATA_ASAN);
     ns.AddPermittedPath("/odm/${LIB}/egl", AsanPath::WITH_DATA_ASAN);
@@ -96,7 +101,7 @@ Namespace BuildVndkNamespace([[maybe_unused]] const Context& ctx,
   }
 
   if (!is_vndklite) {
-    if (is_system_section) {
+    if (is_system_or_unrestricted_section) {
       if (vndk_user == VndkUserPartition::Vendor) {
         // The "vndk" namespace links to the system namespace for LLNDK libs above
         // and links to "sphal" namespace for vendor libs. The ordering matters;
index ce6dcbd..ea1af8d 100644 (file)
@@ -34,10 +34,14 @@ namespace android {
 namespace linkerconfig {
 namespace contents {
 Section BuildUnrestrictedSection(Context& ctx) {
-  ctx.SetCurrentSection(SectionType::Other);
+  ctx.SetCurrentSection(SectionType::Unrestricted);
   std::vector<Namespace> namespaces;
 
   namespaces.emplace_back(BuildUnrestrictedDefaultNamespace(ctx));
+  if (ctx.IsVndkAvailable()) {
+    namespaces.emplace_back(BuildSphalNamespace(ctx));
+    namespaces.emplace_back(BuildVndkNamespace(ctx, VndkUserPartition::Vendor));
+  }
 
   return BuildSection(ctx,
                       "unrestricted",