]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Re: Update objcopy's --section-alignment option
authorAlan Modra <amodra@gmail.com>
Thu, 4 Apr 2024 10:18:14 +0000 (20:48 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 4 Apr 2024 10:32:29 +0000 (21:02 +1030)
ubsan: left shift of 1 by 31 places cannot be represented in type 'int'

* objcopy.c (setup_section): Avoid undefined behaviour when
checking vma and lma for alignment.

binutils/objcopy.c

index 77ab908094652eda3ebbca77ee767eacb94e7011..d9abfdfbb39fdade7f2f2da0c192f02913126694 100644 (file)
@@ -4340,7 +4340,7 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
      and the VMA was not set by the user
      and the section does not have relocations associated with it
      then warn the user.  */
-  if (osection->vma & ((1 << alignment) - 1)
+  if ((osection->vma & (((bfd_vma) 1 << alignment) - 1)) != 0
       && alignment != bfd_section_alignment (isection)
       && change_section_address == 0
       && ! vma_set_by_user
@@ -4352,7 +4352,7 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
   /* Similar check for a non-aligned LMA.
      FIXME: Since this is only an LMA, maybe it does not matter if
      it is not aligned ?  */
-  if (osection->lma & ((1 << alignment) - 1)
+  if ((osection->lma & (((bfd_vma) 1 << alignment) - 1)) != 0
       && alignment != bfd_section_alignment (isection)
       && change_section_address == 0
       && ! lma_set_by_user