mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 02:52:53 +02:00
[JITLink] Read MachO Header CPU field only in jitLink_MachO.
It's the only field we need in this function.
This commit is contained in:
parent
87434205b4
commit
2ccfae6930
@ -16,9 +16,9 @@
|
|||||||
#include "llvm/BinaryFormat/MachO.h"
|
#include "llvm/BinaryFormat/MachO.h"
|
||||||
#include "llvm/ExecutionEngine/JITLink/MachO_arm64.h"
|
#include "llvm/ExecutionEngine/JITLink/MachO_arm64.h"
|
||||||
#include "llvm/ExecutionEngine/JITLink/MachO_x86_64.h"
|
#include "llvm/ExecutionEngine/JITLink/MachO_x86_64.h"
|
||||||
#include "llvm/Support/Endian.h"
|
|
||||||
#include "llvm/Support/Format.h"
|
#include "llvm/Support/Format.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
|
#include "llvm/Support/SwapByteOrder.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@ -34,7 +34,9 @@ void jitLink_MachO(std::unique_ptr<JITLinkContext> Ctx) {
|
|||||||
|
|
||||||
StringRef Data = Ctx->getObjectBuffer().getBuffer();
|
StringRef Data = Ctx->getObjectBuffer().getBuffer();
|
||||||
if (Data.size() < 4) {
|
if (Data.size() < 4) {
|
||||||
Ctx->notifyFailed(make_error<JITLinkError>("Truncated MachO buffer"));
|
StringRef BufferName = Ctx->getObjectBuffer().getBufferIdentifier();
|
||||||
|
Ctx->notifyFailed(make_error<JITLinkError>("Truncated MachO buffer \"" +
|
||||||
|
BufferName + "\""));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,20 +53,26 @@ void jitLink_MachO(std::unique_ptr<JITLinkContext> Ctx) {
|
|||||||
make_error<JITLinkError>("MachO 32-bit platforms not supported"));
|
make_error<JITLinkError>("MachO 32-bit platforms not supported"));
|
||||||
return;
|
return;
|
||||||
} else if (Magic == MachO::MH_MAGIC_64 || Magic == MachO::MH_CIGAM_64) {
|
} else if (Magic == MachO::MH_MAGIC_64 || Magic == MachO::MH_CIGAM_64) {
|
||||||
MachO::mach_header_64 Header;
|
|
||||||
|
|
||||||
memcpy(&Header, Data.data(), sizeof(MachO::mach_header_64));
|
if (Data.size() < sizeof(MachO::mach_header_64)) {
|
||||||
|
StringRef BufferName = Ctx->getObjectBuffer().getBufferIdentifier();
|
||||||
|
Ctx->notifyFailed(make_error<JITLinkError>("Truncated MachO buffer \"" +
|
||||||
|
BufferName + "\""));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the CPU type from the header.
|
||||||
|
uint32_t CPUType;
|
||||||
|
memcpy(&CPUType, Data.data() + 4, sizeof(uint32_t));
|
||||||
if (Magic == MachO::MH_CIGAM_64)
|
if (Magic == MachO::MH_CIGAM_64)
|
||||||
swapStruct(Header);
|
ByteSwap_32(CPUType);
|
||||||
|
|
||||||
LLVM_DEBUG({
|
LLVM_DEBUG({
|
||||||
dbgs() << "jitLink_MachO: cputype = "
|
dbgs() << "jitLink_MachO: cputype = " << format("0x%08" PRIx32, CPUType)
|
||||||
<< format("0x%08" PRIx32, Header.cputype)
|
|
||||||
<< ", cpusubtype = " << format("0x%08" PRIx32, Header.cpusubtype)
|
|
||||||
<< "\n";
|
<< "\n";
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (Header.cputype) {
|
switch (CPUType) {
|
||||||
case MachO::CPU_TYPE_ARM64:
|
case MachO::CPU_TYPE_ARM64:
|
||||||
return jitLink_MachO_arm64(std::move(Ctx));
|
return jitLink_MachO_arm64(std::move(Ctx));
|
||||||
case MachO::CPU_TYPE_X86_64:
|
case MachO::CPU_TYPE_X86_64:
|
||||||
|
Loading…
Reference in New Issue
Block a user