[llvm] r332863 - MC: Have the object writers return the number of bytes written. NFCI.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Mon May 21 11:23:50 PDT 2018
Author: pcc
Date: Mon May 21 11:23:50 2018
New Revision: 332863
URL: http://llvm.org/viewvc/llvm-project?rev=332863&view=rev
Log:
MC: Have the object writers return the number of bytes written. NFCI.
This removes the last external use of the stream.
Part of PR37466.
Differential Revision: https://reviews.llvm.org/D47042
Modified:
llvm/trunk/include/llvm/MC/MCMachObjectWriter.h
llvm/trunk/include/llvm/MC/MCObjectWriter.h
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/lib/MC/MCAssembler.cpp
llvm/trunk/lib/MC/MachObjectWriter.cpp
llvm/trunk/lib/MC/WasmObjectWriter.cpp
llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
Modified: llvm/trunk/include/llvm/MC/MCMachObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCMachObjectWriter.h?rev=332863&r1=332862&r2=332863&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCMachObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MCMachObjectWriter.h Mon May 21 11:23:50 2018
@@ -265,7 +265,7 @@ public:
const MCFragment &FB, bool InSet,
bool IsPCRel) const override;
- void writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
+ uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
};
/// Construct a new Mach-O writer instance.
Modified: llvm/trunk/include/llvm/MC/MCObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectWriter.h?rev=332863&r1=332862&r2=332863&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MCObjectWriter.h Mon May 21 11:23:50 2018
@@ -109,12 +109,12 @@ public:
bool InSet,
bool IsPCRel) const;
- /// Write the object file.
+ /// Write the object file and returns the number of bytes written.
///
/// This routine is called by the assembler after layout and relaxation is
/// complete, fixups have been evaluated and applied, and relocations
/// generated.
- virtual void writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) = 0;
+ virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) = 0;
/// @}
/// \name Binary Output
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=332863&r1=332862&r2=332863&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Mon May 21 11:23:50 2018
@@ -247,7 +247,7 @@ public:
const MCFragment &FB, bool InSet,
bool IsPCRel) const override;
- void writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
+ uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
void writeSection(const SectionIndexMapTy &SectionIndexMap,
uint32_t GroupSymbolIndex, uint64_t Offset, uint64_t Size,
const MCSectionELF &Section);
@@ -1205,8 +1205,10 @@ void ELFObjectWriter::writeSectionHeader
}
}
-void ELFObjectWriter::writeObject(MCAssembler &Asm,
- const MCAsmLayout &Layout) {
+uint64_t ELFObjectWriter::writeObject(MCAssembler &Asm,
+ const MCAsmLayout &Layout) {
+ uint64_t StartOffset = W.OS.tell();
+
MCContext &Ctx = Asm.getContext();
MCSectionELF *StrtabSection =
Ctx.getELFSection(".strtab", ELF::SHT_STRTAB, 0);
@@ -1334,6 +1336,8 @@ void ELFObjectWriter::writeObject(MCAsse
}
Stream.pwrite(reinterpret_cast<char *>(&NumSections), sizeof(NumSections),
NumSectionsOffset);
+
+ return W.OS.tell() - StartOffset;
}
bool ELFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=332863&r1=332862&r2=332863&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Mon May 21 11:23:50 2018
@@ -815,13 +815,8 @@ void MCAssembler::Finish() {
MCAsmLayout Layout(*this);
layout(Layout);
- raw_ostream &OS = getWriter().getStream();
- uint64_t StartOffset = OS.tell();
-
// Write the object file.
- getWriter().writeObject(*this, Layout);
-
- stats::ObjectBytes += OS.tell() - StartOffset;
+ stats::ObjectBytes += getWriter().writeObject(*this, Layout);
}
bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=332863&r1=332862&r2=332863&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Mon May 21 11:23:50 2018
@@ -735,8 +735,10 @@ static MachO::LoadCommandType getLCFromM
llvm_unreachable("Invalid mc version min type");
}
-void MachObjectWriter::writeObject(MCAssembler &Asm,
- const MCAsmLayout &Layout) {
+uint64_t MachObjectWriter::writeObject(MCAssembler &Asm,
+ const MCAsmLayout &Layout) {
+ uint64_t StartOffset = W.OS.tell();
+
// Compute symbol table information and bind symbol indices.
computeSymbolTable(Asm, LocalSymbolData, ExternalSymbolData,
UndefinedSymbolData);
@@ -1011,6 +1013,8 @@ void MachObjectWriter::writeObject(MCAss
// Write the string table.
StringTable.write(W.OS);
}
+
+ return W.OS.tell() - StartOffset;
}
std::unique_ptr<MCObjectWriter>
Modified: llvm/trunk/lib/MC/WasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WasmObjectWriter.cpp?rev=332863&r1=332862&r2=332863&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WasmObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WasmObjectWriter.cpp Mon May 21 11:23:50 2018
@@ -285,7 +285,7 @@ private:
void executePostLayoutBinding(MCAssembler &Asm,
const MCAsmLayout &Layout) override;
- void writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
+ uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
void writeString(const StringRef Str) {
encodeULEB128(Str.size(), W.OS);
@@ -1075,8 +1075,10 @@ static bool isInSymtab(const MCSymbolWas
return true;
}
-void WasmObjectWriter::writeObject(MCAssembler &Asm,
- const MCAsmLayout &Layout) {
+uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm,
+ const MCAsmLayout &Layout) {
+ uint64_t StartOffset = W.OS.tell();
+
LLVM_DEBUG(dbgs() << "WasmObjectWriter::writeObject\n");
MCContext &Ctx = Asm.getContext();
@@ -1472,6 +1474,7 @@ void WasmObjectWriter::writeObject(MCAss
writeCustomRelocSections();
// TODO: Translate the .comment section to the output.
+ return W.OS.tell() - StartOffset;
}
std::unique_ptr<MCObjectWriter>
Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=332863&r1=332862&r2=332863&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Mon May 21 11:23:50 2018
@@ -206,7 +206,7 @@ public:
void assignSectionNumbers();
void assignFileOffsets(MCAssembler &Asm, const MCAsmLayout &Layout);
- void writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
+ uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
};
} // end anonymous namespace
@@ -963,8 +963,10 @@ void WinCOFFObjectWriter::assignFileOffs
Header.PointerToSymbolTable = Offset;
}
-void WinCOFFObjectWriter::writeObject(MCAssembler &Asm,
- const MCAsmLayout &Layout) {
+uint64_t WinCOFFObjectWriter::writeObject(MCAssembler &Asm,
+ const MCAsmLayout &Layout) {
+ uint64_t StartOffset = W.OS.tell();
+
if (Sections.size() > INT32_MAX)
report_fatal_error(
"PE COFF object files can't have more than 2147483647 sections");
@@ -1070,6 +1072,8 @@ void WinCOFFObjectWriter::writeObject(MC
// Write a string table, which completes the entire COFF file.
Strings.write(W.OS);
+
+ return W.OS.tell() - StartOffset;
}
MCWinCOFFObjectTargetWriter::MCWinCOFFObjectTargetWriter(unsigned Machine_)
More information about the llvm-commits
mailing list