mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-26 23:29:22 +00:00
Define generic 1, 2 and 4 byte pc relative relocations. They are common
and at least the 4 byte one will be needed to implement the .cfi_* directives. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120240 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9a08ca318e
commit
e04ed7e45f
@ -22,6 +22,9 @@ enum MCFixupKind {
|
||||
FK_Data_2, ///< A two-byte fixup.
|
||||
FK_Data_4, ///< A four-byte fixup.
|
||||
FK_Data_8, ///< A eight-byte fixup.
|
||||
FK_PCRel_1, ///< A one-byte pc relative fixup.
|
||||
FK_PCRel_2, ///< A two-byte pc relative fixup.
|
||||
FK_PCRel_4, ///< A four-byte pc relative fixup.
|
||||
|
||||
FirstTargetFixupKind = 128,
|
||||
|
||||
@ -77,13 +80,15 @@ public:
|
||||
|
||||
/// getKindForSize - Return the generic fixup kind for a value with the given
|
||||
/// size. It is an error to pass an unsupported size.
|
||||
static MCFixupKind getKindForSize(unsigned Size) {
|
||||
static MCFixupKind getKindForSize(unsigned Size, bool isPCRel) {
|
||||
switch (Size) {
|
||||
default: assert(0 && "Invalid generic fixup size!");
|
||||
case 1: return FK_Data_1;
|
||||
case 2: return FK_Data_2;
|
||||
case 4: return FK_Data_4;
|
||||
case 8: return FK_Data_8;
|
||||
case 1: return isPCRel ? FK_PCRel_1 : FK_Data_1;
|
||||
case 2: return isPCRel ? FK_PCRel_2 : FK_Data_2;
|
||||
case 4: return isPCRel ? FK_PCRel_4 : FK_Data_4;
|
||||
case 8:
|
||||
assert(!isPCRel && "8 byte pc relative fixup is not supported.");
|
||||
return FK_Data_8;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -31,7 +31,6 @@
|
||||
|
||||
#include "../Target/X86/X86FixupKinds.h"
|
||||
#include "../Target/ARM/ARMFixupKinds.h"
|
||||
#include "../Target/MBlaze/MBlazeFixupKinds.h"
|
||||
|
||||
#include <vector>
|
||||
using namespace llvm;
|
||||
@ -371,8 +370,9 @@ namespace {
|
||||
switch (Kind) {
|
||||
default:
|
||||
return false;
|
||||
case X86::reloc_pcrel_1byte:
|
||||
case X86::reloc_pcrel_4byte:
|
||||
case FK_PCRel_1:
|
||||
case FK_PCRel_2:
|
||||
case FK_PCRel_4:
|
||||
case X86::reloc_riprel_4byte:
|
||||
case X86::reloc_riprel_4byte_movq_load:
|
||||
return true;
|
||||
@ -401,6 +401,9 @@ namespace {
|
||||
switch (Kind) {
|
||||
default:
|
||||
return false;
|
||||
case FK_PCRel_1:
|
||||
case FK_PCRel_2:
|
||||
case FK_PCRel_4:
|
||||
case ARM::fixup_arm_pcrel_12:
|
||||
case ARM::fixup_arm_vfp_pcrel_12:
|
||||
case ARM::fixup_arm_branch:
|
||||
@ -429,8 +432,9 @@ namespace {
|
||||
switch (Kind) {
|
||||
default:
|
||||
return false;
|
||||
case MBlaze::reloc_pcrel_2byte:
|
||||
case MBlaze::reloc_pcrel_4byte:
|
||||
case FK_PCRel_1:
|
||||
case FK_PCRel_2:
|
||||
case FK_PCRel_4:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1509,10 +1513,10 @@ void MBlazeELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
|
||||
switch ((unsigned)Fixup.getKind()) {
|
||||
default:
|
||||
llvm_unreachable("Unimplemented");
|
||||
case MBlaze::reloc_pcrel_4byte:
|
||||
case FK_PCRel_4:
|
||||
Type = ELF::R_MICROBLAZE_64_PCREL;
|
||||
break;
|
||||
case MBlaze::reloc_pcrel_2byte:
|
||||
case FK_PCRel_2:
|
||||
Type = ELF::R_MICROBLAZE_32_PCREL;
|
||||
break;
|
||||
}
|
||||
@ -1644,7 +1648,7 @@ void X86ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
|
||||
default: llvm_unreachable("invalid fixup kind!");
|
||||
case FK_Data_8: Type = ELF::R_X86_64_64; break;
|
||||
case X86::reloc_signed_4byte:
|
||||
case X86::reloc_pcrel_4byte:
|
||||
case FK_PCRel_4:
|
||||
assert(isInt<32>(Target.getConstant()));
|
||||
switch (Modifier) {
|
||||
default:
|
||||
@ -1670,7 +1674,7 @@ void X86ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
|
||||
Type = ELF::R_X86_64_32;
|
||||
break;
|
||||
case FK_Data_2: Type = ELF::R_X86_64_16; break;
|
||||
case X86::reloc_pcrel_1byte:
|
||||
case FK_PCRel_1:
|
||||
case FK_Data_1: Type = ELF::R_X86_64_8; break;
|
||||
}
|
||||
}
|
||||
@ -1697,7 +1701,7 @@ void X86ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
|
||||
// FIXME: Should we avoid selecting reloc_signed_4byte in 32 bit mode
|
||||
// instead?
|
||||
case X86::reloc_signed_4byte:
|
||||
case X86::reloc_pcrel_4byte:
|
||||
case FK_PCRel_4:
|
||||
case FK_Data_4:
|
||||
switch (Modifier) {
|
||||
default:
|
||||
@ -1735,7 +1739,7 @@ void X86ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
|
||||
}
|
||||
break;
|
||||
case FK_Data_2: Type = ELF::R_386_16; break;
|
||||
case X86::reloc_pcrel_1byte:
|
||||
case FK_PCRel_1:
|
||||
case FK_Data_1: Type = ELF::R_386_8; break;
|
||||
}
|
||||
}
|
||||
|
@ -22,9 +22,12 @@ const MCFixupKindInfo &MCCodeEmitter::getFixupKindInfo(MCFixupKind Kind) const {
|
||||
{ "FK_Data_1", 0, 8, 0 },
|
||||
{ "FK_Data_2", 0, 16, 0 },
|
||||
{ "FK_Data_4", 0, 32, 0 },
|
||||
{ "FK_Data_8", 0, 64, 0 }
|
||||
{ "FK_Data_8", 0, 64, 0 },
|
||||
{ "FK_PCRel_1", 0, 8, MCFixupKindInfo::FKF_IsPCRel },
|
||||
{ "FK_PCRel_2", 0, 16, MCFixupKindInfo::FKF_IsPCRel },
|
||||
{ "FK_PCRel_4", 0, 32, MCFixupKindInfo::FKF_IsPCRel }
|
||||
};
|
||||
|
||||
assert(Kind <= 3 && "Unknown fixup kind");
|
||||
assert(Kind <= 6 && "Unknown fixup kind");
|
||||
return Builtins[Kind];
|
||||
}
|
||||
|
@ -398,7 +398,7 @@ void MCELFStreamer::EmitValue(const MCExpr *Value, unsigned Size,
|
||||
DF->getContents().push_back(uint8_t(AbsValue >> (i * 8)));
|
||||
} else {
|
||||
DF->addFixup(MCFixup::Create(DF->getContents().size(), AddValueSymbols(Value),
|
||||
MCFixup::getKindForSize(Size)));
|
||||
MCFixup::getKindForSize(Size, false)));
|
||||
DF->getContents().resize(DF->getContents().size() + Size, 0);
|
||||
}
|
||||
}
|
||||
|
@ -337,7 +337,7 @@ void MCMachOStreamer::EmitValue(const MCExpr *Value, unsigned Size,
|
||||
} else {
|
||||
DF->addFixup(MCFixup::Create(DF->getContents().size(),
|
||||
AddValueSymbols(Value),
|
||||
MCFixup::getKindForSize(Size)));
|
||||
MCFixup::getKindForSize(Size, false)));
|
||||
DF->getContents().resize(DF->getContents().size() + Size, 0);
|
||||
}
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ void MCPureStreamer::EmitValue(const MCExpr *Value, unsigned Size,
|
||||
} else {
|
||||
DF->addFixup(MCFixup::Create(DF->getContents().size(),
|
||||
AddValueSymbols(Value),
|
||||
MCFixup::getKindForSize(Size)));
|
||||
MCFixup::getKindForSize(Size, false)));
|
||||
DF->getContents().resize(DF->getContents().size() + Size, 0);
|
||||
}
|
||||
}
|
||||
|
@ -32,11 +32,11 @@ using namespace llvm::object;
|
||||
static unsigned getFixupKindLog2Size(unsigned Kind) {
|
||||
switch (Kind) {
|
||||
default: llvm_unreachable("invalid fixup kind!");
|
||||
case X86::reloc_pcrel_1byte:
|
||||
case FK_PCRel_1:
|
||||
case FK_Data_1: return 0;
|
||||
case X86::reloc_pcrel_2byte:
|
||||
case FK_PCRel_2:
|
||||
case FK_Data_2: return 1;
|
||||
case X86::reloc_pcrel_4byte:
|
||||
case FK_PCRel_4:
|
||||
case X86::reloc_riprel_4byte:
|
||||
case X86::reloc_riprel_4byte_movq_load:
|
||||
case X86::reloc_signed_4byte:
|
||||
@ -49,9 +49,9 @@ static bool isFixupKindPCRel(unsigned Kind) {
|
||||
switch (Kind) {
|
||||
default:
|
||||
return false;
|
||||
case X86::reloc_pcrel_1byte:
|
||||
case X86::reloc_pcrel_2byte:
|
||||
case X86::reloc_pcrel_4byte:
|
||||
case FK_PCRel_1:
|
||||
case FK_PCRel_2:
|
||||
case FK_PCRel_4:
|
||||
case X86::reloc_riprel_4byte:
|
||||
case X86::reloc_riprel_4byte_movq_load:
|
||||
return true;
|
||||
|
@ -689,7 +689,7 @@ void WinCOFFObjectWriter::RecordRelocation(const MCAssembler &Asm,
|
||||
Reloc.Data.VirtualAddress += Fixup.getOffset();
|
||||
|
||||
switch ((unsigned)Fixup.getKind()) {
|
||||
case X86::reloc_pcrel_4byte:
|
||||
case FK_PCRel_4:
|
||||
case X86::reloc_riprel_4byte:
|
||||
case X86::reloc_riprel_4byte_movq_load:
|
||||
Reloc.Data.Type = Is64Bit ? COFF::IMAGE_REL_AMD64_REL32
|
||||
|
@ -363,7 +363,7 @@ void WinCOFFStreamer::EmitValue(const MCExpr *Value, unsigned Size,
|
||||
} else {
|
||||
DF->addFixup(MCFixup::Create(DF->getContents().size(),
|
||||
AddValueSymbols(Value),
|
||||
MCFixup::getKindForSize(Size)));
|
||||
MCFixup::getKindForSize(Size, false)));
|
||||
DF->getContents().resize(DF->getContents().size() + Size, 0);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "llvm/Target/TargetAsmBackend.h"
|
||||
#include "MBlaze.h"
|
||||
#include "MBlazeELFWriterInfo.h"
|
||||
#include "MBlazeFixupKinds.h"
|
||||
#include "llvm/ADT/Twine.h"
|
||||
#include "llvm/MC/MCAssembler.h"
|
||||
#include "llvm/MC/MCAsmLayout.h"
|
||||
@ -32,9 +31,9 @@ static unsigned getFixupKindSize(unsigned Kind) {
|
||||
switch (Kind) {
|
||||
default: assert(0 && "invalid fixup kind!");
|
||||
case FK_Data_1: return 1;
|
||||
case MBlaze::reloc_pcrel_2byte:
|
||||
case FK_PCRel_2:
|
||||
case FK_Data_2: return 2;
|
||||
case MBlaze::reloc_pcrel_4byte:
|
||||
case FK_PCRel_4:
|
||||
case FK_Data_4: return 4;
|
||||
case FK_Data_8: return 8;
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
//===-- MBlaze/MBlazeFixupKinds.h - MBlaze Fixup Entries --------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_MBLAZE_MBLAZEFIXUPKINDS_H
|
||||
#define LLVM_MBLAZE_MBLAZEFIXUPKINDS_H
|
||||
|
||||
#include "llvm/MC/MCFixup.h"
|
||||
|
||||
namespace llvm {
|
||||
namespace MBlaze {
|
||||
enum Fixups {
|
||||
reloc_pcrel_4byte = FirstTargetFixupKind, // 32-bit pcrel, e.g. a brlid
|
||||
reloc_pcrel_2byte // 16-bit pcrel, e.g. beqid
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -14,7 +14,6 @@
|
||||
#define DEBUG_TYPE "mccodeemitter"
|
||||
#include "MBlaze.h"
|
||||
#include "MBlazeInstrInfo.h"
|
||||
#include "MBlazeFixupKinds.h"
|
||||
#include "llvm/MC/MCCodeEmitter.h"
|
||||
#include "llvm/MC/MCExpr.h"
|
||||
#include "llvm/MC/MCInst.h"
|
||||
@ -56,22 +55,6 @@ public:
|
||||
return 2;
|
||||
}
|
||||
|
||||
const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const {
|
||||
const static MCFixupKindInfo Infos[] = {
|
||||
// name offset bits flags
|
||||
{ "reloc_pcrel_4byte", 2, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
|
||||
{ "reloc_pcrel_2byte", 2, 2 * 8, MCFixupKindInfo::FKF_IsPCRel } };
|
||||
|
||||
if (Kind < FirstTargetFixupKind)
|
||||
return MCCodeEmitter::getFixupKindInfo(Kind);
|
||||
|
||||
if (unsigned(Kind-FirstTargetFixupKind) < getNumFixupKinds())
|
||||
return Infos[Kind - FirstTargetFixupKind];
|
||||
|
||||
assert(0 && "Invalid fixup kind.");
|
||||
return Infos[0];
|
||||
}
|
||||
|
||||
static unsigned GetMBlazeRegNum(const MCOperand &MO) {
|
||||
// FIXME: getMBlazeRegisterNumbering() is sufficient?
|
||||
assert(0 && "MBlazeMCCodeEmitter::GetMBlazeRegNum() not yet implemented.");
|
||||
@ -181,13 +164,13 @@ EmitImmediate(const MCInst &MI, unsigned opNo, bool pcrel, unsigned &CurByte,
|
||||
MCFixupKind FixupKind;
|
||||
switch (MI.getOpcode()) {
|
||||
default:
|
||||
FixupKind = pcrel ? MCFixupKind(MBlaze::reloc_pcrel_2byte) : FK_Data_2;
|
||||
FixupKind = pcrel ? FK_PCRel_2 : FK_Data_2;
|
||||
Fixups.push_back(MCFixup::Create(0,oper.getExpr(),FixupKind));
|
||||
break;
|
||||
case MBlaze::ORI32:
|
||||
case MBlaze::ADDI32:
|
||||
case MBlaze::BRLID32:
|
||||
FixupKind = pcrel ? MCFixupKind(MBlaze::reloc_pcrel_4byte) : FK_Data_4;
|
||||
FixupKind = pcrel ? FK_PCRel_4 : FK_Data_4;
|
||||
Fixups.push_back(MCFixup::Create(0,oper.getExpr(),FixupKind));
|
||||
break;
|
||||
}
|
||||
|
@ -29,11 +29,11 @@ using namespace llvm;
|
||||
static unsigned getFixupKindLog2Size(unsigned Kind) {
|
||||
switch (Kind) {
|
||||
default: assert(0 && "invalid fixup kind!");
|
||||
case X86::reloc_pcrel_1byte:
|
||||
case FK_PCRel_1:
|
||||
case FK_Data_1: return 0;
|
||||
case X86::reloc_pcrel_2byte:
|
||||
case FK_PCRel_2:
|
||||
case FK_Data_2: return 1;
|
||||
case X86::reloc_pcrel_4byte:
|
||||
case FK_PCRel_4:
|
||||
case X86::reloc_riprel_4byte:
|
||||
case X86::reloc_riprel_4byte_movq_load:
|
||||
case X86::reloc_signed_4byte:
|
||||
|
@ -15,10 +15,7 @@
|
||||
namespace llvm {
|
||||
namespace X86 {
|
||||
enum Fixups {
|
||||
reloc_pcrel_4byte = FirstTargetFixupKind, // 32-bit pcrel, e.g. a branch.
|
||||
reloc_pcrel_1byte, // 8-bit pcrel, e.g. branch_1
|
||||
reloc_pcrel_2byte, // 16-bit pcrel, e.g. callw
|
||||
reloc_riprel_4byte, // 32-bit rip-relative
|
||||
reloc_riprel_4byte = FirstTargetFixupKind, // 32-bit rip-relative
|
||||
reloc_riprel_4byte_movq_load, // 32-bit rip-relative in movq
|
||||
reloc_signed_4byte, // 32-bit signed. Unlike FK_Data_4
|
||||
// this will be sign extended at
|
||||
|
@ -44,9 +44,6 @@ public:
|
||||
|
||||
const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const {
|
||||
const static MCFixupKindInfo Infos[] = {
|
||||
{ "reloc_pcrel_4byte", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
|
||||
{ "reloc_pcrel_1byte", 0, 1 * 8, MCFixupKindInfo::FKF_IsPCRel },
|
||||
{ "reloc_pcrel_2byte", 0, 2 * 8, MCFixupKindInfo::FKF_IsPCRel },
|
||||
{ "reloc_riprel_4byte", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
|
||||
{ "reloc_riprel_4byte_movq_load", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
|
||||
{ "reloc_signed_4byte", 0, 4 * 8, 0},
|
||||
@ -173,13 +170,7 @@ static MCFixupKind getImmFixupKind(uint64_t TSFlags) {
|
||||
unsigned Size = X86II::getSizeOfImm(TSFlags);
|
||||
bool isPCRel = X86II::isImmPCRel(TSFlags);
|
||||
|
||||
switch (Size) {
|
||||
default: assert(0 && "Unknown immediate size");
|
||||
case 1: return isPCRel ? MCFixupKind(X86::reloc_pcrel_1byte) : FK_Data_1;
|
||||
case 2: return isPCRel ? MCFixupKind(X86::reloc_pcrel_2byte) : FK_Data_2;
|
||||
case 4: return isPCRel ? MCFixupKind(X86::reloc_pcrel_4byte) : FK_Data_4;
|
||||
case 8: assert(!isPCRel); return FK_Data_8;
|
||||
}
|
||||
return MCFixup::getKindForSize(Size, isPCRel);
|
||||
}
|
||||
|
||||
/// Is32BitMemOperand - Return true if the specified instruction with a memory
|
||||
@ -222,9 +213,9 @@ EmitImmediate(const MCOperand &DispOp, unsigned Size, MCFixupKind FixupKind,
|
||||
if (DispOp.isImm()) {
|
||||
// If this is a simple integer displacement that doesn't require a relocation,
|
||||
// emit it now.
|
||||
if (FixupKind != MCFixupKind(X86::reloc_pcrel_1byte) &&
|
||||
FixupKind != MCFixupKind(X86::reloc_pcrel_2byte) &&
|
||||
FixupKind != MCFixupKind(X86::reloc_pcrel_4byte)) {
|
||||
if (FixupKind != FK_PCRel_1 &&
|
||||
FixupKind != FK_PCRel_2 &&
|
||||
FixupKind != FK_PCRel_4) {
|
||||
EmitConstant(DispOp.getImm()+ImmOffset, Size, CurByte, OS);
|
||||
return;
|
||||
}
|
||||
@ -243,13 +234,13 @@ EmitImmediate(const MCOperand &DispOp, unsigned Size, MCFixupKind FixupKind,
|
||||
|
||||
// If the fixup is pc-relative, we need to bias the value to be relative to
|
||||
// the start of the field, not the end of the field.
|
||||
if (FixupKind == MCFixupKind(X86::reloc_pcrel_4byte) ||
|
||||
if (FixupKind == FK_PCRel_4 ||
|
||||
FixupKind == MCFixupKind(X86::reloc_riprel_4byte) ||
|
||||
FixupKind == MCFixupKind(X86::reloc_riprel_4byte_movq_load))
|
||||
ImmOffset -= 4;
|
||||
if (FixupKind == MCFixupKind(X86::reloc_pcrel_2byte))
|
||||
if (FixupKind == FK_PCRel_2)
|
||||
ImmOffset -= 2;
|
||||
if (FixupKind == MCFixupKind(X86::reloc_pcrel_1byte))
|
||||
if (FixupKind == FK_PCRel_1)
|
||||
ImmOffset -= 1;
|
||||
|
||||
if (ImmOffset)
|
||||
|
Loading…
Reference in New Issue
Block a user