MC: Clean up naming in MCObjectWriter. NFC.

s/WriteObject/writeObject/
s/RecordRelocation/recordRelocation/
s/IsSymbolRefDifferenceFullyResolved/isSymbolRefDifferenceFullyResolved/
s/Write8/write8/
s/WriteLE16/writeLE16/
s/WriteLE32/writeLE32/
s/WriteLE64/writeLE64/
s/WriteBE16/writeBE16/
s/WriteBE32/writeBE32/
s/WriteBE64/writeBE64/
s/Write16/write16/
s/Write32/write32/
s/Write64/write64/
s/WriteZeroes/writeZeroes/
s/WriteBytes/writeBytes/

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239108 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jim Grosbach
2015-06-04 22:24:41 +00:00
parent cc68225e0c
commit bc81286cac
20 changed files with 262 additions and 262 deletions

View File

@@ -62,7 +62,7 @@ public:
/// \name API /// \name API
/// @{ /// @{
virtual void RecordRelocation(MachObjectWriter *Writer, MCAssembler &Asm, virtual void recordRelocation(MachObjectWriter *Writer, MCAssembler &Asm,
const MCAsmLayout &Layout, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCFragment *Fragment,
const MCFixup &Fixup, MCValue Target, const MCFixup &Fixup, MCValue Target,
@@ -234,7 +234,7 @@ public:
const MCFixup &Fixup, MCValue Target, const MCFixup &Fixup, MCValue Target,
uint64_t &FixedValue); uint64_t &FixedValue);
void RecordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCFixup &Fixup, const MCFragment *Fragment, const MCFixup &Fixup,
MCValue Target, bool &IsPCRel, MCValue Target, bool &IsPCRel,
uint64_t &FixedValue) override; uint64_t &FixedValue) override;
@@ -254,12 +254,12 @@ public:
void ExecutePostLayoutBinding(MCAssembler &Asm, void ExecutePostLayoutBinding(MCAssembler &Asm,
const MCAsmLayout &Layout) override; const MCAsmLayout &Layout) override;
bool IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
const MCSymbol &SymA, const MCSymbol &SymA,
const MCFragment &FB, bool InSet, const MCFragment &FB, bool InSet,
bool IsPCRel) const override; bool IsPCRel) const override;
void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout) override; void writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
}; };

View File

