-pprCmmStatic :: DynFlags -> [CmmStatic] -> Doc
-pprCmmStatic dflags stat
- = let unres = genLlvmData dflags (Data,stat)
- (_, ldata) = resolveLlvmData dflags initLlvmEnv unres
- in pprLlvmData dflags ldata
+pprInfoTable :: LlvmEnv -> Int -> CLabel -> [CmmStatic] -> (Doc, [LlvmVar])
+pprInfoTable env count lbl stat
+ = let unres = genLlvmData (Text, stat)
+ (_, (ldata, ltypes)) = resolveLlvmData env unres
+
+ setSection ((LMGlobalVar _ ty l _ _ c), d)
+ = let sec = mkLayoutSection count
+ ilabel = strCLabel_llvm (entryLblToInfoLbl lbl)
+ `appendFS` fsLit iTableSuf
+ gv = LMGlobalVar ilabel ty l sec llvmInfAlign c
+ v = if l == Internal then [gv] else []
+ in ((gv, d), v)
+ setSection v = (v,[])
+
+ (ldata', llvmUsed) = setSection (last ldata)
+ in if length ldata /= 1
+ then Outputable.panic "LlvmCodeGen.Ppr: invalid info table!"
+ else (pprLlvmData ([ldata'], ltypes), llvmUsed)
+
+
+-- | We generate labels for info tables by converting them to the same label
+-- as for the entry code but adding this string as a suffix.
+iTableSuf :: String
+iTableSuf = "_itable"
+
+
+-- | Create a specially crafted section declaration that encodes the order this
+-- section should be in the final object code.
+--
+-- The LlvmMangler.llvmFixupAsm pass over the assembly produced by LLVM uses
+-- this section declaration to do its processing.
+mkLayoutSection :: Int -> LMSection
+mkLayoutSection n
+ = Just (fsLit $ infoSection ++ show n)
+
+
+-- | The section we are putting info tables and their entry code into, should
+-- be unique since we process the assembly pattern matching this.
+infoSection :: String
+infoSection = "X98A__STRIP,__me"