[fpc-pascal] Will the size of an executable depend on the uses clause

Michael Van Canneyt michael at freepascal.org
Wed Jun 16 13:15:10 CEST 2021

On Wed, 16 Jun 2021, Bo Berglund via fpc-pascal wrote:

> I had to add SysUtils to make it work but Lazarus put Classes in there by
> itself.
> Since the final binary size after using strip -s on the exe file is 271 kb it
> seems a bit big!
> Or is there a lot behind the scenes I have missed?
> I see many command line utilities (not written by me) that are *much* smaller
> and still do much more....

That's simply because most of their code is in libc.
libc is the equivalent of sysutils, and many other units in FPC taken

So, to be more correct, you would need to see what libraries they load, add all the
sizes of the libraries to the size of the actual executable, and then this
is the total "size" of the binary. That is what you should compare to the
size of the FPC gnerated binary.

As an example take the 'ls' binary.

Binary itself is quite small:

~s -lh /usr/bin/ls
-rwxr-xr-x 1 root root 139K Sep  5  2019 /usr/bin/ls

But look at what it loads:

~$ ldd /usr/bin/ls
 	linux-vdso.so.1 (0x00007ffc3f9c1000)
 	libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f45b7132000)
 	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f45b6f40000)
 	libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f45b6eb0000)
 	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f45b6eaa000)
 	/lib64/ld-linux-x86-64.so.2 (0x00007f45b718f000)
 	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f45b6e87000)
~$ ls -lh /lib/x86_64-linux-gnu/libselinux.so.1 /lib/x86_64-linux-gnu/libc-2.31.so /lib/x86_64-linux-gnu/libpcre2-8.so.0.9.0 /lib/x86_64-linux-gnu/libdl-2.31.so  /lib/x86_64-linux-gnu/libpthread-2.31.so 
-rwxr-xr-x 1 root root 2.0M Dec 16 11:04 /lib/x86_64-linux-gnu/libc-2.31.so
-rw-r--r-- 1 root root  19K Dec 16 11:04 /lib/x86_64-linux-gnu/libdl-2.31.so
-rw-r--r-- 1 root root 571K Dec  7  2019 /lib/x86_64-linux-gnu/libpcre2-8.so.0.9.0
-rwxr-xr-x 1 root root 154K Dec 16 11:04 /lib/x86_64-linux-gnu/libpthread-2.31.so
-rw-r--r-- 1 root root 160K Feb 26  2020 /lib/x86_64-linux-gnu/libselinux.so.1

Total size of code needed to run the application: close to 3 Mb.

Comparison is different because of all kinds of memory sharing techniques,
but in general, the code size of an FPC binary is not too bad.


More information about the fpc-pascal mailing list