X86 PIC JIT bug fix: relocations for constantpool and jumptable.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45515 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/X86/X86CodeEmitter.cpp b/lib/Target/X86/X86CodeEmitter.cpp
index 7e6fb2a..8b8ea0c 100644
--- a/lib/Target/X86/X86CodeEmitter.cpp
+++ b/lib/Target/X86/X86CodeEmitter.cpp
@@ -246,13 +246,12 @@
emitGlobalAddress(RelocOp->getGlobal(), rt, RelocOp->getOffset(),
PCAdj, false, IsPIC);
} else if (RelocOp->isConstantPoolIndex()) {
- // Must be in 64-bit mode.
- emitConstPoolAddress(RelocOp->getIndex(), X86::reloc_pcrel_word,
+ unsigned rt = Is64BitMode ? X86::reloc_pcrel_word : X86::reloc_picrel_word;
+ emitConstPoolAddress(RelocOp->getIndex(), rt,
RelocOp->getOffset(), PCAdj, IsPIC);
} else if (RelocOp->isJumpTableIndex()) {
- // Must be in 64-bit mode.
- emitJumpTableAddress(RelocOp->getIndex(), X86::reloc_pcrel_word,
- PCAdj, IsPIC);
+ unsigned rt = Is64BitMode ? X86::reloc_pcrel_word : X86::reloc_picrel_word;
+ emitJumpTableAddress(RelocOp->getIndex(), rt, PCAdj, IsPIC);
} else {
assert(0 && "Unknown value to relocate!");
}
@@ -269,14 +268,14 @@
if (Op3.isGlobalAddress()) {
DispForReloc = &Op3;
} else if (Op3.isConstantPoolIndex()) {
- if (Is64BitMode) {
+ if (Is64BitMode || IsPIC) {
DispForReloc = &Op3;
} else {
DispVal += MCE.getConstantPoolEntryAddress(Op3.getIndex());
DispVal += Op3.getOffset();
}
} else if (Op3.isJumpTableIndex()) {
- if (Is64BitMode) {
+ if (Is64BitMode || IsPIC) {
DispForReloc = &Op3;
} else {
DispVal += MCE.getJumpTableEntryAddress(Op3.getIndex());