PE linker segmentation fault with MALLOC_PERTURB_=1
authorAlan Modra <amodra@gmail.com>
Tue, 28 May 2019 10:42:32 +0000 (20:12 +0930)
committerAlan Modra <amodra@gmail.com>
Tue, 28 May 2019 11:17:14 +0000 (20:47 +0930)
PR 24596
* emultempl/pe.em (gld_${EMULATION_NAME}_after_open): Check that
the output is coff before accessing coff tdata.
* emultempl/pep.em (gld_${EMULATION_NAME}_after_open): Likewise.

ld/ChangeLog
ld/emultempl/pe.em
ld/emultempl/pep.em

index 581be2e4c8d4a8ce4972012e76fdce8de4709890..52d89ecd7a6373f9ad9289a67bd91e13890d50fd 100644 (file)
@@ -1,3 +1,10 @@
+2019-05-28  Alan Modra  <amodra@gmail.com>
+
+       PR 24596
+       * emultempl/pe.em (gld_${EMULATION_NAME}_after_open): Check that
+       the output is coff before accessing coff tdata.
+       * emultempl/pep.em (gld_${EMULATION_NAME}_after_open): Likewise.
+
 2019-05-28  Szabolcs Nagy  <szabolcs.nagy@arm.com>
 
        * testsuite/ld-aarch64/variant_pcs-now.d: Use --hash-style=sysv.
index 10bacbcc870dcf2121d446eeddd94a2fb1c47af2..218f98acf90360053237405400d1d1973b835cc6 100644 (file)
@@ -1360,7 +1360,8 @@ gld_${EMULATION_NAME}_after_open (void)
      FIXME: This should be done via a function, rather than by
      including an internal BFD header.  */
 
-  if (coff_data (link_info.output_bfd) == NULL
+  if (bfd_get_flavour (link_info.output_bfd) != bfd_target_coff_flavour
+      || coff_data (link_info.output_bfd) == NULL
       || coff_data (link_info.output_bfd)->pe == 0)
     einfo (_("%F%P: cannot perform PE operations on non PE output file '%pB'\n"),
           link_info.output_bfd);
index c0070c0fbef3f7a7089b08acf07d613877fb2be1..649efaf92c399c8ad473272a8ce8c971fb1b7818 100644 (file)
@@ -1348,7 +1348,8 @@ gld_${EMULATION_NAME}_after_open (void)
      FIXME: This should be done via a function, rather than by
      including an internal BFD header.  */
 
-  if (coff_data (link_info.output_bfd) == NULL
+  if (bfd_get_flavour (link_info.output_bfd) != bfd_target_coff_flavour
+      || coff_data (link_info.output_bfd) == NULL
       || coff_data (link_info.output_bfd)->pe == 0)
     einfo (_("%F%P: cannot perform PE operations on non PE output file '%pB'\n"),
           link_info.output_bfd);