PR26445 UBSAN: elf32-csky.c:4115 left shift of negative value

PR 26445
	* elf32-csky.c (csky_relocate_contents): Make relocation a bfd_vma,
	and similarly for variables dealing with overflow.
This commit is contained in:
Alan Modra
2020-08-31 09:50:49 +09:30
parent 880fc278ca
commit f2173852cf
2 changed files with 18 additions and 12 deletions

View File

@ -1,3 +1,9 @@
2020-08-31 Alan Modra <amodra@gmail.com>
PR 26445
* elf32-csky.c (csky_relocate_contents): Make relocation a bfd_vma,
and similarly for variables dealing with overflow.
2020-08-31 Alan Modra <amodra@gmail.com> 2020-08-31 Alan Modra <amodra@gmail.com>
PR 26442 PR 26442

View File

@ -3918,7 +3918,7 @@ elf32_csky_setup_section_lists (bfd *output_bfd,
static bfd_reloc_status_type static bfd_reloc_status_type
csky_relocate_contents (reloc_howto_type *howto, csky_relocate_contents (reloc_howto_type *howto,
bfd *input_bfd, bfd *input_bfd,
long relocation, bfd_vma relocation,
bfd_byte *location) bfd_byte *location)
{ {
int size; int size;
@ -3961,7 +3961,7 @@ csky_relocate_contents (reloc_howto_type *howto,
if (R_CKCORE_DOFFSET_LO16 == howto->type) if (R_CKCORE_DOFFSET_LO16 == howto->type)
{ {
if ((signed) relocation < 0) if ((bfd_signed_vma) relocation < 0)
{ {
x |= CSKY_INSN_ADDI_TO_SUBI; x |= CSKY_INSN_ADDI_TO_SUBI;
relocation = -relocation; relocation = -relocation;
@ -3972,7 +3972,7 @@ csky_relocate_contents (reloc_howto_type *howto,
} }
else if (R_CKCORE_TOFFSET_LO16 == howto->type) else if (R_CKCORE_TOFFSET_LO16 == howto->type)
{ {
if ((signed) relocation < 0) if ((bfd_signed_vma) relocation < 0)
{ {
x |= CSKY_INSN_ADDI_TO_SUBI; x |= CSKY_INSN_ADDI_TO_SUBI;
relocation = -relocation; relocation = -relocation;
@ -3993,13 +3993,13 @@ csky_relocate_contents (reloc_howto_type *howto,
flag = bfd_reloc_ok; flag = bfd_reloc_ok;
if (howto->complain_on_overflow != complain_overflow_dont) if (howto->complain_on_overflow != complain_overflow_dont)
{ {
int addrmask; bfd_vma addrmask;
int fieldmask; bfd_vma fieldmask;
int signmask; bfd_vma signmask;
int ss; bfd_vma ss;
int a; bfd_vma a;
int b; bfd_vma b;
int sum; bfd_vma sum;
/* Get the values to be added together. For signed and unsigned /* Get the values to be added together. For signed and unsigned
relocations, we assume that all values should be truncated to relocations, we assume that all values should be truncated to
the size of an address. For bitfields, all the bits matter. the size of an address. For bitfields, all the bits matter.
@ -4085,7 +4085,7 @@ csky_relocate_contents (reloc_howto_type *howto,
} }
/* Put RELOCATION in the right bits. */ /* Put RELOCATION in the right bits. */
relocation >>= (bfd_vma) rightshift; relocation >>= rightshift;
if ((howto->type == R_CKCORE_DOFFSET_LO16 if ((howto->type == R_CKCORE_DOFFSET_LO16
|| howto->type == R_CKCORE_TOFFSET_LO16) || howto->type == R_CKCORE_TOFFSET_LO16)
@ -4112,7 +4112,7 @@ csky_relocate_contents (reloc_howto_type *howto,
csky_put_insn_32 (input_bfd, CSKY_INSN_JSR_R26, location + 4); csky_put_insn_32 (input_bfd, CSKY_INSN_JSR_R26, location + 4);
} }
relocation <<= (bfd_vma) bitpos; relocation <<= bitpos;
/* Add RELOCATION to the right bits of X. */ /* Add RELOCATION to the right bits of X. */
x = ((x & ~howto->dst_mask) x = ((x & ~howto->dst_mask)
| (((x & howto->src_mask) + relocation) & howto->dst_mask)); | (((x & howto->src_mask) + relocation) & howto->dst_mask));