Skip to content

Commit

Permalink
[MC] Plumb unique_ptr<MCELFObjectTargetWriter> through createELFObjec…
Browse files Browse the repository at this point in the history
…tWriter to

ELFObjectWriter's constructor.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315254 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
lhames committed Oct 9, 2017
1 parent 3b8950a commit 37437af
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 36 deletions.
6 changes: 3 additions & 3 deletions include/llvm/MC/MCELFObjectWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ class MCELFObjectTargetWriter {
/// \param MOTW - The target specific ELF writer subclass.
/// \param OS - The stream to write to.
/// \returns The constructed object writer.
MCObjectWriter *createELFObjectWriter(MCELFObjectTargetWriter *MOTW,
raw_pwrite_stream &OS,
bool IsLittleEndian);
MCObjectWriter *
createELFObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW,
raw_pwrite_stream &OS, bool IsLittleEndian);

} // end namespace llvm

Expand Down
15 changes: 8 additions & 7 deletions lib/MC/ELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ class ELFObjectWriter : public MCObjectWriter {
bool ZLibStyle, unsigned Alignment);

public:
ELFObjectWriter(MCELFObjectTargetWriter *MOTW, raw_pwrite_stream &OS,
bool IsLittleEndian)
: MCObjectWriter(OS, IsLittleEndian), TargetObjectWriter(MOTW) {}
ELFObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW,
raw_pwrite_stream &OS, bool IsLittleEndian)
: MCObjectWriter(OS, IsLittleEndian),
TargetObjectWriter(std::move(MOTW)) {}

~ELFObjectWriter() override = default;

Expand Down Expand Up @@ -1386,8 +1387,8 @@ bool ELFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
InSet, IsPCRel);
}

MCObjectWriter *llvm::createELFObjectWriter(MCELFObjectTargetWriter *MOTW,
raw_pwrite_stream &OS,
bool IsLittleEndian) {
return new ELFObjectWriter(MOTW, OS, IsLittleEndian);
MCObjectWriter *
llvm::createELFObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW,
raw_pwrite_stream &OS, bool IsLittleEndian) {
return new ELFObjectWriter(std::move(MOTW), OS, IsLittleEndian);
}
6 changes: 3 additions & 3 deletions lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ MCObjectWriter *llvm::createAArch64ELFObjectWriter(raw_pwrite_stream &OS,
uint8_t OSABI,
bool IsLittleEndian,
bool IsILP32) {
MCELFObjectTargetWriter *MOTW =
new AArch64ELFObjectWriter(OSABI, IsLittleEndian, IsILP32);
return createELFObjectWriter(MOTW, OS, IsLittleEndian);
auto MOTW =
llvm::make_unique<AArch64ELFObjectWriter>(OSABI, IsLittleEndian, IsILP32);
return createELFObjectWriter(std::move(MOTW), OS, IsLittleEndian);
}
6 changes: 3 additions & 3 deletions lib/Target/AMDGPU/MCTargetDesc/AMDGPUELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ MCObjectWriter *llvm::createAMDGPUELFObjectWriter(bool Is64Bit,
uint8_t OSABI,
bool HasRelocationAddend,
raw_pwrite_stream &OS) {
MCELFObjectTargetWriter *MOTW =
new AMDGPUELFObjectWriter(Is64Bit, OSABI, HasRelocationAddend);
return createELFObjectWriter(MOTW, OS, true);
auto MOTW = llvm::make_unique<AMDGPUELFObjectWriter>(Is64Bit, OSABI,
HasRelocationAddend);
return createELFObjectWriter(std::move(MOTW), OS, true);
}
4 changes: 2 additions & 2 deletions lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,6 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
MCObjectWriter *llvm::createARMELFObjectWriter(raw_pwrite_stream &OS,
uint8_t OSABI,
bool IsLittleEndian) {
MCELFObjectTargetWriter *MOTW = new ARMELFObjectWriter(OSABI);
return createELFObjectWriter(MOTW, OS, IsLittleEndian);
return createELFObjectWriter(llvm::make_unique<ARMELFObjectWriter>(OSABI), OS,
IsLittleEndian);
}
4 changes: 2 additions & 2 deletions lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ unsigned BPFELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,

MCObjectWriter *llvm::createBPFELFObjectWriter(raw_pwrite_stream &OS,
uint8_t OSABI, bool IsLittleEndian) {
MCELFObjectTargetWriter *MOTW = new BPFELFObjectWriter(OSABI);
return createELFObjectWriter(MOTW, OS, IsLittleEndian);
return createELFObjectWriter(llvm::make_unique<BPFELFObjectWriter>(OSABI), OS,
IsLittleEndian);
}
4 changes: 2 additions & 2 deletions lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,6 @@ unsigned HexagonELFObjectWriter::getRelocType(MCContext &Ctx,
MCObjectWriter *llvm::createHexagonELFObjectWriter(raw_pwrite_stream &OS,
uint8_t OSABI,
StringRef CPU) {
MCELFObjectTargetWriter *MOTW = new HexagonELFObjectWriter(OSABI, CPU);
return createELFObjectWriter(MOTW, OS, /*IsLittleEndian*/ true);
auto MOTW = llvm::make_unique<HexagonELFObjectWriter>(OSABI, CPU);
return createELFObjectWriter(std::move(MOTW), OS, /*IsLittleEndian*/ true);
}
4 changes: 2 additions & 2 deletions lib/Target/Lanai/MCTargetDesc/LanaiELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ bool LanaiELFObjectWriter::needsRelocateWithSymbol(const MCSymbol & /*SD*/,

MCObjectWriter *llvm::createLanaiELFObjectWriter(raw_pwrite_stream &OS,
uint8_t OSABI) {
MCELFObjectTargetWriter *MOTW = new LanaiELFObjectWriter(OSABI);
return createELFObjectWriter(MOTW, OS, /*IsLittleEndian=*/false);
return createELFObjectWriter(llvm::make_unique<LanaiELFObjectWriter>(OSABI),
OS, /*IsLittleEndian=*/false);
}
6 changes: 3 additions & 3 deletions lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ MCObjectWriter *llvm::createMipsELFObjectWriter(raw_pwrite_stream &OS,
uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TT.getOS());
bool IsN64 = TT.isArch64Bit() && !IsN32;
bool HasRelocationAddend = TT.isArch64Bit();
auto *MOTW = new MipsELFObjectWriter(OSABI, HasRelocationAddend, IsN64,
TT.isLittleEndian());
return createELFObjectWriter(MOTW, OS, TT.isLittleEndian());
auto MOTW = llvm::make_unique<MipsELFObjectWriter>(
OSABI, HasRelocationAddend, IsN64, TT.isLittleEndian());
return createELFObjectWriter(std::move(MOTW), OS, TT.isLittleEndian());
}
4 changes: 2 additions & 2 deletions lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,6 @@ MCObjectWriter *llvm::createPPCELFObjectWriter(raw_pwrite_stream &OS,
bool Is64Bit,
bool IsLittleEndian,
uint8_t OSABI) {
MCELFObjectTargetWriter *MOTW = new PPCELFObjectWriter(Is64Bit, OSABI);
return createELFObjectWriter(MOTW, OS, IsLittleEndian);
auto MOTW = llvm::make_unique<PPCELFObjectWriter>(Is64Bit, OSABI);
return createELFObjectWriter(std::move(MOTW), OS, IsLittleEndian);
}
4 changes: 2 additions & 2 deletions lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,6 @@ MCObjectWriter *llvm::createSparcELFObjectWriter(raw_pwrite_stream &OS,
bool Is64Bit,
bool IsLittleEndian,
uint8_t OSABI) {
MCELFObjectTargetWriter *MOTW = new SparcELFObjectWriter(Is64Bit, OSABI);
return createELFObjectWriter(MOTW, OS, IsLittleEndian);
auto MOTW = llvm::make_unique<SparcELFObjectWriter>(Is64Bit, OSABI);
return createELFObjectWriter(std::move(MOTW), OS, IsLittleEndian);
}
4 changes: 2 additions & 2 deletions lib/Target/SystemZ/MCTargetDesc/SystemZMCObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ unsigned SystemZObjectWriter::getRelocType(MCContext &Ctx,

MCObjectWriter *llvm::createSystemZObjectWriter(raw_pwrite_stream &OS,
uint8_t OSABI) {
MCELFObjectTargetWriter *MOTW = new SystemZObjectWriter(OSABI);
return createELFObjectWriter(MOTW, OS, /*IsLittleEndian=*/false);
return createELFObjectWriter(llvm::make_unique<SystemZObjectWriter>(OSABI),
OS, /*IsLittleEndian=*/false);
}
5 changes: 2 additions & 3 deletions lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ unsigned X86ELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
MCObjectWriter *llvm::createX86ELFObjectWriter(raw_pwrite_stream &OS,
bool IsELF64, uint8_t OSABI,
uint16_t EMachine) {
MCELFObjectTargetWriter *MOTW =
new X86ELFObjectWriter(IsELF64, OSABI, EMachine);
return createELFObjectWriter(MOTW, OS, /*IsLittleEndian=*/true);
auto MOTW = llvm::make_unique<X86ELFObjectWriter>(IsELF64, OSABI, EMachine);
return createELFObjectWriter(std::move(MOTW), OS, /*IsLittleEndian=*/true);
}

0 comments on commit 37437af

Please sign in to comment.