Skip to content

Conversation

@cjacek
Copy link
Contributor

@cjacek cjacek commented Feb 23, 2025

Instead of duplicating the logic from LinkerDriver::setMachine.

…NFC)

Instead of duplicating the logic from LinkerDriver::setMachine.
@llvmbot
Copy link
Member

llvmbot commented Feb 23, 2025

@llvm/pr-subscribers-lld
@llvm/pr-subscribers-platform-windows

@llvm/pr-subscribers-lld-coff

Author: Jacek Caban (cjacek)

Changes

Instead of duplicating the logic from LinkerDriver::setMachine.


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

1 Files Affected:

  • (modified) lld/COFF/Writer.cpp (+1-10)
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 58727c1615769..3efbcdb452ebe 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -1758,16 +1758,7 @@ template <typename PEHeaderTy> void Writer::writeHeader() {
   assert(coffHeaderOffset == buf - buffer->getBufferStart());
   auto *coff = reinterpret_cast<coff_file_header *>(buf);
   buf += sizeof(*coff);
-  switch (config->machine) {
-  case ARM64EC:
-    coff->Machine = AMD64;
-    break;
-  case ARM64X:
-    coff->Machine = ARM64;
-    break;
-  default:
-    coff->Machine = config->machine;
-  }
+  coff->Machine = ctx.symtab.isEC() ? AMD64 : ctx.symtab.machine;
   coff->NumberOfSections = ctx.outputSections.size();
   coff->Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE;
   if (config->largeAddressAware)

Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The logic for which symtab has which machine set in which mode is still hazy to me, but the change looks straightforward, and I presume we have relevant test coverage to be sure that this really is NFC.

@cjacek cjacek merged commit 94f34c0 into llvm:main Feb 27, 2025
15 checks passed
@cjacek cjacek deleted the arm64x-pe-machine branch February 27, 2025 20:53
SquallATF pushed a commit to SquallATF/llvm-project that referenced this pull request Jun 13, 2025
…NFC) (llvm#128442)

Instead of duplicating the logic from `LinkerDriver::setMachine`.
SquallATF pushed a commit to SquallATF/llvm-project that referenced this pull request Jul 14, 2025
…NFC) (llvm#128442)

Instead of duplicating the logic from `LinkerDriver::setMachine`.
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.

3 participants