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;
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;
support::ubig32_t NumberOfLineNumbers;
support::big32_t Flags;
char Padding[4];
-
- StringRef getName() const;
};
struct XCOFFSymbolEntry {
: 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;
}
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;
}
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;
};
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);
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));