<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Oct 23, 2017 at 6:48 PM, Brian Cain <span dir="ltr"><<a href="mailto:brian.cain@gmail.com" target="_blank">brian.cain@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Mon, Oct 23, 2017 at 8:40 PM, Andrew Kelley via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Mon, Oct 23, 2017 at 9:30 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On Mon, Oct 23, 2017 at 5:28 PM, Andrew Kelley <span dir="ltr"><<a href="mailto:superjoe30@gmail.com" target="_blank">superjoe30@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">For Zig we use LLD as a library. So for us it would be better to avoid global state such as SIGBUS (or any other signal handlers), instead returning an error from the link function when linking fails. If lld can encapsulate this signal handling and prevent the application using lld from getting the signal directly, instead carefully handling the signal in LLD itself and translating it into a proper error code or message, this would be reasonable.</div></blockquote><div><br></div></span><div>Signal handlers and signal masks are inherently process-wide, so there's no way to encapsulate them to lld functions. So my plan is to change the name of lld::{coff,elf}::link's `ExitEarly` parameter to `IsStandalone`, and we (not only call exit(2) but also) set a signal handler only when the argument is true. Since library users pass false to the parameter, it shouldn't change the behavior of lld for the library use case.</div></div></div></div></blockquote><div><br></div></span><div>This sounds good to me.</div><div><br></div><div>And then if an application wants to handle the SIGBUS correctly, it would have to register this signal handler to report the error?</div><span><div> </div><div><br></div></span></div></div></div></blockquote><div><br></div></span><div>It's hard to imagine a "correct" handling for a bus error.  But reporting the error seems like a good idea.  Keeping in mind the fact that there's very limited things you can do from a signal handler.  See signal(7) for details.</div></div></div></div></blockquote><div><br></div><div>Exactly. What I was thinking is to call `write(STDERR_FILENO, "Bus error -- disk full?\n",...)` and then call `_exit` when a SIGBUS is raised.</div></div></div></div>