[Git][haskell-team/DHG_packages][master] Update patch to pass -mcmodel=medium to LLVM backend on loong64

John Paul Adrian Glaubitz (@glaubitz) gitlab at salsa.debian.org
Tue Feb 10 09:35:07 GMT 2026



John Paul Adrian Glaubitz pushed to branch master at Debian Haskell Group / DHG_packages


Commits:
ef5b48ea by John Paul Adrian Glaubitz at 2026-02-10T10:34:43+01:00
Update patch to pass -mcmodel=medium to LLVM backend on loong64

- - - - -


2 changed files:

- p/ghc/debian/changelog
- p/ghc/debian/patches/0004-llvmGen-Pass-mcmodel-medium-option-to-LLVM-backend-on-LoongArch.patch


Changes:

=====================================
p/ghc/debian/changelog
=====================================
@@ -6,6 +6,7 @@ ghc (9.10.3-4) UNRELEASED; urgency=medium
   * Re-enable patch to pass -mcmodel=medium to LLVM backend on loong64
   * Re-enable patch to pass -mcmodel=medium to CC on loong64
   * Stop passing -optc-mcmodel=medium in EXTRA_HADRIAN_FLAGS on loong64
+  * Update patch to pass -mcmodel=medium to LLVM backend on loong64
 
  -- John Paul Adrian Glaubitz <glaubitz at physik.fu-berlin.de>  Sun, 25 Jan 2026 17:56:20 +0100
 


=====================================
p/ghc/debian/patches/0004-llvmGen-Pass-mcmodel-medium-option-to-LLVM-backend-on-LoongArch.patch
=====================================
@@ -1,57 +1,45 @@
 From e70d41406b5d5638b42c4d8222cd03e76bbfeb86 Mon Sep 17 00:00:00 2001
-From: Xin Wang <wangxin03 at loongson.cn>
-Date: Mon, 13 Dec 2024 10:45:20 +0800
-Subject: [PATCH] llvmGen: Pass mcmodel medium option to LLVM backend on LoongArch
+From: Wang Xin <wangxin03 at loongson.cn>
+Date: Tue, 19 Nov 2024 11:10:11 +0000
+Subject: [PATCH] Add -mcmodel=medium moduleflag to generated LLVM IR on
+ LoongArch platform
 
+With the Medium code model, the jump range of the generated jump
+instruction is larger than that of the Small code model. It's a
+temporary fix of the problem descriped in https://gitlab.haskell
+.org/ghc/ghc/-/issues/25495. This commit requires that the LLVM
+used contains the code of commit 9dd1d451d9719aa91b3bdd59c0c6679
+83e1baf05, i.e., version 8.0 and later. Actually we should not
+rely on LLVM, so the only way to solve this problem is to implement
+the LoongArch backend.
+
+Add new type for codemodel
 ---
- compiler/GHC/CmmToLlvm.hs     | 36 ++++++++++++++++++++++++++++++++++-
- compiler/GHC/Llvm/MetaData.hs |  1 -
- configure.ac                  |  2 +-
- 3 files changed, 36 insertions(+), 3 deletions(-)
+ compiler/GHC/CmmToLlvm.hs | 16 +++++++++++++++-
+ 1 file changed, 15 insertions(+), 1 deletion(-)
 
+diff --git a/compiler/GHC/CmmToLlvm.hs b/compiler/GHC/CmmToLlvm.hs
+index 7ab55d975a..372a41acdd 100644
 --- a/compiler/GHC/CmmToLlvm.hs
 +++ b/compiler/GHC/CmmToLlvm.hs
