ABI compatibility for repr(C) structs (and unions)

Đang mở
#626 20 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
backend

Hướng nghiên cứu

Start by comparing the two Miri examples in the issue: identical repr(C) structs with different names behave differently when passed through extern "C". The issue asks whether struct names should affect ABI compatibility and what rules explain the behavior; done means documenting or deciding those rules, which requires unsafe-code and ABI design knowledge.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

I-opsem-nominated

Currently, this code is accepted in miri:

mod m1 {
    unsafe extern "C" {
        pub fn foo(x: Foo);
    }

    #[repr(C)]
    pub struct Foo {
        pub x: i32,
        pub y: i32,
    }
}

mod m2 {
    #[unsafe(no_mangle)]
    extern "C" fn foo(x: Foo) {
        dbg!(x);
    }

    #[repr(C)]
    #[derive(Debug)]
    struct Foo {
        x: i32,
        y: i32,
    }
}

pub fn main() {
    unsafe {
        m1::foo(m1::Foo { x: 5, y: 3 });
    }
}

But it wasn't working in previous versions of miri. If I rename one to Foo2, it no longer works in neither version. To me, it is very surprising that the behavior depends on the name, but I can imagine where it comes from. I didn't find the PR who did this, so I thought it might be a regression somehow. If it is intended, I'm curious about the underlying rules and how it depends on the names.

Ngôn ngữ chính
Không có dữ liệu ngôn ngữ
Star
760
Fork
68
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rust-lang/unsafe-code-guidelines

Tất cả issue của rust-lang/unsafe-code-guidelines

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.