mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-24 14:20:17 +00:00
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 llvm-svn: 332863
This commit is contained in:
parent
9badad2051
commit
438390fae1
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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(MCAssembler &Asm,
|
||||
}
|
||||
Stream.pwrite(reinterpret_cast<char *>(&NumSections), sizeof(NumSections),
|
||||
NumSectionsOffset);
|
||||
|
||||
return W.OS.tell() - StartOffset;
|
||||
}
|
||||
|
||||
bool ELFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
|
||||
|
@ -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,
|
||||
|
@ -735,8 +735,10 @@ static MachO::LoadCommandType getLCFromMCVM(MCVersionMinType Type) {
|
||||
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(MCAssembler &Asm,
|
||||
// Write the string table.
|
||||
StringTable.write(W.OS);
|
||||
}
|
||||
|
||||
return W.OS.tell() - StartOffset;
|
||||
}
|
||||
|
||||
std::unique_ptr<MCObjectWriter>
|
||||
|
@ -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 MCSymbolWasm &Sym) {
|
||||
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(MCAssembler &Asm,
|
||||
writeCustomRelocSections();
|
||||
|
||||
// TODO: Translate the .comment section to the output.
|
||||
return W.OS.tell() - StartOffset;
|
||||
}
|
||||
|
||||
std::unique_ptr<MCObjectWriter>
|
||||
|
@ -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::assignFileOffsets(MCAssembler &Asm,
|
||||
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(MCAssembler &Asm,
|
||||
|
||||
// Write a string table, which completes the entire COFF file.
|
||||
Strings.write(W.OS);
|
||||
|
||||
return W.OS.tell() - StartOffset;
|
||||
}
|
||||
|
||||
MCWinCOFFObjectTargetWriter::MCWinCOFFObjectTargetWriter(unsigned Machine_)
|
||||
|
Loading…
Reference in New Issue
Block a user