On 10/7/20 10:52 PM, Liu Hao via Gcc-patches wrote:
[Please CC me as I am not subscribed to this list.]
[This patch is only a draft and has not been tested at all.]

Some details have been discussed in [1]. mingw-w64 has got an implementation 
[2] [3] for static libraries, but it takes a
destructor using the `__thiscall` convention. As both functions have C linkage, 
they should agree with each other and should
behave simliarily.

Hmm, why isn't the mingw implementation used for all programs? That would avoid the bug.

Considerations:

0) This is going to be an ABI breakage for i?86. I am not sure whether people 
would expect the old, broken behavior.

I'm sure they wouldn't.

1) GCC doesn't provide `__cxa_atexit()`, but it would suffer from the same 
problem. At the moment GCC calls `atexit()` to
register destructors so it appears to work.

Yes.

2) There is an explicit reference to `__cxa_atexit` in 'gcc/cp/decl.c' and it 
probably be changed, unless it is not used by
1?86-w64-mingw32 targets.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83562
[2] 
https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/crt/cxa_thread_atexit.c
[3] 
https://sourceforge.net/p/mingw-w64/mingw-w64/ci/f3e0fbb40cbc9f8821db8bd8a0c4dae8ff671e9f/
[4] https://github.com/msys2/MINGW-packages/issues/7071

This patch is a good start but won't actually fix the bug: the calling convention only makes a difference when we actually call the function, at the line

        e->destructor (e->object);

in atexit_thread.cc, and your patch doesn't change the calling convention for elt::destructor.

I'd think we should add the attribute to __cxa_cdtor_type, and use it more consistently for __cxa_*atexit and __cxa_throw.

Jason

Reply via email to