[llvm] 6b04ec1 - [Object] [NFC] Use llvm::COFF::is64Bit in COFF import file implementation.
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 28 05:29:14 PDT 2023
Author: Jacek Caban
Date: 2023-07-28T14:20:15+02:00
New Revision: 6b04ec1d020c20ce786af030be2c2cb82aed80b9
URL: https://github.com/llvm/llvm-project/commit/6b04ec1d020c20ce786af030be2c2cb82aed80b9
DIFF: https://github.com/llvm/llvm-project/commit/6b04ec1d020c20ce786af030be2c2cb82aed80b9.diff
LOG: [Object] [NFC] Use llvm::COFF::is64Bit in COFF import file implementation.
Reviewed By: jhenderson, efriedma
Differential Revision: https://reviews.llvm.org/D156454
Added:
Modified:
llvm/lib/Object/COFFImportFile.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Object/COFFImportFile.cpp b/llvm/lib/Object/COFFImportFile.cpp
index 765c12cc076c93..a58a444869c871 100644
--- a/llvm/lib/Object/COFFImportFile.cpp
+++ b/llvm/lib/Object/COFFImportFile.cpp
@@ -33,21 +33,6 @@ using namespace llvm;
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 @@ ObjectFactory::createImportDescriptor(std::vector<uint8_t> &Buffer) {
(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 @@ ObjectFactory::createNullImportDescriptor(std::vector<uint8_t> &Buffer) {
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 @@ ObjectFactory::createNullImportDescriptor(std::vector<uint8_t> &Buffer) {
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 @@ NewArchiveMember ObjectFactory::createNullThunk(std::vector<uint8_t> &Buffer) {
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 @@ NewArchiveMember ObjectFactory::createNullThunk(std::vector<uint8_t> &Buffer) {
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 @@ NewArchiveMember ObjectFactory::createNullThunk(std::vector<uint8_t> &Buffer) {
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 @@ NewArchiveMember ObjectFactory::createNullThunk(std::vector<uint8_t> &Buffer) {
// .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
More information about the llvm-commits
mailing list