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

llvm-svn: 249012
This commit is contained in:
Tamas Berghammer 2015-10-01 13:57:54 +00:00
parent b7c5b91068
commit 3c47151d1a
3 changed files with 36 additions and 6 deletions

View File

@ -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(addr_t addr)
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(lldb::addr_t addr, SOEntry &entry)
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;

View File

@ -362,3 +362,12 @@ PlatformAndroid::DownloadSymbolFile (const lldb::ModuleSP& module_sp,
// 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;
}

View File

@ -76,7 +76,10 @@ namespace platform_android {
uint32_t
GetSdkVersion();
bool
GetRemoteOSVersion() override;
Error
DisconnectRemote () override;