Library size increased after migrating to LLD

We have migrated from gnu ld to lld in our software. But we noticed that our library size and run memory has increased after the migration. We have seen difference in “.got” and “rela.dyn” section between lld and gnu ld when linking exactly the same object files into a single dynamic library.

Column 1 Column 2 Column 3 Column 4
LLD 17.0.6 LD 2.33
section size section size
.dynsym 240096 .hash 72860
.gnu.hash 65772 .gnu.hash 80544
.hash 80040 .dynsym 240096
.dynstr 188484 .dynstr 188314
.rela.dyn 5243688 .rela.dyn 4496832
.rela.plt 2328 .rela.plt 2328
.rodata 82912 .plt 1568
.text 22669044 .text 22669044
.plt 1568 .rodata 82912
.dynamic 272 .eh_frame 0
.got 249024 .dynamic 336
.data 4263352 .got 72
.got.plt 800 .got.plt 800
.bss 2960 .data 4263352
.profinf 0 .bss 2960
.comment 19 Total 32102018
Total 3309035

In additionally, we found it may relate to -Bsymbolic option.

Column 1 Column 2 Column 3 Column 4
LD without Bsymbolic LD with Bsymbolic LLD without Bsymbolic LLD with Bsymbolic
.got 249008 .got 72 .got 249024 .got 249024

I have checked @MaskRay 's post on LLD and GNU linker incompatibilities | MaskRay. However, I didn’t find anything related to this.

Is this likely to be intended behaviour? And are there any options in lld which can reduce the library size?

Further analysis needs a reproduce tarball.

extract the linking command, rerun it with -Wl,--reproduce=/tmp/rep.tar to get a tarball which expands to linker input and a response file.

The larger .got might be due to disabled GOT optimization.

Thanks @MaskRay for the explanation.
I am not able to provide the reproduce tarball due to our policy.
But I can share the contents in response.txt

cat response.txt

–chroot .
-shared
-Bsymbolic
-o out.so
–whole-archive
input_1.a
input_2.a
–no-whole-archive
obj1.o
obj2.o
obj3.o

obj1080.o

In addition, I also did same experiments on AARCH64 platform.
No significant difference can be found in GNU LD and LLD.

Column 1 Column 2 Column 3 Column 4
AARCH64 LLD 17.0.6 AARCH64 LD 2.33
section size section size
.dynsym 231216 .hash 71388
.gnu.hash 63928 .gnu.hash 79068
.hash 77080 .dynsym 231264
.dynstr 178488 .dynstr 178313
.rela.dyn 5224440 .rela.dyn 5224368
.rela.plt 2304 .rela.plt 2376
.rodata 34256 .plt 1600
.text 21933832 .text 21933832
.plt 1568 .rodata 34256
.dynamic 272 .dynamic 352
.got 249080 .got 249048
.data 4256432 .got.plt 840
.got.plt 792 .data 4256432
.profinf 0 Total 32263137
.comment 19
Total 32253707

Moreover, as you mentioned, “The larger .got might be due to disabled GOT optimization”. Does LLD have an option for enable/disable the GOT optimization?

From my experience debugging a lot of issues like this, it is nearly impossible to tell what’s the difference for an outsider when the reproduce tarball is not accessible. You are probably on your own now.

The best course of action for your is probably to compare the dynamic relocations.
If you can reproduce .got 72 from -Bsymbolic is valid, the difference should be quite noticeable.