[llvm] 5a68ac8 - [llvm-readobj][COFF] Add support for version 2 of CHPE metadata (#109545)

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 22 13:36:43 PDT 2024


Author: Jacek Caban
Date: 2024-09-22T22:36:39+02:00
New Revision: 5a68ac8ba751d535509826d72f91584cf5d44046

URL: https://github.com/llvm/llvm-project/commit/5a68ac8ba751d535509826d72f91584cf5d44046
DIFF: https://github.com/llvm/llvm-project/commit/5a68ac8ba751d535509826d72f91584cf5d44046.diff

LOG: [llvm-readobj][COFF] Add support for version 2 of CHPE metadata (#109545)

Added: 
    

Modified: 
    llvm/include/llvm/Object/COFF.h
    llvm/test/tools/llvm-readobj/COFF/arm64ec-chpe.yaml
    llvm/tools/llvm-readobj/COFFDumper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Object/COFF.h b/llvm/include/llvm/Object/COFF.h
index dc43c87c4125c3..05b3587224c296 100644
--- a/llvm/include/llvm/Object/COFF.h
+++ b/llvm/include/llvm/Object/COFF.h
@@ -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 };

diff  --git a/llvm/test/tools/llvm-readobj/COFF/arm64ec-chpe.yaml b/llvm/test/tools/llvm-readobj/COFF/arm64ec-chpe.yaml
index 2aa80df0820e90..1f5e7e10888989 100644
--- a/llvm/test/tools/llvm-readobj/COFF/arm64ec-chpe.yaml
+++ b/llvm/test/tools/llvm-readobj/COFF/arm64ec-chpe.yaml
@@ -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 [
@@ -17,6 +17,7 @@
 # CHECK-NEXT:     0x1000 -> 0x2000
 # CHECK-NEXT:     0x1020 -> 0x2030
 # CHECK-NEXT:   ]
+# CHECK-NOT:    AuxiliaryDelayloadIAT:
 
 --- !COFF
 OptionalHeader:
@@ -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:         []
+...

diff  --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp
index 65d67d29a5aa30..1666f7692ad5f0 100644
--- a/llvm/tools/llvm-readobj/COFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/COFFDumper.cpp
@@ -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) {


        


More information about the llvm-commits mailing list