[PATCH v7 3/3] aarch64: Implement Structured Exception Handling (SEH) on AArch64
Alice Carlotti
alice.carlotti@arm.com
Thu Apr 16 10:29:08 GMT 2026
On Thu, Apr 16, 2026 at 03:38:49AM +0100, Alice Carlotti wrote:
> On Thu, Mar 19, 2026 at 12:16:38PM +0100, Evgeny Karpov wrote:
>
> Apologies for the long wait - it's taken me a while to get to grips with the
> spec and implementation in detail.
>
> > The patch reuses shared helpers for SEH and implements SEH on AArch64.
> > The implementation is based on
> > (https://learn.microsoft.com/en-us/cpp/build/arm64-exception-handling?view=msvc-170)
> > and pdata/xdata SEH records are emitted from md_finish.
> >
> > When .pdata/.xdata is emitted, the function size is required.
> > Function sizes are calculated as late as possible, and the code segment needs
> > to be relaxed to be able to calculate the function sizes.
> >
> > Initially, obj_coff_generate_pdata was declared in write_object_file.
>
> I think you mean "called in write_object_file".
>
> > Before the change, obj_coff_generate_pdata was used only to validate
> > syntax, which was sufficient for that purpose. However, that location
> > seems incorrect, as it is too late to emit .pdata/.xdata records
> > in the AArch64 case.
> >
> > md_finish has been declared for AArch64 and extended with
> > seh_aarch64_write_data to emit .pdata/.xdata records after all
> > assembly has been completed.
> >
> > Signed-off-by: Evgeny Karpov <evgeny@kmaps.co>
>
> Some general remarks:
>
> - Epilogue/epilog and prologue/prolog in various names. We should be
> consistent with Microsoft's description, so remove the "ue"s.
Actually, I've changed my thoughts on this - we should be consistent with the
existing Binutils usage (and the GCC coding convention matches this). So add
the "ue"s wherever they are missing.
>
> - It hard to know whether the input parsing is correct when this patch doesn't
> include any tests or documentation for the assembler directives.
>
...
> > +/* Write out the xdata information for one function. */
> > +static void
> > +seh_aarch64_write_function_xdata (struct seh_aarch64_context *seh_ctx)
> > +{
...
> > +
> > + unsigned unwind_bytes = 0;
> > + if (is_first_frag || is_last_frag)
> > + unwind_bytes += prolog_size;
> > +
> > + if (header->ext_epilogue_count)
> > + unwind_bytes += last_epilog_index - first_epilog_index;
> > +
> > + const bool has_phantom_prolog = is_fragmented_function && is_last_frag;
Don't we have a phantom prolog whenever we're not in the first fragment (where
I assume the real prolog exists)?
It might be help run your testing with the fragment size artificially limited
to a much smaller number, so that some functions are split into three or more
fragments. Otherwise I suspect the fragmentation code is likely to be
untested.
Alice
> > + if (has_phantom_prolog && unwind_bytes)
> > + {
> > + /* One more epilogue scope and unwind code are emitted with phantom
> > + prolog. */
> > + unwind_bytes += 1;
> > + ++header->ext_epilogue_count;
> > + }
> > +
...
More information about the Binutils
mailing list