1

I'm trying to understand the differences between the following function prologs of a number of obj-c function decompilations.

I know they store variables for the caller to use when the function returns. But why the differences?

Sample 1

void * -[Issue ideal](void * self, void * _cmd)
sub        sp, sp, #0x40
stp        x22, x21, [sp, #0x10]
stp        x20, x19, [sp, #0x20]
stp        x29, x30, [sp, #0x30]
add        x29, sp, #0x30
mov        x19, x0

Sample 2

void * -[Issue path](void * self, void * _cmd)
stp        x26, x25, [sp, #-0x50]!
stp        x24, x23, [sp, #0x10]
stp        x22, x21, [sp, #0x20]
stp        x20, x19, [sp, #0x30]
stp        x29, x30, [sp, #0x40]
add        x29, sp, #0x40
mov        x19, x0

Sample 3

void -[ContentView showPageThumb:page:data:guid:](void * self, void * _cmd, void * arg2, long long arg3, void * arg4, void * arg5)
stp        x24, x23, [sp, #-0x40]!
stp        x22, x21, [sp, #0x10]
stp        x20, x19, [sp, #0x20]
stp        x29, x30, [sp, #0x30]
add        x29, sp, #0x30
mov        x20, x5
mov        x21, x4
mov        x22, x3
mov        x19, x0
mov        x0, x2
1

I haven't touched this stuff for a while, but I'd say compiler is simply saving opcodes or following a complicated template, perhaps to do with optimisation. Notice that

stp        x24, x23, [sp, #-0x40]!
stp        x22, x21, [sp, #0x10]
stp        x20, x19, [sp, #0x20]
stp        x29, x30, [sp, #0x30]

does the same job as

sub        sp, sp, #0x40
stp        x22, x21, [sp, #0x10]
stp        x20, x19, [sp, #0x20]
stp        x29, x30, [sp, #0x30]

plus stores one additional register x24 . This because the first example uses writeback addressing in [sp, #-0x40]!

http://www.davespace.co.uk/arm/introduction-to-arm/addressing.html (a random google result on addressing modes in ARM).

Same with your second example - it still allocates x50 bytes on the stack. The difference is rather superficial, they all do the same job. add,movs are not part of prologue IIRC.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.