Non deterministic order of DT_NEEDED entries in dynamic libraries
## Summary
In GHC 9.10 (and probably in newer versions as well, I haven't verified this) the order of DT_NEEDED entries in dynamic libraries that GHC produces is non-deterministic. This results in non-reproducible builds, and has been reported as a bug in Debian [here](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1125305).
## Steps to reproduce
```bash
$ mkdir -p haskell/{foo,bar,baz}
$ cd haskell/foo/
$ cabal init --non-interactive --lib --dependency=base --package-name=foo
$ cd ../bar/
$ cabal init --non-interactive --lib --dependency=base --package-name=bar
$ cd ../baz/
$ cabal init --non-interactive --lib --dependency=base,foo,bar --package-name=baz
$ cd ..
$ echo 'packages: */*.cabal */' > cabal.project
$ cabal build foo
$ cabal build baz
$ ldd dist-newstyle/build/x86_64-linux/ghc-*/baz-0.1.0.0/build/libHSbaz-0.1.0.0-inplace-*.so
[..]
libHSfoo-0.1.0.0-inplace-ghc9.10.3.so => /home/jspricke/haskell/dist-newstyle/build/x86_64-linux/ghc-9.10.3/foo-0.1.0.0/build/libHSfoo-0.1.0.0-inplace-ghc9.10.3.so (0x00007f787a138000)
libHSbar-0.1.0.0-inplace-ghc9.10.3.so => /home/jspricke/haskell/dist-newstyle/build/x86_64-linux/ghc-9.10.3/bar-0.1.0.0/build/libHSbar-0.1.0.0-inplace-ghc9.10.3.so (0x00007f787a133000)
$ rm -r dist-newstyle/
$ cabal build bar
$ cabal build baz
$ ldd dist-newstyle/build/x86_64-linux/ghc-*/baz-0.1.0.0/build/libHSbaz-0.1.0.0-inplace-*.so
[..]
libHSbar-0.1.0.0-inplace-ghc9.10.3.so => /home/jspricke/haskell/dist-newstyle/build/x86_64-linux/ghc-9.10.3/bar-0.1.0.0/build/libHSbar-0.1.0.0-inplace-ghc9.10.3.so (0x00007fc869fb4000)
libHSfoo-0.1.0.0-inplace-ghc9.10.3.so => /home/jspricke/haskell/dist-newstyle/build/x86_64-linux/ghc-9.10.3/foo-0.1.0.0/build/libHSfoo-0.1.0.0-inplace-ghc9.10.3.so (0x00007fc869faf000)
```
## Expected behavior
GHC was producing deterministic results up to version 9.6.
## Bug Analysis
This regression was introduced with commit https://gitlab.haskell.org/ghc/ghc/-/commit/3b5be05, where the switch from Data.Map to UniqMap introduced non-determinism in the order of the packages passed to the linker. The following patch restores the previous behavior by explicitly sorting the package lists derived from the UniqMap
```diff
diff --git a/compiler/GHC/Unit/State.hs b/compiler/GHC/Unit/State.hs
index 6475597450..7519d5b0e9 100644
--- a/compiler/GHC/Unit/State.hs
+++ b/compiler/GHC/Unit/State.hs
@@ -112,7 +112,7 @@ import System.FilePath as FilePath
import Control.Monad
import Data.Graph (stronglyConnComp, SCC(..))
import Data.Char ( toUpper )
-import Data.List ( intersperse, partition, sortBy, sortOn )
+import Data.List ( intersperse, partition, sortBy, sortOn, sort )
import Data.Set (Set)
import Data.Monoid (First(..))
import qualified Data.Semigroup as Semigroup
@@ -1694,7 +1694,7 @@ mkUnitState logger cfg = do
-- NB: preload IS important even for type-checking, because we
-- need the correct include path to be set.
--
- let preload1 = nonDetKeysUniqMap (filterUniqMap (isJust . uv_explicit) vis_map)
+ let preload1 = sort $ nonDetKeysUniqMap (filterUniqMap (isJust . uv_explicit) vis_map)
-- add default preload units if they can be found in the db
basicLinkedUnits = fmap (RealUnit . Definite)
```
I am not sure if there are other places where the order matter, but since this patch seems to work, I can submit a PR if you believe it's the right approach.
issue