summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2018-05-21 18:23:50 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2018-05-21 18:23:50 +0000
commit438390fae1f0f6125b914e5f1bd4ef2e7deb8c05 (patch)
tree75c6368bbd66ae73103e12c73b87459488056a7c /llvm/lib/MC
parent9badad2051c41049354e2650c1b321e7e0d0d3e1 (diff)
downloadbcm5719-llvm-438390fae1f0f6125b914e5f1bd4ef2e7deb8c05.tar.gz
bcm5719-llvm-438390fae1f0f6125b914e5f1bd4ef2e7deb8c05.zip
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
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp10
-rw-r--r--llvm/lib/MC/MCAssembler.cpp7
-rw-r--r--llvm/lib/MC/MachObjectWriter.cpp8
-rw-r--r--llvm/lib/MC/WasmObjectWriter.cpp9
-rw-r--r--llvm/lib/MC/WinCOFFObjectWriter.cpp10
5 files changed, 27 insertions, 17 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index e5014e64043..9826996c571 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -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(
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index f72c3fda8f0..f63df8b1002 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -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,
diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp
index ba8922c8997..a464af1d42a 100644
--- a/llvm/lib/MC/MachObjectWriter.cpp
+++ b/llvm/lib/MC/MachObjectWriter.cpp
@@ -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>
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index cbb12cab71e..f3ff3b9c284 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -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>
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp
index c87bc02fe05..f78f04ca7d3 100644
--- a/llvm/lib/MC/WinCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp
@@ -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_)
OpenPOWER on IntegriCloud