rust-lang / rust-lang/rust-bindgen

objc_direct methods are emitted as msg_send! instead of a direct C call

Open
#3,473 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Input C/C++ Header
__attribute__((objc_root_class))
@interface Foo {
    Class isa;
}
- (int)bar:(int)x __attribute__((objc_direct));
@end
Bindgen Invocation
$ bindgen input.h -- -x objective-c -fobjc-arc
Actual Results

bindgen 0.72.1 and 0.73.1 both emit an objc::msg_send! wrapper:

unsafe fn bar_(&self, x: c_int) -> c_int {
    msg_send!(*self, bar: x)
}

Clang compiles an objc_direct method as an ordinary C function, not as a messenger entry:

define hidden i32 @"\01-[Foo bar:]"(ptr noundef %0, i32 noundef %1)

nm shows a defined symbol -[Foo bar:]. Direct methods are not added to the class's method list, so objc_msgSend cannot find bar:.

ir/objc.rs walks CXCursor_ObjCInstanceMethodDecl and always builds a msg_send! call. There is no check for ObjCDirectAttr / objc_direct.

Expected Results

Emit a direct C FFI declaration for objc_direct methods (extern "C" { #[link_name = "\u{1}-[Foo bar:]"] fn ... }), not msg_send!.

Environment
bindgen: 0.72.1 and 0.73.1 (rust-lang/rust-bindgen 77cbc723)
clang/libclang: Apple clang 21.0.0
rustc: 1.97.1
target: aarch64-apple-darwin
OS: macOS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in ir/objc.rs at the CXCursor_ObjCInstanceMethodDecl handling and reproduce the issue with the bindgen invocation shown in the report. Trace how objc_direct attributes are exposed by libclang and how the generated method call is selected. Done means objc_direct methods generate a direct C FFI declaration with the expected link name rather than an objc::msg_send! wrapper.

Written by the indexing model from the issue text.

Assessment

Tech stack
objective-c, rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.