Make i386-*-freebsd expression work on JIT path

* Enable i386 ABI creation for freebsd
* Added an extra argument in ABISysV_i386::PrepareTrivialCall for mmap
  syscall
* Unlike linux, the last argument of mmap is actually 64-bit(off_t).
  This requires us to push an additional word for the higher order bits.
* Prior to this change, ktrace dump will show mmap failures due to
  invalid argument coming from the 6th mmap argument.

Patch by Karnajit Wangkhem

Differential Revision:	https://reviews.llvm.org/D34776

llvm-svn: 311002
This commit is contained in:
Ed Maste 2017-08-16 12:55:02 +00:00
parent 9c5d64b901
commit 37c40af712
12 changed files with 65 additions and 33 deletions

View File

@ -53,6 +53,7 @@ public:
};
typedef std::shared_ptr<PlatformProperties> PlatformPropertiesSP;
typedef llvm::SmallVector<lldb::addr_t, 6> MmapArgList;
//----------------------------------------------------------------------
/// @class Platform Platform.h "lldb/Target/Platform.h"
@ -628,8 +629,11 @@ public:
virtual Status Unlink(const FileSpec &file_spec);
virtual uint64_t ConvertMmapFlagsToPlatform(const ArchSpec &arch,
unsigned flags);
virtual MmapArgList GetMmapArgumentList(const ArchSpec &arch,
lldb::addr_t addr,
lldb::addr_t length,
unsigned prot, unsigned flags,
lldb::addr_t fd, lldb::addr_t offset);
virtual bool GetSupportsRSync() { return m_supports_rsync; }

View File

