Bug 5560 – unittests add code size when compiling with -lib and without -unittest

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2011-02-10T14:15:00Z
Last change time
2011-05-03T16:14:51Z
Assigned to
nobody
Creator
schveiguy

Comments

Comment #0 by schveiguy — 2011-02-10T14:15:33Z
When compiling a lib with that has unit tests, but without -unittest, each unit test for some reason adds a small amount of space. For example: lib1.d: void foo() {} lib2.d: void foo() {} unittest {} lib3.d void foo() {} unittest {} unittest {} results: steves@steve-laptop:~/testd/unittestbug$ ~/dmd-2.051/linux/bin/dmd -lib -oflib1.a lib1.d steves@steve-laptop:~/testd/unittestbug$ ~/dmd-2.051/linux/bin/dmd -lib -oflib2.a lib2.d steves@steve-laptop:~/testd/unittestbug$ ~/dmd-2.051/linux/bin/dmd -lib -oflib3.a lib3.d steves@steve-laptop:~/testd/unittestbug$ ls -l *.a -rw-r--r-- 1 steves steves 3070 2011-02-10 17:07 lib1.a -rw-r--r-- 1 steves steves 3914 2011-02-10 17:07 lib2.a -rw-r--r-- 1 steves steves 4758 2011-02-10 17:07 lib3.a If I compile these files with the -c option: steves@steve-laptop:~/testd/unittestbug$ ~/dmd-2.051/linux/bin/dmd -c *.d steves@steve-laptop:~/testd/unittestbug$ ls -l *.o -rw-r--r-- 1 steves steves 1184 2011-02-10 17:08 lib1.o -rw-r--r-- 1 steves steves 1184 2011-02-10 17:08 lib2.o -rw-r--r-- 1 steves steves 1184 2011-02-10 17:08 lib3.o So clearly it has something to do with the -lib option, but I'm not sure what.
Comment #1 by bugzilla — 2011-05-03T15:27:36Z
The size of libphobos.a has nothing to do with the size of an executable linked with Phobos. Multiobj will increase the size of the library simply because there's a lot of bookkeeping overhead for each .o file - overhead that does not go into the executable.
Comment #2 by schveiguy — 2011-05-03T16:14:51Z
You are right, in the final executable, the size is the same. I'm not sure why the discrepancy in the object file, but clearly it's not affecting the exe.