This is an archive of the discontinued LLVM Phabricator instance.

[ARM64EC 1/?] Add parsing support to llvm-objdump/llvm-readobj.
ClosedPublic

Authored by efriedma on May 11 2022, 1:27 PM.

Details

Summary

This is the first patch of a patchset to add initial support for ARM64EC. Basic documentation is available at https://docs.microsoft.com/en-us/windows/uwp/porting/arm64ec-abi . (Discourse post: https://discourse.llvm.org/t/initial-patches-for-arm64ec-windows-11-now-posted/62449 .)

The file format for ARM64EC is basically identical to normal ARM64. There are a few extra sections, but the existing code for reading ARM64 object files just works.

Diff Detail

Event Timeline

efriedma created this revision.May 11 2022, 1:27 PM
Herald added a project: Restricted Project. · View Herald Transcript
efriedma requested review of this revision.May 11 2022, 1:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2022, 1:27 PM

Nice! I started looking into this long ago, but essentially didn't get any further than this patch...

A couple other hunks you might want to incorporate (or maybe you have them queued up already, in later patches - in that case, just disregard me):

diff --git a/llvm/lib/Object/WindowsMachineFlag.cpp b/llvm/lib/Object/WindowsMachineFlag.cpp
index f7f2b20ae1a2..eef0ea83c927 100644
--- a/llvm/lib/Object/WindowsMachineFlag.cpp
+++ b/llvm/lib/Object/WindowsMachineFlag.cpp
@@ -25,6 +25,7 @@ COFF::MachineTypes llvm::getMachineType(StringRef S) {
       .Cases("x86", "i386", COFF::IMAGE_FILE_MACHINE_I386)
       .Case("arm", COFF::IMAGE_FILE_MACHINE_ARMNT)
       .Case("arm64", COFF::IMAGE_FILE_MACHINE_ARM64)
+      .Case("arm64ec", COFF::IMAGE_FILE_MACHINE_ARM64EC)
       .Default(COFF::IMAGE_FILE_MACHINE_UNKNOWN);
 }
 
@@ -34,6 +35,8 @@ StringRef llvm::machineToStr(COFF::MachineTypes MT) {
     return "arm";
   case COFF::IMAGE_FILE_MACHINE_ARM64:
     return "arm64";
+  case COFF::IMAGE_FILE_MACHINE_ARM64EC:
+    return "arm64ec";
   case COFF::IMAGE_FILE_MACHINE_AMD64:
     return "x64";
   case COFF::IMAGE_FILE_MACHINE_I386: 
diff --git a/llvm/lib/ObjectYAML/COFFEmitter.cpp b/llvm/lib/ObjectYAML/COFFEmitter.cpp
index d884e2fd55cd..0068ccfe17a6 100644
--- a/llvm/lib/ObjectYAML/COFFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/COFFEmitter.cpp
@@ -48,7 +48,8 @@ struct COFFParser {
   bool isPE() const { return Obj.OptionalHeader.hasValue(); }
   bool is64Bit() const {
     return Obj.Header.Machine == COFF::IMAGE_FILE_MACHINE_AMD64 ||
-           Obj.Header.Machine == COFF::IMAGE_FILE_MACHINE_ARM64;
+           Obj.Header.Machine == COFF::IMAGE_FILE_MACHINE_ARM64 ||
+           Obj.Header.Machine == COFF::IMAGE_FILE_MACHINE_ARM64EC;
   }
 
   uint32_t getFileAlignment() const {
efriedma edited the summary of this revision. (Show Details)May 11 2022, 2:22 PM
apazos added a subscriber: apazos.May 11 2022, 3:17 PM
apazos added inline comments.
llvm/lib/ObjectYAML/COFFYAML.cpp
81

Was this RISCV change accidental?

efriedma added inline comments.May 11 2022, 4:32 PM
llvm/lib/ObjectYAML/COFFYAML.cpp
81

More of a "while I'm here" thing; I could split it into a separate patch, I guess.

DavidSpickett added a subscriber: DavidSpickett.
DavidSpickett added inline comments.
llvm/lib/BinaryFormat/Magic.cpp
237

Is the value documented yet? I'm looking at https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#machine-types but I don't see it.

mstorsjo added inline comments.May 12 2022, 5:36 AM
llvm/lib/BinaryFormat/Magic.cpp
237

It actually seems to be missing in winnt.h in the 10.0.22000.0 WinSDK headers too.

efriedma added inline comments.May 12 2022, 9:25 AM
llvm/lib/BinaryFormat/Magic.cpp
237

If you're looking at anything related to ARM64EC, you should looking at the Windows 11 SDK.

Pretty sure the constant is in the SDK headers.

efriedma updated this revision to Diff 429071.May 12 2022, 2:12 PM

Update more places that check for IMAGE_FILE_MACHINE_ARM64

Any further comments on this? I'd like to start landing some ARM64EC patches soon.

This revision is now accepted and ready to land.Sep 2 2022, 1:24 AM
This revision was landed with ongoing or failed builds.Sep 5 2022, 12:26 PM
This revision was automatically updated to reflect the committed changes.