public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Joseph Faulls <Joseph.Faulls@imgtec.com>
Cc: "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: Re: [Exception Handling] Why does frame unwind label have static alignment 4?
Date: Mon, 17 Jan 2022 10:55:16 -0800	[thread overview]
Message-ID: <CAMe9rOrj7q4xTRwA2gob3YJ9UQVN8keHJJbnNZ8k+KP63fLUUA@mail.gmail.com> (raw)
In-Reply-To: <LO4P265MB5914E35E1B04136D184866A680579@LO4P265MB5914.GBRP265.PROD.OUTLOOK.COM>

On Mon, Jan 17, 2022 at 9:24 AM Joseph Faulls <Joseph.Faulls@imgtec.com> wrote:
>
> Hello all,
>
> Small disclaimer of being new to EH, but I have come across a problem that seems quite fundamental to EH frame registry. I am targeting riscv64, but I believe the problem to be entirely platform agnostic.
>
> When using EH frame registry, a label is put at the beginning of the frame unwind info to register and deregister frames:
>
> libgcc/crtstuff.c:
> > STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[]
> >      __attribute__((section(__LIBGCC_EH_FRAME_SECTION_NAME__), aligned(4)))
>
> This is then populated with struct dwarf_fde:
>
> libgcc/unwind-dw2-fde.h:
> > struct dwarf_fde
> > {
> >   uword length;
> >   sword CIE_delta;
> >   unsigned char pc_begin[];
> > } __attribute__ ((packed, aligned (__alignof__ (void *))));
>
> The trouble is that the __EH_FRAME_BEGIN__ has alignment 4, whereas the struct dwarf_fde has alignment of void*. When targeting 64-bit, these values are not the same.
> It is this that is causing 4 bytes of padding. This is the disassembly of a simple program targeting riscv64 that throws an exception:
> > 22954 000000000000e324 <__EH_FRAME_BEGIN__>:
> > e324:       0000                    unimp
> > e326:       0000                    unimp
> > e328:       0010                    0x10
> > e32a:       0000                    unimp
> > e32c:       0000                    unimp
> > e32e:       0000                    unimp
> > e330:       00527a03                0x527a03
>
> It is this that causes __register_frame_info_bases to fall flat on its face:
>
> Libgcc/crtstuff.c in function frame_dummy:
> > __register_frame_info (__EH_FRAME_BEGIN__, &object);
>
> libgcc/unwind-dw2-fde.c
> >   void
> >   __register_frame_info_bases (const void *begin, struct object *ob,
> >                                void *tbase, void *dbase)
> >   {
> >     /* If .eh_frame is empty, don't register at all.  */
> >     if ((const uword *) begin == 0 || *(const uword *) begin == 0)
> >       return;
> > ...
> > void
> > __register_frame_info (const void *begin, struct object *ob)
> > {
> >   __register_frame_info_bases (begin, ob, 0, 0);
> > }
>
> This means no EH frames are ever registered, and so exceptions cannot be handled!
>
> So, why does __EH_FRAME_BEGIN__ have alignment 4 and not of __alignof__ (void *) ? Is this a bug?
>
> Thanks,
> Joe

This is:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=27576

-- 
H.J.

      reply	other threads:[~2022-01-17 18:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17 17:24 Joseph Faulls
2022-01-17 18:55 ` H.J. Lu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMe9rOrj7q4xTRwA2gob3YJ9UQVN8keHJJbnNZ8k+KP63fLUUA@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=Joseph.Faulls@imgtec.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).