Open cuviper opened 8 months ago
As far as I know LLVM generally does not try to be exception-safe. It is compiled with -fno-exceptions
by default.
In Fedora we enable LLVM_ENABLE_EH
for unknown reasons -- this seems like a good motivation to disable it and see if anything breaks.
In Fedora we enable
LLVM_ENABLE_EH
for unknown reasons -- this seems like a good motivation to disable it and see if anything breaks.
Hm, no, I misremembered: We use LLVM_ENABLE_RTTI
, not LLVM_ENABLE_EH
.
Whether operator new
throws an exception is determined by whether libstdc++ has been built with -fno-exceptions
, not LLVM.
With that in mind, your idea of catching the exception in allocate_buffer and explicitly aborting sounds reasonable to me.
See #85449.
However, I just noticed that LLVM does have a std::new_handler
that reports too, which should be installed by InitLLVM
-- but Rust doesn't call that. Do you think we should? (rust-lang/rust#79153 looks related)
See #85449.
However, I just noticed that LLVM does have a
std::new_handler
that reports too, which should be installed byInitLLVM
-- but Rust doesn't call that. Do you think we should? (rust-lang/rust#79153 looks related)
Oh, that's a great find! So that's how OOM is supposed to be handled.
I'm not sure we really want everything in InitLLVM, but it looks like we should at least be calling install_out_of_memory_new_handler().
Ref: https://github.com/rust-lang/rust/issues/121305
In that Rust issue, running on an
i686
host, I found thatDenseMap::allocateBuckets
->llvm::allocate_buffer
->operator new
was throwingstd::bad_alloc
. Then when unwinding runs the destructors intoLLVMContextDispose
, we get back intoDenseMapBase::erase
and hitSIGSEGV
, presumably in the same instance that failed allocation.Maybe
allocate_buffer
should catch and callreport_bad_alloc_error
like thesafe_*alloc
functions do? But even so, it seems that some part ofDenseMap
is not exception safe.