};
struct AuxSymbol {
- AuxiliaryType AuxType;
+ AuxiliaryType AuxType;
COFF::Auxiliary Aux;
};
typedef SmallVector<AuxSymbol, 1> AuxiliarySymbols;
- name Name;
- int Index;
+ name Name;
+ int Index;
AuxiliarySymbols Aux;
- COFFSymbol *Other;
- COFFSection *Section;
- int Relocations;
+ COFFSymbol *Other;
+ COFFSection *Section;
+ int Relocations;
const MCSymbol *MC;
// This class contains staging data for a COFF relocation entry.
struct COFFRelocation {
COFF::relocation Data;
- COFFSymbol *Symb;
+ COFFSymbol *Symb;
COFFRelocation() : Symb(nullptr) {}
static size_t size() { return COFF::RelocationSize; }
public:
COFF::section Header;
- std::string Name;
- int Number;
+ std::string Name;
+ int Number;
MCSectionData const *MCData;
- COFFSymbol *Symbol;
- relocations Relocations;
+ COFFSymbol *Symbol;
+ relocations Relocations;
COFFSection(StringRef name);
static size_t size();
class WinCOFFObjectWriter : public MCObjectWriter {
public:
-
- typedef std::vector<std::unique_ptr<COFFSymbol>> symbols;
+ typedef std::vector<std::unique_ptr<COFFSymbol>> symbols;
typedef std::vector<std::unique_ptr<COFFSection>> sections;
- typedef DenseMap<MCSymbol const *, COFFSymbol *> symbol_map;
+ typedef DenseMap<MCSymbol const *, COFFSymbol *> symbol_map;
typedef DenseMap<MCSection const *, COFFSection *> section_map;
std::unique_ptr<MCWinCOFFObjectTargetWriter> TargetObjectWriter;
// Root level file contents.
COFF::header Header;
- sections Sections;
- symbols Symbols;
+ sections Sections;
+ symbols Symbols;
StringTableBuilder Strings;
// Maps used during object file creation.
section_map SectionMap;
- symbol_map SymbolMap;
+ symbol_map SymbolMap;
bool UseBigObj;
}
COFFSymbol *createSymbol(StringRef Name);
- COFFSymbol *GetOrCreateCOFFSymbol(const MCSymbol * Symbol);
+ COFFSymbol *GetOrCreateCOFFSymbol(const MCSymbol *Symbol);
COFFSection *createSection(StringRef Name);
template <typename object_t, typename list_t>
return true;
// if it has relocations pointing at it, keep it
- if (Relocations > 0) {
+ if (Relocations > 0) {
assert(Section->Number != -1 && "Sections with relocations must be real!");
return true;
}
// if the section its in is being droped, drop it
if (Section->Number == -1)
- return false;
+ return false;
// if it is the section symbol, keep it
if (Section->Symbol == this)
// Section class implementation
COFFSection::COFFSection(StringRef name)
- : Name(name)
- , MCData(nullptr)
- , Symbol(nullptr) {
+ : Name(name), MCData(nullptr), Symbol(nullptr) {
memset(&Header, 0, sizeof(Header));
}
-size_t COFFSection::size() {
- return COFF::SectionSize;
-}
+size_t COFFSection::size() { return COFF::SectionSize; }
//------------------------------------------------------------------------------
// WinCOFFObjectWriter class implementation
/// A template used to lookup or create a symbol/section, and initialize it if
/// needed.
template <typename object_t, typename list_t>
-object_t *WinCOFFObjectWriter::createCOFFEntity(StringRef Name,
- list_t &List) {
+object_t *WinCOFFObjectWriter::createCOFFEntity(StringRef Name, list_t &List) {
List.push_back(make_unique<object_t>(Name));
return List.back().get();
/// This function takes a section data object from the assembler
/// and creates the associated COFF section staging object.
void WinCOFFObjectWriter::DefineSection(MCSectionData const &SectionData) {
- assert(SectionData.getSection().getVariant() == MCSection::SV_COFF
- && "Got non-COFF section in the COFF backend!");
+ assert(SectionData.getSection().getVariant() == MCSection::SV_COFF &&
+ "Got non-COFF section in the COFF backend!");
// FIXME: Not sure how to verify this (at least in a debug build).
MCSectionCOFF const &Sec =
- static_cast<MCSectionCOFF const &>(SectionData.getSection());
+ static_cast<MCSectionCOFF const &>(SectionData.getSection());
COFFSection *coff_section = createSection(Sec.getSectionName());
- COFFSymbol *coff_symbol = createSymbol(Sec.getSectionName());
+ COFFSymbol *coff_symbol = createSymbol(Sec.getSectionName());
if (Sec.getSelection() != COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE) {
if (const MCSymbol *S = Sec.getCOMDATSymbol()) {
COFFSymbol *COMDATSymbol = GetOrCreateCOFFSymbol(S);
uint32_t &Characteristics = coff_section->Header.Characteristics;
switch (Sec.getAlignment()) {
- case 1: Characteristics |= COFF::IMAGE_SCN_ALIGN_1BYTES; break;
- case 2: Characteristics |= COFF::IMAGE_SCN_ALIGN_2BYTES; break;
- case 4: Characteristics |= COFF::IMAGE_SCN_ALIGN_4BYTES; break;
- case 8: Characteristics |= COFF::IMAGE_SCN_ALIGN_8BYTES; break;
- case 16: Characteristics |= COFF::IMAGE_SCN_ALIGN_16BYTES; break;
- case 32: Characteristics |= COFF::IMAGE_SCN_ALIGN_32BYTES; break;
- case 64: Characteristics |= COFF::IMAGE_SCN_ALIGN_64BYTES; break;
- case 128: Characteristics |= COFF::IMAGE_SCN_ALIGN_128BYTES; break;
- case 256: Characteristics |= COFF::IMAGE_SCN_ALIGN_256BYTES; break;
- case 512: Characteristics |= COFF::IMAGE_SCN_ALIGN_512BYTES; break;
- case 1024: Characteristics |= COFF::IMAGE_SCN_ALIGN_1024BYTES; break;
- case 2048: Characteristics |= COFF::IMAGE_SCN_ALIGN_2048BYTES; break;
- case 4096: Characteristics |= COFF::IMAGE_SCN_ALIGN_4096BYTES; break;
- case 8192: Characteristics |= COFF::IMAGE_SCN_ALIGN_8192BYTES; break;
+ case 1:
+ Characteristics |= COFF::IMAGE_SCN_ALIGN_1BYTES;
+ break;
+ case 2:
+ Characteristics |= COFF::IMAGE_SCN_ALIGN_2BYTES;
+ break;
+ case 4:
+ Characteristics |= COFF::IMAGE_SCN_ALIGN_4BYTES;
+ break;
+ case 8:
+ Characteristics |= COFF::IMAGE_SCN_ALIGN_8BYTES;
+ break;
+ case 16:
+ Characteristics |= COFF::IMAGE_SCN_ALIGN_16BYTES;
+ break;
+ case 32:
+ Characteristics |= COFF::IMAGE_SCN_ALIGN_32BYTES;
+ break;
+ case 64:
+ Characteristics |= COFF::IMAGE_SCN_ALIGN_64BYTES;
+ break;
+ case 128:
+ Characteristics |= COFF::IMAGE_SCN_ALIGN_128BYTES;
+ break;
+ case 256:
+ Characteristics |= COFF::IMAGE_SCN_ALIGN_256BYTES;
+ break;
+ case 512:
+ Characteristics |= COFF::IMAGE_SCN_ALIGN_512BYTES;
+ break;
+ case 1024:
+ Characteristics |= COFF::IMAGE_SCN_ALIGN_1024BYTES;
+ break;
+ case 2048:
+ Characteristics |= COFF::IMAGE_SCN_ALIGN_2048BYTES;
+ break;
+ case 4096:
+ Characteristics |= COFF::IMAGE_SCN_ALIGN_4096BYTES;
+ break;
+ case 8192:
+ Characteristics |= COFF::IMAGE_SCN_ALIGN_8192BYTES;
+ break;
default:
llvm_unreachable("unsupported section alignment");
}
if (Symbol.isVariable()) {
const MCSymbolRefExpr *SymRef =
- dyn_cast<MCSymbolRefExpr>(Symbol.getVariableValue());
+ dyn_cast<MCSymbolRefExpr>(Symbol.getVariableValue());
if (!SymRef)
report_fatal_error("Weak externals may only alias symbols");
std::string WeakName = (".weak." + Symbol.getName() + ".default").str();
COFFSymbol *WeakDefault = createSymbol(WeakName);
WeakDefault->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE;
- WeakDefault->Data.StorageClass = COFF::IMAGE_SYM_CLASS_EXTERNAL;
- WeakDefault->Data.Type = 0;
- WeakDefault->Data.Value = 0;
+ WeakDefault->Data.StorageClass = COFF::IMAGE_SYM_CLASS_EXTERNAL;
+ WeakDefault->Data.Type = 0;
+ WeakDefault->Data.Value = 0;
coff_symbol->Other = WeakDefault;
}
coff_symbol->Aux[0].AuxType = ATWeakExternal;
coff_symbol->Aux[0].Aux.WeakExternal.TagIndex = 0;
coff_symbol->Aux[0].Aux.WeakExternal.Characteristics =
- COFF::IMAGE_WEAK_EXTERN_SEARCH_LIBRARY;
+ COFF::IMAGE_WEAK_EXTERN_SEARCH_LIBRARY;
coff_symbol->MC = &Symbol;
} else {
const MCSymbol *Base = Layout.getBaseSymbol(Symbol);
coff_symbol->Data.Value = getSymbolValue(Symbol, Layout);
- coff_symbol->Data.Type = (ResSymData.getFlags() & 0x0000FFFF) >> 0;
+ coff_symbol->Data.Type = (ResSymData.getFlags() & 0x0000FFFF) >> 0;
coff_symbol->Data.StorageClass = (ResSymData.getFlags() & 0x00FF0000) >> 16;
// If no storage class was specified in the streamer, define it here.
// Encode a string table entry offset in base 64, padded to 6 chars, and
// prefixed with a double slash: '//AAAAAA', '//AAAAAB', ...
// Buffer must be at least 8 bytes large. No terminating null appended.
-static void encodeBase64StringEntry(char* Buffer, uint64_t Value) {
+static void encodeBase64StringEntry(char *Buffer, uint64_t Value) {
assert(Value > Max7DecimalOffset && Value <= MaxBase64Offset &&
"Illegal section name encoding for value");
Buffer[0] = '/';
Buffer[1] = '/';
- char* Ptr = Buffer + 7;
+ char *Ptr = Buffer + 7;
for (unsigned i = 0; i < 6; ++i) {
unsigned Rem = Value % 64;
Value /= 64;
} else if (StringTableEntry <= Max7DecimalOffset) {
// With seven digits, we have to skip the terminating null. Because
// sprintf always appends it, we use a larger temporary buffer.
- char buffer[9] = { };
+ char buffer[9] = {};
std::sprintf(buffer, "/%d", unsigned(StringTableEntry));
std::memcpy(S.Header.Name, buffer, 8);
} else if (StringTableEntry <= MaxBase64Offset) {
}
bool WinCOFFObjectWriter::IsPhysicalSection(COFFSection *S) {
- return (S->Header.Characteristics
- & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA) == 0;
+ return (S->Header.Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA) ==
+ 0;
}
//------------------------------------------------------------------------------
}
void WinCOFFObjectWriter::WriteAuxiliarySymbols(
- const COFFSymbol::AuxiliarySymbols &S) {
- for(COFFSymbol::AuxiliarySymbols::const_iterator i = S.begin(), e = S.end();
- i != e; ++i) {
- switch(i->AuxType) {
+ const COFFSymbol::AuxiliarySymbols &S) {
+ for (COFFSymbol::AuxiliarySymbols::const_iterator i = S.begin(), e = S.end();
+ i != e; ++i) {
+ switch (i->AuxType) {
case ATFunctionDefinition:
WriteLE32(i->Aux.FunctionDefinition.TagIndex);
WriteLE32(i->Aux.FunctionDefinition.TotalSize);
const MCSymbol &Symbol = Target.getSymA()->getSymbol();
const MCSymbol &A = Symbol;
if (!Asm.hasSymbolData(A))
- Asm.getContext().reportFatalError(
- Fixup.getLoc(),
- Twine("symbol '") + A.getName() + "' can not be undefined");
+ Asm.getContext().reportFatalError(Fixup.getLoc(),
+ Twine("symbol '") + A.getName() +
+ "' can not be undefined");
const MCSymbolData &A_SD = Asm.getSymbolData(A);
++Reloc.Symb->Relocations;
Reloc.Data.VirtualAddress += Fixup.getOffset();
- Reloc.Data.Type =
- TargetObjectWriter->getRelocType(Target, Fixup, CrossSection,
- Asm.getBackend());
+ Reloc.Data.Type = TargetObjectWriter->getRelocType(
+ Target, Fixup, CrossSection, Asm.getBackend());
// FIXME: Can anyone explain what this does other than adjust for the size
// of the offset?
break;
case COFF::IMAGE_REL_ARM_BRANCH11:
case COFF::IMAGE_REL_ARM_BLX11:
- // IMAGE_REL_ARM_BRANCH11 and IMAGE_REL_ARM_BLX11 are only used for
- // pre-ARMv7, which implicitly rules it out of ARMNT (it would be valid
- // for Windows CE).
+ // IMAGE_REL_ARM_BRANCH11 and IMAGE_REL_ARM_BLX11 are only used for
+ // pre-ARMv7, which implicitly rules it out of ARMNT (it would be valid
+ // for Windows CE).
case COFF::IMAGE_REL_ARM_BRANCH24:
case COFF::IMAGE_REL_ARM_BLX24:
case COFF::IMAGE_REL_ARM_MOV32A:
Header.NumberOfSections = NumberOfSections;
Header.NumberOfSymbols = 0;
- for (auto FI = Asm.file_names_begin(), FE = Asm.file_names_end();
- FI != FE; ++FI) {
+ for (auto FI = Asm.file_names_begin(), FE = Asm.file_names_end(); FI != FE;
+ ++FI) {
// round up to calculate the number of auxiliary symbols required
unsigned SymbolSize = UseBigObj ? COFF::Symbol32Size : COFF::Symbol16Size;
unsigned Count = (FI->size() + SymbolSize - 1) / SymbolSize;
continue;
const MCSectionCOFF &MCSec =
- static_cast<const MCSectionCOFF &>(Section->MCData->getSection());
+ static_cast<const MCSectionCOFF &>(Section->MCData->getSection());
const MCSymbol *COMDAT = MCSec.getCOMDATSymbol();
assert(COMDAT);
if (Assoc->Number == -1)
continue;
- Section->Symbol->Aux[0].Aux.SectionDefinition.Number = SectionIndices[Assoc];
+ Section->Symbol->Aux[0].Aux.SectionDefinition.Number =
+ SectionIndices[Assoc];
}
-
// Assign file offsets to COFF object file structures.
unsigned offset = 0;
"Section's symbol's aux symbol must be a Section Definition!");
Aux.Aux.SectionDefinition.Length = Sec->Header.SizeOfRawData;
Aux.Aux.SectionDefinition.NumberOfRelocations =
- Sec->Header.NumberOfRelocations;
+ Sec->Header.NumberOfRelocations;
Aux.Aux.SectionDefinition.NumberOfLinenumbers =
- Sec->Header.NumberOfLineNumbers;
+ Sec->Header.NumberOfLineNumbers;
}
Header.PointerToSymbolTable = offset;
}
}
- for (i = Sections.begin(), ie = Sections.end(),
- j = Asm.begin(), je = Asm.end();
+ for (i = Sections.begin(), ie = Sections.end(), j = Asm.begin(),
+ je = Asm.end();
(i != ie) && (j != je); ++i, ++j) {
if ((*i)->Number == -1)
OS.write(Strings.data().data(), Strings.data().size());
}
-MCWinCOFFObjectTargetWriter::MCWinCOFFObjectTargetWriter(unsigned Machine_) :
- Machine(Machine_) {
-}
+MCWinCOFFObjectTargetWriter::MCWinCOFFObjectTargetWriter(unsigned Machine_)
+ : Machine(Machine_) {}
// Pin the vtable to this file.
void MCWinCOFFObjectTargetWriter::anchor() {}