public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] lto: Don't add indirect symbols for versioned aliases in IR
@ 2023-03-30 16:42 H.J. Lu
  2023-03-30 21:27 ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2023-03-30 16:42 UTC (permalink / raw)
  To: binutils

Linker adds indirect symbols for versioned symbol aliases, which are
created by ".symver foo, foo@FOO", by checking symbol type, value and
section so that references to foo will be replaced by references to
foo@FOO if foo and foo@FOO have the same symbol type, value and section.
But in IR, since all symbols of the same type have the same value and
section, we can't tell if a symbol is an alias of another symbol by
their types, values and sections.  We shouldn't add indirect symbols
for versioned symbol aliases in IR.

bfd/

	PR ld/30281
	* elflink.c (elf_link_add_object_symbols): Don't add indirect
	symbols for ".symver foo, foo@FOO" aliases in IR.

ld/

	PR ld/30281
	* testsuite/ld-plugin/lto.exp: Add PR ld/30281 test.
	* testsuite/ld-plugin/pr30281.t: New file.
	* testsuite/ld-plugin/pr30281.c: Likewise.
---
 bfd/elflink.c                    | 9 ++++++++-
 ld/testsuite/ld-plugin/lto.exp   | 9 +++++++++
 ld/testsuite/ld-plugin/pr30281.c | 4 ++++
 ld/testsuite/ld-plugin/pr30281.t | 4 ++++
 4 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 ld/testsuite/ld-plugin/pr30281.c
 create mode 100644 ld/testsuite/ld-plugin/pr30281.t

diff --git a/bfd/elflink.c b/bfd/elflink.c
index bab1a36598e..f10faa5f8bd 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -5382,7 +5382,14 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 	      h->unique_global = (flags & BSF_GNU_UNIQUE) != 0;
 	    }
 
-	  if (definition && !dynamic)
+	  /* Don't add indirect symbols for .symver x, x@FOO aliases
+	     in IR.  Since all data or text symbols in IR have the
+	     same type, value and section, we can't tell if a symbol
+	     is an alias of another symbol by their types, values and
+	     sections.  */
+	  if (definition
+	      && !dynamic
+	      && (abfd->flags & BFD_PLUGIN) == 0)
 	    {
 	      char *p = strchr (name, ELF_VER_CHR);
 	      if (p != NULL && p[1] != ELF_VER_CHR)
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 98e811177ef..e7e7952bb1b 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -530,6 +530,15 @@ set lto_link_elf_tests [list \
    {} \
    "pr29086" \
   ] \
+  [list \
+   "Build pr30281.so" \
+   "-shared -Wl,--version-script,pr30281.t \
+    -O2 -fPIC -flto-partition=max -flto=2" \
+   "-O2 -fPIC -flto-partition=max -flto=2" \
+   {pr30281.c} \
+   "" \
+   "pr30281.so" \
+  ] \
 ]
 
 # PR 14918 checks that libgcc is not spuriously included in a shared link of
diff --git a/ld/testsuite/ld-plugin/pr30281.c b/ld/testsuite/ld-plugin/pr30281.c
new file mode 100644
index 00000000000..ba9722a389c
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr30281.c
@@ -0,0 +1,4 @@
+extern __inline __attribute__((__gnu_inline__)) void foo(void) {}
+__attribute__((__symver__("foo@GLIBC_2.2.5")))
+int __collector_foo_2_2(void) {}
+void foo(void) {}
diff --git a/ld/testsuite/ld-plugin/pr30281.t b/ld/testsuite/ld-plugin/pr30281.t
new file mode 100644
index 00000000000..3169ad398c9
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr30281.t
@@ -0,0 +1,4 @@
+GLIBC_2.2.5 {
+  global:
+    foo;
+};
-- 
2.39.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lto: Don't add indirect symbols for versioned aliases in IR
  2023-03-30 16:42 [PATCH] lto: Don't add indirect symbols for versioned aliases in IR H.J. Lu
@ 2023-03-30 21:27 ` Alan Modra
  2023-04-03 18:24   ` H.J. Lu
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Modra @ 2023-03-30 21:27 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Thu, Mar 30, 2023 at 09:42:14AM -0700, H.J. Lu via Binutils wrote:
> bfd/
> 
> 	PR ld/30281
> 	* elflink.c (elf_link_add_object_symbols): Don't add indirect
> 	symbols for ".symver foo, foo@FOO" aliases in IR.
> 
> ld/
> 
> 	PR ld/30281
> 	* testsuite/ld-plugin/lto.exp: Add PR ld/30281 test.
> 	* testsuite/ld-plugin/pr30281.t: New file.
> 	* testsuite/ld-plugin/pr30281.c: Likewise.

Looks good to me.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lto: Don't add indirect symbols for versioned aliases in IR
  2023-03-30 21:27 ` Alan Modra
@ 2023-04-03 18:24   ` H.J. Lu
  2023-04-11  9:07     ` Nick Clifton
  0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2023-04-03 18:24 UTC (permalink / raw)
  To: Alan Modra, Nick Clifton; +Cc: binutils

On Thu, Mar 30, 2023 at 2:27 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Thu, Mar 30, 2023 at 09:42:14AM -0700, H.J. Lu via Binutils wrote:
> > bfd/
> >
> >       PR ld/30281
> >       * elflink.c (elf_link_add_object_symbols): Don't add indirect
> >       symbols for ".symver foo, foo@FOO" aliases in IR.
> >
> > ld/
> >
> >       PR ld/30281
> >       * testsuite/ld-plugin/lto.exp: Add PR ld/30281 test.
> >       * testsuite/ld-plugin/pr30281.t: New file.
> >       * testsuite/ld-plugin/pr30281.c: Likewise.
>
> Looks good to me.
>

Hi Nick,

Is this OK for 2.40 branch?

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lto: Don't add indirect symbols for versioned aliases in IR
  2023-04-03 18:24   ` H.J. Lu
@ 2023-04-11  9:07     ` Nick Clifton
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Clifton @ 2023-04-11  9:07 UTC (permalink / raw)
  To: H.J. Lu, Alan Modra; +Cc: binutils

Hi H.J.

>> On Thu, Mar 30, 2023 at 09:42:14AM -0700, H.J. Lu via Binutils wrote:
>>> bfd/
>>>
>>>        PR ld/30281
>>>        * elflink.c (elf_link_add_object_symbols): Don't add indirect
>>>        symbols for ".symver foo, foo@FOO" aliases in IR.
>>>
>>> ld/
>>>
>>>        PR ld/30281
>>>        * testsuite/ld-plugin/lto.exp: Add PR ld/30281 test.
>>>        * testsuite/ld-plugin/pr30281.t: New file.
>>>        * testsuite/ld-plugin/pr30281.c: Likewise.

> Is this OK for 2.40 branch?

Sure - please go ahead.

Cheers
   Nick



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-04-11  9:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-30 16:42 [PATCH] lto: Don't add indirect symbols for versioned aliases in IR H.J. Lu
2023-03-30 21:27 ` Alan Modra
2023-04-03 18:24   ` H.J. Lu
2023-04-11  9:07     ` Nick Clifton

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).