[PATCH] D156454: [Object] [NFC] Use llvm::COFF::is64Bit in COFF import file implementation.

Jacek Caban via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 28 05:29:21 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6b04ec1d020c: [Object] [NFC] Use llvm::COFF::is64Bit in COFF import file implementation. (authored by jacek).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156454/new/

https://reviews.llvm.org/D156454

Files:
  llvm/lib/Object/COFFImportFile.cpp


Index: llvm/lib/Object/COFFImportFile.cpp
===================================================================
--- llvm/lib/Object/COFFImportFile.cpp
+++ llvm/lib/Object/COFFImportFile.cpp
@@ -33,21 +33,6 @@
 namespace llvm {
 namespace object {
 
-static bool is32bit(MachineTypes Machine) {
-  switch (Machine) {
-  default:
-    llvm_unreachable("unsupported machine");
-  case IMAGE_FILE_MACHINE_ARM64:
-  case IMAGE_FILE_MACHINE_ARM64EC:
-  case IMAGE_FILE_MACHINE_ARM64X:
-  case IMAGE_FILE_MACHINE_AMD64:
-    return false;
-  case IMAGE_FILE_MACHINE_ARMNT:
-  case IMAGE_FILE_MACHINE_I386:
-    return true;
-  }
-}
-
 static uint16_t getImgRelRelocation(MachineTypes Machine) {
   switch (Machine) {
   default:
@@ -204,7 +189,7 @@
           (ImportName.size() + 1)),
       u32(NumberOfSymbols),
       u16(0),
-      u16(is32bit(Machine) ? IMAGE_FILE_32BIT_MACHINE : C_Invalid),
+      u16(is64Bit(Machine) ? C_Invalid : IMAGE_FILE_32BIT_MACHINE),
   };
   append(Buffer, Header);
 
@@ -340,7 +325,7 @@
           sizeof(coff_import_directory_table_entry)),
       u32(NumberOfSymbols),
       u16(0),
-      u16(is32bit(Machine) ? IMAGE_FILE_32BIT_MACHINE : C_Invalid),
+      u16(is64Bit(Machine) ? C_Invalid : IMAGE_FILE_32BIT_MACHINE),
   };
   append(Buffer, Header);
 
@@ -389,7 +374,7 @@
 NewArchiveMember ObjectFactory::createNullThunk(std::vector<uint8_t> &Buffer) {
   const uint32_t NumberOfSections = 2;
   const uint32_t NumberOfSymbols = 1;
-  uint32_t VASize = is32bit(Machine) ? 4 : 8;
+  uint32_t VASize = is64Bit(Machine) ? 8 : 4;
 
   // COFF Header
   coff_file_header Header{
@@ -403,7 +388,7 @@
           VASize),
       u32(NumberOfSymbols),
       u16(0),
-      u16(is32bit(Machine) ? IMAGE_FILE_32BIT_MACHINE : C_Invalid),
+      u16(is64Bit(Machine) ? C_Invalid : IMAGE_FILE_32BIT_MACHINE),
   };
   append(Buffer, Header);
 
@@ -418,8 +403,8 @@
        u32(0),
        u16(0),
        u16(0),
-       u32((is32bit(Machine) ? IMAGE_SCN_ALIGN_4BYTES
-                             : IMAGE_SCN_ALIGN_8BYTES) |
+       u32((is64Bit(Machine) ? IMAGE_SCN_ALIGN_8BYTES
+                             : IMAGE_SCN_ALIGN_4BYTES) |
            IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ |
            IMAGE_SCN_MEM_WRITE)},
       {{'.', 'i', 'd', 'a', 't', 'a', '$', '4'},
@@ -432,8 +417,8 @@
        u32(0),
        u16(0),
        u16(0),
-       u32((is32bit(Machine) ? IMAGE_SCN_ALIGN_4BYTES
-                             : IMAGE_SCN_ALIGN_8BYTES) |
+       u32((is64Bit(Machine) ? IMAGE_SCN_ALIGN_8BYTES
+                             : IMAGE_SCN_ALIGN_4BYTES) |
            IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ |
            IMAGE_SCN_MEM_WRITE)},
   };
@@ -441,12 +426,12 @@
 
   // .idata$5, ILT
   append(Buffer, u32(0));
-  if (!is32bit(Machine))
+  if (is64Bit(Machine))
     append(Buffer, u32(0));
 
   // .idata$4, IAT
   append(Buffer, u32(0));
-  if (!is32bit(Machine))
+  if (is64Bit(Machine))
     append(Buffer, u32(0));
 
   // Symbol Table


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156454.545109.patch
Type: text/x-patch
Size: 3012 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230728/eb91d69c/attachment.bin>


More information about the llvm-commits mailing list