diff options
author | Xi Ruoyao <xry111@xry111.site> | 2022-09-20 14:09:29 +0800 |
---|---|---|
committer | WANG Xuerui <git@xen0n.name> | 2022-10-08 18:12:07 +0800 |
commit | 3b8cf95f16b3fe3e9bdd7c281f00ae16e83d38c9 (patch) | |
tree | 9aaf1463432b56e180dcd6653ef7dc2c94fc507a | |
parent | LoongArch: fix gas BFD_RELOC_8/16/24 bug (diff) | |
download | binutils-gdb-3b8cf95f16b3fe3e9bdd7c281f00ae16e83d38c9.tar.gz binutils-gdb-3b8cf95f16b3fe3e9bdd7c281f00ae16e83d38c9.tar.bz2 binutils-gdb-3b8cf95f16b3fe3e9bdd7c281f00ae16e83d38c9.zip |
LoongArch: Don't write into GOT for local ifunc
Local ifuncs are always resolved at runtime via R_LARCH_IRELATIVE, so
there is no need to write anything into GOT. And when we write the GOT
we actually trigger a heap-buffer-overflow: If a and b are different
sections, we cannot access something in b with "a->contents + (offset
from a)" because "a->contents" and "b->contents" are heap buffers
allocated separately, not slices of a large buffer.
So stop writing into GOT for local ifunc now.
(cherry picked from commit 6224a6c2ead26a04f0b2b8ccf4ff5b817afbb425)
-rw-r--r-- | bfd/elfnn-loongarch.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c index ed42b8b6770..af18a8a0168 100644 --- a/bfd/elfnn-loongarch.c +++ b/bfd/elfnn-loongarch.c @@ -3179,6 +3179,8 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, htab->elf.srelgot, &rela); } h->got.offset |= 1; + bfd_put_NN (output_bfd, relocation, + got->contents + got_off); } } else @@ -3200,10 +3202,9 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, } local_got_offsets[r_symndx] |= 1; } + bfd_put_NN (output_bfd, relocation, got->contents + got_off); } - bfd_put_NN (output_bfd, relocation, got->contents + got_off); - relocation = got_off + sec_addr (got); } |