@@ -32,7 +32,7 @@ class MCValue;
/// the object writer to modify the assembler data structures at appropriate /// the object writer to modify the assembler data structures at appropriate
/// points. Once assembly is complete, the object writer is given the /// points. Once assembly is complete, the object writer is given the
/// MCAssembler instance, which contains all the symbol and section data which /// MCAssembler instance, which contains all the symbol and section data which
/// should be emitted as part of WriteObject(). /// should be emitted as part of writeObject().
/// ///
/// The object writer also contains a number of helper methods for writing /// The object writer also contains a number of helper methods for writing
/// binary data to the output stream. /// binary data to the output stream.
@@ -75,8 +75,8 @@ public:
/// This routine is called by the assembler after layout and relaxation, and /// This routine is called by the assembler after layout and relaxation, and
/// post layout binding. The implementation is responsible for storing /// post layout binding. The implementation is responsible for storing
/// information about the relocation so that it can be emitted during /// information about the relocation so that it can be emitted during
/// WriteObject(). /// writeObject().
virtual void RecordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCFragment *Fragment,
const MCFixup &Fixup, MCValue Target, const MCFixup &Fixup, MCValue Target,
bool &IsPCRel, uint64_t &FixedValue) = 0; bool &IsPCRel, uint64_t &FixedValue) = 0;
@@ -86,12 +86,12 @@ public:
/// ///
/// Clients are not required to answer precisely and may conservatively return /// Clients are not required to answer precisely and may conservatively return
/// false, even when a difference is fully resolved. /// false, even when a difference is fully resolved.
bool IsSymbolRefDifferenceFullyResolved(const MCAssembler &Asm, bool isSymbolRefDifferenceFullyResolved(const MCAssembler &Asm,
const MCSymbolRefExpr *A, const MCSymbolRefExpr *A,
const MCSymbolRefExpr *B, const MCSymbolRefExpr *B,
bool InSet) const; bool InSet) const;
virtual bool IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
const MCSymbol &SymA, const MCSymbol &SymA,
const MCFragment &FB, const MCFragment &FB,
bool InSet, bool InSet,
@@ -107,57 +107,57 @@ public:
/// This routine is called by the assembler after layout and relaxation is /// This routine is called by the assembler after layout and relaxation is
/// complete, fixups have been evaluated and applied, and relocations /// complete, fixups have been evaluated and applied, and relocations
/// generated. /// generated.
virtual void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout) = 0; virtual void writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) = 0;
/// @} /// @}
/// \name Binary Output /// \name Binary Output
/// @{ /// @{
void Write8(uint8_t Value) { OS << char(Value); } void write8(uint8_t Value) { OS << char(Value); }
void WriteLE16(uint16_t Value) { void writeLE16(uint16_t Value) {
support::endian::Writer<support::little>(OS).write(Value); support::endian::Writer<support::little>(OS).write(Value);
} }
void WriteLE32(uint32_t Value) { void writeLE32(uint32_t Value) {
support::endian::Writer<support::little>(OS).write(Value); support::endian::Writer<support::little>(OS).write(Value);
} }
void WriteLE64(uint64_t Value) { void writeLE64(uint64_t Value) {
support::endian::Writer<support::little>(OS).write(Value); support::endian::Writer<support::little>(OS).write(Value);
} }
void WriteBE16(uint16_t Value) { void writeBE16(uint16_t Value) {
support::endian::Writer<support::big>(OS).write(Value); support::endian::Writer<support::big>(OS).write(Value);
} }
void WriteBE32(uint32_t Value) { void writeBE32(uint32_t Value) {
support::endian::Writer<support::big>(OS).write(Value); support::endian::Writer<support::big>(OS).write(Value);
} }
void WriteBE64(uint64_t Value) { void writeBE64(uint64_t Value) {
support::endian::Writer<support::big>(OS).write(Value); support::endian::Writer<support::big>(OS).write(Value);
} }
void Write16(uint16_t Value) { void write16(uint16_t Value) {
if (IsLittleEndian) if (IsLittleEndian)
WriteLE16(Value); writeLE16(Value);
else else
WriteBE16(Value); writeBE16(Value);
} }
void Write32(uint32_t Value) { void write32(uint32_t Value) {
if (IsLittleEndian) if (IsLittleEndian)
WriteLE32(Value); writeLE32(Value);
else else
WriteBE32(Value); writeBE32(Value);
} }
void Write64(uint64_t Value) { void write64(uint64_t Value) {
if (IsLittleEndian) if (IsLittleEndian)
WriteLE64(Value); writeLE64(Value);
else else
WriteBE64(Value); writeBE64(Value);
} }
void WriteZeros(unsigned N) { void WriteZeros(unsigned N) {
@@ -169,12 +169,12 @@ public:
OS << StringRef(Zeros, N % 16); OS << StringRef(Zeros, N % 16);
} }
void WriteBytes(const SmallVectorImpl<char> &ByteVec, void writeBytes(const SmallVectorImpl<char> &ByteVec,
unsigned ZeroFillSize = 0) { unsigned ZeroFillSize = 0) {
WriteBytes(StringRef(ByteVec.data(), ByteVec.size()), ZeroFillSize); writeBytes(StringRef(ByteVec.data(), ByteVec.size()), ZeroFillSize);
} }
void WriteBytes(StringRef Str, unsigned ZeroFillSize = 0) { void writeBytes(StringRef Str, unsigned ZeroFillSize = 0) {
// TODO: this version may need to go away once all fragment contents are // TODO: this version may need to go away once all fragment contents are
// converted to SmallVector<char, N> // converted to SmallVector<char, N>
assert( assert(

View File

@@ -150,9 +150,9 @@ class ELFObjectWriter : public MCObjectWriter {
void WriteWord(uint64_t W) { void WriteWord(uint64_t W) {
if (is64Bit()) if (is64Bit())
Write64(W); write64(W);
else else
Write32(W); write32(W);
} }
template <typename T> void write(T Val) { template <typename T> void write(T Val) {
@@ -176,7 +176,7 @@ class ELFObjectWriter : public MCObjectWriter {
const MCSymbol *Sym, uint64_t C, const MCSymbol *Sym, uint64_t C,
unsigned Type) const; unsigned Type) const;
void RecordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCFixup &Fixup, const MCFragment *Fragment, const MCFixup &Fixup,
MCValue Target, bool &IsPCRel, MCValue Target, bool &IsPCRel,
uint64_t &FixedValue) override; uint64_t &FixedValue) override;
@@ -216,7 +216,7 @@ class ELFObjectWriter : public MCObjectWriter {
void writeRelocations(const MCAssembler &Asm, const MCSectionELF &Sec); void writeRelocations(const MCAssembler &Asm, const MCSectionELF &Sec);
bool IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
const MCSymbol &SymA, const MCSymbol &SymA,
const MCFragment &FB, const MCFragment &FB,
bool InSet, bool InSet,
@@ -224,7 +224,7 @@ class ELFObjectWriter : public MCObjectWriter {
bool isWeak(const MCSymbol &Sym) const override; bool isWeak(const MCSymbol &Sym) const override;
void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout) override; void writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
void writeSection(const SectionIndexMapTy &SectionIndexMap, void writeSection(const SectionIndexMapTy &SectionIndexMap,
uint32_t GroupSymbolIndex, uint64_t Offset, uint64_t Size, uint32_t GroupSymbolIndex, uint64_t Offset, uint64_t Size,
const MCSectionELF &Section); const MCSectionELF &Section);
@@ -307,47 +307,47 @@ void ELFObjectWriter::writeHeader(const MCAssembler &Asm) {
// emitWord method behaves differently for ELF32 and ELF64, writing // emitWord method behaves differently for ELF32 and ELF64, writing
// 4 bytes in the former and 8 in the latter. // 4 bytes in the former and 8 in the latter.
WriteBytes(ELF::ElfMagic); // e_ident[EI_MAG0] to e_ident[EI_MAG3] writeBytes(ELF::ElfMagic); // e_ident[EI_MAG0] to e_ident[EI_MAG3]
Write8(is64Bit() ? ELF::ELFCLASS64 : ELF::ELFCLASS32); // e_ident[EI_CLASS] write8(is64Bit() ? ELF::ELFCLASS64 : ELF::ELFCLASS32); // e_ident[EI_CLASS]
// e_ident[EI_DATA] // e_ident[EI_DATA]
Write8(isLittleEndian() ? ELF::ELFDATA2LSB : ELF::ELFDATA2MSB); write8(isLittleEndian() ? ELF::ELFDATA2LSB : ELF::ELFDATA2MSB);
Write8(ELF::EV_CURRENT); // e_ident[EI_VERSION] write8(ELF::EV_CURRENT); // e_ident[EI_VERSION]
// e_ident[EI_OSABI] // e_ident[EI_OSABI]
Write8(TargetObjectWriter->getOSABI()); write8(TargetObjectWriter->getOSABI());
Write8(0); // e_ident[EI_ABIVERSION] write8(0); // e_ident[EI_ABIVERSION]
WriteZeros(ELF::EI_NIDENT - ELF::EI_PAD); WriteZeros(ELF::EI_NIDENT - ELF::EI_PAD);
Write16(ELF::ET_REL); // e_type write16(ELF::ET_REL); // e_type
Write16(TargetObjectWriter->getEMachine()); // e_machine = target write16(TargetObjectWriter->getEMachine()); // e_machine = target
Write32(ELF::EV_CURRENT); // e_version write32(ELF::EV_CURRENT); // e_version
WriteWord(0); // e_entry, no entry point in .o file WriteWord(0); // e_entry, no entry point in .o file
WriteWord(0); // e_phoff, no program header for .o WriteWord(0); // e_phoff, no program header for .o
WriteWord(0); // e_shoff = sec hdr table off in bytes WriteWord(0); // e_shoff = sec hdr table off in bytes
// e_flags = whatever the target wants // e_flags = whatever the target wants
Write32(Asm.getELFHeaderEFlags()); write32(Asm.getELFHeaderEFlags());
// e_ehsize = ELF header size // e_ehsize = ELF header size
Write16(is64Bit() ? sizeof(ELF::Elf64_Ehdr) : sizeof(ELF::Elf32_Ehdr)); write16(is64Bit() ? sizeof(ELF::Elf64_Ehdr) : sizeof(ELF::Elf32_Ehdr));
Write16(0); // e_phentsize = prog header entry size write16(0); // e_phentsize = prog header entry size
Write16(0); // e_phnum = # prog header entries = 0 write16(0); // e_phnum = # prog header entries = 0
// e_shentsize = Section header entry size // e_shentsize = Section header entry size
Write16(is64Bit() ? sizeof(ELF::Elf64_Shdr) : sizeof(ELF::Elf32_Shdr)); write16(is64Bit() ? sizeof(ELF::Elf64_Shdr) : sizeof(ELF::Elf32_Shdr));
// e_shnum = # of section header ents // e_shnum = # of section header ents
Write16(0); write16(0);
// e_shstrndx = Section # of '.shstrtab' // e_shstrndx = Section # of '.shstrtab'
assert(StringTableIndex < ELF::SHN_LORESERVE); assert(StringTableIndex < ELF::SHN_LORESERVE);
Write16(StringTableIndex); write16(StringTableIndex);
} }
uint64_t ELFObjectWriter::SymbolValue(const MCSymbol &Sym, uint64_t ELFObjectWriter::SymbolValue(const MCSymbol &Sym,
@@ -605,7 +605,7 @@ static bool isWeak(const MCSymbolELF &Sym) {
} }
} }
void ELFObjectWriter::RecordRelocation(MCAssembler &Asm, void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
const MCAsmLayout &Layout, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCFragment *Fragment,
const MCFixup &Fixup, MCValue Target, const MCFixup &Fixup, MCValue Target,
@@ -1035,14 +1035,14 @@ void ELFObjectWriter::WriteSecHdrEntry(uint32_t Name, uint32_t Type,
uint32_t Link, uint32_t Info, uint32_t Link, uint32_t Info,
uint64_t Alignment, uint64_t Alignment,
uint64_t EntrySize) { uint64_t EntrySize) {
Write32(Name); // sh_name: index into string table write32(Name); // sh_name: index into string table
Write32(Type); // sh_type write32(Type); // sh_type
WriteWord(Flags); // sh_flags WriteWord(Flags); // sh_flags
WriteWord(Address); // sh_addr WriteWord(Address); // sh_addr
WriteWord(Offset); // sh_offset WriteWord(Offset); // sh_offset
WriteWord(Size); // sh_size WriteWord(Size); // sh_size
Write32(Link); // sh_link write32(Link); // sh_link
Write32(Info); // sh_info write32(Info); // sh_info
WriteWord(Alignment); // sh_addralign WriteWord(Alignment); // sh_addralign
WriteWord(EntrySize); // sh_entsize WriteWord(EntrySize); // sh_entsize
} }
@@ -1174,7 +1174,7 @@ void ELFObjectWriter::writeSectionHeader(
} }
} }
void ELFObjectWriter::WriteObject(MCAssembler &Asm, void ELFObjectWriter::writeObject(MCAssembler &Asm,
const MCAsmLayout &Layout) { const MCAsmLayout &Layout) {
MCContext &Ctx = Asm.getContext(); MCContext &Ctx = Asm.getContext();
MCSectionELF *StrtabSection = MCSectionELF *StrtabSection =
@@ -1308,7 +1308,7 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
NumSectionsOffset); NumSectionsOffset);
} }
bool ELFObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl( bool ELFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
const MCAssembler &Asm, const MCSymbol &SA, const MCFragment &FB, const MCAssembler &Asm, const MCSymbol &SA, const MCFragment &FB,
bool InSet, bool IsPCRel) const { bool InSet, bool IsPCRel) const {
const auto &SymA = cast<MCSymbolELF>(SA); const auto &SymA = cast<MCSymbolELF>(SA);
@@ -1317,7 +1317,7 @@ bool ELFObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(
if (::isWeak(SymA)) if (::isWeak(SymA))
return false; return false;
} }
return MCObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(Asm, SymA, FB, return MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(Asm, SymA, FB,
InSet, IsPCRel); InSet, IsPCRel);
} }

View File