@ -206,7 +206,7 @@ ABISP
ABISysV_i386::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) {
static ABISP g_abi_sp;
if ((arch.GetTriple().getArch() == llvm::Triple::x86) &&
arch.GetTriple().isOSLinux()) {
(arch.GetTriple().isOSLinux() || arch.GetTriple().isOSFreeBSD())) {
if (!g_abi_sp)
g_abi_sp.reset(new ABISysV_i386(process_sp));
return g_abi_sp;

View File

@ -314,13 +314,19 @@ void PlatformFreeBSD::CalculateTrapHandlerSymbolNames() {
m_trap_handlers.push_back(ConstString("_sigtramp"));
}
uint64_t PlatformFreeBSD::ConvertMmapFlagsToPlatform(const ArchSpec &arch,
unsigned flags) {
MmapArgList PlatformFreeBSD::GetMmapArgumentList(const ArchSpec &arch,
addr_t addr, addr_t length,
unsigned prot, unsigned flags,
addr_t fd, addr_t offset) {
uint64_t flags_platform = 0;
if (flags & eMmapFlagsPrivate)
flags_platform |= MAP_PRIVATE;
if (flags & eMmapFlagsAnon)
flags_platform |= MAP_ANON;
return flags_platform;
MmapArgList args({addr, length, prot, flags_platform, fd, offset});
if (arch.GetTriple().getArch() == llvm::Triple::x86)
args.push_back(0);
return args;
}

View File

@ -61,8 +61,10 @@ public:
void CalculateTrapHandlerSymbolNames() override;
uint64_t ConvertMmapFlagsToPlatform(const ArchSpec &arch,
unsigned flags) override;
MmapArgList GetMmapArgumentList(const ArchSpec &arch, lldb::addr_t addr,
lldb::addr_t length, unsigned prot,
unsigned flags, lldb::addr_t fd,
lldb::addr_t offset) override;
private:
DISALLOW_COPY_AND_ASSIGN(PlatformFreeBSD);

View File

@ -390,8 +390,10 @@ void PlatformLinux::CalculateTrapHandlerSymbolNames() {
m_trap_handlers.push_back(ConstString("_sigtramp"));
}
uint64_t PlatformLinux::ConvertMmapFlagsToPlatform(const ArchSpec &arch,
unsigned flags) {
MmapArgList PlatformLinux::GetMmapArgumentList(const ArchSpec &arch,
addr_t addr, addr_t length,
unsigned prot, unsigned flags,
addr_t fd, addr_t offset) {
uint64_t flags_platform = 0;
uint64_t map_anon = MAP_ANON;
@ -406,6 +408,8 @@ uint64_t PlatformLinux::ConvertMmapFlagsToPlatform(const ArchSpec &arch,
flags_platform |= MAP_PRIVATE;
if (flags & eMmapFlagsAnon)
flags_platform |= map_anon;
return flags_platform;
MmapArgList args({addr, length, prot, flags_platform, fd, offset});
return args;
}

View File

@ -59,8 +59,10 @@ public:
void CalculateTrapHandlerSymbolNames() override;
uint64_t ConvertMmapFlagsToPlatform(const ArchSpec &arch,
unsigned flags) override;
MmapArgList GetMmapArgumentList(const ArchSpec &arch, lldb::addr_t addr,
lldb::addr_t length, unsigned prot,
unsigned flags, lldb::addr_t fd,
lldb::addr_t offset) override;
private:
DISALLOW_COPY_AND_ASSIGN(PlatformLinux);

View File

@ -420,13 +420,17 @@ void PlatformNetBSD::CalculateTrapHandlerSymbolNames() {
m_trap_handlers.push_back(ConstString("_sigtramp"));
}
uint64_t PlatformNetBSD::ConvertMmapFlagsToPlatform(const ArchSpec &arch,
unsigned flags) {
MmapArgList PlatformNetBSD::GetMmapArgumentList(const ArchSpec &arch,
addr_t addr, addr_t length,
unsigned prot, unsigned flags,
addr_t fd, addr_t offset) {
uint64_t flags_platform = 0;
if (flags & eMmapFlagsPrivate)
flags_platform |= MAP_PRIVATE;
if (flags & eMmapFlagsAnon)
flags_platform |= MAP_ANON;
return flags_platform;
MmapArgList args({addr, length, prot, flags_platform, fd, offset});
return args;
}

View File

@ -59,8 +59,10 @@ public:
void CalculateTrapHandlerSymbolNames() override;
uint64_t ConvertMmapFlagsToPlatform(const ArchSpec &arch,
unsigned flags) override;
MmapArgList GetMmapArgumentList(const ArchSpec &arch, lldb::addr_t addr,
lldb::addr_t length, unsigned prot,
unsigned flags, lldb::addr_t fd,
lldb::addr_t offset) override;
private:
DISALLOW_COPY_AND_ASSIGN(PlatformNetBSD);

View File

@ -211,13 +211,17 @@ void PlatformOpenBSD::CalculateTrapHandlerSymbolNames() {
m_trap_handlers.push_back(ConstString("_sigtramp"));
}
uint64_t PlatformOpenBSD::ConvertMmapFlagsToPlatform(const ArchSpec &arch,
unsigned flags) {
MmapArgList PlatformOpenBSD::GetMmapArgumentList(const ArchSpec &arch,
addr_t addr, addr_t length,
unsigned prot, unsigned flags,
addr_t fd, addr_t offset) {
uint64_t flags_platform = 0;
if (flags & eMmapFlagsPrivate)
flags_platform |= MAP_PRIVATE;
if (flags & eMmapFlagsAnon)
flags_platform |= MAP_ANON;
return flags_platform;
MmapArgList args({addr, length, prot, flags_platform, fd, offset});
return args;
}

View File

@ -53,8 +53,10 @@ public:
void CalculateTrapHandlerSymbolNames() override;
uint64_t ConvertMmapFlagsToPlatform(const ArchSpec &arch,
unsigned flags) override;
MmapArgList GetMmapArgumentList(const ArchSpec &arch, lldb::addr_t addr,
lldb::addr_t length, unsigned prot,
unsigned flags, lldb::addr_t fd,
lldb::addr_t offset) override;
private:
DISALLOW_COPY_AND_ASSIGN(PlatformOpenBSD);

View File

@ -64,7 +64,7 @@ bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
options.SetTimeout(std::chrono::milliseconds(500));
options.SetTrapExceptions(false);
addr_t prot_arg, flags_arg = 0;
addr_t prot_arg;
if (prot == eMmapProtNone)
prot_arg = PROT_NONE;
else {
@ -77,11 +77,6 @@ bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
prot_arg |= PROT_WRITE;
}
const ArchSpec arch = process->GetTarget().GetArchitecture();
flags_arg =
process->GetTarget().GetPlatform()->ConvertMmapFlagsToPlatform(arch,
flags);
AddressRange mmap_range;
if (sc.GetAddressRange(range_scope, 0, use_inline_block_range,
mmap_range)) {
@ -89,7 +84,10 @@ bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
process->GetTarget().GetScratchClangASTContext();
CompilerType clang_void_ptr_type =
clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
lldb::addr_t args[] = {addr, length, prot_arg, flags_arg, fd, offset};
const ArchSpec arch = process->GetTarget().GetArchitecture();
MmapArgList args =
process->GetTarget().GetPlatform()->GetMmapArgumentList(
arch, addr, length, prot_arg, flags, fd, offset);
lldb::ThreadPlanSP call_plan_sp(
new ThreadPlanCallFunction(*thread, mmap_range.GetBaseAddress(),
clang_void_ptr_type, args, options));

View File

@ -1316,14 +1316,18 @@ Status Platform::Unlink(const FileSpec &path) {
return error;
}
uint64_t Platform::ConvertMmapFlagsToPlatform(const ArchSpec &arch,
unsigned flags) {
MmapArgList Platform::GetMmapArgumentList(const ArchSpec &arch, addr_t addr,
addr_t length, unsigned prot,
unsigned flags, addr_t fd,
addr_t offset) {
uint64_t flags_platform = 0;
if (flags & eMmapFlagsPrivate)
flags_platform |= MAP_PRIVATE;
if (flags & eMmapFlagsAnon)
flags_platform |= MAP_ANON;
return flags_platform;
MmapArgList args({addr, length, prot, flags_platform, fd, offset});
return args;
}
lldb_private::Status Platform::RunShellCommand(