shared library size

Guillaume Piolat first.last at gmail.com
Mon Jul 2 12:21:04 UTC 2018


On Monday, 2 July 2018 at 09:35:53 UTC, boolangery wrote:
> Hi,
>
> Why shared library size is so big ?
>
> I tried to build https://github.com/etcimon/libasync as a 
> shared library:
>
>
> build/libasync.so: ELF 64-bit LSB shared object, x86-64, 
> version 1 (SYSV), dynamically linked, 
> BuildID[sha1]=4df6b6d12da6d6cf2108178a14b61fc9453a8e9e, stripped
>
> 2,6M	build/libasync.so
>
> ldd build/libasync.so
> 	linux-vdso.so.1 (0x00007ffd65d54000)
> 	librt.so.1 => /lib64/librt.so.1 (0x00007f5181e94000)
> 	libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f5181c7d000)
> 	libphobos2-ldc.so.74 => /lib64/libphobos2-ldc.so.74 
> (0x00007f51815b3000)
> 	libdruntime-ldc.so.74 => /lib64/libdruntime-ldc.so.74 
> (0x00007f51812a3000)
> 	libdl.so.2 => /lib64/libdl.so.2 (0x00007f518109f000)
> 	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f5180e81000)
> 	libm.so.6 => /lib64/libm.so.6 (0x00007f5180b36000)
> 	libc.so.6 => /lib64/libc.so.6 (0x00007f5180780000)
> 	/lib64/ld-linux-x86-64.so.2 (0x00007f5182527000)
> 	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f5180569000)
>
> Its just 16K lines of codes, why 2.6M ? Do you have tips for 
> reduce this size ?
>
> Thanks

Hello,

On POSIX by default, all the symbols in a shared library are 
exported. That makes a lot of symbols that can't be stripped 
automatically by the linker!

And it won't change anytime soon 
(https://github.com/ldc-developers/ldc/issues/2431).

The one option you have with LDC to have smaller shared libraries 
is to use:

$ ldc2 -exported_symbols_list list-of-symbols.lst -dead_strip 
<rest-of-cmdline>

Good luck!


More information about the digitalmars-d-ldc mailing list