Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better working destructors on windows #2663

Merged
merged 2 commits into from
Dec 18, 2023
Merged

Better working destructors on windows #2663

merged 2 commits into from
Dec 18, 2023

Conversation

xTachyon
Copy link
Contributor

Tries to solve #1725 and #2092.

I found that clang can only generate one entry when calling clang_Cursor_getCXXManglings with the Microsoft ABI. Also the conditions for "group 1" destructors don't apply at all on the MS ABI, having a completely different mangling format.

Also, it seems like the entry from clang_Cursor_getCXXManglings will always be the regular "base" destructor that is most interesting usually, while the entry from clang_Cursor_getMangling will always be the "vbase destructor" that's supposed to be able to destroy anything. However, only the base destructor is always available, the other ones being generated on the fly when the code actually needs it.

So far, the code always chose the vbase dtor that happened to never exist, and this is why the code always failed with a link error.

What I wish I figured out how to do was to get the information from clang under which ABI we operate at the moment, but I couldn't find a way to do this, so I just checked if we run under Windows instead. I suspect this might not work well with the MinGW target.

With the main branch unmodified I get one failed test under WSL and over 500 under Windows. I did not see whether I could have Windows only tests, but it looked like a lot of effort to get all tests working under Windows at this point, so I don't know if I could add any tests at the moment.

Here is the manual test I performed. Most usual things seems to work fine, except for classes that use virtual inheritance (the vbase destructor) because it's not the correct destructor to call directly. It seems to crash in a deterministic fashion on my machine from a null pointer access, so it might be fine? This is just trying to make the best of out of a bad situation.

Is there anything I could do make it better? Sorry for the rambly description.

@xTachyon
Copy link
Contributor Author

r? @emilio

@pvdrz
Copy link
Contributor

pvdrz commented Oct 17, 2023

I think this would definitely break cross compilation. You may want to use TargetInfo instead (see https://github.com/rust-lang/rust-bindgen/blob/main/bindgen/ir/context.rs#L562)

@xTachyon
Copy link
Contributor Author

xTachyon commented Oct 18, 2023

There doesn't seem to be any clang_TargetInfo_* to get the ABI, but I figured just checking if the triple contains msvc should be good enough.

Is this better?

@xTachyon
Copy link
Contributor Author

Is this project still alive? @pvdrz

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but can we add a test? Should be able to pass the --target flag, see bindgen-tests/tests/headers/win32-vectorcall-1_0.h for example.

@xTachyon xTachyon requested a review from emilio December 17, 2023 18:32
@emilio emilio merged commit 5ff913a into rust-lang:main Dec 18, 2023
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants