diff options
author | Jason Sams <jsams@google.com> | 2015-05-07 15:20:05 -0700 |
---|---|---|
committer | Jason Sams <jsams@google.com> | 2015-05-07 15:20:05 -0700 |
commit | d97617a0a736b4dadcf978bfc1fa0aef0d4d50d3 (patch) | |
tree | 751ea9ffa6fd5d132a51d23b2592a432dfaecee2 | |
parent | 4f8c2b8c519715b05812a1c5b4de0d138ab49dfb (diff) | |
download | rs-d97617a0a736b4dadcf978bfc1fa0aef0d4d50d3.tar.gz |
Add a way to link against different driver names.
The existing linker path hard-coded "-lRSDriver" into the command line, but
this won't work for partner drivers that have a different implementation
loaded. In order to still properly handle use of the CPU driver, this needs
to change depending on whether we actually loaded an OVERRIDE_RS_DRIVER or
not.
bug 20894664
Change-Id: I0c4a4f12f5db819b234952bc8f364ac6300f147b
-rw-r--r-- | cpu_ref/rsCpuExecutable.cpp | 12 | ||||
-rw-r--r-- | cpu_ref/rsCpuExecutable.h | 4 | ||||
-rw-r--r-- | cpu_ref/rsCpuScript.cpp | 3 | ||||
-rw-r--r-- | cpu_ref/rsCpuScriptGroup2.cpp | 3 | ||||
-rw-r--r-- | rsContext.cpp | 1 | ||||
-rw-r--r-- | rsContext.h | 10 | ||||
-rw-r--r-- | rsDriverLoader.cpp | 3 |
7 files changed, 31 insertions, 5 deletions
diff --git a/cpu_ref/rsCpuExecutable.cpp b/cpu_ref/rsCpuExecutable.cpp index 1553da28..e7831085 100644 --- a/cpu_ref/rsCpuExecutable.cpp +++ b/cpu_ref/rsCpuExecutable.cpp @@ -110,12 +110,20 @@ const char* SharedLibraryUtils::RS_CACHE_DIR = "com.android.renderscript.cache"; #ifndef RS_COMPATIBILITY_LIB -bool SharedLibraryUtils::createSharedLibrary(const char *cacheDir, const char *resName) { +bool SharedLibraryUtils::createSharedLibrary(const char *driverName, + const char *cacheDir, + const char *resName) { std::string sharedLibName = findSharedObjectName(cacheDir, resName); std::string objFileName = cacheDir; objFileName.append("/"); objFileName.append(resName); objFileName.append(".o"); + // Should be something like "libRSDriver.so". + std::string linkDriverName = driverName; + // Remove ".so" and replace "lib" with "-l". + // This will leave us with "-lRSDriver" instead. + linkDriverName.erase(linkDriverName.length() - 3); + linkDriverName.replace(0, 3, "-l"); const char *compiler_rt = SYSLIBPATH"/libcompiler_rt.so"; const char *mTriple = "-mtriple=" DEFAULT_TARGET_TRIPLE_STRING; @@ -126,7 +134,7 @@ bool SharedLibraryUtils::createSharedLibrary(const char *cacheDir, const char *r "-shared", "-nostdlib", compiler_rt, mTriple, libPath, - "-lRSDriver", "-lm", "-lc", + linkDriverName.c_str(), "-lm", "-lc", objFileName.c_str(), "-o", sharedLibName.c_str(), nullptr diff --git a/cpu_ref/rsCpuExecutable.h b/cpu_ref/rsCpuExecutable.h index 785f53d1..fd79ca1d 100644 --- a/cpu_ref/rsCpuExecutable.h +++ b/cpu_ref/rsCpuExecutable.h @@ -29,7 +29,9 @@ class Context; class SharedLibraryUtils { public: #ifndef RS_COMPATIBILITY_LIB - static bool createSharedLibrary(const char* cacheDir, const char* resName); + static bool createSharedLibrary(const char* driverName, + const char* cacheDir, + const char* resName); #endif // Load the shared library referred to by cacheDir and resName. If we have diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp index 3f64534a..32823747 100644 --- a/cpu_ref/rsCpuScript.cpp +++ b/cpu_ref/rsCpuScript.cpp @@ -385,7 +385,8 @@ bool RsdCpuScriptImpl::init(char const *resName, char const *cacheDir, return false; } - if (!SharedLibraryUtils::createSharedLibrary(cacheDir, resName)) { + if (!SharedLibraryUtils::createSharedLibrary(mCtx->getContext()->getDriverName(), + cacheDir, resName)) { ALOGE("Linker: Failed to link object file '%s'", resName); mCtx->unlockMutex(); return false; diff --git a/cpu_ref/rsCpuScriptGroup2.cpp b/cpu_ref/rsCpuScriptGroup2.cpp index 1cc382f4..2329b75b 100644 --- a/cpu_ref/rsCpuScriptGroup2.cpp +++ b/cpu_ref/rsCpuScriptGroup2.cpp @@ -397,7 +397,8 @@ void CpuScriptGroup2Impl::compile(const char* cacheDir) { // Create and load the shared lib //===--------------------------------------------------------------------===// - if (!SharedLibraryUtils::createSharedLibrary(cacheDir, resName)) { + if (!SharedLibraryUtils::createSharedLibrary( + getCpuRefImpl()->getContext()->getDriverName(), cacheDir, resName)) { ALOGE("Failed to link object file '%s'", resName); unlink(objFilePath.c_str()); return; diff --git a/rsContext.cpp b/rsContext.cpp index 0bf9d9df..29b4036f 100644 --- a/rsContext.cpp +++ b/rsContext.cpp @@ -517,6 +517,7 @@ bool Context::initContext(Device *dev, const RsSurfaceConfig *sc) { } mHasSurface = false; + mDriverName = NULL; timerInit(); timerSet(RS_TIMER_INTERNAL); diff --git a/rsContext.h b/rsContext.h index 5965caeb..6cb0ed76 100644 --- a/rsContext.h +++ b/rsContext.h @@ -283,6 +283,11 @@ public: return mCacheDir; } + // Returns the actual loaded driver's name (like "libRSDriver.so"). + const char * getDriverName() { + return mDriverName; + } + protected: @@ -336,6 +341,11 @@ private: bool mHasSurface; bool mIsContextLite; + // This holds the name of the driver (like "libRSDriver.so"). + // Since this is always just a static string, we don't have to + // allocate, copy, or free any memory here. + const char* mDriverName; + Vector<ObjectBase *> mNames; uint64_t mTimers[_RS_TIMER_TOTAL]; diff --git a/rsDriverLoader.cpp b/rsDriverLoader.cpp index 37bd12a2..528af0fa 100644 --- a/rsDriverLoader.cpp +++ b/rsDriverLoader.cpp @@ -204,6 +204,9 @@ bool Context::loadRuntime(const char* filename) { goto error; } + // Only map in the actual driver name if we successfully load the runtime. + mDriverName = filename; + return true; |