Re: [PATCH v12 1/1] aarch64: Implement Structured Exception Handling (SEH) on AArch64
Evgeny Karpov <[email protected]> Tue, 21 Jul 2026 10:35:51 +0200
| Newsgroups | gmane.comp.gnu.binutils |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 20 Jul 2026, Alice Carlotti wrote:
> > + /* Calculate how many unwind bytes will be emitted in .xdata record. */
> > + unsigned unwind_bytes = seh_ctx->unwind_codes_byte_count;
> > +
> > + /* Check if current fragment has a phantom prologue. If yes, then
> > + the unwinding size should be adjusted. */
> > + const bool has_phantom_prologue = fragment_offset != 0;
> > + if (has_phantom_prologue && unwind_bytes)
>
> The list of unwind codes will always include at least one `end` unwind code for
> the prologue (phantom or non-phantom), even after any future optimisations are
> applied. So any checks that unwind_bytes or code_words are nonzero can be
> dropped (or replaced by a single assert that unwind_bytes is zero at the start
> of the function).
Ok, in current implementation, code_words are nonzero, however it might be changed later.
The check will be removed for now.
> > + {
> > + /* One more epilogue scope and unwind code are emitted with phantom
> > + prologue. */
> > + unwind_bytes += 1;
> > + ++epilogue_count;
>
> What is this epilogue_count increment doing? You don't seem to emit any extra
> epilogue scope to match the increased count, so I think this increment needs to
> be removed.
There is a comment above to clarify this.
It is required for fragments that have a phantom prologue in the current implementation.
Otherwise, an exception in the second and later fragment will not be unwound.
This epilogue references these unwind codes.
This is tested in gas/testsuite/gas/pe/seh-aarch64-large-func.d.
> > + header |= seh_ctx->has_exception_data << has_exception_data_shift;
> > +
> > + /* Check if short or extended header for a .xdata record should be
> > + used. */
> > + unsigned header_size = 8;
> > + bool single_epilog = false;
> > + if ((code_words != 0 || epilogue_count != 0)
>
> code_words is always nonzero (as explained above).
Ok, it will be removed for now.
> > + && code_words < 32
> > + && epilogue_count < 32)
> > + {
> > + header_size = 4;
> > + if (epilogue_count == 1)
>
> This condition still needs more checks (epilogue start index < 32, and I think
> also the epilogue needs to be at the end of the function).
Start index is not used in that place, it is not clear why it is requested to be checked.
As it was mentioned earlier, the epilogue at the end of the function does not use unwind codes
and it is not required to emit it as an epilogue scope.
> > + seh_aarch64_emit_epilogue_scopes (seh_ctx,
> > + fragment_offset,
> > + first_fragment_scope,
> > + last_fragment_scope);
> > + }
> > +
> > + if (code_words)
>
> code_words is always nonzero.
Ok, it will be removed for now.
> > +} seh_aarch64_except_info;
> > +
> > +typedef union seh_aarch64_unwind_info
> > +{
> > + seh_aarch64_except_info except_info;
> > + seh_aarch64_packed_unwind_data packed_unwind_data;
> > +} seh_aarch64_unwind_info;
>
> These three structs/unions are unused, so should be removed.
These structs/unions will be removed.
Regards,
Evgeny