[PATCH] D156473: [Object] Use COFF archive format for import libraries.

Jacek Caban via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 27 11:55:58 PDT 2023


jacek created this revision.
jacek added reviewers: mstorsjo, efriedma, vadikp-intel.
Herald added subscribers: ormris, steven_wu, hiraditya, kristof.beyls.
Herald added a project: All.
jacek requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This is similar to D143540 <https://reviews.llvm.org/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.


https://reviews.llvm.org/D156473

Files:
  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


Index: llvm/test/tools/llvm-lib/implibs.test
===================================================================
--- llvm/test/tools/llvm-lib/implibs.test
+++ llvm/test/tools/llvm-lib/implibs.test
@@ -13,7 +13,12 @@
 
 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
Index: llvm/test/tools/llvm-dlltool/coff-exports.def
===================================================================
--- llvm/test/tools/llvm-dlltool/coff-exports.def
+++ 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 @@
 ; 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
Index: llvm/lib/Object/COFFImportFile.cpp
===================================================================
--- llvm/lib/Object/COFFImportFile.cpp
+++ llvm/lib/Object/COFFImportFile.cpp
@@ -611,7 +611,7 @@
   }
 
   return writeArchive(Path, Members, /*WriteSymtab*/ true,
-                      object::Archive::K_GNU,
+                      MinGW ? object::Archive::K_GNU : object::Archive::K_COFF,
                       /*Deterministic*/ true, /*Thin*/ false);
 }
 
Index: lld/test/COFF/export.test
===================================================================
--- lld/test/COFF/export.test
+++ lld/test/COFF/export.test
@@ -68,10 +68,10 @@
 # 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156473.544875.patch
Type: text/x-patch
Size: 2933 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230727/b984eaec/attachment.bin>


More information about the llvm-commits mailing list