libobjc2: some changes needed to build on OS X. CDECL macro to prefix symbol names in assembly code with an underscore, macros to omit the .type and .section derictives which are unsupported on OS X, and also a linker flag to make weak symbols work

main
ericwa 13 years ago
parent 71b6439091
commit 317e951b0c

@ -275,6 +275,19 @@ if (LIBDISPATCH)
target_link_libraries(objc ${LIBDISPATCH}) target_link_libraries(objc ${LIBDISPATCH})
endif () endif ()
# Enable .type and .section assembly directives on platforms other than OS X
if (NOT APPLE)
add_definitions(-DHAS_SECTION_DIRECTIVE=1 -DHAS_TYPE_DIRECTIVE=1)
endif ()
# Make weak symbols work on OS X
if (APPLE)
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS
"${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS} -undefined dynamic_lookup")
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-undefined,dynamic_lookup")
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,-undefined,dynamic_lookup")
endif ()
# #
# Installation # Installation
# #

@ -1,3 +1,5 @@
#include "common.S"
# #
# This file defines some trampolines for calling blocks. A block function # This file defines some trampolines for calling blocks. A block function
# looks like this: # looks like this:
@ -15,33 +17,33 @@
.file "block_trampolines.S" .file "block_trampolines.S"
#if __arm__ #if __arm__
.syntax unified .syntax unified
.globl __objc_block_trampoline_sret .globl CDECL(__objc_block_trampoline_sret)
.type __objc_block_trampoline_sret, %function TYPE_DIRECTIVE(CDECL(__objc_block_trampoline_sret), %function)
.globl __objc_block_trampoline_end_sret .globl CDECL(__objc_block_trampoline_end_sret)
.globl __objc_block_trampoline .globl CDECL(__objc_block_trampoline)
.type __objc_block_trampoline, %function TYPE_DIRECTIVE(CDECL(__objc_block_trampoline), %function)
.globl __objc_block_trampoline_end .globl CDECL(__objc_block_trampoline_end)
#else #else
.globl __objc_block_trampoline_sret .globl CDECL(__objc_block_trampoline_sret)
.type __objc_block_trampoline_sret, @function TYPE_DIRECTIVE(CDECL(__objc_block_trampoline_sret), @function)
.globl __objc_block_trampoline_end_sret .globl CDECL(__objc_block_trampoline_end_sret)
.globl __objc_block_trampoline .globl CDECL(__objc_block_trampoline)
.type __objc_block_trampoline, @function TYPE_DIRECTIVE(CDECL(__objc_block_trampoline), @function)
.globl __objc_block_trampoline_end .globl CDECL(__objc_block_trampoline_end)
#endif #endif
#if __x86_64 #if __x86_64
__objc_block_trampoline: CDECL(__objc_block_trampoline):
mov -15(%rip), %rsi # Load the block pointer into the second argument mov -15(%rip), %rsi # Load the block pointer into the second argument
xchg %rdi, %rsi # Swap the first and second arguments xchg %rdi, %rsi # Swap the first and second arguments
jmp *-32(%rip) # Call the block function jmp *-32(%rip) # Call the block function
__objc_block_trampoline_end: CDECL(__objc_block_trampoline_end):
__objc_block_trampoline_sret: CDECL(__objc_block_trampoline_sret):
mov -15(%rip), %rdx # Load the block pointer into the second argument mov -15(%rip), %rdx # Load the block pointer into the second argument
xchg %rdx, %rsi # Swap the first and second arguments xchg %rdx, %rsi # Swap the first and second arguments
jmp *-32(%rip) # Call the block function jmp *-32(%rip) # Call the block function
__objc_block_trampoline_end_sret: CDECL(__objc_block_trampoline_end_sret):
#elif __i386 #elif __i386
__objc_block_trampoline: CDECL(__objc_block_trampoline):
call next_line # Store the instruction pointer on the stack call next_line # Store the instruction pointer on the stack
next_line: next_line:
pop %eax # Load the old instruction pointer pop %eax # Load the old instruction pointer
@ -50,8 +52,8 @@ next_line:
mov -9(%eax), %ebx # Load the block pointer to %ebx mov -9(%eax), %ebx # Load the block pointer to %ebx
mov %ebx, 4(%esp) # Store the block pointer in the first argument mov %ebx, 4(%esp) # Store the block pointer in the first argument
jmp *-13(%eax) # Call the block function jmp *-13(%eax) # Call the block function
__objc_block_trampoline_end: CDECL(__objc_block_trampoline_end):
__objc_block_trampoline_sret: CDECL(__objc_block_trampoline_sret):
call next_line2 # Store the instruction pointer on the stack call next_line2 # Store the instruction pointer on the stack
next_line2: next_line2:
pop %eax # Load the old instruction pointer pop %eax # Load the old instruction pointer
@ -60,51 +62,53 @@ next_line2:
mov -9(%eax), %ebx # Load the block pointer to %ebx mov -9(%eax), %ebx # Load the block pointer to %ebx
mov %ebx, 8(%esp) # Store the block pointer in the first argument mov %ebx, 8(%esp) # Store the block pointer in the first argument
jmp *-13(%eax) # Call the block function jmp *-13(%eax) # Call the block function
__objc_block_trampoline_end_sret: CDECL(__objc_block_trampoline_end_sret):
#elif __mips__ #elif __mips__
# ifdef _ABI64 # ifdef _ABI64
__objc_block_trampoline: CDECL(__objc_block_trampoline):
move $a1, $a0 move $a1, $a0
ld $a0, -16($25) ld $a0, -16($25)
ld $25, -8($25) ld $25, -8($25)
jr $25 jr $25
__objc_block_trampoline_end: CDECL(__objc_block_trampoline_end):
__objc_block_trampoline_sret: CDECL(__objc_block_trampoline_sret):
move $a2, $a1 move $a2, $a1
ld $a1, -16($25) ld $a1, -16($25)
ld $25, -8($25) ld $25, -8($25)
jr $25 jr $25
__objc_block_trampoline_end_sret: CDECL(__objc_block_trampoline_end_sret):
# else # else
__objc_block_trampoline: CDECL(__objc_block_trampoline):
move $a1, $a0 move $a1, $a0
lw $a0, -8($25) lw $a0, -8($25)
lw $25, -4($25) lw $25, -4($25)
jr $25 jr $25
__objc_block_trampoline_end: CDECL(__objc_block_trampoline_end):
__objc_block_trampoline_sret: CDECL(__objc_block_trampoline_sret):
move $a2, $a1 move $a2, $a1
lw $a1, -8($25) lw $a1, -8($25)
lw $25, -4($25) lw $25, -4($25)
jr $25 jr $25
__objc_block_trampoline_end_sret: CDECL(__objc_block_trampoline_end_sret):
# endif # endif
#elif __arm__ #elif __arm__
__objc_block_trampoline: CDECL(__objc_block_trampoline):
mov r1, r0 // Move self over _cmd mov r1, r0 // Move self over _cmd
ldr r0, [pc, #-16] // Load the block pointer over self ldr r0, [pc, #-16] // Load the block pointer over self
ldr pc, [pc, #-24] // Jump to the block function ldr pc, [pc, #-24] // Jump to the block function
__objc_block_trampoline_end: CDECL(__objc_block_trampoline_end):
__objc_block_trampoline_sret: CDECL(__objc_block_trampoline_sret):
mov r2, r1 // Move self over _cmd mov r2, r1 // Move self over _cmd
ldr r1, [pc, #-16] // Load the block pointer over self ldr r1, [pc, #-16] // Load the block pointer over self
ldr pc, [pc, #-24] // Jump to the block function ldr pc, [pc, #-24] // Jump to the block function
__objc_block_trampoline_end_sret: CDECL(__objc_block_trampoline_end_sret):
#else #else
#warning imp_implementationWithBlock() not implemented for your architecture #warning imp_implementationWithBlock() not implemented for your architecture
__objc_block_trampoline: CDECL(__objc_block_trampoline):
__objc_block_trampoline_end: CDECL(__objc_block_trampoline_end):
__objc_block_trampoline_sret: CDECL(__objc_block_trampoline_sret):
__objc_block_trampoline_end_sret: CDECL(__objc_block_trampoline_end_sret):
#endif #endif
#if HAS_SECTION_DIRECTIVE
.section .note.GNU-stack,"",%progbits .section .note.GNU-stack,"",%progbits
#endif

@ -0,0 +1,12 @@
#if defined(__WIN32__) || defined(__APPLE__)
#define CDECL(symbol) _##symbol
#else
#define CDECL(symbol) symbol
#endif
#if HAS_TYPE_DIRECTIVE
#define TYPE_DIRECTIVE(symbol, symboltype) .type symbol, symboltype
#else
#define TYPE_DIRECTIVE(symbol, symboltype)
#endif

@ -1,3 +1,4 @@
#include "common.S"
#if __x86_64 #if __x86_64
#include "objc_msgSend.x86-64.S" #include "objc_msgSend.x86-64.S"
#elif __i386 #elif __i386
@ -9,4 +10,6 @@
#else #else
#warning objc_msgSend() not implemented for your architecture #warning objc_msgSend() not implemented for your architecture
#endif #endif
#if HAS_SECTION_DIRECTIVE
.section .note.GNU-stack,"",%progbits .section .note.GNU-stack,"",%progbits
#endif

@ -77,7 +77,7 @@
.save {\receiver} .save {\receiver}
mov r1, \sel mov r1, \sel
bl slowMsgLookup(PLT) // This is the only place where the CFI directives have to be accurate... bl CDECL(slowMsgLookup)(PLT) // This is the only place where the CFI directives have to be accurate...
mov ip, r0 // IMP -> ip mov ip, r0 // IMP -> ip
pop {r5} // restore (modified) self to r5 pop {r5} // restore (modified) self to r5
@ -87,16 +87,16 @@
.fnend .fnend
.endm .endm
.globl objc_msgSend_fpret .globl CDECL(objc_msgSend_fpret)
.type objc_msgSend_fpret, %function TYPE_DIRECTIVE(CDECL(objc_msgSend_fpret), %function)
.globl objc_msgSend .globl CDECL(objc_msgSend)
.type objc_msgSend, %function TYPE_DIRECTIVE(CDECL(objc_msgSend), %function)
objc_msgSend: CDECL(objc_msgSend):
objc_msgSend_fpret: CDECL(objc_msgSend_fpret):
MSGSEND r0, r1 MSGSEND r0, r1
.globl objc_msgSend_stret .globl CDECL(objc_msgSend_stret)
.type objc_msgSend_stret, %function TYPE_DIRECTIVE(CDECL(objc_msgSend_stret), %function)
objc_msgSend_stret: CDECL(objc_msgSend_stret):
MSGSEND r1, r2 MSGSEND r1, r2
LSmallIntClass: LSmallIntClass:

@ -127,7 +127,7 @@ lw $zero, ($zero)
# MIPS implementations. # MIPS implementations.
# Note: A better linker ought to be able to turn this into a single # Note: A better linker ought to be able to turn this into a single
# jump-immediate, so revisit this decision later... # jump-immediate, so revisit this decision later...
LP $25, %got_disp(slowMsgLookup)($t8) LP $25, %got_disp(CDECL(slowMsgLookup))($t8)
daddiu $sp, $sp, -SAVE_SIZE # We need to preserve all registers that may contain arguments: daddiu $sp, $sp, -SAVE_SIZE # We need to preserve all registers that may contain arguments:
@ -193,24 +193,24 @@ lw $zero, ($zero)
6: # smallObject: 6: # smallObject:
#if _ABI64 #if _ABI64
dsll $t4, $t4, 3 # Convert tag to pointer offset dsll $t4, $t4, 3 # Convert tag to pointer offset
LP $t6, %got_disp(SmallObjectClasses)($t8) # Load small object classes array address LP $t6, %got_disp(CDECL(SmallObjectClasses))($t8) # Load small object classes array address
daddu $t4, $t4, $t6 # Add the base address to the offset daddu $t4, $t4, $t6 # Add the base address to the offset
b 1b # Return to the normal path b 1b # Return to the normal path
LP $t4, ($t4) # Load the class (in delay slot) LP $t4, ($t4) # Load the class (in delay slot)
#else #else
b 1b b 1b
LP $t4, %got_disp(SmallIntClass)($t8) LP $t4, %got_disp(CDECL(SmallIntClass))($t8)
#endif #endif
.cfi_endproc .cfi_endproc
.endm .endm
.globl objc_msgSend .globl CDECL(objc_msgSend)
.type objc_msgSend, @function TYPE_DIRECTIVE(CDECL(objc_msgSend), @function)
.globl objc_msgSend_fpret .globl CDECL(objc_msgSend_fpret)
.type objc_msgSend_fpret, @function TYPE_DIRECTIVE(CDECL(objc_msgSend_fpret), @function)
objc_msgSend_fpret: CDECL(objc_msgSend_fpret):
objc_msgSend: CDECL(objc_msgSend):
MSGSEND $a0, $a1 MSGSEND $a0, $a1
.globl objc_msgSend_stret .globl CDECL(objc_msgSend_stret)
.type objc_msgSend_stret, @function TYPE_DIRECTIVE(CDECL(objc_msgSend_stret), @function)
objc_msgSend_stret: CDECL(objc_msgSend_stret):
MSGSEND $a1, $a2 MSGSEND $a1, $a2

@ -87,15 +87,15 @@
jmp 1b jmp 1b
.cfi_endproc .cfi_endproc
.endm .endm
.globl objc_msgSend_fpret .globl CDECL(objc_msgSend_fpret)
.type objc_msgSend_fpret, @function TYPE_DIRECTIVE(CDECL(objc_msgSend_fpret), @function)
objc_msgSend_fpret: CDECL(objc_msgSend_fpret):
MSGSEND 4, 8, 1 MSGSEND 4, 8, 1
.globl objc_msgSend .globl CDECL(objc_msgSend)
.type objc_msgSend, @function TYPE_DIRECTIVE(CDECL(objc_msgSend), @function)
objc_msgSend: CDECL(objc_msgSend):
MSGSEND 4, 8, 0 MSGSEND 4, 8, 0
.globl objc_msgSend_stret .globl CDECL(objc_msgSend_stret)
.type objc_msgSend_stret, @function TYPE_DIRECTIVE(CDECL(objc_msgSend_stret), @function)
objc_msgSend_stret: CDECL(objc_msgSend_stret):
MSGSEND 8, 12, 0 MSGSEND 8, 12, 0

@ -234,7 +234,7 @@
.endif .endif
.cfi_adjust_cfa_offset 0xD8 .cfi_adjust_cfa_offset 0xD8
call slowMsgLookup # Call the slow lookup function call CDECL(slowMsgLookup) # Call the slow lookup function
mov %rax, %r10 # Load the returned IMP mov %rax, %r10 # Load the returned IMP
pop %rdx pop %rdx
@ -260,20 +260,20 @@
6: # smallObject: 6: # smallObject:
and \receiver, %r10 # Find the small int type and \receiver, %r10 # Find the small int type
shll $3, %r10d shll $3, %r10d
lea SmallObjectClasses(%rip), %r11 lea CDECL(SmallObjectClasses)(%rip), %r11
add %r11, %r10 add %r11, %r10
mov (%r10), %r10 mov (%r10), %r10
jmp 1b jmp 1b
.cfi_endproc .cfi_endproc
.endm .endm
.globl objc_msgSend .globl CDECL(objc_msgSend)
.type objc_msgSend, @function TYPE_DIRECTIVE(CDECL(objc_msgSend), @function)
.globl objc_msgSend_fpret .globl CDECL(objc_msgSend_fpret)
.type objc_msgSend_fpret, @function TYPE_DIRECTIVE(CDECL(objc_msgSend_fpret), @function)
objc_msgSend_fpret: CDECL(objc_msgSend_fpret):
objc_msgSend: CDECL(objc_msgSend):
MSGSEND %rdi, %rsi MSGSEND %rdi, %rsi
.globl objc_msgSend_stret .globl CDECL(objc_msgSend_stret)
.type objc_msgSend_stret, @function TYPE_DIRECTIVE(CDECL(objc_msgSend_stret), @function)
objc_msgSend_stret: CDECL(objc_msgSend_stret):
MSGSEND %rsi, %rdx MSGSEND %rsi, %rdx

Loading…
Cancel
Save