<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi<br>
<br>
I'm working on the XCore target and am having difficulty building libgcc.<br>
<br>
Background:<br>
If I use a libgcc built by llvm3.0-gcc with my current clang-llvm3.3 compiler, exceptions 'seem' to work.<br>
Trying to rebuild libgcc however breaks exception handling - they aren't caught!<br>
I thus assumed I needed to focus on the unwind code and particularly functions that call @llvm.eh.unwind.init().<br>
I reinforced this assumption by swapping the assembler output from the llvm-gcc lib into my new lib for
<b>some</b> such functions - and exceptions 'seem' to work again.<br>
(the critical functions being <font color="black" face="Tahoma" size="2"><span style="font-size:10pt;" dir="ltr">found in eh_personality.o, unwind-dw2.o, eh_throw.o</span></font><font color="black" face="Tahoma" size="2"><span style="font-size:10pt;" dir="ltr">)</span></font><br>
<br>
Looking at functions built using the llvm3.0-gcc front end, I noticed that R0 & R1 were spilled/restored (clobbering '_Unwind_Reason_Code') , along with the callee saved regs.<br>
<br>
So how are things meant to work?<br>
<br>
For example take:<br>
    define i32 @_Unwind_RaiseException(%struct._Unwind_Exception* %exc)<br>
<br>
This calls:<br>
    @llvm.eh.unwind.init()<br>
followed by:<br>
    call void @llvm.eh.return()<br>
    ret i32 '_Unwind_Reason_Code'<br>
    call void @abort()<br>
<br>
>From my reading, I need to spill all callee save regs (R4-R10) during the prologue.<br>
(R0-R3, LR & FP are caller saved/argument registers)<br>
BUT<br>
Q: what about exception info (and what is this)?<br>
Q: is it %exc (R0)?<br>
Q: is it 'ExceptionPointerRegister' & 'ExceptionSelectorRegister' (R0&R1)?<br>
<br>
Then:<br>
<br>
Calling abort, does not restore callee save regs.<br>
<br>
For 'return' epilogues, I restore callee save regs (R4-10) & R0 will hold the '_Unwind_Reason_Code'.<br>
<br>
However, what must I do for llvm.eh.return() epilogues?<br>
Q: do I restore callee save regs (R4-R10)?<br>
Q: do I restore exception info (R0-R1)?<br>
<br>
<br>
I have tried only spilling/restoring callee save regs - but this doesn't work, I end up with an uncaught exception.<br>
<br>
So I tried spilling R0 & R1 and trying to restore them only for llvm.eh.return() but this will not compile.<br>
viz unwind-dw2.c will report:<br>
    BB#0: derived from LLVM BB %entry<br>
        Live Ins: %R0 %R0 %R1 %R4 %R5 %R6 %R7 %R8 %R9 %R10 %LR %R0 %R1<br>
        ENTSP_lu6 120, %SP<imp-def>, %SP<imp-use>, %LR<imp-use,kill><br>
        PROLOG_LABEL <MCSym=.Ltmp68><br>
        PROLOG_LABEL <MCSym=.Ltmp69><br>
        STWSP_lru6 %R0<kill>, 119, %SP<imp-use><br>
        PROLOG_LABEL <MCSym=.Ltmp59><br>
        STWSP_lru6 %R1<kill>, 118, %SP<imp-use><br>
        PROLOG_LABEL <MCSym=.Ltmp60><br>
        STWSP_lru6 %R4<kill>, 117, %SP<imp-use><br>
        PROLOG_LABEL <MCSym=.Ltmp61><br>
        STWSP_lru6 %R5<kill>, 116, %SP<imp-use><br>
        PROLOG_LABEL <MCSym=.Ltmp62><br>
        STWSP_lru6 %R6<kill>, 115, %SP<imp-use><br>
        PROLOG_LABEL <MCSym=.Ltmp63><br>
        STWSP_lru6 %R7<kill>, 114, %SP<imp-use><br>
        PROLOG_LABEL <MCSym=.Ltmp64><br>
        STWSP_lru6 %R8<kill>, 113, %SP<imp-use><br>
        PROLOG_LABEL <MCSym=.Ltmp65><br>
        STWSP_lru6 %R9<kill>, 112, %SP<imp-use><br>
        PROLOG_LABEL <MCSym=.Ltmp66><br>
        STWSP_lru6 %R10<kill>, 111, %SP<imp-use><br>
        PROLOG_LABEL <MCSym=.Ltmp67><br>
        %R4<def> = COPY %R0<br>
...<br>
    *** Bad machine code: Using an undefined physical register ***<br>
    - function:    _Unwind_RaiseException<br>
    - basic block: BB#0 entry (0x33d9f20)<br>
    - instruction: %R4<def> = COPY %R0<br>
    - operand 1:   %R0<br>
<br>
<br>
To see if I am on the right track I may try to:<br>
    1. hack llvm to not kill R0 during the spill<br>
    2. manually add spilled/restore R0 & R1 into the assembler output for functions that call llvm.eh.return().<br>
However, I would prefer knowledgeable input at this stage!<br>
<br>
Thank you.<br>
<br>
Robert<br>
<br>
<br>
</div>
</body>
</html>