gnustep / libobjc2

Objective-C runtime library intended for use with Clang.
http://www.gnustep.org/
MIT License
434 stars 118 forks source link

Wrong stack pointer offset in objc_msgSend.aarch64.S leads to register corruption #265

Closed hmelder closed 9 months ago

hmelder commented 9 months ago

I was working on a test to fix this and stumbled upon #264. This was not trivial to find, as it was causing some random exceptions in libs-base.

diff --git a/objc_msgSend.aarch64.S b/objc_msgSend.aarch64.S
index 25cbfd6..e9e30ba 100644
--- a/objc_msgSend.aarch64.S
+++ b/objc_msgSend.aarch64.S
@@ -169,7 +169,7 @@ CDECL(objc_msgSend_stret):
        EH_NOP
        ldp    x2, x3, [sp, #32]
        EH_NOP
-       ldp    x4, x5, [sp, #64]
+       ldp    x4, x5, [sp, #48]
        EH_NOP
        ldp    x6, x7, [sp, #64]
        EH_NOP

I'll make a PR with this fix and a unit test.

hmelder commented 9 months ago

This was never triggered by the tests because clang never generated objc_msgSend calls.

We can rerun objc_msgSend.m with -Xclang -fobjc-dispatch-method=non-legacy.