From 29f628db8835fd86b85ffb40d4a9ed5b1c28f1e6 Mon Sep 17 00:00:00 2001 From: Dominik Vogt Date: Mon, 9 Nov 2015 17:12:56 +0100 Subject: [PATCH] bfd: Fix left shift of negative value. 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 | 9 +++++++++ bfd/bfd-in.h | 2 +- bfd/bfd-in2.h | 2 +- bfd/dwarf2.c | 4 ++-- bfd/elf64-ppc.c | 4 ++-- bfd/libbfd.c | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 57ea3c1af9..60d13b9daa 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,12 @@ +2015-11-09 Dominik Vogt + + * 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 * po/zh_CN.po: Updated (simplified) Chinese translation. diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index 9e40df5713..1721ce7003 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 e2e247da28..900b45cfb8 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 cbd4cf6486..401ec43a7c 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 cda8e592cd..0a85ab88df 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 40afc2db5b..69582d5a86 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; }