My answer is probably incomplete but, until a more complete answer appears, we can start with the following.
1. GCC's manual. Debian and the Free Software Foundation unfortunately have slightly conflicting understandings of what constitutes free software. GCC's manual might help you at the moment, but the manual has been segregated for minor, technical legal reasons to Debian's non-free archive.
It goes against the spirit of Debian to advise anyone to install from non-free, doesn't it? I will only say that I have installed GCC's manual from non-free on my own Debian box as follows. In /etc/apt/sources.list:
deb http://mirror.us.leaseweb.net/debian/ stretch main contrib non-free
deb-src http://mirror.us.leaseweb.net/debian/ stretch main contrib non-free
(You can list whichever mirror you like, but Leaseweb's is as good as any.) Then, apt-get update
and apt-get install gcc-doc
, followed by info gcc
.)
2. Options to GCC. In GCC's manual, you can open the chapter "Invoking GCC," open the section "Code Gen Options," and press /
to search for -fPIC
. The explanation there is terse and technical, but it starts your investigation in the right place. (Even if the explanation does not make sense to you now, you'll return to it later.)
3. Uekawa's Debian Library Packaging Guide. The most illuminating document however is somewhat a secret. It is a standard Debian document, known to Debian Developers, which for obscure reasons is not packaged in Debian, so non-Developers usually don't know about it. Here it is.
The linked document tells you how these libraries work, how one compiles and links them, and so on. However, if you need to know more....
4. The ELF Specification.
These detail the format to which GCC builds and ld.gold
links.
5. Autotools. At some point, your investigation might lead you to the GNU Autotools—namely, Autoconf, Automake, Libtool, M4, and so on. I do not believe that the Autotools will solve your problem and, even if they did, I doubt that they would do it in a way that illuminated your understanding of the process. The Autotools can be useful but, in your particular case, I would avoid pursuing the Autotools for the time being. Focus on the other sources, rather.
Admittedly, someone out there probably knows a more direct answer to your question but, as of this writing, that person had not yet posted. Meanwhile, if you need to research it for yourself, my answer has given the sources. Reading those is what I would do. Though not a Haskell programmer, reading those is how I have solved similar linking problems in the past. Those are the standard sources.
The reading is most educational and is broadly useful in any case, so it won't waste your time.
(I would recommend that you avoid accepting my answer even if you choose to upvote it. Your question is a good question. We want this question to remain open until it has drawn a more direct answer than mine.)