[llvm-dev] Exceptions not getting caught on bare-metal target

Anton Korobeynikov via llvm-dev llvm-dev at lists.llvm.org
Fri Jul 3 08:48:25 PDT 2020


Dominik,

Multiple things are involved:

1. You need to make sure libunwind knows where to look for EH tables.
Usually some communication from dynamic linker or some other way of
obtaining the address of EH table section is necessary
2. You need to describe properly the location of all registers that
need to be restored. If there is something special on your platform,
then you need to implement this functionality in libunwind as well.

You may want to enable debug printing in libunwind – usually it helps a lot.

On Fri, Jul 3, 2020 at 1:22 PM Dominik Montada via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
>
> Hi,
>
> We're working on adding exception handling support for a downstream
> bare-metal target. I read through the LLVM exception handling docs [1]
> and went through some patches from other backends to understand what
> parts we need to implement.
>
> We're now at a point were it feels like it should work, but
> unfortunately exceptions are still not getting caught. Our target uses
> DWARF unwinding.
>
> The problem seems to be that findFDE cannot find a CIE which covers the
> given PC. We're not sure why this is though. From [2] and other backend
> implementations we gathered that unw_getcontext saves the PC of the
> call-site, i.e. the return address of unw_getcontext and that is that we
> are doing as well.
>
> Is there some other target hook in LLVM or libunwind that we need to
> implement in order to get this to work? Or are we not emitting
> enough/correct CFI instructions (currently we only emit .cfi_def_cfa in
> the prolog, we don't have any callee-saved registers).
>
> Speaking of calling conventions: our target is special in that registers
> are automatically pushed to a special save area upon executing a call,
> and automatically restored when executing a return instruction. I assume
> we need to implement some target specific code in stepWithDwarf to
> handle this?
>
> Any help in this regard would be highly appreciated!
>
> Cheers,
>
> Dominik
>
> [1] https://llvm.org/docs/ExceptionHandling.html
> [2] https://www.nongnu.org/libunwind/man/unw_getcontext(3).html
>
> --
> ----------------------------------------------------------------------
> Dominik Montada                   Email: dominik.montada at hightec-rt.com
> HighTec EDV-Systeme GmbH          Phone: +49 681 92613 19
> Europaallee 19                    Fax:   +49-681-92613-26
> D-66113 Saarbrücken               WWW: http://www.hightec-rt.com
>
> Managing Director: Vera Strothmann
> Register Court: Saarbrücken, HRB 10445, VAT ID: DE 138344222
>
> This e-mail may contain confidential and/or privileged information. If
> you are not the intended recipient please notify the sender immediately
> and destroy this e-mail. Any unauthorised copying, disclosure or
> distribution of the material in this e-mail is strictly forbidden.
> ---
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev



-- 
With best regards, Anton Korobeynikov
Department of Statistical Modelling, Saint Petersburg State University


More information about the llvm-dev mailing list