Very large binary files compiled by gcc

Hello to everibody!
I have a big problem compiling from source apps for Linux.
Let us take for example Squid3.
I downloaded tarball, configured and compiled it.
It was compiled OK, but the squid executable file is 24M!
I downloaded ready rpm package, and extracted files into some directory.
Executable for squid is 5.2M only, almost 5 times less than mine!
Configuration and compilation params was the same (tested it with squid -v)
What I am doing wrong?!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
$ du -h squid-3.3.5/src/squid
24M     squid-3.3.5/src/squid
$  du -h squidtest/usr/sbin/squid
5.2M    squidtest/usr/sbin/squid
$ ldd squid-3.3.5/src/squid
        linux-gate.so.1 =>  (0x008f4000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x00d84000)
        libcrypt.so.1 => /lib/libcrypt.so.1 (0x0017c000)
        libgssapi_krb5.so.2 => /lib/libgssapi_krb5.so.2 (0x0081e000)
        libkrb5.so.3 => /lib/libkrb5.so.3 (0x003bb000)
        libk5crypto.so.3 => /lib/libk5crypto.so.3 (0x001ac000)
        libcom_err.so.2 => /lib/libcom_err.so.2 (0x00c48000)
        libnsl.so.1 => /lib/libnsl.so.1 (0x007b0000)
        libresolv.so.2 => /lib/libresolv.so.2 (0x001d7000)
        librt.so.1 => /lib/librt.so.1 (0x00981000)
        libdl.so.2 => /lib/libdl.so.2 (0x001f1000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x002a4000)
        libm.so.6 => /lib/libm.so.6 (0x001f6000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00d0e000)
        libc.so.6 => /lib/libc.so.6 (0xb7621000)
        /lib/ld-linux.so.2 (0x00284000)
        libfreebl3.so => /lib/libfreebl3.so (0x0088c000)
        libkrb5support.so.0 => /lib/libkrb5support.so.0 (0x00220000)
        libkeyutils.so.1 => /lib/libkeyutils.so.1 (0x008e5000)
        libselinux.so.1 => /lib/libselinux.so.1 (0x0095f000)
$ ldd squidtest/usr/sbin/squid
        linux-gate.so.1 =>  (0x0076f000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x00bf1000)
        libcrypt.so.1 => /lib/libcrypt.so.1 (0x008ef000)
        libxml2.so.2 => /usr/lib/libxml2.so.2 (0x0017b000)
        libexpat.so.1 => /lib/libexpat.so.1 (0x00c1c000)
        libssl.so.10 => /usr/lib/libssl.so.10 (0x006bf000)
        libcrypto.so.10 => /usr/lib/libcrypto.so.10 (0x002c6000)
        libgssapi_krb5.so.2 => /lib/libgssapi_krb5.so.2 (0x00ade000)
        libkrb5.so.3 => /lib/libkrb5.so.3 (0x0048c000)
        libk5crypto.so.3 => /lib/libk5crypto.so.3 (0x00c97000)
        libcom_err.so.2 => /lib/libcom_err.so.2 (0x00569000)
        libnsl.so.1 => /lib/libnsl.so.1 (0x0096f000)
        libresolv.so.2 => /lib/libresolv.so.2 (0x009aa000)
        librt.so.1 => /lib/librt.so.1 (0x00849000)
        libdl.so.2 => /lib/libdl.so.2 (0x00623000)
        libltdl.so.7 => /usr/lib/libltdl.so.7 (0x00ef2000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x009c4000)
        libm.so.6 => /lib/libm.so.6 (0x0056e000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00598000)
        libc.so.6 => /lib/libc.so.6 (0x00cc2000)
        /lib/ld-linux.so.2 (0x00ecd000)
        libfreebl3.so => /lib/libfreebl3.so (0x005b6000)
        libz.so.1 => /lib/libz.so.1 (0x00605000)
        libkrb5support.so.0 => /lib/libkrb5support.so.0 (0x00628000)
        libkeyutils.so.1 => /lib/libkeyutils.so.1 (0x00619000)
        libselinux.so.1 => /lib/libselinux.so.1 (0x00688000)
OK, seems I got the reason!
Binary in rpm was stripped, but compiled by me - was not.
So I striiped it by strip --strip-unneeded
File size of stripped squid became 7 times less from original!
$ du -h squid
3.5M squid
I simply could not expect such effect, because did stripping before,
and loss of size was no more than 10 percents
man strip
running strip is a good way to get the size down after you have a binary and the binary is in ELF format. strip just removes debug and unreferenced symbols after the binary has been created.

You can also try compiling the source with out the debug flag turned on. if using gcc it is the -g option. That prevents the compiler from adding the symbolic debugging symbols at compile time.
Last edited on
Often stripping is done on all executables in /bin /sbin /usr/bin and /usr/sbin at once, rather than on each package. See how LFS does it:
http://www.linuxfromscratch.org/lfs/view/6.7-rc1/chapter06/strippingagain.html
Topic archived. No new replies allowed.