[llvm] b26bfcc - [llvm-readobj][Object][COFF] Include COFF import file machine type in format string. (#78366)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 17 13:47:22 PST 2024
Author: Jacek Caban
Date: 2024-01-17T22:47:18+01:00
New Revision: b26bfcc1ecc3c56d36fe6e525788024d1fdee01c
URL: https://github.com/llvm/llvm-project/commit/b26bfcc1ecc3c56d36fe6e525788024d1fdee01c
DIFF: https://github.com/llvm/llvm-project/commit/b26bfcc1ecc3c56d36fe6e525788024d1fdee01c.diff
LOG: [llvm-readobj][Object][COFF] Include COFF import file machine type in format string. (#78366)
Added:
Modified:
llvm/include/llvm/Object/COFFImportFile.h
llvm/lib/Object/COFFImportFile.cpp
llvm/test/tools/llvm-dlltool/coff-exports.def
llvm/test/tools/llvm-lib/arm64ec-implib.test
llvm/test/tools/llvm-readobj/COFF/exports-implib.test
llvm/test/tools/llvm-readobj/COFF/file-headers.test
llvm/tools/llvm-readobj/COFFImportDumper.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Object/COFFImportFile.h b/llvm/include/llvm/Object/COFFImportFile.h
index 0fb65fabdbcad59..edc836ff0348cb2 100644
--- a/llvm/include/llvm/Object/COFFImportFile.h
+++ b/llvm/include/llvm/Object/COFFImportFile.h
@@ -65,6 +65,8 @@ class COFFImportFile : public SymbolicFile {
uint16_t getMachine() const { return getCOFFImportHeader()->Machine; }
+ StringRef getFileFormatName() const;
+
private:
bool isData() const {
return getCOFFImportHeader()->getType() == COFF::IMPORT_DATA;
diff --git a/llvm/lib/Object/COFFImportFile.cpp b/llvm/lib/Object/COFFImportFile.cpp
index eeb13ffe9c11b0b..b60e32f498eb5a8 100644
--- a/llvm/lib/Object/COFFImportFile.cpp
+++ b/llvm/lib/Object/COFFImportFile.cpp
@@ -33,6 +33,25 @@ using namespace llvm;
namespace llvm {
namespace object {
+StringRef COFFImportFile::getFileFormatName() const {
+ switch (getMachine()) {
+ case COFF::IMAGE_FILE_MACHINE_I386:
+ return "COFF-import-file-i386";
+ case COFF::IMAGE_FILE_MACHINE_AMD64:
+ return "COFF-import-file-x86-64";
+ case COFF::IMAGE_FILE_MACHINE_ARMNT:
+ return "COFF-import-file-ARM";
+ case COFF::IMAGE_FILE_MACHINE_ARM64:
+ return "COFF-import-file-ARM64";
+ case COFF::IMAGE_FILE_MACHINE_ARM64EC:
+ return "COFF-import-file-ARM64EC";
+ case COFF::IMAGE_FILE_MACHINE_ARM64X:
+ return "COFF-import-file-ARM64X";
+ default:
+ return "COFF-import-file-<unknown arch>";
+ }
+}
+
static uint16_t getImgRelRelocation(MachineTypes Machine) {
switch (Machine) {
default:
diff --git a/llvm/test/tools/llvm-dlltool/coff-exports.def b/llvm/test/tools/llvm-dlltool/coff-exports.def
index 91a7e27ea4720fe..57c557446021565 100644
--- a/llvm/test/tools/llvm-dlltool/coff-exports.def
+++ b/llvm/test/tools/llvm-dlltool/coff-exports.def
@@ -1,8 +1,8 @@
; RUN: llvm-dlltool -m i386:x86-64 --input-def %s --output-lib %t.a
-; RUN: llvm-readobj %t.a | FileCheck %s
+; RUN: llvm-readobj %t.a | FileCheck %s --check-prefixes=CHECK,CHECK-X64
; RUN: llvm-nm --print-armap %t.a | FileCheck --check-prefix=SYMTAB %s
; RUN: llvm-dlltool -m arm64 --input-def %s --output-lib %t.a
-; RUN: llvm-readobj %t.a | FileCheck %s
+; RUN: llvm-readobj %t.a | FileCheck %s --check-prefixes=CHECK,CHECK-ARM64
; RUN: llvm-nm --print-armap %t.a | FileCheck --check-prefix=SYMTAB %s
LIBRARY test.dll
@@ -13,7 +13,8 @@ TestFunction3 ; This is a comment
AnotherFunction
; CHECK: File: test.dll
-; CHECK: Format: COFF-import-file
+; CHECK-X64: Format: COFF-import-file-x86-64
+; CHECK-ARM64: Format: COFF-import-file-ARM64
; CHECK: Type: code
; CHECK: Name type: name
; CHECK-NEXT: Symbol: __imp_TestFunction1
diff --git a/llvm/test/tools/llvm-lib/arm64ec-implib.test b/llvm/test/tools/llvm-lib/arm64ec-implib.test
index ee8b134d06b1667..3c74b4bf6607659 100644
--- a/llvm/test/tools/llvm-lib/arm64ec-implib.test
+++ b/llvm/test/tools/llvm-lib/arm64ec-implib.test
@@ -26,19 +26,19 @@ READOBJ-NEXT: Arch: aarch64
READOBJ-NEXT: AddressSize: 64bit
READOBJ-EMPTY:
READOBJ-NEXT: File: test.lib(test.dll)
-READOBJ-NEXT: Format: COFF-ARM64
+READOBJ-NEXT: Format: COFF-ARM64EC
READOBJ-NEXT: Arch: aarch64
READOBJ-NEXT: AddressSize: 64bit
READOBJ-EMPTY:
READOBJ-NEXT: File: test.dll
-READOBJ-NEXT: Format: COFF-import-file
+READOBJ-NEXT: Format: COFF-import-file-ARM64EC
READOBJ-NEXT: Type: code
READOBJ-NEXT: Name type: name
READOBJ-NEXT: Symbol: __imp_funcexp
READOBJ-NEXT: Symbol: funcexp
READOBJ-EMPTY:
READOBJ-NEXT: File: test.dll
-READOBJ-NEXT: Format: COFF-import-file
+READOBJ-NEXT: Format: COFF-import-file-ARM64EC
READOBJ-NEXT: Type: data
READOBJ-NEXT: Name type: name
READOBJ-NEXT: Symbol: __imp_dataexp
diff --git a/llvm/test/tools/llvm-readobj/COFF/exports-implib.test b/llvm/test/tools/llvm-readobj/COFF/exports-implib.test
index 75d0809ecbb2d05..ee567b2977a3681 100644
--- a/llvm/test/tools/llvm-readobj/COFF/exports-implib.test
+++ b/llvm/test/tools/llvm-readobj/COFF/exports-implib.test
@@ -1,25 +1,25 @@
RUN: llvm-readobj --coff-exports %p/Inputs/library.lib | FileCheck %s
CHECK: File: library.dll
-CHECK: Format: COFF-import-file
+CHECK: Format: COFF-import-file-i386
CHECK: Type: const
CHECK: Name type: undecorate
CHECK: Symbol: __imp__constant
CHECK: File: library.dll
-CHECK: Format: COFF-import-file
+CHECK: Format: COFF-import-file-i386
CHECK: Type: data
CHECK: Name type: noprefix
CHECK: Symbol: __imp__data
CHECK: File: library.dll
-CHECK: Format: COFF-import-file
+CHECK: Format: COFF-import-file-i386
CHECK: Type: code
CHECK: Name type: name
CHECK: Symbol: __imp__function
CHECK: File: library.dll
-CHECK: Format: COFF-import-file
+CHECK: Format: COFF-import-file-i386
CHECK: Type: code
CHECK: Name type: ordinal
CHECK: Symbol: __imp__ordinal
diff --git a/llvm/test/tools/llvm-readobj/COFF/file-headers.test b/llvm/test/tools/llvm-readobj/COFF/file-headers.test
index 6e9ca67c2a65452..b83a6cf5b972b34 100644
--- a/llvm/test/tools/llvm-readobj/COFF/file-headers.test
+++ b/llvm/test/tools/llvm-readobj/COFF/file-headers.test
@@ -320,7 +320,7 @@ symbols:
# RUN: llvm-readobj -h %p/Inputs/magic.coff-importlib \
# RUN: | FileCheck %s --strict-whitespace --match-full-lines --check-prefix IMPORTLIB
-# IMPORTLIB:Format: COFF-import-file
+# IMPORTLIB:Format: COFF-import-file-i386
# IMPORTLIB-NEXT:Type: code
# IMPORTLIB-NEXT:Name type: noprefix
# IMPORTLIB-NEXT:Symbol: __imp__func
diff --git a/llvm/tools/llvm-readobj/COFFImportDumper.cpp b/llvm/tools/llvm-readobj/COFFImportDumper.cpp
index c9d5e82263db111..8aedc310ae3a9fe 100644
--- a/llvm/tools/llvm-readobj/COFFImportDumper.cpp
+++ b/llvm/tools/llvm-readobj/COFFImportDumper.cpp
@@ -23,7 +23,7 @@ namespace llvm {
void dumpCOFFImportFile(const COFFImportFile *File, ScopedPrinter &Writer) {
Writer.startLine() << '\n';
Writer.printString("File", File->getFileName());
- Writer.printString("Format", "COFF-import-file");
+ Writer.printString("Format", File->getFileFormatName());
const coff_import_header *H = File->getCOFFImportHeader();
switch (H->getType()) {
More information about the llvm-commits
mailing list