elf: Verify section size for mixed ordered/unordered inputs
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 9 Jan 2021 05:38:39 +0000 (21:38 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 9 Jan 2021 05:38:51 +0000 (21:38 -0800)
When fixing up SHF_LINK_ORDER, issue a fatal error if the output section
size is increased.  Otherwise, bfd_set_section_contents will fail later
when attempting to write contents past the end of the output section.

PR ld/26256
PR ld/27160
* elflink.c (elf_fixup_link_order): Verify that fixing up
SHF_LINK_ORDER doesn't increase the output section size.

bfd/ChangeLog
bfd/elflink.c

index baf6af94bb4418b2fb42c862c5c74eede8f534d1..86fec902024584916ae5bfa25ffa1e834a7ac7b4 100644 (file)
@@ -1,3 +1,10 @@
+2021-01-08  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/26256
+       PR ld/27160
+       * elflink.c (elf_fixup_link_order): Verify that fixing up
+       SHF_LINK_ORDER doesn't increase the output section size.
+
 2021-01-09  Alan Modra  <amodra@gmail.com>
 
        * configure: Regenerate.
index a7c952b6fc1b09665722ce5a933275e5b642ac25..acc959d526a9adecb8314ddfbae560a6922ff080 100644 (file)
@@ -12039,6 +12039,14 @@ elf_fixup_link_order (struct bfd_link_info *info, bfd *abfd, asection *o)
       offset = sections[n]->offset + sections[n]->size;
 
   free (sections);
+
+  /* Verify that fixing up SHF_LINK_ORDER doesn't increase the section
+     size.  */
+  if (offset > o->size)
+    info->callbacks->einfo
+      (_("%F%P: %pA has ordered sections with incompatible alignments\n"),
+       o);
+
   return TRUE;
 }