[NFC][XCOFF] format `XCOFFObjectWriter.cpp`

This commit is contained in:
esmeyi 2022-12-04 23:57:33 -05:00
parent a73db7f1ad
commit 664cbfaf07
1 changed files with 22 additions and 27 deletions

View File

@ -206,8 +206,8 @@ struct ExceptionTableEntry {
unsigned Lang;
unsigned Reason;
ExceptionTableEntry(const MCSymbol *Trap, unsigned Lang, unsigned Reason) :
Trap(Trap), Lang(Lang), Reason(Reason) {}
ExceptionTableEntry(const MCSymbol *Trap, unsigned Lang, unsigned Reason)
: Trap(Trap), Lang(Lang), Reason(Reason) {}
};
struct ExceptionInfo {
@ -220,8 +220,8 @@ struct ExceptionSectionEntry : public SectionEntry {
std::map<const StringRef, ExceptionInfo> ExceptionTable;
bool isDebugEnabled = false;
ExceptionSectionEntry(StringRef N, int32_t Flags) :
SectionEntry(N, Flags | XCOFF::STYP_EXCEPT) {
ExceptionSectionEntry(StringRef N, int32_t Flags)
: SectionEntry(N, Flags | XCOFF::STYP_EXCEPT) {
assert(N.size() <= XCOFF::NameSize && "Section too long.");
memcpy(Name, N.data(), N.size());
}
@ -319,22 +319,20 @@ class XCOFFObjectWriter : public MCObjectWriter {
const MCAsmLayout &Layout,
const DwarfSectionEntry &DwarfEntry,
uint64_t &CurrentAddressLocation);
void writeSectionForExceptionSectionEntry(const MCAssembler &Asm,
const MCAsmLayout &Layout,
ExceptionSectionEntry &ExceptionEntry,
uint64_t &CurrentAddressLocation);
void writeSectionForExceptionSectionEntry(
const MCAssembler &Asm, const MCAsmLayout &Layout,
ExceptionSectionEntry &ExceptionEntry, uint64_t &CurrentAddressLocation);
void writeSymbolTable(const MCAsmLayout &Layout);
void writeSymbolAuxDwarfEntry(uint64_t LengthOfSectionPortion,
uint64_t NumberOfRelocEnt = 0);
void writeSymbolAuxCsectEntry(uint64_t SectionOrLength,
uint8_t SymbolAlignmentAndType,
uint8_t StorageMappingClass);
void writeSymbolAuxFunctionEntry(uint32_t EntryOffset,
uint32_t FunctionSize,
void writeSymbolAuxFunctionEntry(uint32_t EntryOffset, uint32_t FunctionSize,
uint64_t LineNumberPointer,
uint32_t EndIndex);
void writeSymbolAuxExceptionEntry(uint64_t EntryOffset,
uint32_t FunctionSize, uint32_t EndIndex);
void writeSymbolAuxExceptionEntry(uint64_t EntryOffset, uint32_t FunctionSize,
uint32_t EndIndex);
void writeSymbolEntry(StringRef SymbolName, uint64_t Value,
int16_t SectionNumber, uint16_t SymbolType,
uint8_t StorageClass, uint8_t NumberOfAuxEntries = 1);
@ -1090,12 +1088,9 @@ void XCOFFObjectWriter::finalizeSectionInfo() {
SymbolTableOffset = RawPointer;
}
void XCOFFObjectWriter::addExceptionEntry(const MCSymbol *Symbol,
const MCSymbol *Trap,
unsigned LanguageCode,
unsigned ReasonCode,
unsigned FunctionSize,
bool hasDebug) {
void XCOFFObjectWriter::addExceptionEntry(
const MCSymbol *Symbol, const MCSymbol *Trap, unsigned LanguageCode,
unsigned ReasonCode, unsigned FunctionSize, bool hasDebug) {
// If a module had debug info, debugging is enabled and XCOFF emits the
// exception auxilliary entry.
if (hasDebug)
@ -1116,28 +1111,28 @@ void XCOFFObjectWriter::addExceptionEntry(const MCSymbol *Symbol,
}
unsigned XCOFFObjectWriter::getExceptionSectionSize() {
unsigned EntryNum=0;
unsigned EntryNum = 0;
for (auto it = ExceptionSection.ExceptionTable.begin();
it != ExceptionSection.ExceptionTable.end(); ++it)
it != ExceptionSection.ExceptionTable.end(); ++it)
// The size() gets +1 to account for the initial entry containing the
// symbol table index.
EntryNum += it->second.Entries.size() + 1;
return EntryNum * (is64Bit() ? XCOFF::ExceptionSectionEntrySize64 :
XCOFF::ExceptionSectionEntrySize32);
return EntryNum * (is64Bit() ? XCOFF::ExceptionSectionEntrySize64
: XCOFF::ExceptionSectionEntrySize32);
}
unsigned XCOFFObjectWriter::getExceptionOffset(const MCSymbol *Symbol) {
unsigned EntryNum = 0;
for (auto it = ExceptionSection.ExceptionTable.begin();
it != ExceptionSection.ExceptionTable.end(); ++it) {
it != ExceptionSection.ExceptionTable.end(); ++it) {
if (Symbol == it->second.FunctionSymbol)
break;
EntryNum += it->second.Entries.size() + 1;
}
return EntryNum * (is64Bit() ? XCOFF::ExceptionSectionEntrySize64 :
XCOFF::ExceptionSectionEntrySize32);
return EntryNum * (is64Bit() ? XCOFF::ExceptionSectionEntrySize64
: XCOFF::ExceptionSectionEntrySize32);
}
void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) {
@ -1204,12 +1199,12 @@ void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) {
bool hasExceptEntry = false;
auto Entry =
ExceptionSection.ExceptionTable.find(Sym.MCSym->getName());
if(Entry != ExceptionSection.ExceptionTable.end()) {
if (Entry != ExceptionSection.ExceptionTable.end()) {
hasExceptEntry = true;
for (auto &TrapEntry : Entry->second.Entries) {
TrapEntry.TrapAddress = Layout.getSymbolOffset(*(Sym.MCSym)) +
TrapEntry.Trap->getOffset();
}
}
}
Sym.SymbolTableIndex = SymbolTableIndex;
SymbolIndexMap[Sym.MCSym] = Sym.SymbolTableIndex;