[Git][ghc/ghc][wip/supersven/add-LLVMAS-target] WIP: Select LLVMAS target in configure tools

Sven Tennie (@supersven) gitlab at gitlab.haskell.org
Mon Aug 5 17:13:28 UTC 2024



Sven Tennie pushed to branch wip/supersven/add-LLVMAS-target at Glasgow Haskell Compiler / GHC


Commits:
81dd18b7 by Sven Tennie at 2024-08-05T19:13:02+02:00
WIP: Select LLVMAS target in configure tools

- - - - -


12 changed files:

- compiler/GHC/Settings/IO.hs
- configure.ac
- distrib/configure.ac.in
- hadrian/bindist/Makefile
- hadrian/cfg/default.host.target.in
- hadrian/cfg/default.target.in
- hadrian/src/Rules/Generate.hs
- + m4/fp_prog_llvm_as_args.m4
- m4/fp_settings.m4
- m4/prep_target_file.m4
- utils/ghc-toolchain/exe/Main.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Target.hs


Changes:

=====================================
compiler/GHC/Settings/IO.hs
=====================================
@@ -167,6 +167,7 @@ initSettings top_dir = do
   lc_prog <- getSetting "LLVM llc command"
   lo_prog <- getSetting "LLVM opt command"
   las_prog <- getSetting "LLVM llvm-as command"
+  las_args <- unescapeArgs <$> getToolSetting "LLVM llvm-as flags"
 
   let iserv_prog = libexec "ghc-iserv"
 
@@ -234,7 +235,7 @@ initSettings top_dir = do
       , toolSettings_opt_windres = []
       , toolSettings_opt_lo      = []
       , toolSettings_opt_lc      = []
-      , toolSettings_opt_las     = ["--target=" ++ llvmTarget]
+      , toolSettings_opt_las     = las_args
       , toolSettings_opt_i       = []
 
       , toolSettings_extraGccViaCFlags = extraGccViaCFlags


=====================================
configure.ac
=====================================
@@ -545,6 +545,9 @@ FIND_LLVM_PROG([LLVMAS], [clang], [$LlvmMinVersion], [$LlvmMaxVersion])
 LlvmAsCmd="$LLVMAS"
 AC_SUBST([LlvmAsCmd])
 
+dnl ** Which LLVM assembler arguments to use (e.g. `--target=...`)?
+FP_PROG_LLVM_AS_ARGS()
+
 dnl --------------------------------------------------------------
 dnl End of configure script option section
 dnl --------------------------------------------------------------


=====================================
distrib/configure.ac.in
=====================================
@@ -214,6 +214,9 @@ FIND_LLVM_PROG([LLVMAS], [clang], [$LlvmMinVersion], [$LlvmMaxVersion])
 LlvmAsCmd="$LLVMAS"
 AC_SUBST([LlvmAsCmd])
 
+dnl ** Which LLVM assembler arguments to use (e.g. `--target=...`)?
+FP_PROG_LLVM_AS_ARGS()
+
 dnl ** Check gcc version and flags we need to pass it **
 FP_GCC_VERSION
 FP_GCC_SUPPORTS_NO_PIE


=====================================
hadrian/bindist/Makefile
=====================================
@@ -131,6 +131,7 @@ lib/settings : config.mk
 	@echo ',("LLVM llc command", "$(SettingsLlcCommand)")' >> $@
 	@echo ',("LLVM opt command", "$(SettingsOptCommand)")' >> $@
 	@echo ',("LLVM llvm-as command", "$(SettingsLlvmAsCommand)")' >> $@
+	@echo ',("LLVM llvm-as flags", "$(SettingsLlvmAsArgs)")' >> $@
 	@echo ',("Use inplace MinGW toolchain", "$(SettingsUseDistroMINGW)")' >> $@
 	@echo
 	@echo ',("Use interpreter", "$(GhcWithInterpreter)")' >> $@


