Support linking with --as-needed for Linux shared libraries
Summary
I received a "complaint" in a Fedora Package review that ghc overlinks shlibs:
Actually, the library is overlinked, in the sense that it is directly linked with libraries that supply no symbols it needs. You can verify this by running "ldd -u /usr/lib64/ghc-9.2.6/lib/libHSconstraints-0.13.4-InOzZ0BhTs66yu6vYmTru-ghc9.2.6.so". This suggests it was linked without -Wl,--as-needed. Then again, this seems to be true of every other Haskell shared library. Perhaps -Wl,--as-needed is not used when linking Haskell libraries? Sorry if I am asking stupid questions. I know very little about the ghc toolchain.
Interestingly, the libraries in /usr/lib64/ghc-9.2.6/lib do not have the GNU_RELRO program header, meaning they were linked without -Wl,-z,relro, but the libraries in the x86_64-linux-ghc-9.2.6 subdirectory do have that header.
Steps to reproduce
$ ldd -u ghc-9.4.4-x86_64-unknown-linux/lib/x86_64-linux-ghc-9.4.4/libHSbytestring-0.11.3.1-ghc9.4.4.so
Unused direct dependencies:
/var/home/petersen/Downloads/ghc-9.4.4-x86_64-unknown-linux/lib/x86_64-linux-ghc-9.4.4/./libHSpretty-1.1.3.6-ghc9.4.4.so
/var/home/petersen/Downloads/ghc-9.4.4-x86_64-unknown-linux/lib/x86_64-linux-ghc-9.4.4/./libHSghc-boot-th-9.4.4-ghc9.4.4.so
/var/home/petersen/Downloads/ghc-9.4.4-x86_64-unknown-linux/lib/x86_64-linux-ghc-9.4.4/./libHSdeepseq-1.4.8.0-ghc9.4.4.so
/var/home/petersen/Downloads/ghc-9.4.4-x86_64-unknown-linux/lib/x86_64-linux-ghc-9.4.4/./libHSarray-0.5.4.0-ghc9.4.4.so
/lib64/libgmp.so.10
- Operating System: Fedora Linux
- System Architecture: x86_64