<div dir="ltr"><div dir="ltr">On Thu, Apr 15, 2021 at 9:30 PM Fangrui Song via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 2021-04-15, Manoj Gupta via llvm-dev wrote:<br>
>LLD reproducers is something we'd like to have in Chrome OS as well, see<br>
>bug <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=1134940" rel="noreferrer" target="_blank">https://bugs.chromium.org/p/chromium/issues/detail?id=1134940</a> (no<br>
>activity yet).<br>
>Our plan is to create a shell wrapper and re-exec LLD if needed with<br>
>--reproduce. Obviously, if LLD supports creating reproducers natively,<br>
>that'd be great!<br>
><br>
>-Manoj<br>
<br>
The crash report can be easily implemented via a shell script, but is difficult<br>
to implementat reliably in the process itself.  When a process crashes,<br>
naturally not everything can work very robustly. The process wants to recover<br>
some state and starts a .tar writer, collects every touched file and places<br>
them in the .tar writer. There are many steps things can go afoul. I am<br>
worrying about the robustness. Of course, this may be solved by a multiprocess<br>
architecture, but I am not sure we want to pay the complexity in the LLD<br>
entrypoint itself.<br></blockquote><div><br></div><div>I'm hoping that we could reuse llvm::CrashRecoveryContext just like Clang does without needing multi-process architecture. Furthermore, we might be able to extract some of the common infrastructure from Clang to LLVM and then use it in lld. Clang has already solved this so there's no need to duplicate the effort.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
(Crashing LLD is not the idea I hear a lot. For some groups it has been very stable.<br>
The crashes are more frequently from some optimizations triggered by llvm/lib/LTO.<br>
The nature of the crashes is useful, if Fuchsia/ChromeOS folks would like to provide.)<br>
<br>
On the other hand, this task seems to require a fair amount of customization to<br>
me.  First we have the tarball size problem. Then say there is a common crash<br>
and 100 links of a similar kind crash at the same time, do we write 100<br>
tarballs?  In a controlled environment, for example when there is some<br>
deduplicater or throttling this may be feasible. The output filename may want<br>
customization as well, and different groups may have different opinions.  It<br>
feels to me that a script, whether or not LLD has the built-in crash reporting<br>
feature, is indispensable. Then the built-in C++ crash reporter code in LLD<br>
does not convince me.<br></blockquote><div><br></div><div>I cannot speak for others, but at least in our case we are usually limited by the available memory and on the machines we have we can only run single to low double digit of link jobs in parallel. We also never had this issue with Clang and we usually run hundreds of parallel jobs.</div><div><br></div><div>Regarding the output name, I'd again take an inspiration from Clang and simply use a temporary filename generated by llvm::sys::fs::createTemporaryFile. That way we don't need to worry about two failing link jobs trying to write to the same file. We never needed the customization for Clang and I doubt we will for lld.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
>On Thu, Apr 15, 2021 at 11:23 AM David Blaikie via llvm-dev <<br>
><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
>> On Thu, Apr 15, 2021 at 1:37 AM Petr Hosek via llvm-dev<br>
>> <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
>> ><br>
>> > lld crashes are more rare, but they do happen. For example, we see lld<br>
>> segfaulting occasionally on our bots. I'd like to fix it, but I don't know<br>
>> how to reproduce this issue because we never managed to reproduce it<br>
>> locally. This is primarily where the motivation for this feature came from.<br>
>> In the case of Clang, we already configure our build to generate<br>
>> reproducers in a dedicated directory and at the end of the build we upload<br>
>> its content to a dedicated (short lived) storage bucket. We would like to<br>
>> do the same with lld and if this feature existed, we would use it in our<br>
>> build.<br>
>> ><br>
>> > The size of the reproducers is not really an issue; even if they are a<br>
>> few gigabytes, they're still dwarfed by the size of the debug info, at<br>
>> least in our build.<br>
>> ><br>
>> > Passing -Wl,--reproduce is something a compiler engineer can do when<br>
>> debugging an issue locally, but it's not something a bot can do. Even most<br>
>> developers on our team wouldn't know how to do it which is why the<br>
>> automatic crash reproducer generation in Clang is so valuable, all that<br>
>> developers need to do is to follow the instructions without having to<br>
>> modify the build and we've had great success with it in the case of Clang.<br>
>><br>
>> Probably would help (if this isn't done already) this part at least<br>
>> (ie: users who don't have this newly proposed feature enabled) if<br>
>> lld's crash reporter printed the command line to run with the extra<br>
>> flag "to reproduce this run <this command>" for discoverability?<br>
>><br>
>> (not to derail the primary discussion on this thread, which I don't<br>
>> have much opinion on)<br>
>><br>
>> > I'm leaning towards the second option, that is implementing this feature<br>
>> directly in lld. The reason is that we most often see lld crashes when<br>
>> linking Rust code. If we implemented this feature in the Clang driver, we<br>
>> would also need to do the same inside the Rust driver (and any other<br>
>> compiler driver that supports lld). If we implement it in lld, we only need<br>
>> to do it once, so it's more universal.<br>
>> ><br>
>> > On Wed, Apr 14, 2021 at 3:40 PM Fāng-ruì Sòng via llvm-dev <<br>
>> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
>> >><br>
>> >> On Wed, Apr 14, 2021 at 3:27 PM Haowei Wu <<a href="mailto:haowei@google.com" target="_blank">haowei@google.com</a>> wrote:<br>
>> >> ><br>
>> >> > > I am skeptical that users will want to have this behavior by<br>
>> default.<br>
>> >> > > If this behavior is guarded by an option, it might be fine.<br>
>> >> ><br>
>> >> > That's a good point. If the reproducer will be more than a few<br>
>> hundreds MiBs, it is definitely not suitable to be enabled by default. I<br>
>> agree it's better to be guarded by an option flag such as<br>
>> `--gen-lld-crash-reproducer`.<br>
>> >> ><br>
>> >> > On Wed, Apr 14, 2021 at 2:40 PM Fangrui Song <<a href="mailto:maskray@google.com" target="_blank">maskray@google.com</a>><br>
>> wrote:<br>
>> >> >><br>
>> >> >><br>
>> >> >> On 2021-04-14, Haowei Wu via llvm-dev wrote:<br>
>> >> >> >*Background / Motivation*<br>
>> >> >> ><br>
>> >> >> >Both clang and lld have the ability to generate a reproducer (an<br>
>> archive<br>
>> >> >> >with input files and invoker script to reproduce the clang/lld<br>
>> build).<br>
>> >> >> >While clang will generate a reproducer archive when a crash<br>
>> happens, lld<br>
>> >> >> >only generates a reproducer when '--reproduce' flag is explicitly<br>
>> set (this<br>
>> >> >> >is equivalent to Clang's -gen-reproducer flag). This is not very<br>
>> helpful<br>
>> >> >> >for debugging lld bugs, particularly when the crash happens in<br>
>> building big<br>
>> >> >> >projects, since it will be unrealistic to set reproducer flags to<br>
>> generate<br>
>> >> >> >reproducer archives for every lld invocation. This design also<br>
>> causes<br>
>> >> >> >troubles when the crash happens on bots only, as in most cases,<br>
>> developers<br>
>> >> >> >do not have access to the file system of these bots. It would be<br>
>> great to<br>
>> >> >> >improve the lld reproducer generation for easier debugging in these<br>
>> >> >> >scenarios.<br>
>> >> >> ><br>
>> >> >> >*Proposal*<br>
>> >> >> ><br>
>> >> >> >Given the use cases and status of clang and lld. I think there are 2<br>
>> >> >> >possible solutions.<br>
>> >> >> ><br>
>> >> >> >*Extend Clang driver*<br>
>> >> >> >In most cases, lld is invoked by the clang driver instead of being<br>
>> invoked<br>
>> >> >> >by the build system directly. Therefore, the clang driver can be<br>
>> changed to<br>
>> >> >> >re-invoke lld with '--reproduce' flags when it detects the lld<br>
>> subprocess<br>
>> >> >> >is crashed.<br>
>> >> >> ><br>
>> >> >> >Advantages:<br>
>> >> >> >    * It probably does not require any changes to the lld and might<br>
>> be<br>
>> >> >> >easier than handling the crash directly in lld.<br>
>> >> >> ><br>
>> >> >> >Disadvantages:<br>
>> >> >> >    * In case when there is a racing condition in the build system,<br>
>> the<br>
>> >> >> >input files might have changed between 1st lld crash and 2nd lld<br>
>> rerun with<br>
>> >> >> >'--reproduce' flag. In this case, the generated lld reproducer<br>
>> archive<br>
>> >> >> >might not be able to trigger a crash, makes it less useful.<br>
>> >> >> ><br>
>> >> >> >*Improve lld reproducer*<br>
>> >> >> >Another way would be to make lld generate a reproducer archive when<br>
>> it<br>
>> >> >> >crashes, just like what clang is doing.<br>
>> >> >> ><br>
>> >> >> >Advantages:<br>
>> >> >> >    * It will work no matter if lld is invoked from Clang or from<br>
>> the build<br>
>> >> >> >system.<br>
>> >> >> >    * It will catch the input file in case the crash is caused by<br>
>> build<br>
>> >> >> >races.<br>
>> >> >> ><br>
>> >> >> >Disadvantages:<br>
>> >> >> >    * It might need a lot of work if lld does not already have a<br>
>> >> >> >sophisticated crash handler. It might still need some plumbing<br>
>> changes in<br>
>> >> >> >clang driver so lld can honor the '-fcrash-diagnostic-dir' flag.<br>
>> >> >> ><br>
>> >> >> >*Comments?*<br>
>> >> >> >Which approach do you prefer? Feel free to share your opinions.<br>
>> >> >><br>
>> >> >> There is a resource difference between clang -gen-reproducer /<br>
>> >> >> environment variable "FORCE_CLANG_DIAGNOSTICS_CRASH" and ld.lld<br>
>> --reproduce.<br>
>> >> >><br>
>> >> >> clang -gen-reproducer produces a source file and a .sh file for one<br>
>> >> >> single translation unit, the space consumption is low.<br>
>> >> >> ld.lld --reproduce can potentially pack a large list of files, which<br>
>> may<br>
>> >> >> take hundreds of megabytes or several gigabytes.<br>
>> >> >><br>
>> >> >> I am skeptical that users will want to have this behavior by default.<br>
>> >> >> If this behavior is guarded by an option, it might be fine.<br>
>> >><br>
>> >> I'll retract my words about an option. This behavior looks like it<br>
>> >> needs a fair bit of customization and is build system dependent.<br>
>> >> You can replace the proposed option with a shell script wrapper, which<br>
>> >> is more convenient than implementing the restartable action in the<br>
>> >> clang driver.<br>
>> >> When dealing with linker problems, (I doubt there are many nowadays;<br>
>> >> when there are problems, mostly are LTO problems), I will usually<br>
>> >> change compiler/linker options a bit.<br>
>> >> If you do this, you may only specify the proposed option when all the<br>
>> >> stuff has been done, but then it is only a very small extra step to<br>
>> >> invoke the link again with -Wl,--reproduce.<br>
>> >> _______________________________________________<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
>> ><br>
>> > _______________________________________________<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
>> _______________________________________________<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
>><br>
<br>
>_______________________________________________<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
_______________________________________________<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>