[binutils-gdb] Adjust pdata function table entries sorting for AArch64
Jan Beulich via Binutils-cvs <[email protected]>
| Newsgroups | gmane.comp.gnu.binutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8270bb3d68f96b34253feed2b54f27ea553c9364 commit 8270bb3d68f96b34253feed2b54f27ea553c9364 Author: Evgeny Karpov <[email protected]> Date: Fri Mar 20 14:09:33 2026 +0100 Adjust pdata function table entries sorting for AArch64 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 <[email protected]> Co-authored-by: Ron Riddle <[email protected]> Signed-off-by: Evgeny Karpov <[email protected]> bfd/ * peXXigen.c (sort_x64_pdata): Rename from this ... (sort_pdata): ... to this. (defined): Use function_table_entry_size. Diff: --- bfd/peXXigen.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c index 2ab0dd50bf4..bdb23dcbcab 100644 --- a/bfd/peXXigen.c +++ b/bfd/peXXigen.c @@ -3169,7 +3169,7 @@ _bfd_XX_get_symbol_info (bfd * abfd, asymbol *symbol, symbol_info *ret) #if !defined(COFF_WITH_pep) && (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64)) static int -sort_x64_pdata (const void *l, const void *r) +sort_pdata (const void *l, const void *r) { const char *lp = (const char *) l; const char *rp = (const char *) r; @@ -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_pdata); bfd_set_section_contents (pfinfo->output_bfd, sec, tmp_data, 0, x); free (tmp_data);