diff options
| author | Hiroshi Inoue <inouehrs@jp.ibm.com> | 2018-05-30 04:48:29 +0000 |
|---|---|---|
| committer | Hiroshi Inoue <inouehrs@jp.ibm.com> | 2018-05-30 04:48:29 +0000 |
| commit | 3872c6c63383d48a5f940bf535877df45b18027f (patch) | |
| tree | aca5849b17fc3421bddf24010c9bac15444b4aac /llvm/lib/ExecutionEngine | |
| parent | 4c2aa9fb0bad1192ac038bb1ac42828238a68670 (diff) | |
| download | bcm5719-llvm-3872c6c63383d48a5f940bf535877df45b18027f.tar.gz bcm5719-llvm-3872c6c63383d48a5f940bf535877df45b18027f.zip | |
[PowerPC] fix broken JIT-compiled code with tail call optimization
The relocation for branch instructions in the dynamic loader of ExecutionEngine assumes branch instructions with R_PPC64_REL24 relocation type are only bl. However, with the tail call optimization, b instructions can be also used to jump into another function.
This patch makes the relocation to keep bits in the branch instruction other than the jump offset to avoid relocation rewrites a b instruction into bl.
Differential Revision: https://reviews.llvm.org/D47456
llvm-svn: 333502
Diffstat (limited to 'llvm/lib/ExecutionEngine')
| -rw-r--r-- | llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index 322883f4fea..e15fd0b124b 100644 --- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -772,8 +772,9 @@ void RuntimeDyldELF::resolvePPC64Relocation(const SectionEntry &Section, int64_t delta = static_cast<int64_t>(Value - FinalAddress + Addend); if (SignExtend64<26>(delta) != delta) llvm_unreachable("Relocation R_PPC64_REL24 overflow"); - // Generates a 'bl <address>' instruction - writeInt32BE(LocalAddress, 0x48000001 | (delta & 0x03FFFFFC)); + // We preserve bits other than LI field, i.e. PO and AA/LK fields. + uint32_t Inst = readBytesUnaligned(LocalAddress, 4); + writeInt32BE(LocalAddress, (Inst & 0xFC000003) | (delta & 0x03FFFFFC)); } break; case ELF::R_PPC64_REL32: { uint64_t FinalAddress = Section.getLoadAddressWithOffset(Offset); |

