From c23a43f67564704cfb038b28a3ddfe288d455bea Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 19 Dec 2024 10:37:56 -0500 Subject: [PATCH 1/3] [llvm-lib] Add /llvmlibindex:no to disable writing an index This can be used with /llvmlibthin to create thin archives without an index, which is a prerequisite for porting https://reviews.llvm.org/D117284 to lld-link. --- lld/test/COFF/thin-archive.s | 15 ++++++++++++++- llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp | 8 +++++++- llvm/lib/ToolDrivers/llvm-lib/Options.td | 5 +++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lld/test/COFF/thin-archive.s b/lld/test/COFF/thin-archive.s index a35eabed688ce..f2b9e6dda66cf 100644 --- a/lld/test/COFF/thin-archive.s +++ b/lld/test/COFF/thin-archive.s @@ -5,7 +5,20 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-windows-msvc -o %t.lib.obj \ # RUN: %S/Inputs/mangled-symbol.s # RUN: lld-link /lib /out:%t.lib %t.lib.obj -# RUN: lld-link /lib /llvmlibthin /out:%t_thin.lib %t.lib.obj +# RUN: lld-link /lib /llvmlibindex:no /out:%t_noindex.lib %t.lib.obj +# RUN: lld-link /lib /llvmlibthin /llvmlibindex /out:%t_thin.lib %t.lib.obj +# RUN: lld-link /lib /llvmlibthin /llvmlibindex:no \ +# RUN: /out:%t_thin_noindex.lib %t.lib.obj + +# RUN: llvm-nm --print-armap %t.lib \ +# RUN: | FileCheck %s --check-prefix=SYMTAB +# RUN: llvm-nm --print-armap %t_noindex.lib \ +# RUN: | FileCheck %s --check-prefix=NO-SYMTAB +# RUN: llvm-nm --print-armap %t_thin_noindex.lib \ +# RUN: | FileCheck %s --check-prefix=NO-SYMTAB + +# SYMTAB: ?f@@YAHXZ in +# NO-SYMTAB-NOT: ?f@@YAHXZ in # RUN: lld-link /entry:main %t.main.obj %t.lib /out:%t.exe 2>&1 | \ # RUN: FileCheck --allow-empty %s diff --git a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp index 319aebffdbbba..138d9fc7f1d7f 100644 --- a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp +++ b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp @@ -516,8 +516,14 @@ int llvm::libDriverMain(ArrayRef ArgsArr) { std::reverse(Members.begin(), Members.end()); bool Thin = Args.hasArg(OPT_llvmlibthin); + + auto Symtab = Args.hasFlag(OPT_llvmlibindex, OPT_llvmlibindex_no, + /*default=*/true) + ? SymtabWritingMode::NormalSymtab + : SymtabWritingMode::NoSymtab; + if (Error E = writeArchive( - OutputPath, Members, SymtabWritingMode::NormalSymtab, + OutputPath, Members, Symtab, Thin ? object::Archive::K_GNU : object::Archive::K_COFF, /*Deterministic=*/true, Thin, nullptr, COFF::isArm64EC(LibMachine))) { handleAllErrors(std::move(E), [&](const ErrorInfoBase &EI) { diff --git a/llvm/lib/ToolDrivers/llvm-lib/Options.td b/llvm/lib/ToolDrivers/llvm-lib/Options.td index a3d901d77054a..18734d719ec4f 100644 --- a/llvm/lib/ToolDrivers/llvm-lib/Options.td +++ b/llvm/lib/ToolDrivers/llvm-lib/Options.td @@ -28,6 +28,11 @@ def nativedeffile : P<"defArm64Native", "def file to use to generate native ARM6 def llvmlibthin : F<"llvmlibthin">, HelpText<"Make .lib point to .obj files instead of copying their contents">; +def llvmlibindex : F<"llvmlibindex">, + HelpText<"Write an index to the output (default)">; +def llvmlibindex_no : F<"llvmlibindex:no">, + HelpText<"Do not write an index to the output">; + def llvmlibempty : F<"llvmlibempty">, HelpText<"When given no contents, produce an empty .lib file">; From 487050c9966339a1addd713b223cbf262e965cae Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 19 Dec 2024 11:16:03 -0500 Subject: [PATCH 2/3] forgot to test thin lib with index case --- lld/test/COFF/thin-archive.s | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lld/test/COFF/thin-archive.s b/lld/test/COFF/thin-archive.s index f2b9e6dda66cf..55d71ea635673 100644 --- a/lld/test/COFF/thin-archive.s +++ b/lld/test/COFF/thin-archive.s @@ -14,6 +14,8 @@ # RUN: | FileCheck %s --check-prefix=SYMTAB # RUN: llvm-nm --print-armap %t_noindex.lib \ # RUN: | FileCheck %s --check-prefix=NO-SYMTAB +# RUN: llvm-nm --print-armap %t_thin.lib \ +# RUN: | FileCheck %s --check-prefix=SYMTAB # RUN: llvm-nm --print-armap %t_thin_noindex.lib \ # RUN: | FileCheck %s --check-prefix=NO-SYMTAB From fcfcebd4b7cada181159a5864cd0be82ea1948d2 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 19 Dec 2024 12:16:28 -0500 Subject: [PATCH 3/3] comment --- llvm/lib/ToolDrivers/llvm-lib/Options.td | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/llvm/lib/ToolDrivers/llvm-lib/Options.td b/llvm/lib/ToolDrivers/llvm-lib/Options.td index 18734d719ec4f..fbca73aeccd9a 100644 --- a/llvm/lib/ToolDrivers/llvm-lib/Options.td +++ b/llvm/lib/ToolDrivers/llvm-lib/Options.td @@ -28,10 +28,8 @@ def nativedeffile : P<"defArm64Native", "def file to use to generate native ARM6 def llvmlibthin : F<"llvmlibthin">, HelpText<"Make .lib point to .obj files instead of copying their contents">; -def llvmlibindex : F<"llvmlibindex">, - HelpText<"Write an index to the output (default)">; -def llvmlibindex_no : F<"llvmlibindex:no">, - HelpText<"Do not write an index to the output">; +defm llvmlibindex : B<"llvmlibindex", "Write an index to the output (default)", + "Do not write an index to the output">; def llvmlibempty : F<"llvmlibempty">, HelpText<"When given no contents, produce an empty .lib file">;