linker: Enable debug logging via properties

This patch lets developers tune logging of dlopen/dlerror with
setting system property.

Note that for security purposes this option is disabled on user build
for non-debuggable apps.

For starters there are 3 debug options:
 dlerror - enables logging of all dlerrors
 dlopen - traces dlopen calls

To enable system-wide logging (works only for userdebug/eng builds)
use debug.ld.all property.

To enable logging for particular app use debug.ld.app.<appname> property.

Example: Running "adb shell setprop debug.ld.all dlerror,dlopen" will log all
dlerror message as well as trace all calls to dlopen.

Bug: http://b/29458203
Change-Id: I2392c80a795509e16fe5689d0500d18b99772a64
diff --git a/linker/dlfcn.cpp b/linker/dlfcn.cpp
index a3ebcd6..110846d 100644
--- a/linker/dlfcn.cpp
+++ b/linker/dlfcn.cpp
@@ -68,6 +68,7 @@
 static void* dlopen_ext(const char* filename, int flags,
                         const android_dlextinfo* extinfo, void* caller_addr) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
+  g_linker_logger.ResetState();
   void* result = do_dlopen(filename, flags, extinfo, caller_addr);
   if (result == nullptr) {
     __bionic_format_dlerror("dlopen failed", linker_get_error_buffer());
@@ -88,6 +89,7 @@
 
 void* dlsym_impl(void* handle, const char* symbol, const char* version, void* caller_addr) {
   ScopedPthreadMutexLocker locker(&g_dl_mutex);
+  g_linker_logger.ResetState();
   void* result;
   if (!do_dlsym(handle, symbol, version, caller_addr, &result)) {
     __bionic_format_dlerror(linker_get_error_buffer(), nullptr);