bcc vendor plugin must be loaded from the sphal namespace
bcc loads vendor plugin in its address space. Since bcc is a system
process, the vendor plugin must be loaded from the sphal namespace where
VNDK-SP libraries are provided. This is to ensure that the vendor plugin
is linked against to the VNDK-SP version of libraries. It also prevents
the vendor plugin from using non-VNDK-SP libs such as libLLVM.so.
Bug: 62517583
Test: a sample renderscript app (CameraScript) runs well
Change-Id: I87c9d55c3527bee8c6d2653fa8a796143a7bb146
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;