-@@ -196,7 +196,7 @@ cmmLlvmGen _ = return ()
- 
- cmmMetaLlvmPrelude :: LlvmM ()
- cmmMetaLlvmPrelude = do
--  metas <- flip mapM stgTBAA $ \(uniq, name, parent) -> do
-+  tbaa_metas <- flip mapM stgTBAA $ \(uniq, name, parent) -> do
-     -- Generate / lookup meta data IDs
-     tbaaId <- getMetaUniqueId
-     setUniqMeta uniq tbaaId
-@@ -209,10 +209,44 @@ cmmMetaLlvmPrelude = do
-               -- just a name on its own. Previously `null` was accepted as the
-               -- name.
-               Nothing -> [ MetaStr name ]
-+
-+  platform <- getPlatform
-+  cfg <- getConfig
-+  let code_model_metas =
+@@ -221,7 +221,12 @@ cmmMetaLlvmPrelude = do
+           case platformArch platform of
+             ArchX86_64 | llvmCgAvxEnabled cfg -> [mkStackAlignmentMeta 32]
+             _                                 -> []
+-  module_flags_metas <- mkModuleFlagsMeta stack_alignment_metas
++  let codel_model_metas =
 +          case platformArch platform of
 +            -- FIXME: We should not rely on LLVM
 +            ArchLoongArch64 -> [mkCodeModelMeta CMMedium]
 +            _                                 -> []
-+  module_flags_metas <- mkModuleFlagsMeta code_model_metas
-+  let metas = tbaa_metas ++ module_flags_metas
-+
++  module_flags_metas <- mkModuleFlagsMeta (stack_alignment_metas ++ codel_model_metas)
+   let metas = tbaa_metas ++ module_flags_metas
    cfg <- getConfig
    renderLlvm (ppLlvmMetas cfg metas)
-              (ppLlvmMetas cfg metas)
+@@ -244,6 +249,15 @@ mkStackAlignmentMeta :: Integer -> ModuleFlag
+ mkStackAlignmentMeta alignment =
+     ModuleFlag MFBError "override-stack-alignment" (MetaLit $ LMIntLit alignment i32)
  
-+mkNamedMeta :: LMString -> [MetaExpr] -> LlvmM [MetaDecl]
-+mkNamedMeta name exprs = do
-+    (ids, decls) <- unzip <$> mapM f exprs
-+    return $ decls ++ [MetaNamed name ids]
-+  where
-+    f expr = do
-+      i <- getMetaUniqueId
-+      return (i, MetaUnnamed i expr)
-+
-+mkModuleFlagsMeta :: [ModuleFlag] -> LlvmM [MetaDecl]
-+mkModuleFlagsMeta =
-+    mkNamedMeta "llvm.module.flags" . map moduleFlagToMetaExpr
-+
 +-- LLVM's @LLVM::CodeModel::Model@ enumeration
 +data CodeModel = CMMedium
 +
@@ -61,18 +49,9 @@ Subject: [PATCH] llvmGen: Pass mcmodel medium option to LLVM backend on LoongArc
 +    ModuleFlag MFBError "Code Model" (MetaLit $ LMIntLit n i32)
 +  where
 +    n = case codemodel of CMMedium -> 3 -- as of LLVM 8
-+
+ 
  -- -----------------------------------------------------------------------------
  -- | Marks variables as used where necessary
- --
---- a/configure.ac
-+++ b/configure.ac
-@@ -543,7 +543,7 @@ AC_SUBST(InstallNameToolCmd)
- # tools we are looking for. In the past, GHC supported a number of
- # versions of LLVM simultaneously, but that stopped working around
- # 3.5/3.6 release of LLVM.
--LlvmMinVersion=11  # inclusive
-+LlvmMinVersion=13  # inclusive
- LlvmMaxVersion=20 # not inclusive
- AC_SUBST([LlvmMinVersion])
- AC_SUBST([LlvmMaxVersion])
+-- 
+2.47.3
+



View it on GitLab: https://salsa.debian.org/haskell-team/DHG_packages/-/commit/ef5b48ea387db938db7512e4df11743f6585692d

-- 
View it on GitLab: https://salsa.debian.org/haskell-team/DHG_packages/-/commit/ef5b48ea387db938db7512e4df11743f6585692d
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-haskell-commits/attachments/20260210/075b1f0a/attachment-0001.htm>


More information about the Pkg-haskell-commits mailing list