iphone + LDC, a new ARM adventure

Jacob Carlborg doob at me.com
Mon Jan 6 01:22:10 PST 2014


On 2014-01-05 18:28, Dan Olson wrote:
> Jacob Carlborg <doob at me.com> writes:
>
>> On 2014-01-05 08:34, Dan Olson wrote:
>>
>>> Ah, I didn't connect SLJL with setjmp/longjmp. Good clue. Yes, it
>>> appears arm-apple-darwin exceptions are setjmp based (confirmed by
>>> compiling a c++ function with clang). Ok, I will dig in some more, see
>>> where it leads me.
>>
>> Hmm, I would have thought iOS used DWARF-based exception handling.
>
> Hi Jacob.
>
> Yeah, I probably have called it wrong as I am just learning about
> exception handling implementations.  clangc c++ exception handling for
> C++ armv7-apple-darwin is emitting __gxx_personality_sj0 and plugs in
> _Unwind_SjLj_Register/_Unwind_SjLj_Unregister.  Perhaps those are just
> for catching C code longjmps?
>
> For example, this C++ code:
>
>      try {
>          death();
>      }
>      catch (...) {
>          puts("got it");
>      }
>
> produced (edited):
>
> _main:
> 	.cfi_startproc
> 	.cfi_personality 155, L___gxx_personality_sj0$non_lazy_ptr
> Leh_func_begin0:
> 	.cfi_lsda 16, Lexception0
> @ BB#0:                                 @ %entry
> 	push	{r4, r5, r6, r7, lr}
>
> --- snip ---
>
> LPC0_1:
> 	add	r1, pc
> 	str.w	sp, [sp, #52]
> 	str	r1, [sp, #48]
> 	movs	r1, #1
> 	str	r1, [sp, #16]
> 	blx	__Unwind_SjLj_Register
> Ltmp0:
> 	blx	__Z5deathv
> Ltmp1:
> LBB0_1:                                 @ %try.cont
> 	add	r0, sp, #12
> 	blx	__Unwind_SjLj_Unregister
> 	add	r4, sp, #64
> 	movs	r0, #0
>
> --- snip function prologue ---
>
> LBB0_5:                                 @ %invoke.cont2
> Ltmp2:
> 	ldr	r0, [sp, #20]
> 	ldr	r1, [sp, #24]
> 	blx	___cxa_begin_catch
> 	movw	r0, :lower16:(L_.str-(LPC0_3+4))
> 	movt	r0, :upper16:(L_.str-(LPC0_3+4))
> LPC0_3:
> 	add	r0, pc
> 	blx	_puts
> 	mov.w	r0, #-1
> 	str	r0, [sp, #16]
> 	blx	___cxa_end_catch
> 	b	LBB0_1
>
> And I do see an exception table.
>
> 	.section	__TEXT,__gcc_except_tab
> 	.align	2
> GCC_except_table0:
> Lexception0:
> L_LSDA_0:
> 	.byte	255                     @ @LPStart Encoding = omit
> 	.byte	155                     @ @TType Encoding = indirect pcrel sdata4
> 	.asciz	 "\212\200\200"         @ @TType base offset
> 	.byte	3                       @ Call site Encoding = udata4
> 	.byte	2                       @ Call site table length
> 	.byte	0                       @ >> Call Site 0 <<
>                                          @   On exception at call site 0
> 	.byte	1                       @   Action: 1
> 	.byte	1                       @ >> Action Record 1 <<
>                                          @   Catch TypeInfo 1
> 	.byte	0                       @   No further actions
>                                          @ >> Catch TypeInfos <<
> 	.long	0                       @ TypeInfo 1
> 	.align	2
>
>
> I read llvm source code for a while yesterday and really haven't wrapped
> by brain around it yet.

You could try and compare it with x86 64bit code. C++ code on x86 64bit 
is using DWARF-based exception handling. You can see if that code 
contains anything related to SLJL.

Also Objective-C on x86 32bit uses SLJL but on 64bit is uses DWARF.

-- 
/Jacob Carlborg


More information about the digitalmars-d-ldc mailing list