Rename variables to match the LLVM style.

llvm-svn: 295265
This commit is contained in:
Rui Ueyama 2017-02-16 01:06:45 +00:00
parent 4e05eaa9e8
commit 6237678b14
1 changed files with 96 additions and 93 deletions

View File

@ -637,13 +637,13 @@ void WinCOFFObjectWriter::recordRelocation(
return; return;
} }
MCSection *Section = Fragment->getParent(); MCSection *MCSec = Fragment->getParent();
// Mark this symbol as requiring an entry in the symbol table. // Mark this symbol as requiring an entry in the symbol table.
assert(SectionMap.find(Section) != SectionMap.end() && assert(SectionMap.find(MCSec) != SectionMap.end() &&
"Section must already have been defined in executePostLayoutBinding!"); "Section must already have been defined in executePostLayoutBinding!");
COFFSection *coff_section = SectionMap[Section]; COFFSection *Sec = SectionMap[MCSec];
const MCSymbolRefExpr *SymB = Target.getSymB(); const MCSymbolRefExpr *SymB = Target.getSymB();
bool CrossSection = false; bool CrossSection = false;
@ -765,7 +765,14 @@ void WinCOFFObjectWriter::recordRelocation(
FixedValue = 0; FixedValue = 0;
if (TargetObjectWriter->recordRelocation(Fixup)) if (TargetObjectWriter->recordRelocation(Fixup))
coff_section->Relocations.push_back(Reloc); Sec->Relocations.push_back(Reloc);
}
static std::time_t getTime() {
std::time_t Now = time(nullptr);
if (Now < 0 || !isUInt<32>(Now))
return UINT32_MAX;
return Now;
} }
void WinCOFFObjectWriter::writeObject(MCAssembler &Asm, void WinCOFFObjectWriter::writeObject(MCAssembler &Asm,
@ -883,13 +890,13 @@ void WinCOFFObjectWriter::writeObject(MCAssembler &Asm,
// Assign file offsets to COFF object file structures. // Assign file offsets to COFF object file structures.
unsigned offset = getInitialOffset(); unsigned Offset = getInitialOffset();
if (UseBigObj) if (UseBigObj)
offset += COFF::Header32Size; Offset += COFF::Header32Size;
else else
offset += COFF::Header16Size; Offset += COFF::Header16Size;
offset += COFF::SectionSize * Header.NumberOfSections; Offset += COFF::SectionSize * Header.NumberOfSections;
for (const auto &Section : Asm) { for (const auto &Section : Asm) {
COFFSection *Sec = SectionMap[&Section]; COFFSection *Sec = SectionMap[&Section];
@ -901,10 +908,10 @@ void WinCOFFObjectWriter::writeObject(MCAssembler &Asm,
if (IsPhysicalSection(Sec)) { if (IsPhysicalSection(Sec)) {
// Align the section data to a four byte boundary. // Align the section data to a four byte boundary.
offset = alignTo(offset, 4); Offset = alignTo(Offset, 4);
Sec->Header.PointerToRawData = offset; Sec->Header.PointerToRawData = Offset;
offset += Sec->Header.SizeOfRawData; Offset += Sec->Header.SizeOfRawData;
} }
if (!Sec->Relocations.empty()) { if (!Sec->Relocations.empty()) {
@ -917,14 +924,14 @@ void WinCOFFObjectWriter::writeObject(MCAssembler &Asm,
} else { } else {
Sec->Header.NumberOfRelocations = Sec->Relocations.size(); Sec->Header.NumberOfRelocations = Sec->Relocations.size();
} }
Sec->Header.PointerToRelocations = offset; Sec->Header.PointerToRelocations = Offset;
if (RelocationsOverflow) { if (RelocationsOverflow) {
// Reloc #0 will contain actual count, so make room for it. // Reloc #0 will contain actual count, so make room for it.
offset += COFF::RelocationSize; Offset += COFF::RelocationSize;
} }
offset += COFF::RelocationSize * Sec->Relocations.size(); Offset += COFF::RelocationSize * Sec->Relocations.size();
for (auto &Relocation : Sec->Relocations) { for (auto &Relocation : Sec->Relocations) {
assert(Relocation.Symb->getIndex() != -1); assert(Relocation.Symb->getIndex() != -1);
@ -944,15 +951,12 @@ void WinCOFFObjectWriter::writeObject(MCAssembler &Asm,
Sec->Header.NumberOfLineNumbers; Sec->Header.NumberOfLineNumbers;
} }
Header.PointerToSymbolTable = offset; Header.PointerToSymbolTable = Offset;
// MS LINK expects to be able to use this timestamp to implement their // MS LINK expects to be able to use this timestamp to implement their
// /INCREMENTAL feature. // /INCREMENTAL feature.
if (Asm.isIncrementalLinkerCompatible()) { if (Asm.isIncrementalLinkerCompatible()) {
std::time_t Now = time(nullptr); Header.TimeDateStamp = getTime();
if (Now < 0 || !isUInt<32>(Now))
Now = UINT32_MAX;
Header.TimeDateStamp = Now;
} else { } else {
// Have deterministic output if /INCREMENTAL isn't needed. Also matches GNU. // Have deterministic output if /INCREMENTAL isn't needed. Also matches GNU.
Header.TimeDateStamp = 0; Header.TimeDateStamp = 0;
@ -961,86 +965,85 @@ void WinCOFFObjectWriter::writeObject(MCAssembler &Asm,
// Write it all to disk... // Write it all to disk...
WriteFileHeader(Header); WriteFileHeader(Header);
{ for (auto &Section : Sections) {
sections::iterator i, ie; if (Section->Number != -1) {
MCAssembler::iterator j, je; if (Section->Relocations.size() >= 0xffff)
Section->Header.Characteristics |= COFF::IMAGE_SCN_LNK_NRELOC_OVFL;
writeSectionHeader(Section->Header);
}
}
for (auto &Section : Sections) { SmallVector<char, 128> Buf;
if (Section->Number != -1) {
if (Section->Relocations.size() >= 0xffff) sections::iterator I, IE;
Section->Header.Characteristics |= COFF::IMAGE_SCN_LNK_NRELOC_OVFL; MCAssembler::iterator J, JE;
writeSectionHeader(Section->Header); for (I = Sections.begin(), IE = Sections.end(), J = Asm.begin(),
} JE = Asm.end();
I != IE && J != JE; ++I, ++J) {
COFFSection &Sec = *I->get();
MCSection &MCSec = *J;
if (Sec.Number == -1)
continue;
if (Sec.Header.PointerToRawData != 0) {
assert(getStream().tell() <= Sec.Header.PointerToRawData &&
"Section::PointerToRawData is insane!");
unsigned SectionDataPadding =
Sec.Header.PointerToRawData - getStream().tell();
assert(SectionDataPadding < 4 &&
"Should only need at most three bytes of padding!");
WriteZeros(SectionDataPadding);
// Save the contents of the section to a temporary buffer, we need this
// to CRC the data before we dump it into the object file.
Buf.clear();
raw_svector_ostream VecOS(Buf);
raw_pwrite_stream &OldStream = getStream();
// Redirect the output stream to our buffer.
setStream(VecOS);
// Fill our buffer with the section data.
Asm.writeSectionData(&MCSec, Layout);
// Reset the stream back to what it was before.
setStream(OldStream);
// Calculate our CRC with an initial value of '0', this is not how
// JamCRC is specified but it aligns with the expected output.
JamCRC JC(/*Init=*/0x00000000U);
JC.update(Buf);
// Write the section contents to the object file.
getStream() << Buf;
// Update the section definition auxiliary symbol to record the CRC.
COFFSection *Sec = SectionMap[&MCSec];
COFFSymbol::AuxiliarySymbols &AuxSyms = Sec->Symbol->Aux;
assert(AuxSyms.size() == 1 && AuxSyms[0].AuxType == ATSectionDefinition);
AuxSymbol &SecDef = AuxSyms[0];
SecDef.Aux.SectionDefinition.CheckSum = JC.getCRC();
} }
SmallVector<char, 128> SectionContents; if (!Sec.Relocations.empty()) {
for (i = Sections.begin(), ie = Sections.end(), j = Asm.begin(), assert(getStream().tell() == Sec.Header.PointerToRelocations &&
je = Asm.end(); "Section::PointerToRelocations is insane!");
(i != ie) && (j != je); ++i, ++j) {
if ((*i)->Number == -1) if (Sec.Relocations.size() >= 0xffff) {
continue; // In case of overflow, write actual relocation count as first
// relocation. Including the synthetic reloc itself (+ 1).
if ((*i)->Header.PointerToRawData != 0) { COFF::relocation R;
assert(getStream().tell() <= (*i)->Header.PointerToRawData && R.VirtualAddress = Sec.Relocations.size() + 1;
"Section::PointerToRawData is insane!"); R.SymbolTableIndex = 0;
R.Type = 0;
unsigned SectionDataPadding = WriteRelocation(R);
(*i)->Header.PointerToRawData - getStream().tell();
assert(SectionDataPadding < 4 &&
"Should only need at most three bytes of padding!");
WriteZeros(SectionDataPadding);
// Save the contents of the section to a temporary buffer, we need this
// to CRC the data before we dump it into the object file.
SectionContents.clear();
raw_svector_ostream VecOS(SectionContents);
raw_pwrite_stream &OldStream = getStream();
// Redirect the output stream to our buffer.
setStream(VecOS);
// Fill our buffer with the section data.
Asm.writeSectionData(&*j, Layout);
// Reset the stream back to what it was before.
setStream(OldStream);
// Calculate our CRC with an initial value of '0', this is not how
// JamCRC is specified but it aligns with the expected output.
JamCRC JC(/*Init=*/0x00000000U);
JC.update(SectionContents);
// Write the section contents to the object file.
getStream() << SectionContents;
// Update the section definition auxiliary symbol to record the CRC.
COFFSection *Sec = SectionMap[&*j];
COFFSymbol::AuxiliarySymbols &AuxSyms = Sec->Symbol->Aux;
assert(AuxSyms.size() == 1 &&
AuxSyms[0].AuxType == ATSectionDefinition);
AuxSymbol &SecDef = AuxSyms[0];
SecDef.Aux.SectionDefinition.CheckSum = JC.getCRC();
} }
if (!(*i)->Relocations.empty()) { for (const auto &Relocation : Sec.Relocations)
assert(getStream().tell() == (*i)->Header.PointerToRelocations && WriteRelocation(Relocation.Data);
"Section::PointerToRelocations is insane!"); } else
assert(Sec.Header.PointerToRelocations == 0 &&
if ((*i)->Relocations.size() >= 0xffff) { "Section::PointerToRelocations is insane!");
// In case of overflow, write actual relocation count as first
// relocation. Including the synthetic reloc itself (+ 1).
COFF::relocation r;
r.VirtualAddress = (*i)->Relocations.size() + 1;
r.SymbolTableIndex = 0;
r.Type = 0;
WriteRelocation(r);
}
for (const auto &Relocation : (*i)->Relocations)
WriteRelocation(Relocation.Data);
} else
assert((*i)->Header.PointerToRelocations == 0 &&
"Section::PointerToRelocations is insane!");
}
} }
assert(getStream().tell() == Header.PointerToSymbolTable && assert(getStream().tell() == Header.PointerToSymbolTable &&