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) { ...@@ -45,11 +45,12 @@ void ELFDataSection::appendZeros(ELFStreamer &Str, SizeT NumBytes) {
void ELFDataSection::appendRelocationOffset(ELFStreamer &Str, bool IsRela, void ELFDataSection::appendRelocationOffset(ELFStreamer &Str, bool IsRela,
RelocOffsetT RelocOffset) { RelocOffsetT RelocOffset) {
const SizeT RelocAddrSize = typeWidthInBytes(getPointerType());
if (IsRela) { if (IsRela) {
appendZeros(Str, RelocAddrSize); appendZeros(Str, RelocAddrSize);
return; return;
} }
static_assert(RelocAddrSize == 4, " writeLE32 assumes RelocAddrSize is 4"); assert(RelocAddrSize == 4 && " writeLE32 assumes RelocAddrSize is 4");
Str.writeLE32(RelocOffset); Str.writeLE32(RelocOffset);
Header.sh_size += RelocAddrSize; Header.sh_size += RelocAddrSize;
} }
......
...@@ -1773,8 +1773,7 @@ void InstImpl<TraitsType>::InstX86Round::emit(const Cfg *Func) const { ...@@ -1773,8 +1773,7 @@ void InstImpl<TraitsType>::InstX86Round::emit(const Cfg *Func) const {
Ostream &Str = Func->getContext()->getStrEmit(); Ostream &Str = Func->getContext()->getStrEmit();
assert(this->getSrcSize() == 3); assert(this->getSrcSize() == 3);
Str << "\t" << this->Opcode Str << "\t" << this->Opcode
<< Traits::TypeAttributes[this->getDest()->getType()].SpSdString << Traits::TypeAttributes[this->getDest()->getType()].SpSdString << "\t";
<< "\t";
this->getSrc(1)->emit(Func); this->getSrc(1)->emit(Func);
Str << ", "; Str << ", ";
this->getSrc(0)->emit(Func); this->getSrc(0)->emit(Func);
......
...@@ -592,9 +592,11 @@ void TargetX8664::lowerIndirectJump(Variable *JumpTarget) { ...@@ -592,9 +592,11 @@ void TargetX8664::lowerIndirectJump(Variable *JumpTarget) {
std::unique_ptr<AutoBundle> Bundler; std::unique_ptr<AutoBundle> Bundler;
if (!NeedSandboxing) { if (!NeedSandboxing) {
Variable *T = makeReg(IceType_i64); if (JumpTarget->getType() != IceType_i64) {
_movzx(T, JumpTarget); Variable *T = makeReg(IceType_i64);
JumpTarget = T; _movzx(T, JumpTarget);
JumpTarget = T;
}
} else { } else {
Variable *T = makeReg(IceType_i32); Variable *T = makeReg(IceType_i32);
Variable *T64 = makeReg(IceType_i64); Variable *T64 = makeReg(IceType_i64);
......
...@@ -6851,6 +6851,7 @@ void TargetX86Base<TraitsType>::lowerCaseCluster(const CaseCluster &Case, ...@@ -6851,6 +6851,7 @@ void TargetX86Base<TraitsType>::lowerCaseCluster(const CaseCluster &Case,
constexpr RelocOffsetT RelocOffset = 0; constexpr RelocOffsetT RelocOffset = 0;
constexpr Variable *NoBase = nullptr; constexpr Variable *NoBase = nullptr;
constexpr Constant *NoOffset = nullptr;
auto JTName = GlobalString::createWithString(Ctx, JumpTable->getName()); auto JTName = GlobalString::createWithString(Ctx, JumpTable->getName());
Constant *Offset = Ctx->getConstantSym(RelocOffset, JTName); Constant *Offset = Ctx->getConstantSym(RelocOffset, JTName);
uint16_t Shift = typeWidthInBytesLog2(PointerType); uint16_t Shift = typeWidthInBytesLog2(PointerType);
...@@ -6860,9 +6861,16 @@ void TargetX86Base<TraitsType>::lowerCaseCluster(const CaseCluster &Case, ...@@ -6860,9 +6861,16 @@ void TargetX86Base<TraitsType>::lowerCaseCluster(const CaseCluster &Case,
if (Traits::Is64Bit && NeedSandboxing) { if (Traits::Is64Bit && NeedSandboxing) {
assert(Index != nullptr && Index->getType() == IceType_i32); assert(Index != nullptr && Index->getType() == IceType_i32);
} }
auto *TargetInMemory = X86OperandMem::create(Func, PointerType, NoBase,
Offset, Index, Shift, Segment); if (PointerType == IceType_i32) {
_mov(Target, TargetInMemory); _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); lowerIndirectJump(Target);
...@@ -8357,8 +8365,11 @@ void TargetDataX86<TraitsType>::lowerJumpTables() { ...@@ -8357,8 +8365,11 @@ void TargetDataX86<TraitsType>::lowerJumpTables() {
switch (getFlags().getOutFileType()) { switch (getFlags().getOutFileType()) {
case FT_Elf: { case FT_Elf: {
ELFObjectWriter *Writer = Ctx->getObjectWriter(); 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()) for (const JumpTableData &JT : Ctx->getJumpTables())
Writer->writeJumpTable(JT, Traits::FK_Abs, IsPIC); Writer->writeJumpTable(JT, RelocationKind, IsPIC);
} break; } break;
case FT_Asm: case FT_Asm:
// Already emitted from Cfg // 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