[Git][ghc/ghc][wip/toolchain-selection] 4 commits: ROMES: WIP 5

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Mon May 22 17:55:43 UTC 2023



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


Commits:
c1c320fc by Rodrigo Mesquita at 2023-05-22T17:53:42+01:00
ROMES: WIP 5

- - - - -
a8be9fae by Rodrigo Mesquita at 2023-05-22T17:53:47+01:00
Revert "Rip more of configure that is no longer being used"

I realized we still need this function in rts/configure.ac

This reverts commit 01f5d4b480f4ab1514ac0a4fc957db199d1a0279.

- - - - -
3cd81437 by Rodrigo Mesquita at 2023-05-22T17:53:47+01:00
Revert get_arm_isa deletion from 74f03f243d08aa910d39cdd9dadb976e9386283a

As in the previous commit, we still need this info from the rts
configure script.

I suppose it could be useful for the rts to also read somehow the
toolchain information...

- - - - -
97a64016 by Rodrigo Mesquita at 2023-05-22T18:47:25+01:00
helper AC function for enable/disable

- - - - -


12 changed files:

- compiler/GHC/Driver/DynFlags.hs
- compiler/GHC/Driver/Main.hs
- compiler/GHC/Driver/Pipeline/Execute.hs
- compiler/GHC/Linker/ExtraObj.hs
- compiler/GHC/SysTools.hs
- hadrian/src/Oracles/Setting.hs
- hadrian/src/Rules/Generate.hs
- hadrian/src/Settings/Builders/Ghc.hs
- hadrian/src/Settings/Builders/Hsc2Hs.hs
- m4/fptools_set_haskell_platform_vars.m4
- + m4/get_arm_isa.m4
- m4/ghc_toolchain.m4


Changes:

=====================================
compiler/GHC/Driver/DynFlags.hs
=====================================
@@ -113,7 +113,6 @@ import Control.Monad.Trans.Class (lift)
 import Control.Monad.Trans.Except (ExceptT)
 import Control.Monad.Trans.Reader (ReaderT)
 import Control.Monad.Trans.Writer (WriterT)
-import Data.IORef
 import System.IO
 import System.IO.Error (catchIOError)
 import System.Environment (lookupEnv)


=====================================
compiler/GHC/Driver/Main.hs
=====================================
@@ -109,9 +109,6 @@ module GHC.Driver.Main
 
 import GHC.Prelude
 
-import GHC.Platform
-import GHC.Platform.Ways
-
 import GHC.Driver.Plugins
 import GHC.Driver.Session
 import GHC.Driver.Backend


=====================================
compiler/GHC/Driver/Pipeline/Execute.hs
=====================================
@@ -288,7 +288,6 @@ runAsPhase :: Bool -> PipeEnv -> HscEnv -> Maybe ModLocation -> FilePath -> IO F
 runAsPhase with_cpp pipe_env hsc_env location input_fn = do
         let dflags     = hsc_dflags   hsc_env
         let logger     = hsc_logger   hsc_env
-        let unit_env   = hsc_unit_env hsc_env
 
         let cmdline_include_paths = includePaths dflags
         let pic_c_flags = picCCOpts dflags


=====================================
compiler/GHC/Linker/ExtraObj.hs
=====================================
@@ -42,7 +42,6 @@ import GHC.SysTools.Tasks
 import GHC.SysTools.Info
 import GHC.Linker.Unit
 
-import Control.Monad.IO.Class
 import Control.Monad
 import Data.Maybe
 


=====================================
compiler/GHC/SysTools.hs
=====================================
@@ -35,7 +35,6 @@ import GHC.Prelude
 import GHC.Utils.Panic
 import GHC.Driver.Session
 
-import GHC.Linker.ExtraObj
 import GHC.SysTools.Info
 import GHC.SysTools.Tasks
 import GHC.SysTools.BaseDir


=====================================
hadrian/src/Oracles/Setting.hs
=====================================
@@ -123,8 +123,8 @@ data ToolchainSetting
 -- be part of settings, so they should be moved out
 setting :: Setting -> Action String
 setting key = case key of
-    BuildArch          -> systemConf "build-arch"
-    BuildOs            -> systemConf "build-os"
+    BuildArch          -> hostConf archStr -- ROMES:TODO: This is only correct while we assume BUILD=HOST=TARGET
+    BuildOs            -> hostConf osStr   -- This too.
     BuildPlatform      -> systemConf "build-platform"
     BuildVendor        -> systemConf "build-vendor"
     CursesIncludeDir   -> systemConf "curses-include-dir"


=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -431,7 +431,7 @@ generateSettings = do
         , ("ld command", expr $ settingsFileSetting ToolchainSetting_LdCommand)
         , ("ld flags", expr $ settingsFileSetting ToolchainSetting_LdFlags)
         , ("ld supports compact unwind", expr $ queryTargetTargetConfig linkSupportsCompactUnwind)
-        , ("ld supports filelist", expr $ queryTargetTargetConfig ldSupportsFilelist)
+        , ("ld supports filelist", expr $ queryTargetTargetConfig linkSupportsFilelist)
         , ("ld supports response files", expr $ queryTargetTargetConfig linkSupportsResponseFiles)
         , ("ld is GNU ld", expr $ queryTargetTargetConfig linkIsGnu)
         , ("Merge objects command", expr $ settingsFileSetting ToolchainSetting_MergeObjectsCommand)


=====================================
hadrian/src/Settings/Builders/Ghc.hs
=====================================
@@ -14,7 +14,7 @@ import Rules.Libffi (libffiName)
 import qualified Data.Set as Set
 import System.Directory
 import Data.Version.Extra
-import GHC.Toolchain (ccProgram, tgtCCompiler, cppProgram, tgtCPreprocessor)
+import GHC.Toolchain (ccProgram, tgtCCompiler)
 import GHC.Toolchain.Program
 
 ghcBuilderArgs :: Args
@@ -294,6 +294,3 @@ includeGhcArgs = do
 -- Utilities
 getStagedCCFlags :: Args
 getStagedCCFlags = prgFlags . ccProgram . tgtCCompiler <$> getStagedTargetConfig
-
-getStagedCPPFlags :: Args
-getStagedCPPFlags = prgFlags . cppProgram . tgtCPreprocessor <$> getStagedTargetConfig


=====================================
hadrian/src/Settings/Builders/Hsc2Hs.hs
=====================================
@@ -5,7 +5,7 @@ import Hadrian.Haskell.Cabal.Type
 import Builder
 import Packages
 import Settings.Builders.Common
-import GHC.Toolchain (tgtCCompiler, ccProgram, tgtCPreprocessor, cppProgram, tgtCCompilerLink, ccLinkProgram)
+import GHC.Toolchain (tgtCCompiler, ccProgram, tgtCCompilerLink, ccLinkProgram)
 import GHC.Toolchain.Program
 
 hsc2hsBuilderArgs :: Args


=====================================
m4/fptools_set_haskell_platform_vars.m4
=====================================
@@ -1,3 +1,134 @@
+# FPTOOLS_SET_HASKELL_PLATFORM_VARS_SHELL_FUNCTIONS
+# ----------------------------------
+# Drop in shell functions used by FPTOOLS_SET_HASKELL_PLATFORM_VARS
+AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS_SHELL_FUNCTIONS],
+[
+    checkArch() {
+        case [$]1 in
+        i386)
+            test -z "[$]2" || eval "[$]2=ArchX86"
+            ;;
+        x86_64|amd64)
+            test -z "[$]2" || eval "[$]2=ArchX86_64"
+            ;;
+        powerpc)
+            test -z "[$]2" || eval "[$]2=ArchPPC"
+            ;;
+        powerpc64)
+            test -z "[$]2" || eval "[$]2=\"ArchPPC_64 ELF_V1\""
+            ;;
+        powerpc64le)
+            test -z "[$]2" || eval "[$]2=\"ArchPPC_64 ELF_V2\""
+            ;;
+        s390x)
+            test -z "[$]2" || eval "[$]2=ArchS390X"
+            ;;
+        arm)
+            GET_ARM_ISA()
+            test -z "[$]2" || eval "[$]2=\"ArchARM \$ARM_ISA \$ARM_ISA_EXT \$ARM_ABI\""
+            ;;
+        aarch64)
+            test -z "[$]2" || eval "[$]2=ArchAArch64"
+            ;;
+        alpha)
+            test -z "[$]2" || eval "[$]2=ArchAlpha"
+            ;;
+        mips|mipseb)
+            test -z "[$]2" || eval "[$]2=ArchMipseb"
+            ;;
+        mipsel)
+            test -z "[$]2" || eval "[$]2=ArchMipsel"
+            ;;
+        riscv64)
+            test -z "[$]2" || eval "[$]2=ArchRISCV64"
+            ;;
+        wasm32)
+            test -z "[$]2" || eval "[$]2=ArchWasm32"
+            ;;
+        loongarch64)
+            test -z "[$]2" || eval "[$]2=ArchLoongArch64"
+            ;;
+        hppa|hppa1_1|ia64|m68k|nios2|riscv32|loongarch32|rs6000|s390|sh4|vax)
+            test -z "[$]2" || eval "[$]2=ArchUnknown"
+            ;;
+        javascript)
+            test -z "[$]2" || eval "[$]2=ArchJavaScript"
+            ;;
+        *)
+            echo "Unknown arch [$]1"
+            exit 1
+            ;;
+        esac
+    }
+
+    checkVendor() {
+        case [$]1 in
+        dec|none|unknown|hp|apple|next|sun|sgi|ibm|montavista|portbld|alpine)
+            ;;
+        *)
+            AC_MSG_WARN([Unknown vendor [$]1])
+            ;;
+        esac
+    }
+
+    checkOS() {
+        case [$]1 in
+        linux|linux-android)
+            test -z "[$]2" || eval "[$]2=OSLinux"
+            ;;
+        darwin|ios|watchos|tvos)
+            test -z "[$]2" || eval "[$]2=OSDarwin"
+            ;;
+        solaris2)
+            test -z "[$]2" || eval "[$]2=OSSolaris2"
+            ;;
+        mingw32|windows)
+            test -z "[$]2" || eval "[$]2=OSMinGW32"
+            ;;
+        freebsd)
+            test -z "[$]2" || eval "[$]2=OSFreeBSD"
+            ;;
+        dragonfly)
+            test -z "[$]2" || eval "[$]2=OSDragonFly"
+            ;;
+        kfreebsdgnu)
+            test -z "[$]2" || eval "[$]2=OSKFreeBSD"
+            ;;
+        openbsd)
+            test -z "[$]2" || eval "[$]2=OSOpenBSD"
+            ;;
+        netbsd)
+            test -z "[$]2" || eval "[$]2=OSNetBSD"
+            ;;
+        haiku)
+            test -z "[$]2" || eval "[$]2=OSHaiku"
+            ;;
+        nto-qnx)
+            test -z "[$]2" || eval "[$]2=OSQNXNTO"
+            ;;
+        wasi)
+            test -z "[$]2" || eval "[$]2=OSWasi"
+            ;;
+        dragonfly|hpux|linuxaout|freebsd2|nextstep2|nextstep3|sunos4|ultrix)
+            test -z "[$]2" || eval "[$]2=OSUnknown"
+            ;;
+        aix)
+            test -z "[$]2" || eval "[$]2=OSAIX"
+            ;;
+        gnu)
+            test -z "[$]2" || eval "[$]2=OSHurd"
+            ;;
+        ghcjs|js)
+            test -z "[$]2" || eval "[$]2=OSGhcjs"
+            ;;
+        *)
+            echo "Unknown OS '[$]1'"
+            exit 1
+            ;;
+        esac
+    }
+])
+
 # Note [autoconf assembler checks and -flto]
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # Autoconf's AC_COMPILE_IFELSE macro is fragile in the case of checks
@@ -43,3 +174,13 @@ AC_DEFUN([GHC_SUBSECTIONS_VIA_SYMBOLS],
 # We might have to generate a bunch of -D CPP flags to satisfy these dependencies (future work).
 
 
+# FPTOOLS_SET_HASKELL_PLATFORM_VARS
+# ----------------------------------
+# Set the Haskell platform variables
+AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS],
+[
+    AC_REQUIRE([FPTOOLS_SET_HASKELL_PLATFORM_VARS_SHELL_FUNCTIONS])
+    checkArch "[$]$1Arch" "Haskell$1Arch"
+    checkVendor "[$]$1Vendor"
+    checkOS "[$]$1OS" "Haskell$1Os"
+])


