summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/MachObjectWriter.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2015-09-01 16:19:03 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2015-09-01 16:19:03 +0000
commitabdb2d2aba6777dd786dfaed7e4df41a025bd672 (patch)
tree5d641d9327546bfcdc69122779a6eed6ed6cda7f /llvm/lib/MC/MachObjectWriter.cpp
parent491d3bfd43c20da21756cf4452b2a1de851dafa3 (diff)
downloadbcm5719-llvm-abdb2d2aba6777dd786dfaed7e4df41a025bd672.tar.gz
bcm5719-llvm-abdb2d2aba6777dd786dfaed7e4df41a025bd672.zip
[MC] Allow MCObjectWriter's output stream to be swapped out
There are occasions where it is useful to consider the entirety of the contents of a section. For example, compressed debug info needs the entire section available before it can compress it and write it out. The compressed debug info scenario was previously implemented by mirroring the implementation of writeSectionData in the ELFObjectWriter. Instead, allow the output stream to be swapped on demand. This lets callers redirect the output stream to a more convenient location before it hits the object file. No functionality change is intended. Differential Revision: http://reviews.llvm.org/D12509 llvm-svn: 246554
Diffstat (limited to 'llvm/lib/MC/MachObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/MachObjectWriter.cpp39
1 files changed, 20 insertions, 19 deletions
diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp
index 59565e28978..b9ab6c12a47 100644
--- a/llvm/lib/MC/MachObjectWriter.cpp
+++ b/llvm/lib/MC/MachObjectWriter.cpp
@@ -129,7 +129,7 @@ void MachObjectWriter::writeHeader(MachO::HeaderFileType Type,
// struct mach_header (28 bytes) or
// struct mach_header_64 (32 bytes)
- uint64_t Start = OS.tell();
+ uint64_t Start = getStream().tell();
(void) Start;
write32(is64Bit() ? MachO::MH_MAGIC_64 : MachO::MH_MAGIC);
@@ -144,8 +144,9 @@ void MachObjectWriter::writeHeader(MachO::HeaderFileType Type,
if (is64Bit())
write32(0); // reserved
- assert(OS.tell() - Start ==
- (is64Bit()?sizeof(MachO::mach_header_64): sizeof(MachO::mach_header)));
+ assert(
+ getStream().tell() - Start ==
+ (is64Bit() ? sizeof(MachO::mach_header_64) : sizeof(MachO::mach_header)));
}
/// writeSegmentLoadCommand - Write a segment load command.
@@ -159,7 +160,7 @@ void MachObjectWriter::writeSegmentLoadCommand(
// struct segment_command (56 bytes) or
// struct segment_command_64 (72 bytes)
- uint64_t Start = OS.tell();
+ uint64_t Start = getStream().tell();
(void) Start;
unsigned SegmentLoadCommandSize =
@@ -190,7 +191,7 @@ void MachObjectWriter::writeSegmentLoadCommand(
write32(NumSections);
write32(0); // flags
- assert(OS.tell() - Start == SegmentLoadCommandSize);
+ assert(getStream().tell() - Start == SegmentLoadCommandSize);
}
void MachObjectWriter::writeSection(const MCAsmLayout &Layout,
@@ -210,7 +211,7 @@ void MachObjectWriter::writeSection(const MCAsmLayout &Layout,
// struct section (68 bytes) or
// struct section_64 (80 bytes)
- uint64_t Start = OS.tell();
+ uint64_t Start = getStream().tell();
(void) Start;
writeBytes(Section.getSectionName(), 16);
@@ -234,8 +235,8 @@ void MachObjectWriter::writeSection(const MCAsmLayout &Layout,
if (is64Bit())
write32(0); // reserved3
- assert(OS.tell() - Start == (is64Bit() ? sizeof(MachO::section_64) :
- sizeof(MachO::section)));
+ assert(getStream().tell() - Start ==
+ (is64Bit() ? sizeof(MachO::section_64) : sizeof(MachO::section)));
}
void MachObjectWriter::writeSymtabLoadCommand(uint32_t SymbolOffset,
@@ -244,7 +245,7 @@ void MachObjectWriter::writeSymtabLoadCommand(uint32_t SymbolOffset,
uint32_t StringTableSize) {
// struct symtab_command (24 bytes)
- uint64_t Start = OS.tell();
+ uint64_t Start = getStream().tell();
(void) Start;
write32(MachO::LC_SYMTAB);
@@ -254,7 +255,7 @@ void MachObjectWriter::writeSymtabLoadCommand(uint32_t SymbolOffset,
write32(StringTableOffset);
write32(StringTableSize);
- assert(OS.tell() - Start == sizeof(MachO::symtab_command));
+ assert(getStream().tell() - Start == sizeof(MachO::symtab_command));
}
void MachObjectWriter::writeDysymtabLoadCommand(uint32_t FirstLocalSymbol,
@@ -267,7 +268,7 @@ void MachObjectWriter::writeDysymtabLoadCommand(uint32_t FirstLocalSymbol,
uint32_t NumIndirectSymbols) {
// struct dysymtab_command (80 bytes)
- uint64_t Start = OS.tell();
+ uint64_t Start = getStream().tell();
(void) Start;
write32(MachO::LC_DYSYMTAB);
@@ -291,7 +292,7 @@ void MachObjectWriter::writeDysymtabLoadCommand(uint32_t FirstLocalSymbol,
write32(0); // locreloff
write32(0); // nlocrel
- assert(OS.tell() - Start == sizeof(MachO::dysymtab_command));
+ assert(getStream().tell() - Start == sizeof(MachO::dysymtab_command));
}
MachObjectWriter::MachSymbolData *
@@ -387,7 +388,7 @@ void MachObjectWriter::writeNlist(MachSymbolData &MSD,
void MachObjectWriter::writeLinkeditLoadCommand(uint32_t Type,
uint32_t DataOffset,
uint32_t DataSize) {
- uint64_t Start = OS.tell();
+ uint64_t Start = getStream().tell();
(void) Start;
write32(Type);
@@ -395,7 +396,7 @@ void MachObjectWriter::writeLinkeditLoadCommand(uint32_t Type,
write32(DataOffset);
write32(DataSize);
- assert(OS.tell() - Start == sizeof(MachO::linkedit_data_command));
+ assert(getStream().tell() - Start == sizeof(MachO::linkedit_data_command));
}
static unsigned ComputeLinkerOptionsLoadCommandSize(
@@ -411,7 +412,7 @@ void MachObjectWriter::writeLinkerOptionsLoadCommand(
const std::vector<std::string> &Options)
{
unsigned Size = ComputeLinkerOptionsLoadCommandSize(Options, is64Bit());
- uint64_t Start = OS.tell();
+ uint64_t Start = getStream().tell();
(void) Start;
write32(MachO::LC_LINKER_OPTION);
@@ -427,7 +428,7 @@ void MachObjectWriter::writeLinkerOptionsLoadCommand(
// Pad to a multiple of the pointer size.
writeBytes("", OffsetToAlignment(BytesWritten, is64Bit() ? 8 : 4));
- assert(OS.tell() - Start == Size);
+ assert(getStream().tell() - Start == Size);
}
void MachObjectWriter::recordRelocation(MCAssembler &Asm,
@@ -906,12 +907,12 @@ void MachObjectWriter::writeObject(MCAssembler &Asm,
// Write out the loh commands, if there is one.
if (LOHSize) {
#ifndef NDEBUG
- unsigned Start = OS.tell();
+ unsigned Start = getStream().tell();
#endif
Asm.getLOHContainer().emit(*this, Layout);
// Pad to a multiple of the pointer size.
writeBytes("", OffsetToAlignment(LOHRawSize, is64Bit() ? 8 : 4));
- assert(OS.tell() - Start == LOHSize);
+ assert(getStream().tell() - Start == LOHSize);
}
// Write the symbol table data, if used.
@@ -947,7 +948,7 @@ void MachObjectWriter::writeObject(MCAssembler &Asm,
writeNlist(Entry, Layout);
// Write the string table.
- OS << StringTable.data();
+ getStream() << StringTable.data();
}
}
OpenPOWER on IntegriCloud