[llvm-dev] lld: sigbus error handling

Mark Kettenis via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 24 05:17:44 PDT 2017


> Date: Mon, 23 Oct 2017 15:21:25 -0700
> From: Rui Ueyama via llvm-dev <llvm-dev at lists.llvm.org>
> 
> If your system does not support fallocate(2), we use ftruncate(2) to create
> an output file. fallocate(2) succeeds even if your disk have less space
> than the requested size, because it creates a sparse file. If you mmap such
> sparse file, you'll receive a SIGBUS when the disk actually becomes full.
> 
> So, lld can die suddenly with SIGBUS when your disk becomes full, and
> currently we are not doing anything about it. It's sometimes hard to notice
> that that was caused by the lack of disk space.
> 
> I wonder if we should print out a hint (e.g. "Bus error -- disk full?")
> when we receive a SIGBUS. Any opinions?

I'm not a huge fan of catching "fatal" signals like this.  It tends to
make debugging more difficult as you don't get a core dump anymore.
And since SIGBUS is also generated for unaligned access that is
somewhat annoying.

If you go this route, please realize that:

* Some systems actually generate SIGSEGV in this scenario.

* You can only call functions that are async-signal safe.  Hight-level
  output functions (stdio, iostream) are almost certainly not
  async-signal safe.

* You may be able to distinguish a SIGBUS caused by unaligned access
  from the "disk-full" case by looking at siginfo, but beware of
  portability issues there.

* You probably only want to install the handler on systems that lack
  fallocate(2).

I think you present a compelling reason to implement fallocate(2) on
OpenBSD.

Cheers,

Mark


More information about the llvm-dev mailing list