-
Notifications
You must be signed in to change notification settings - Fork 576
Clarify and test extern abi workaround for variadic function support #3669
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
Conversation
Well, it got closed by adding rust-lang/rust#136946 which is still unstable. So what this PR here does would already have been possible back when #2458 was landed, as far as I can see. Or am I misunderstanding something? |
As |
I think rust-lang/rust#110505 is mostly a misunderstanding, and no work-around was ever required... the error said "must have a compatible calling convention, like You apparently came to the same conclusion though. And what this PR here does is still use "C" for variadics. (The user of the macro must use "C" for them or things won't work. That's already true today before this PR.) So if that is what you mean by work-around then the work-around is still around after this PR, isn't it? |
This has been hard to pin down. @ChrisDenton tried to do this in #3622 and had to revert some of it in #3628. By workarounds I just mean things the |
So the build is clean which means that hardcoding "C" in some cases is not necessary (whether it was ever necessary in the great matrix of things is another question). 🙃 |
Mostly for my own FYI: the remaining discrepancy here is that |
The issue was that currently the windows crates will use a different ABI string depending on the options used (hence I assumed nobody was relying on it). But one thing my initial PR turned up is that people were relying on the specific ABI string even though it doesn't ultimately change the actually used ABI. I would support just using |
Ah, thanks for the reminder - that was the breaking change that @Berrysoft bumped into with storing function pointers. I'll test that here but if that's still an issue I'll probably abandon this change as much as I'd like to remove the workaround. |
Yep, still an issue. Here is a minimal repro for clarity - assume that the definition of windows_link::link!("kernel32.dll" "system" fn GetTickCount() -> u32);
#[cfg(target_arch = "x86")]
type GetTickCountType = unsafe extern "system" fn() -> u32;
#[cfg(target_arch = "x86_64")]
type GetTickCountType = unsafe extern "C" fn() -> u32;
static GET_TICK_COUNT: GetTickCountType = GetTickCount;
#[test]
fn store_ptr() {
unsafe {
GET_TICK_COUNT();
}
} |
I will instead add a more specific test for this scenario and we can remove the workaround in future when we bump the major version of |
No, I think that is fully the right thing to do. I am saying the reason given in the PR description doesn't make sense -- this cannot possibly have anything to do with rust-lang/rust#110505 since nothing changed in the compiler here (except that we made the wording of the error message less confusing). If you try the example from the issue, it still errors. My current theory is that the initial introduction of the hack that replaces the |
The The Either way, Rust requires different syntax depending on the target arch so a macro is still preferable. |
Oh yeah, you need the macro for the different attributes. (Though it could likely be done with a bunch of I was talking only about the part where the macro hard-codes the ABI to "C" on some configurations. I am not aware of anything Rust does (or used to do) that would require this. I am all for removing it (which unfortunately is a breaking change as you noted), and don't understand why it was added. For this PR, it just means that the description should be updated, since the current description does not make logical sense. This has nothing to do with rust-lang/rust#110505 being closed. Nothing changed in the stable compiler to close that issue, we just added an unstable feature you are not using. AFAIK, this exact PR could have been landed in 2023 and would have worked just the same. Or maybe there's some actual change in rustc. But rust-lang/rust#110505 doesn't describe that change, and the PR that closed that issue (rust-lang/rust#119587) cannot be that change. |
Tracking this back a bit, it seems like #3450 just copied the work-around that was originally introduced in #2458. But that just replaced a hard-coded "system" (which, yeah, won't work for variadics) by a hard-coded "C", so we have to go back even further to #2412. But that seems to just move the macros around and deduplicate their implementation. So that brings us all the way back to #2164. There's a comment thread there saying this was a workaround for rust-lang/rust#110505 but that just doesn't check out -- there's no variadics in that PR, and the PR was written half a year before rust-lang/rust#110505 was filed. So the justification seems to be
which isn't quite correct for variadics, and which also doesn't explain why So I think there was some sort of misunderstanding, not documented anywhere publicly I could find, that led to the original hard-coding of "system" here, and since then there've been various adjustments (overwriting with "system" stopped working when variadics got added so it got changed to "C") without ever questioning the original choice of overwriting Put differently, rust-lang/rust#110505 explains #2458 (changing hard-coded "system" to "C"), but doesn't explain #2164 (hard-coding "system" in the first place). |
I've filed #3672 to track entirely getting rid of this work-around. |
Thanks! |
Improve test coverage for extern abi discrepancy.