Closed trungnt2910 closed 6 months ago
Do make o/compiler/x86_64-gcc/built.fat
and make o/compiler/aarch64-gcc/built.fat
work without issue?
make x86_64-gcc
and make aarch64-gcc
, which include the targets you mentioned, worked without issues.
Nice. Thank you!
This will be potentially useful for llamafile since the llama.cpp web server wants c++ exceptions very badly and people have filed many bugs about how it crashes when they misformat their OpenAI API JSON request. What steps do I have to take to be able to use this?
Support for C++ exceptions is a collaboration between the compiler (so that it could convert try
/catch
blocks into magic function calls) and the runtime library (which provides the functions themselves).
I'm currently sponsored to bring C++ exceptions support to cosmo, so I'm giving this task a high(er) priority; some progress could be seen in the near future. Any help and PR reviews are appreciated.
The intended steps are (not really happening sequentially):
libunwind
(low-level unwinding functions, see https://github.com/jart/cosmopolitan/pull/1053. I will fix the build errors there soon).libcxxabi
(higher-level C++-specific exception support functions (_cxa_*
) and RTTI support classes).cosmocc
and related files to allow exceptions. It might be desirable to keep -fno-exceptions
the default to reduce the binary size, but after having the suitable runtime libraries we might be able to allow -fexceptions
in cosmocc
instead of outright rejecting it.@trungnt2910 does building libunwind
require gcc
to have --enable-sjlj-exceptions
or is it just the use of libunwind
? The related question is: are you able to build libunwind
successfully with the vendored x86_64-linux-musl-gcc
(without using the compilers built here)?
Finally I found sjlj is required for objc's exception without libunwind, it is not required for build libunwind with sjlj support... to use sjlj in libunwind, you need to configure libunwind to use sjlj model, not gcc itself
@trungnt2910 does building libunwind require gcc to have --enable-sjlj-exceptions or is it just the use of libunwind?
Building libunwind
might succeed without __USING_SJLJ_EXCEPTIONS__
, but we would need a valid .eh_frame
section embedded in the APE for other kinds of unwinding to work.
you need to configure libunwind to use sjlj model, not gcc itself
Actually, no. libunwind
uses the sjlj model when it detects the __USING_SJLJ_EXCEPTIONS__
macro, pre-defined in all gcc
builds with sjlj
enabled:
Your plan sounds good to me @trungnt2910. I'm happy to help review runtime changes.
This would enable unwind functionality for cosmo programs without having to embed additional information in the binaries.
Thanks to @codehz for the suggestion.