Fix is_greylisted check in case of an absolute path

Some apps are explicitly calling System.loadLibrary(.)
for internal platform libraries like cutils.

Bug: http://b/27100558
Change-Id: I765cf3fc542778d3b487069c9955d367840b3c05
diff --git a/linker/linker.cpp b/linker/linker.cpp
index f7dbdf0..77642e7 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -163,6 +163,14 @@
 }
 
 // TODO(dimitry): This is workaround for http://b/26394120 - it will be removed before the release
+#if defined(__LP64__)
+static const char* const kSystemLibDir = "/system/lib64";
+#else
+static const char* const kSystemLibDir = "/system/lib";
+#endif
+
+static std::string dirname(const char *path);
+
 static bool is_greylisted(const char* name, const soinfo* needed_by) {
   static const char* const kLibraryGreyList[] = {
     "libandroid_runtime.so",
@@ -191,6 +199,12 @@
     return true;
   }
 
+  // if this is an absolute path - make sure it points to /system/lib(64)
+  if (name[0] == '/' && dirname(name) == kSystemLibDir) {
+    // and reduce the path to basename
+    name = basename(name);
+  }
+
   for (size_t i = 0; kLibraryGreyList[i] != nullptr; ++i) {
     if (strcmp(name, kLibraryGreyList[i]) == 0) {
       return true;