[Git][ghc/ghc][wip/toolchain-selection] 3 commits: Remove more settings bits from hadrian/cfg

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Tue May 30 16:27:57 UTC 2023



Rodrigo Mesquita pushed to branch wip/toolchain-selection at Glasgow Haskell Compiler / GHC


Commits:
37aa0f13 by Rodrigo Mesquita at 2023-05-30T10:43:58+01:00
Remove more settings bits from hadrian/cfg

- - - - -
188f60e3 by Rodrigo Mesquita at 2023-05-30T17:27:11+01:00
Use llvm target from ghc-toolchain

- - - - -
cdb184e4 by Rodrigo Mesquita at 2023-05-30T17:27:50+01:00
Print default.target

- - - - -


10 changed files:

- hadrian/cfg/system.config.in
- hadrian/src/Oracles/Flag.hs
- hadrian/src/Oracles/Setting.hs
- hadrian/src/Rules/Generate.hs
- hadrian/stack.yaml
- m4/ghc_toolchain.m4
- mk/project.mk.in
- utils/ghc-toolchain/Main.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Target.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cc.hs


Changes:

=====================================
hadrian/cfg/system.config.in
=====================================
@@ -11,11 +11,8 @@ cc             = @CC@
 happy          = @HappyCmd@
 ld             = @LD@
 make           = @MakeCmd@
-system-merge-objects = @LD_STAGE0@
 objdump        = @ObjdumpCmd@
 sphinx-build   = @SPHINXBUILD@
-system-ar      = @AR_STAGE0@
-system-cc      = @CC_STAGE0@
 system-ghc     = @WithGhc@
 system-ghc-pkg = @GhcPkgCmd@
 tar            = @TarCmd@
@@ -34,16 +31,12 @@ python         = @PythonCmd@
 # Information about builders:
 #============================
 
-system-ar-supports-at-file = @ArSupportsAtFile_STAGE0@
-system-ar-supports-dash-l = @ArSupportsDashL_STAGE0@
 cc-llvm-backend           = @CcLlvmBackend@
 
 # Build options:
 #===============
 
-use-libffi-for-adjustors = @UseLibffiForAdjustors@
 ghc-source-path      = @hardtop@
-leading-underscore   = @LeadingUnderscore@
 
 # Information about build, host and target systems:
 #==================================================
@@ -59,7 +52,6 @@ host-vendor           = @HostVendor_CPP@
 target-platform       = @TargetPlatform@
 target-platform-full  = @TargetPlatformFull@
 target-vendor         = @TargetVendor_CPP@
-llvm-target           = @LLVMTarget_CPP@
 
 cross-compiling       = @CrossCompiling@
 
@@ -89,21 +81,7 @@ project-git-commit-id  = @ProjectGitCommitId@
 # might become redundant.
 # See Note [tooldir: How GHC finds mingw on Windows]
 
-# ROMES:TODO: Drop almost every of these from settings.
-settings-c-compiler-command = @SettingsCCompilerCommand@
-settings-cxx-compiler-command = @SettingsCxxCompilerCommand@
-settings-cpp-command = @SettingsCPPCommand@
-settings-cpp-flags = @SettingsCPPFlags@
-settings-haskell-cpp-command = @SettingsHaskellCPPCommand@
-settings-haskell-cpp-flags = @SettingsHaskellCPPFlags@
-settings-c-compiler-flags = @SettingsCCompilerFlags@
-settings-cxx-compiler-flags = @SettingsCxxCompilerFlags@
-settings-c-compiler-link-flags = @SettingsCCompilerLinkFlags@
-settings-c-compiler-supports-no-pie = @SettingsCCompilerSupportsNoPie@
-settings-merge-objects-command = @SettingsMergeObjectsCommand@
-settings-merge-objects-flags = @SettingsMergeObjectsFlags@
-settings-ar-command = @SettingsArCommand@
-settings-ranlib-command = @SettingsRanlibCommand@
+# ROMES:TODO: Get rid of some of these settings completely?
 settings-otool-command = @SettingsOtoolCommand@
 settings-install_name_tool-command = @SettingsInstallNameToolCommand@
 settings-dll-wrap-command = @SettingsDllWrapCommand@
@@ -114,8 +92,6 @@ settings-llc-command = @SettingsLlcCommand@
 settings-opt-command = @SettingsOptCommand@
 settings-use-distro-mingw = @SettingsUseDistroMINGW@
 
-target-word-size = @TargetWordSize@
-target-word-big-endian = @TargetWordBigEndian@
 target-has-libm = @TargetHasLibm@
 
 # Include and library directories:


=====================================
hadrian/src/Oracles/Flag.hs
=====================================
@@ -70,7 +70,7 @@ flag f = do
             UseSystemFfi         -> SystemConfigKey "use-system-ffi"
             BootstrapThreadedRts -> SystemConfigKey "bootstrap-threaded-rts"
             BootstrapEventLoggingRts -> SystemConfigKey "bootstrap-event-logging-rts"
-            UseLibffiForAdjustors -> SystemConfigKey "use-libffi-for-adjustors"
+            UseLibffiForAdjustors -> HostTargetKey tgtUseLibffiForAdjustors
             UseLibdw             -> SystemConfigKey "use-lib-dw"
             UseLibnuma           -> SystemConfigKey "use-lib-numa"
             UseLibm              -> SystemConfigKey "use-lib-m"


=====================================
hadrian/src/Oracles/Setting.hs
=====================================
@@ -149,7 +149,7 @@ setting key = case key of
     LibdwLibDir        -> systemConf "libdw-lib-dir"
     LibnumaIncludeDir  -> systemConf "libnuma-include-dir"
     LibnumaLibDir      -> systemConf "libnuma-lib-dir"
-    LlvmTarget         -> systemConf "llvm-target"
+    LlvmTarget         -> targetConf tgtLlvmTarget
     ProjectGitCommitId -> systemConf "project-git-commit-id"
     ProjectName        -> systemConf "project-name"
     ProjectVersion     -> systemConf "project-version"
@@ -167,7 +167,7 @@ setting key = case key of
     TargetVendor       -> systemConf "target-vendor"
     TargetArchHaskell  -> targetConf (show . archHaskell)
     TargetOsHaskell    -> targetConf (show . osHaskell)
-    TargetWordSize     -> systemConf "target-word-size" -- targetConf tgtWordSize
+    TargetWordSize     -> targetConf (show . wordSize2Bytes . tgtWordSize)
     BourneShell        -> systemConf "bourne-shell"
   where
     systemConf = lookupSystemConfig


=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -23,6 +23,7 @@ import Target
 import Utilities
 
 import qualified GHC.Toolchain as Toolchain
+import GHC.Toolchain (Endianness(..), wordSize2Bytes)
 import GHC.Toolchain.Program (prgFlags)
 
 -- | Track this file to rebuild generated files whenever it changes.
@@ -448,8 +449,8 @@ generateSettings = do
         , ("target platform string", getSetting TargetPlatform)
         , ("target os", getSetting TargetOsHaskell)
         , ("target arch", getSetting TargetArchHaskell)
-        , ("target word size", expr $ lookupSystemConfig "target-word-size")
-        , ("target word big endian", expr $ lookupSystemConfig "target-word-big-endian")
+        , ("target word size", expr $ queryTargetTargetConfig wordSize)
+        , ("target word big endian", expr $ queryTargetTargetConfig isBigEndian)
         , ("target has GNU nonexec stack", expr $ queryTargetTargetConfig (yesNo . Toolchain.tgtSupportsGnuNonexecStack))
         , ("target has .ident directive", expr $ queryTargetTargetConfig (yesNo . Toolchain.tgtSupportsIdentDirective))
         , ("target has subsections via symbols", expr $ queryTargetTargetConfig (yesNo . Toolchain.tgtSupportsSubsectionsViaSymbols))
@@ -482,6 +483,8 @@ generateSettings = do
     linkSupportsCompactUnwind   = yesNo . Toolchain.ccLinkSupportsCompactUnwind . Toolchain.tgtCCompilerLink
     linkIsGnu                   = yesNo . Toolchain.ccLinkIsGnu . Toolchain.tgtCCompilerLink
     arFlags = unwords . prgFlags . Toolchain.arMkArchive . Toolchain.tgtAr
+    isBigEndian = yesNo . (\case BigEndian -> True; LittleEndian -> False) . Toolchain.tgtEndianness 
+    wordSize    = show . wordSize2Bytes . Toolchain.tgtWordSize
 
 
 


=====================================
hadrian/stack.yaml
=====================================
@@ -2,6 +2,7 @@ resolver: lts-19.8
 
 packages:
 - '.'
+- 'utils/ghc-toolchain'
 
 nix:
    enable: false
@@ -12,3 +13,4 @@ nix:
    - git
    - ncurses
    - perl
+   - ghc-toolchain


=====================================
m4/ghc_toolchain.m4
=====================================
@@ -65,6 +65,9 @@ AC_DEFUN([FIND_GHC_TOOLCHAIN],
         python3 -c 'import sys; print(sys.argv)' "[$]@"
     ) <acargs || exit 1
 
+    cat acargs
+    cat default.target
+
     #rm -Rf acargs acghc-toolchain actmp-ghc-toolchain
 ])
 


