From 3fdb18f8df209ebfee51f16288c46acd1ca024b2 Mon Sep 17 00:00:00 2001 From: romes Date: Mon, 13 Mar 2023 15:04:28 +0000 Subject: Hardwire a better unit-id for ghc Previously, the unit-id of ghc-the-library was fixed as `ghc`. This was done primarily because the compiler must know the unit-id of some packages (including ghc) a-priori to define wired-in names. However, as seen in #20742, a reinstallable `ghc` whose unit-id is fixed to `ghc` might result in subtle bugs when different ghc's interact. A good example of this is having GHC_A load a plugin compiled by GHC_B, where GHC_A and GHC_B are linked to ghc-libraries that are ABI incompatible. Without a distinction between the unit-id of the ghc library GHC_A is linked against and the ghc library the plugin it is loading was compiled against, we can't check compatibility. This patch gives a slightly better unit-id to ghc (ghc-version) by (1) Not setting -this-unit-id to ghc, but rather to the new unit-id (modulo stage0) (2) Adding a definition to `GHC.Settings.Config` whose value is the new unit-id. (2.1) `GHC.Settings.Config` is generated by Hadrian (2.2) and also by cabal through `compiler/Setup.hs` This unit-id definition is imported by `GHC.Unit.Types` and used to set the wired-in unit-id of "ghc", which was previously fixed to "ghc" The commits following this one will improve the unit-id with a cabal-style package hash and check compatibility when loading plugins. Note that we also ensure that ghc's unit key matches unit id both when hadrian or cabal builds ghc, and in this way we no longer need to add `ghc` to the WiringMap. --- testsuite/tests/driver/j-space/jspace.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'testsuite/tests') diff --git a/testsuite/tests/driver/j-space/jspace.hs b/testsuite/tests/driver/j-space/jspace.hs index b0c83eb4d1..7f1ef697e8 100644 --- a/testsuite/tests/driver/j-space/jspace.hs +++ b/testsuite/tests/driver/j-space/jspace.hs @@ -2,6 +2,7 @@ module Main where import GHC import GHC.Driver.Monad +import GHC.Driver.Session import System.Environment import GHC.Driver.Env.Types import GHC.Profiling @@ -25,6 +26,9 @@ initGhcM xs = do let cmdOpts = ["-fforce-recomp"] ++ xs (df2, leftovers, _) <- parseDynamicFlags (hsc_logger session) df1 (map noLoc cmdOpts) setSessionDynFlags df2 + ghcUnitId <- case lookup "Project Unit Id" (compilerInfo df2) of + Nothing -> fail "failed to find ghc's unit-id in the compiler info" + Just ghcUnitId -> pure ghcUnitId ts <- mapM (\s -> guessTarget s Nothing Nothing) $ map unLoc leftovers setTargets ts _ <- load LoadAllTargets @@ -36,7 +40,7 @@ initGhcM xs = do liftIO $ do requestHeapCensus performGC - [ys] <- filter (isPrefixOf "ghc:GHC.Unit.Module.ModDetails.ModDetails") . lines <$> readFile "jspace.hp" + [ys] <- filter (isPrefixOf (ghcUnitId <> ":GHC.Unit.Module.ModDetails.ModDetails")) . lines <$> readFile "jspace.hp" let (n :: Int) = read (last (words ys)) -- The output should be 50 * 8 * word_size (i.e. 3200, or 1600 on 32-bit architectures): -- the test contains DEPTH + WIDTH + 2 = 50 modules J, H_0, .., H_DEPTH, W_1, .., W_WIDTH, -- cgit v1.2.1