[Git][ghc/ghc][wip/romes/graph-compact-easy] 2 commits: rts: remove -Wl,-U,___darwin_check_fd_set_overflow hack

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Tue Dec 3 11:10:56 UTC 2024


Rodrigo Mesquita pushed to branch wip/romes/graph-compact-easy at Glasgow Haskell Compiler / GHC


Commits:
45fb9238 by Cheng Shao at 2024-12-02T18:07:57+00:00
rts: remove -Wl,-U,___darwin_check_fd_set_overflow hack

This patch bumps macOS minimum SDK version to 11.0 for x86_64-darwin
to align it with aarch64-darwin. This allows us to get rid of the
horrible -Wl,-U,___darwin_check_fd_set_overflow hack, which is causing
linker warnings and testsuite failures on macOS 15. Fixes #25504.

- - - - -
b5d0b857 by Rodrigo Mesquita at 2024-12-03T11:10:47+00:00
HPT fixes

- - - - -


6 changed files:

- .gitlab/generate-ci/gen_ci.hs
- .gitlab/jobs.yaml
- compiler/GHC/Unit/Home/PackageTable.hs
- ghc/GHCi/Leak.hs
- ghc/GHCi/UI.hs
- rts/rts.cabal


Changes:

=====================================
.gitlab/generate-ci/gen_ci.hs
=====================================
@@ -444,7 +444,7 @@ opsysVariables AArch64 (Darwin {}) =
           ]
 opsysVariables Amd64 (Darwin {}) =
   mconcat [ "NIX_SYSTEM" =: "x86_64-darwin"
-          , "MACOSX_DEPLOYMENT_TARGET" =: "10.13"
+          , "MACOSX_DEPLOYMENT_TARGET" =: "11.0"
           -- "# Only Sierra and onwards supports clock_gettime. See #12858"
           , "ac_cv_func_clock_gettime" =: "no"
           -- # Only newer OS Xs support utimensat. See #17895


=====================================
.gitlab/jobs.yaml
=====================================
@@ -1072,7 +1072,7 @@
       "HADRIAN_ARGS": "--docs=no-sphinx-pdfs",
       "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
       "LANG": "en_US.UTF-8",
-      "MACOSX_DEPLOYMENT_TARGET": "10.13",
+      "MACOSX_DEPLOYMENT_TARGET": "11.0",
       "NIX_SYSTEM": "x86_64-darwin",
       "RUNTEST_ARGS": "",
       "TEST_ENV": "x86_64-darwin-validate",
@@ -3834,7 +3834,7 @@
       "IGNORE_PERF_FAILURES": "all",
       "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
       "LANG": "en_US.UTF-8",
-      "MACOSX_DEPLOYMENT_TARGET": "10.13",
+      "MACOSX_DEPLOYMENT_TARGET": "11.0",
       "NIX_SYSTEM": "x86_64-darwin",
       "RUNTEST_ARGS": "",
       "TEST_ENV": "x86_64-darwin-release",
@@ -5213,7 +5213,7 @@
       "HADRIAN_ARGS": "--docs=no-sphinx-pdfs",
       "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
       "LANG": "en_US.UTF-8",
-      "MACOSX_DEPLOYMENT_TARGET": "10.13",
+      "MACOSX_DEPLOYMENT_TARGET": "11.0",
       "NIX_SYSTEM": "x86_64-darwin",
       "RUNTEST_ARGS": "",
       "TEST_ENV": "x86_64-darwin-validate",


=====================================
compiler/GHC/Unit/Home/PackageTable.hs
=====================================
@@ -72,6 +72,16 @@ module GHC.Unit.Home.PackageTable
 
     -- * Utilities
   , pprHPT
+
+    -- * Internals
+    --
+    -- | These provide access to the internals of the HomePackageTable to
+    -- facilitate existing workflows that used the previous API. For instance,
+    -- if you were listing out all elements, you can keep doing so by reading
+    -- the internal IO ref and then listing the moduleenv contents out.
+    --
+    -- In GHC itself these should be avoided.
+  , hptInternalTableRef
   ) where
 
 import GHC.Prelude