@@ -394,7 +394,7 @@ bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout,
MCValue &Target, uint64_t &Value) const { MCValue &Target, uint64_t &Value) const {
++stats::evaluateFixup; ++stats::evaluateFixup;
// FIXME: This code has some duplication with RecordRelocation. We should // FIXME: This code has some duplication with recordRelocation. We should
// probably merge the two into a single callback that tries to evaluate a // probably merge the two into a single callback that tries to evaluate a
// fixup and records a relocation if one is needed. // fixup and records a relocation if one is needed.
const MCExpr *Expr = Fixup.getValue(); const MCExpr *Expr = Fixup.getValue();
@@ -416,7 +416,7 @@ bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout,
if (A->getKind() != MCSymbolRefExpr::VK_None || SA.isUndefined()) { if (A->getKind() != MCSymbolRefExpr::VK_None || SA.isUndefined()) {
IsResolved = false; IsResolved = false;
} else { } else {
IsResolved = getWriter().IsSymbolRefDifferenceFullyResolvedImpl( IsResolved = getWriter().isSymbolRefDifferenceFullyResolvedImpl(
*this, SA, *DF, false, true); *this, SA, *DF, false, true);
} }
} }
@@ -576,7 +576,7 @@ void MCAsmLayout::layoutFragment(MCFragment *F) {
/// a MCEncodedFragment. /// a MCEncodedFragment.
static void writeFragmentContents(const MCFragment &F, MCObjectWriter *OW) { static void writeFragmentContents(const MCFragment &F, MCObjectWriter *OW) {
const MCEncodedFragment &EF = cast<MCEncodedFragment>(F); const MCEncodedFragment &EF = cast<MCEncodedFragment>(F);
OW->WriteBytes(EF.getContents()); OW->writeBytes(EF.getContents());
} }
void MCAssembler::registerSymbol(const MCSymbol &Symbol, bool *Created) { void MCAssembler::registerSymbol(const MCSymbol &Symbol, bool *Created) {
@@ -670,10 +670,10 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout,
for (uint64_t i = 0; i != Count; ++i) { for (uint64_t i = 0; i != Count; ++i) {
switch (AF.getValueSize()) { switch (AF.getValueSize()) {
default: llvm_unreachable("Invalid size!"); default: llvm_unreachable("Invalid size!");
case 1: OW->Write8 (uint8_t (AF.getValue())); break; case 1: OW->write8 (uint8_t (AF.getValue())); break;
case 2: OW->Write16(uint16_t(AF.getValue())); break; case 2: OW->write16(uint16_t(AF.getValue())); break;
case 4: OW->Write32(uint32_t(AF.getValue())); break; case 4: OW->write32(uint32_t(AF.getValue())); break;
case 8: OW->Write64(uint64_t(AF.getValue())); break; case 8: OW->write64(uint64_t(AF.getValue())); break;
} }
} }
break; break;
@@ -703,10 +703,10 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout,
for (uint64_t i = 0, e = FF.getSize() / FF.getValueSize(); i != e; ++i) { for (uint64_t i = 0, e = FF.getSize() / FF.getValueSize(); i != e; ++i) {
switch (FF.getValueSize()) { switch (FF.getValueSize()) {
default: llvm_unreachable("Invalid size!"); default: llvm_unreachable("Invalid size!");
case 1: OW->Write8 (uint8_t (FF.getValue())); break; case 1: OW->write8 (uint8_t (FF.getValue())); break;
case 2: OW->Write16(uint16_t(FF.getValue())); break; case 2: OW->write16(uint16_t(FF.getValue())); break;
case 4: OW->Write32(uint32_t(FF.getValue())); break; case 4: OW->write32(uint32_t(FF.getValue())); break;
case 8: OW->Write64(uint64_t(FF.getValue())); break; case 8: OW->write64(uint64_t(FF.getValue())); break;
} }
} }
break; break;
@@ -714,13 +714,13 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout,
case MCFragment::FT_LEB: { case MCFragment::FT_LEB: {
const MCLEBFragment &LF = cast<MCLEBFragment>(F); const MCLEBFragment &LF = cast<MCLEBFragment>(F);
OW->WriteBytes(LF.getContents()); OW->writeBytes(LF.getContents());
break; break;
} }
case MCFragment::FT_SafeSEH: { case MCFragment::FT_SafeSEH: {
const MCSafeSEHFragment &SF = cast<MCSafeSEHFragment>(F); const MCSafeSEHFragment &SF = cast<MCSafeSEHFragment>(F);
OW->Write32(SF.getSymbol()->getIndex()); OW->write32(SF.getSymbol()->getIndex());
break; break;
} }
@@ -729,19 +729,19 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout,
const MCOrgFragment &OF = cast<MCOrgFragment>(F); const MCOrgFragment &OF = cast<MCOrgFragment>(F);
for (uint64_t i = 0, e = FragmentSize; i != e; ++i) for (uint64_t i = 0, e = FragmentSize; i != e; ++i)
OW->Write8(uint8_t(OF.getValue())); OW->write8(uint8_t(OF.getValue()));
break; break;
} }
case MCFragment::FT_Dwarf: { case MCFragment::FT_Dwarf: {
const MCDwarfLineAddrFragment &OF = cast<MCDwarfLineAddrFragment>(F); const MCDwarfLineAddrFragment &OF = cast<MCDwarfLineAddrFragment>(F);
OW->WriteBytes(OF.getContents()); OW->writeBytes(OF.getContents());
break; break;
} }
case MCFragment::FT_DwarfFrame: { case MCFragment::FT_DwarfFrame: {
const MCDwarfCallFrameFragment &CF = cast<MCDwarfCallFrameFragment>(F); const MCDwarfCallFrameFragment &CF = cast<MCDwarfCallFrameFragment>(F);
OW->WriteBytes(CF.getContents()); OW->writeBytes(CF.getContents());
break; break;
} }
} }
@@ -819,7 +819,7 @@ std::pair<uint64_t, bool> MCAssembler::handleFixup(const MCAsmLayout &Layout,
// The fixup was unresolved, we need a relocation. Inform the object // The fixup was unresolved, we need a relocation. Inform the object
// writer of the relocation, and give it an opportunity to adjust the // writer of the relocation, and give it an opportunity to adjust the
// fixup value if need be. // fixup value if need be.
getWriter().RecordRelocation(*this, Layout, &F, Fixup, Target, IsPCRel, getWriter().recordRelocation(*this, Layout, &F, Fixup, Target, IsPCRel,
FixedValue); FixedValue);
} }
return std::make_pair(FixedValue, IsPCRel); return std::make_pair(FixedValue, IsPCRel);
@@ -897,7 +897,7 @@ void MCAssembler::Finish() {
} }
// Write the object file. // Write the object file.
getWriter().WriteObject(*this, Layout); getWriter().writeObject(*this, Layout);
stats::ObjectBytes += OS.tell() - StartOffset; stats::ObjectBytes += OS.tell() - StartOffset;
} }

View File

