[MC] Plumb unique_ptr<MCWinCOFFObjectTargetWriter> through

createWinCOFFObjectWriter to WinCOFFObjectWriter's constructor.

Fixes the same ownership issue for COFF that r315245 did for MachO:
WinCOFFObjectWriter takes ownership of its MCWinCOFFObjectTargetWriter, so we
want to pass this through to the constructor via a unique_ptr, rather than a
raw ptr.

llvm-svn: 315257
This commit is contained in:
Lang Hames 2017-10-10 00:50:29 +00:00
parent a0b68be6cf
commit 77dff39cb4
5 changed files with 17 additions and 16 deletions

View File

@ -42,8 +42,9 @@ class raw_pwrite_stream;
/// \param MOTW - The target specific WinCOFF writer subclass. /// \param MOTW - The target specific WinCOFF writer subclass.
/// \param OS - The stream to write to. /// \param OS - The stream to write to.
/// \returns The constructed object writer. /// \returns The constructed object writer.
MCObjectWriter *createWinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW, MCObjectWriter *
raw_pwrite_stream &OS); createWinCOFFObjectWriter(std::unique_ptr<MCWinCOFFObjectTargetWriter> MOTW,
raw_pwrite_stream &OS);
} // end namespace llvm } // end namespace llvm
#endif // LLVM_MC_MCWINCOFFOBJECTWRITER_H #endif // LLVM_MC_MCWINCOFFOBJECTWRITER_H

View File

@ -145,7 +145,8 @@ public:
bool UseBigObj; bool UseBigObj;
WinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW, raw_pwrite_stream &OS); WinCOFFObjectWriter(std::unique_ptr<MCWinCOFFObjectTargetWriter> MOTW,
raw_pwrite_stream &OS);
void reset() override { void reset() override {
memset(&Header, 0, sizeof(Header)); memset(&Header, 0, sizeof(Header));
@ -222,9 +223,9 @@ void COFFSymbol::set_name_offset(uint32_t Offset) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// WinCOFFObjectWriter class implementation // WinCOFFObjectWriter class implementation
WinCOFFObjectWriter::WinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW, WinCOFFObjectWriter::WinCOFFObjectWriter(
raw_pwrite_stream &OS) std::unique_ptr<MCWinCOFFObjectTargetWriter> MOTW, raw_pwrite_stream &OS)
: MCObjectWriter(OS, true), TargetObjectWriter(MOTW) { : MCObjectWriter(OS, true), TargetObjectWriter(std::move(MOTW)) {
Header.Machine = TargetObjectWriter->getMachine(); Header.Machine = TargetObjectWriter->getMachine();
} }
@ -1084,8 +1085,7 @@ void MCWinCOFFObjectTargetWriter::anchor() {}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// WinCOFFObjectWriter factory function // WinCOFFObjectWriter factory function
MCObjectWriter * MCObjectWriter *llvm::createWinCOFFObjectWriter(
llvm::createWinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW, std::unique_ptr<MCWinCOFFObjectTargetWriter> MOTW, raw_pwrite_stream &OS) {
raw_pwrite_stream &OS) { return new WinCOFFObjectWriter(std::move(MOTW), OS);
return new WinCOFFObjectWriter(MOTW, OS);
} }

View File

@ -97,8 +97,8 @@ bool AArch64WinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
namespace llvm { namespace llvm {
MCObjectWriter *createAArch64WinCOFFObjectWriter(raw_pwrite_stream &OS) { MCObjectWriter *createAArch64WinCOFFObjectWriter(raw_pwrite_stream &OS) {
MCWinCOFFObjectTargetWriter *MOTW = new AArch64WinCOFFObjectWriter(); auto MOTW = llvm::make_unique<AArch64WinCOFFObjectWriter>();
return createWinCOFFObjectWriter(MOTW, OS); return createWinCOFFObjectWriter(std::move(MOTW), OS);
} }
} // end namespace llvm } // end namespace llvm

View File

@ -92,8 +92,8 @@ namespace llvm {
MCObjectWriter *createARMWinCOFFObjectWriter(raw_pwrite_stream &OS, MCObjectWriter *createARMWinCOFFObjectWriter(raw_pwrite_stream &OS,
bool Is64Bit) { bool Is64Bit) {
MCWinCOFFObjectTargetWriter *MOTW = new ARMWinCOFFObjectWriter(Is64Bit); auto MOTW = llvm::make_unique<ARMWinCOFFObjectWriter>(Is64Bit);
return createWinCOFFObjectWriter(MOTW, OS); return createWinCOFFObjectWriter(std::move(MOTW), OS);
} }
} // end namespace llvm } // end namespace llvm

View File

@ -106,6 +106,6 @@ unsigned X86WinCOFFObjectWriter::getRelocType(MCContext &Ctx,
MCObjectWriter *llvm::createX86WinCOFFObjectWriter(raw_pwrite_stream &OS, MCObjectWriter *llvm::createX86WinCOFFObjectWriter(raw_pwrite_stream &OS,
bool Is64Bit) { bool Is64Bit) {
MCWinCOFFObjectTargetWriter *MOTW = new X86WinCOFFObjectWriter(Is64Bit); auto MOTW = llvm::make_unique<X86WinCOFFObjectWriter>(Is64Bit);
return createWinCOFFObjectWriter(MOTW, OS); return createWinCOFFObjectWriter(std::move(MOTW), OS);
} }