Thread overview
[Issue 5560] New: unittests add code size when compiling with -lib and without -unittest
May 03, 2011
Walter Bright
February 10, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5560

           Summary: unittests add code size when compiling with -lib and
                    without -unittest
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: schveiguy@yahoo.com


--- Comment #0 from Steven Schveighoffer <schveiguy@yahoo.com> 2011-02-10 14:15:33 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 03, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5560


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> 2011-05-03 15:27:36 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 03, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5560


Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #2 from Steven Schveighoffer <schveiguy@yahoo.com> 2011-05-03 16:14:51 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------