ObjC ARC `__weak` struct fields are passed by value (`Copy`) instead of the hidden-pointer ABI
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 50/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- c, objective-c, rust
Research direction
Start with input.h and reproduce the bindgen invocation using Objective-C ARC on aarch64-apple-darwin. Compare the generated W definition and takeW declaration with Clang's calling convention for a struct containing __weak id. Done means bindgen no longer emits an incorrect Copy by-value signature, either matching the hidden-pointer ABI or refusing that binding.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 846
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 11
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rust-lang/rust-bindgen
-
--enable-cxx-namespaces panics on namespace [[deprecated]] { ("[" is not a valid Ident)Possibly taken @lwz23 claimed this 47 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
rust-lang/rust-bindgen#3485 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rust-lang/rust-bindgen#3483 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
rust-lang/rust-bindgen#3370 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
rust-lang/rust-bindgen#3363 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
rust-lang/rust-bindgen#3540 ·
Maintainers usually reply within 1 day
All issues in rust-lang/rust-bindgen
Similar issues
-
yara-x fails to build with rsa 0.10.0: unresolved import rsa::Pkcs1v15SignPossibly taken @CfirTsabari claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 87/100
VirusTotal/yara-x#865 ·
Maintainers usually reply within 1 day
-
good first issue help wanted program
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
hffgzktbcc-blip/ounce-core#297 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nautechsystems/nautilus_trader#5631 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
bytecodealliance/rustix#1736 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
longbridge/gpui-kit#3871 ·
Maintainers usually reply within 1 day