From e04ed7e45f194f14a7b28bbf3f55694d8e2bcf80 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Sun, 28 Nov 2010 14:17:56 +0000 Subject: [PATCH] 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 --- include/llvm/MC/MCFixup.h | 15 ++++++++----- lib/MC/ELFObjectWriter.cpp | 26 +++++++++++++---------- lib/MC/MCCodeEmitter.cpp | 7 ++++-- lib/MC/MCELFStreamer.cpp | 2 +- lib/MC/MCMachOStreamer.cpp | 2 +- lib/MC/MCPureStreamer.cpp | 2 +- lib/MC/MachObjectWriter.cpp | 12 +++++------ lib/MC/WinCOFFObjectWriter.cpp | 2 +- lib/MC/WinCOFFStreamer.cpp | 2 +- lib/Target/MBlaze/MBlazeAsmBackend.cpp | 5 ++--- lib/Target/MBlaze/MBlazeFixupKinds.h | 24 --------------------- lib/Target/MBlaze/MBlazeMCCodeEmitter.cpp | 21 ++---------------- lib/Target/X86/X86AsmBackend.cpp | 6 +++--- lib/Target/X86/X86FixupKinds.h | 5 +---- lib/Target/X86/X86MCCodeEmitter.cpp | 23 ++++++-------------- 15 files changed, 56 insertions(+), 98 deletions(-) delete mode 100644 lib/Target/MBlaze/MBlazeFixupKinds.h diff --git a/include/llvm/MC/MCFixup.h b/include/llvm/MC/MCFixup.h index eed4c349e84..5352c642e62 100644 --- a/include/llvm/MC/MCFixup.h +++ b/include/llvm/MC/MCFixup.h @@ -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; } } }; diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 3b649dbbd25..4b978368ecf 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -31,7 +31,6 @@ #include "../Target/X86/X86FixupKinds.h" #include "../Target/ARM/ARMFixupKinds.h" -#include "../Target/MBlaze/MBlazeFixupKinds.h" #include 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; } } diff --git a/lib/MC/MCCodeEmitter.cpp b/lib/MC/MCCodeEmitter.cpp index d5132378554..b11751c27e8 100644 --- a/lib/MC/MCCodeEmitter.cpp +++ b/lib/MC/MCCodeEmitter.cpp @@ -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]; } diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index ec28a902a20..5b707cb2189 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -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); } } diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp index 88fa2304932..39b1d4fd4ae 100644 --- a/lib/MC/MCMachOStreamer.cpp +++ b/lib/MC/MCMachOStreamer.cpp @@ -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); } } diff --git a/lib/MC/MCPureStreamer.cpp b/lib/MC/MCPureStreamer.cpp index 6af1659b935..2dfb389f092 100644 --- a/lib/MC/MCPureStreamer.cpp +++ b/lib/MC/MCPureStreamer.cpp @@ -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); } } diff --git a/lib/MC/MachObjectWriter.cpp b/lib/MC/MachObjectWriter.cpp index a70f1c3d224..45d2ff74912 100644 --- a/lib/MC/MachObjectWriter.cpp +++ b/lib/MC/MachObjectWriter.cpp @@ -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; diff --git a/lib/MC/WinCOFFObjectWriter.cpp b/lib/MC/WinCOFFObjectWriter.cpp index fd79203fdac..b330bddce6f 100644 --- a/lib/MC/WinCOFFObjectWriter.cpp +++ b/lib/MC/WinCOFFObjectWriter.cpp @@ -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 diff --git a/lib/MC/WinCOFFStreamer.cpp b/lib/MC/WinCOFFStreamer.cpp index 376751be515..0f0224891d5 100644 --- a/lib/MC/WinCOFFStreamer.cpp +++ b/lib/MC/WinCOFFStreamer.cpp @@ -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); } } diff --git a/lib/Target/MBlaze/MBlazeAsmBackend.cpp b/lib/Target/MBlaze/MBlazeAsmBackend.cpp index 7de3cf8424a..56c04199cff 100644 --- a/lib/Target/MBlaze/MBlazeAsmBackend.cpp +++ b/lib/Target/MBlaze/MBlazeAsmBackend.cpp @@ -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; } diff --git a/lib/Target/MBlaze/MBlazeFixupKinds.h b/lib/Target/MBlaze/MBlazeFixupKinds.h deleted file mode 100644 index 72466ca6ebe..00000000000 --- a/lib/Target/MBlaze/MBlazeFixupKinds.h +++ /dev/null @@ -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 diff --git a/lib/Target/MBlaze/MBlazeMCCodeEmitter.cpp b/lib/Target/MBlaze/MBlazeMCCodeEmitter.cpp index 625c73f0f9b..e7fb788b3c7 100644 --- a/lib/Target/MBlaze/MBlazeMCCodeEmitter.cpp +++ b/lib/Target/MBlaze/MBlazeMCCodeEmitter.cpp @@ -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; } diff --git a/lib/Target/X86/X86AsmBackend.cpp b/lib/Target/X86/X86AsmBackend.cpp index f27cd039430..48467c89e5b 100644 --- a/lib/Target/X86/X86AsmBackend.cpp +++ b/lib/Target/X86/X86AsmBackend.cpp @@ -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: diff --git a/lib/Target/X86/X86FixupKinds.h b/lib/Target/X86/X86FixupKinds.h index 64ee3eb3304..95077591d53 100644 --- a/lib/Target/X86/X86FixupKinds.h +++ b/lib/Target/X86/X86FixupKinds.h @@ -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 diff --git a/lib/Target/X86/X86MCCodeEmitter.cpp b/lib/Target/X86/X86MCCodeEmitter.cpp index 586216d774b..bd37999620b 100644 --- a/lib/Target/X86/X86MCCodeEmitter.cpp +++ b/lib/Target/X86/X86MCCodeEmitter.cpp @@ -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)