ahgamut / superconfigure

wrap autotools configure scripts to build with Cosmopolitan Libc
The Unlicense
159 stars 22 forks source link

gcc: Enable SJLJ exceptions #19

Closed trungnt2910 closed 6 months ago

trungnt2910 commented 6 months ago

This would enable unwind functionality for cosmo programs without having to embed additional information in the binaries.

Thanks to @codehz for the suggestion.

ahgamut commented 6 months ago

Do make o/compiler/x86_64-gcc/built.fat and make o/compiler/aarch64-gcc/built.fat work without issue?

trungnt2910 commented 6 months ago

make x86_64-gcc and make aarch64-gcc, which include the targets you mentioned, worked without issues.

ahgamut commented 6 months ago

Nice. Thank you!

jart commented 6 months ago

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?

trungnt2910 commented 6 months ago

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):

ahgamut commented 6 months ago

@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)?

codehz commented 6 months ago

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 commented 6 months ago

@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.

trungnt2910 commented 6 months ago

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:

https://github.com/llvm/llvm-project/blob/4daea501c4fc969bc6d8baafe646487ae1881aab/libunwind/src/config.h#L114

jart commented 6 months ago

Your plan sounds good to me @trungnt2910. I'm happy to help review runtime changes.