=====================================
mk/project.mk.in
=====================================
@@ -94,7 +94,6 @@ TargetPlatform_CPP      = @TargetPlatform_CPP@
 TargetArch_CPP          = @TargetArch_CPP@
 TargetOS_CPP            = @TargetOS_CPP@
 TargetVendor_CPP        = @TargetVendor_CPP@
-LLVMTarget_CPP          = @LLVMTarget_CPP@
 
 BuildPlatform_CPP       = @BuildPlatform_CPP@
 BuildArch_CPP           = @BuildArch_CPP@


=====================================
utils/ghc-toolchain/Main.hs
=====================================
@@ -292,7 +292,8 @@ archHasNativeAdjustors = \case
 
 mkTarget :: Opts -> M Target
 mkTarget opts = do
-    cc0 <- findCc (optCc opts)
+    let tgtLlvmTarget = optTriple opts
+    cc0 <- findCc tgtLlvmTarget (optCc opts)
     cxx <- findCxx (optCxx opts)
     cpp <- findCpp (optCpp opts) cc0
     hsCpp <- findHsCpp (optHsCpp opts) cc0
@@ -325,7 +326,6 @@ mkTarget opts = do
     tgtSupportsSubsectionsViaSymbols <- checkSubsectionsViaSymbols cc
     tgtSupportsIdentDirective <- checkIdentDirective cc
     tgtSupportsGnuNonexecStack <- checkGnuNonexecStack archOs cc
-    let tgtLlvmTarget = optTriple opts
 
     -- code generator configuration
     tgtUnregisterised <- determineUnregisterised archOs (optUnregisterised opts)


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Target.hs
=====================================
@@ -41,7 +41,6 @@ data Target = Target
       -- GHC capabilities
     , tgtUnregisterised :: Bool
     , tgtTablesNextToCode :: Bool
-    -- , tgtHasRtsLinker :: Bool -- NO NEED! Rebase on MR removing it.
     -- , tgtHasThreadedRts :: Bool -- Do we need this for each target? Or just when bootstrapping?
     , tgtUseLibffiForAdjustors :: Bool -- We need to know whether or not to include libffi headers, and generate additional code for it
 
@@ -63,3 +62,8 @@ data Target = Target
     }
     deriving (Show, Read, Eq, Ord)
 
+-- | The word size as an integer representing the number of bytes
+wordSize2Bytes :: WordSize -> Int
+wordSize2Bytes WS4 = 4
+wordSize2Bytes WS8 = 8
+


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cc.hs
=====================================
@@ -28,10 +28,12 @@ newtype Cc = Cc { ccProgram :: Program
 _ccProgram :: Lens Cc Program
 _ccProgram = Lens ccProgram (\x o -> o{ccProgram=x})
 
-findCc :: ProgOpt -> M Cc
-findCc progOpt = checking "for C compiler" $ do
+findCc :: String -- ^ The llvm target to use if Cc supports --target
+       -> ProgOpt -> M Cc
+findCc llvmTarget progOpt = checking "for C compiler" $ do
     ccProgram <- findProgram "C compiler" progOpt ["cc", "clang", "gcc"]
-    cc <- ignoreUnusedArgs $ Cc {ccProgram}
+    cc' <- ignoreUnusedArgs $ Cc {ccProgram}
+    cc  <- supportsTarget llvmTarget cc'
     checkCcWorks cc
     checkC99Support cc
     checkCcSupportsExtraViaCFlags cc
@@ -56,6 +58,15 @@ ignoreUnusedArgs cc = checking "for -Qunused-arguments support" $ do
     let cc' = over (_ccProgram % _prgFlags) (++["-Qunused-arguments"]) cc
     (cc' <$ checkCcWorks cc') <|> return cc
 
+-- Does CC support the --target=<triple> option? If so, we should pass it
+-- whenever possible to avoid ambiguity and potential compile-time errors (e.g.
+-- see #20162).
+supportsTarget :: String -- ^ The llvm target to use if Cc supports --target
+               -> Cc -> M Cc
+supportsTarget llvmTarget cc = checking "whether Cc supports --target" $ do
+    let cc' = over (_ccProgram % _prgFlags) (++["--target="++llvmTarget]) cc
+    (cc' <$ checkCcWorks cc') <|> return cc
+
 checkC99Support :: Cc -> M ()
 checkC99Support cc = checking "for C99 support" $ withTempDir $ \dir -> do
     let test_o = dir </> "test.o"



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2adee66879754dcc9308f5c8b4ee751afc2af3bc...cdb184e4b5be33fa4d9aa9eb9bd485d852d87aa1

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2adee66879754dcc9308f5c8b4ee751afc2af3bc...cdb184e4b5be33fa4d9aa9eb9bd485d852d87aa1
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/20230530/4fbf96de/attachment-0001.html>


More information about the ghc-commits mailing list