[Git][ghc/ghc][wip/romes/24985] 2 commits: Don't use build CFLAGS and friends as target settings

Rodrigo Mesquita pushed to branch wip/romes/24985 at Glasgow Haskell Compiler / GHC Commits: 670f28fb by Rodrigo Mesquita at 2025-09-19T10:23:26+01:00 Don't use build CFLAGS and friends as target settings In the GHC in tree configure, `CFLAGS`, `CXXFLAGS`, and similar tool configuration flags apply to the BUILD phase of the compiler, i.e. to the tools run to compile GHC itself. Notably, they should /not/ be carried over to the Target settings, i.e. these flags should /not/ apply to the tool which GHC invokes at runtime. Fixes #25637 - - - - - 0b6d63ea by Rodrigo Mesquita at 2025-09-19T10:24:10+01:00 ghc-toolchain: Linker search on target archOS Instead of using CPP of the host platform to determine whether to find linker This mimics the logic in `m4/find_ld.m4` - - - - - 5 changed files: - configure.ac - m4/fp_setup_windows_toolchain.m4 - m4/ghc_toolchain.m4 - utils/ghc-toolchain/exe/Main.hs - utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs Changes: ===================================== configure.ac ===================================== @@ -43,12 +43,6 @@ dnl interprets build/host/target and how this interacts with $CC tests test -n "$target_alias" && ac_tool_prefix=$target_alias- dnl ---------------------------------------------------------- -dnl ** Store USER specified environment variables to pass them on to -dnl ** ghc-toolchain (in m4/ghc-toolchain.m4) -USER_CFLAGS="$CFLAGS" -USER_LDFLAGS="$LDFLAGS" -USER_LIBS="$LIBS" -USER_CXXFLAGS="$CXXFLAGS" dnl The lower-level/not user-facing environment variables that may still be set dnl by developers such as in ghc-wasm-meta USER_CONF_CC_OPTS_STAGE2="$CONF_CC_OPTS_STAGE2" ===================================== m4/fp_setup_windows_toolchain.m4 ===================================== @@ -146,11 +146,11 @@ AC_DEFUN([FP_SETUP_WINDOWS_TOOLCHAIN],[ dnl We override the USER_* flags here since the user delegated dnl configuration to the bundled windows toolchain, and these are the dnl options required by the bundled windows toolchain. - USER_CFLAGS="$CFLAGS" USER_CPP_ARGS="$CONF_CPP_OPTS_STAGE2" - USER_CXXFLAGS="$CXXFLAGS" USER_HS_CPP_ARGS="$HaskellCPPArgs" - USER_LDFLAGS="$CONF_GCC_LINKER_OPTS_STAGE2" + USER_CONF_CC_OPTS_STAGE2="$CONF_CC_OPTS_STAGE2" + USER_CONF_CXX_OPTS_STAGE2="$CONF_CXX_OPTS_STAGE2" + USER_CONF_GCC_LINKER_OPTS_STAGE2="$CONF_GCC_LINKER_OPTS_STAGE2" USER_JS_CPP_ARGS="$JavaScriptCPPArgs" USER_CMM_CPP_ARGS="$CmmCPPArgs" ]) ===================================== m4/ghc_toolchain.m4 ===================================== @@ -8,18 +8,6 @@ AC_DEFUN([ADD_GHC_TOOLCHAIN_ARG], done ]) -dnl $1 argument name -dnl $2 first variable to try -dnl $3 variable to add if the first variable is empty -AC_DEFUN([ADD_GHC_TOOLCHAIN_ARG_CHOOSE], -[ - if test -z "$2"; then - ADD_GHC_TOOLCHAIN_ARG([$1],[$3]) - else - ADD_GHC_TOOLCHAIN_ARG([$1],[$2]) - fi -]) - AC_DEFUN([ENABLE_GHC_TOOLCHAIN_ARG], [ if test "$2" = "YES"; then @@ -123,10 +111,9 @@ AC_DEFUN([FIND_GHC_TOOLCHAIN], ENABLE_GHC_TOOLCHAIN_ARG([dwarf-unwind], [$enable_dwarf_unwind]) dnl We store USER_* variants of all user-specified flags to pass them over to ghc-toolchain. - ADD_GHC_TOOLCHAIN_ARG_CHOOSE([cc-opt], [$USER_CONF_CC_OPTS_STAGE2], [$USER_CFLAGS]) - ADD_GHC_TOOLCHAIN_ARG_CHOOSE([cc-link-opt], [$USER_CONF_GCC_LINKER_OPTS_STAGE2], [$USER_LDFLAGS]) - ADD_GHC_TOOLCHAIN_ARG([cc-link-opt], [$USER_LIBS]) - ADD_GHC_TOOLCHAIN_ARG_CHOOSE([cxx-opt], [$USER_CONF_CXX_OPTS_STAGE2], [$USER_CXXFLAGS]) + ADD_GHC_TOOLCHAIN_ARG([cc-opt], [$USER_CONF_CC_OPTS_STAGE2]) + ADD_GHC_TOOLCHAIN_ARG([cc-link-opt], [$USER_CONF_GCC_LINKER_OPTS_STAGE2]) + ADD_GHC_TOOLCHAIN_ARG([cxx-opt], [$USER_CONF_CXX_OPTS_STAGE2]) ADD_GHC_TOOLCHAIN_ARG([cpp-opt], [$USER_CPP_ARGS]) ADD_GHC_TOOLCHAIN_ARG([hs-cpp-opt], [$USER_HS_CPP_ARGS]) ADD_GHC_TOOLCHAIN_ARG([js-cpp-opt], [$USER_JS_CPP_ARGS]) ===================================== utils/ghc-toolchain/exe/Main.hs ===================================== @@ -428,17 +428,21 @@ archHasNativeAdjustors = \case ArchJavaScript -> True _ -> False - --- | The platforms which we attempt to override ld +-- | The platforms which we attempt to override ld: +-- Should we attempt to find a more efficient linker on this platform? ldOverrideWhitelist :: ArchOS -> Bool ldOverrideWhitelist a = case archOS_OS a of + -- N.B. On Darwin it is quite important that we use the system linker + -- unchanged as it is very easy to run into broken setups (e.g. unholy mixtures + -- of Homebrew and the Apple toolchain). + -- + -- See #21712. + OSDarwin -> False OSLinux -> True OSMinGW32 -> True _ -> False - - mkTarget :: Opts -> M Target mkTarget opts = do normalised_triple <- normaliseTriple (fromMaybe (error "missing --triple") (optTriple opts)) @@ -459,7 +463,8 @@ mkTarget opts = do cmmCpp <- findCmmCpp (optCmmCpp opts) cc0 cc <- addPlatformDepCcFlags archOs cc0 readelf <- optional $ findReadelf (optReadelf opts) - ccLink <- findCcLink tgtLlvmTarget (optLd opts) (optCcLink opts) (ldOverrideWhitelist archOs && fromMaybe True (optLdOverride opts)) archOs cc readelf + ccLink <- findCcLink tgtLlvmTarget (optLd opts) (optCcLink opts) + (ldOverrideWhitelist archOs && fromMaybe True (optLdOverride opts)) archOs cc readelf ar <- findAr tgtVendor (optAr opts) -- TODO: We could have ===================================== utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs ===================================== @@ -83,7 +83,7 @@ findCcLink target ld progOpt ldOverride archOs cc readelf = checking "for C comp -- | Try to convince @cc@ to use a more efficient linker than @bfd.ld@ findLinkFlags :: Bool -> Cc -> Program -> M Program findLinkFlags enableOverride cc ccLink - | enableOverride && doLinkerSearch = + | enableOverride = oneOf "this can't happen" [ -- Annoyingly, gcc silently falls back to vanilla ld (typically bfd -- ld) if @-fuse-ld@ is given with a non-existent linker. @@ -105,20 +105,6 @@ linkSupportsTarget archOs cc target link = checking "whether cc linker supports --target" $ supportsTarget archOs (Lens id const) (checkLinkWorks cc) target link --- | Should we attempt to find a more efficient linker on this platform? --- --- N.B. On Darwin it is quite important that we use the system linker --- unchanged as it is very easy to run into broken setups (e.g. unholy mixtures --- of Homebrew and the Apple toolchain). --- --- See #21712. -doLinkerSearch :: Bool -#if defined(linux_HOST_OS) -doLinkerSearch = True -#else -doLinkerSearch = False -#endif - -- | See Note [No PIE when linking] in GHC.Driver.Session checkSupportsNoPie :: Cc -> Program -> M Bool checkSupportsNoPie cc ccLink = checking "whether the cc linker supports -no-pie" $ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/04926a38edb58b4f460b34a19e7296a... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/04926a38edb58b4f460b34a19e7296a... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Rodrigo Mesquita (@alt-romes)