[clang] [lld] [llvm] [llvm][lld][clang] Delay initializing TargetOptions in LTO builds until a Triple is available (PR #179509)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 6 02:03:58 PST 2026


================
@@ -46,16 +46,23 @@ std::string BitcodeCompiler::getThinLTOOutputFile(StringRef path) {
 
 lto::Config BitcodeCompiler::createConfig() {
   lto::Config c;
-  c.Options = initTargetOptionsFromCodeGenFlags();
-  c.Options.EmitAddrsig = true;
+  bool emitAsm = ctx.config.emit == EmitKind::ASM;
+  c.ModifyTargetOptions = [emitAsm](TargetOptions &options) {
+    options.EmitAddrsig = true;
+    // Always emit a section per function/datum with LTO. LLVM LTO should get
+    // most of the benefit of linker GC, but there are still opportunities for
+    // ICF.
+    options.FunctionSections = true;
+    options.DataSections = true;
+
+    if (emitAsm) {
----------------
nikic wrote:

braces

https://github.com/llvm/llvm-project/pull/179509


More information about the cfe-commits mailing list