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

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 14 15:53:34 PST 2026


================
@@ -43,50 +43,72 @@ static std::string getThinLTOOutputFile(Ctx &ctx, StringRef modulePath) {
                                    ctx.arg.thinLTOPrefixReplaceNew);
 }
 
+static std::shared_ptr<MemoryBuffer> getBBSectionsMemoryBuffer(Ctx &ctx) {
+  if (ctx.arg.ltoBasicBlockSections.empty() ||
+      ctx.arg.ltoBasicBlockSections == "all" ||
+      ctx.arg.ltoBasicBlockSections == "none")
+    return nullptr;
+
+  if (ctx.arg.ltoBasicBlockSections == "labels") {
+    Warn(ctx)
+        << "'--lto-basic-block-sections=labels' is deprecated; Please use "
+           "'--lto-basic-block-address-map' instead";
+    return nullptr;
+  }
+
+  ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr =
+      MemoryBuffer::getFile(ctx.arg.ltoBasicBlockSections.str());
+  if (!mbOrErr) {
+    ErrAlways(ctx) << "cannot open " << ctx.arg.ltoBasicBlockSections << ":"
+                   << mbOrErr.getError().message();
+  }
+  return std::move(*mbOrErr);
+}
+
 static lto::Config createConfig(Ctx &ctx) {
   lto::Config c;
 
----------------
MaskRay wrote:

delete the blank line between c and mbPtr

In lld/ELF, a blank line is added mainly when:

There's a logical break between the declaration block and subsequent code.
Multiple declarations form a cohesive group that sets up state before a distinct block of logic begins.

Most cases don't apply.

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


More information about the cfe-commits mailing list