[Interest] Size of libQt5Core in 5.3

Thiago Macieira thiago.macieira at intel.com
Sun May 11 23:05:22 CEST 2014


Em dom 11 maio 2014, às 13:25:36, Giuseppe D'Angelo escreveu:
> In general you should take an analytic approach: pass
> 
> > -Wl,-Map,qtcoremapfile
> 
> to QtCore's linker command line, and examine the map file using a 
> script. Then proceed to trim.

Build output:

-rwxr-xr-x 1 thiago users 38586440 Mai 11 11:05 libQt5Core.so.5.3.1

After stripping:
-rwxr-xr-x 1 thiago users 4684568 Mai 11 11:11 libQt5Core.so.5.3.1

ELF sections, sorted by size:
$ eu-readelf -S libQt5Core.so.5.3.1 | sort -k1.66r
[Nr] Name                 Type         Addr             Off      Size     ES 
Flags Lk Inf Al
[13] .text                PROGBITS     0000000000084ed0 00084ed0 0026b554  0 
AX     0   0 16
[16] .rodata              PROGBITS     0000000000328960 00328960 000f47c3  0 A      
0   0 32
[18] .eh_frame            PROGBITS     000000000041d150 0041d150 000410fc  0 A      
0   0  8
[15] .gcc_except_table    PROGBITS     00000000002f0430 002f0430 00038518  0 A      
0   0  4
[ 3] .dynstr              STRTAB       0000000000021df0 00021df0 00033cf8  0 A      
0   0  1
[ 2] .dynsym              DYNSYM       0000000000000298 00000298 00021b58 24 A      
3   1  8
[ 9] .rela.dyn            RELA         000000000006c8d0 0006c8d0 00015918 24 A      
2   0  8
[19] .eh_frame_hdr        PROGBITS     000000000045e24c 0045e24c 0000e5fc  0 A      
0   0  4
[ 5] .gnu.hash            GNU_HASH     000000000005f4e0 0005f4e0 0000a55c  0 A      
2   0  8
[ 4] .hash                HASH         0000000000055ae8 00055ae8 000099f8  4 A      
2   0  8
[25] .data.rel.ro         PROGBITS     000000000046fec0 0046eec0 00006be8  0 
WA     0   0 16
[ 6] .gnu.version         GNU_versym   0000000000069a3c 00069a3c 00002cf2  2 A      
2   0  2
[10] .rela.plt            RELA         00000000000821e8 000821e8 00001ad0 24 A      
2  12  8
[21] .data.rel.ro.local   PROGBITS     000000000046e550 0046d550 00001938  0 
WA     0   0 16
[31] .bss                 NOBITS       0000000000478000 00476ff8 000018b8  0 WA     
0   0 16
[12] .plt                 PROGBITS     0000000000083ce0 00083ce0 000011f0 16 
AX     0   0 16
[28] .got.plt             PROGBITS     0000000000476fe8 00475fe8 00000908  0 
WA     0   0  8
[29] .data                PROGBITS     00000000004778f0 004768f0 00000704  0 
WA     0   0 16
[26] .dynamic             DYNAMIC      0000000000476aa8 00475aa8 000002d0 16 
WA     3   0  8
[27] .got                 PROGBITS     0000000000476d78 00475d78 00000270  0 
WA     0   0  8
[ 8] .gnu.version_r       GNU_verneed  000000000006c74c 0006c74c 00000180  0 A      
3   8  4
[34] .shstrtab            STRTAB       0000000000000000 004770fc 00000158  0        
0   0  1
[32] .comment             PROGBITS     0000000000000000 00476ff8 000000e8  1 MS     
0   0  1
[ 1] .note.gnu.build-id   NOTE         0000000000000270 00000270 00000024  0 A      
0   0  4
[24] .init_array          INIT_ARRAY   000000000046fea0 0046eea0 00000020  0 
WA     0   0  8
[ 7] .gnu.version_d       GNU_verdef   000000000006c730 0006c730 0000001c  0 A      
3   1  4
[17] .interp              PROGBITS     000000000041d130 0041d130 0000001c  0 A      
0   0 16
[11] .init                PROGBITS     0000000000083cb8 00083cb8 0000001a  0 
AX     0   0  4
[20] .tbss                NOBITS       000000000046e550 0046d550 00000010  0 
WAT    0   0  8
[23] .fini_array          FINI_ARRAY   000000000046fe90 0046ee90 00000010  0 WA     
0   0  8
[14] .fini                PROGBITS     00000000002f0424 002f0424 00000009  0 AX     
0   0  4
[22] .jcr                 PROGBITS     000000000046fe88 0046ee88 00000008  0 
WA     0   0  8
[33] .note.gnu.gold-version NOTE         0000000000000000 004770e0 0000001c  0        
0   0  4
[30] .tm_clone_table      PROGBITS     0000000000477ff8 00476ff8 00000000  0 WA     
0   0  8
[ 0]                      NULL         0000000000000000 00000000 00000000  0        
0   0  0

As you can see, the largest section is .text, at 2536788 bytes, followed by 
.rodata at 1001411, then the two exception tables, at 266492 and 230680 each. 
The further sections are either by-products of the code (dynamic strings, 
symbol hashing tables) or too small to count here.

So the first thing you may want to do is to force QtCore to compile without 
exceptions. The command-line option -no-exceptions to configure was removed, 
you need to do that manually by modifying QtCore's .pro file.

Then let's look into the .text section's map fie, sorted by size:

$ perl -n -e 'if (/ \.text.*\s(0x.*)\s+(.*\.o)/) { $sizes{hex($1)} = $2; } 
END {
  for $size (sort { $a <=> $b } keys %sizes) {
    $total += $size; print $size, " ", $sizes{$size}, "\n"; 
  } 
  print "$total\n";
}' QtCore.map
[...]
45476 .obj/qobject.o
48523 .obj/qregexp.o
53198 .obj/qstatemachine.o
53657 .obj/qsettings.o
58416 .obj/qdatetime.o
58836 .obj/qvariant.o
59344 .obj/qlocale.o
83403 .obj/qstring.o
89452 .obj/qxmlstream.o
192595 .obj/qcryptographichash.o
2160601

Note that the total doesn't match the section size because it doesn't include 
padding between files and because the script didn't include the non-inlined 
inlined functions.

If we run the same for the .rodata section:
13696 .obj/qtimezoneprivate.o
15412 .obj/moc_qlocale.o
16156 .obj/qurlidna.o
33644 .obj/moc_qnamespace.o
99797 .obj/qtldurl.o
168104 .obj/qstring.o
248808 .obj/qlocale.o
251684 .obj/qrc_mimetypes.o
924845

The above are easy to explain: QLocale and and the Qt namespace have a lot of 
enums, which cause their meta objects to grow (the names aren't compressed); 
qurlidna.cpp and qstring.cpp include a large chunk of Unicode tables and 
stringprep tables; qlocale.cpp includes the CLDR data that John talked about; 
finally, mimetypes.qrc contains the MIME type data that QMimeType requires to 
run.

In other words, no easy gains here. QtCore is big because it contains a lot of 
stuff, none of which is really big.
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list