=====================================
m4/get_arm_isa.m4
=====================================
@@ -0,0 +1,117 @@
+# GET_ARM_ISA
+# ----------------------------------
+# Get info about the ISA on the ARM arch
+AC_DEFUN([GET_ARM_ISA],
+[
+    AC_COMPILE_IFELSE([
+        AC_LANG_PROGRAM(
+            [],
+            [#if defined(__ARM_ARCH_2__)  || \
+                 defined(__ARM_ARCH_3__)  || \
+                 defined(__ARM_ARCH_3M__) || \
+                 defined(__ARM_ARCH_4__)  || \
+                 defined(__ARM_ARCH_4T__) || \
+                 defined(__ARM_ARCH_5__)  || \
+                 defined(__ARM_ARCH_5T__) || \
+                 defined(__ARM_ARCH_5E__) || \
+                 defined(__ARM_ARCH_5TE__)
+                 return 0;
+             #else
+                 not pre arm v6
+             #endif]
+        )],
+        [AC_DEFINE(arm_HOST_ARCH_PRE_ARMv6, 1, [ARM pre v6])
+         AC_DEFINE(arm_HOST_ARCH_PRE_ARMv7, 1, [ARM pre v7])
+         changequote(, )dnl
+         ARM_ISA=ARMv5
+         ARM_ISA_EXT="[]"
+         changequote([, ])dnl
+        ],
+        [
+            AC_COMPILE_IFELSE([
+                AC_LANG_PROGRAM(
+                    [],
+                    [#if defined(__ARM_ARCH_6__)   || \
+                         defined(__ARM_ARCH_6J__)  || \
+                         defined(__ARM_ARCH_6T2__) || \
+                         defined(__ARM_ARCH_6Z__)  || \
+                         defined(__ARM_ARCH_6ZK__) || \
+                         defined(__ARM_ARCH_6K__)  || \
+                         defined(__ARM_ARCH_6KZ__) || \
+                         defined(__ARM_ARCH_6M__)
+                         return 0;
+                     #else
+                         not pre arm v7
+                     #endif]
+                )],
+                [AC_DEFINE(arm_HOST_ARCH_PRE_ARMv7, 1, [ARM pre v7])
+                 if grep -q Raspbian /etc/issue && uname -m | grep -q armv7; then
+                   # Raspbian unfortunately makes some extremely questionable
+                   # packaging decisions, configuring gcc to compile for ARMv6
+                   # despite the fact that the RPi4 is ARMv8. As ARMv8 doesn't
+                   # support all instructions supported by ARMv6 this can
+                   # break. Work around this by checking uname to verify
+                   # that we aren't running on armv7.
+                   # See #17856.
+                   AC_MSG_NOTICE([Found compiler which claims to target ARMv6 running on ARMv7, assuming this is ARMv7 on Raspbian (see T17856)])
+                   ARM_ISA=ARMv7
+                   changequote(, )dnl
+                   ARM_ISA_EXT="[VFPv2]"
+                   changequote([, ])dnl
+                 else
+                   ARM_ISA=ARMv6
+                   AC_COMPILE_IFELSE([
+                          AC_LANG_PROGRAM(
+                                  [],
+                                  [#if defined(__VFP_FP__)
+                                       return 0;
+                                  #else
+                                       no vfp
+                                  #endif]
+                          )],
+                          [changequote(, )dnl
+                           ARM_ISA_EXT="[VFPv2]"
+                           changequote([, ])dnl
+                          ],
+                          [changequote(, )dnl
+                           ARM_ISA_EXT="[]"
+                           changequote([, ])dnl
+                          ]
+                  )
+                fi],
+                [changequote(, )dnl
+                 ARM_ISA=ARMv7
+                 ARM_ISA_EXT="[VFPv3,NEON]"
+                 changequote([, ])dnl
+                ])
+        ])
+
+        AC_COMPILE_IFELSE(
+               [AC_LANG_PROGRAM(
+                       [],
+                       [#if defined(__SOFTFP__)
+                            return 0;
+                       #else
+                            not softfp
+                       #endif]
+               )],
+               [changequote(, )dnl
+                ARM_ABI="SOFT"
+                changequote([, ])dnl
+               ],
+               [AC_COMPILE_IFELSE(
+                    [AC_LANG_PROGRAM(
+                       [],
+                       [#if defined(__ARM_PCS_VFP)
+                            return 0;
+                       #else
+                            no hard float ABI
+                       #endif]
+                    )],
+                    [ARM_ABI="HARD"],
+                    [ARM_ABI="SOFTFP"]
+               )]
+        )
+
+        AC_SUBST(ARM_ISA)
+])


=====================================
m4/ghc_toolchain.m4
=====================================
@@ -8,6 +8,17 @@ AC_DEFUN([ADD_GHC_TOOLCHAIN_ARG],
     done
 ])
 
+dnl $1 argument name
+dnl $2 variable
+AC_DEFUN([ENABLE_GHC_TOOLCHAIN_ARG],
+[
+    if test "$2" = "YES"; then
+        echo "--enable-$1" >> acargs
+    elif test "$2" = "NO"; then
+        echo "--disable-$1" >> acargs
+    fi
+])
+
 AC_DEFUN([FIND_GHC_TOOLCHAIN],
 [
     "$GHC" -v0 \
@@ -42,17 +53,8 @@ AC_DEFUN([FIND_GHC_TOOLCHAIN],
     echo "--readelf=$READELF" >> acargs
     ADD_GHC_TOOLCHAIN_ARG([readelf-opt], [$READELFFLAGS])
 
-    if test "$Unregisterised" = "YES"; then
-        echo "--enable-unregisterised" >> acargs
-    else
-        echo "--disable-unregisterised" >> acargs
-    fi
-
-    if test "$TablesNextToCode" = "YES"; then
-        echo "--enable-tables-next-to-code" >> acargs
-    else
-        echo "--disable-tables-next-to-code" >> acargs
-    fi
+    ENABLE_GHC_TOOLCHAIN_ARG([unregisterised], [$Unregisterised])
+    ENABLE_GHC_TOOLCHAIN_ARG([tables-next-to-code], [$TablesNextToCode])
 
     (
         set --



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/dff45613e1b07060c55efca280c96533e353636b...97a64016882224b52197e5796ca7be5e959eddca

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/dff45613e1b07060c55efca280c96533e353636b...97a64016882224b52197e5796ca7be5e959eddca
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/20230522/6faa0e42/attachment-0001.html>


More information about the ghc-commits mailing list