Issue 91055
Summary `--retain-symbols-file` is not compatible with GNU
Labels lld:ELF
Assignees
Reporter rui314
    It looks like lld uses `--retain-symbols-file` to control whether a symbol is put into .dynsym or not. However, for GNU ld, the option doesn't seem to have any effect on .dynsym. Instead, it controls whether a symbol is put into the output .symtab or not.

Here is a test script:

```shell
cat <<EOF | cc -c -o a.o -xc -
void foo() {}
void bar() {}
void baz() {}
EOF

cat <<EOF > symbols
foo
baz
EOF

cc -shared -o b.so a.o -Wl,--retain-symbols-file=symbols
nm b.so
readelf -W --dyn-syms b.so

cc -fuse-ld=lld -shared -o c.so a.o -Wl,--retain-symbols-file=symbols
nm c.so
readelf -W --dyn-syms c.so
```

You can see that the symbols in .dynsym and .symtab are different between lld and GNU ld.

```
$ bash -x /tmp/foo
+ cat
+ cc -c -o a.o -xc -
+ cat
+ cc -shared -o b.so a.o -Wl,--retain-symbols-file=symbols
+ nm b.so
000000000000110f T baz
00000000000010f9 T foo
+ readelf -W --dyn-syms b.so

Symbol table '.dynsym' contains 8 entries:
   Num:    Value          Size Type Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL DEFAULT  UND
     1: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __cxa_finalize
     2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_registerTMCloneTable
     3: 0000000000000000     0 NOTYPE  WEAK DEFAULT  UND _ITM_deregisterTMCloneTable
     4: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
     5: 00000000000010f9    11 FUNC    GLOBAL DEFAULT   10 foo
     6: 0000000000001104    11 FUNC GLOBAL DEFAULT   10 bar
     7: 000000000000110f    11 FUNC    GLOBAL DEFAULT   10 baz
+ cc -fuse-ld=lld -shared -o c.so a.o -Wl,--retain-symbols-file=symbols
+ nm c.so
0000000000001674 t bar
000000000000167f T baz
0000000000003888 b completed.0
 w __cxa_finalize
00000000000015b0 t deregister_tm_clones
0000000000001620 t __do_global_dtors_aux
00000000000026f0 d __do_global_dtors_aux_fini_array_entry
0000000000003860 d __dso_handle
0000000000002700 d _DYNAMIC
00000000000016a8 t _fini
0000000000001669 T foo
0000000000001660 t frame_dummy
00000000000026f8 d __frame_dummy_init_array_entry
0000000000000530 r __FRAME_END__
0000000000003868 d _GLOBAL_OFFSET_TABLE_
 w __gmon_start__
000000000000168c t _init
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
00000000000015e0 t register_tm_clones
0000000000003868 d __TMC_END__
0000000000003868 d __TMC_LIST__
+ readelf -W --dyn-syms c.so

Symbol table '.dynsym' contains 7 entries:
   Num:    Value          Size Type    Bind   Vis Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
 1: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
 2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterTMCloneTable
     3: 0000000000000000     0 NOTYPE  WEAK DEFAULT  UND _ITM_registerTMCloneTable
     4: 0000000000000000     0 FUNC WEAK   DEFAULT  UND __cxa_finalize
     5: 0000000000001669    11 FUNC GLOBAL DEFAULT   10 foo
     6: 000000000000167f    11 FUNC    GLOBAL DEFAULT   10 baz
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to