diff --git a/bfd/ChangeLog b/bfd/ChangeLog index c4a83dfe4f7..8293e9d7952 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2021-05-06 Stafford Horne + + PR 21464 + * elf32-or1k.c (or1k_elf_relocate_section): Relax R_OR1K_GOT16 + overflow check if we have R_OR1K_GOT_AHI16 followed by + R_OR1K_GOT16. + 2021-05-06 Stafford Horne PR 21464 diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c index 1b8938df37f..5eca4300c45 100644 --- a/bfd/elf32-or1k.c +++ b/bfd/elf32-or1k.c @@ -1278,6 +1278,7 @@ or1k_elf_relocate_section (bfd *output_bfd, asection *sgot, *splt; bfd_vma plt_base, got_base, got_sym_value; bool ret_val = true; + bool saw_gotha = false; if (htab == NULL) return false; @@ -1485,6 +1486,16 @@ or1k_elf_relocate_section (bfd *output_bfd, || r_type == R_OR1K_GOT_AHI16) relocation -= got_sym_value; + if (r_type == R_OR1K_GOT_AHI16) + saw_gotha = true; + + /* If we have a R_OR1K_GOT16 followed by a R_OR1K_GOT_AHI16 + relocation we assume the code is doing the right thing to avoid + overflows. Here we mask the lower 16-bit of the relocation to + avoid overflow validation failures. */ + if (r_type == R_OR1K_GOT16 && saw_gotha) + relocation &= 0xffff; + /* Addend should be zero. */ if (rel->r_addend != 0) {