Skip to content

Commit ec43c12

Browse files
committedJun 10, 2021
[NFC][XCOFF] Replace structs FileHeader32/SectionHeader32 with constants.
Summary: Some structs like FileHeader32/SectionHeader32 defined in llvm/include/llvm/BinaryFormat/XCOFF.h seem unnecessary, because we only need their size. So this patch removes them and defines size constants directly. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D103901
1 parent a9e4f91 commit ec43c12

File tree

3 files changed

+6
-27
lines changed

3 files changed

+6
-27
lines changed
 

‎llvm/include/llvm/BinaryFormat/XCOFF.h

+2-23
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace XCOFF {
2626

2727
constexpr size_t FileNamePadSize = 6;
2828
constexpr size_t NameSize = 8;
29+
constexpr size_t FileHeaderSize32 = 20;
30+
constexpr size_t SectionHeaderSize32 = 40;
2931
constexpr size_t SymbolTableEntrySize = 18;
3032
constexpr size_t RelocationSerializationSize32 = 10;
3133
constexpr uint16_t RelocOverflow = 65535;
@@ -255,29 +257,6 @@ enum RelocationType : uint8_t {
255257
///< large code model TOC-relative relocation.
256258
};
257259

258-
struct FileHeader32 {
259-
uint16_t Magic;
260-
uint16_t NumberOfSections;
261-
int32_t TimeStamp;
262-
uint32_t SymbolTableFileOffset;
263-
int32_t NumberOfSymbolTableEntries;
264-
uint16_t AuxiliaryHeaderSize;
265-
uint16_t Flags;
266-
};
267-
268-
struct SectionHeader32 {
269-
char Name[XCOFF::NameSize];
270-
uint32_t PhysicalAddress;
271-
uint32_t VirtualAddress;
272-
uint32_t Size;
273-
uint32_t FileOffsetToData;
274-
uint32_t FileOffsetToRelocations;
275-
uint32_t FileOffsetToLineNumbers;
276-
uint16_t NumberOfRelocations;
277-
uint16_t NumberOfLineNumbers;
278-
int32_t Flags;
279-
};
280-
281260
enum CFileStringType : uint8_t {
282261
XFT_FN = 0, ///< Specifies the source-file name.
283262
XFT_CT = 1, ///< Specifies the compiler time stamp.

‎llvm/lib/MC/XCOFFObjectWriter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -922,8 +922,8 @@ void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) {
922922
SymbolTableEntryCount = SymbolTableIndex;
923923

924924
// Calculate the RawPointer value for each section.
925-
uint64_t RawPointer = sizeof(XCOFF::FileHeader32) + auxiliaryHeaderSize() +
926-
SectionCount * sizeof(XCOFF::SectionHeader32);
925+
uint64_t RawPointer = XCOFF::FileHeaderSize32 + auxiliaryHeaderSize() +
926+
SectionCount * XCOFF::SectionHeaderSize32;
927927
for (auto *Sec : Sections) {
928928
if (Sec->Index == Section::UninitializedIndex || Sec->IsVirtual)
929929
continue;

‎llvm/lib/ObjectYAML/XCOFFEmitter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ bool XCOFFWriter::initFileHeader(uint64_t CurrentOffset) {
158158

159159
bool XCOFFWriter::assignAddressesAndIndices() {
160160
uint64_t CurrentOffset =
161-
sizeof(XCOFF::FileHeader32) /* TODO: + auxiliaryHeaderSize() */ +
162-
InitSections.size() * sizeof(XCOFF::SectionHeader32);
161+
XCOFF::FileHeaderSize32 /* TODO: + auxiliaryHeaderSize() */ +
162+
InitSections.size() * XCOFF::SectionHeaderSize32;
163163

164164
// Calculate section header info.
165165
if (!initSectionHeader(CurrentOffset))

0 commit comments

Comments
 (0)
Please sign in to comment.