[llvm-bugs] [Bug 48361] New: foo at v1 and foo@@v1 aren't handled properly

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Dec 2 06:00:11 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=48361

            Bug ID: 48361
           Summary: foo at v1 and foo@@v1 aren't handled properly
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: hjl.tools at gmail.com
                CC: i at maskray.me, llvm-bugs at lists.llvm.org,
                    smithp352 at googlemail.com

[hjl at gnu-cfl-2 pr26978]$ cat main.c
extern void foo (void);

int
main ()
{
  foo ();
  return 0;
}
[hjl at gnu-cfl-2 pr26978]$ cat ver 
v1 {};
[hjl at gnu-cfl-2 pr26978]$ cat def1w.s 
        .text
        .weak foo
        .symver foo, foo@@@v1
        .type   foo, %object
foo:
        hlt
[hjl at gnu-cfl-2 pr26978]$ cat hid1.s 
        .text
        .globl foo_v1
        .symver foo_v1, foo at v1
        .type   foo_v1, %object
foo_v1:
        ret
[hjl at gnu-cfl-2 pr26978]$ 

ld correctly rejects:

[hjl at gnu-cfl-2 pr26978]$ make
cc    -c -o main.o main.c
as   -o def1w.o def1w.s
as   -o hid1.o hid1.s
ld -shared -o libfoo.so --version-script=ver def1w.o hid1.o
ld: hid1.o:(.text+0x0): multiple definition of `foo at v1'
ld: hid1.o:(*IND*+0x0): multiple definition of `foo'
make: *** [Makefile:10: libfoo.so] Error 1
[hjl at gnu-cfl-2 pr26978]$ 

lld generates a bogus libfoo.so:

[hjl at gnu-cfl-2 pr26978]$ make LD=ld.lld
ld.lld -shared -o libfoo.so --version-script=ver def1w.o hid1.o
cc -o x main.o libfoo.so -Wl,-R,.
/usr/local/bin/ld: libfoo.so:(.text+0x1): multiple definition of `foo at v1'
/usr/local/bin/ld: libfoo.so:(*IND*+0x0): multiple definition of `foo'
collect2: error: ld returned 1 exit status
make: *** [Makefile:7: x] Error 1
[hjl at gnu-cfl-2 pr26978]$ 


[hjl at gnu-cfl-2 pr26978]$ readelf --dyn-syms libfoo.so

Symbol table '.dynsym' contains 4 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 000000000000130d     0 OBJECT  WEAK   DEFAULT    7 foo@@v1
     2: 000000000000130e     0 OBJECT  GLOBAL DEFAULT    7 foo_v1
     3: 000000000000130e     0 OBJECT  GLOBAL DEFAULT    7 foo at v1
[hjl at gnu-cfl-2 pr26978]$ 

foo@@v1 and foo at v1 define the same symbol.  lld doesn't check the bogus
libfoo.so and let the weak definition to override the non-weak one:

[hjl at gnu-cfl-2 pr26978]$ cc -o x main.o libfoo.so -Wl,-R,. -fuse-ld=lld
[hjl at gnu-cfl-2 pr26978]$ ./x
Segmentation fault (core dumped)
[hjl at gnu-cfl-2 pr26978]$

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201202/98dc088e/attachment.html>


More information about the llvm-bugs mailing list