Skip to content

[Windows] Wrong ABI when interfacing with C code #28676

Closed

Description

@tomaka

Here is a gist containing the entire source code if you want to reproduce.

When calling the function foo defined like this in C:

typedef struct {
    size_t a;
    size_t b;
    size_t c;
    size_t d;
} Foo;

size_t foo(void* a, void* b, void* c, void* d, Foo f) {
    return f.c;
}

And like this in Rust:

extern {
    fn foo(_: *const libc::c_void, _: *const libc::c_void, _: *const libc::c_void,
           _: *const libc::c_void, _: Foo) -> libc::size_t;
}

You get a crash with the MSVC version of Rust, but the MinGW version works.

This is because apparently the C code expects Foo to actually be a pointer.

If you change the Rust declaration to *const Foo, then it works with the MSVC version and crashes with the MinGW version.

Activity

  1. tomaka commented on Sep 26, 2015

    @tomaka
    ContributorAuthor

    Someone pointed out that this is maybe not a MSVC-related issue.
    I only tested 32 MinGW vs 64 bits MSVC, so maybe it's an issue of 32bits vs 64bits instead of MinGW vs MSVC.

  2. changed the title [-][MSVC] Wrong ABI when interfacing with C code[/-] [+][Windows] Wrong ABI when interfacing with C code[/+] on Sep 26, 2015
  3. retep998 commented on Sep 26, 2015

    @retep998
    Contributor

    Possibly related to #24427

  4. eefriedman commented on Sep 26, 2015

    @eefriedman
    Contributor
  5. added
    O-windows
    on Sep 28, 2015
  6. added a commit that references this issue on Oct 14, 2015
  7. added a commit that references this issue on Oct 15, 2015
    eafe106
  8. added a commit that references this issue on Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    O-windows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions