Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cjacek
Copy link
Contributor

@cjacek cjacek commented Sep 21, 2024

No description provided.

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 21, 2024

@llvm/pr-subscribers-llvm-binary-utilities

Author: Jacek Caban (cjacek)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/109545.diff

3 Files Affected:

  • (modified) llvm/include/llvm/Object/COFF.h (+5)
  • (modified) llvm/test/tools/llvm-readobj/COFF/arm64ec-chpe.yaml (+67-2)
  • (modified) llvm/tools/llvm-readobj/COFFDumper.cpp (+6)
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) {

@cjacek
Copy link
Contributor Author

cjacek commented Sep 21, 2024

The change to chpe_metadata also affects the check in COFFObjectFile::initLoadConfigPtr, which uses sizeof(), but it should be fine for v1 as it should have placeholders there anyway, like we do in lld/test/COFF/Inputs/loadconfig-arm64ec.s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants