[lld] [llvm] [LLD][COFF] Make unresolved symbol search behavior compliant with MSVC link.exe (PR #85290)

Alexandre Ganea via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 16 16:46:05 PDT 2025


================
@@ -2111,25 +2125,38 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
   {
     llvm::TimeTraceScope timeScope2("Parse & queue inputs");
     bool inLib = false;
+    std::optional<std::shared_future<ArchiveFile *>> inLibArchive;
     for (auto *arg : args) {
       switch (arg->getOption().getID()) {
       case OPT_end_lib:
         if (!inLib)
           error("stray " + arg->getSpelling());
         inLib = false;
+        inLibArchive = std::nullopt;
         break;
       case OPT_start_lib:
         if (inLib)
           error("nested " + arg->getSpelling());
         inLib = true;
+        // In is important to create a fake archive here so that we remember its
+        // placement on the command-line. This will be later needed to resolve
+        // symbols in the archive order required by the MSVC specification.
+        {
+          auto a = std::make_shared<std::promise<ArchiveFile *>>();
----------------
aganea wrote:

I did try several things, including what you're suggesting, as well as the [std::bind trick](https://stackoverflow.com/a/12744621), but nothing else works, besides the `share_ptr` above.

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


More information about the llvm-commits mailing list