rust-lang / rust-lang/rust-bindgen
objc_runtime_name is ignored: class!(SourceName) looks up a class that does not exist
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))
__attribute__((objc_runtime_name("BNRuntimeFoo")))
@interface BNSourceFoo {
Class isa;
}
+ (int)bar:(int)x;
@end
Bindgen Invocation
$ bindgen input.h -- -x objective-c -fobjc-arc
Actual Results
bindgen 0.72.1 and 0.73.1 both emit class!(BNSourceFoo) — the source identifier — and never mention BNRuntimeFoo:
unsafe fn bar_(x: c_int) -> c_int {
msg_send!(class!(BNSourceFoo), bar: x)
}
Clang registers the class under the runtime name. nm on the implementation:
_OBJC_CLASS_$_BNRuntimeFoo
+[BNSourceFoo bar:]
LLVM has c"BNRuntimeFoo\00" as the classname string. objc_getClass("BNSourceFoo") therefore returns nil.
A C caller [BNSourceFoo bar:7] prints v=17 (the compiler uses the runtime name). The generated Rust method does objc_getClass("BNSourceFoo") + objc_msgSend and prints v=0 (message to nil). Same numbers twice on both bindgen versions.
ir/objc.rs ObjCInterface::from_ty sets interface.name = cursor.spelling() and codegen does class!(#class_name). There is no read of objc_runtime_name / ObjCRuntimeNameAttr.
Expected Results
class! / the Objective-C class lookup should use the runtime name (BNRuntimeFoo), not the source name, so objc_getClass finds the class clang actually registered.
Environment
bindgen: 0.72.1 and 0.73.1 (rust-lang/rust-bindgen 77cbc723)
clang/libclang: Homebrew clang 21.1.8
rustc: 1.97.1
target: aarch64-apple-darwin
OS: macOS
Contributor 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.
Research direction
Start in ir/objc.rs at ObjCInterface::from_ty and follow the codegen path that emits class!(...). Inspect the ObjC runtime-name attribute represented by ObjCRuntimeNameAttr, then run bindgen on the shown header. Done when the generated lookup uses BNRuntimeFoo rather than BNSourceFoo, matching the class registered by Clang.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- objective-c, rust
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100