···11global __darwin_objc_msgSend_fixup
22-33-extern objcdarwin_class_lookup
44-extern objc_msg_lookup
55-extern sel_get_any_uid
66-extern objcdarwin_SaveRegisters
77-extern objcdarwin_RestoreRegisters
22+extern objc_msgSend
8394%ifidn __OUTPUT_FORMAT__, elf64
105116BITS 64
127section text
1381414-;__darwin_objc_msgSend_fixed:
1515-; add rsi, 8
1616-; jmp __darwin_objc_msgSend WRT ..plt
1717-189__darwin_objc_msgSend_fixup:
1919- ; Procedure:
2020- ; 1) get the converted GNU class from an Apple class
2121- ; 2) convert Apple selector to GNU
2222- ; 3) run objc_msg_lookup
2323- ; 4) jump to the pointer returned by objc_msg_lookup
2424-2525- call objcdarwin_SaveRegisters WRT ..plt
2626- call objcdarwin_class_lookup WRT ..plt
2727- mov [rsp], rax ; save the converted value
2828-2929- ; move the second argument into the first argument
3030- mov rdi, [rsp+8]
3131- add rdi, 8 ; the selector itself is the second element of what we receive as SEL
3232- mov rdi, [rdi]
3333- call sel_get_any_uid WRT ..plt
3434- ; rax now has the GNU selector
3535- ; move rax to the second argument
3636- mov rsi, rax
3737-3838- ; restore the first argument
3939- mov rdi, [rsp]
4040- call objc_msg_lookup WRT ..plt
4141-4242- ; optimize the next call by fixing the function pointer
4343- mov rsi, [rsp+8]
4444- ;mov [rsi], rax ; TODO: fixups not working, the target method still isn't getting the selector it expects
4545-4646- call objcdarwin_RestoreRegisters WRT ..plt
4747- jmp rax
1010+ mov rsi, [rsi+8]
1111+ jmp objc_msgSend WRT ..plt
48124913%elifidn __OUTPUT_FORMAT__, elf
50145115BITS 32
5216section text
53171818+; Is it even used with the old runtime?
5419__darwin_objc_msgSend_fixup:
5555-5656- mov ecx, [esp+4]
5757- push ecx ; arg for func call
5858-5959- call objcdarwin_class_lookup ;WRT ..plt
6060-6161- add esp, 4 ; remove argument
6262- mov [esp+4], eax ; change the class id
6363-6464- mov ecx, [esp+8] ; second argument
6565- add ecx, 4 ; the selector itself is the second element of what we receive as SEL
6666- mov ecx, [ecx]
6767- push ecx
6868-6969- call sel_get_any_uid ;WRT ..plt
7070-7171- add esp, 4
7272- mov [esp+8], eax
7373-7474- push eax ; reuse the sel_get_any_uid retval
7520 mov eax, [esp+8]
7676- push eax ; class id
7777-7878- call objc_msg_lookup ;WRT ..plt
7979- add esp, 8
8080-8181- ; optimize the next call by fixing the function pointer
8282- mov ecx, [esp+8]
8383- ;mov [ecx], eax ; TODO: fixups not working, the target method still isn't getting the selector it expects
8484-8585- jmp eax
2121+ add eax, 4
2222+ mov eax, [eax]
2323+ mov [esp+8], eax
2424+ jmp objc_msgSend
86258726%else
8827
-77
src/libobjcdarwin/objc_msgSend_stret.nasm
···11-global __darwin_objc_msgSend_stret
22-33-extern objcdarwin_class_lookup
44-extern objc_msg_lookup
55-extern sel_get_any_uid
66-extern objcdarwin_SaveRegisters
77-extern objcdarwin_RestoreRegisters
88-99-%ifidn __OUTPUT_FORMAT__, elf64
1010-1111-BITS 64
1212-section text
1313-1414-; Compared to ordinary msgSend, arguments are shifted by one - first arg is the stret
1515-__darwin_objc_msgSend_stret:
1616- ; Procedure:
1717- ; 1) get the converted GNU class from an Apple class
1818- ; 2) convert Apple selector to GNU
1919- ; 3) run objc_msg_lookup
2020- ; 4) jump to the pointer returned by objc_msg_lookup
2121-2222- call objcdarwin_SaveRegisters WRT ..plt
2323- mov rdi, rsi
2424- call objcdarwin_class_lookup WRT ..plt
2525- mov [rsp+8], rax ; save the converted value
2626-2727- ; move the second argument into the first argument
2828- mov rdi, [rsp+16]
2929- call sel_get_any_uid WRT ..plt
3030- ; rax now has the GNU selector
3131- ; move rax to the second argument
3232- mov rsi, rax
3333- mov [rsp+16], rax
3434- ; restore the first argument
3535- mov rdi, [rsp+8]
3636- call objc_msg_lookup WRT ..plt
3737-3838- call objcdarwin_RestoreRegisters WRT ..plt
3939- jmp rax
4040-4141-%elifidn __OUTPUT_FORMAT__, elf
4242-4343-BITS 32
4444-section text
4545-4646-__darwin_objc_msgSend_stret:
4747-4848- mov ecx, [esp+8]
4949- push ecx ; arg for func call
5050-5151- call objcdarwin_class_lookup ;WRT ..plt
5252-5353- add esp, 4 ; remove argument
5454- mov [esp+8], eax ; change the class id
5555-5656- mov ecx, [esp+12] ; second argument
5757- push ecx
5858-5959- call sel_get_any_uid ;WRT ..plt
6060-6161- add esp, 4
6262- mov [esp+12], eax
6363-6464- push eax ; reuse the sel_get_any_uid retval
6565- mov eax, [esp+12]
6666- push eax ; class id
6767-6868- call objc_msg_lookup ;WRT ..plt
6969- add esp, 8
7070-7171- jmp eax
7272-7373-%else
7474-7575-%error "Unsupported platform"
7676-7777-%endif