Skip to content

Commit

Permalink
[COFF] Widen PE32Header fields to fit 64 bit versions
Browse files Browse the repository at this point in the history
The PE32Header struct is only used by COFFYAML, for intermediate
storage. The struct doesn't match the on-disk struct layout as it
uses native integers instead of e.g. support::ulittle32_t, so just
widen the fields to fit values for object::pe32plus_header, in
addition to object::pe32_header.

This avoids truncating the 64 bit ImageBase for 64 bit executables.

Differential Revision: https://reviews.llvm.org/D70464
  • Loading branch information
mstorsjo committed Nov 21, 2019
1 parent 337151f commit 2229391
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 5 additions & 5 deletions llvm/include/llvm/BinaryFormat/COFF.h
Expand Up @@ -547,7 +547,7 @@ struct PE32Header {
uint32_t AddressOfEntryPoint; // RVA
uint32_t BaseOfCode; // RVA
uint32_t BaseOfData; // RVA
uint32_t ImageBase;
uint64_t ImageBase;
uint32_t SectionAlignment;
uint32_t FileAlignment;
uint16_t MajorOperatingSystemVersion;
Expand All @@ -563,10 +563,10 @@ struct PE32Header {
uint16_t Subsystem;
// FIXME: This should be DllCharacteristics to match the COFF spec.
uint16_t DLLCharacteristics;
uint32_t SizeOfStackReserve;
uint32_t SizeOfStackCommit;
uint32_t SizeOfHeapReserve;
uint32_t SizeOfHeapCommit;
uint64_t SizeOfStackReserve;
uint64_t SizeOfStackCommit;
uint64_t SizeOfHeapReserve;
uint64_t SizeOfHeapCommit;
uint32_t LoaderFlags;
// FIXME: This should be NumberOfRvaAndSizes to match the COFF spec.
uint32_t NumberOfRvaAndSize;
Expand Down
4 changes: 3 additions & 1 deletion llvm/test/tools/yaml2obj/COFF/basic-arm64.yaml
Expand Up @@ -3,15 +3,17 @@
# RUN: obj2yaml %t | FileCheck %s --check-prefix=ROUNDTRIP

# CHECK: OptionalHeaderSize: 240
# CHECK: ImageBase: 0x140000000

# ROUNDTRIP: ImageBase: 5368709120
# ROUNDTRIP: VirtualAddress: 4096
# ROUNDTRIP: VirtualAddress: 8192
# ROUNDTRIP: VirtualAddress: 12288

--- !COFF
OptionalHeader:
AddressOfEntryPoint: 4096
ImageBase: 1073741824
ImageBase: 5368709120
SectionAlignment: 4096
FileAlignment: 512
MajorOperatingSystemVersion: 6
Expand Down

0 comments on commit 2229391

Please sign in to comment.