objc_direct methods are emitted as msg_send! instead of a direct C call
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- objective-c, rust
- Domain
- tooling
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.
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
- 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 48 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
-
Unit tests use deprecated constant (part 2)Possibly taken @servo-highfive claimed this today. OpenE-less-complex
Difficulty 1/5 Under an hour Newbie friendliness 84/100
servo/servo#49766 · 1 comment ·
Maintainers usually reply within 1 day
-
bug good first issue help wanted linux macos testing
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
area: app type: test
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
bug priority: medium
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
storytold/photocraft#12706 · 1 comment ·
Maintainers usually reply within 1 day
-
bug priority-low to-agent
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day