tuxad.com

Linux Systemhaus Herford

Code sizes

There are many sources on the web telling you how to write small C code. But different versions of gcc produce different code sizes. I made a small test with different gcc-versions:

  • gcc 3.2.3 (exactly: "gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-54)")
  • gcc 3.3.3 (exactly: "gcc (GCC) 3.3.3 20040412 (Red Hat Linux 3.3.3-7)")
  • gcc 3.3.5 (exactly: "gcc (GCC) 3.3.6-hammer 20050117 (prerelease)")
  • gcc 3.3.6 (original GNU code)
  • gcc 3.4.6 (exactly: "gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-3)")
  • gcc 4.1.0 (exactly: "gcc (GCC) 4.1.0 20060304 (Red Hat 4.1.0-3)")

With each gcc I built the dietlibc-0.30 with standard dietlibc options/flags and got the following file sizes of bin-i386/dietlibc.a:

  • gcc 3.2.3: 681214
  • gcc 3.3.3: 631384
  • gcc 3.3.5: 631336
  • gcc 3.3.6: 631504
  • gcc 3.4.6: 627568
  • gcc 4.1.0: 627204

Then I used each compiled dietlibc with each gcc to compile some small tools. The executables were stripped ("strip -s -R .note -R .comment"). The matrix values are the sums of the tools file sizes:

diet323 diet333 diet335 diet336 diet346 diet410
gcc323 26300 24060 24140 24204 24172 26180
gcc333 24108 23816 23904 23816 23940 25896
gcc335 24120 23828 23916 23828 23952 25908
gcc336 24280 24016 24112 24016 24176 26124
gcc346 24172 23880 23968 23880 23972 25960
gcc410 24356 24064 24152 24064 24188 26144

Short note about the old-fashioned gcc-2.95.3: The file sizes I got with it are even inferior to gcc-3.2.3 and nearly bad as gcc-4.1.0.

A last test shows file sizes when compiling a tool with gcc-3.4.6:

diet -Os gcc -Os; strip 3776
diet -Os gcc -Os 7358
diet gcc -Os 7418
diet gcc -O2 7578
gcc -Os 7730
gcc -O2 7854
gcc -O2 -g 13966
gcc -Os -static 550334

Last note: With sstrip or elftrunc (dietlibc contrib) you can strip symbols and section headers from ELF executables to get smaller files.



Copyright © 2004-2021 Frank W. Bergmann
Alle Rechte vorbehalten. Rechtliche Hinweise

Keywords dieser Seite: Linux, Systemhaus, Herford, LPI, LPIC, LPIC-2, LPIC-3, zertifiziert, Zertifizierung, Linux-Systemhaus, Unix, Betriebssystem, Linux, Systementwicklung, Optimierung, Systemprogramme, Programmierung, Software-Entwicklung, Patches, System-Administration, Systemadministration, OpenSource, Performance, Monitoring-Spezialist, Monitoringsystem, Nagios, Monitoring, Nagios-Plugin, Nagios-Server, NRPE, SNMP, IT-Security, Nameserver, DYNDNS, Hosting, Webhoster, Webhosting-Unternehmen, Webserver, Domainhosting, Domains, Virtual-Root, VirtualRoot, Linux-Distribution, Linux-Software, Linux-System, Linux-Hosts, Mail-Server, Mailprovider, Mailserver, Spamschutz, DNSBL, Technische Dokumentation, Administration, Sicherheitskonzept, Software-Entwicklung, Softwareentwicklung, Softwareprojekt, Datenschutz, Datensicherheit, Distribution, GNU GPL, Hardware, Firewire, IT-Dienstleister, IT-Dienstleistung, Internet-Fullservice, Internetserver, Netzwerk, Netzwerkadministration, Netzwerkdienste, Netzwerke, Netzwerktechnik, Programm, Programmiersprachen, Projekt, Python, Risikoanalyse, Virtual-Root-Server, Router, SMTP-Relay, SNMP, Schulungen, Security, Server, Serverdienste, Spam-Empfang, Spam-Versand, Spamassassin, Spammer, Spammer-Datenbanken, Spammer-Netze, Spammerlisten, Spamtrap, Linux, GNU, Linux-Systemhaus, Herford, Linux