@@ -468,7 +468,7 @@ static void AttemptToFoldSymbolOffsetDifference(
if (SA.isUndefined() || SB.isUndefined()) if (SA.isUndefined() || SB.isUndefined())
return; return;
if (!Asm->getWriter().IsSymbolRefDifferenceFullyResolved(*Asm, A, B, InSet)) if (!Asm->getWriter().isSymbolRefDifferenceFullyResolved(*Asm, A, B, InSet))
return; return;
if (SA.getFragment() == SB.getFragment()) { if (SA.getFragment() == SB.getFragment()) {

View File

@@ -17,7 +17,7 @@ using namespace llvm;
MCObjectWriter::~MCObjectWriter() { MCObjectWriter::~MCObjectWriter() {
} }
bool MCObjectWriter::IsSymbolRefDifferenceFullyResolved( bool MCObjectWriter::isSymbolRefDifferenceFullyResolved(
const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B, const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B,
bool InSet) const { bool InSet) const {
// Modified symbol references cannot be resolved. // Modified symbol references cannot be resolved.
@@ -33,11 +33,11 @@ bool MCObjectWriter::IsSymbolRefDifferenceFullyResolved(
if (!SA.getFragment() || !SB.getFragment()) if (!SA.getFragment() || !SB.getFragment())
return false; return false;
return IsSymbolRefDifferenceFullyResolvedImpl(Asm, SA, *SB.getFragment(), return isSymbolRefDifferenceFullyResolvedImpl(Asm, SA, *SB.getFragment(),
InSet, false); InSet, false);
} }
bool MCObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl( bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB, const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB,
bool InSet, bool IsPCRel) const { bool InSet, bool IsPCRel) const {
const MCSection &SecA = SymA.getSection(); const MCSection &SecA = SymA.getSection();

View File

@@ -132,17 +132,17 @@ void MachObjectWriter::WriteHeader(unsigned NumLoadCommands,
uint64_t Start = OS.tell(); uint64_t Start = OS.tell();
(void) Start; (void) Start;
Write32(is64Bit() ? MachO::MH_MAGIC_64 : MachO::MH_MAGIC); write32(is64Bit() ? MachO::MH_MAGIC_64 : MachO::MH_MAGIC);
Write32(TargetObjectWriter->getCPUType()); write32(TargetObjectWriter->getCPUType());
Write32(TargetObjectWriter->getCPUSubtype()); write32(TargetObjectWriter->getCPUSubtype());
Write32(MachO::MH_OBJECT); write32(MachO::MH_OBJECT);
Write32(NumLoadCommands); write32(NumLoadCommands);
Write32(LoadCommandsSize); write32(LoadCommandsSize);
Write32(Flags); write32(Flags);
if (is64Bit()) if (is64Bit())
Write32(0); // reserved write32(0); // reserved
assert(OS.tell() - Start == assert(OS.tell() - Start ==
(is64Bit()?sizeof(MachO::mach_header_64): sizeof(MachO::mach_header))); (is64Bit()?sizeof(MachO::mach_header_64): sizeof(MachO::mach_header)));
@@ -165,29 +165,29 @@ void MachObjectWriter::WriteSegmentLoadCommand(unsigned NumSections,
unsigned SegmentLoadCommandSize = unsigned SegmentLoadCommandSize =
is64Bit() ? sizeof(MachO::segment_command_64): is64Bit() ? sizeof(MachO::segment_command_64):
sizeof(MachO::segment_command); sizeof(MachO::segment_command);
Write32(is64Bit() ? MachO::LC_SEGMENT_64 : MachO::LC_SEGMENT); write32(is64Bit() ? MachO::LC_SEGMENT_64 : MachO::LC_SEGMENT);
Write32(SegmentLoadCommandSize + write32(SegmentLoadCommandSize +
NumSections * (is64Bit() ? sizeof(MachO::section_64) : NumSections * (is64Bit() ? sizeof(MachO::section_64) :
sizeof(MachO::section))); sizeof(MachO::section)));
WriteBytes("", 16); writeBytes("", 16);
if (is64Bit()) { if (is64Bit()) {
Write64(0); // vmaddr write64(0); // vmaddr
Write64(VMSize); // vmsize write64(VMSize); // vmsize
Write64(SectionDataStartOffset); // file offset write64(SectionDataStartOffset); // file offset
Write64(SectionDataSize); // file size write64(SectionDataSize); // file size
} else { } else {
Write32(0); // vmaddr write32(0); // vmaddr
Write32(VMSize); // vmsize write32(VMSize); // vmsize
Write32(SectionDataStartOffset); // file offset write32(SectionDataStartOffset); // file offset
Write32(SectionDataSize); // file size write32(SectionDataSize); // file size
} }
// maxprot // maxprot
Write32(MachO::VM_PROT_READ | MachO::VM_PROT_WRITE | MachO::VM_PROT_EXECUTE); write32(MachO::VM_PROT_READ | MachO::VM_PROT_WRITE | MachO::VM_PROT_EXECUTE);
// initprot // initprot
Write32(MachO::VM_PROT_READ | MachO::VM_PROT_WRITE | MachO::VM_PROT_EXECUTE); write32(MachO::VM_PROT_READ | MachO::VM_PROT_WRITE | MachO::VM_PROT_EXECUTE);
Write32(NumSections); write32(NumSections);
Write32(0); // flags write32(0); // flags
assert(OS.tell() - Start == SegmentLoadCommandSize); assert(OS.tell() - Start == SegmentLoadCommandSize);
} }
@@ -212,30 +212,30 @@ void MachObjectWriter::WriteSection(const MCAssembler &Asm,
uint64_t Start = OS.tell(); uint64_t Start = OS.tell();
(void) Start; (void) Start;
WriteBytes(Section.getSectionName(), 16); writeBytes(Section.getSectionName(), 16);
WriteBytes(Section.getSegmentName(), 16); writeBytes(Section.getSegmentName(), 16);
if (is64Bit()) { if (is64Bit()) {
Write64(getSectionAddress(&Sec)); // address write64(getSectionAddress(&Sec)); // address
Write64(SectionSize); // size write64(SectionSize); // size
} else { } else {
Write32(getSectionAddress(&Sec)); // address write32(getSectionAddress(&Sec)); // address
Write32(SectionSize); // size write32(SectionSize); // size
} }
Write32(FileOffset); write32(FileOffset);
unsigned Flags = Section.getTypeAndAttributes(); unsigned Flags = Section.getTypeAndAttributes();
if (Section.hasInstructions()) if (Section.hasInstructions())
Flags |= MachO::S_ATTR_SOME_INSTRUCTIONS; Flags |= MachO::S_ATTR_SOME_INSTRUCTIONS;
assert(isPowerOf2_32(Section.getAlignment()) && "Invalid alignment!"); assert(isPowerOf2_32(Section.getAlignment()) && "Invalid alignment!");
Write32(Log2_32(Section.getAlignment())); write32(Log2_32(Section.getAlignment()));
Write32(NumRelocations ? RelocationsStart : 0); write32(NumRelocations ? RelocationsStart : 0);
Write32(NumRelocations); write32(NumRelocations);
Write32(Flags); write32(Flags);
Write32(IndirectSymBase.lookup(&Sec)); // reserved1 write32(IndirectSymBase.lookup(&Sec)); // reserved1
Write32(Section.getStubSize()); // reserved2 write32(Section.getStubSize()); // reserved2
if (is64Bit()) if (is64Bit())
Write32(0); // reserved3 write32(0); // reserved3
assert(OS.tell() - Start == (is64Bit() ? sizeof(MachO::section_64) : assert(OS.tell() - Start == (is64Bit() ? sizeof(MachO::section_64) :
sizeof(MachO::section))); sizeof(MachO::section)));
@@ -250,12 +250,12 @@ void MachObjectWriter::WriteSymtabLoadCommand(uint32_t SymbolOffset,
uint64_t Start = OS.tell(); uint64_t Start = OS.tell();
(void) Start; (void) Start;
Write32(MachO::LC_SYMTAB); write32(MachO::LC_SYMTAB);
Write32(sizeof(MachO::symtab_command)); write32(sizeof(MachO::symtab_command));
Write32(SymbolOffset); write32(SymbolOffset);
Write32(NumSymbols); write32(NumSymbols);
Write32(StringTableOffset); write32(StringTableOffset);
Write32(StringTableSize); write32(StringTableSize);
assert(OS.tell() - Start == sizeof(MachO::symtab_command)); assert(OS.tell() - Start == sizeof(MachO::symtab_command));
} }
@@ -273,26 +273,26 @@ void MachObjectWriter::WriteDysymtabLoadCommand(uint32_t FirstLocalSymbol,
uint64_t Start = OS.tell(); uint64_t Start = OS.tell();
(void) Start; (void) Start;
Write32(MachO::LC_DYSYMTAB); write32(MachO::LC_DYSYMTAB);
Write32(sizeof(MachO::dysymtab_command)); write32(sizeof(MachO::dysymtab_command));
Write32(FirstLocalSymbol); write32(FirstLocalSymbol);
Write32(NumLocalSymbols); write32(NumLocalSymbols);
Write32(FirstExternalSymbol); write32(FirstExternalSymbol);
Write32(NumExternalSymbols); write32(NumExternalSymbols);
Write32(FirstUndefinedSymbol); write32(FirstUndefinedSymbol);
Write32(NumUndefinedSymbols); write32(NumUndefinedSymbols);
Write32(0); // tocoff write32(0); // tocoff
Write32(0); // ntoc write32(0); // ntoc
Write32(0); // modtaboff write32(0); // modtaboff
Write32(0); // nmodtab write32(0); // nmodtab
Write32(0); // extrefsymoff write32(0); // extrefsymoff
Write32(0); // nextrefsyms write32(0); // nextrefsyms
Write32(IndirectSymbolOffset); write32(IndirectSymbolOffset);
Write32(NumIndirectSymbols); write32(NumIndirectSymbols);
Write32(0); // extreloff write32(0); // extreloff
Write32(0); // nextrel write32(0); // nextrel
Write32(0); // locreloff write32(0); // locreloff
Write32(0); // nlocrel write32(0); // nlocrel
assert(OS.tell() - Start == sizeof(MachO::dysymtab_command)); assert(OS.tell() - Start == sizeof(MachO::dysymtab_command));
} }
@@ -390,17 +390,17 @@ void MachObjectWriter::WriteNlist(MachSymbolData &MSD,
// struct nlist (12 bytes) // struct nlist (12 bytes)
Write32(MSD.StringIndex); write32(MSD.StringIndex);
Write8(Type); write8(Type);
Write8(SectionIndex); write8(SectionIndex);
// The Mach-O streamer uses the lowest 16-bits of the flags for the 'desc' // The Mach-O streamer uses the lowest 16-bits of the flags for the 'desc'
// value. // value.
Write16(Flags); write16(Flags);
if (is64Bit()) if (is64Bit())
Write64(Address); write64(Address);
else else
Write32(Address); write32(Address);
} }
void MachObjectWriter::WriteLinkeditLoadCommand(uint32_t Type, void MachObjectWriter::WriteLinkeditLoadCommand(uint32_t Type,
@@ -409,10 +409,10 @@ void MachObjectWriter::WriteLinkeditLoadCommand(uint32_t Type,
uint64_t Start = OS.tell(); uint64_t Start = OS.tell();
(void) Start; (void) Start;
Write32(Type); write32(Type);
Write32(sizeof(MachO::linkedit_data_command)); write32(sizeof(MachO::linkedit_data_command));
Write32(DataOffset); write32(DataOffset);
Write32(DataSize); write32(DataSize);
assert(OS.tell() - Start == sizeof(MachO::linkedit_data_command)); assert(OS.tell() - Start == sizeof(MachO::linkedit_data_command));
} }
@@ -433,28 +433,28 @@ void MachObjectWriter::WriteLinkerOptionsLoadCommand(
uint64_t Start = OS.tell(); uint64_t Start = OS.tell();
(void) Start; (void) Start;
Write32(MachO::LC_LINKER_OPTION); write32(MachO::LC_LINKER_OPTION);
Write32(Size); write32(Size);
Write32(Options.size()); write32(Options.size());
uint64_t BytesWritten = sizeof(MachO::linker_option_command); uint64_t BytesWritten = sizeof(MachO::linker_option_command);
for (const std::string &Option : Options) { for (const std::string &Option : Options) {
// Write each string, including the null byte. // Write each string, including the null byte.
WriteBytes(Option.c_str(), Option.size() + 1); writeBytes(Option.c_str(), Option.size() + 1);
BytesWritten += Option.size() + 1; BytesWritten += Option.size() + 1;
} }
// Pad to a multiple of the pointer size. // Pad to a multiple of the pointer size.
WriteBytes("", OffsetToAlignment(BytesWritten, is64Bit() ? 8 : 4)); writeBytes("", OffsetToAlignment(BytesWritten, is64Bit() ? 8 : 4));
assert(OS.tell() - Start == Size); assert(OS.tell() - Start == Size);
} }
void MachObjectWriter::RecordRelocation(MCAssembler &Asm, void MachObjectWriter::recordRelocation(MCAssembler &Asm,
const MCAsmLayout &Layout, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCFragment *Fragment,
const MCFixup &Fixup, MCValue Target, const MCFixup &Fixup, MCValue Target,
bool &IsPCRel, uint64_t &FixedValue) { bool &IsPCRel, uint64_t &FixedValue) {
TargetObjectWriter->RecordRelocation(this, Asm, Layout, Fragment, Fixup, TargetObjectWriter->recordRelocation(this, Asm, Layout, Fragment, Fixup,
Target, FixedValue); Target, FixedValue);
} }
@@ -644,7 +644,7 @@ void MachObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm,
BindIndirectSymbols(Asm); BindIndirectSymbols(Asm);
} }
bool MachObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl( bool MachObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB, const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB,
bool InSet, bool IsPCRel) const { bool InSet, bool IsPCRel) const {
if (InSet) if (InSet)
@@ -711,7 +711,7 @@ bool MachObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(
return false; return false;
} }
void MachObjectWriter::WriteObject(MCAssembler &Asm, void MachObjectWriter::writeObject(MCAssembler &Asm,
const MCAsmLayout &Layout) { const MCAsmLayout &Layout) {
// Compute symbol table information and bind symbol indices. // Compute symbol table information and bind symbol indices.
ComputeSymbolTable(Asm, LocalSymbolData, ExternalSymbolData, ComputeSymbolTable(Asm, LocalSymbolData, ExternalSymbolData,
@@ -815,11 +815,11 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
assert(VersionInfo.Major < 65536 && "unencodable major target version"); assert(VersionInfo.Major < 65536 && "unencodable major target version");
uint32_t EncodedVersion = VersionInfo.Update | (VersionInfo.Minor << 8) | uint32_t EncodedVersion = VersionInfo.Update | (VersionInfo.Minor << 8) |
(VersionInfo.Major << 16); (VersionInfo.Major << 16);
Write32(VersionInfo.Kind == MCVM_OSXVersionMin ? MachO::LC_VERSION_MIN_MACOSX : write32(VersionInfo.Kind == MCVM_OSXVersionMin ? MachO::LC_VERSION_MIN_MACOSX :
MachO::LC_VERSION_MIN_IPHONEOS); MachO::LC_VERSION_MIN_IPHONEOS);
Write32(sizeof(MachO::version_min_command)); write32(sizeof(MachO::version_min_command));
Write32(EncodedVersion); write32(EncodedVersion);
Write32(0); // reserved. write32(0); // reserved.
} }
// Write the data-in-code load command, if used. // Write the data-in-code load command, if used.
@@ -893,8 +893,8 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
// (approximately, the exact algorithm is more complicated than this). // (approximately, the exact algorithm is more complicated than this).
std::vector<RelAndSymbol> &Relocs = Relocations[&Sec]; std::vector<RelAndSymbol> &Relocs = Relocations[&Sec];
for (const RelAndSymbol &Rel : make_range(Relocs.rbegin(), Relocs.rend())) { for (const RelAndSymbol &Rel : make_range(Relocs.rbegin(), Relocs.rend())) {
Write32(Rel.MRE.r_word0); write32(Rel.MRE.r_word0);
Write32(Rel.MRE.r_word1); write32(Rel.MRE.r_word1);
} }
} }
@@ -910,9 +910,9 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
<< " end: " << End << "(" << Data->End->getName() << ")" << " end: " << End << "(" << Data->End->getName() << ")"
<< " size: " << End - Start << " size: " << End - Start
<< "\n"); << "\n");
Write32(Start); write32(Start);
Write16(End - Start); write16(End - Start);
Write16(Data->Kind); write16(Data->Kind);
} }
// Write out the loh commands, if there is one. // Write out the loh commands, if there is one.
@@ -922,7 +922,7 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
#endif #endif
Asm.getLOHContainer().emit(*this, Layout); Asm.getLOHContainer().emit(*this, Layout);
// Pad to a multiple of the pointer size. // Pad to a multiple of the pointer size.
WriteBytes("", OffsetToAlignment(LOHRawSize, is64Bit() ? 8 : 4)); writeBytes("", OffsetToAlignment(LOHRawSize, is64Bit() ? 8 : 4));
assert(OS.tell() - Start == LOHSize); assert(OS.tell() - Start == LOHSize);
} }
@@ -942,12 +942,12 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
uint32_t Flags = MachO::INDIRECT_SYMBOL_LOCAL; uint32_t Flags = MachO::INDIRECT_SYMBOL_LOCAL;
if (it->Symbol->isAbsolute()) if (it->Symbol->isAbsolute())
Flags |= MachO::INDIRECT_SYMBOL_ABS; Flags |= MachO::INDIRECT_SYMBOL_ABS;
Write32(Flags); write32(Flags);
continue; continue;
} }
} }
Write32(it->Symbol->getIndex()); write32(it->Symbol->getIndex());
} }
// FIXME: Check that offsets match computed ones. // FIXME: Check that offsets match computed ones.

