Index: llvm/trunk/include/llvm/MC/MCMachObjectWriter.h =================================================================== --- llvm/trunk/include/llvm/MC/MCMachObjectWriter.h +++ llvm/trunk/include/llvm/MC/MCMachObjectWriter.h @@ -265,7 +265,7 @@ 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. Index: llvm/trunk/include/llvm/MC/MCObjectWriter.h =================================================================== --- llvm/trunk/include/llvm/MC/MCObjectWriter.h +++ llvm/trunk/include/llvm/MC/MCObjectWriter.h @@ -109,12 +109,12 @@ 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 Index: llvm/trunk/lib/MC/ELFObjectWriter.cpp =================================================================== --- llvm/trunk/lib/MC/ELFObjectWriter.cpp +++ llvm/trunk/lib/MC/ELFObjectWriter.cpp @@ -247,7 +247,7 @@ 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::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 @@ } Stream.pwrite(reinterpret_cast(&NumSections), sizeof(NumSections), NumSectionsOffset); + + return W.OS.tell() - StartOffset; } bool ELFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl( Index: llvm/trunk/lib/MC/MCAssembler.cpp =================================================================== --- llvm/trunk/lib/MC/MCAssembler.cpp +++ llvm/trunk/lib/MC/MCAssembler.cpp @@ -815,13 +815,8 @@ 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, Index: llvm/trunk/lib/MC/MachObjectWriter.cpp =================================================================== --- llvm/trunk/lib/MC/MachObjectWriter.cpp +++ llvm/trunk/lib/MC/MachObjectWriter.cpp @@ -735,8 +735,10 @@ 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 @@ // Write the string table. StringTable.write(W.OS); } + + return W.OS.tell() - StartOffset; } std::unique_ptr Index: llvm/trunk/lib/MC/WasmObjectWriter.cpp =================================================================== --- llvm/trunk/lib/MC/WasmObjectWriter.cpp +++ llvm/trunk/lib/MC/WasmObjectWriter.cpp @@ -285,7 +285,7 @@ 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 @@ 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 @@ writeCustomRelocSections(); // TODO: Translate the .comment section to the output. + return W.OS.tell() - StartOffset; } std::unique_ptr Index: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp =================================================================== --- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp +++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp @@ -206,7 +206,7 @@ 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 @@ 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 @@ // Write a string table, which completes the entire COFF file. Strings.write(W.OS); + + return W.OS.tell() - StartOffset; } MCWinCOFFObjectTargetWriter::MCWinCOFFObjectTargetWriter(unsigned Machine_)