1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 12:12:47 +01:00

Using crtp to refactor the xcoff section header

SUMMARY:
According to https://reviews.llvm.org/D68575#inline-617586, Create a NFC patch for it.

Using crtp to refactor the xcoff section header
Move the define of SectionFlagsReservedMask and SectionFlagsTypeMask from XCOFFDumper.cpp to XCOFFObjectFile.h

Reviewers: hubert.reinterpretcast,jasonliu
Subscribers: rupprecht, seiyai,hiraditya

Differential Revision: https://reviews.llvm.org/D69131
This commit is contained in:
diggerlin 2019-11-07 11:51:34 -05:00
parent 90ce51c254
commit 20cfcdf6d9
3 changed files with 36 additions and 25 deletions

View File

@ -47,7 +47,20 @@ struct XCOFFFileHeader64 {
support::ubig32_t NumberOfSymTableEntries;
};
struct XCOFFSectionHeader32 {
template <typename T> struct XCOFFSectionHeader {
// Least significant 3 bits are reserved.
static constexpr unsigned SectionFlagsReservedMask = 0x7;
// The low order 16 bits of section flags denotes the section type.
static constexpr unsigned SectionFlagsTypeMask = 0xffffu;
public:
StringRef getName() const;
uint16_t getSectionType() const;
bool isReservedSectionType() const;
};
struct XCOFFSectionHeader32 : XCOFFSectionHeader<XCOFFSectionHeader32> {
char Name[XCOFF::NameSize];
support::ubig32_t PhysicalAddress;
support::ubig32_t VirtualAddress;
@ -58,11 +71,9 @@ struct XCOFFSectionHeader32 {
support::ubig16_t NumberOfRelocations;
support::ubig16_t NumberOfLineNumbers;
support::big32_t Flags;
StringRef getName() const;
};
struct XCOFFSectionHeader64 {
struct XCOFFSectionHeader64 : XCOFFSectionHeader<XCOFFSectionHeader64> {
char Name[XCOFF::NameSize];
support::ubig64_t PhysicalAddress;
support::ubig64_t VirtualAddress;
@ -74,8 +85,6 @@ struct XCOFFSectionHeader64 {
support::ubig32_t NumberOfLineNumbers;
support::big32_t Flags;
char Padding[4];
StringRef getName() const;
};
struct XCOFFSymbolEntry {

View File

@ -46,6 +46,25 @@ static StringRef generateXCOFFFixedNameStringRef(const char *Name) {
: StringRef(Name, XCOFF::NameSize);
}
// Explictly instantiate template classes.
template struct XCOFFSectionHeader<XCOFFSectionHeader32>;
template struct XCOFFSectionHeader<XCOFFSectionHeader64>;
template <typename T> StringRef XCOFFSectionHeader<T>::getName() const {
const T &DerivedXCOFFSectionHeader = static_cast<const T &>(*this);
return generateXCOFFFixedNameStringRef(DerivedXCOFFSectionHeader.Name);
}
template <typename T> uint16_t XCOFFSectionHeader<T>::getSectionType() const {
const T &DerivedXCOFFSectionHeader = static_cast<const T &>(*this);
return DerivedXCOFFSectionHeader.Flags & SectionFlagsTypeMask;
}
template <typename T>
bool XCOFFSectionHeader<T>::isReservedSectionType() const {
return getSectionType() & SectionFlagsReservedMask;
}
bool XCOFFRelocation32::isRelocationSigned() const {
return Info & XR_SIGN_INDICATOR_MASK;
}
@ -688,14 +707,6 @@ ObjectFile::createXCOFFObjectFile(MemoryBufferRef MemBufRef,
return XCOFFObjectFile::create(FileType, MemBufRef);
}
StringRef XCOFFSectionHeader32::getName() const {
return generateXCOFFFixedNameStringRef(Name);
}
StringRef XCOFFSectionHeader64::getName() const {
return generateXCOFFFixedNameStringRef(Name);
}
XCOFF::StorageClass XCOFFSymbolRef::getStorageClass() const {
return OwningObjectPtr->toSymbolEntry(SymEntDataRef)->StorageClass;
}

View File

@ -49,13 +49,6 @@ private:
void printCsectAuxEnt32(const XCOFFCsectAuxEnt32 *AuxEntPtr);
void printSectAuxEntForStat(const XCOFFSectAuxEntForStat *AuxEntPtr);
void printSymbol(const SymbolRef &);
// Least significant 3 bits are reserved.
static constexpr unsigned SectionFlagsReservedMask = 0x7;
// The low order 16 bits of section flags denotes the section type.
static constexpr unsigned SectionFlagsTypeMask = 0xffffu;
void printRelocations(ArrayRef<XCOFFSectionHeader32> Sections);
const XCOFFObjectFile &Obj;
};
@ -496,8 +489,7 @@ void XCOFFDumper::printSectionHeaders(ArrayRef<T> Sections) {
DictScope SecDS(W, "Section");
W.printNumber("Index", Index++);
uint16_t SectionType = Sec.Flags & SectionFlagsTypeMask;
uint16_t SectionType = Sec.getSectionType();
switch (SectionType) {
case XCOFF::STYP_OVRFLO:
printOverflowSectionHeader(Sec);
@ -513,8 +505,7 @@ void XCOFFDumper::printSectionHeaders(ArrayRef<T> Sections) {
printGenericSectionHeader(Sec);
break;
}
// For now we just dump the section type portion of the flags.
if (SectionType & SectionFlagsReservedMask)
if (Sec.isReservedSectionType())
W.printHex("Flags", "Reserved", SectionType);
else
W.printEnum("Type", SectionType, makeArrayRef(SectionTypeFlagsNames));