Don't include coff/pe.h in coff-x86_64.c
authorAlan Modra <amodra@gmail.com>
Sat, 30 Oct 2021 23:38:15 +0000 (10:08 +1030)
committerAlan Modra <amodra@gmail.com>
Sun, 31 Oct 2021 01:12:52 +0000 (11:42 +1030)
commit590abc168fb25908cde1df89f4905b575c14e55d
tree7acf9238680c5b56af5602ecc69930961ccf128c
parent1c5e9d8d8cfdc4528ec4713dc6001e8b66c28134
Don't include coff/pe.h in coff-x86_64.c

This (and other) code from coffcode.h is broken for x86_64_coff_vec,
and has been ever since support was added in 2006 commit 99ad839030c1
Here, bfd_coff_aoutsz must match coff_swap_aouthdr_out otherwise we
end up writing garbage.

      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
 include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
      char * buff;
      bfd_size_type amount = bfd_coff_aoutsz (abfd);

      buff = (char *) bfd_malloc (amount);
      if (buff == NULL)
return false;

      coff_swap_aouthdr_out (abfd, & internal_a, buff);
      amount = bfd_bwrite (buff, amount, abfd);

We have removed support for --target=x86_64-coff, likely because it
never worked properly, but still produce coff-x86_64.o with
--enable-targets=all.  This means objcopy can recognize x86_64 COFF
files but will write garbage to the output file, a fact found by
fuzzers.  I suspect x86_64 COFF is still broken after this fix, and
mention of coff-x86_64.* should be removed from bfd/Makefile.am.

* coff-x86_64.c: Don't include coff/pe.h.
(COFF_WITH_pex64): Don't define here.
* pe-x86_64.c: Include coff/pe.h and other headers.
(PEI_HEADERS): Define.
bfd/coff-x86_64.c
bfd/pe-x86_64.c