This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] gas: don't emit stray unversioned symbol when using ".symver x,x at v"


If you try to version a symbol using the same name, e.g., ".symver
x,x@v", gas will emit two symbols in the .o file -- an unversioned x
and a versioned x, as in this example from HJ's patch for PR 18720:

$ cat indirect3b.c
#include <stdio.h>

void
foo (void)
{
  printf ("MAIN\n");
}

asm (".symver foo,foo@FOO");
$ gcc -c -fpic indirect3b.c
$ nm indirect3b.o
0000000000000000 T foo
0000000000000000 T foo@FOO
                 U _GLOBAL_OFFSET_TABLE_
0000000000000000 r .LC0
                 U puts

The first unversioned definition of "foo" leads to problems in both ld and gold:

https://sourceware.org/bugzilla/show_bug.cgi?id=18703
https://sourceware.org/bugzilla/show_bug.cgi?id=18720

The following patch to gas eliminates the extra unversioned
definition, and solves both problems:

diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index 78dc6d9..8668be0 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -2182,6 +2182,11 @@ elf_frob_symbol (symbolS *symp, int *puntp)
              memmove (&p[2], &p[3], l);
              S_SET_NAME (symp, sy_obj->versioned_name);
            }
+         else if (strncmp (S_GET_NAME (symp), sy_obj->versioned_name,
+                           strlen (S_GET_NAME (symp))) == 0)
+           {
+             S_SET_NAME (symp, sy_obj->versioned_name);
+           }
          else
            {
              symbolS *symp2;

With this patch, we get:

$ nm indirect3b.o
0000000000000000 T foo@FOO
                 U _GLOBAL_OFFSET_TABLE_
0000000000000000 r .LC0
                 U puts

There are a couple of testcases whose expected results would need to
be adjusted, so I wanted to solicit more opinions about whether this
is an appropriate change to the assembler before submitting formally
as a patch.

-cary


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]