=====================================
hadrian/cfg/default.host.target.in
=====================================
@@ -9,6 +9,7 @@ Target
 , tgtEndianness = LittleEndian
 , tgtSymbolsHaveLeadingUnderscore = False
 , tgtLlvmTarget = "@HostPlatform@"
+, tgtLlvmAsArgs = @LlvmAsArgsHostList@
 , tgtUnregisterised = False
 , tgtTablesNextToCode = True
 , tgtUseLibffiForAdjustors = True


=====================================
hadrian/cfg/default.target.in
=====================================
@@ -9,6 +9,7 @@ Target
 , tgtEndianness = @TargetEndianness@
 , tgtSymbolsHaveLeadingUnderscore = @LeadingUnderscoreBool@
 , tgtLlvmTarget = "@LlvmTarget@"
+, tgtLlvmAsArgs = @LlvmAsArgsTargetList@
 , tgtUnregisterised = @UnregisterisedBool@
 , tgtTablesNextToCode = @TablesNextToCodeBool@
 , tgtUseLibffiForAdjustors = @UseLibffiForAdjustorsBool@


=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -491,6 +491,7 @@ generateSettings settingsFile = do
         , ("LLVM llc command", expr $ settingsFileSetting ToolchainSetting_LlcCommand)
         , ("LLVM opt command", expr $ settingsFileSetting ToolchainSetting_OptCommand)
         , ("LLVM llvm-as command", expr $ settingsFileSetting ToolchainSetting_LlvmAsCommand)
+        , ("LLVM llvm-as flags", queryTarget llvmAsFlags)
         , ("Use inplace MinGW toolchain", expr $ settingsFileSetting ToolchainSetting_DistroMinGW)
 
         , ("Use interpreter", expr $ yesNo <$> ghcWithInterpreter)
@@ -537,6 +538,7 @@ generateSettings settingsFile = do
     arSupportsDashL' = yesNo . arSupportsDashL . tgtAr
     ranlibPath  = maybe "" (prgPath . ranlibProgram) . tgtRanlib
     mergeObjsSupportsResponseFiles' = maybe "NO" (yesNo . mergeObjsSupportsResponseFiles) . tgtMergeObjs
+    llvmAsFlags = escapeArgs . tgtLlvmAsArgs
 
 isBigEndian, wordSize :: Toolchain.Target -> String
 isBigEndian = yesNo . (\case BigEndian -> True; LittleEndian -> False) . tgtEndianness


=====================================
m4/fp_prog_llvm_as_args.m4
=====================================
@@ -0,0 +1,38 @@
+# FP_PROG_LLVM_AS_ARGS
+# ---------------
+#
+# Sets the arguments of the LLVM assembler ($LLVMAS; usually clang.)
+AC_DEFUN([FP_PROG_LLVM_AS_ARGS],
+[
+# Cross-compiling: We need to define the target triple for the LLVM assembler.
+# Though, it does not hurt to define it for the non-cross case as well.
+LlvmAsArgsTarget="--target=$TargetPlatform"
+LlvmAsArgsHost="--target=$HostPlatform"
+
+# Create a minimal LLVM IR file for testing
+cat > test.ll <<EOF
+define i32 @main() {
+entry:
+  ret i32 0
+}
+EOF
+
+AC_MSG_CHECKING([whether \$LLVMAS supports host flags passed by GHC when compiling])
+if $LLVMAS $LlvmAsArgsHost test.ll > /dev/null 2>&1 ; then
+    AC_MSG_RESULT([yes])
+else
+    AC_MSG_RESULT([no])
+    AC_MSG_ERROR([\$LLVMAS ($LLVMAS) does not support host flags: $LlvmAsArgsHost])
+fi
+
+AC_MSG_CHECKING([whether \$LLVMAS supports target flags passed by GHC when compiling])
+if $LLVMAS $LlvmAsArgsTarget test.ll > /dev/null 2>&1 ; then
+    AC_MSG_RESULT([yes])
+else
+    AC_MSG_RESULT([no])
+    AC_MSG_ERROR([\$LLVMAS ($LLVMAS) does not support target flags: $LlvmAsArgsTarget])
+fi
+
+AC_SUBST(LlvmAsArgsHost)
+AC_SUBST(LlvmAsArgsTarget)
+])# FP_PROG_LLVM_AS_ARGS


