[Git][ghc/ghc][wip/fix-darwin-toolchain-cruft] 8 commits: compiler: add targetHasRTSWays function
Cheng Shao pushed to branch wip/fix-darwin-toolchain-cruft at Glasgow Haskell Compiler / GHC Commits: 69e0ab59 by Cheng Shao at 2026-01-06T19:37:56-05:00 compiler: add targetHasRTSWays function This commit adds a `targetHasRTSWays` util function in `GHC.Driver.Session` to query if the target RTS has a given Ways (e.g. WayThreaded). - - - - - 25a0ab94 by Cheng Shao at 2026-01-06T19:37:56-05:00 compiler: link on-demand external interpreter with threaded RTS This commit makes the compiler link the on-demand external interpreter program with threaded RTS if it is available in the target RTS ways. This is a better default than the previous single-threaded RTS, and it enables the external interpreter to benefit from parallelism when deserializing CreateBCOs messages. - - - - - 92404a2b by Cheng Shao at 2026-01-06T19:37:56-05:00 hadrian: link iserv with threaded RTS This commit makes hadrian link iserv with threaded RTS if it's available in the RTS ways. Also cleans up the iserv main C program which can be replaced by the `-fkeep-cafs` link-time option. - - - - - a20542d2 by Cheng Shao at 2026-01-06T19:38:38-05:00 ghc-internal: remove unused GMP macros This patch removes unused GMP related macros from `ghc-internal`. The in-tree GMP version was hard coded and outdated, but it was not used anywhere anyway. - - - - - 4079dcd6 by Cheng Shao at 2026-01-06T19:38:38-05:00 hadrian: fix in-tree gmp configure error on newer c compilers Building in-tree gmp on newer c compilers that default to c23 fails at configure stage, this patch fixes it, see added comment for explanation. - - - - - 414d1fe1 by Cheng Shao at 2026-01-06T19:39:20-05:00 compiler: fix LLVM backend pdep/pext handling for i386 target This patch fixes LLVM backend's pdep/pext handling for i386 target, and also removes non-existent 128/256/512 bit hs_pdep/hs_pext callees. See amended note for more explanation. Fixes #26450. Co-authored-by: Codex <codex@openai.com> - - - - - c7f6fba3 by Cheng Shao at 2026-01-06T19:39:20-05:00 ci: remove allow_failure flag for i386 alpine job The LLVM codegen issue for i386 has been fixed, and the i386 alpine job should pass now. This commit removes the allow_failure flag so that other i386 regressions in the future are signaled more timely. - - - - - e4c20ab7 by Cheng Shao at 2026-01-07T01:40:15+01:00 ci: update darwin boot ghc to 9.10.3 This patch updates darwin boot ghc to 9.10.3, along with other related updates, and pays off some technical debt here: - Update `nixpkgs` and use the `nixpkgs-25.05-darwin` channel. - Update the `niv` template. - Update LLVM to 21. - Use `stdenvNoCC` to prevent nix packaged apple sdk from being used by boot ghc, and manually set `DEVELOPER_DIR`/`SDKROOT` to enforce the usage of system-wide command line sdk for macos. - When building nix derivation for boot ghc, run `configure` via the `arch` command so that `configure` and its subprocesses pick up the manually specified architecture. - Remove the previous horrible hack that obliterates `configure` to make every autoconf test result in true. `configure` now properly does its job. - Remove the now obsolete configure args and post install settings file patching logic. - Use `scheme-small` for texlive to avoid build failures in certain unused texlive packages, especially on x86_64-darwin. - - - - - 17 changed files: - .gitlab/darwin/nix/sources.json - .gitlab/darwin/nix/sources.nix - .gitlab/darwin/toolchain.nix - .gitlab/generate-ci/gen_ci.hs - .gitlab/jobs.yaml - compiler/GHC.hs - compiler/GHC/CmmToLlvm/CodeGen.hs - compiler/GHC/Driver/Session.hs - compiler/GHC/Runtime/Interpreter/C.hs - compiler/GHC/Runtime/Interpreter/Init.hs - hadrian/src/Packages.hs - hadrian/src/Rules/Gmp.hs - hadrian/src/Settings/Packages.hs - libraries/ghc-internal/configure.ac - libraries/ghc-internal/include/HsIntegerGmp.h.in - − utils/iserv/cbits/iservmain.c - utils/iserv/iserv.cabal.in Changes: ===================================== .gitlab/darwin/nix/sources.json ===================================== @@ -1,26 +1,14 @@ { - "niv": { - "branch": "master", - "description": "Easy dependency management for Nix projects", - "homepage": "https://github.com/nmattia/niv", - "owner": "nmattia", - "repo": "niv", - "rev": "e0ca65c81a2d7a4d82a189f1e23a48d59ad42070", - "sha256": "1pq9nh1d8nn3xvbdny8fafzw87mj7gsmp6pxkdl65w2g18rmcmzx", - "type": "tarball", - "url": "https://github.com/nmattia/niv/archive/e0ca65c81a2d7a4d82a189f1e23a48d59ad42...", - "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" - }, "nixpkgs": { - "branch": "nixos-unstable", + "branch": "nixpkgs-25.05-darwin", "description": "Nix Packages collection", "homepage": "", "owner": "nixos", "repo": "nixpkgs", - "rev": "2893f56de08021cffd9b6b6dfc70fd9ccd51eb60", - "sha256": "1anwxmjpm21msnnlrjdz19w31bxnbpn4kgf93sn3npihi7wf4a8h", + "rev": "ac62194c3917d5f474c1a844b6fd6da2db95077d", + "sha256": "0v6bd1xk8a2aal83karlvc853x44dg1n4nk08jg3dajqyy0s98np", "type": "tarball", - "url": "https://github.com/nixos/nixpkgs/archive/2893f56de08021cffd9b6b6dfc70fd9ccd5...", + "url": "https://github.com/nixos/nixpkgs/archive/ac62194c3917d5f474c1a844b6fd6da2db9...", "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" } } ===================================== .gitlab/darwin/nix/sources.nix ===================================== @@ -10,29 +10,50 @@ let let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; fetch_tarball = pkgs: name: spec: let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; fetch_git = name: spec: let ref = - if spec ? ref then spec.ref else + spec.ref or ( if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; in - builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }; + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); fetch_local = spec: spec.path; @@ -66,16 +87,16 @@ let hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; hasThisAsNixpkgsPath = <nixpkgs> == ./.; in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import <nixpkgs> {} - else - abort - '' - Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import <nixpkgs> { } + else + abort + '' + Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; # The actual fetching function. fetch = pkgs: name: spec: @@ -95,13 +116,13 @@ let # the path directly as opposed to the fetched source. replace = name: drv: let - saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; # Ports of functions for older nix versions @@ -112,7 +133,7 @@ let ); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee... - range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee... stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); @@ -123,43 +144,46 @@ let concatStrings = builtins.concatStringsSep ""; # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d1... - optionalAttrs = cond: as: if cond then as else {}; + optionalAttrs = cond: as: if cond then as else { }; # fetchTarball version that is compatible between all the versions of Nix builtins_fetchTarball = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchTarball; in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; # fetchurl version that is compatible between all the versions of Nix builtins_fetchurl = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchurl; in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchurl attrs; + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; # Create the final "sources" from the config mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) config.sources; + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; # The "config" used by the fetchers mkConfig = { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) , system ? builtins.currentSystem , pkgs ? mkPkgs sources system }: rec { @@ -171,4 +195,4 @@ let }; in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } ===================================== .gitlab/darwin/toolchain.nix ===================================== @@ -11,69 +11,67 @@ let hsPkgs = pkgs.haskellPackages; alex = hsPkgs.alex; happy = hsPkgs.happy; - targetTriple = pkgs.stdenv.targetPlatform.config; + targetTriple = pkgs.stdenvNoCC.targetPlatform.config; ghcBindists = let version = ghc.version; in { - aarch64-darwin = hostPkgs.fetchurl { + aarch64-darwin = hostPkgs.fetchzip { url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-aarch64-apple-darwin.tar.xz"; - sha256 = "sha256-/6+DtdeossBJIMbjkJwL4h3eJ7rzgNCV+ifoQKOi6AQ="; + hash = "sha512-xUlt7zc/OT3a1SR0BxmFFgrabPkWUENATdw4NbQwEi5+nH5yPau+HSrGI5UUoKdO4gdpgZlPaxtI7eSk0fx1+g=="; }; - x86_64-darwin = hostPkgs.fetchurl { + x86_64-darwin = hostPkgs.fetchzip { url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-x86_64-apple-darwin.tar.xz"; - sha256 = "sha256-jPIhiJMOENesUnDUJeIaPatgavc6ZVSTY5NFIAxlC+k="; + hash = "sha512-4/INeJwPPGbOj9MepwnIvIg2lvFkqS8w/3U/I8f6gCsoNlgwPr78iyY9vd6vfMONR1GxNQU3L/lxE07F3P0Qag=="; }; - }; - ghc = pkgs.stdenv.mkDerivation rec { - version = "9.10.1"; + ghc = pkgs.stdenvNoCC.mkDerivation rec { + version = "9.10.3"; name = "ghc"; - src = ghcBindists.${pkgs.stdenv.hostPlatform.system}; + src = ghcBindists.${pkgs.stdenvNoCC.hostPlatform.system}; + + dontUpdateAutotoolsGnuConfigScripts = true; + configureFlags = [ - "CC=/usr/bin/clang" - "CLANG=/usr/bin/clang" "AR=/usr/bin/ar" - "LLC=${llvm}/bin/llc" - "OPT=${llvm}/bin/opt" - "LLVMAS=${llvm_clang}/bin/clang" - "CONF_CC_OPTS_STAGE2=--target=${targetTriple}" - "CONF_CXX_OPTS_STAGE2=--target=${targetTriple}" - "CONF_GCC_LINKER_OPTS_STAGE2=--target=${targetTriple}" + "CC=/usr/bin/clang" + "CXX=/usr/bin/clang++" + "INSTALL=/usr/bin/install" + "INSTALL_NAME_TOOL=/usr/bin/install_name_tool" + "MergeObjsCmd=/usr/bin/ld" + "NM=/usr/bin/nm" + "OTOOL=/usr/bin/otool" + "RANLIB=/usr/bin/ranlib" ]; - buildPhase = "true"; - - # This is a horrible hack because the configure script invokes /usr/bin/clang - # without a `--target` flag. Then depending on whether the `nix` binary itself is - # a native x86 or arm64 binary means that /usr/bin/clang thinks it needs to run in - # x86 or arm64 mode. - - # The correct answer for the check in question is the first one we try, so by replacing - # the condition to true; we select the right C++ standard library still. - preConfigure = '' - sed "s/\"\$CC\" -o actest actest.o \''${1} 2>\/dev\/null/true/i" configure > configure.new - mv configure.new configure - chmod +x configure - cat configure + # Use the arch command to explicitly specify architecture, so that + # configure and its subprocesses would pick up the architecture we + # choose via the system argument. + preConfigure = pkgs.lib.optionalString (system == "aarch64-darwin") '' + substituteInPlace configure \ + --replace-fail "#! /bin/sh" "#!/usr/bin/env -S /usr/bin/arch -arm64 /bin/sh" + '' + pkgs.lib.optionalString (system == "x86_64-darwin") '' + substituteInPlace configure \ + --replace-fail "#! /bin/sh" "#!/usr/bin/env -S /usr/bin/arch -x86_64 /bin/sh" + '' + '' + unset DEVELOPER_DIR SDKROOT + export DEVELOPER_DIR="$(/usr/bin/xcode-select --print-path)" + export SDKROOT="$(/usr/bin/xcrun --sdk macosx --show-sdk-path)" ''; + dontPatchShebangsInConfigure = true; + # N.B. Work around #20253. nativeBuildInputs = [ pkgs.gnused ]; - postInstallPhase = '' - settings="$out/lib/ghc-${version}/settings" - sed -i -e "s%\"llc\"%\"${llvm}/bin/llc\"%" $settings - sed -i -e "s%\"opt\"%\"${llvm}/bin/opt\"%" $settings - sed -i -e "s%\"clang\"%\"/usr/bin/clang\"%" $settings - sed -i -e 's%("C compiler command", "")%("C compiler command", "/usr/bin/clang")%' $settings - sed -i -e 's%("C compiler flags", "")%("C compiler flags", "--target=${targetTriple}")%' $settings - sed -i -e 's%("C++ compiler flags", "")%("C++ compiler flags", "--target=${targetTriple}")%' $settings - sed -i -e 's%("C compiler link flags", "")%("C compiler link flags", "--target=${targetTriple}")%' $settings - ''; + + dontBuild = true; + + enableParallelInstalling = true; + + dontFixup = true; # Sanity check: verify that we can compile hello world. doInstallCheck = true; installCheckPhase = '' - unset DYLD_LIBRARY_PATH $out/bin/ghc --info cd $TMP mkdir test-ghc; cd test-ghc @@ -91,13 +89,13 @@ let ourtexlive = with pkgs; texlive.combine { inherit (texlive) - scheme-medium collection-xetex fncychap titlesec tabulary varwidth + scheme-small collection-xetex fncychap tex-gyre titlesec tabulary varwidth framed capt-of wrapfig needspace dejavu-otf helvetic upquote; }; fonts = with pkgs; makeFontsConf { fontDirectories = [ dejavu_fonts ]; }; - llvm = pkgs.llvm_15; - llvm_clang = pkgs.llvmPackages_15.clang-unwrapped; + llvm = pkgs.llvm_21; + llvm_clang = pkgs.llvmPackages_21.clang-unwrapped; in pkgs.writeTextFile { name = "toolchain"; ===================================== .gitlab/generate-ci/gen_ci.hs ===================================== @@ -1250,7 +1250,7 @@ alpine_x86 = , fullyStaticBrokenTests (disableValidate (allowFailureGroup (standardBuildsWithConfig Amd64 (Linux Alpine312) staticNativeInt))) -- Dynamically linked build, suitable for building your own static executables on alpine , disableValidate (standardBuildsWithConfig Amd64 (Linux Alpine323) (splitSectionsBroken vanilla)) - , allowFailureGroup (standardBuildsWithConfig I386 (Linux Alpine323) (splitSectionsBroken vanilla)) + , standardBuildsWithConfig I386 (Linux Alpine323) (splitSectionsBroken vanilla) ] where -- ghcilink002 broken due to #17869 ===================================== .gitlab/jobs.yaml ===================================== @@ -484,7 +484,7 @@ ".gitlab/ci.sh clean", "cat ci_timings.txt" ], - "allow_failure": true, + "allow_failure": false, "artifacts": { "expire_in": "2 weeks", "paths": [ @@ -1155,7 +1155,7 @@ ".gitlab/ci.sh clean", "cat ci_timings.txt" ], - "allow_failure": true, + "allow_failure": false, "artifacts": { "expire_in": "8 weeks", "paths": [ @@ -4034,7 +4034,7 @@ ".gitlab/ci.sh clean", "cat ci_timings.txt" ], - "allow_failure": true, + "allow_failure": false, "artifacts": { "expire_in": "1 year", "paths": [ ===================================== compiler/GHC.hs ===================================== @@ -719,7 +719,7 @@ setTopSessionDynFlags dflags = do { interpCreateProcess = createIservProcessHook (hsc_hooks hsc_env) } - interp <- liftIO $ initInterpreter tmpfs logger platform finder_cache unit_env interp_opts + interp <- liftIO $ initInterpreter dflags tmpfs logger platform finder_cache unit_env interp_opts modifySession $ \h -> hscSetFlags dflags h{ hsc_IC = (hsc_IC h){ ic_dflags = dflags } ===================================== compiler/GHC/CmmToLlvm/CodeGen.hs ===================================== @@ -248,6 +248,14 @@ Since x86 PDep/PExt instructions only exist for 32/64 bit widths we use the 32bit variant to compute the 8/16bit primops. To do so we extend/truncate the argument/result around the call. + +Note that the 64-bit intrinsics (`llvm.x86.bmi.pdep.64` and +`llvm.x86.bmi.pext.64`) are only legal on 64-bit x86 targets, not on +i386. Therefore on i386 we must fall back to the runtime helper +(`hs_pdep64`/`hs_pext64`) for the 64-bit primops. + +See https://github.com/llvm/llvm-project/issues/172857 for upstream +discussion about portable pdep/pext intrinsics. -} genCall (PrimTarget op@(MO_Pdep w)) [dst] args = do cfg <- getConfig @@ -970,36 +978,34 @@ cmmPrimOpFunctions mop = do W8 -> fsLit "llvm.x86.bmi.pdep.32" W16 -> fsLit "llvm.x86.bmi.pdep.32" W32 -> fsLit "llvm.x86.bmi.pdep.32" - W64 -> fsLit "llvm.x86.bmi.pdep.64" - W128 -> fsLit "llvm.x86.bmi.pdep.128" - W256 -> fsLit "llvm.x86.bmi.pdep.256" - W512 -> fsLit "llvm.x86.bmi.pdep.512" + W64 + | is32bit -> fsLit "hs_pdep64" + | otherwise -> fsLit "llvm.x86.bmi.pdep.64" + -- LLVM only provides x86 PDep/PExt intrinsics for 32/64 bits + _ -> unsupported | otherwise -> case w of W8 -> fsLit "hs_pdep8" W16 -> fsLit "hs_pdep16" W32 -> fsLit "hs_pdep32" W64 -> fsLit "hs_pdep64" - W128 -> fsLit "hs_pdep128" - W256 -> fsLit "hs_pdep256" - W512 -> fsLit "hs_pdep512" + _ -> unsupported MO_Pext w | isBmi2Enabled -> case w of -- See Note [LLVM PDep/PExt intrinsics] W8 -> fsLit "llvm.x86.bmi.pext.32" W16 -> fsLit "llvm.x86.bmi.pext.32" W32 -> fsLit "llvm.x86.bmi.pext.32" - W64 -> fsLit "llvm.x86.bmi.pext.64" - W128 -> fsLit "llvm.x86.bmi.pext.128" - W256 -> fsLit "llvm.x86.bmi.pext.256" - W512 -> fsLit "llvm.x86.bmi.pext.512" + W64 + | is32bit -> fsLit "hs_pext64" + | otherwise -> fsLit "llvm.x86.bmi.pext.64" + -- LLVM only provides x86 PDep/PExt intrinsics for 32/64 bits + _ -> unsupported | otherwise -> case w of W8 -> fsLit "hs_pext8" W16 -> fsLit "hs_pext16" W32 -> fsLit "hs_pext32" W64 -> fsLit "hs_pext64" - W128 -> fsLit "hs_pext128" - W256 -> fsLit "hs_pext256" - W512 -> fsLit "hs_pext512" + _ -> unsupported MO_AddIntC w -> case w of W8 -> fsLit "llvm.sadd.with.overflow.i8" ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -197,6 +197,8 @@ module GHC.Driver.Session ( -- * Compiler configuration suitable for display to the user compilerInfo, + targetHasRTSWays, + wordAlignment, setUnsafeGlobalDynFlags, @@ -3635,6 +3637,15 @@ compilerInfo dflags queryCmdMaybe p f = expandDirectories (query (maybe "" (prgPath . p) . f)) queryFlagsMaybe p f = query (maybe "" (unwords . map escapeArg . prgFlags . p) . f) +-- | Query if the target RTS has the given 'Ways'. It's computed from +-- the @"RTS ways"@ field in the settings file. +targetHasRTSWays :: DynFlags -> Ways -> Bool +targetHasRTSWays dflags ways + | Just ws <- lookup "RTS ways" $ compilerInfo dflags = + waysTag ways + `elem` words ws + | otherwise = panic "RTS ways not found in settings" + -- Note [Special unit-ids] -- ~~~~~~~~~~~~~~~~~~~~~~~ -- Certain units are special to the compiler: ===================================== compiler/GHC/Runtime/Interpreter/C.hs ===================================== @@ -8,7 +8,9 @@ where import GHC.Prelude import GHC.Platform +import GHC.Platform.Ways import GHC.Data.FastString +import GHC.Driver.Session import GHC.Utils.Logger import GHC.Utils.TmpFs import GHC.Unit.Types @@ -18,11 +20,10 @@ import GHC.Unit.State import GHC.Utils.Panic.Plain import GHC.Linker.Executable import GHC.Linker.Config -import GHC.Utils.CliOption -- | Generate iserv program for the target -generateIservC :: Logger -> TmpFs -> ExecutableLinkOpts -> UnitEnv -> IO FilePath -generateIservC logger tmpfs opts unit_env = do +generateIservC :: DynFlags -> Logger -> TmpFs -> ExecutableLinkOpts -> UnitEnv -> IO FilePath +generateIservC dflags logger tmpfs opts unit_env = do -- get the unit-id of the ghci package. We need this to load the -- interpreter code. let unit_state = ue_homeUnitState unit_env @@ -60,6 +61,12 @@ generateIservC logger tmpfs opts unit_env = do -- must retain CAFs for running interpreted code. , leKeepCafs = True + -- link with -threaded if target has threaded RTS + , leWays = + let ways = leWays opts + ways' = addWay WayThreaded ways + in if targetHasRTSWays dflags ways' then ways' else ways + -- enable all rts options , leRtsOptsEnabled = RtsOptsAll ===================================== compiler/GHC/Runtime/Interpreter/Init.hs ===================================== @@ -9,6 +9,7 @@ where import GHC.Prelude +import GHC.Driver.DynFlags import GHC.Platform import GHC.Platform.Ways import GHC.Settings @@ -57,14 +58,15 @@ data InterpOpts = InterpOpts -- | Initialize code interpreter initInterpreter - :: TmpFs + :: DynFlags + -> TmpFs -> Logger -> Platform -> FinderCache -> UnitEnv -> InterpOpts -> IO (Maybe Interp) -initInterpreter tmpfs logger platform finder_cache unit_env opts = do +initInterpreter dflags tmpfs logger platform finder_cache unit_env opts = do lookup_cache <- liftIO $ mkInterpSymbolCache @@ -125,7 +127,7 @@ initInterpreter tmpfs logger platform finder_cache unit_env opts = do dynamic = interpWays opts `hasWay` WayDyn prog <- case interpProg opts of -- build iserv program if none specified - "" -> generateIservC logger tmpfs (interpExecutableLinkOpts opts) unit_env + "" -> generateIservC dflags logger tmpfs (interpExecutableLinkOpts opts) unit_env _ -> pure (interpProg opts ++ flavour) where flavour ===================================== hadrian/src/Packages.hs ===================================== @@ -217,7 +217,7 @@ timeoutPath = "testsuite/timeout/install-inplace/bin/timeout" <.> exe -- TODO: Can we extract this information from Cabal files? -- | Some program packages should not be linked with Haskell main function. nonHsMainPackage :: Package -> Bool -nonHsMainPackage = (`elem` [hp2ps, iserv, unlit, ghciWrapper]) +nonHsMainPackage = (`elem` [hp2ps, unlit, ghciWrapper]) {- ===================================== hadrian/src/Rules/Gmp.hs ===================================== @@ -126,6 +126,12 @@ gmpRules = do interpretInContext ctx $ mconcat [ getStagedCCFlags + -- gmp fails to configure with newer compilers + -- that default to c23: + -- https://gmplib.org/list-archives/gmp-devel/2025-January/006279.html. + -- for now just manually specify -std=gnu11 until + -- next upstream release. + , arg "-std=gnu11" -- gmp symbols are only used by bignum logic in -- ghc-internal and shouldn't be exported by the -- ghc-internal shared library. ===================================== hadrian/src/Settings/Packages.hs ===================================== @@ -41,6 +41,8 @@ packageArgs = do libzstdLibraryDir <- getSetting LibZstdLibDir stageVersion <- readVersion <$> (expr $ ghcVersionStage stage) + rtsWays <- getRtsWays + mconcat --------------------------------- base --------------------------------- [ package base ? mconcat @@ -185,11 +187,15 @@ packageArgs = do -- -- The Solaris linker does not support --export-dynamic option. It also -- does not need it since it exports all dynamic symbols by default - , package iserv - ? expr isElfTarget + , package iserv ? mconcat [ + expr isElfTarget ? notM (expr $ anyTargetOs [OSFreeBSD, OSSolaris2])? mconcat [ builder (Ghc LinkHs) ? arg "-optl-Wl,--export-dynamic" ] + -- Link iserv with -threaded if possible + , builder (Cabal Flags) ? any (wayUnit Threaded) rtsWays `cabalFlag` "threaded" + ] + -------------------------------- haddock ------------------------------- , package haddockApi ? builder (Cabal Flags) ? arg "in-ghc-tree" ===================================== libraries/ghc-internal/configure.ac ===================================== @@ -195,28 +195,10 @@ dnl-------------------------------------------------------------------- if test "$HaveFrameworkGMP" = "YES" || test "$HaveLibGmp" = "YES" then AC_MSG_RESULT([no]) - UseIntreeGmp=0 AC_CHECK_HEADER([gmp.h], , [AC_MSG_ERROR([Cannot find gmp.h])]) - - AC_MSG_CHECKING([GMP version]) - AC_COMPUTE_INT(GhcGmpVerMj, __GNU_MP_VERSION, [#include <gmp.h>], - AC_MSG_ERROR([Unable to get value of __GNU_MP_VERSION])) - AC_COMPUTE_INT(GhcGmpVerMi, __GNU_MP_VERSION_MINOR, [#include <gmp.h>], - AC_MSG_ERROR([Unable to get value of __GNU_MP_VERSION_MINOR])) - AC_COMPUTE_INT(GhcGmpVerPl, __GNU_MP_VERSION_PATCHLEVEL, [#include <gmp.h>], - AC_MSG_ERROR([Unable to get value of __GNU_MP_VERSION_PATCHLEVEL])) - AC_MSG_RESULT([$GhcGmpVerMj.$GhcGmpVerMi.$GhcGmpVerPl]) - else AC_MSG_RESULT([yes]) - UseIntreeGmp=1 HaveSecurePowm=1 - - AC_MSG_CHECKING([GMP version]) - GhcGmpVerMj=6 - GhcGmpVerMi=1 - GhcGmpVerPl=2 - AC_MSG_RESULT([$GhcGmpVerMj.$GhcGmpVerMi.$GhcGmpVerPl]) fi GMP_INSTALL_INCLUDES="HsIntegerGmp.h ghc-gmp.h" @@ -231,10 +213,6 @@ AC_SUBST(GMP_INSTALL_INCLUDES) AC_SUBST(HaveLibGmp) AC_SUBST(HaveFrameworkGMP) AC_SUBST(HaveSecurePowm) -AC_SUBST(UseIntreeGmp) -AC_SUBST(GhcGmpVerMj) -AC_SUBST(GhcGmpVerMi) -AC_SUBST(GhcGmpVerPl) # Compute offsets/sizes used by jsbits/base.js if test "$host" = "javascript-ghcjs" ===================================== libraries/ghc-internal/include/HsIntegerGmp.h.in ===================================== @@ -1,14 +1,4 @@ #pragma once -/* Whether GMP is embedded into ghc-internal */ -#define GHC_GMP_INTREE @UseIntreeGmp@ - -/* The following values denote the GMP version used during GHC build-time */ -#define GHC_GMP_VERSION_MJ @GhcGmpVerMj@ -#define GHC_GMP_VERSION_MI @GhcGmpVerMi@ -#define GHC_GMP_VERSION_PL @GhcGmpVerPl@ -#define GHC_GMP_VERSION \ - (@GhcGmpVerMj@ * 10000 + @GhcGmpVerMi@ * 100 + @GhcGmpVerPl@) - /* Whether GMP supports mpz_powm_sec */ #define HAVE_SECURE_POWM @HaveSecurePowm@ ===================================== utils/iserv/cbits/iservmain.c deleted ===================================== @@ -1,18 +0,0 @@ -#include <ghcversion.h> -# include <rts/PosixSource.h> -#include <Rts.h> - -#include <HsFFI.h> - -int main (int argc, char *argv[]) -{ - RtsConfig conf = defaultRtsConfig; - - // We never know what symbols GHC will look up in the future, so - // we must retain CAFs for running interpreted code. - conf.keep_cafs = 1; - - conf.rts_opts_enabled = RtsOptsAll; - extern StgClosure ZCMain_main_closure; - hs_main(argc, argv, &ZCMain_main_closure, conf); -} ===================================== utils/iserv/iserv.cabal.in ===================================== @@ -23,11 +23,17 @@ Category: Development build-type: Simple cabal-version: >=1.10 +Flag threaded + Description: Link the iserv executable against the threaded RTS + Default: True + Manual: True + Executable iserv Default-Language: Haskell2010 - ghc-options: -no-hs-main + ghc-options: -fkeep-cafs -rtsopts + if flag(threaded) + ghc-options: -threaded Main-Is: Main.hs - C-Sources: cbits/iservmain.c Hs-Source-Dirs: src include-dirs: . Build-Depends: View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4c9d0e22cff41bcd77ae4216f3cbeee... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/4c9d0e22cff41bcd77ae4216f3cbeee... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Cheng Shao (@TerrorJack)