OSDN Git Service

Do not link VNDK libraries to system from vendor/product default
authorKiyoung Kim <kiyoungkim@google.com>
Thu, 14 May 2020 07:25:15 +0000 (16:25 +0900)
committerKiyoung Kim <kiyoungkim@google.com>
Fri, 15 May 2020 00:45:19 +0000 (09:45 +0900)
There was an issue that P vendor fails with Wifi because ubsan
libclangrt was linked to system even the library was in VNDK. This
change removes vndk libraries from sanitizer library list when linking
from vendor/product default so we can stick on partition's own VNDK
library.

Bug: 155907604
Test: Tested with cuttlefish
Change-Id: I7c23c6ba5f263a716b44778c9441dde68943259b

contents/common/system_links.cc
contents/context/context.cc
contents/include/linkerconfig/context.h
contents/namespace/productdefault.cc
contents/namespace/vendordefault.cc
contents/tests/backward_compatibility/testbase.h
contents/tests/configuration/include/mockenv.h
generator/variableloader.cc

index 207d9b5..08c88f7 100644 (file)
@@ -32,12 +32,15 @@ using android::linkerconfig::modules::Namespace;
 using android::linkerconfig::modules::Section;
 
 void AddStandardSystemLinks(const Context& ctx, Section* section) {
-  std::string system_ns_name = ctx.GetSystemNamespaceName();
-  section->ForEachNamespaces([system_ns_name](Namespace& ns) {
+  const std::string system_ns_name = ctx.GetSystemNamespaceName();
+  const bool is_section_vndk_enabled = ctx.IsSectionVndkEnabled();
+  section->ForEachNamespaces([&](Namespace& ns) {
     if (ns.GetName() != system_ns_name) {
-      ns.GetLink(system_ns_name)
-          .AddSharedLib(Var("STUB_LIBRARIES"),
-                        Var("SANITIZER_RUNTIME_LIBRARIES"));
+      if (!is_section_vndk_enabled || ns.GetName() != "default") {
+        ns.GetLink(system_ns_name)
+            .AddSharedLib(Var("STUB_LIBRARIES"),
+                          Var("SANITIZER_RUNTIME_LIBRARIES"));
+      }
     }
   });
 }
index 7281c57..e260e51 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <android-base/strings.h>
 
+#include "linkerconfig/environment.h"
 #include "linkerconfig/log.h"
 #include "linkerconfig/namespacebuilder.h"
 #include "linkerconfig/variables.h"
@@ -123,6 +124,21 @@ std::string Var(const std::string& name, const std::string& default_value) {
   return default_value;
 }
 
+bool Context::IsSectionVndkEnabled() const {
+  if (!IsVndkAvailable() || android::linkerconfig::modules::IsVndkLiteDevice()) {
+    return false;
+  }
+  if (IsVendorSection()) {
+    return true;
+  }
+  if (IsProductSection() &&
+      android::linkerconfig::modules::IsProductVndkVersionDefined()) {
+    return true;
+  }
+
+  return false;
+}
+
 }  // namespace contents
 }  // namespace linkerconfig
 }  // namespace android
index 6eb1de1..3179c00 100644 (file)
@@ -77,6 +77,8 @@ class Context : public modules::BaseContext {
   void RegisterApexNamespaceBuilder(const std::string& name,
                                     ApexNamespaceBuilder builder);
 
+  bool IsSectionVndkEnabled() const;
+
  private:
   std::map<std::string, ApexNamespaceBuilder> builders_;
 
index 23fe083..6dc505e 100644 (file)
@@ -34,7 +34,8 @@ Namespace BuildProductDefaultNamespace([[maybe_unused]] const Context& ctx) {
   ns.AddPermittedPath(Var("PRODUCT", "product"), AsanPath::WITH_DATA_ASAN);
 
   ns.GetLink(ctx.GetSystemNamespaceName())
-      .AddSharedLib(Var("LLNDK_LIBRARIES_PRODUCT"));
+      .AddSharedLib(
+          {Var("LLNDK_LIBRARIES_PRODUCT"), Var("SANITIZER_DEFAULT_PRODUCT")});
   ns.GetLink("vndk").AddSharedLib({Var("VNDK_SAMEPROCESS_LIBRARIES_PRODUCT"),
                                    Var("VNDK_CORE_LIBRARIES_PRODUCT")});
   if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
index f9b5f09..eefd0b4 100644 (file)
@@ -103,7 +103,8 @@ Namespace BuildVendorDefaultNamespace([[maybe_unused]] const Context& ctx) {
     ns.AddRequires(kVndkLiteVendorRequires);
   } else {
     ns.GetLink(ctx.GetSystemNamespaceName())
-        .AddSharedLib(Var("LLNDK_LIBRARIES_VENDOR"));
+        .AddSharedLib(
+            {Var("LLNDK_LIBRARIES_VENDOR"), Var("SANITIZER_DEFAULT_VENDOR")});
     ns.GetLink("vndk").AddSharedLib({Var("VNDK_SAMEPROCESS_LIBRARIES_VENDOR"),
                                      Var("VNDK_CORE_LIBRARIES_VENDOR")});
     if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
index 193b85e..9705eda 100644 (file)
@@ -27,6 +27,8 @@ inline void MockVndkVariables(std::string partition, std::string vndk_ver) {
   Variables::AddValue("VNDK_SAMEPROCESS_LIBRARIES_" + partition,
                       "vndk_sameprocess_libraries");
   Variables::AddValue("VNDK_CORE_LIBRARIES_" + partition, "vndk_core_libraries");
+  Variables::AddValue("SANITIZER_DEFAULT_" + partition,
+                      "sanitizer_default_libraries");
 }
 
 inline void MockVariables(std::string vndk_ver = "Q") {
index d72be4a..d8e9285 100644 (file)
@@ -47,6 +47,10 @@ inline void MockGenericVariables() {
       "VNDK_USING_CORE_VARIANT_LIBRARIES", "");
   android::linkerconfig::modules::Variables::AddValue("STUB_LIBRARIES",
                                                       "stub_libraries");
+  android::linkerconfig::modules::Variables::AddValue(
+      "SANITIZER_DEFAULT_VENDOR", "sanitizer_default_libraries");
+  android::linkerconfig::modules::Variables::AddValue(
+      "SANITIZER_DEFAULT_PRODUCT", "sanitizer_default_libraries");
 }
 
 inline void MockVndkVersion(std::string vndk_version) {
index b64b474..ab43d1d 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <android-base/result.h>
 #include <android-base/strings.h>
+
 #include <climits>
 #include <cstdlib>
 #include <cstring>
@@ -125,6 +126,8 @@ void LoadVndkLibraryListVariables(const std::string& root,
       vndk_path + "/etc/vndkcore.libraries." + vndk_version + ".txt";
   const std::string vndkprivate_libraries_path =
       vndk_path + "/etc/vndkprivate.libraries." + vndk_version + ".txt";
+  const std::string sanitizer_library_path =
+      root + "/system/etc/sanitizer.libraries.txt";
 
   Variables::AddValue("LLNDK_LIBRARIES_" + partition,
                       GetPublicLibrariesString(llndk_libraries_path,
@@ -142,6 +145,10 @@ void LoadVndkLibraryListVariables(const std::string& root,
                       GetPublicLibrariesString(vndkcore_libraries_path,
                                                vndkprivate_libraries_path));
 
+  Variables::AddValue("SANITIZER_DEFAULT_" + partition,
+                      GetPublicLibrariesString(sanitizer_library_path,
+                                               vndkcore_libraries_path));
+
   if (partition == "VENDOR") {
     auto vndkcorevariant_library_path =
         root + "/system/etc/vndkcorevariant.libraries.txt";