@@ -122,7 +132,7 @@ data HomePackageTable = HPT {
     -- about the table 'HomeModInfo' updates. On insertions we must make sure to
     -- update this field (insertions can only be done through the API exposed).
 
-    lastLoadedKey :: !(Maybe Unique)
+    lastLoadedKey :: Maybe Unique
     -- ^ What was the last module loaded into this HPT?
     --
     -- Like 'hasHoles', this is a cache that is updated with insertions and kept
@@ -180,12 +190,15 @@ addHomeModInfoToHpt :: HomeModInfo -> HomePackageTable -> IO HomePackageTable
 addHomeModInfoToHpt hmi hpt = addToHpt hpt (moduleName (mi_module (hm_iface hmi))) hmi
   where
     addToHpt :: HomePackageTable -> ModuleName -> HomeModInfo -> IO HomePackageTable
-    addToHpt HPT{table=hptr, hasHoles} mn hmi = do
-      atomicModifyIORef' hptr (\hpt -> (addToUDFM hpt mn hmi, ()))
+    addToHpt HPT{table=hptr, hasHoles, lastLoadedKey} mn hmi = do
+      alreadyExisted <- atomicModifyIORef' hptr (\hpt -> (addToUDFM hpt mn hmi, elemUDFM mn hpt))
+      -- If the key already existed in the map, this insertion is overwriting
+      -- the HMI of a previously loaded module (likely in rehydration).
       return
         HPT{ table = hptr
            , hasHoles = hasHoles && isHoleModule (mi_semantic_module (hm_iface hmi))
-           , lastLoadedKey = Just $! getUnique mn
+           , lastLoadedKey = if alreadyExisted then lastLoadedKey
+                                               else Just $! getUnique mn
            }
 
 ----------------------------------------------------------------------------------
@@ -429,3 +442,12 @@ concatHpt f HPT{table} = do
   return $ concat . eltsUDFM . mapMaybeUDFM g $ hpt
   where
     g hmi = case f hmi of { [] -> Nothing; as -> Just as }
+
+--------------------------------------------------------------------------------
+-- * Internals (see haddocks!)
+--------------------------------------------------------------------------------
+
+-- | Gets the internal 'IORef' which holds the 'HomeModInfo's of this HPT.
+-- Use with care.
+hptInternalTableRef :: HomePackageTable -> IORef (DModuleNameEnv HomeModInfo)
+hptInternalTableRef = table


=====================================
ghc/GHCi/Leak.hs
=====================================
@@ -41,7 +41,8 @@ data LeakModIndicators = LeakModIndicators
 getLeakIndicators :: HscEnv -> IO LeakIndicators
 getLeakIndicators hsc_env =
   fmap LeakIndicators $
-    forM (eltsUDFM (hsc_HPT hsc_env)) $ \hmi at HomeModInfo{..} -> do
+    hpt <- readIORef $ hptInternalTableRef $ hsc_HPT hsc_env
+    forM (eltsUDFM hpt) $ \hmi at HomeModInfo{..} -> do
       leakMod <- mkWeakPtr hmi Nothing
       leakIface <- mkWeakPtr hm_iface Nothing
       leakDetails <- mkWeakPtr hm_details Nothing


=====================================
ghc/GHCi/UI.hs
=====================================
@@ -4494,10 +4494,13 @@ discardInterfaceCache =
 
 clearHPTs :: GhciMonad m => m ()
 clearHPTs = do
-  let pruneHomeUnitEnv hme = hme { homeUnitEnv_hpt = emptyHomePackageTable }
+  let pruneHomeUnitEnv hme = do
+        emptyHpt <- newHomePackageTable
+        pure  hme{ homeUnitEnv_hpt = emptyHpt }
       discardMG hsc = hsc { hsc_mod_graph = GHC.emptyMG }
-  modifySession (discardMG . discardIC . hscUpdateHUG (unitEnv_map pruneHomeUnitEnv))
-
+  modifySessionM $ \hsc_env -> do
+    hug' <- traverse pruneHomeUnitEnv $ hsc_HUG hsc_env
+    pure $ discardMG $ discardIC $ hscUpdateHUG (const hug') hsc_env
 
 -- The unused package warning doesn't make sense once the targets get out of
 -- sync with the package flags. See #21110


=====================================
rts/rts.cabal
=====================================
@@ -332,8 +332,6 @@ library
 
       if os(osx)
         ld-options: "-Wl,-search_paths_first"
-                    -- See Note [fd_set_overflow]
-                    "-Wl,-U,___darwin_check_fd_set_overflow"
                     -- See Note [Undefined symbols in the RTS]
                     "-Wl,-undefined,dynamic_lookup"
         if !arch(x86_64) && !arch(aarch64)
@@ -549,48 +547,6 @@ library
                     -- We don't want to compile posix/ticker/*.c, these will be #included
                     -- from Ticker.c
 
-
--- Note [fd_set_overflow]
--- ~~~~~~~~~~~~~~~~~~~~~~
--- In this note is the very sad tale of __darwin_fd_set_overflow.
--- The 8.10.5 release was broken because it was built in an environment
--- where the libraries were provided by XCode 12.*, these libraries introduced
--- a reference to __darwin_fd_set_overflow via the FD_SET macro which is used in
--- Select.c. Unfortunately, this symbol is not available with XCode 11.* which
--- led to a linker error when trying to link anything. This is almost certainly
--- a bug in XCode but we still have to work around it.
-
--- Undefined symbols for architecture x86_64:
---  "___darwin_check_fd_set_overflow", referenced from:
---      _awaitEvent in libHSrts.a(Select.o)
--- ld: symbol(s) not found for architecture x86_64
-
--- One way to fix this is to upgrade your version of xcode, but this would
--- force the upgrade on users prematurely. Fortunately it also seems safe to pass
--- the linker option "-Wl,-U,___darwin_check_fd_set_overflow" because the usage of
--- the symbol is guarded by a guard to check if it's defined.
-
--- __header_always_inline int
--- __darwin_check_fd_set(int _a, const void *_b)
--- {
---    if ((uintptr_t)&__darwin_check_fd_set_overflow != (uintptr_t) 0) {
---#if defined(_DARWIN_UNLIMITED_SELECT) || defined(_DARWIN_C_SOURCE)
---        return __darwin_check_fd_set_overflow(_a, _b, 1);
---#else
---        return __darwin_check_fd_set_overflow(_a, _b, 0);
---#endif
---    } else {
---        return 1;
---    }
---}
-
--- Across the internet there are many other reports of this issue
---  See: https://github.com/mono/mono/issues/19393
---     , https://github.com/sitsofe/fio/commit/b6a1e63a1ff607692a3caf3c2db2c3d575ba2320
-
--- The issue was originally reported in #19950
-
-
 -- Note [Undefined symbols in the RTS]
 -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 -- The RTS is built with a number of `-u` flags. This is to handle cyclic



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0090429152cedf89c751ce744a5895b92ba63744...b5d0b857568123781e0369445b90ed70af8e3324

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0090429152cedf89c751ce744a5895b92ba63744...b5d0b857568123781e0369445b90ed70af8e3324
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20241203/fdc288a7/attachment-0001.html>


More information about the ghc-commits mailing list