From a2e8394997b99ca803f72b5322afcc3a63421082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 9 Jan 2026 10:24:42 +0200 Subject: [PATCH] [LLD] [MinGW] Add the --fat-lto-objects flag (#174962) This uses the same syntax as the ELF linker (added in 14e3bec8fc3e1f10c3dc57277ae3dbf9a4087b1c), mapping it to the recently added COFF linker flag in 759fb0a224e85c01fffcd42b1e71a4bea6fc757e. --- lld/MinGW/Driver.cpp | 4 ++++ lld/MinGW/Options.td | 8 ++++++++ lld/test/MinGW/driver.test | 9 ++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp index 156902649cde..70639573b397 100644 --- a/lld/MinGW/Driver.cpp +++ b/lld/MinGW/Driver.cpp @@ -518,6 +518,10 @@ bool link(ArrayRef argsArr, llvm::raw_ostream &stdoutOS, add("-thinlto-object-suffix-replace:" + StringRef(arg->getValue())); if (auto *arg = args.getLastArg(OPT_thinlto_prefix_replace_eq)) add("-thinlto-prefix-replace:" + StringRef(arg->getValue())); + if (args.hasFlag(OPT_fat_lto_objects, OPT_no_fat_lto_objects, false)) + add("-fat-lto-objects"); + else + add("-fat-lto-objects:no"); for (auto *a : args.filtered(OPT_plugin_opt_eq_minus)) add("-mllvm:-" + StringRef(a->getValue())); diff --git a/lld/MinGW/Options.td b/lld/MinGW/Options.td index e6cf48e685b7..66643be562d3 100644 --- a/lld/MinGW/Options.td +++ b/lld/MinGW/Options.td @@ -39,6 +39,11 @@ multiclass B { def no_ # NAME: Flag<["--", "-"], "no-" # name>, HelpText; } +multiclass BB { + def NAME: Flag<["--"], name>, HelpText; + def no_ # NAME: Flag<["--"], "no-" # name>, HelpText; +} + multiclass B_disable { def NAME: Flag<["--", "-"], name>, HelpText; def disable_ # NAME: Flag<["--", "-"], "disable-" # name>, HelpText; @@ -166,6 +171,9 @@ def lto_emit_asm: FF<"lto-emit-asm">, HelpText<"Emit assembly code">; def lto_sample_profile: JJ<"lto-sample-profile=">, HelpText<"Sample profile file path">; +defm fat_lto_objects: BB<"fat-lto-objects", + "Use the .llvm.lto section, which contains LLVM bitcode, in fat LTO object files to perform LTO.", + "Ignore the .llvm.lto section in relocatable object files (default).">; def thinlto_cache_dir: JJ<"thinlto-cache-dir=">, HelpText<"Path to ThinLTO cached object file directory">; diff --git a/lld/test/MinGW/driver.test b/lld/test/MinGW/driver.test index ef03c01dd038..e3332a456c2a 100644 --- a/lld/test/MinGW/driver.test +++ b/lld/test/MinGW/driver.test @@ -430,7 +430,7 @@ RUN: ld.lld -### foo.o -m i386pe --thinlto-prefix-replace=_foo 2>&1 | FileCheck THINLTO_PREFIX_REPLACE: -thinlto-prefix-replace:_foo RUN: ld.lld -### foo.o -m i386pep -plugin-opt=mcpu=x86-64 -plugin-opt=-emulated-tls -plugin-opt=thinlto -plugin-opt=O2 -plugin-opt=dwo_dir=foo -plugin-opt=cs-profile-generate -plugin-opt=cs-profile-path=bar 2>&1 | FileCheck -check-prefix=LTO_OPTS %s -LTO_OPTS: -mllvm:-mcpu=x86-64 -opt:lldlto=2 -dwodir:foo -lto-cs-profile-generate -lto-cs-profile-file:bar -mllvm:-emulated-tls +LTO_OPTS: -mllvm:-mcpu=x86-64 -opt:lldlto=2 -dwodir:foo -lto-cs-profile-generate -lto-cs-profile-file:bar -fat-lto-objects:no -mllvm:-emulated-tls RUN: ld.lld -### foo.o -m i386pep --lto-O2 --lto-CGO1 --lto-cs-profile-generate --lto-cs-profile-file=foo 2>&1 | FileCheck -check-prefix=LTO_OPTS2 %s LTO_OPTS2:-opt:lldlto=2 -opt:lldltocgo=1 -lto-cs-profile-generate -lto-cs-profile-file:foo @@ -478,3 +478,10 @@ WARN_RPATH: warning: parameter -{{-?}}rpath has no effect on PE/COFF targets RUN: ld.lld -### foo.o -m i386pe --dependent-load-flag=0x800 2>&1 | FileCheck -check-prefix=DEPENDENT_LOAD_FLAG %s DEPENDENT_LOAD_FLAG: -dependentloadflag:0x800 + +RUN: ld.lld -### -m i386pep foo.o 2>&1 | FileCheck -check-prefix NO-FAT-LTO %s +RUN: ld.lld -### -m i386pep foo.o --fat-lto-objects --no-fat-lto-objects 2>&1 | FileCheck -check-prefix NO-FAT-LTO %s +NO-FAT-LTO: -fat-lto-objects:no + +RUN: ld.lld -### -m i386pep foo.o --no-fat-lto-objects --fat-lto-objects 2>&1 | FileCheck -check-prefix FAT-LTO %s +FAT-LTO: -fat-lto-objects{{ }}