[llvm] bacc7ae - [Object] Use COFF archive format for import libraries.
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 28 05:29:15 PDT 2023
Author: Jacek Caban
Date: 2023-07-28T14:20:15+02:00
New Revision: bacc7aebb9b902b7edb6c20164cd033d6c162796
URL: https://github.com/llvm/llvm-project/commit/bacc7aebb9b902b7edb6c20164cd033d6c162796
DIFF: https://github.com/llvm/llvm-project/commit/bacc7aebb9b902b7edb6c20164cd033d6c162796.diff
LOG: [Object] Use COFF archive format for import libraries.
This is similar to D143540 for import libraries. ARM64EC will need it
for EC symbol table, but it should be fine for other targets as well
and it improves MSVC compatibility. I left mingw case unchanged to be
safe, although I think that it wouldn't hurt to change that as well.
The visible effect in tests is a sorted symbol map.
Revieved By: mstorsjo
Differential Revision: https://reviews.llvm.org/D156473
Added:
Modified:
lld/test/COFF/export.test
llvm/lib/Object/COFFImportFile.cpp
llvm/test/tools/llvm-dlltool/coff-exports.def
llvm/test/tools/llvm-lib/implibs.test
Removed:
################################################################################
diff --git a/lld/test/COFF/export.test b/lld/test/COFF/export.test
index cbd17c95d87cef..d340e0174b563e 100644
--- a/lld/test/COFF/export.test
+++ b/lld/test/COFF/export.test
@@ -68,10 +68,10 @@ CHECK6-NOT: duplicate /export option: exportfn1
# RUN: llvm-nm -M %t.lib | FileCheck --check-prefix=SYMTAB %s
SYMTAB: __imp_exportfn1 in export.test.tmp.DLL
-SYMTAB: exportfn1 in export.test.tmp.DLL
SYMTAB: __imp_exportfn2 in export.test.tmp.DLL
-SYMTAB: exportfn2 in export.test.tmp.DLL
SYMTAB: __imp_exportfn3 in export.test.tmp.DLL
+SYMTAB: exportfn1 in export.test.tmp.DLL
+SYMTAB: exportfn2 in export.test.tmp.DLL
SYMTAB: exportfn3 in export.test.tmp.DLL
# RUN: lld-link /out:%t.dll /dll %t.obj /export:foo=kernel32.foobar
diff --git a/llvm/lib/Object/COFFImportFile.cpp b/llvm/lib/Object/COFFImportFile.cpp
index a58a444869c871..f20fa9ff6f3230 100644
--- a/llvm/lib/Object/COFFImportFile.cpp
+++ b/llvm/lib/Object/COFFImportFile.cpp
@@ -611,7 +611,7 @@ Error writeImportLibrary(StringRef ImportName, StringRef Path,
}
return writeArchive(Path, Members, /*WriteSymtab*/ true,
- object::Archive::K_GNU,
+ MinGW ? object::Archive::K_GNU : object::Archive::K_COFF,
/*Deterministic*/ true, /*Thin*/ false);
}
diff --git a/llvm/test/tools/llvm-dlltool/coff-exports.def b/llvm/test/tools/llvm-dlltool/coff-exports.def
index df7f0821cc567a..91a7e27ea4720f 100644
--- a/llvm/test/tools/llvm-dlltool/coff-exports.def
+++ b/llvm/test/tools/llvm-dlltool/coff-exports.def
@@ -1,13 +1,16 @@
; RUN: llvm-dlltool -m i386:x86-64 --input-def %s --output-lib %t.a
; RUN: llvm-readobj %t.a | FileCheck %s
+; 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-nm --print-armap %t.a | FileCheck --check-prefix=SYMTAB %s
LIBRARY test.dll
EXPORTS
TestFunction1
TestFunction2;
TestFunction3 ; This is a comment
+AnotherFunction
; CHECK: File: test.dll
; CHECK: Format: COFF-import-file
@@ -21,3 +24,9 @@ TestFunction3 ; This is a comment
; CHECK: Name type: name
; CHECK-NEXT: Symbol: __imp_TestFunction3{{$}}
; CHECK-NEXT: Symbol: TestFunction3{{$}}
+
+; SYMTAB: Archive map
+; SYMTAB: TestFunction1 in test.dll
+; SYMTAB: TestFunction2 in test.dll
+; SYMTAB: TestFunction3 in test.dll
+; SYMTAB: AnotherFunction in test.dll
diff --git a/llvm/test/tools/llvm-lib/implibs.test b/llvm/test/tools/llvm-lib/implibs.test
index e98c158b6f594e..58049261f20a61 100644
--- a/llvm/test/tools/llvm-lib/implibs.test
+++ b/llvm/test/tools/llvm-lib/implibs.test
@@ -13,7 +13,12 @@ CHECK: lib.dll
Test that import libraries can be created from a def file
-RUN: echo -e "NAME lib.dll\nEXPORTS\nMyFunc" > %t/implib.def
+RUN: echo -e "NAME lib.dll\nEXPORTS\nMyFunc\nAnotherFunc" > %t/implib.def
RUN: llvm-lib -out:%t/implib.lib -def:%t/implib.def -machine:x64
RUN: llvm-ar t %t/implib.lib | FileCheck %s
+
+RUN: llvm-nm --print-armap %t/implib.lib | FileCheck --check-prefix=SYMTAB %s
+SYMTAB: Archive map
+SYMTAB-NEXT: AnotherFunc in lib.dll
+SYMTAB-NEXT: MyFunc in lib.dll
More information about the llvm-commits
mailing list