Index: lld/ELF/Config.h =================================================================== --- lld/ELF/Config.h +++ lld/ELF/Config.h @@ -16,6 +16,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/BinaryFormat/ELF.h" +#include "llvm/LTO/LTO.h" #include "llvm/Support/CachePruning.h" #include "llvm/Support/CodeGen.h" #include "llvm/Support/Endian.h" @@ -358,6 +359,8 @@ // this means to map the primary and thread stacks as PROT_MTE. Note: This is // not supported on Android 11 & 12. bool androidMemtagStack; + // When using a unified pre-link LTO pipeline, specify the backend LTO mode. + llvm::lto::LTO::LTOKind forceLTOMode = llvm::lto::LTO::LTOK_Default; }; // The only instance of Configuration struct. Index: lld/ELF/Driver.cpp =================================================================== --- lld/ELF/Driver.cpp +++ lld/ELF/Driver.cpp @@ -1317,6 +1317,19 @@ for (auto *arg : args.filtered(OPT_mllvm)) parseClangOption(arg->getValue(), arg->getSpelling()); + config->forceLTOMode = llvm::lto::LTO::LTOK_Default; + if (auto *arg = args.getLastArg(OPT_lto_type_eq)) { + StringRef s = arg->getValue(); + if (s == "thin") + config->forceLTOMode = llvm::lto::LTO::LTOK_UnifiedThin; + else if (s == "full") + config->forceLTOMode = llvm::lto::LTO::LTOK_UnifiedRegular; + else if (s == "default") + config->forceLTOMode = llvm::lto::LTO::LTOK_Default; + else + error("unknown LTO mode: " + s); + } + // --threads= takes a positive integer and provides the default value for // --thinlto-jobs=. if (auto *arg = args.getLastArg(OPT_threads)) { Index: lld/ELF/LTO.cpp =================================================================== --- lld/ELF/LTO.cpp +++ lld/ELF/LTO.cpp @@ -201,7 +201,8 @@ } ltoObj = std::make_unique(createConfig(), backend, - config->ltoPartitions); + config->ltoPartitions, + config->forceLTOMode); // Initialize usedStartStop. if (bitcodeFiles.empty()) Index: lld/ELF/Options.td =================================================================== --- lld/ELF/Options.td +++ lld/ELF/Options.td @@ -541,6 +541,9 @@ def: Flag<["-"], "V">, Alias, HelpText<"Alias for --version">; // LTO-related options. + +def lto_type_eq: J<"lto=">, HelpText<"Set LTO backend">, + MetaVarName<"[full,thin]">; def lto_aa_pipeline: JJ<"lto-aa-pipeline=">, HelpText<"AA pipeline to run during LTO. Used in conjunction with -lto-newpm-passes">; def lto_debug_pass_manager: FF<"lto-debug-pass-manager">,