View File

@@ -177,19 +177,19 @@ public:
void ExecutePostLayoutBinding(MCAssembler &Asm, void ExecutePostLayoutBinding(MCAssembler &Asm,
const MCAsmLayout &Layout) override; const MCAsmLayout &Layout) override;
bool IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
const MCSymbol &SymA, const MCSymbol &SymA,
const MCFragment &FB, bool InSet, const MCFragment &FB, bool InSet,
bool IsPCRel) const override; bool IsPCRel) const override;
bool isWeak(const MCSymbol &Sym) const override; bool isWeak(const MCSymbol &Sym) const override;
void RecordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCFixup &Fixup, const MCFragment *Fragment, const MCFixup &Fixup,
MCValue Target, bool &IsPCRel, MCValue Target, bool &IsPCRel,
uint64_t &FixedValue) override; uint64_t &FixedValue) override;
void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout) override; void writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
}; };
} }
@@ -546,40 +546,40 @@ bool WinCOFFObjectWriter::IsPhysicalSection(COFFSection *S) {
void WinCOFFObjectWriter::WriteFileHeader(const COFF::header &Header) { void WinCOFFObjectWriter::WriteFileHeader(const COFF::header &Header) {
if (UseBigObj) { if (UseBigObj) {
WriteLE16(COFF::IMAGE_FILE_MACHINE_UNKNOWN); writeLE16(COFF::IMAGE_FILE_MACHINE_UNKNOWN);
WriteLE16(0xFFFF); writeLE16(0xFFFF);
WriteLE16(COFF::BigObjHeader::MinBigObjectVersion); writeLE16(COFF::BigObjHeader::MinBigObjectVersion);
WriteLE16(Header.Machine); writeLE16(Header.Machine);
WriteLE32(Header.TimeDateStamp); writeLE32(Header.TimeDateStamp);
WriteBytes(StringRef(COFF::BigObjMagic, sizeof(COFF::BigObjMagic))); writeBytes(StringRef(COFF::BigObjMagic, sizeof(COFF::BigObjMagic)));
WriteLE32(0); writeLE32(0);
WriteLE32(0); writeLE32(0);
WriteLE32(0); writeLE32(0);
WriteLE32(0); writeLE32(0);
WriteLE32(Header.NumberOfSections); writeLE32(Header.NumberOfSections);
WriteLE32(Header.PointerToSymbolTable); writeLE32(Header.PointerToSymbolTable);
WriteLE32(Header.NumberOfSymbols); writeLE32(Header.NumberOfSymbols);
} else { } else {
WriteLE16(Header.Machine); writeLE16(Header.Machine);
WriteLE16(static_cast<int16_t>(Header.NumberOfSections)); writeLE16(static_cast<int16_t>(Header.NumberOfSections));
WriteLE32(Header.TimeDateStamp); writeLE32(Header.TimeDateStamp);
WriteLE32(Header.PointerToSymbolTable); writeLE32(Header.PointerToSymbolTable);
WriteLE32(Header.NumberOfSymbols); writeLE32(Header.NumberOfSymbols);
WriteLE16(Header.SizeOfOptionalHeader); writeLE16(Header.SizeOfOptionalHeader);
WriteLE16(Header.Characteristics); writeLE16(Header.Characteristics);
} }
} }
void WinCOFFObjectWriter::WriteSymbol(const COFFSymbol &S) { void WinCOFFObjectWriter::WriteSymbol(const COFFSymbol &S) {
WriteBytes(StringRef(S.Data.Name, COFF::NameSize)); writeBytes(StringRef(S.Data.Name, COFF::NameSize));
WriteLE32(S.Data.Value); writeLE32(S.Data.Value);
if (UseBigObj) if (UseBigObj)
WriteLE32(S.Data.SectionNumber); writeLE32(S.Data.SectionNumber);
else else
WriteLE16(static_cast<int16_t>(S.Data.SectionNumber)); writeLE16(static_cast<int16_t>(S.Data.SectionNumber));
WriteLE16(S.Data.Type); writeLE16(S.Data.Type);
Write8(S.Data.StorageClass); write8(S.Data.StorageClass);
Write8(S.Data.NumberOfAuxSymbols); write8(S.Data.NumberOfAuxSymbols);
WriteAuxiliarySymbols(S.Aux); WriteAuxiliarySymbols(S.Aux);
} }
@@ -589,44 +589,44 @@ void WinCOFFObjectWriter::WriteAuxiliarySymbols(
i != e; ++i) { i != e; ++i) {
switch (i->AuxType) { switch (i->AuxType) {
case ATFunctionDefinition: case ATFunctionDefinition:
WriteLE32(i->Aux.FunctionDefinition.TagIndex); writeLE32(i->Aux.FunctionDefinition.TagIndex);
WriteLE32(i->Aux.FunctionDefinition.TotalSize); writeLE32(i->Aux.FunctionDefinition.TotalSize);
WriteLE32(i->Aux.FunctionDefinition.PointerToLinenumber); writeLE32(i->Aux.FunctionDefinition.PointerToLinenumber);
WriteLE32(i->Aux.FunctionDefinition.PointerToNextFunction); writeLE32(i->Aux.FunctionDefinition.PointerToNextFunction);
WriteZeros(sizeof(i->Aux.FunctionDefinition.unused)); WriteZeros(sizeof(i->Aux.FunctionDefinition.unused));
if (UseBigObj) if (UseBigObj)
WriteZeros(COFF::Symbol32Size - COFF::Symbol16Size); WriteZeros(COFF::Symbol32Size - COFF::Symbol16Size);
break; break;
case ATbfAndefSymbol: case ATbfAndefSymbol:
WriteZeros(sizeof(i->Aux.bfAndefSymbol.unused1)); WriteZeros(sizeof(i->Aux.bfAndefSymbol.unused1));
WriteLE16(i->Aux.bfAndefSymbol.Linenumber); writeLE16(i->Aux.bfAndefSymbol.Linenumber);
WriteZeros(sizeof(i->Aux.bfAndefSymbol.unused2)); WriteZeros(sizeof(i->Aux.bfAndefSymbol.unused2));
WriteLE32(i->Aux.bfAndefSymbol.PointerToNextFunction); writeLE32(i->Aux.bfAndefSymbol.PointerToNextFunction);
WriteZeros(sizeof(i->Aux.bfAndefSymbol.unused3)); WriteZeros(sizeof(i->Aux.bfAndefSymbol.unused3));
if (UseBigObj) if (UseBigObj)
WriteZeros(COFF::Symbol32Size - COFF::Symbol16Size); WriteZeros(COFF::Symbol32Size - COFF::Symbol16Size);
break; break;
case ATWeakExternal: case ATWeakExternal:
WriteLE32(i->Aux.WeakExternal.TagIndex); writeLE32(i->Aux.WeakExternal.TagIndex);
WriteLE32(i->Aux.WeakExternal.Characteristics); writeLE32(i->Aux.WeakExternal.Characteristics);
WriteZeros(sizeof(i->Aux.WeakExternal.unused)); WriteZeros(sizeof(i->Aux.WeakExternal.unused));
if (UseBigObj) if (UseBigObj)
WriteZeros(COFF::Symbol32Size - COFF::Symbol16Size); WriteZeros(COFF::Symbol32Size - COFF::Symbol16Size);
break; break;
case ATFile: case ATFile:
WriteBytes( writeBytes(
StringRef(reinterpret_cast<const char *>(&i->Aux), StringRef(reinterpret_cast<const char *>(&i->Aux),
UseBigObj ? COFF::Symbol32Size : COFF::Symbol16Size)); UseBigObj ? COFF::Symbol32Size : COFF::Symbol16Size));
break; break;
case ATSectionDefinition: case ATSectionDefinition:
WriteLE32(i->Aux.SectionDefinition.Length); writeLE32(i->Aux.SectionDefinition.Length);
WriteLE16(i->Aux.SectionDefinition.NumberOfRelocations); writeLE16(i->Aux.SectionDefinition.NumberOfRelocations);
WriteLE16(i->Aux.SectionDefinition.NumberOfLinenumbers); writeLE16(i->Aux.SectionDefinition.NumberOfLinenumbers);
WriteLE32(i->Aux.SectionDefinition.CheckSum); writeLE32(i->Aux.SectionDefinition.CheckSum);
WriteLE16(static_cast<int16_t>(i->Aux.SectionDefinition.Number)); writeLE16(static_cast<int16_t>(i->Aux.SectionDefinition.Number));
Write8(i->Aux.SectionDefinition.Selection); write8(i->Aux.SectionDefinition.Selection);
WriteZeros(sizeof(i->Aux.SectionDefinition.unused)); WriteZeros(sizeof(i->Aux.SectionDefinition.unused));
WriteLE16(static_cast<int16_t>(i->Aux.SectionDefinition.Number >> 16)); writeLE16(static_cast<int16_t>(i->Aux.SectionDefinition.Number >> 16));
if (UseBigObj) if (UseBigObj)
WriteZeros(COFF::Symbol32Size - COFF::Symbol16Size); WriteZeros(COFF::Symbol32Size - COFF::Symbol16Size);
break; break;
@@ -635,23 +635,23 @@ void WinCOFFObjectWriter::WriteAuxiliarySymbols(
} }
void WinCOFFObjectWriter::WriteSectionHeader(const COFF::section &S) { void WinCOFFObjectWriter::WriteSectionHeader(const COFF::section &S) {
WriteBytes(StringRef(S.Name, COFF::NameSize)); writeBytes(StringRef(S.Name, COFF::NameSize));
WriteLE32(S.VirtualSize); writeLE32(S.VirtualSize);
WriteLE32(S.VirtualAddress); writeLE32(S.VirtualAddress);
WriteLE32(S.SizeOfRawData); writeLE32(S.SizeOfRawData);
WriteLE32(S.PointerToRawData); writeLE32(S.PointerToRawData);
WriteLE32(S.PointerToRelocations); writeLE32(S.PointerToRelocations);
WriteLE32(S.PointerToLineNumbers); writeLE32(S.PointerToLineNumbers);
WriteLE16(S.NumberOfRelocations); writeLE16(S.NumberOfRelocations);
WriteLE16(S.NumberOfLineNumbers); writeLE16(S.NumberOfLineNumbers);
WriteLE32(S.Characteristics); writeLE32(S.Characteristics);
} }
void WinCOFFObjectWriter::WriteRelocation(const COFF::relocation &R) { void WinCOFFObjectWriter::WriteRelocation(const COFF::relocation &R) {
WriteLE32(R.VirtualAddress); writeLE32(R.VirtualAddress);
WriteLE32(R.SymbolTableIndex); writeLE32(R.SymbolTableIndex);
WriteLE16(R.Type); writeLE16(R.Type);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -669,7 +669,7 @@ void WinCOFFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm,
DefineSymbol(Symbol, Asm, Layout); DefineSymbol(Symbol, Asm, Layout);
} }
bool WinCOFFObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl( bool WinCOFFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB, const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB,
bool InSet, bool IsPCRel) const { bool InSet, bool IsPCRel) const {
// MS LINK expects to be able to replace all references to a function with a // MS LINK expects to be able to replace all references to a function with a
@@ -678,7 +678,7 @@ bool WinCOFFObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(
if ((((SymA.getFlags() & COFF::SF_TypeMask) >> COFF::SF_TypeShift) >> if ((((SymA.getFlags() & COFF::SF_TypeMask) >> COFF::SF_TypeShift) >>
COFF::SCT_COMPLEX_TYPE_SHIFT) == COFF::IMAGE_SYM_DTYPE_FUNCTION) COFF::SCT_COMPLEX_TYPE_SHIFT) == COFF::IMAGE_SYM_DTYPE_FUNCTION)
return false; return false;
return MCObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(Asm, SymA, FB, return MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(Asm, SymA, FB,
InSet, IsPCRel); InSet, IsPCRel);
} }
@@ -699,7 +699,7 @@ bool WinCOFFObjectWriter::isWeak(const MCSymbol &Sym) const {
return true; return true;
} }
void WinCOFFObjectWriter::RecordRelocation( void WinCOFFObjectWriter::recordRelocation(
MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment, MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment,
const MCFixup &Fixup, MCValue Target, bool &IsPCRel, uint64_t &FixedValue) { const MCFixup &Fixup, MCValue Target, bool &IsPCRel, uint64_t &FixedValue) {
assert(Target.getSymA() && "Relocation must reference a symbol!"); assert(Target.getSymA() && "Relocation must reference a symbol!");
@@ -830,7 +830,7 @@ void WinCOFFObjectWriter::RecordRelocation(
coff_section->Relocations.push_back(Reloc); coff_section->Relocations.push_back(Reloc);
} }
void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm, void WinCOFFObjectWriter::writeObject(MCAssembler &Asm,
const MCAsmLayout &Layout) { const MCAsmLayout &Layout) {
size_t SectionsSize = Sections.size(); size_t SectionsSize = Sections.size();
if (SectionsSize > static_cast<size_t>(INT32_MAX)) if (SectionsSize > static_cast<size_t>(INT32_MAX))

View File

@@ -252,7 +252,7 @@ bool AArch64AsmBackend::writeNopData(uint64_t Count, MCObjectWriter *OW) const {
// We are properly aligned, so write NOPs as requested. // We are properly aligned, so write NOPs as requested.
Count /= 4; Count /= 4;
for (uint64_t i = 0; i != Count; ++i) for (uint64_t i = 0; i != Count; ++i)
OW->Write32(0xd503201f); OW->write32(0xd503201f);
return true; return true;
} }

View File

@@ -33,7 +33,7 @@ public:
AArch64MachObjectWriter(uint32_t CPUType, uint32_t CPUSubtype) AArch64MachObjectWriter(uint32_t CPUType, uint32_t CPUSubtype)
: MCMachObjectTargetWriter(true /* is64Bit */, CPUType, CPUSubtype) {} : MCMachObjectTargetWriter(true /* is64Bit */, CPUType, CPUSubtype) {}
void RecordRelocation(MachObjectWriter *Writer, MCAssembler &Asm, void recordRelocation(MachObjectWriter *Writer, MCAssembler &Asm,
const MCAsmLayout &Layout, const MCFragment *Fragment, const MCAsmLayout &Layout, const MCFragment *Fragment,
const MCFixup &Fixup, MCValue Target, const MCFixup &Fixup, MCValue Target,
uint64_t &FixedValue) override; uint64_t &FixedValue) override;
@@ -139,7 +139,7 @@ static bool canUseLocalRelocation(const MCSectionMachO &Section,
return false; return false;
} }
void AArch64MachObjectWriter::RecordRelocation( void AArch64MachObjectWriter::recordRelocation(
MachObjectWriter *Writer, MCAssembler &Asm, const MCAsmLayout &Layout, MachObjectWriter *Writer, MCAssembler &Asm, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target,
uint64_t &FixedValue) { uint64_t &FixedValue) {
@@ -313,7 +313,7 @@ void AArch64MachObjectWriter::RecordRelocation(
Asm.getContext().reportFatalError(Fixup.getLoc(), Asm.getContext().reportFatalError(Fixup.getLoc(),
"unable to resolve variable '" + "unable to resolve variable '" +
Symbol->getName() + "'"); Symbol->getName() + "'");
return RecordRelocation(Writer, Asm, Layout, Fragment, Fixup, Target, return recordRelocation(Writer, Asm, Layout, Fragment, Fixup, Target,
FixedValue); FixedValue);
} }

View File

@@ -260,9 +260,9 @@ bool ARMAsmBackend::writeNopData(uint64_t Count, MCObjectWriter *OW) const {
hasNOP() ? Thumb2_16bitNopEncoding : Thumb1_16bitNopEncoding; hasNOP() ? Thumb2_16bitNopEncoding : Thumb1_16bitNopEncoding;
uint64_t NumNops = Count / 2; uint64_t NumNops = Count / 2;
for (uint64_t i = 0; i != NumNops; ++i) for (uint64_t i = 0; i != NumNops; ++i)
OW->Write16(nopEncoding); OW->write16(nopEncoding);
if (Count & 1) if (Count & 1)
OW->Write8(0); OW->write8(0);
return true; return true;
} }
// ARM mode // ARM mode
@@ -270,21 +270,21 @@ bool ARMAsmBackend::writeNopData(uint64_t Count, MCObjectWriter *OW) const {
hasNOP() ? ARMv6T2_NopEncoding : ARMv4_NopEncoding; hasNOP() ? ARMv6T2_NopEncoding : ARMv4_NopEncoding;
uint64_t NumNops = Count / 4; uint64_t NumNops = Count / 4;
for (uint64_t i = 0; i != NumNops; ++i) for (uint64_t i = 0; i != NumNops; ++i)
OW->Write32(nopEncoding); OW->write32(nopEncoding);
// FIXME: should this function return false when unable to write exactly // FIXME: should this function return false when unable to write exactly
// 'Count' bytes with NOP encodings? // 'Count' bytes with NOP encodings?
switch (Count % 4) { switch (Count % 4) {
default: default:
break; // No leftover bytes to write break; // No leftover bytes to write
case 1: case 1:
OW->Write8(0); OW->write8(0);
break; break;
case 2: case 2:
OW->Write16(0); OW->write16(0);
break; break;
case 3: case 3:
OW->Write16(0); OW->write16(0);
OW->Write8(0xa0); OW->write8(0xa0);
break; break;
} }

View File

@@ -52,7 +52,7 @@ public:
ARMMachObjectWriter(bool Is64Bit, uint32_t CPUType, uint32_t CPUSubtype) ARMMachObjectWriter(bool Is64Bit, uint32_t CPUType, uint32_t CPUSubtype)
: MCMachObjectTargetWriter(Is64Bit, CPUType, CPUSubtype) {} : MCMachObjectTargetWriter(Is64Bit, CPUType, CPUSubtype) {}
void RecordRelocation(MachObjectWriter *Writer, MCAssembler &Asm, void recordRelocation(MachObjectWriter *Writer, MCAssembler &Asm,
const MCAsmLayout &Layout, const MCFragment *Fragment, const MCAsmLayout &Layout, const MCFragment *Fragment,
const MCFixup &Fixup, MCValue Target, const MCFixup &Fixup, MCValue Target,
uint64_t &FixedValue) override; uint64_t &FixedValue) override;
@@ -338,7 +338,7 @@ bool ARMMachObjectWriter::requiresExternRelocation(MachObjectWriter *Writer,
return false; return false;
} }
void ARMMachObjectWriter::RecordRelocation(MachObjectWriter *Writer, void ARMMachObjectWriter::recordRelocation(MachObjectWriter *Writer,
MCAssembler &Asm, MCAssembler &Asm,
const MCAsmLayout &Layout, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCFragment *Fragment,

View File

@@ -57,7 +57,7 @@ bool BPFAsmBackend::writeNopData(uint64_t Count, MCObjectWriter *OW) const {
return false; return false;
for (uint64_t i = 0; i < Count; i += 8) for (uint64_t i = 0; i < Count; i += 8)
OW->Write64(0x15000000); OW->write64(0x15000000);
return true; return true;
} }

View File

@@ -177,7 +177,7 @@ public:
bool writeNopData(uint64_t Count, MCObjectWriter *OW) const override { bool writeNopData(uint64_t Count, MCObjectWriter *OW) const override {
uint64_t NumNops = Count / 4; uint64_t NumNops = Count / 4;
for (uint64_t i = 0; i != NumNops; ++i) for (uint64_t i = 0; i != NumNops; ++i)
OW->Write32(0x60000000); OW->write32(0x60000000);
OW->WriteZeros(Count % 4); OW->WriteZeros(Count % 4);

View File

@@ -40,7 +40,7 @@ public:
PPCMachObjectWriter(bool Is64Bit, uint32_t CPUType, uint32_t CPUSubtype) PPCMachObjectWriter(bool Is64Bit, uint32_t CPUType, uint32_t CPUSubtype)
: MCMachObjectTargetWriter(Is64Bit, CPUType, CPUSubtype) {} : MCMachObjectTargetWriter(Is64Bit, CPUType, CPUSubtype) {}
void RecordRelocation(MachObjectWriter *Writer, MCAssembler &Asm, void recordRelocation(MachObjectWriter *Writer, MCAssembler &Asm,
const MCAsmLayout &Layout, const MCFragment *Fragment, const MCAsmLayout &Layout, const MCFragment *Fragment,
const MCFixup &Fixup, MCValue Target, const MCFixup &Fixup, MCValue Target,
uint64_t &FixedValue) override { uint64_t &FixedValue) override {

View File

@@ -29,14 +29,14 @@ public:
const MCAsmLayout &Layout) override { const MCAsmLayout &Layout) override {
//XXX: Implement if necessary. //XXX: Implement if necessary.
} }
void RecordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
const MCFragment *Fragment, const MCFixup &Fixup, const MCFragment *Fragment, const MCFixup &Fixup,
MCValue Target, bool &IsPCRel, MCValue Target, bool &IsPCRel,
uint64_t &FixedValue) override { uint64_t &FixedValue) override {
assert(!"Not implemented"); assert(!"Not implemented");
} }
void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout) override; void writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
}; };
@@ -64,7 +64,7 @@ public:
} //End anonymous namespace } //End anonymous namespace
void AMDGPUMCObjectWriter::WriteObject(MCAssembler &Asm, void AMDGPUMCObjectWriter::writeObject(MCAssembler &Asm,
const MCAsmLayout &Layout) { const MCAsmLayout &Layout) {
for (MCAssembler::iterator I = Asm.begin(), E = Asm.end(); I != E; ++I) { for (MCAssembler::iterator I = Asm.begin(), E = Asm.end(); I != E; ++I) {
Asm.writeSectionData(&*I, Layout); Asm.writeSectionData(&*I, Layout);

View File

@@ -260,7 +260,7 @@ namespace {
uint64_t NumNops = Count / 4; uint64_t NumNops = Count / 4;
for (uint64_t i = 0; i != NumNops; ++i) for (uint64_t i = 0; i != NumNops; ++i)
OW->Write32(0x01000000); OW->write32(0x01000000);
return true; return true;
} }

View File

@@ -105,7 +105,7 @@ void SystemZMCAsmBackend::applyFixup(const MCFixup &Fixup, char *Data,
bool SystemZMCAsmBackend::writeNopData(uint64_t Count, bool SystemZMCAsmBackend::writeNopData(uint64_t Count,
MCObjectWriter *OW) const { MCObjectWriter *OW) const {
for (uint64_t I = 0; I != Count; ++I) for (uint64_t I = 0; I != Count; ++I)
OW->Write8(7); OW->write8(7);
return true; return true;
} }

View File

@@ -326,7 +326,7 @@ bool X86AsmBackend::writeNopData(uint64_t Count, MCObjectWriter *OW) const {
// FIXME: We could generated something better than plain 0x90. // FIXME: We could generated something better than plain 0x90.
if (!HasNopl) { if (!HasNopl) {
for (uint64_t i = 0; i < Count; ++i) for (uint64_t i = 0; i < Count; ++i)
OW->Write8(0x90); OW->write8(0x90);
return true; return true;
} }
@@ -336,10 +336,10 @@ bool X86AsmBackend::writeNopData(uint64_t Count, MCObjectWriter *OW) const {
const uint8_t ThisNopLength = (uint8_t) std::min(Count, MaxNopLength); const uint8_t ThisNopLength = (uint8_t) std::min(Count, MaxNopLength);
const uint8_t Prefixes = ThisNopLength <= 10 ? 0 : ThisNopLength - 10; const uint8_t Prefixes = ThisNopLength <= 10 ? 0 : ThisNopLength - 10;
for (uint8_t i = 0; i < Prefixes; i++) for (uint8_t i = 0; i < Prefixes; i++)
OW->Write8(0x66); OW->write8(0x66);
const uint8_t Rest = ThisNopLength - Prefixes; const uint8_t Rest = ThisNopLength - Prefixes;
for (uint8_t i = 0; i < Rest; i++) for (uint8_t i = 0; i < Rest; i++)
OW->Write8(Nops[Rest - 1][i]); OW->write8(Nops[Rest - 1][i]);
Count -= ThisNopLength; Count -= ThisNopLength;
} while (Count != 0); } while (Count != 0);

View File

@@ -57,7 +57,7 @@ public:
X86MachObjectWriter(bool Is64Bit, uint32_t CPUType, uint32_t CPUSubtype) X86MachObjectWriter(bool Is64Bit, uint32_t CPUType, uint32_t CPUSubtype)
: MCMachObjectTargetWriter(Is64Bit, CPUType, CPUSubtype) {} : MCMachObjectTargetWriter(Is64Bit, CPUType, CPUSubtype) {}
void RecordRelocation(MachObjectWriter *Writer, MCAssembler &Asm, void recordRelocation(MachObjectWriter *Writer, MCAssembler &Asm,
const MCAsmLayout &Layout, const MCFragment *Fragment, const MCAsmLayout &Layout, const MCFragment *Fragment,
const MCFixup &Fixup, MCValue Target, const MCFixup &Fixup, MCValue Target,
uint64_t &FixedValue) override { uint64_t &FixedValue) override {