From c677e790e5e8ff986ca84229f37751d26bf87f45 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 21 Dec 2011 14:26:29 +0000 Subject: Small refactoring so that RelocNeedsGOT can stay in the target independent side when the target specific bits are moved to the Target directory. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147053 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'lib/MC/ELFObjectWriter.h') diff --git a/lib/MC/ELFObjectWriter.h b/lib/MC/ELFObjectWriter.h index 9adf0b1..3ba722c 100644 --- a/lib/MC/ELFObjectWriter.h +++ b/lib/MC/ELFObjectWriter.h @@ -351,7 +351,7 @@ class ELFObjectWriter : public MCObjectWriter { protected: virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, bool IsPCRel, bool IsRelocWithSymbol, - int64_t Addend) = 0; + int64_t Addend) const = 0; virtual void adjustFixupOffset(const MCFixup &Fixup, uint64_t &RelocOffset) {} }; @@ -368,7 +368,7 @@ class ELFObjectWriter : public MCObjectWriter { protected: virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, bool IsPCRel, bool IsRelocWithSymbol, - int64_t Addend); + int64_t Addend) const; }; @@ -395,11 +395,10 @@ class ELFObjectWriter : public MCObjectWriter { virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, bool IsPCRel, bool IsRelocWithSymbol, - int64_t Addend); + int64_t Addend) const; private: unsigned GetRelocTypeInner(const MCValue &Target, const MCFixup &Fixup, bool IsPCRel) const; - }; //===- PPCELFObjectWriter -------------------------------------------===// @@ -414,7 +413,7 @@ class ELFObjectWriter : public MCObjectWriter { protected: virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, bool IsPCRel, bool IsRelocWithSymbol, - int64_t Addend); + int64_t Addend) const; virtual void adjustFixupOffset(const MCFixup &Fixup, uint64_t &RelocOffset); }; @@ -430,7 +429,7 @@ class ELFObjectWriter : public MCObjectWriter { protected: virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, bool IsPCRel, bool IsRelocWithSymbol, - int64_t Addend); + int64_t Addend) const; }; //===- MipsELFObjectWriter -------------------------------------------===// @@ -453,7 +452,7 @@ class ELFObjectWriter : public MCObjectWriter { virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, bool IsPCRel, bool IsRelocWithSymbol, - int64_t Addend); + int64_t Addend) const; }; } -- cgit v1.1 From edae8e1e4d5bd9b59f18ecef04a248be95d8ca46 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 21 Dec 2011 17:30:17 +0000 Subject: Move the X86 specific bits of the ELF writer to the Target/X86 directory. Other targets will follow shortly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147060 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.h | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'lib/MC/ELFObjectWriter.h') diff --git a/lib/MC/ELFObjectWriter.h b/lib/MC/ELFObjectWriter.h index 3ba722c..32ab198 100644 --- a/lib/MC/ELFObjectWriter.h +++ b/lib/MC/ELFObjectWriter.h @@ -351,27 +351,11 @@ class ELFObjectWriter : public MCObjectWriter { protected: virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, bool IsPCRel, bool IsRelocWithSymbol, - int64_t Addend) const = 0; + int64_t Addend) const; virtual void adjustFixupOffset(const MCFixup &Fixup, uint64_t &RelocOffset) {} }; - //===- X86ELFObjectWriter -------------------------------------------===// - - class X86ELFObjectWriter : public ELFObjectWriter { - public: - X86ELFObjectWriter(MCELFObjectTargetWriter *MOTW, - raw_ostream &_OS, - bool IsLittleEndian); - - virtual ~X86ELFObjectWriter(); - protected: - virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, - bool IsPCRel, bool IsRelocWithSymbol, - int64_t Addend) const; - }; - - //===- ARMELFObjectWriter -------------------------------------------===// class ARMELFObjectWriter : public ELFObjectWriter { -- cgit v1.1 From e8526d030f2cf8cc79f2d923274944cb0fa9c4eb Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 21 Dec 2011 20:09:46 +0000 Subject: Switch from WriteEFlags to getEFlags in preparation for moving it to Target/. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147087 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/MC/ELFObjectWriter.h') diff --git a/lib/MC/ELFObjectWriter.h b/lib/MC/ELFObjectWriter.h index 32ab198..653b821 100644 --- a/lib/MC/ELFObjectWriter.h +++ b/lib/MC/ELFObjectWriter.h @@ -244,7 +244,7 @@ class ELFObjectWriter : public MCObjectWriter { unsigned NumberOfSections); /// Default e_flags = 0 - virtual void WriteEFlags() { Write32(0); } + virtual unsigned getEFlags() { return 0; } virtual void WriteSymbolEntry(MCDataFragment *SymtabF, MCDataFragment *ShndxF, @@ -369,7 +369,7 @@ class ELFObjectWriter : public MCObjectWriter { virtual ~ARMELFObjectWriter(); - virtual void WriteEFlags(); + virtual unsigned getEFlags(); protected: virtual const MCSymbol *ExplicitRelSym(const MCAssembler &Asm, const MCValue &Target, @@ -425,7 +425,7 @@ class ELFObjectWriter : public MCObjectWriter { bool IsLittleEndian); virtual ~MipsELFObjectWriter(); - virtual void WriteEFlags(); + virtual unsigned getEFlags(); protected: virtual const MCSymbol *ExplicitRelSym(const MCAssembler &Asm, -- cgit v1.1 From e99183d2ace21eb25325304c164b21bf2910fc63 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 22 Dec 2011 00:21:50 +0000 Subject: getEFlags is const. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147114 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/MC/ELFObjectWriter.h') diff --git a/lib/MC/ELFObjectWriter.h b/lib/MC/ELFObjectWriter.h index 653b821..59734e8 100644 --- a/lib/MC/ELFObjectWriter.h +++ b/lib/MC/ELFObjectWriter.h @@ -244,7 +244,7 @@ class ELFObjectWriter : public MCObjectWriter { unsigned NumberOfSections); /// Default e_flags = 0 - virtual unsigned getEFlags() { return 0; } + virtual unsigned getEFlags() const { return 0; } virtual void WriteSymbolEntry(MCDataFragment *SymtabF, MCDataFragment *ShndxF, @@ -369,7 +369,7 @@ class ELFObjectWriter : public MCObjectWriter { virtual ~ARMELFObjectWriter(); - virtual unsigned getEFlags(); + virtual unsigned getEFlags() const; protected: virtual const MCSymbol *ExplicitRelSym(const MCAssembler &Asm, const MCValue &Target, @@ -425,7 +425,7 @@ class ELFObjectWriter : public MCObjectWriter { bool IsLittleEndian); virtual ~MipsELFObjectWriter(); - virtual unsigned getEFlags(); + virtual unsigned getEFlags() const; protected: virtual const MCSymbol *ExplicitRelSym(const MCAssembler &Asm, -- cgit v1.1 From 69bbda03918a18bd4477bb254d51346ee3033567 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 22 Dec 2011 00:37:50 +0000 Subject: Move the ARM specific parts of the ELF writer to Target/ARM. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147115 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.h | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) (limited to 'lib/MC/ELFObjectWriter.h') diff --git a/lib/MC/ELFObjectWriter.h b/lib/MC/ELFObjectWriter.h index 59734e8..71140f1 100644 --- a/lib/MC/ELFObjectWriter.h +++ b/lib/MC/ELFObjectWriter.h @@ -152,7 +152,7 @@ class ELFObjectWriter : public MCObjectWriter { const MCFragment &F, const MCFixup &Fixup, bool IsPCRel) const { - return NULL; + return TargetObjectWriter->ExplicitRelSym(Asm, Target, F, Fixup, IsPCRel); } bool is64Bit() const { return TargetObjectWriter->is64Bit(); } @@ -243,8 +243,9 @@ class ELFObjectWriter : public MCObjectWriter { virtual void WriteHeader(uint64_t SectionDataSize, unsigned NumberOfSections); - /// Default e_flags = 0 - virtual unsigned getEFlags() const { return 0; } + virtual unsigned getEFlags() const { + return TargetObjectWriter->getEFlags(); + } virtual void WriteSymbolEntry(MCDataFragment *SymtabF, MCDataFragment *ShndxF, @@ -356,35 +357,6 @@ class ELFObjectWriter : public MCObjectWriter { uint64_t &RelocOffset) {} }; - //===- ARMELFObjectWriter -------------------------------------------===// - - class ARMELFObjectWriter : public ELFObjectWriter { - public: - // FIXME: MCAssembler can't yet return the Subtarget, - enum { DefaultEABIVersion = 0x05000000U }; - - ARMELFObjectWriter(MCELFObjectTargetWriter *MOTW, - raw_ostream &_OS, - bool IsLittleEndian); - - virtual ~ARMELFObjectWriter(); - - virtual unsigned getEFlags() const; - protected: - virtual const MCSymbol *ExplicitRelSym(const MCAssembler &Asm, - const MCValue &Target, - const MCFragment &F, - const MCFixup &Fixup, - bool IsPCRel) const; - - virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, - bool IsPCRel, bool IsRelocWithSymbol, - int64_t Addend) const; - private: - unsigned GetRelocTypeInner(const MCValue &Target, - const MCFixup &Fixup, bool IsPCRel) const; - }; - //===- PPCELFObjectWriter -------------------------------------------===// class PPCELFObjectWriter : public ELFObjectWriter { -- cgit v1.1 From f3a86fb03d196994dc7923351f15d8ed9343013e Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 22 Dec 2011 01:57:09 +0000 Subject: Move PPC bits to lib/Target/PowerPC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147124 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.h | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'lib/MC/ELFObjectWriter.h') diff --git a/lib/MC/ELFObjectWriter.h b/lib/MC/ELFObjectWriter.h index 71140f1..6516fb5 100644 --- a/lib/MC/ELFObjectWriter.h +++ b/lib/MC/ELFObjectWriter.h @@ -353,24 +353,6 @@ class ELFObjectWriter : public MCObjectWriter { virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, bool IsPCRel, bool IsRelocWithSymbol, int64_t Addend) const; - virtual void adjustFixupOffset(const MCFixup &Fixup, - uint64_t &RelocOffset) {} - }; - - //===- PPCELFObjectWriter -------------------------------------------===// - - class PPCELFObjectWriter : public ELFObjectWriter { - public: - PPCELFObjectWriter(MCELFObjectTargetWriter *MOTW, - raw_ostream &_OS, - bool IsLittleEndian); - - virtual ~PPCELFObjectWriter(); - protected: - virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, - bool IsPCRel, bool IsRelocWithSymbol, - int64_t Addend) const; - virtual void adjustFixupOffset(const MCFixup &Fixup, uint64_t &RelocOffset); }; //===- MBlazeELFObjectWriter -------------------------------------------===// -- cgit v1.1 From 4982159b885f1db4cc29b1695841121db85a64a1 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 22 Dec 2011 02:28:24 +0000 Subject: Move the MBlaze ELF writer bits to lib/Target/MBlaze. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147129 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.h | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'lib/MC/ELFObjectWriter.h') diff --git a/lib/MC/ELFObjectWriter.h b/lib/MC/ELFObjectWriter.h index 6516fb5..658a4a9 100644 --- a/lib/MC/ELFObjectWriter.h +++ b/lib/MC/ELFObjectWriter.h @@ -355,21 +355,6 @@ class ELFObjectWriter : public MCObjectWriter { int64_t Addend) const; }; - //===- MBlazeELFObjectWriter -------------------------------------------===// - - class MBlazeELFObjectWriter : public ELFObjectWriter { - public: - MBlazeELFObjectWriter(MCELFObjectTargetWriter *MOTW, - raw_ostream &_OS, - bool IsLittleEndian); - - virtual ~MBlazeELFObjectWriter(); - protected: - virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, - bool IsPCRel, bool IsRelocWithSymbol, - int64_t Addend) const; - }; - //===- MipsELFObjectWriter -------------------------------------------===// class MipsELFObjectWriter : public ELFObjectWriter { -- cgit v1.1 From 090445967f0b5988446faffefd1d0722f982bc7a Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 22 Dec 2011 03:03:17 +0000 Subject: Move the Mips only bits of the ELF writer to lib/Target/Mips. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147133 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.h | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'lib/MC/ELFObjectWriter.h') diff --git a/lib/MC/ELFObjectWriter.h b/lib/MC/ELFObjectWriter.h index 658a4a9..2776eab 100644 --- a/lib/MC/ELFObjectWriter.h +++ b/lib/MC/ELFObjectWriter.h @@ -354,29 +354,6 @@ class ELFObjectWriter : public MCObjectWriter { bool IsPCRel, bool IsRelocWithSymbol, int64_t Addend) const; }; - - //===- MipsELFObjectWriter -------------------------------------------===// - - class MipsELFObjectWriter : public ELFObjectWriter { - public: - MipsELFObjectWriter(MCELFObjectTargetWriter *MOTW, - raw_ostream &_OS, - bool IsLittleEndian); - - virtual ~MipsELFObjectWriter(); - virtual unsigned getEFlags() const; - - protected: - virtual const MCSymbol *ExplicitRelSym(const MCAssembler &Asm, - const MCValue &Target, - const MCFragment &F, - const MCFixup &Fixup, - bool IsPCRel) const; - - virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, - bool IsPCRel, bool IsRelocWithSymbol, - int64_t Addend) const; - }; } #endif -- cgit v1.1 From 7bd278019d745d8b339f6b896926ce32ce118db7 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 22 Dec 2011 03:24:43 +0000 Subject: Misc cleanups. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147135 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.h | 113 ++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 56 deletions(-) (limited to 'lib/MC/ELFObjectWriter.h') diff --git a/lib/MC/ELFObjectWriter.h b/lib/MC/ELFObjectWriter.h index 2776eab..f99a082 100644 --- a/lib/MC/ELFObjectWriter.h +++ b/lib/MC/ELFObjectWriter.h @@ -140,18 +140,18 @@ class ELFObjectWriter : public MCObjectWriter { unsigned ShstrtabIndex; - virtual const MCSymbol *SymbolToReloc(const MCAssembler &Asm, - const MCValue &Target, - const MCFragment &F, - const MCFixup &Fixup, - bool IsPCRel) const; - - // For arch-specific emission of explicit reloc symbol - virtual const MCSymbol *ExplicitRelSym(const MCAssembler &Asm, - const MCValue &Target, - const MCFragment &F, - const MCFixup &Fixup, - bool IsPCRel) const { + const MCSymbol *SymbolToReloc(const MCAssembler &Asm, + const MCValue &Target, + const MCFragment &F, + const MCFixup &Fixup, + bool IsPCRel) const; + + // TargetObjectWriter wrappers. + const MCSymbol *ExplicitRelSym(const MCAssembler &Asm, + const MCValue &Target, + const MCFragment &F, + const MCFixup &Fixup, + bool IsPCRel) const { return TargetObjectWriter->ExplicitRelSym(Asm, Target, F, Fixup, IsPCRel); } @@ -159,6 +159,16 @@ class ELFObjectWriter : public MCObjectWriter { bool hasRelocationAddend() const { return TargetObjectWriter->hasRelocationAddend(); } + unsigned getEFlags() const { + return TargetObjectWriter->getEFlags(); + } + unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, + bool IsPCRel, bool IsRelocWithSymbol, + int64_t Addend) const { + return TargetObjectWriter->GetRelocType(Target, Fixup, IsPCRel, + IsRelocWithSymbol, Addend); + } + public: ELFObjectWriter(MCELFObjectTargetWriter *MOTW, @@ -240,30 +250,26 @@ class ELFObjectWriter : public MCObjectWriter { F.getContents() += StringRef(buf, 8); } - virtual void WriteHeader(uint64_t SectionDataSize, - unsigned NumberOfSections); + void WriteHeader(uint64_t SectionDataSize, + unsigned NumberOfSections); - virtual unsigned getEFlags() const { - return TargetObjectWriter->getEFlags(); - } - - virtual void WriteSymbolEntry(MCDataFragment *SymtabF, - MCDataFragment *ShndxF, - uint64_t name, uint8_t info, - uint64_t value, uint64_t size, - uint8_t other, uint32_t shndx, - bool Reserved); + void WriteSymbolEntry(MCDataFragment *SymtabF, + MCDataFragment *ShndxF, + uint64_t name, uint8_t info, + uint64_t value, uint64_t size, + uint8_t other, uint32_t shndx, + bool Reserved); - virtual void WriteSymbol(MCDataFragment *SymtabF, MCDataFragment *ShndxF, + void WriteSymbol(MCDataFragment *SymtabF, MCDataFragment *ShndxF, ELFSymbolData &MSD, const MCAsmLayout &Layout); typedef DenseMap SectionIndexMapTy; - virtual void WriteSymbolTable(MCDataFragment *SymtabF, - MCDataFragment *ShndxF, - const MCAssembler &Asm, - const MCAsmLayout &Layout, - const SectionIndexMapTy &SectionIndexMap); + void WriteSymbolTable(MCDataFragment *SymtabF, + MCDataFragment *ShndxF, + const MCAssembler &Asm, + const MCAsmLayout &Layout, + const SectionIndexMapTy &SectionIndexMap); virtual void RecordRelocation(const MCAssembler &Asm, const MCAsmLayout &Layout, @@ -271,8 +277,8 @@ class ELFObjectWriter : public MCObjectWriter { const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue); - virtual uint64_t getSymbolIndexInSymbolTable(const MCAssembler &Asm, - const MCSymbol *S); + uint64_t getSymbolIndexInSymbolTable(const MCAssembler &Asm, + const MCSymbol *S); // Map from a group section to the signature symbol typedef DenseMap GroupMapTy; @@ -288,14 +294,14 @@ class ELFObjectWriter : public MCObjectWriter { /// \param StringTable [out] - The string table data. /// \param StringIndexMap [out] - Map from symbol names to offsets in the /// string table. - virtual void ComputeSymbolTable(MCAssembler &Asm, + void ComputeSymbolTable(MCAssembler &Asm, const SectionIndexMapTy &SectionIndexMap, - RevGroupMapTy RevGroupMap, - unsigned NumRegularSections); + RevGroupMapTy RevGroupMap, + unsigned NumRegularSections); - virtual void ComputeIndexMap(MCAssembler &Asm, - SectionIndexMapTy &SectionIndexMap, - const RelMapTy &RelMap); + void ComputeIndexMap(MCAssembler &Asm, + SectionIndexMapTy &SectionIndexMap, + const RelMapTy &RelMap); void CreateRelocationSections(MCAssembler &Asm, MCAsmLayout &Layout, RelMapTy &RelMap); @@ -303,17 +309,17 @@ class ELFObjectWriter : public MCObjectWriter { void WriteRelocations(MCAssembler &Asm, MCAsmLayout &Layout, const RelMapTy &RelMap); - virtual void CreateMetadataSections(MCAssembler &Asm, MCAsmLayout &Layout, - SectionIndexMapTy &SectionIndexMap, - const RelMapTy &RelMap); + void CreateMetadataSections(MCAssembler &Asm, MCAsmLayout &Layout, + SectionIndexMapTy &SectionIndexMap, + const RelMapTy &RelMap); // Create the sections that show up in the symbol table. Currently // those are the .note.GNU-stack section and the group sections. - virtual void CreateIndexedSections(MCAssembler &Asm, MCAsmLayout &Layout, - GroupMapTy &GroupMap, - RevGroupMapTy &RevGroupMap, - SectionIndexMapTy &SectionIndexMap, - const RelMapTy &RelMap); + void CreateIndexedSections(MCAssembler &Asm, MCAsmLayout &Layout, + GroupMapTy &GroupMap, + RevGroupMapTy &RevGroupMap, + SectionIndexMapTy &SectionIndexMap, + const RelMapTy &RelMap); virtual void ExecutePostLayoutBinding(MCAssembler &Asm, const MCAsmLayout &Layout); @@ -326,14 +332,14 @@ class ELFObjectWriter : public MCObjectWriter { void ComputeSectionOrder(MCAssembler &Asm, std::vector &Sections); - virtual void WriteSecHdrEntry(uint32_t Name, uint32_t Type, uint64_t Flags, + void WriteSecHdrEntry(uint32_t Name, uint32_t Type, uint64_t Flags, uint64_t Address, uint64_t Offset, uint64_t Size, uint32_t Link, uint32_t Info, uint64_t Alignment, uint64_t EntrySize); - virtual void WriteRelocationsFragment(const MCAssembler &Asm, - MCDataFragment *F, - const MCSectionData *SD); + void WriteRelocationsFragment(const MCAssembler &Asm, + MCDataFragment *F, + const MCSectionData *SD); virtual bool IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, @@ -343,16 +349,11 @@ class ELFObjectWriter : public MCObjectWriter { bool IsPCRel) const; virtual void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout); - virtual void WriteSection(MCAssembler &Asm, + void WriteSection(MCAssembler &Asm, const SectionIndexMapTy &SectionIndexMap, uint32_t GroupSymbolIndex, uint64_t Offset, uint64_t Size, uint64_t Alignment, const MCSectionELF &Section); - - protected: - virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, - bool IsPCRel, bool IsRelocWithSymbol, - int64_t Addend) const; }; } -- cgit v1.1 From 3963d617b3709c510003ac816fb42f28539fc62b Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 22 Dec 2011 03:38:00 +0000 Subject: Kill the monstrosity that was ELFObjectWriter.h. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147136 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.h | 360 ----------------------------------------------- 1 file changed, 360 deletions(-) delete mode 100644 lib/MC/ELFObjectWriter.h (limited to 'lib/MC/ELFObjectWriter.h') diff --git a/lib/MC/ELFObjectWriter.h b/lib/MC/ELFObjectWriter.h deleted file mode 100644 index f99a082..0000000 --- a/lib/MC/ELFObjectWriter.h +++ /dev/null @@ -1,360 +0,0 @@ -//===- lib/MC/ELFObjectWriter.h - ELF File Writer -------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements ELF object file writer information. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_MC_ELFOBJECTWRITER_H -#define LLVM_MC_ELFOBJECTWRITER_H - -#include "MCELF.h" -#include "llvm/ADT/OwningPtr.h" -#include "llvm/ADT/SmallPtrSet.h" -#include "llvm/ADT/SmallString.h" -#include "llvm/ADT/STLExtras.h" -#include "llvm/MC/MCAssembler.h" -#include "llvm/MC/MCELFObjectWriter.h" -#include "llvm/MC/MCELFSymbolFlags.h" -#include "llvm/MC/MCObjectWriter.h" -#include "llvm/MC/MCExpr.h" -#include "llvm/MC/MCSymbol.h" - -#include - -namespace llvm { - -class MCSection; -class MCDataFragment; -class MCSectionELF; - -class ELFObjectWriter : public MCObjectWriter { - protected: - - static bool isFixupKindPCRel(const MCAssembler &Asm, unsigned Kind); - static bool RelocNeedsGOT(MCSymbolRefExpr::VariantKind Variant); - static uint64_t SymbolValue(MCSymbolData &Data, const MCAsmLayout &Layout); - static bool isInSymtab(const MCAssembler &Asm, const MCSymbolData &Data, - bool Used, bool Renamed); - static bool isLocal(const MCSymbolData &Data, bool isSignature, - bool isUsedInReloc); - static bool IsELFMetaDataSection(const MCSectionData &SD); - static uint64_t DataSectionSize(const MCSectionData &SD); - static uint64_t GetSectionFileSize(const MCAsmLayout &Layout, - const MCSectionData &SD); - static uint64_t GetSectionAddressSize(const MCAsmLayout &Layout, - const MCSectionData &SD); - - void WriteDataSectionData(MCAssembler &Asm, - const MCAsmLayout &Layout, - const MCSectionELF &Section); - - /*static bool isFixupKindX86RIPRel(unsigned Kind) { - return Kind == X86::reloc_riprel_4byte || - Kind == X86::reloc_riprel_4byte_movq_load; - }*/ - - /// ELFSymbolData - Helper struct for containing some precomputed - /// information on symbols. - struct ELFSymbolData { - MCSymbolData *SymbolData; - uint64_t StringIndex; - uint32_t SectionIndex; - - // Support lexicographic sorting. - bool operator<(const ELFSymbolData &RHS) const { - if (MCELF::GetType(*SymbolData) == ELF::STT_FILE) - return true; - if (MCELF::GetType(*RHS.SymbolData) == ELF::STT_FILE) - return false; - return SymbolData->getSymbol().getName() < - RHS.SymbolData->getSymbol().getName(); - } - }; - - /// @name Relocation Data - /// @{ - - struct ELFRelocationEntry { - // Make these big enough for both 32-bit and 64-bit - uint64_t r_offset; - int Index; - unsigned Type; - const MCSymbol *Symbol; - uint64_t r_addend; - - ELFRelocationEntry() - : r_offset(0), Index(0), Type(0), Symbol(0), r_addend(0) {} - - ELFRelocationEntry(uint64_t RelocOffset, int Idx, - unsigned RelType, const MCSymbol *Sym, - uint64_t Addend) - : r_offset(RelocOffset), Index(Idx), Type(RelType), - Symbol(Sym), r_addend(Addend) {} - - // Support lexicographic sorting. - bool operator<(const ELFRelocationEntry &RE) const { - return RE.r_offset < r_offset; - } - }; - - /// The target specific ELF writer instance. - llvm::OwningPtr TargetObjectWriter; - - SmallPtrSet UsedInReloc; - SmallPtrSet WeakrefUsedInReloc; - DenseMap Renames; - - llvm::DenseMap > Relocations; - DenseMap SectionStringTableIndex; - - /// @} - /// @name Symbol Table Data - /// @{ - - SmallString<256> StringTable; - std::vector LocalSymbolData; - std::vector ExternalSymbolData; - std::vector UndefinedSymbolData; - - /// @} - - bool NeedsGOT; - - bool NeedsSymtabShndx; - - // This holds the symbol table index of the last local symbol. - unsigned LastLocalSymbolIndex; - // This holds the .strtab section index. - unsigned StringTableIndex; - // This holds the .symtab section index. - unsigned SymbolTableIndex; - - unsigned ShstrtabIndex; - - - const MCSymbol *SymbolToReloc(const MCAssembler &Asm, - const MCValue &Target, - const MCFragment &F, - const MCFixup &Fixup, - bool IsPCRel) const; - - // TargetObjectWriter wrappers. - const MCSymbol *ExplicitRelSym(const MCAssembler &Asm, - const MCValue &Target, - const MCFragment &F, - const MCFixup &Fixup, - bool IsPCRel) const { - return TargetObjectWriter->ExplicitRelSym(Asm, Target, F, Fixup, IsPCRel); - } - - bool is64Bit() const { return TargetObjectWriter->is64Bit(); } - bool hasRelocationAddend() const { - return TargetObjectWriter->hasRelocationAddend(); - } - unsigned getEFlags() const { - return TargetObjectWriter->getEFlags(); - } - unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup, - bool IsPCRel, bool IsRelocWithSymbol, - int64_t Addend) const { - return TargetObjectWriter->GetRelocType(Target, Fixup, IsPCRel, - IsRelocWithSymbol, Addend); - } - - - public: - ELFObjectWriter(MCELFObjectTargetWriter *MOTW, - raw_ostream &_OS, bool IsLittleEndian) - : MCObjectWriter(_OS, IsLittleEndian), - TargetObjectWriter(MOTW), - NeedsGOT(false), NeedsSymtabShndx(false){ - } - - virtual ~ELFObjectWriter(); - - void WriteWord(uint64_t W) { - if (is64Bit()) - Write64(W); - else - Write32(W); - } - - void StringLE16(char *buf, uint16_t Value) { - buf[0] = char(Value >> 0); - buf[1] = char(Value >> 8); - } - - void StringLE32(char *buf, uint32_t Value) { - StringLE16(buf, uint16_t(Value >> 0)); - StringLE16(buf + 2, uint16_t(Value >> 16)); - } - - void StringLE64(char *buf, uint64_t Value) { - StringLE32(buf, uint32_t(Value >> 0)); - StringLE32(buf + 4, uint32_t(Value >> 32)); - } - - void StringBE16(char *buf ,uint16_t Value) { - buf[0] = char(Value >> 8); - buf[1] = char(Value >> 0); - } - - void StringBE32(char *buf, uint32_t Value) { - StringBE16(buf, uint16_t(Value >> 16)); - StringBE16(buf + 2, uint16_t(Value >> 0)); - } - - void StringBE64(char *buf, uint64_t Value) { - StringBE32(buf, uint32_t(Value >> 32)); - StringBE32(buf + 4, uint32_t(Value >> 0)); - } - - void String8(MCDataFragment &F, uint8_t Value) { - char buf[1]; - buf[0] = Value; - F.getContents() += StringRef(buf, 1); - } - - void String16(MCDataFragment &F, uint16_t Value) { - char buf[2]; - if (isLittleEndian()) - StringLE16(buf, Value); - else - StringBE16(buf, Value); - F.getContents() += StringRef(buf, 2); - } - - void String32(MCDataFragment &F, uint32_t Value) { - char buf[4]; - if (isLittleEndian()) - StringLE32(buf, Value); - else - StringBE32(buf, Value); - F.getContents() += StringRef(buf, 4); - } - - void String64(MCDataFragment &F, uint64_t Value) { - char buf[8]; - if (isLittleEndian()) - StringLE64(buf, Value); - else - StringBE64(buf, Value); - F.getContents() += StringRef(buf, 8); - } - - void WriteHeader(uint64_t SectionDataSize, - unsigned NumberOfSections); - - void WriteSymbolEntry(MCDataFragment *SymtabF, - MCDataFragment *ShndxF, - uint64_t name, uint8_t info, - uint64_t value, uint64_t size, - uint8_t other, uint32_t shndx, - bool Reserved); - - void WriteSymbol(MCDataFragment *SymtabF, MCDataFragment *ShndxF, - ELFSymbolData &MSD, - const MCAsmLayout &Layout); - - typedef DenseMap SectionIndexMapTy; - void WriteSymbolTable(MCDataFragment *SymtabF, - MCDataFragment *ShndxF, - const MCAssembler &Asm, - const MCAsmLayout &Layout, - const SectionIndexMapTy &SectionIndexMap); - - virtual void RecordRelocation(const MCAssembler &Asm, - const MCAsmLayout &Layout, - const MCFragment *Fragment, - const MCFixup &Fixup, - MCValue Target, uint64_t &FixedValue); - - uint64_t getSymbolIndexInSymbolTable(const MCAssembler &Asm, - const MCSymbol *S); - - // Map from a group section to the signature symbol - typedef DenseMap GroupMapTy; - // Map from a signature symbol to the group section - typedef DenseMap RevGroupMapTy; - // Map from a section to the section with the relocations - typedef DenseMap RelMapTy; - // Map from a section to its offset - typedef DenseMap SectionOffsetMapTy; - - /// ComputeSymbolTable - Compute the symbol table data - /// - /// \param StringTable [out] - The string table data. - /// \param StringIndexMap [out] - Map from symbol names to offsets in the - /// string table. - void ComputeSymbolTable(MCAssembler &Asm, - const SectionIndexMapTy &SectionIndexMap, - RevGroupMapTy RevGroupMap, - unsigned NumRegularSections); - - void ComputeIndexMap(MCAssembler &Asm, - SectionIndexMapTy &SectionIndexMap, - const RelMapTy &RelMap); - - void CreateRelocationSections(MCAssembler &Asm, MCAsmLayout &Layout, - RelMapTy &RelMap); - - void WriteRelocations(MCAssembler &Asm, MCAsmLayout &Layout, - const RelMapTy &RelMap); - - void CreateMetadataSections(MCAssembler &Asm, MCAsmLayout &Layout, - SectionIndexMapTy &SectionIndexMap, - const RelMapTy &RelMap); - - // Create the sections that show up in the symbol table. Currently - // those are the .note.GNU-stack section and the group sections. - void CreateIndexedSections(MCAssembler &Asm, MCAsmLayout &Layout, - GroupMapTy &GroupMap, - RevGroupMapTy &RevGroupMap, - SectionIndexMapTy &SectionIndexMap, - const RelMapTy &RelMap); - - virtual void ExecutePostLayoutBinding(MCAssembler &Asm, - const MCAsmLayout &Layout); - - void WriteSectionHeader(MCAssembler &Asm, const GroupMapTy &GroupMap, - const MCAsmLayout &Layout, - const SectionIndexMapTy &SectionIndexMap, - const SectionOffsetMapTy &SectionOffsetMap); - - void ComputeSectionOrder(MCAssembler &Asm, - std::vector &Sections); - - void WriteSecHdrEntry(uint32_t Name, uint32_t Type, uint64_t Flags, - uint64_t Address, uint64_t Offset, - uint64_t Size, uint32_t Link, uint32_t Info, - uint64_t Alignment, uint64_t EntrySize); - - void WriteRelocationsFragment(const MCAssembler &Asm, - MCDataFragment *F, - const MCSectionData *SD); - - virtual bool - IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, - const MCSymbolData &DataA, - const MCFragment &FB, - bool InSet, - bool IsPCRel) const; - - virtual void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout); - void WriteSection(MCAssembler &Asm, - const SectionIndexMapTy &SectionIndexMap, - uint32_t GroupSymbolIndex, - uint64_t Offset, uint64_t Size, uint64_t Alignment, - const MCSectionELF &Section); - }; -} - -#endif -- cgit v1.1