LoongArch: Fix PLT entry generate bug
authormengqinggang <mengqinggang@loongson.cn>
Thu, 11 May 2023 10:03:54 +0000 (18:03 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Mon, 15 May 2023 01:22:27 +0000 (09:22 +0800)
If a function symbol only get its address by la.global, without
directly called by bl instruction, the PLT entry is not required.

bfd/ChangeLog:

* elfnn-loongarch.c (loongarch_elf_adjust_dynamic_symbol): Fix PLT
entry generate bug.

ld/ChangeLog:

* testsuite/ld-elf/shared.exp: Clear xfail for LoongArch.

bfd/elfnn-loongarch.c
ld/testsuite/ld-elf/shared.exp

index b0f9b6ec69e01a1b5ec8129b303138eb00663d5a..3fb74edb45c143e70e45458846c3d8d901e63ba4 100644 (file)
@@ -980,7 +980,7 @@ loongarch_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
      (although we could actually do it here).  */
   if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
     {
-      if (h->plt.refcount < 0
+      if (h->plt.refcount <= 0
          || (h->type != STT_GNU_IFUNC
              && (SYMBOL_REFERENCES_LOCAL (info, h)
                  || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
@@ -993,8 +993,6 @@ loongarch_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
          h->plt.offset = MINUS_ONE;
          h->needs_plt = 0;
        }
-      else
-       h->needs_plt = 1;
 
       return true;
     }
index db9d71398de3e6ee87405b6544845837a3aec83f..1eef9f456678daaaa2c7d0d269e2347d87c2c100 100644 (file)
@@ -504,7 +504,8 @@ run_ld_link_tests [list \
 # but that is just an optimization so don't complain loudly.
 setup_xfail *-*-*
 clear_xfail alpha-*-* bfin-*-linux* csky-*-* frv-*-* hppa*-*-* i?86-*-*
-clear_xfail ia64-*-* microblaze-*-* powerpc*-*-* x86_64-*-* xtensa-*-*
+clear_xfail ia64-*-* loongarch*-*-* microblaze-*-* powerpc*-*-* x86_64-*-*
+clear_xfail xtensa-*-*
 run_ld_link_tests {
     {"pr22374 function pointer initialization"
        "" "tmpdir/pr22374.so" "" "pr22374a.s"