September 21, 2015
http://bugzilla.gdcproject.org/show_bug.cgi?id=199

Johannes Pfau <johannespfau@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |johannespfau@gmail.com

--- Comment #1 from Johannes Pfau <johannespfau@gmail.com> ---
I think we can't fix this. Does this work with DMD or LDC?

The problem is this: We already build the ModuleInfo chain by emitting one c constructor per module. This means all unittests are referenced by ModuleInfos which are referenced by c constructors which are always kept in the executable by linker scripts. This enures that, as long as you link all objects explicitly, all unittests will be linked in, even without explicitly importing modules.

However, this does not work for code in static libraries because c constructors
in static libraries do not work:
http://stackoverflow.com/questions/1202494/why-doesnt-attribute-constructor-work-in-a-static-library

The linker only looks at object files in static libraries if it searches an undefined symbol. If all symbols are defined, it does not search the object files.

Now you want this to work without imports in your main application. But how could gdc know, when compiling the main applications which additional modules might exists in a static library? If we know module X exists we can add an reference to force the linker. But in your case we explicitly do not know about additional modules so we can't add a reference.

You can use the same workarounds C++ uses though:
http://stackoverflow.com/a/4767951/471401
Use it with GDC like this:
gdc -funittest main.d -Wl,--whole-archive libtest.a -Wl,--no-whole-archive

-- 
You are receiving this mail because:
You are watching all bug changes.


June 29, 2017
https://bugzilla.gdcproject.org/show_bug.cgi?id=199

Johannes Pfau <johannespfau@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |WONTFIX
             Status|ASSIGNED                    |RESOLVED

--- Comment #2 from Johannes Pfau <johannespfau@gmail.com> ---
I think DMD has got the same problem and now there's the workaround of linking the tests into a shared library instead, so closing as WONT FIX.

AFAIK there's no way to really make static libraries work for this, as the linker always only pulls required objects in, except when using -Wl,--whole-archive.

A solution is to directly link all objects instead of creating an archive (which is what we do for druntime & phobos tests now to avoid this problem).

-- 
You are receiving this mail because:
You are watching all bug changes.