[Git][ghc/ghc][wip/toolchain-selection] 5 commits: Part of -Wl,--no-as-needed saga

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Mon Jun 26 10:53:29 UTC 2023



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


Commits:
bd8f0e0a by Rodrigo Mesquita at 2023-06-26T11:53:18+01:00
Part of -Wl,--no-as-needed saga

- - - - -
7df6961f by Rodrigo Mesquita at 2023-06-26T11:53:18+01:00
Support more targets and dont use llvmtarget

- - - - -
994ffb61 by Rodrigo Mesquita at 2023-06-26T11:53:18+01:00
allow duplos in place of triples

- - - - -
000d60a0 by Rodrigo Mesquita at 2023-06-26T11:53:18+01:00
Split GHC.Platform.ArchOS from ghc-boot into ghc-platform

- - - - -
db1e17ea by Rodrigo Mesquita at 2023-06-26T11:53:18+01:00
Use ghc-platform instead of ghc-boot

del async dep

- - - - -


19 changed files:

- hadrian/cabal.project
- hadrian/hadrian.cabal
- hadrian/src/Packages.hs
- hadrian/src/Rules/ToolArgs.hs
- hadrian/src/Settings/Default.hs
- hadrian/stack.yaml
- libraries/ghc-boot/ghc-boot.cabal.in
- + libraries/ghc-platform/CHANGELOG.md
- + libraries/ghc-platform/LICENSE
- + libraries/ghc-platform/ghc-platform.cabal
- libraries/ghc-boot/GHC/Platform/ArchOS.hs → libraries/ghc-platform/src/GHC/Platform/ArchOS.hs
- m4/fptools_set_c_ld_flags.m4
- m4/ghc_toolchain.m4
- utils/ghc-toolchain/Main.hs
- + utils/ghc-toolchain/acghc-toolchain
- utils/ghc-toolchain/ghc-toolchain.cabal
- utils/ghc-toolchain/src/GHC/Toolchain/ParseTriple.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Ar.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs


Changes:

=====================================
hadrian/cabal.project
=====================================
@@ -1,5 +1,6 @@
 packages: ./
           ../utils/ghc-toolchain/
+          ../libraries/ghc-platform/
 
 -- This essentially freezes the build plan for hadrian
 index-state: 2023-03-30T10:00:00Z


=====================================
hadrian/hadrian.cabal
=====================================
@@ -166,8 +166,8 @@ executable hadrian
                        , text                 >= 1.2     && < 3
                        , cryptohash-sha256    >= 0.11    && < 0.12
                        , base16-bytestring    >= 0.1.1 && < 1.1.0.0
+                       , ghc-platform
                        , ghc-toolchain
-                       , ghc-boot
     ghc-options:       -Wall
                        -Wincomplete-record-updates
                        -Wredundant-constraints


=====================================
hadrian/src/Packages.hs
=====================================
@@ -4,7 +4,7 @@ module Packages (
     array, base, binary, bytestring, cabal, cabalSyntax, checkPpr,
     checkExact, countDeps,
     compareSizes, compiler, containers, deepseq, deriveConstants, directory,
-    exceptions, filepath, genapply, genprimopcode, ghc, ghcBignum, ghcBoot, ghcBootTh,
+    exceptions, filepath, genapply, genprimopcode, ghc, ghcBignum, ghcBoot, ghcBootTh, ghcPlatform,
     ghcCompact, ghcConfig, ghcHeap, ghci, ghciWrapper, ghcPkg, ghcPrim, haddock, haskeline,
     hsc2hs, hp2ps, hpc, hpcBin, integerGmp, integerSimple, iserv, iservProxy,
     libffi, mtl, parsec, pretty, primitive, process, remoteIserv, rts,
@@ -36,7 +36,7 @@ ghcPackages :: [Package]
 ghcPackages =
     [ array, base, binary, bytestring, cabalSyntax, cabal, checkPpr, checkExact, countDeps
     , compareSizes, compiler, containers, deepseq, deriveConstants, directory
-    , exceptions, filepath, genapply, genprimopcode, ghc, ghcBignum, ghcBoot, ghcBootTh
+    , exceptions, filepath, genapply, genprimopcode, ghc, ghcBignum, ghcBoot, ghcBootTh, ghcPlatform
     , ghcCompact, ghcConfig, ghcHeap, ghci, ghciWrapper, ghcPkg, ghcPrim, haddock, haskeline, hsc2hs
     , hp2ps, hpc, hpcBin, integerGmp, integerSimple, iserv, libffi, mtl
     , parsec, pretty, process, rts, runGhc, stm, semaphoreCompat, templateHaskell
@@ -52,7 +52,7 @@ isGhcPackage = (`elem` ghcPackages)
 -- | Package definitions, see 'Package'.
 array, base, binary, bytestring, cabalSyntax, cabal, checkPpr, checkExact, countDeps,
   compareSizes, compiler, containers, deepseq, deriveConstants, directory,
-  exceptions, filepath, genapply, genprimopcode, ghc, ghcBignum, ghcBoot, ghcBootTh,
+  exceptions, filepath, genapply, genprimopcode, ghc, ghcBignum, ghcBoot, ghcBootTh, ghcPlatform,
   ghcCompact, ghcConfig, ghcHeap, ghci, ghciWrapper, ghcPkg, ghcPrim, haddock, haskeline, hsc2hs,
   hp2ps, hpc, hpcBin, integerGmp, integerSimple, iserv, iservProxy, remoteIserv, libffi, mtl,
   parsec, pretty, primitive, process, rts, runGhc, semaphoreCompat, stm, templateHaskell,
@@ -83,6 +83,7 @@ ghc                 = prg  "ghc-bin"         `setPath` "ghc"
 ghcBignum           = lib  "ghc-bignum"
 ghcBoot             = lib  "ghc-boot"
 ghcBootTh           = lib  "ghc-boot-th"
+ghcPlatform         = lib  "ghc-platform"
 ghcCompact          = lib  "ghc-compact"
 ghcConfig           = prg  "ghc-config"      `setPath` "testsuite/ghc-config"
 ghcHeap             = lib  "ghc-heap"


=====================================
hadrian/src/Rules/ToolArgs.hs
=====================================
@@ -158,6 +158,7 @@ toolTargets = [ binary
               -- , runGhc  -- # depends on ghc library
               , ghcBoot
               , ghcBootTh
+              , ghcPlatform
               , ghcHeap
               , ghci
               , ghcPkg  -- # executable


=====================================
hadrian/src/Settings/Default.hs
=====================================
@@ -85,6 +85,7 @@ stage0Packages = do
              , runGhc
              , ghcBoot
              , ghcBootTh
+             , ghcPlatform
              , ghcHeap
              , ghci
              , ghcPkg


=====================================
hadrian/stack.yaml
=====================================
@@ -3,6 +3,7 @@ resolver: lts-19.8
 packages:
 - '.'
 - '../utils/ghc-toolchain'
+- '../libraries/ghc-platform'
 
 nix:
    enable: false


=====================================
libraries/ghc-boot/ghc-boot.cabal.in
=====================================
@@ -51,7 +51,6 @@ Library
             GHC.Serialized
             GHC.ForeignSrcLang
             GHC.HandleEncoding
-            GHC.Platform.ArchOS
             GHC.Platform.Host
             GHC.Settings.Utils
             GHC.UniqueSubdir
@@ -65,6 +64,10 @@ Library
             , GHC.ForeignSrcLang.Type
             , GHC.Lexeme
 
+    -- reexport platform modules from ghc-platform
+    reexported-modules:
+              GHC.Platform.ArchOS
+
     -- but done by Hadrian
     autogen-modules:
             GHC.Version
@@ -77,6 +80,7 @@ Library
                    directory  >= 1.2 && < 1.4,
                    filepath   >= 1.3 && < 1.5,
                    deepseq    >= 1.4 && < 1.5,
+                   ghc-platform >= 0.1,
                    ghc-boot-th == @ProjectVersionMunged@
     if !os(windows)
         build-depends:


=====================================
libraries/ghc-platform/CHANGELOG.md
=====================================
@@ -0,0 +1,8 @@
+# Revision history for ghc-platform
+
+## 0.1.0.0 -- 2023-06-20
+
+* First version. Split off the `GHC.Platform.ArchOS` module from the
+    non-reinstallable `ghc-boot` package into this reinstallable standalone
+    package which abides by the PVP, in part motivated by the ongoing work on
+    `ghc-toolchain` towards runtime retargetability.


=====================================
libraries/ghc-platform/LICENSE
=====================================
@@ -0,0 +1,30 @@
+Copyright (c) 2023, Rodrigo Mesquita
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+
+    * Neither the name of Rodrigo Mesquita nor the names of other
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


=====================================
libraries/ghc-platform/ghc-platform.cabal
=====================================
@@ -0,0 +1,20 @@
+cabal-version:      3.0
+name:               ghc-platform
+version:            0.1.0.0
+synopsis:           Platform information used by GHC and friends
+license:            BSD-3-Clause
+license-file:       LICENSE
+author:             Rodrigo Mesquita
+maintainer:         ghc-devs at haskell.org
+build-type:         Simple
+extra-doc-files:    CHANGELOG.md
+
+common warnings
+    ghc-options: -Wall
+
+library
+    import:           warnings
+    exposed-modules:  GHC.Platform.ArchOS
+    build-depends:    base >=4.15.0.0
+    hs-source-dirs:   src
+    default-language: Haskell2010


=====================================
libraries/ghc-boot/GHC/Platform/ArchOS.hs → libraries/ghc-platform/src/GHC/Platform/ArchOS.hs
=====================================


=====================================
m4/fptools_set_c_ld_flags.m4
=====================================
@@ -17,8 +17,9 @@ AC_DEFUN([FPTOOLS_SET_C_LD_FLAGS],
         ;;
     esac
 
+    -- ROMES:TODO: ELF, mention note
     case $$1 in
-    *-linux)
+    *-linux|*-freebsd*)
         FP_LINK_SUPPORTS_NO_AS_NEEDED([$3])
         ;;
     esac


=====================================
m4/ghc_toolchain.m4
=====================================
@@ -22,16 +22,15 @@ AC_DEFUN([ENABLE_GHC_TOOLCHAIN_ARG],
 AC_DEFUN([FIND_GHC_TOOLCHAIN],
 [
     "$GHC" -v0 \
-        -ilibraries/ghc-boot -iutils/ghc-toolchain/src \
+        -ilibraries/ghc-platform/src -iutils/ghc-toolchain/src \
         -XNoImplicitPrelude \
         -odir actmp-ghc-toolchain -hidir actmp-ghc-toolchain \
         utils/ghc-toolchain/Main.hs -o acghc-toolchain
 
     rm -f acargs
-    dnl TODO: LLVMTarget vs Target, which should go where?
-    dnl echo "--triple=$target" >> acargs
-    dnl For now, LlvmTarget matches the configure output.
-    echo "--triple=$LlvmTarget" >> acargs
+
+    echo "--triple=$target" >> acargs
+    echo "--llvm-triple=$LlvmTarget" >> acargs
     # echo "--cc=$CC" >> acargs
     # ADD_GHC_TOOLCHAIN_ARG([cc-opt], [$CONF_CC_OPTS_STAGE1])
 


=====================================
utils/ghc-toolchain/Main.hs
=====================================
@@ -5,7 +5,7 @@ module Main where
 
 import Control.Monad
 import Data.Char (toUpper)
-import Data.Maybe (isNothing)
+import Data.Maybe (isNothing,fromMaybe)
 import System.Exit
 import System.Console.GetOpt
 import System.Environment
@@ -33,6 +33,7 @@ import GHC.Toolchain.Tools.Readelf
 data Opts = Opts
     { optTriple    :: String
     , optTargetPrefix :: Maybe String
+    , optLlvmTriple :: Maybe String
     , optCc        :: ProgOpt
     , optCxx       :: ProgOpt
     , optCpp       :: ProgOpt
@@ -57,6 +58,7 @@ emptyOpts :: Opts
 emptyOpts = Opts
     { optTriple    = ""
     , optTargetPrefix = Nothing
+    , optLlvmTriple = Nothing
     , optCc        = po0
     , optCxx       = po0
     , optCpp       = po0
@@ -98,6 +100,9 @@ _optWindres = Lens optWindres (\x o -> o {optWindres=x})
 _optTriple :: Lens Opts String
 _optTriple = Lens optTriple (\x o -> o {optTriple=x})
 
+_optLlvmTriple :: Lens Opts (Maybe String)
+_optLlvmTriple = Lens optLlvmTriple (\x o -> o {optLlvmTriple=x})
+
 _optTargetPrefix :: Lens Opts (Maybe String)
 _optTargetPrefix = Lens optTargetPrefix (\x o -> o {optTargetPrefix=x})
 
@@ -123,6 +128,7 @@ options :: [OptDescr (Opts -> Opts)]
 options =
     [ tripleOpt
     , targetPrefixOpt
+    , llvmTripleOpt
     , verbosityOpt
     , keepTempOpt
     ] ++
@@ -174,6 +180,7 @@ options =
         ]
 
     tripleOpt = Option ['t'] ["triple"] (ReqArg (set _optTriple) "TRIPLE") "Target triple"
+    llvmTripleOpt = Option [] ["llvm-triple"] (ReqArg (set _optLlvmTriple . Just) "LLVMTRIPLE") "LLVM Target triple"
 
     targetPrefixOpt = Option ['T'] ["target-prefix"] (ReqArg (set _optTargetPrefix . Just) "PREFIX")
         "A target prefix which will be added to all tool names when searching for toolchain components"
@@ -297,7 +304,8 @@ archHasNativeAdjustors = \case
 
 mkTarget :: Opts -> M Target
 mkTarget opts = do
-    let tgtLlvmTarget = optTriple opts
+    -- Use Llvm target if specified, otherwise use triple as llvm target
+    let tgtLlvmTarget = fromMaybe (optTriple opts) (optLlvmTriple opts)
     cc0 <- findCc tgtLlvmTarget (optCc opts)
     cxx <- findCxx tgtLlvmTarget (optCxx opts)
     cpp <- findCpp (optCpp opts) cc0


=====================================
utils/ghc-toolchain/acghc-toolchain
=====================================
Binary files /dev/null and b/utils/ghc-toolchain/acghc-toolchain differ


=====================================
utils/ghc-toolchain/ghc-toolchain.cabal
=====================================
@@ -36,8 +36,7 @@ library
                       filepath,
                       process,
                       transformers,
-                      async,
-                      ghc-boot
+                      ghc-platform
     hs-source-dirs:   src
     default-language: Haskell2010
 
@@ -50,6 +49,6 @@ executable ghc-toolchain
                       filepath,
                       process,
                       transformers,
-                      ghc-boot,
+                      ghc-platform,
                       ghc-toolchain
     default-language: Haskell2010


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/ParseTriple.hs
=====================================
@@ -9,17 +9,21 @@ import GHC.Toolchain.CheckArm
 import GHC.Toolchain.Tools.Cc
 
 -- | Parse a triple `arch-vendor-os` into an 'ArchOS' and a vendor name 'String'
-parseTriple :: Cc -> String -> M (ArchOS, String)
+parseTriple :: Cc -> String -> M (ArchOS, Maybe String)
 parseTriple cc triple
+  | [archName, osName] <- parts
+  = do arch <- parseArch cc archName
+       os   <- parseOs osName
+       return (ArchOS arch os, Nothing)
   | [archName, vendorName, osName] <- parts
   = do arch <- parseArch cc archName
-       os <- parseOs vendorName osName
-       return $ (ArchOS arch os, vendorName)
+       os   <- parseOs osName
+       return (ArchOS arch os, Just vendorName)
 
   | [archName, vendorName, osName, _abi] <- parts
   = do arch <- parseArch cc archName
-       os <- parseOs vendorName osName
-       return $ (ArchOS arch os, vendorName)
+       os   <- parseOs osName
+       return (ArchOS arch os, Just vendorName)
 
   | otherwise
   = throwE $ "malformed triple " ++ triple
@@ -38,7 +42,7 @@ parseArch cc arch =
       "s390x" -> pure ArchS390X
       "arm" -> findArmIsa cc
       _ | "armv" `isPrefixOf` arch -> findArmIsa cc
-      "arm64" -> pure ArchAArch64 -- TODO Should we support this alias or does this cause confusion?
+      "arm64" -> pure ArchAArch64
       "aarch64" -> pure ArchAArch64
       "alpha" -> pure ArchAlpha
       "mips" -> pure ArchMipseb
@@ -46,10 +50,11 @@ parseArch cc arch =
       "mipsel" -> pure ArchMipsel
       "riscv64" -> pure ArchRISCV64
       "hppa" -> pure ArchUnknown
+      "wasm32" -> pure ArchWasm32
       _ -> throwE $ "Unknown architecture " ++ arch
 
-parseOs :: String -> String -> M OS
-parseOs vendor os =
+parseOs :: String -> M OS
+parseOs os =
     case os of
       "linux" -> pure OSLinux
       "linux-android" -> pure OSLinux
@@ -68,7 +73,8 @@ parseOs vendor os =
       "nto-qnc" -> pure OSQNXNTO
       "aix" -> pure OSAIX
       "gnu" -> pure OSHurd
-      _ -> throwE $ "Unknown vendor/operating system " ++ vendor ++ "-" ++ os
+      "wasi" -> pure OSWasi
+      _ -> throwE $ "Unknown operating system " ++ os
 
 splitOn :: Char -> String -> [String]
 splitOn sep = go


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Ar.hs
=====================================
@@ -31,7 +31,7 @@ instance Show Ar where
     , "}"
     ]
 
-findAr :: String -- ^ Vendor name from the target triple
+findAr :: Maybe String -- ^ Vendor name from the target triple, if specified
        -> ProgOpt -> M Ar
 findAr vendor progOpt = checking "for 'ar'" $ do
     bareAr <- findProgram "ar archiver" progOpt ["ar"]
@@ -48,7 +48,7 @@ findAr vendor progOpt = checking "for 'ar'" $ do
           -- TODO: It'd be better not to handle Apple specifically here?
           -- It's quite tedious to check for Apple's crazy timestamps in
           -- .a files, so we hardcode it.
-          | vendor == "apple" = True
+          | vendor == Just "apple" = True
           | mode:_ <- prgFlags mkArchive
           , 's' `elem` mode = False
           | otherwise = True


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs
=====================================
@@ -126,6 +126,11 @@ checkSupportsNoPie ccLink = checking "whether the cc linker supports -no-pie" $
     (code, out, _err) <- readProgram ccLink ["-no-pie", "-Werror", "-x", "c", test_c, "-o", test]
     return (isSuccess code && not ("unrecognized" `isInfixOf` out))
 
+-- ROMES:TODO: This check is wrong here and in configure because with ld.gold parses "-n" "o_compact_unwind"
+-- TODO:
+-- * Check if compiling for darwin
+-- * Then do the check
+-- * Otherwise say its just not supported
 checkSupportsCompactUnwind :: Cc -> Program -> M Bool
 checkSupportsCompactUnwind cc ccLink = checking "whether the cc linker understands -no_compact_unwind" $
   withTempDir $ \dir -> do
@@ -155,6 +160,7 @@ checkSupportsFilelist cc ccLink = checking "whether the cc linker understands -f
 
     return (isSuccess exitCode)
 
+-- ROMES:TODO: Move to MergeTools, don't use neither of these, check that merging works with the @args.txt
 checkSupportsResponseFiles :: Cc -> Program -> M Bool
 checkSupportsResponseFiles cc ccLink = checking "whether the cc linker supports response files" $
   withTempDir $ \dir -> do



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a9a1b8bce5e980e6e953140ee1cc8c112c44d703...db1e17eaf8b7f0b61d5dfa65012a05ea4e0ccc63

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a9a1b8bce5e980e6e953140ee1cc8c112c44d703...db1e17eaf8b7f0b61d5dfa65012a05ea4e0ccc63
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/20230626/eac02f55/attachment-0001.html>


More information about the ghc-commits mailing list