Skip to content

Commit

Permalink
[llvm-readobj][COFF] Add support for version 2 of CHPE metadata (#109545
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cjacek authored Sep 22, 2024
1 parent 2e729ba commit 5a68ac8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
5 changes: 5 additions & 0 deletions llvm/include/llvm/Object/COFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,11 @@ struct chpe_metadata {
support::ulittle32_t ExtraRFETableSize;
support::ulittle32_t __os_arm64x_dispatch_fptr;
support::ulittle32_t AuxiliaryIATCopy;

// Added in CHPE metadata v2
support::ulittle32_t AuxiliaryDelayloadIAT;
support::ulittle32_t AuxiliaryDelayloadIATCopy;
support::ulittle32_t HybridImageInfoBitfield;
};

enum chpe_range_type { Arm64 = 0, Arm64EC = 1, Amd64 = 2 };
Expand Down
69 changes: 67 additions & 2 deletions llvm/test/tools/llvm-readobj/COFF/arm64ec-chpe.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-readobj --coff-load-config %t | FileCheck %s
# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: llvm-readobj --coff-load-config %t1 | FileCheck %s

# CHECK: CHPEMetadataPointer: 0x180005000
# CHECK: CHPEMetadata [
Expand All @@ -17,6 +17,7 @@
# CHECK-NEXT: 0x1000 -> 0x2000
# CHECK-NEXT: 0x1020 -> 0x2030
# CHECK-NEXT: ]
# CHECK-NOT: AuxiliaryDelayloadIAT:

--- !COFF
OptionalHeader:
Expand Down Expand Up @@ -85,3 +86,67 @@ sections:
- UInt32: 0x2030
symbols: []
...

# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: llvm-readobj --coff-load-config %t2 | FileCheck --check-prefix=CHPE2 %s

# CHPE2: CHPEMetadata [
# CHPE2-NEXT: Version: 0x2
# CHPE2: AuxiliaryDelayloadIAT: 0x1
# CHPE2-NEXT: AuxiliaryDelayloadIATCopy: 0x2
# CHPE2-NEXT: HybridImageInfoBitfield: 0x4

--- !COFF
OptionalHeader:
ImageBase: 0x180000000
SectionAlignment: 4096
FileAlignment: 512
DLLCharacteristics: [ ]
LoadConfigTable:
RelativeVirtualAddress: 0x4000
Size: 320
header:
Machine: IMAGE_FILE_MACHINE_AMD64
Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE, IMAGE_FILE_DLL ]
sections:
- Name: .text
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
VirtualAddress: 0x1000
VirtualSize: 0x2050
- Name: .rdata
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
VirtualAddress: 0x4000
VirtualSize: 328
StructuredData:
- LoadConfig:
CHPEMetadataPointer: 0x180005000
- Name: .data
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
VirtualAddress: 0x5000
VirtualSize: 144
StructuredData:
- UInt32: 2 # Version
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 0
- UInt32: 1 # AuxiliaryDelayloadIAT
- UInt32: 2 # AuxiliaryDelayloadIATCopy
- UInt32: 4 # HybridImageInfoBitfield
symbols: []
...
6 changes: 6 additions & 0 deletions llvm/tools/llvm-readobj/COFFDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,12 @@ void COFFDumper::printCOFFLoadConfig() {
W.printHex("ExtraRFETableSize", CHPE->ExtraRFETableSize);
W.printHex("__os_arm64x_dispatch_fptr", CHPE->__os_arm64x_dispatch_fptr);
W.printHex("AuxiliaryIATCopy", CHPE->AuxiliaryIATCopy);

if (CHPE->Version >= 2) {
W.printHex("AuxiliaryDelayloadIAT", CHPE->AuxiliaryDelayloadIAT);
W.printHex("AuxiliaryDelayloadIATCopy", CHPE->AuxiliaryDelayloadIATCopy);
W.printHex("HybridImageInfoBitfield", CHPE->HybridImageInfoBitfield);
}
}

if (Tables.SEHTableVA) {
Expand Down

0 comments on commit 5a68ac8

Please sign in to comment.