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

mingw: abi change on recent gcc #9205

Closed
klutzy opened this issue Sep 15, 2013 · 8 comments · Fixed by #14591
Closed

mingw: abi change on recent gcc #9205

klutzy opened this issue Sep 15, 2013 · 8 comments · Fixed by #14591
Labels
A-ffi Area: Foreign Function Interface (FFI) O-windows Operating system: Windows

Comments

@klutzy
Copy link
Contributor

klutzy commented Sep 15, 2013

Win32's cdecl callconv is different from linux's cdecl on returning large structs. For example (from test suite),

struct TwoU64s {
    uint64_t one;
    uint64_t two;
};

TwoU64s rust_dbg_extern_identity_TwoU64s(TwoU64s u) {
    return u;
}

On linux or mingw (gcc <=4.6), the function ends with:

ret    $0x4

This means callee cleans stack for extra space. However, msvc (cl.exe) treats it differently:

ret

then caller is expected to clean 4 bytes.
This implies it will hurt stack if mingw caller calls msvc function.
It is a known issue, and is reported at gcc bugzilla and at mingw.

However, mingw's recent gcc follows win32 convention. (mingw-w64's gcc 4.8 also does.)
This is good for msvc compatibility, however it causes make check-fast failure on latest mingw:

task <unnamed> failed at 'assertion failed: `(left == right) &&
(right == left)`
(left: `t_317::TwoU64s{one: 98784247808u64, two: 257698037760u64}`,
right: `t_317::TwoU64s{one: 22u64, two: 94489280535u64}`)',
C:\home\stone\rust-vanilla\src\test\run-pass\extern-pass-TwoU64s-ref.rs:27
make: *** [i686-pc-mingw32/test/run_pass_stage2_driver-i686-pc-mingw32.out]
Error 101

Relevant codes are: extern-pass-TwoU64s-ref.rs, rust_test_helpers.cpp.

(Well, to build rust with latest mingw, you need some hacks: 1, 2.)

I think we should follow msvc's calling convention on Win32. It implies that we (and bors) have to upgrade mingw later.

vadimcn added a commit to vadimcn/rust that referenced this issue Sep 17, 2013
…change (rust-lang#9205).

These really should have been marked xfail-win32, but that doesn't exist, so xfail-fast it is.
klutzy added a commit to klutzy/rust that referenced this issue Nov 14, 2013
Rename {struct-update,fsu}-moves-and-copies, since win32
failed to run the test since UAC prevents any executable whose
name contaning "update". (rust-lang#10452)

Some tests related to rust-lang#9205 are expected to fail on gcc 4.8,
so they are marked as `xfail-win32` instead of `xfail-fast`.

Some tests using `extra::tempfile` fail on win32 due to rust-lang#10462.
Mark them as `xfail-win32`.
@zokier
Copy link

zokier commented Nov 14, 2013

I tested this with clang and mingw, with bad results. It seems to be broken there too, I submitted bug to llvm. Hopefully anything they are going to do would help us solve our issue too.

https://gist.github.com/zokier/7464584

http://llvm.org/bugs/show_bug.cgi?id=17924

@klutzy
Copy link
Contributor Author

klutzy commented Jan 22, 2014

Seems that LLVM fixed it: http://llvm.org/bugs/show_bug.cgi?id=18034
When this is fixed, buildbot will need mingw update before (#8598) re-enabling tests.

@klutzy
Copy link
Contributor Author

klutzy commented May 22, 2014

We migrated to mingw-w64 with gcc 4.8. needstest!

@klutzy
Copy link
Contributor Author

klutzy commented Jun 2, 2014

@volth I've just downloaded nightly installer and confirmed that it works well on latest mingw (gcc 4.8.1).
Usually the crash happens if wrong mingw dll is chosen. Could you check if your $PATH has other mingw dependency? If you run which libgcc_s_dw-2.dll on msys shell, it should show /mingw/bin/libgcc_s_dw-2.dll, but if you installed other mingw-bundled software (e.g. GHC) it can introduce dll hell.
Also, could you run gdb rustc.exe and type run? If the crash is reproduced, it shows where it goes wrong and backtrace command provides stack trace.

@klutzy
Copy link
Contributor Author

klutzy commented Jun 2, 2014

(If you still have the problem, you'd be better to open new issue; I'm going to close this issue soon since the "abi" issue" is fixed.)

@klutzy
Copy link
Contributor Author

klutzy commented Jun 2, 2014

(Also, we recommend to use mingw-w64 instead of mingw: https://github.com/mozilla/rust/wiki/Using-Rust-on-Windows)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ffi Area: Foreign Function Interface (FFI) O-windows Operating system: Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@zokier @klutzy and others