Skip to content

Commit 816a34a

Browse files
committed
Auto merge of rust-lang#38146 - kali:master, r=alexcrichton
fix objc ABI in std::env::args iOS use different calling convention for `objc_msgSend` depending on the platform. armv7 expect good old variadic arguments, but aarch64 wants "normal" convention: `objc_msgSend` has to be called mimicking the actual callee prototype. https://developer.apple.com/library/content/documentation/General/Conceptual/CocoaTouch64BitGuide/ConvertingYourAppto64-Bit/ConvertingYourAppto64-Bit.html#//apple_ref/doc/uid/TP40013501-CH3-SW26 This currently breaks std::env:args() on aarch64 iOS devices. As far as I can tell, in the standard library, this is the only occurrence of ObjectiveC dispatching.
2 parents d9aae63 + a1882ca commit 816a34a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/libstd/sys/unix/args.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,23 @@ mod imp {
172172

173173
extern {
174174
fn sel_registerName(name: *const libc::c_uchar) -> Sel;
175-
fn objc_msgSend(obj: NsId, sel: Sel, ...) -> NsId;
176175
fn objc_getClass(class_name: *const libc::c_uchar) -> NsId;
177176
}
178177

178+
#[cfg(target_arch="aarch64")]
179+
extern {
180+
fn objc_msgSend(obj: NsId, sel: Sel) -> NsId;
181+
#[link_name="objc_msgSend"]
182+
fn objc_msgSend_ul(obj: NsId, sel: Sel, i: libc::c_ulong) -> NsId;
183+
}
184+
185+
#[cfg(not(target_arch="aarch64"))]
186+
extern {
187+
fn objc_msgSend(obj: NsId, sel: Sel, ...) -> NsId;
188+
#[link_name="objc_msgSend"]
189+
fn objc_msgSend_ul(obj: NsId, sel: Sel, ...) -> NsId;
190+
}
191+
179192
#[link(name = "Foundation", kind = "framework")]
180193
#[link(name = "objc")]
181194
#[cfg(not(cargobuild))]
@@ -199,7 +212,7 @@ mod imp {
199212

200213
let cnt: usize = mem::transmute(objc_msgSend(args, count_sel));
201214
for i in 0..cnt {
202-
let tmp = objc_msgSend(args, object_at_sel, i);
215+
let tmp = objc_msgSend_ul(args, object_at_sel, i as libc::c_ulong);
203216
let utf_c_str: *const libc::c_char =
204217
mem::transmute(objc_msgSend(tmp, utf8_sel));
205218
let bytes = CStr::from_ptr(utf_c_str).to_bytes();

0 commit comments

Comments
 (0)