diff options
author | Alan Modra <amodra@gmail.com> | 2020-08-31 11:14:31 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2020-08-31 20:28:10 +0930 |
commit | 1a211fc7d87dc92c2c91d24d0424d8f0485587f9 (patch) | |
tree | 3d7ab2f48076d53b42d1b9ca2ea10f504bad9c86 /bfd/mep-relocs.pl | |
parent | 108f6f97bd862e969f898c1347903ae1cf38ead4 (diff) | |
download | gdb-1a211fc7d87dc92c2c91d24d0424d8f0485587f9.zip gdb-1a211fc7d87dc92c2c91d24d0424d8f0485587f9.tar.gz gdb-1a211fc7d87dc92c2c91d24d0424d8f0485587f9.tar.bz2 |
PR26466 UBSAN: elf32-mep.c:300 left shift of negative value
PR 26466
* mep-relocs.pl (emit_apply): Handle HI16S adjustment. Use "u"
variable and rewrite signed overflow check.
* elf32-mep.c: Regenerate.
(mep_final_link_relocate): Delete "s".
Diffstat (limited to 'bfd/mep-relocs.pl')
-rwxr-xr-x | bfd/mep-relocs.pl | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/bfd/mep-relocs.pl b/bfd/mep-relocs.pl index 599ff64..544ee01 100755 --- a/bfd/mep-relocs.pl +++ b/bfd/mep-relocs.pl @@ -156,20 +156,23 @@ sub emit_apply { $e = '^e4' # endian swap for data } print NEW " case R_MEP_$relocs[$i]: /* $pattern[$i] */\n"; + if ($relocs[$i] =~ /HI16S/) { + print NEW " u += 0x8000;\n" + } if ($attrs[$i] =~ /tp-rel/i) { - print NEW " $v -= mep_tpoff_base(rel->r_offset);\n"; + print NEW " u -= mep_tpoff_base(rel->r_offset);\n"; } if ($attrs[$i] =~ /gp-rel/i) { - print NEW " $v -= mep_sdaoff_base(rel->r_offset);\n"; + print NEW " u -= mep_sdaoff_base(rel->r_offset);\n"; } if ($attrs[$i] !~ /no-overflow/ && $bits[$i] < 32) { if ($v eq "u") { $max = (1 << $bits[$i]) - 1; print NEW " if (u > $max) r = bfd_reloc_overflow;\n"; } else { - $min = -(1 << ($bits[$i]-1)); - $max = (1 << ($bits[$i]-1)) - 1; - print NEW " if ($min > s || s > $max) r = bfd_reloc_overflow;\n"; + $min = (1 << ($bits[$i]-1)); + $max = (1 << ($bits[$i])) - 1; + print NEW " if (u + $min > $max) r = bfd_reloc_overflow;\n"; } } for ($b=0; $b<length($pattern[$i]); $b += 8) { @@ -183,11 +186,11 @@ sub emit_apply { print NEW " byte[$bb$e] = "; print NEW "(byte[$bb$e] & 0x$rmask) | " if $rmask ne "00"; if ($left) { - print NEW "(($v << $left) & 0x$mask)"; + print NEW "((u << $left) & 0x$mask)"; } elsif ($right) { - print NEW "(($v >> $right) & 0x$mask)"; + print NEW "((u >> $right) & 0x$mask)"; } else { - print NEW "($v & 0x$mask)"; + print NEW "(u & 0x$mask)"; } print NEW ";\n"; } |