release-request-cf825746-bd0b-4ee1-a15a-04c90380d879-for-git_oc-dr1-release-4099047 snap-temp-L55200000074003152

Change-Id: Id9c50fed4607092ba5938bc49820b7a8085d244d
diff --git a/tools/bcc/Android.bp b/tools/bcc/Android.bp
index 507fdd9..63729fd 100644
--- a/tools/bcc/Android.bp
+++ b/tools/bcc/Android.bp
@@ -37,6 +37,7 @@
             shared_libs: [
                 "libdl",
                 "liblog",
+                "libvndksupport",
             ],
         },
     },
diff --git a/tools/bcc/Main.cpp b/tools/bcc/Main.cpp
index 3887bd9..e1d3096 100644
--- a/tools/bcc/Main.cpp
+++ b/tools/bcc/Main.cpp
@@ -44,6 +44,10 @@
 #include <bcc/RSCompilerDriver.h>
 #include <bcc/Source.h>
 
+#ifdef __ANDROID__
+#include <vndksupport/linker.h>
+#endif
+
 using namespace bcc;
 
 #define STR2(a) #a
@@ -121,6 +125,13 @@
                            " cache invalidation at a later time"),
             llvm::cl::value_desc("checksum"));
 
+#ifdef __ANDROID__
+llvm::cl::opt<std::string>
+OptVendorPlugin("plugin", llvm::cl::ZeroOrMore,
+    llvm::cl::value_desc("pluginfilename"),
+    llvm::cl::desc("Load the specified vendor plugin. Use this instead of the -load option"));
+#endif
+
 //===----------------------------------------------------------------------===//
 // Compiler Options
 //===----------------------------------------------------------------------===//
@@ -288,6 +299,21 @@
     return EXIT_FAILURE;
   }
 
+#ifdef __ANDROID__
+  if (!OptVendorPlugin.empty()) {
+    // bcc is a system process and the vendor plugin is a vendor lib. Since the
+    // vendor lib might have been compiled using the old versions of platform
+    // libraries, they must not be directly loaded into the default namespace
+    // but into the sphal namespace where old versions of platform libraries
+    // (aka VNDK libs) are provided.
+    void* handle = android_load_sphal_library(OptVendorPlugin.c_str(), RTLD_LAZY|RTLD_GLOBAL);
+    if (handle == nullptr) {
+      ALOGE("Failed to load vendor plugin %s", OptVendorPlugin.c_str());
+      return EXIT_FAILURE;
+    }
+  }
+#endif
+
   if (!ConfigCompiler(RSCD)) {
     ALOGE("Failed to configure compiler");
     return EXIT_FAILURE;