[PATCH] D77807: [LLD][ELF] Implement --discard-* for cases when -r or --emit-relocs are used.
Igor Kudrin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 10 22:05:28 PDT 2020
ikudrin added a comment.
In D77807#1974679 <https://reviews.llvm.org/D77807#1974679>, @MaskRay wrote:
> Honestly I am wondering whether a relocation scanning is justified. The only problem I can think of with the current conservative choice for --discard-locals + (-r | --emit-relocs) is that the output is larger. The output contains some otherwise unneeded STB_LOCAL symbols. Note, STB_LOCAL symbols not used by a relocation don't interfere with linking.
In our case, the output is analyzed with additional tools and these unneeded symbols slow down the process significantly.
> This discards local symbols as well. My question is why we have these unreferenced local symbols in object files and why we need to save .symtab space for them.
>
> An assembler can convert a local symbol reference to a relocation referencing a STT_SECTION symbol, or resolve the fixup at assembly time. If the intention is to discard the unreferenced local symbols, a better way may be to not generate the local symbols in the object files. Alternatively, generate `.L` temporary labels which are a special kind of local symbols which usually don't survive in the object file.
Here is a reduced example of the initial problem I am solving in this patch:
$ cat a.c
static int foo = 0;
int bar() { return foo; }
$ clang -c a.c
$ readelf -rs a.o
Relocation section '.rela.text' at offset 0x150 contains 1 entry:
Offset Info Type Sym. Value Sym. Name + Addend
000000000007 00040000000b R_X86_64_32S 0000000000000000 .bss + 0
...
Symbol table '.symtab' contains 6 entries:
Num: Value Size Type Bind Vis Ndx Name
...
2: 0000000000000000 4 OBJECT LOCAL DEFAULT 4 foo
...
$ ld.bfd -r a.o --discard-all -o ar.o && nm ar.o
0000000000000000 T bar
$ ld.lld -r a.o --discard-all -o ar.o && nm ar.o
0000000000000000 T bar
0000000000000000 b foo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77807/new/
https://reviews.llvm.org/D77807
More information about the llvm-commits
mailing list