[Lldb-commits] [lldb] r249012 - Restrict the scope of a hack in DYLDRendezvous

Tamas Berghammer via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 1 06:57:54 PDT 2015


Author: tberghammer
Date: Thu Oct  1 08:57:54 2015
New Revision: 249012

URL: http://llvm.org/viewvc/llvm-project?rev=249012&view=rev
Log:
Restrict the scope of a hack in DYLDRendezvous

The hack is there to work around an incorrect load address reported
by the android linker on API 21 and 22 devices. This CL restricts the
hack to those android API levels.

Differential revision: http://reviews.llvm.org/D13288

Modified:
    lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
    lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
    lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h

Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp?rev=249012&r1=249011&r2=249012&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp Thu Oct  1 08:57:54 2015
@@ -17,6 +17,7 @@
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/Symbol.h"
 #include "lldb/Symbol/SymbolContext.h"
+#include "lldb/Target/Platform.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
 
@@ -372,6 +373,25 @@ DYLDRendezvous::ReadStringFromMemory(add
     return str;
 }
 
+// Returns true if the load bias reported by the linker is incorrect for the given entry. This
+// function is used to handle cases where we want to work around a bug in the system linker.
+static bool
+isLoadBiasIncorrect(Target& target, const std::string& file_path)
+{
+    // On Android L (API 21, 22) the load address of the "/system/bin/linker" isn't filled in
+    // correctly.
+    uint32_t os_major = 0, os_minor = 0, os_update = 0;
+    if (target.GetArchitecture().GetTriple().getEnvironment() == llvm::Triple::Android &&
+        target.GetPlatform()->GetOSVersion(os_major, os_minor, os_update) &&
+        (os_major == 21 || os_major == 22) &&
+        (file_path == "/system/bin/linker" || file_path == "/system/bin/linker64"))
+    {
+        return true;
+    }
+
+    return false;
+}
+
 bool
 DYLDRendezvous::ReadSOEntryFromMemory(lldb::addr_t addr, SOEntry &entry)
 {
@@ -413,11 +433,9 @@ DYLDRendezvous::ReadSOEntryFromMemory(ll
     std::string file_path = ReadStringFromMemory(entry.path_addr);
     entry.file_spec.SetFile(file_path, false);
 
-    // On Android L (5.0, 5.1) the load address of the "/system/bin/linker" isn't filled in
-    // correctly. To get the correct load address we fetch the load address of the file from the
-    // proc file system.
-    if (arch.GetTriple().getEnvironment() == llvm::Triple::Android && entry.base_addr == 0 &&
-        (file_path == "/system/bin/linker" || file_path == "/system/bin/linker64"))
+    // If the load bias reported by the linker is incorrect then fetch the load address of the file
+    // from the proc file system.
+    if (isLoadBiasIncorrect(m_process->GetTarget(), file_path))
     {
         lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
         bool is_loaded = false;

Modified: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp?rev=249012&r1=249011&r2=249012&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp Thu Oct  1 08:57:54 2015
@@ -362,3 +362,12 @@ PlatformAndroid::DownloadSymbolFile (con
     // Download the symbolfile from the remote device
     return GetFile(symfile_platform_filespec, dst_file_spec);
 }
+
+bool
+PlatformAndroid::GetRemoteOSVersion ()
+{
+    m_major_os_version = GetSdkVersion();
+    m_minor_os_version = 0;
+    m_update_os_version = 0;
+    return m_major_os_version != 0;
+}

Modified: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h?rev=249012&r1=249011&r2=249012&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h (original)
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h Thu Oct  1 08:57:54 2015
@@ -76,7 +76,10 @@ namespace platform_android {
         
         uint32_t
         GetSdkVersion();
-        
+
+        bool
+        GetRemoteOSVersion() override;
+
         Error
         DisconnectRemote () override;
 




More information about the lldb-commits mailing list