[PATCH v6 4/4] aarch64: Emit pdata/xdata SEH records from md_finish

Alice Carlotti alice.carlotti@arm.com
Fri Mar 13 18:50:29 GMT 2026


On Wed, Mar 11, 2026 at 03:11:46PM +0100, Evgeny Karpov wrote:
> Initially, obj_coff_generate_pdata was declared 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
> obj_coff_generate_pdata to emit .pdata/.xdata records after all
> assembly has been completed.

It looks like you now call obj_coff_generate_pdata twice - once in
write_object_file and once in aarch64_md_finish?  That seems unintuitive,
although I see that

+  if (!seh_ctx_root)
+    return;
+
+  struct seh_aarch64_context *seh_ctx = seh_ctx_root;
+  seh_ctx_root = NULL;

makes the second call effectively a nop - this definitely justifies a comment
to explain what's going on.  However, it feels like there should be a better
way of doing this - e.g. by making early generation a separate hook.  

Also, should this be part of patch 3/4?  It doesn't seem to make sense as a
standalone change.

Alice

> 
> Signed-off-by: Evgeny Karpov <evgeny@kmaps.co>
> 
> gas/ChangeLog:
> 
> 	* config/tc-aarch64.c (defined): Add OBJ_COFF guard.
> 	(aarch64_md_finish): Add.
> 	* config/tc-aarch64.h (defined): Add OBJ_COFF guard.
> 	(md_finish): Add.
> 	(aarch64_md_finish): Add.
> ---
>  gas/config/tc-aarch64.c | 12 ++++++++++++
>  gas/config/tc-aarch64.h |  5 +++++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
> index cd76163488c..a17292832d5 100644
> --- a/gas/config/tc-aarch64.c
> +++ b/gas/config/tc-aarch64.c
> @@ -10375,6 +10375,18 @@ aarch64_cleanup (void)
>      }
>  }
>  
> +#if defined (OBJ_COFF)
> +/* Called after all assembly has been done.  */
> +
> +void
> +aarch64_md_finish (void)
> +{
> +#ifdef obj_coff_generate_pdata
> +  obj_coff_generate_pdata ();
> +#endif
> +}
> +#endif /* OBJ_COFF.  */
> +
>  #ifdef OBJ_ELF
>  /* Remove any excess mapping symbols generated for alignment frags in
>     SEC.  We may have created a mapping symbol before a zero byte
> diff --git a/gas/config/tc-aarch64.h b/gas/config/tc-aarch64.h
> index d1fb4c9058b..79ce8d773fc 100644
> --- a/gas/config/tc-aarch64.h
> +++ b/gas/config/tc-aarch64.h
> @@ -82,6 +82,11 @@ struct aarch64_fix
>  
>  #define tc_frob_section(S) aarch64_frob_section (S)
>  
> +#if defined (OBJ_COFF)
> +#define md_finish aarch64_md_finish
> +extern void aarch64_md_finish (void);
> +#endif
> +
>  /* The key used to sign a function's return address.  */
>  enum pointer_auth_key {
>    AARCH64_PAUTH_KEY_A,


More information about the Binutils mailing list