在 2021-08-04 05:56, Jeremy Drake via Mingw-w64-public 写道:
On Wed, 4 Aug 2021, Martin Storsjö wrote:

On Tue, 3 Aug 2021, Jeremy Drake wrote:

While debugging this, noticed ruby seems to make *extensive* use of
setjmp/longjmp.  Originally it was trying to use __builtin_setjmp but that
was crashing around the setjmp call (maybe clang's __builtin_setjmp wants
a different size of jmp_buf?).

FWIW, IIRC, __builtin_setjmp is something entirely different from the regular
setjmp/longjmp, maybe related to the SJLJ unwind mechanism, i.e. same
operating principle, but the implementation details are different.


That's what I thought, that it was only for internal use of the
compiler/runtime, so I was very surprised to see ruby prefer to use it if
present, rather than the normal library functions.

`__builtin_setjmp()` and `__builtin_longjmp()` are super tiny constructs that look like their standard counterparts, except that they only restore the SP, BP and PC (IP) registers [1]. Their advantage is that they can be inlined and thus are very fast (neither will result in a function call). The apparent drawback is that they don't restore floating-point environments. In addition, they save and restore the BP register, basing on the assumption that BP is the frame pointer, which is not always the case (e.g. when both occur in the same leaf function and `-fomit-frame-pointer` is in effect) and may cause obscure crashes.


[1] https://gcc.godbolt.org/z/hY1abdeah



--
Best regards,
LIU Hao

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to