<div dir="ltr">I think the easiest way for you to deal with this will be to redirect FDs 1 and 2 to the NUL device, or to a pipe or wherever you'd like LLVM or any other third party libraries to send their output.</div><br><div class="gmail_quote"><div dir="ltr">On Sun, Sep 9, 2018 at 9:30 AM Janus Lynggaard Thorborg via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hello,<br><div><br></div><div>outs() and errs() are routinely used around llvm and cannot really be disabled. It would seem that in certain types of Windows applications, stderr and stdout are not opened by default, which is an assumption of llvm.</div><div><br></div><div>This leaves errs() and outs() with an error code, because writing calls will fail due to invalid fd handles. Thus, when an llvm lib is unloaded, it will terminate the entire process due to a non-zero EC in ~raw_fd_ostream() that calls report_fatal_error().</div><div><br></div><div>It doesn't help that outs(), errs() etc. are not returning raw_fd_ostream, so you cannot clear the error codes manually (without dynamic_cast):</div><div><br><div><font face="monospace, monospace">struct LLVMCleanup</font></div><div><font face="monospace, monospace">{</font></div><div><font face="monospace, monospace">    ~LLVMCleanup()</font></div><div><font face="monospace, monospace">    {</font></div><div><font face="monospace, monospace">        for (auto stream : {&llvm::errs(), &llvm::outs()})</font></div><div><font face="monospace, monospace">        {</font></div><div><span style="font-family:monospace,monospace">   </span><span style="font-family:monospace,monospace"> </span><span style="font-family:monospace,monospace">   </span><span style="font-family:monospace,monospace"> </span><span style="font-family:monospace,monospace">   </span><span style="font-family:monospace,monospace"> </span><span style="font-family:monospace,monospace">if (auto fdStream = dynamic_cast<llvm::raw_fd_ostream*>(stream))</span></div><div><span style="font-family:monospace,monospace">   </span><span style="font-family:monospace,monospace"> </span><span style="font-family:monospace,monospace">   </span><span style="font-family:monospace,monospace"> </span><span style="font-family:monospace,monospace">   </span><span style="font-family:monospace,monospace"> </span><span style="font-family:monospace,monospace">   </span><span style="font-family:monospace,monospace"> </span><span style="font-family:monospace,monospace">fdStream->clear_error();</span></div><div><span style="font-family:monospace,monospace">   </span><span style="font-family:monospace,monospace"> </span><span style="font-family:monospace,monospace">   </span><span style="font-family:monospace,monospace"> </span><span style="font-family:monospace,monospace">}</span></div><div><span style="font-family:monospace,monospace">   </span><span style="font-family:monospace,monospace"> </span><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace">};</font></div></div><div><br></div><div>Above is my currently working fix (if I sprinkle it in enough places) but it is a pretty fragile solution. Is there some special initialization or handling that I'm missing? My program is itself a dynamic lib, so I don't control state of stderr or stdout. I would rather not terminate my host process because diagnostic prints failed.<br><br>Thanks - and regards, </div><div>Janus</div></div></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>