Index: src/bfd/peXXigen.c =================================================================== --- src.orig/bfd/peXXigen.c 2010-09-07 21:55:15.000000000 +0200 +++ src/bfd/peXXigen.c 2010-09-11 12:07:59.864985700 +0200 @@ -2256,6 +2256,26 @@ _bfd_XX_get_symbol_info (bfd * abfd, asy coff_get_symbol_info (abfd, symbol, ret); } +#if !defined(COFF_WITH_pep) && defined(COFF_WITH_pex64) +static int +sort_x64_pdata (const void *l, const void *r) +{ + const void *lp = ((const void *) l); + const void *rp = ((const void *) r); + bfd_vma vl, vr; + vl = bfd_getl32 (lp); vr = bfd_getl32 (rp); + if (vl != vr) + return (vl < vr ? -1 : 1); + vl = bfd_getl32 (lp + 4); vr = bfd_getl32 (rp + 4); + if (vl != vr) + return (vl < vr ? -1 : 1); + vl = bfd_getl32 (lp + 8); vr = bfd_getl32 (rp + 8); + if (vl != vr) + return (vl < vr ? -1 : 1); + return 0; +} +#endif + /* Handle the .idata section and other things that need symbol table access. */ @@ -2265,6 +2285,9 @@ _bfd_XXi_final_link_postscript (bfd * ab struct coff_link_hash_entry *h1; struct bfd_link_info *info = pfinfo->info; bfd_boolean result = TRUE; +#if !defined(COFF_WITH_pep) && defined(COFF_WITH_pex64) + asection *sec; +#endif /* There are a few fields that need to be filled in now while we have symbol table access. @@ -2383,6 +2406,28 @@ _bfd_XXi_final_link_postscript (bfd * ab pe_data (abfd)->pe_opthdr.DataDirectory[PE_TLS_TABLE].Size = 0x18; } +/* If there is a .pdata section and we have linked pdata finally, we + need to sort the entries ascending. */ +#if !defined(COFF_WITH_pep) && defined(COFF_WITH_pex64) + sec = bfd_get_section_by_name (abfd, ".pdata"); + if (sec) + { + unsigned char *contents = NULL; + bfd_size_type x = sec->rawsize ? sec->rawsize : sec->size; + + if (!x || !bfd_get_section_contents (abfd, sec, pfinfo->contents, 0, x)) + contents = NULL; + else + contents = pfinfo->contents; + + if (contents && x != 0) + { + qsort (contents, (size_t) ((sec->size size : x) / 12), 12, sort_x64_pdata); + bfd_set_section_contents (pfinfo->output_bfd, sec, contents, 0, x); + } + } +#endif + /* If we couldn't find idata$2, we either have an excessively trivial program or are in DEEP trouble; we have to assume trivial program.... */