This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Commit: Fix unsigned vs signed comparisons in SH code
- From: Nick Clifton <nickc at redhat dot com>
- To: binutils at sourceware dot org
- Date: Tue, 26 Nov 2019 14:06:16 +0000
- Subject: Commit: Fix unsigned vs signed comparisons in SH code
Hi Guys,
It seems that recent versions of clang have a new warning that catches
code like this:
if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000)
So I am checking in the patch below to fix a couple of places where
this happens. There may be more, but I am not using the latest
version of clang myself.
Cheers
Nick
bfd/ChangeLog
2019-11-26 Nick Clifton <nickc@redhat.com>
* elf32-sh.c (sh_elf_reloc): Use a signed_vma when checking for a
negative relocated value.
* coff-sh.c (sh_reloc): Likewise.
diff --git a/bfd/coff-sh.c b/bfd/coff-sh.c
index 4b6b0de542..1077a20e6c 100644
--- a/bfd/coff-sh.c
+++ b/bfd/coff-sh.c
@@ -632,7 +632,7 @@ sh_reloc (bfd * abfd,
sym_value -= 0x1000;
insn = (insn & 0xf000) | (sym_value & 0xfff);
bfd_put_16 (abfd, (bfd_vma) insn, hit_data);
- if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000)
+ if ((bfd_signed_vma) sym_value < -0x1000 || sym_value >= 0x1000)
return bfd_reloc_overflow;
break;
default:
diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c
index 8aa49b099c..863e2e1bfc 100644
--- a/bfd/elf32-sh.c
+++ b/bfd/elf32-sh.c
@@ -288,7 +288,7 @@ sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
sym_value -= 0x1000;
insn = (insn & 0xf000) | (sym_value & 0xfff);
bfd_put_16 (abfd, (bfd_vma) insn, hit_data);
- if (sym_value < (bfd_vma) -0x1000 || sym_value >= 0x1000)
+ if ((bfd_signed_vma) sym_value < -0x1000 || sym_value >= 0x1000)
return bfd_reloc_overflow;
break;
default: