[PATCH v3 1/7] Adjust pdata function table entries sorting for AArch64

Saurabh Jha saurabh.jha@arm.com
Thu Aug 14 13:12:39 GMT 2025



On 8/14/2025 8:53 AM, 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-author:
> Zac Walker <zacwalker@microsoft.com>
> 
> Contributor:
> Ron Riddle <ron.riddle@microsoft.com>
> 
> Validated by
> Martin Vejbora <martin.vejbora@microsoft.com>
> Radek Barton <radek.barton@microsoft.com> and
> Evgeny Karpov <evgeny@kmaps.co>
> 
> bfd/ChangeLog:
> 
> 	* peXXigen.c (defined): New.
> 	(_bfd_XXi_final_link_postscript): Use
> 	FUNCTION_TABLE_ENTRY_SIZE.
> ---
>   bfd/peXXigen.c | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
> index c337fc5b282..147b1cb0be2 100644
> --- a/bfd/peXXigen.c
> +++ b/bfd/peXXigen.c
> @@ -4706,6 +4706,13 @@ _bfd_XXi_final_link_postscript (bfd * abfd,
> struct coff_final_link_info *pfinfo)
>   #if !defined(COFF_WITH_pep) && (defined(COFF_WITH_pex64) ||
> defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64) ||
> defined (COFF_WITH_peRiscV64))
>     {
>       asection *sec = bfd_get_section_by_name (abfd, ".pdata");
> +#if defined (COFF_WITH_peAArch64)
> +/* https://learn.microsoft.com/en-us/cpp/build/arm64-exception-handling#pdata-records.
> */
> +  #define FUNCTION_TABLE_ENTRY_SIZE 8
> +#else
> +/* https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#the-pdata-section.
> */
> +  #define FUNCTION_TABLE_ENTRY_SIZE 12
> +#endif
If this is being used at only one place, shouldn't we just have this if 
statement along with a local variable inside _bfd_XXi_final_link_postscript?

If you are defining it here more for readability, maybe a single line 
comment explaining the purpose of this might be helpful. The name is 
descriptive enough but a comment explaining the context where it will be 
used.
> 
>       if (sec)
>         {
> @@ -4715,8 +4722,8 @@ _bfd_XXi_final_link_postscript (bfd * abfd,
> struct coff_final_link_info *pfinfo)
>   	if (bfd_malloc_and_get_section (abfd, sec, &tmp_data))
>   	  {
>   	    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);
>   	    bfd_set_section_contents (pfinfo->output_bfd, sec,
>   				      tmp_data, 0, x);
>   	    free (tmp_data);



More information about the Binutils mailing list