From 8f383897b69c58e02bc447b3c0813361f04bdc1e Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 31 Aug 2020 08:09:23 +0930 Subject: [PATCH] mn10300: ubsan: shift exponent too large * elf-m10300.c (mn10300_elf_relax_delete_bytes): Calculate alignment from reloc addend after reloc type R_MN10300_ALIGN is found. --- bfd/ChangeLog | 6 ++++++ bfd/elf-m10300.c | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 31c74bf8bee..5d004cd7df0 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2020-08-31 Alan Modra + + * elf-m10300.c (mn10300_elf_relax_delete_bytes): Calculate + alignment from reloc addend after reloc type R_MN10300_ALIGN is + found. + 2020-08-30 Alan Modra PR 26435 diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c index 7c63ce4cd12..7a2b67569b0 100644 --- a/bfd/elf-m10300.c +++ b/bfd/elf-m10300.c @@ -2418,17 +2418,19 @@ mn10300_elf_relax_delete_bytes (bfd *abfd, are deleting. */ for (; irel < irelend; irel++) { - int alignment = 1 << irel->r_addend; - if (ELF32_R_TYPE (irel->r_info) == (int) R_MN10300_ALIGN && irel->r_offset > addr - && irel->r_offset < toaddr - && (count < alignment - || alignment % count != 0)) + && irel->r_offset < toaddr) { - irelalign = irel; - toaddr = irel->r_offset; - break; + int alignment = 1 << irel->r_addend; + + if (count < alignment + || alignment % count != 0) + { + irelalign = irel; + toaddr = irel->r_offset; + break; + } } } } -- 2.30.2