[lld] [LLD][COFF] Handle --start-lib/--end-lib group in the same way as other archives (PR #136496)

Jacek Caban via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 9 16:08:54 PDT 2025


================
@@ -2172,37 +2173,78 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
     return false;
   };
 
+  // Store start_lib/end_lib arguments in order to render dignostics in the
+  // same way the flags are written on the command line.
+  llvm::opt::Arg *startLibArg = nullptr;
+  llvm::opt::Arg *endLibArg = nullptr;
+  auto endLibSpelling = [&]() {
+    return endLibArg ? endLibArg->getSpelling()
+                     : lld::args::getOptionSpellingLikeArg(
+                           ctx.optTable, OPT_end_lib, startLibArg, ctx.saver);
+  };
+
   // Create a list of input files. These can be given as OPT_INPUT options
   // and OPT_wholearchive_file options, and we also need to track OPT_start_lib
   // and OPT_end_lib.
   {
     llvm::TimeTraceScope timeScope2("Parse & queue inputs");
-    bool inLib = false;
+    std::optional<std::shared_ptr<CmdLineArchive *>> inCmdLineArchive;
+    auto close = [&]() {
+      enqueueTask([=]() {
+        assert(inCmdLineArchive);
+        if (CmdLineArchive *a = **inCmdLineArchive)
+          a->maybeParse();
+      });
+    };
+
     for (auto *arg : args) {
       switch (arg->getOption().getID()) {
       case OPT_end_lib:
-        if (!inLib)
+        if (!inCmdLineArchive) {
           Err(ctx) << "stray " << arg->getSpelling();
-        inLib = false;
+        } else {
+          endLibArg = arg;
+          close();
+          inCmdLineArchive = std::nullopt;
+        }
         break;
       case OPT_start_lib:
-        if (inLib)
+        if (inCmdLineArchive) {
           Err(ctx) << "nested " << arg->getSpelling();
-        inLib = true;
+        } else {
+          startLibArg = arg;
+          inCmdLineArchive = std::make_shared<CmdLineArchive *>();
+          enqueueTask([&, inCmdLineArchive, startLibArg, endLibArg]() {
+            // In is important to create a fake archive here so that we
----------------
cjacek wrote:

```suggestion
            // It is important to create a fake archive here so that we
```

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


More information about the llvm-commits mailing list