Commit 83425dec by Nicolas Capens Committed by Nicolas Capens

Support 64-bit jump tables with LP64 data model.

BUG=swiftshader:9 Change-Id: I779abfe7775632e1108e9d608bf21a63c8cefe9e Reviewed-on: https://chromium-review.googlesource.com/407882Reviewed-by: 's avatarJim Stichnoth <stichnot@chromium.org> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 21f78bb1
......@@ -45,11 +45,12 @@ void ELFDataSection::appendZeros(ELFStreamer &Str, SizeT NumBytes) {
void ELFDataSection::appendRelocationOffset(ELFStreamer &Str, bool IsRela,
RelocOffsetT RelocOffset) {
const SizeT RelocAddrSize = typeWidthInBytes(getPointerType());
if (IsRela) {
appendZeros(Str, RelocAddrSize);
return;
}
static_assert(RelocAddrSize == 4, " writeLE32 assumes RelocAddrSize is 4");
assert(RelocAddrSize == 4 && " writeLE32 assumes RelocAddrSize is 4");
Str.writeLE32(RelocOffset);
Header.sh_size += RelocAddrSize;
}
......
......@@ -1773,8 +1773,7 @@ void InstImpl<TraitsType>::InstX86Round::emit(const Cfg *Func) const {
Ostream &Str = Func->getContext()->getStrEmit();
assert(this->getSrcSize() == 3);
Str << "\t" << this->Opcode
<< Traits::TypeAttributes[this->getDest()->getType()].SpSdString
<< "\t";
<< Traits::TypeAttributes[this->getDest()->getType()].SpSdString << "\t";
this->getSrc(1)->emit(Func);
Str << ", ";
this->getSrc(0)->emit(Func);
......
......@@ -592,9 +592,11 @@ void TargetX8664::lowerIndirectJump(Variable *JumpTarget) {
std::unique_ptr<AutoBundle> Bundler;
if (!NeedSandboxing) {
Variable *T = makeReg(IceType_i64);
_movzx(T, JumpTarget);
JumpTarget = T;
if (JumpTarget->getType() != IceType_i64) {
Variable *T = makeReg(IceType_i64);
_movzx(T, JumpTarget);
JumpTarget = T;
}
} else {
Variable *T = makeReg(IceType_i32);
Variable *T64 = makeReg(IceType_i64);
......
......@@ -6851,6 +6851,7 @@ void TargetX86Base<TraitsType>::lowerCaseCluster(const CaseCluster &Case,
constexpr RelocOffsetT RelocOffset = 0;
constexpr Variable *NoBase = nullptr;
constexpr Constant *NoOffset = nullptr;
auto JTName = GlobalString::createWithString(Ctx, JumpTable->getName());
Constant *Offset = Ctx->getConstantSym(RelocOffset, JTName);
uint16_t Shift = typeWidthInBytesLog2(PointerType);
......@@ -6860,9 +6861,16 @@ void TargetX86Base<TraitsType>::lowerCaseCluster(const CaseCluster &Case,
if (Traits::Is64Bit && NeedSandboxing) {
assert(Index != nullptr && Index->getType() == IceType_i32);
}
auto *TargetInMemory = X86OperandMem::create(Func, PointerType, NoBase,
Offset, Index, Shift, Segment);
_mov(Target, TargetInMemory);
if (PointerType == IceType_i32) {
_mov(Target, X86OperandMem::create(Func, PointerType, NoBase, Offset,
Index, Shift, Segment));
} else {
auto *Base = makeReg(IceType_i64);
_lea(Base, X86OperandMem::create(Func, IceType_void, NoBase, Offset));
_mov(Target, X86OperandMem::create(Func, PointerType, Base, NoOffset,
Index, Shift, Segment));
}
lowerIndirectJump(Target);
......@@ -8357,8 +8365,11 @@ void TargetDataX86<TraitsType>::lowerJumpTables() {
switch (getFlags().getOutFileType()) {
case FT_Elf: {
ELFObjectWriter *Writer = Ctx->getObjectWriter();
constexpr FixupKind FK_Abs64 = llvm::ELF::R_X86_64_64;
const FixupKind RelocationKind =
(getPointerType() == IceType_i32) ? Traits::FK_Abs : FK_Abs64;
for (const JumpTableData &JT : Ctx->getJumpTables())
Writer->writeJumpTable(JT, Traits::FK_Abs, IsPIC);
Writer->writeJumpTable(JT, RelocationKind, IsPIC);
} break;
case FT_Asm:
// Already emitted from Cfg
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment