]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd: Fix left shift of negative value.
authorDominik Vogt <vogt@linux.vnet.ibm.com>
Mon, 9 Nov 2015 16:12:56 +0000 (17:12 +0100)
committerAndreas Krebbel <krebbel@linux.vnet.ibm.com>
Mon, 9 Nov 2015 16:12:56 +0000 (17:12 +0100)
This patch fixes all occurences of left-shifting negative constants in C code
which is undefined by the C standard.

bfd/ChangeLog:

        * elf64-ppc.c (ppc64_elf_size_stubs, ppc64_elf_build_stubs): Fix left
        shift of negative value.
        * libbfd.c (safe_read_leb128): Likewise.
        * dwarf2.c (place_sections): Likewise.
        * bfd-in.h (align_power): Likewise.
        * bfd-in2.h (align_power): Likewise.

bfd/ChangeLog
bfd/bfd-in.h
bfd/bfd-in2.h
bfd/dwarf2.c
bfd/elf64-ppc.c
bfd/libbfd.c

index 57ea3c1af943900bd9781353385dd711ad5e8d50..60d13b9daabcee5f949c33e4adab3c98f9b1e8f2 100644 (file)
@@ -1,3 +1,12 @@
+2015-11-09  Dominik Vogt  <vogt@linux.vnet.ibm.com>
+
+       * elf64-ppc.c (ppc64_elf_size_stubs, ppc64_elf_build_stubs): Fix left
+       shift of negative value.
+       * libbfd.c (safe_read_leb128): Likewise.
+       * dwarf2.c (place_sections): Likewise.
+       * bfd-in.h (align_power): Likewise.
+       * bfd-in2.h (align_power): Likewise.
+
 2015-10-30  Nick Clifton  <nickc@redhat.com>
 
        * po/zh_CN.po: Updated (simplified) Chinese translation.
index 9e40df5713ca477aa0dee4a0bd5c17ede092fb26..1721ce7003d4a76953793b002583997e438e3cb0 100644 (file)
@@ -272,7 +272,7 @@ alent;
 /* Object and core file sections.  */
 
 #define        align_power(addr, align)        \
-  (((addr) + ((bfd_vma) 1 << (align)) - 1) & ((bfd_vma) -1 << (align)))
+  (((addr) + ((bfd_vma) 1 << (align)) - 1) & (-((bfd_vma) 1 << (align))))
 
 typedef struct bfd_section *sec_ptr;
 
index e2e247da28a41547ca8ba40faa836285928f8c59..900b45cfb8526301eb2c195dfea4f04c05d3d002 100644 (file)
@@ -279,7 +279,7 @@ alent;
 /* Object and core file sections.  */
 
 #define        align_power(addr, align)        \
-  (((addr) + ((bfd_vma) 1 << (align)) - 1) & ((bfd_vma) -1 << (align)))
+  (((addr) + ((bfd_vma) 1 << (align)) - 1) & (-((bfd_vma) 1 << (align))))
 
 typedef struct bfd_section *sec_ptr;
 
index cbd4cf64869f47a400151d7976b6b3525b212c5e..401ec43a7cedc53afe053b9f674c00e359905bce 100644 (file)
@@ -3354,8 +3354,8 @@ place_sections (bfd *orig_bfd, struct dwarf2_debug *stash)
                  /* Align the new address to the current section
                     alignment.  */
                  last_vma = ((last_vma
-                              + ~((bfd_vma) -1 << sect->alignment_power))
-                             & ((bfd_vma) -1 << sect->alignment_power));
+                              + ~(-((bfd_vma) 1 << sect->alignment_power)))
+                             & (-((bfd_vma) 1 << sect->alignment_power)));
                  sect->vma = last_vma;
                  last_vma += sz;
                }
index cda8e592cd8060336349bd535f292c2c63032a65..0a85ab88df7023eb2b2244e537253c97d7b59128 100644 (file)
@@ -12497,7 +12497,7 @@ ppc64_elf_size_stubs (struct bfd_link_info *info)
          if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
            stub_sec->size = ((stub_sec->size
                               + (1 << htab->params->plt_stub_align) - 1)
-                             & (-1 << htab->params->plt_stub_align));
+                             & -(1 << htab->params->plt_stub_align));
 
       for (stub_sec = htab->params->stub_bfd->sections;
           stub_sec != NULL;
@@ -13021,7 +13021,7 @@ ppc64_elf_build_stubs (struct bfd_link_info *info,
       if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
        stub_sec->size = ((stub_sec->size
                           + (1 << htab->params->plt_stub_align) - 1)
-                         & (-1 << htab->params->plt_stub_align));
+                         & -(1 << htab->params->plt_stub_align));
 
   for (stub_sec = htab->params->stub_bfd->sections;
        stub_sec != NULL;
index 40afc2db5b325fc16e05451dfaabda1bc0763257..69582d5a860217639574aa4d8d3e4f67146db90d 100644 (file)
@@ -1037,7 +1037,7 @@ safe_read_leb128 (bfd *abfd ATTRIBUTE_UNUSED,
     *length_return = num_read;
 
   if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
-    result |= (bfd_vma) -1 << shift;
+    result |= -((bfd_vma) 1 << shift);
 
   return result;
 }