Bug#1125455: ghc: enable ld override for loong64

fanpeng fanpeng at loongson.cn
Tue Feb 10 03:18:34 GMT 2026


On Tue, 10 Feb 2026 11:04:41 +0800 fanpeng wrote:


Get the patch from upstream directly.

Commit ID: e70d41406b5d5638b42c4d8222cd03e76bbfeb86


--- a/compiler/GHC/CmmToLlvm.hs
+++ b/compiler/GHC/CmmToLlvm.hs
@@ -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 (stack_alignment_metas ++ 
codel_model_metas)
    let metas = tbaa_metas ++ module_flags_metas
    cfg <- getConfig
    renderLlvm (ppLlvmMetas cfg metas)
@@ -244,6 +249,15 @@ mkStackAlignmentMeta :: Integer -> ModuleFlag
  mkStackAlignmentMeta alignment =
      ModuleFlag MFBError "override-stack-alignment" (MetaLit $ LMIntLit 
alignment i32)

+-- LLVM's @LLVM::CodeModel::Model@ enumeration
+data CodeModel = CMMedium
+
+-- Pass -mcmodel=medium option to LLVM on LoongArch64
+mkCodeModelMeta :: CodeModel -> ModuleFlag
+mkCodeModelMeta codemodel =
+    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


 > From e70d41406b5d5638b42c4d8222cd03e76bbfeb86 Mon Sep 17 00:00:00 2001
 > From: Xin Wang
 > Date: Mon, 13 Dec 2024 10:45:20 +0800
 > Subject: [PATCH] llvmGen: Pass mcmodel medium option to LLVM backend 
on LoongArch
 >
 > ---
 > compiler/GHC/CmmToLlvm.hs | 17 ++++++++++++++++-
 > 1 file changed, 16 insertions(+), 1 deletion(-)
 >
 > --- a/compiler/GHC/CmmToLlvm.hs
 > +++ b/compiler/GHC/CmmToLlvm.hs
 > @@ -219,7 +219,13 @@ cmmMetaLlvmPrelude = do
 > ArchX86_64 | llvmCgAvxEnabled cfg -> [mkStackAlignmentMeta 32]
 > _ -> []
 > module_flags_metas <- mkModuleFlagsMeta stack_alignment_metas
 > - let metas = tbaa_metas ++ module_flags_metas
 > + let code_model_metas =
 > + case platformArch platform of
 > + -- FIXME: We should not rely on LLVM
 > + ArchLoongArch64 -> [mkCodeModelMeta CMMedium]
 > + _ -> []
 > + mcmodel_flags_metas <- mkModuleFlagsMeta code_model_metas
 > + let metas = tbaa_metas ++ module_flags_metas ++ mcmodel_flags_metas
 > cfg <- getConfig
 > renderLlvm (ppLlvmMetas cfg metas)
 > (ppLlvmMetas cfg metas)
 > @@ -241,6 +247,15 @@ mkStackAlignmentMeta :: Integer -> ModuleFlag
 > mkStackAlignmentMeta alignment =
 > ModuleFlag MFBError "override-stack-alignment" (MetaLit $ LMIntLit 
alignment i32)
 >
 > +-- LLVM's @LLVM::CodeModel::Model@ enumeration
 > +data CodeModel = CMMedium
 > +
 > +-- Pass -mcmodel=medium option to LLVM on LoongArch64
 > +mkCodeModelMeta :: CodeModel -> ModuleFlag
 > +mkCodeModelMeta codemodel =
 > + 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-haskell-maintainers/attachments/20260210/c30a8991/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Add-mcmodel-medium-moduleflag-to-generated-LLVM-IR-o.patch
Type: text/x-patch
Size: 2389 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/pkg-haskell-maintainers/attachments/20260210/c30a8991/attachment-0001.bin>


More information about the Pkg-haskell-maintainers mailing list