]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
LoongArch: ld: Fix hidden ifunc symbol linker error bug.
authormengqinggang <mengqinggang@loongson.cn>
Mon, 9 Jan 2023 08:35:26 +0000 (16:35 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Mon, 16 Jan 2023 01:05:46 +0000 (09:05 +0800)
For hidden ifunc symbols, it not have GOT entry, only have gotplt entry. When
process R_LARCH_SOP_PUSH_GPREL, the offset is gotplt entry address minus GOT
address. When call bfd_put_NN(got->contents + offset), the absolute value of
offset is grather than got size, and other memory not belonging to GOT is be
overwritten.

bfd/ChangeLog:

* elfnn-loongarch.c (loongarch_elf_relocate_section): If hidden ifunc
symbol, don't call bfd_put_NN.

bfd/elfnn-loongarch.c

index fafdc7c7458bed6207cf27503df03f99f231e6ad..449fad6d25df5645da3355bf7dc3c04a2d4d8f86 100644 (file)
@@ -2502,7 +2502,10 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
 
                  if ((off & 1) != 0)
                    off &= ~1;
-                 else
+                 /* If h has processed (h->got.offset |= 1) or h is hideen
+                    ifunc (h->got.offset == -1), skip it. Hidden ifunc symbol
+                    not has got entry, only has got.plt entry.  */
+                 else if ((h->got.offset & 1) == 0)
                    {
                      /* The pr21964-4. Create relocate entry.  */
                      if (is_pic && h->start_stop)