Bug#1125455: ghc: enable ld override for loong64

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


Yes, It‘s also possible to use only the parameters in EXTRA_HADRIAN_FLAGS.

In addition, I notice that the content of this patch 0004-* patch will 
conflict, but this modification for Loong64 is necessary if the LLvm 
backend is used.


diff --git a/compiler/GHC/CmmToLlvm.hs b/compiler/GHC/CmmToLlvm.hs
index de5d84c..ac52827 100644
--- 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


On Sun, 25 Jan 2026 09:53:36 +0100 John Paul Adrian Glaubitz wrote:

 > Hi fanpeng,
 >
 > On Wed, 2026-01-14 at 06:32 +0000, fanpeng wrote:
 > > And the 0005-* patch is also required for C files.
 >
 > Did you forget this particular patch? I'm not seeing it here.
 >
 > Why not just keep the parameters in EXTRA_HADRIAN_FLAGS?
 >
 > Adrian
 >
 >
 > --
 > .''`. John Paul Adrian Glaubitz
 > : :' : Debian Developer
 > `. `' Physicist
 > `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
 >
 >

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


More information about the Pkg-haskell-maintainers mailing list