ObjC ARC `__weak` struct fields are passed by value (`Copy`) instead of the hidden-pointer ABI

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

Maintainer thường phản hồi trong vòng 1 ngày

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

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
50/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c, objective-c, rust
Lĩnh vực
compilers, tooling

Hướng nghiên cứu

Bắt đầu với input.h và tái hiện lệnh gọi bindgen bằng Objective-C ARC trên aarch64-apple-darwin. So sánh định nghĩa W và khai báo takeW được sinh ra với quy ước gọi của Clang cho một struct chứa __weak id. Hoàn tất khi bindgen không còn phát ra chữ ký Copy-by-value không chính xác, mà либо khớp với ABI con trỏ ẩn hoặc từ chối binding đó.

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

Mô tả

Input C/C++ Header
typedef struct objc_object *id;

typedef struct {
    __weak id w;
    int t;
} W;

int takeW(W s, int z);
int takeWp(id p, int t);
id box7(void);
Bindgen Invocation
$ bindgen input.h --no-rustfmt-bindings -- -x objective-c -fobjc-arc
Actual Results

bindgen emits a Copy by-value struct. Layout tests compile (size_of::<W>() == 16).

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct W {
    pub w: id,
    pub t: ::std::os::raw::c_int,
}

unsafe extern "C" {
    pub fn takeW(s: W, z: ::std::os::raw::c_int) -> ::std::os::raw::c_int;
    pub fn takeWp(p: id, t: ::std::os::raw::c_int) -> ::std::os::raw::c_int;
}

An __weak field makes the record nontrivial for calls under ARC. Clang passes takeW indirectly (objc_copyWeak / hidden pointer). rustc passes [2 x i64] in registers.

On Darwin aarch64, s.t = 10, z = 1:

C  takeW(s, 1) = 11    takeWp(o, 10) = 11
Rust takeW(s, 1) = 10    takeWp(o, 10) = 11

The thin __weak id parameter matches. Only the by-value struct disagrees.

This is not #778 (C++ Itanium user-destructor “non-trivial for the purposes of calls”). It is a C struct with an ObjC ARC ownership qualifier. bindgen has no __weak / objc_ownership handling.

Expected Results

A record with an __weak field should not be passed as a Copy by-value argument. Clang’s calling convention for that type is a hidden pointer; the generated signature should match that (or bindgen should refuse to emit a by-value Copy binding).

Environment
bindgen current main: 77cbc72
bindgen:              0.73.1
clang:                Apple clang 21.0.0
rustc:                1.97.1
target:               aarch64-apple-darwin
Ngôn ngữ chính
Rust
Star
5.3k
Fork
846
Merge trung bình
2 ngày 6 giờ
Pull request đã merge (30 ngày)
11

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

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/rust-bindgen

Tất cả issue của rust-lang/rust-bindgen

Issue tương tự

Thêm issue về Rust

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.