This patch is the first of 2 patches to enable dynamic support on
Windows. This patch should be committed on it's own. Second patch
focuses more on distribution.
This introduces an auto-splitting functions for DLLs. The way the
split is done, no extra handling is required for the rest of the
toolchain. So it's all confined to the shell script that does the work.
Secondly, this script corrects the way symbols were linked. There weren't
enough symbols to go above the threshold. If I measure amount of symbols
in the input object files going into the link and the amount coming out,
the difference is huge.
Looking at it further this is because of two things. We never explicitly
use __declspec, we just change the names of the functions to match the
conventions that __declspec would use.
This is fine, but it means that binutil's default of --export-all-symbols
is still enabled. Which means, we'll re-export any symbol we link from
archives as well.
In fact I got rid of dll-split all together and allow all symbols to go
into the same dll and we end up with:
$ nm -g "R:\ghc\libHSghc-8.1-ghc8.1.20160617.dll" | wc -l 49610
This down from ~240,000 (mingwex and mingw32 are huge for instance).
These two changes should solve the problem once and for all. There is one
caveat, the RTS packages can never be split. The reason is there is a mutual
dependencies between Base and RTS. The cycle is broken at the compilation of
Base, but the build system has no idea about the relationship between these
two, so it assumes RTS is one package and "guesses" the final RTS dll name.
This isn't easy to change, however the RTS doesn't have a ton of symbols,
but do keep an eye out for this:
Number of symbols in object files for rts/dist/build/libHSrts-ghc8.1.20161013.dll: 1273 DLL rts/dist/build/libHSrts-ghc8.1.20161013.dll OK, no need to split
This cycle is also fragile, since ghc-prim is also required before it is built.
So you might get strange link errors because a new closure is needed by the rts
that hasn't been manually added. In that case they should be added to the def
files in rts/win32.
The major limitation in this version is that only the threaded rts can be used.
Due to the fact that we can't link with unknown symbols on Windows in the final
link. This will be addressed next.
More details of how the linking works here