From 9d477ab892a720f8920abf397438da1f0d43baf0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 21 Oct 2019 16:15:34 +0200 Subject: Work around LLD bug #43744 --- libbuild2/cc/link-rule.cxx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libbuild2/cc/link-rule.cxx b/libbuild2/cc/link-rule.cxx index 71d609d..528d67f 100644 --- a/libbuild2/cc/link-rule.cxx +++ b/libbuild2/cc/link-rule.cxx @@ -2717,6 +2717,7 @@ namespace build2 // The same logic as during hashing above. See also a similar loop // inside append_libraries(). // + bool seen_obj (false); for (const prerequisite_target& p: t.prerequisite_targets[a]) { const target* pt (p.target); @@ -2743,7 +2744,10 @@ namespace build2 if (la || ls) append_libraries (sargs, *f, la, p.data, bs, a, li); else + { sargs.push_back (relative (f->path ()).string ()); // string()&& + seen_obj = true; + } } } @@ -2752,6 +2756,25 @@ namespace build2 if (!manifest.empty () && tsys == "mingw32") sargs.push_back (relative (manifest).string ()); + // LLD misses an input file if we are linking only whole archives (LLVM + // bug #43744). Repeating one of the previously-mentioned archives seems + // to work around the issue. + // + if (!seen_obj && + !lt.static_library () && + tsys == "win32-msvc" && + cast (rs["bin.ld.id"]) == "msvc-lld") + { + auto i (find_if (sargs.rbegin (), sargs.rend (), + [] (const string& a) + { + return a.compare (0, 14, "/WHOLEARCHIVE:") == 0; + })); + + if (i != sargs.rend ()) + sargs.push_back (i->c_str () + 14); + } + // Shallow-copy sargs over to args. // append_args (sargs); -- cgit v1.1