This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/7] Fix invalid left shift of negative value.


On Fri, Oct 30, 2015 at 03:38:15PM +0100, Dominik Vogt wrote:
> The following series of patches fixes all occurences of
> left-shifting negative constants in C code which is undefined by
> the C standard.  The patches have been tested on s390x, covering
> only a small subset of the changes.

Changes in bfd/.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

Attachment: 0001-ChangeLog
Description: Text document

>From 92432c3f068acb9528fc340da340b78bf8b6564f Mon Sep 17 00:00:00 2001
From: Dominik Vogt <vogt@linux.vnet.ibm.com>
Date: Fri, 30 Oct 2015 15:11:28 +0100
Subject: [PATCH 1/7] bfd: Fix left shift of negative value.

---
 bfd/bfd-in.h    | 2 +-
 bfd/bfd-in2.h   | 2 +-
 bfd/dwarf2.c    | 4 ++--
 bfd/elf64-ppc.c | 4 ++--
 bfd/libbfd.c    | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index 9e40df5..1721ce7 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -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;
 
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index e2e247d..900b45c 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -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;
 
diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
index cbd4cf6..401ec43 100644
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -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;
 		}
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index cda8e59..0a85ab8 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -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;
diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index 40afc2d..69582d5 100644
--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -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;
 }
-- 
2.3.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]