* [PATCH] ld: Always call elf_backend_output_arch_local_syms
@ 2022-11-16 23:20 H.J. Lu
2022-11-17 3:21 ` Alan Modra
0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2022-11-16 23:20 UTC (permalink / raw)
To: binutils
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 | 5 +++++
bfd/elflink.c | 3 +--
bfd/elfnn-aarch64.c | 5 +++++
ld/testsuite/ld-elf/linux-x86.exp | 15 +++++++++++++++
ld/testsuite/ld-elf/pr29797.c | 21 +++++++++++++++++++++
5 files changed, 47 insertions(+), 2 deletions(-)
create mode 100644 ld/testsuite/ld-elf/pr29797.c
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index ec18a8ab362..c7d73171e62 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -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;
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 20cee4c76a4..81b34129463 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -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)))
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 7b93672c0df..a9fefbd44a9 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -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;
diff --git a/ld/testsuite/ld-elf/linux-x86.exp b/ld/testsuite/ld-elf/linux-x86.exp
index 06379057ff2..7822bd227f0 100644
--- a/ld/testsuite/ld-elf/linux-x86.exp
+++ b/ld/testsuite/ld-elf/linux-x86.exp
@@ -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
index 00000000000..9e3113fe98d
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr29797.c
@@ -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;
+}
--
2.37.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] ld: Always call elf_backend_output_arch_local_syms
2022-11-16 23:20 [PATCH] ld: Always call elf_backend_output_arch_local_syms H.J. Lu
@ 2022-11-17 3:21 ` Alan Modra
0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2022-11-17 3:21 UTC (permalink / raw)
To: H.J. Lu; +Cc: binutils
On Wed, Nov 16, 2022 at 03:20:39PM -0800, H.J. Lu via Binutils wrote:
> 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.
OK.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-17 3:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-16 23:20 [PATCH] ld: Always call elf_backend_output_arch_local_syms H.J. Lu
2022-11-17 3:21 ` Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).