From 31f3578b00a2ea85fb730b690f0478529103c748 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 17 Dec 2010 18:01:31 +0000 Subject: [PATCH] Store and free the TargetObjectWriter. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122070 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.cpp | 39 +++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 4c67efdaf9c..c07c23149b6 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringMap.h" @@ -148,6 +149,9 @@ namespace { } }; + /// The target specific ELF writer instance. + llvm::OwningPtr TargetObjectWriter; + SmallPtrSet UsedInReloc; SmallPtrSet WeakrefUsedInReloc; DenseMap Renames; @@ -194,10 +198,12 @@ namespace { const MCFragment &F) const; public: - ELFObjectWriter(raw_ostream &_OS, bool _Is64Bit, bool IsLittleEndian, + ELFObjectWriter(MCELFObjectTargetWriter *MOTW, + raw_ostream &_OS, bool _Is64Bit, bool IsLittleEndian, uint16_t _EMachine, bool _HasRelAddend, Triple::OSType _OSType) : MCObjectWriter(_OS, IsLittleEndian), + TargetObjectWriter(MOTW), NeedsGOT(false), NeedsSymtabShndx(false), Is64Bit(_Is64Bit), HasRelocationAddend(_HasRelAddend), OSType(_OSType), EMachine(_EMachine) { @@ -375,7 +381,8 @@ namespace { class X86ELFObjectWriter : public ELFObjectWriter { public: - X86ELFObjectWriter(raw_ostream &_OS, bool _Is64Bit, bool IsLittleEndian, + X86ELFObjectWriter(MCELFObjectTargetWriter *MOTW, + raw_ostream &_OS, bool _Is64Bit, bool IsLittleEndian, uint16_t _EMachine, bool _HasRelAddend, Triple::OSType _OSType); @@ -391,7 +398,8 @@ namespace { class ARMELFObjectWriter : public ELFObjectWriter { public: - ARMELFObjectWriter(raw_ostream &_OS, bool _Is64Bit, bool IsLittleEndian, + ARMELFObjectWriter(MCELFObjectTargetWriter *MOTW, + raw_ostream &_OS, bool _Is64Bit, bool IsLittleEndian, uint16_t _EMachine, bool _HasRelAddend, Triple::OSType _OSType); @@ -406,7 +414,8 @@ namespace { class MBlazeELFObjectWriter : public ELFObjectWriter { public: - MBlazeELFObjectWriter(raw_ostream &_OS, bool _Is64Bit, bool IsLittleEndian, + MBlazeELFObjectWriter(MCELFObjectTargetWriter *MOTW, + raw_ostream &_OS, bool _Is64Bit, bool IsLittleEndian, uint16_t _EMachine, bool _HasRelAddend, Triple::OSType _OSType); @@ -1477,13 +1486,14 @@ MCObjectWriter *llvm::createELFObjectWriter(MCELFObjectTargetWriter *MOTW, switch (EMachine) { case ELF::EM_386: case ELF::EM_X86_64: - return new X86ELFObjectWriter(OS, Is64Bit, IsLittleEndian, EMachine, + return new X86ELFObjectWriter(MOTW, OS, Is64Bit, IsLittleEndian, EMachine, HasRelocationAddend, OSType); break; case ELF::EM_ARM: - return new ARMELFObjectWriter(OS, Is64Bit, IsLittleEndian, EMachine, + return new ARMELFObjectWriter(MOTW, OS, Is64Bit, IsLittleEndian, EMachine, HasRelocationAddend, OSType); break; case ELF::EM_MBLAZE: - return new MBlazeELFObjectWriter(OS, Is64Bit, IsLittleEndian, EMachine, + return new MBlazeELFObjectWriter(MOTW, OS, Is64Bit, IsLittleEndian, + EMachine, HasRelocationAddend, OSType); break; default: llvm_unreachable("Unsupported architecture"); break; } @@ -1493,11 +1503,12 @@ MCObjectWriter *llvm::createELFObjectWriter(MCELFObjectTargetWriter *MOTW, /// START OF SUBCLASSES for ELFObjectWriter //===- ARMELFObjectWriter -------------------------------------------===// -ARMELFObjectWriter::ARMELFObjectWriter(raw_ostream &_OS, bool _Is64Bit, +ARMELFObjectWriter::ARMELFObjectWriter(MCELFObjectTargetWriter *MOTW, + raw_ostream &_OS, bool _Is64Bit, bool _IsLittleEndian, uint16_t _EMachine, bool _HasRelocationAddend, Triple::OSType _OSType) - : ELFObjectWriter(_OS, _Is64Bit, _IsLittleEndian, _EMachine, + : ELFObjectWriter(MOTW, _OS, _Is64Bit, _IsLittleEndian, _EMachine, _HasRelocationAddend, _OSType) {} @@ -1580,12 +1591,13 @@ unsigned ARMELFObjectWriter::GetRelocType(const MCValue &Target, //===- MBlazeELFObjectWriter -------------------------------------------===// -MBlazeELFObjectWriter::MBlazeELFObjectWriter(raw_ostream &_OS, bool _Is64Bit, +MBlazeELFObjectWriter::MBlazeELFObjectWriter(MCELFObjectTargetWriter *MOTW, + raw_ostream &_OS, bool _Is64Bit, bool _IsLittleEndian, uint16_t _EMachine, bool _HasRelocationAddend, Triple::OSType _OSType) - : ELFObjectWriter(_OS, _Is64Bit, _IsLittleEndian, _EMachine, + : ELFObjectWriter(MOTW, _OS, _Is64Bit, _IsLittleEndian, _EMachine, _HasRelocationAddend, _OSType) { } @@ -1629,11 +1641,12 @@ unsigned MBlazeELFObjectWriter::GetRelocType(const MCValue &Target, //===- X86ELFObjectWriter -------------------------------------------===// -X86ELFObjectWriter::X86ELFObjectWriter(raw_ostream &_OS, bool _Is64Bit, +X86ELFObjectWriter::X86ELFObjectWriter(MCELFObjectTargetWriter *MOTW, + raw_ostream &_OS, bool _Is64Bit, bool _IsLittleEndian, uint16_t _EMachine, bool _HasRelocationAddend, Triple::OSType _OSType) - : ELFObjectWriter(_OS, _Is64Bit, _IsLittleEndian, _EMachine, + : ELFObjectWriter(MOTW, _OS, _Is64Bit, _IsLittleEndian, _EMachine, _HasRelocationAddend, _OSType) {} -- 2.34.1