From 10f28ec3ef373dd00dfb6e39ee9a4aa59bb8d123 Mon Sep 17 00:00:00 2001 From: Daniel Sanders Date: Thu, 6 Nov 2014 09:53:05 +0000 Subject: [PATCH] [JIT] Fix more missing endian conversions (opcodes for AArch64, ARM, and Mips stub functions, and ARM target in general) Summary: Fixed all of the missing endian conversions that Lang Hames and I identified in RuntimeDyldMachOARM.h. Fixed the opcode emission in RuntimeDyldImpl::createStubFunction() for AArch64, ARM, Mips when the host endian doesn't match the target endian. PowerPC will need changing if it's opcodes are affected by endianness but I've left this for now since I'm unsure if this is the case and it's the only path that specifies the target endian. This patch fixes MachO_ARM_PIC_relocations.s on a big-endian Mips host. This is the last of the known issues on this host. Reviewers: lhames Reviewed By: lhames Subscribers: aemerson, llvm-commits Differential Revision: http://reviews.llvm.org/D6130 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221446 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../RuntimeDyld/RuntimeDyld.cpp | 33 +++++++------------ .../RuntimeDyld/Targets/RuntimeDyldMachOARM.h | 16 ++++----- 2 files changed, 18 insertions(+), 31 deletions(-) diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index 488130112de..83c098ded0c 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -585,28 +585,20 @@ uint8_t *RuntimeDyldImpl::createStubFunction(uint8_t *Addr, // This stub has to be able to access the full address space, // since symbol lookup won't necessarily find a handy, in-range, // PLT stub for functions which could be anywhere. - uint32_t *StubAddr = (uint32_t *)Addr; - // Stub can use ip0 (== x16) to calculate address - *StubAddr = 0xd2e00010; // movz ip0, #:abs_g3: - StubAddr++; - *StubAddr = 0xf2c00010; // movk ip0, #:abs_g2_nc: - StubAddr++; - *StubAddr = 0xf2a00010; // movk ip0, #:abs_g1_nc: - StubAddr++; - *StubAddr = 0xf2800010; // movk ip0, #:abs_g0_nc: - StubAddr++; - *StubAddr = 0xd61f0200; // br ip0 + writeBytesUnaligned(0xd2e00010, Addr, 4); // movz ip0, #:abs_g3: + writeBytesUnaligned(0xf2c00010, Addr+4, 4); // movk ip0, #:abs_g2_nc: + writeBytesUnaligned(0xf2a00010, Addr+8, 4); // movk ip0, #:abs_g1_nc: + writeBytesUnaligned(0xf2800010, Addr+12, 4); // movk ip0, #:abs_g0_nc: + writeBytesUnaligned(0xd61f0200, Addr+16, 4); // br ip0 return Addr; } else if (Arch == Triple::arm || Arch == Triple::armeb) { // TODO: There is only ARM far stub now. We should add the Thumb stub, // and stubs for branches Thumb - ARM and ARM - Thumb. - uint32_t *StubAddr = (uint32_t *)Addr; - *StubAddr = 0xe51ff004; // ldr pc,