Skip to content

[LLD][COFF] Use primary symbol table machine in Writer::writeHeader (NFC) #128442

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

Merged
merged 1 commit into from
Feb 27, 2025

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 Mar 10, 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 Mar 20, 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 Apr 2, 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 Apr 17, 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 Apr 30, 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 May 15, 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 May 29, 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 Jun 13, 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