[PATCH] D70378: [LLD][COFF] Cover usage of LLD as a library

Alexandre Ganea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 14:42:06 PDT 2020


aganea added a comment.

Thanks for the feedback @MaskRay @grimar!

In D70378#2219292 <https://reviews.llvm.org/D70378#2219292>, @MaskRay wrote:

> I think making `lldMain` "reentrancy safe" is useful.

I have another series of changes to also make it thread-safe, but I'll send out an RFC first, because that requires changes in how `cl::opts` are stored.

> For non-verbose mode, is it possible to suppress output for the first N-1 invocations of `lldMain`?

Done.

> I noticed a problem in `llvm::timeTraceProfilerInitialize`.

You mean the `thread_locals` that are not reinitialized?

> `LLD_IN_TEST=3` is currently set for COFF.
> I wonder whether 2 is sufficient.

Done.



================
Comment at: lld/test/COFF/guardcf-lto.ll:11
 ; RUN: llvm-as %s -o %t.bc
-; RUN: lld-link -entry:main -guard:cf -dll %t.bc %t.lib %t.ldcfg.obj -out:%t.dll
-; RUN: llvm-readobj --coff-load-config %t.dll | FileCheck %s
+; RUN: lld-link -entry:main -guard:cf -dll %t.bc %t.lib %t.ldcfg.obj -out:%t2.dll
+; RUN: llvm-readobj --coff-load-config %t2.dll | FileCheck %s
----------------
MaskRay wrote:
> Why can't `%t.ll` be used?
Because -dll outputs both %t.dll and %t.lib, which happens to also be an input, so the second iteration would fail otherwise.


================
Comment at: lld/tools/lld/lld.cpp:178
+      SaveAndRestore<bool> sr(errorHandler().verbose, true);
+      log("LLD_IN_TEST (new LLD session)");
+    }
----------------
grimar wrote:
> May be I am missing something, but I read it as: you use `SaveAndRestore` to set
> `errorHandler().verbose` to true and restore the value back, because want to bypass
> the check in:
> 
> ```
> void ErrorHandler::log(const Twine &msg) {
>   if (!verbose)
>     return;
>   std::lock_guard<std::mutex> lock(mu);
>   lld::errs() << logName << ": " << msg << "\n";
> }
> ```
> 
> My question: why instead not to use `lld::errs()` directly here?
> E.g:
> 
> ```
> lld::errs() << ErrorHandler::logName <<  ": "LLD_IN_TEST (new LLD session)\n";
> ```
Removed and replaced by what @MaskRay was proposing, ie. only print output for the last iteration.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70378/new/

https://reviews.llvm.org/D70378



More information about the llvm-commits mailing list