[PATCH v6 1/4] Adjust pdata function table entries sorting for AArch64

Alice Carlotti alice.carlotti@arm.com
Fri Mar 13 17:31:08 GMT 2026


On Wed, Mar 11, 2026 at 03:11:43PM +0100, Evgeny Karpov wrote:
> The .pdata section contains an array of function table entries that
> are used for exception handling. The entries should be sorted by
> begin address, which is usually the first 4 bytes RVA in the entry.
> Entry sizes are different for x64 and AArch64.
> This difference is addressed in this patch.
> 
> This is the first patch in the patch series implementing
> Structured Exception Handling (SEH) for aarch64-w64-mingw32.
> 
> Co-authored-by: Zac Walker <zacwalker@microsoft.com>
> Co-authored-by: Ron Riddle <ron.riddle@microsoft.com>
> Signed-off-by: Evgeny Karpov <evgeny@kmaps.co>
> 
> bfd/ChangeLog:
> 
> 	* peXXigen.c (defined): Use function_table_entry_size.
> ---
>  bfd/peXXigen.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
> index 2ab0dd50bf4..36135582786 100644
> --- a/bfd/peXXigen.c
> +++ b/bfd/peXXigen.c
> @@ -4724,9 +4724,21 @@ _bfd_XXi_final_link_postscript (bfd * abfd, struct coff_final_link_info *pfinfo)
>  
>  	if (bfd_malloc_and_get_section (abfd, sec, &tmp_data))
>  	  {
> +	    /* The size of a .pdata entry that describes a function that is used
> +	       for exception handling.  */
> +	    unsigned function_table_entry_size;
> +#if defined (COFF_WITH_peAArch64)
> +	    /* https://learn.microsoft.com/en-us/cpp/build/arm64-exception-handling#pdata-records.  */
> +	    function_table_entry_size = 8;
> +#else
> +	    /* https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#the-pdata-section.  */
> +	    function_table_entry_size = 12;
> +#endif
> +	    /* .pdata entries should be sorted by the function start
> +	       address.  */
>  	    qsort (tmp_data,
> -		   (size_t) (x / 12),
> -		   12, sort_x64_pdata);
> +		   (size_t) (x / function_table_entry_size),
> +		   function_table_entry_size, sort_x64_pdata);

I think sort_x64_pdata should be renamed to sort_pdata, but this otherwise
looks fine to me.

Alice

>  	    bfd_set_section_contents (pfinfo->output_bfd, sec,
>  				      tmp_data, 0, x);
>  	    free (tmp_data);


More information about the Binutils mailing list