Status of dynamic linking on Windows

As a motivating example, I have a program where the logic is written in Haskell, but the GUI is written in C++ (using Qt). The Haskell code is compiled to a library, which can then be used by the C++ code. On Linux, it’s simple enough to do this by compiling the Haskell package to a shared library with -dynamic -shared -fPIC -fPIE -flink-rt. By contrast, on Windows I’ve been compiling it to a static library instead (with -static -optl-static -staticlib).

However, in the process of releasing a new version, today I tried recompiling it on Windows, and got a nasty error about relocation truncated to fit: R_X86_64_32. Looking this up, apparently it means my static library has gotten too big to link easily — and since GHC doesn’t seem to support changing the code model, the obvious alternative would be to use dynamic linking on Windows too.

Which leads me to my question: what is the status of dynamic linking on Windows currently? The GHC User’s Guide suggests that it should be fairly simple to accomplish. But the relevant GHC Wiki article says there are problems with the ordinal value getting too large when the DLL has too many symbols. Normally I’d discount a 4-year-old article in favour of the current user’s guide… except that when I tried compiling to a DLL, I did indeed get an error message saying that the ordinals were too large. On Linux, each package is compiled to a separate .so file, which keeps them fairly small, but when I try the same GHC options on Windows, it just complains that there are no 'dyn' versions of the dependencies. Which would seem to indicate that it would work if I could compile the dependencies dynamically, but I can’t find any information on how to do so. This whole situation is quite confusing, and I would greatly appreciate some clarification on GHC’s support for compiling shared libraries on Windows.

1 Like

Hi @bradrn, you might have better luck simply opening an issue on the GHC issue tracker. Or maybe comment on one of the existing ones. Some of them are truly ancient:

If you don’t have an account already, ping me when you create one so I can manually approve it.

Thanks for the suggestions @chreekat! But I’m not convinced making another issue will help here… as you note, we already have plenty of issues. I know that the Haskell Foundation maintains a few repos to discuss GHC proposals — perhaps one of those might be more suitable for instigating work in this area?

On the one hand, I think that more issues about specific problems are good: you have a really specific reproduction here, and I can’t tell if it’s actually covered by one of the existing issues or not! Specific examples are much better to work with than overly-general ones.

On the other, I don’t know what group, if any, could be a good fit for discussing a problem where everyone agrees it’s a problem but nobody’s working on it. (There’s a lot of those.) Maybe the technical working group? @david-christiansen might have pointers.

Except, sad to say, I don’t really: my ‘specific reproduction’ is just ‘I tried to compile a random program with -dynamic and failed on Windows’. It seems likely to me that this is actually caused by the combination of the many smaller dynamic-linking-related issues which GHC has on Windows.

(Ironically, the most specific issue I’m having on Windows is related to static issues: as I said above, it seems straightforwardly the case that the resulting static library is just too large for the code model.)

If you’d like to propose that HF fund getting this fixed, then TWG is the right place to go. Getting to there may require doing a bit of leg-work, however - the first step is to figure out what actually needs to be fixed so that a budget for the work can be drawn up.

I second @chreekat’s recommendation that you create an issue. Even though the program itself is big, if it’s open source, then a decent reproducer would be something like a quick Powershell script that grabs the dependencies and builds it, exhibiting the error.

(off topic) brassica looks rad, by the way. I’m not a linguist but I do like me some language history.

1 Like

Oh, I wasn’t even considering funding! At the moment, all I want is to start a conversation around something which seems like it’s been stalled for many years.

This sounds very reasonable. It doesn’t even need a PowerShell script — it’s basically just cabal build then cmake. [EDIT: even cmake turns out to be unnecessary!] I’ll open an issue now.

Ooh, thanks! On a GHC-related note: the fancy web interface is thanks to the new WASM backend, which made it considerably easier for me to link up Haskell and JavaScript.

1 Like

Done! See #23644: Dynamic linking support on Windows · Issues · Glasgow Haskell Compiler / GHC · GitLab.

1 Like