PR25444, Floating point exception in _bfd_elf_compute_section_file_positions
authorAlan Modra <amodra@gmail.com>
Thu, 23 Jan 2020 01:05:51 +0000 (11:35 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 23 Jan 2020 09:23:25 +0000 (19:53 +1030)
PR 25444
* elf.c (assign_file_positions_for_load_sections): Avoid divide
by zero when p_align is zero.

bfd/ChangeLog
bfd/elf.c

index 635932462b8b48d32fdd2efba239e01893e8a70f..97f5384be398a6eab5e478c61fb7cd168ed67a39 100644 (file)
@@ -1,3 +1,9 @@
+2020-01-23  Alan Modra  <amodra@gmail.com>
+
+       PR 25444
+       * elf.c (assign_file_positions_for_load_sections): Avoid divide
+       by zero when p_align is zero.
+
 2020-01-22  Maxim Blinov  <maxim.blinov@embecosm.com>
 
        * bfd/elfnn-riscv.c (riscv_skip_prefix): New.
index 08aaab644a821b75c984fa6c9f01345a0d0afb0a..a8d98a60f4eac8b670ac52900c5f8887f49f2ba4 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -5755,11 +5755,17 @@ assign_file_positions_for_load_sections (bfd *abfd,
            {
              p->p_offset = off;
              if (no_contents)
-               /* Put meaningless p_offset for PT_LOAD segments
-                  without file contents somewhere within the first
-                  page, in an attempt to not point past EOF.  */
-               p->p_offset = off % (p->p_align > maxpagesize
-                                    ? p->p_align : maxpagesize);
+               {
+                 /* Put meaningless p_offset for PT_LOAD segments
+                    without file contents somewhere within the first
+                    page, in an attempt to not point past EOF.  */
+                 bfd_size_type align = maxpagesize;
+                 if (align < p->p_align)
+                   align = p->p_align;
+                 if (align < 1)
+                   align = 1;
+                 p->p_offset = off % align;
+               }
            }
          else
            {