cwalls251 / iphone-dev

Automatically exported from code.google.com/p/iphone-dev
0 stars 0 forks source link

Struct-returning Obj-C methods always crash #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I believe the ARM PCS says that struct-returning methods should use a hidden 
first parameter (r0 
on ARM) to store the address of the struct. But the objc_msgSend implementation 
on the iPhone 
always assumes that r0 is the receiver. This causes a crash when methods like 
+[UIHardware 
fullScreenApplicationContentRect] are called.

How does the iPhone Obj-C runtime return structs?

Why wasn't this an issue before (modulo the silly problems with intel 
targeting)? LLVM recently had 
some changes to TargetARM in SVN, maybe this broke things? In any case there is 
the _stret 
infrastructure in LLVM-GCC for x86 platforms, so maybe that could be used to 
fix the issue. 
Regardless this is going to require some reverse engineering.

Original issue reported on code.google.com by nightwat...@gmail.com on 12 Sep 2007 at 5:00

GoogleCodeExporter commented 8 years ago
Seems to me (by a quick look at the +[UIHardware 
fullScreenApplicationContentRect] asm) that the struct addr is 
shuffled after the receiver and selector parameters, so it starts as r2 in the 
objc_msgSend call. Need to verify 
that this is what the caller is doing and also that this is the behavior that 
struct-returning obj-c methods that 
*we* generate exhibit.

Original comment by nightwat...@gmail.com on 12 Sep 2007 at 5:11

GoogleCodeExporter commented 8 years ago
Sounds fun. That probably explains why my application died horribly when I 
built with the latest toolchain. Glad 
you're on the case. You've done a great job getting this far in just the short 
amount of time since the phone's 
been out. Yeah if I had a nickel for every time I've said "how'd this *ever* 
work?" :)

Original comment by kaisers...@gmail.com on 12 Sep 2007 at 5:50

GoogleCodeExporter commented 8 years ago
I noticed that problem too, wenn calling -[NSValue pointValue], which returns a
struct CGPoint. As a workaround, I can use -[NSValue getValue:], so it's ok for 
now.

Original comment by onit...@gmail.com on 12 Sep 2007 at 10:13

GoogleCodeExporter commented 8 years ago

Original comment by nightwat...@gmail.com on 12 Sep 2007 at 4:01

GoogleCodeExporter commented 8 years ago
Should be fixed now. It was an ugly change I had made in 0.20 and forgotten 
about, perhaps because I didn't 
fully understand the issue at the time. We have a better solution now.

Original comment by nightwat...@gmail.com on 12 Sep 2007 at 4:25