=====================================
m4/fp_settings.m4
=====================================
@@ -128,6 +128,7 @@ AC_DEFUN([FP_SETTINGS],
     SettingsOptCommand="$OptCmd"
 
     SettingsLlvmAsCommand="$LlvmAsCmd"
+    SettingsLlvmAsArgs="$LlvmAsArgs"
 
     # Mac-only tools
     if test -z "$OtoolCmd"; then
@@ -168,4 +169,5 @@ AC_DEFUN([FP_SETTINGS],
     AC_SUBST(SettingsOptCommand)
     AC_SUBST(SettingsLlvmAsCommand)
     AC_SUBST(SettingsUseDistroMINGW)
+    AC_SUBST(SettingsLlvmAsArgs)
 ])


=====================================
m4/prep_target_file.m4
=====================================
@@ -154,6 +154,8 @@ AC_DEFUN([PREP_TARGET_FILE],[
     PREP_LIST([CONF_CPP_OPTS_STAGE2])
     PREP_LIST([CONF_CXX_OPTS_STAGE2])
     PREP_LIST([CONF_CC_OPTS_STAGE2])
+    PREP_LIST([LlvmAsArgsHost])
+    PREP_LIST([LlvmAsArgsTarget])
 
     dnl Host target
     PREP_BOOLEAN([ArSupportsAtFile_STAGE0])


=====================================
utils/ghc-toolchain/exe/Main.hs
=====================================
@@ -392,6 +392,7 @@ mkTarget opts = do
     normalised_triple <- normaliseTriple (optTriple opts)
     -- Use Llvm target if specified, otherwise use triple as llvm target
     let tgtLlvmTarget = fromMaybe normalised_triple (optLlvmTriple opts)
+        tgtLlvmAsArgs = ["--target=" <> tgtLlvmTarget]
 
     (archOs, tgtVendor) <- do
       cc0 <- findBasicCc (optCc opts)
@@ -478,6 +479,7 @@ mkTarget opts = do
                    , tgtSupportsIdentDirective
                    , tgtSupportsGnuNonexecStack
                    , tgtLlvmTarget
+                   , tgtLlvmAsArgs
                    }
     return t
 


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Target.hs
=====================================
@@ -48,6 +48,7 @@ data Target = Target
     , tgtEndianness :: Endianness
     , tgtSymbolsHaveLeadingUnderscore :: Bool
     , tgtLlvmTarget :: String
+    , tgtLlvmAsArgs :: [String]
 
       -- GHC capabilities
     , tgtUnregisterised :: Bool
@@ -107,6 +108,7 @@ instance Show Target where
     , ", tgtEndianness = " ++ show tgtEndianness
     , ", tgtSymbolsHaveLeadingUnderscore = " ++ show tgtSymbolsHaveLeadingUnderscore
     , ", tgtLlvmTarget = " ++ show tgtLlvmTarget
+    , ", tgtLlvmAsArgs = " ++ show tgtLlvmAsArgs
     , ", tgtUnregisterised = " ++ show tgtUnregisterised
     , ", tgtTablesNextToCode = " ++ show tgtTablesNextToCode
     , ", tgtUseLibffiForAdjustors = " ++ show tgtUseLibffiForAdjustors



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/81dd18b7bbba06669f49dcec7c0b5e38b4ab1d1e

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/81dd18b7bbba06669f49dcec7c0b5e38b4ab1d1e
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/20240805/814a24d2/attachment-0001.html>


More information about the ghc-commits mailing list