ld: Always call elf_backend_output_arch_local_syms
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 16 Nov 2022 23:06:37 +0000 (15:06 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 17 Nov 2022 16:13:37 +0000 (08:13 -0800)
Always call elf_backend_output_arch_local_syms since only the backend
knows if elf_backend_output_arch_local_syms is needed when all symbols
are striped.  elf_backend_output_arch_local_syms is defined only for
x86, ARM and AARCH64.  On x86, elf_backend_output_arch_local_syms must
be called to handle local IFUNC symbols even if all symbols are striped.
Update ARM and AARCH64 to skip elf_backend_output_arch_local_syms when
symbols aren't needed.

bfd/

PR ld/29797
* elf32-arm.c (elf32_arm_output_arch_local_syms): Skip if symbols
aren't needed.
* elfnn-aarch64.c (elfNN_aarch64_output_arch_local_syms):
Likewise.
* elflink.c (bfd_elf_final_link): Always call
elf_backend_output_arch_local_syms if available.

ld/

PR ld/29797
* testsuite/ld-elf/linux-x86.exp: Run PR ld/29797 test.
* testsuite/ld-elf/pr29797.c: New file.

bfd/elf32-arm.c
bfd/elflink.c
bfd/elfnn-aarch64.c
ld/testsuite/ld-elf/linux-x86.exp
ld/testsuite/ld-elf/pr29797.c [new file with mode: 0644]

index ec18a8ab362322bf284a924647324918b8e337db..c7d73171e628185b09e45d88048e85034acf8c93 100644 (file)
@@ -18110,6 +18110,11 @@ elf32_arm_output_arch_local_syms (bfd *output_bfd,
   bfd_size_type size;
   bfd *input_bfd;
 
+  if (info->strip == strip_all
+      && !info->emitrelocations
+      && !bfd_link_relocatable (info))
+    return true;
+
   htab = elf32_arm_hash_table (info);
   if (htab == NULL)
     return false;
index 20cee4c76a49ee5089f5bfa26ffd638988cee7c1..81b341294637ba7ff5700e4a93dc1703c312341d 100644 (file)
@@ -12877,8 +12877,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
 
   /* If backend needs to output some local symbols not present in the hash
      table, do it now.  */
-  if (bed->elf_backend_output_arch_local_syms
-      && (info->strip != strip_all || emit_relocs))
+  if (bed->elf_backend_output_arch_local_syms)
     {
       if (! ((*bed->elf_backend_output_arch_local_syms)
             (abfd, info, &flinfo, elf_link_output_symstrtab)))
index 7b93672c0df1b752385fe61ac5419549d5d79395..a9fefbd44a961550fb3f3576b84cd83161c17184 100644 (file)
@@ -8476,6 +8476,11 @@ elfNN_aarch64_output_arch_local_syms (bfd *output_bfd,
   output_arch_syminfo osi;
   struct elf_aarch64_link_hash_table *htab;
 
+  if (info->strip == strip_all
+      && !info->emitrelocations
+      && !bfd_link_relocatable (info))
+    return true;
+
   htab = elf_aarch64_hash_table (info);
 
   osi.finfo = finfo;
index 06379057ff2498794ed69c07cc4bd25862d084d8..7822bd227f06ccd93f2937e6a504ff91df826692 100644 (file)
@@ -203,6 +203,21 @@ run_ld_link_exec_tests [list \
     ] \
 ]
 
+# Run-time tests which require working ifunc attribute support.
+if { [check_ifunc_attribute_available] } {
+    run_ld_link_exec_tests [list \
+       [list \
+           "Run pr29797" \
+           "-s" \
+           "" \
+           { pr29797.c } \
+           "pr29797" \
+           "pass.out" \
+           "-O0" \
+       ] \
+    ]
+}
+
 # Old gcc silently ignores __attribute__ ((aligned())) with too big alignment.
 proc compiler_honours_aligned { } {
     global CC_FOR_TARGET READELF srcdir subdir
diff --git a/ld/testsuite/ld-elf/pr29797.c b/ld/testsuite/ld-elf/pr29797.c
new file mode 100644 (file)
index 0000000..9e3113f
--- /dev/null
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+static int foo (int x) __attribute__ ((ifunc ("resolve_foo")));
+
+static int foo_impl(int x)
+{
+  return x;
+}
+
+static void *resolve_foo (void)
+{
+  return (void *) foo_impl;
+}
+
+int
+main ()
+{
+  foo (0);
+  puts ("PASS");
+  return 0;
+}