1 -----------------------------------------------------------------------------
3 -- Object-file symbols (called CLabel for histerical raisins).
5 -- (c) The University of Glasgow 2004
7 -----------------------------------------------------------------------------
10 CLabel, -- abstract type
19 mkStaticConEntryLabel,
22 mkStaticInfoTableLabel,
28 mkLocalInfoTableLabel,
31 mkLocalStaticConEntryLabel,
32 mkLocalConInfoTableLabel,
33 mkLocalStaticInfoTableLabel,
34 mkLocalClosureTableLabel,
46 mkPlainModuleInitLabel,
52 mkMainCapabilityLabel,
53 mkMAP_FROZEN_infoLabel,
54 mkEMPTY_MVAR_infoLabel,
57 mkCAFBlackHoleInfoTableLabel,
58 mkSECAFBlackHoleInfoTableLabel,
60 mkRtsSlowTickyCtrLabel,
83 mkCCLabel, mkCCSLabel,
85 DynamicLinkerLabelInfo(..),
87 dynamicLinkerLabelInfo,
91 infoLblToEntryLbl, entryLblToInfoLbl,
92 needsCDecl, isAsmTemp, externallyVisibleCLabel,
93 CLabelType(..), labelType, labelDynamic,
99 #include "HsVersions.h"
100 #include "../includes/ghcconfig.h"
102 import CmdLineOpts ( DynFlags, opt_Static, opt_DoTickyProfiling )
103 import Packages ( isHomeModule, isDllName )
104 import DataCon ( ConTag )
105 import Module ( moduleFS, Module )
106 import Name ( Name, isExternalName )
107 import Unique ( pprUnique, Unique )
108 import PrimOp ( PrimOp )
109 import Config ( cLeadingUnderscore )
110 import CostCentre ( CostCentre, CostCentreStack )
114 -- -----------------------------------------------------------------------------
118 CLabel is an abstract type that supports the following operations:
122 - In a C file, does it need to be declared before use? (i.e. is it
123 guaranteed to be already in scope in the places we need to refer to it?)
125 - If it needs to be declared, what type (code or data) should it be
128 - Is it visible outside this object file or not?
130 - Is it "dynamic" (see details below)
132 - Eq and Ord, so that we can make sets of CLabels (currently only
133 used in outputting C as far as I can tell, to avoid generating
134 more than one declaration for any given label).
136 - Converting an info table label into an entry label.
140 = IdLabel -- A family of labels related to the
141 Name -- definition of a particular Id or Con
144 | DynIdLabel -- like IdLabel, but in a separate package,
145 Name -- and might therefore need a dynamic
146 IdLabelInfo -- reference.
148 | CaseLabel -- A family of labels related to a particular
150 {-# UNPACK #-} !Unique -- Unique says which case expression
154 {-# UNPACK #-} !Unique
157 {-# UNPACK #-} !Unique
160 Module -- the module name
162 Bool -- True <=> is in a different package
163 -- at some point we might want some kind of version number in
164 -- the module init label, to guard against compiling modules in
165 -- the wrong order. We can't use the interface file version however,
166 -- because we don't always recompile modules which depend on a module
167 -- whose version has changed.
169 | PlainModuleInitLabel -- without the vesrion & way info
171 Bool -- True <=> is in a different package
175 | RtsLabel RtsLabelInfo
177 | ForeignLabel FastString -- a 'C' (or otherwise foreign) label
178 (Maybe Int) -- possible '@n' suffix for stdcall functions
179 -- When generating C, the '@n' suffix is omitted, but when
180 -- generating assembler we must add it to the label.
181 Bool -- True <=> is dynamic
183 | CC_Label CostCentre
184 | CCS_Label CostCentreStack
186 -- Dynamic Linking in the NCG:
187 -- generated and used inside the NCG only,
188 -- see module PositionIndependentCode for details.
190 | DynamicLinkerLabel DynamicLinkerLabelInfo CLabel
191 -- special variants of a label used for dynamic linking
193 | PicBaseLabel -- a label used as a base for PIC calculations
194 -- on some platforms.
195 -- It takes the form of a local numeric
196 -- assembler label '1'; it is pretty-printed
197 -- as 1b, referring to the previous definition
198 -- of 1: in the assembler source file.
203 = Closure -- Label for closure
204 | SRT -- Static reference table
205 | SRTDesc -- Static reference table descriptor
206 | InfoTable -- Info tables for closures; always read-only
207 | Entry -- entry point
208 | Slow -- slow entry point
210 | RednCounts -- Label of place to keep Ticky-ticky info for
213 | Bitmap -- A bitmap (function or case return)
215 | ConEntry -- constructor entry point
216 | ConInfoTable -- corresponding info table
217 | StaticConEntry -- static constructor entry point
218 | StaticInfoTable -- corresponding info table
220 | ClosureTable -- table of closures for Enum tycons
234 = RtsSelectorInfoTable Bool{-updatable-} Int{-offset-} -- Selector thunks
235 | RtsSelectorEntry Bool{-updatable-} Int{-offset-}
237 | RtsApInfoTable Bool{-updatable-} Int{-arity-} -- AP thunks
238 | RtsApEntry Bool{-updatable-} Int{-arity-}
242 | RtsInfo LitString -- misc rts info tables
243 | RtsEntry LitString -- misc rts entry points
244 | RtsRetInfo LitString -- misc rts ret info tables
245 | RtsRet LitString -- misc rts return points
246 | RtsData LitString -- misc rts data bits, eg CHARLIKE_closure
247 | RtsCode LitString -- misc rts code
249 | RtsInfoFS FastString -- misc rts info tables
250 | RtsEntryFS FastString -- misc rts entry points
251 | RtsRetInfoFS FastString -- misc rts ret info tables
252 | RtsRetFS FastString -- misc rts return points
253 | RtsDataFS FastString -- misc rts data bits, eg CHARLIKE_closure
254 | RtsCodeFS FastString -- misc rts code
256 | RtsSlowTickyCtr String
259 -- NOTE: Eq on LitString compares the pointer only, so this isn't
262 data DynamicLinkerLabelInfo
263 = CodeStub -- MachO: Lfoo$stub, ELF: foo@plt
264 | SymbolPtr -- MachO: Lfoo$non_lazy_ptr, Windows: __imp_foo
265 | GotSymbolPtr -- ELF: foo@got
266 | GotSymbolOffset -- ELF: foo@gotoff
270 -- -----------------------------------------------------------------------------
271 -- Constructing CLabels
273 -- These are always local:
274 mkSRTLabel name = IdLabel name SRT
275 mkSRTDescLabel name = IdLabel name SRTDesc
276 mkSlowEntryLabel name = IdLabel name Slow
277 mkBitmapLabel name = IdLabel name Bitmap
278 mkRednCountsLabel name = IdLabel name RednCounts
280 -- These have local & (possibly) external variants:
281 mkLocalClosureLabel name = IdLabel name Closure
282 mkLocalInfoTableLabel name = IdLabel name InfoTable
283 mkLocalEntryLabel name = IdLabel name Entry
284 mkLocalClosureTableLabel name = IdLabel name ClosureTable
286 mkClosureLabel dflags name
287 | isDllName dflags name = DynIdLabel name Closure
288 | otherwise = IdLabel name Closure
290 mkInfoTableLabel dflags name
291 | isDllName dflags name = DynIdLabel name InfoTable
292 | otherwise = IdLabel name InfoTable
294 mkEntryLabel dflags name
295 | isDllName dflags name = DynIdLabel name Entry
296 | otherwise = IdLabel name Entry
298 mkClosureTableLabel dflags name
299 | isDllName dflags name = DynIdLabel name ClosureTable
300 | otherwise = IdLabel name ClosureTable
302 mkLocalConInfoTableLabel con = IdLabel con ConInfoTable
303 mkLocalConEntryLabel con = IdLabel con ConEntry
304 mkLocalStaticInfoTableLabel con = IdLabel con StaticInfoTable
305 mkLocalStaticConEntryLabel con = IdLabel con StaticConEntry
307 mkConInfoTableLabel name False = IdLabel name ConInfoTable
308 mkConInfoTableLabel name True = DynIdLabel name ConInfoTable
310 mkStaticInfoTableLabel name False = IdLabel name StaticInfoTable
311 mkStaticInfoTableLabel name True = DynIdLabel name StaticInfoTable
313 mkConEntryLabel dflags name
314 | isDllName dflags name = DynIdLabel name ConEntry
315 | otherwise = IdLabel name ConEntry
317 mkStaticConEntryLabel dflags name
318 | isDllName dflags name = DynIdLabel name StaticConEntry
319 | otherwise = IdLabel name StaticConEntry
322 mkReturnPtLabel uniq = CaseLabel uniq CaseReturnPt
323 mkReturnInfoLabel uniq = CaseLabel uniq CaseReturnInfo
324 mkAltLabel uniq tag = CaseLabel uniq (CaseAlt tag)
325 mkDefaultLabel uniq = CaseLabel uniq CaseDefault
327 mkStringLitLabel = StringLitLabel
328 mkAsmTempLabel = AsmTempLabel
330 mkModuleInitLabel :: DynFlags -> Module -> String -> CLabel
331 mkModuleInitLabel dflags mod way
332 = ModuleInitLabel mod way $! (not (isHomeModule dflags mod))
334 mkPlainModuleInitLabel :: DynFlags -> Module -> CLabel
335 mkPlainModuleInitLabel dflags mod
336 = PlainModuleInitLabel mod $! (not (isHomeModule dflags mod))
338 -- Some fixed runtime system labels
340 mkSplitMarkerLabel = RtsLabel (RtsCode SLIT("__stg_split_marker"))
341 mkUpdInfoLabel = RtsLabel (RtsInfo SLIT("stg_upd_frame"))
342 mkSeqInfoLabel = RtsLabel (RtsInfo SLIT("stg_seq_frame"))
343 mkIndStaticInfoLabel = RtsLabel (RtsInfo SLIT("stg_IND_STATIC"))
344 mkMainCapabilityLabel = RtsLabel (RtsData SLIT("MainCapability"))
345 mkMAP_FROZEN_infoLabel = RtsLabel (RtsInfo SLIT("stg_MUT_ARR_PTRS_FROZEN"))
346 mkEMPTY_MVAR_infoLabel = RtsLabel (RtsInfo SLIT("stg_EMPTY_MVAR"))
348 mkTopTickyCtrLabel = RtsLabel (RtsData SLIT("top_ct"))
349 mkCAFBlackHoleInfoTableLabel = RtsLabel (RtsInfo SLIT("stg_CAF_BLACKHOLE"))
350 mkSECAFBlackHoleInfoTableLabel = if opt_DoTickyProfiling then
351 RtsLabel (RtsInfo SLIT("stg_SE_CAF_BLACKHOLE"))
352 else -- RTS won't have info table unless -ticky is on
353 panic "mkSECAFBlackHoleInfoTableLabel requires -ticky"
354 mkRtsPrimOpLabel primop = RtsLabel (RtsPrimOp primop)
356 moduleRegdLabel = ModuleRegdLabel
358 mkSelectorInfoLabel upd off = RtsLabel (RtsSelectorInfoTable upd off)
359 mkSelectorEntryLabel upd off = RtsLabel (RtsSelectorEntry upd off)
361 mkApInfoTableLabel upd off = RtsLabel (RtsApInfoTable upd off)
362 mkApEntryLabel upd off = RtsLabel (RtsApEntry upd off)
366 mkForeignLabel :: FastString -> Maybe Int -> Bool -> CLabel
367 mkForeignLabel str mb_sz is_dynamic = ForeignLabel str mb_sz is_dynamic
371 mkCCLabel cc = CC_Label cc
372 mkCCSLabel ccs = CCS_Label ccs
374 mkRtsInfoLabel str = RtsLabel (RtsInfo str)
375 mkRtsEntryLabel str = RtsLabel (RtsEntry str)
376 mkRtsRetInfoLabel str = RtsLabel (RtsRetInfo str)
377 mkRtsRetLabel str = RtsLabel (RtsRet str)
378 mkRtsCodeLabel str = RtsLabel (RtsCode str)
379 mkRtsDataLabel str = RtsLabel (RtsData str)
381 mkRtsInfoLabelFS str = RtsLabel (RtsInfoFS str)
382 mkRtsEntryLabelFS str = RtsLabel (RtsEntryFS str)
383 mkRtsRetInfoLabelFS str = RtsLabel (RtsRetInfoFS str)
384 mkRtsRetLabelFS str = RtsLabel (RtsRetFS str)
385 mkRtsCodeLabelFS str = RtsLabel (RtsCodeFS str)
386 mkRtsDataLabelFS str = RtsLabel (RtsDataFS str)
388 mkRtsSlowTickyCtrLabel :: String -> CLabel
389 mkRtsSlowTickyCtrLabel pat = RtsLabel (RtsSlowTickyCtr pat)
393 mkDynamicLinkerLabel :: DynamicLinkerLabelInfo -> CLabel -> CLabel
394 mkDynamicLinkerLabel = DynamicLinkerLabel
396 dynamicLinkerLabelInfo :: CLabel -> Maybe (DynamicLinkerLabelInfo, CLabel)
397 dynamicLinkerLabelInfo (DynamicLinkerLabel info lbl) = Just (info, lbl)
398 dynamicLinkerLabelInfo _ = Nothing
400 -- Position independent code
402 mkPicBaseLabel :: CLabel
403 mkPicBaseLabel = PicBaseLabel
405 -- -----------------------------------------------------------------------------
406 -- Converting info labels to entry labels.
408 infoLblToEntryLbl :: CLabel -> CLabel
409 infoLblToEntryLbl (IdLabel n InfoTable) = IdLabel n Entry
410 infoLblToEntryLbl (IdLabel n ConInfoTable) = IdLabel n ConEntry
411 infoLblToEntryLbl (IdLabel n StaticInfoTable) = IdLabel n StaticConEntry
412 infoLblToEntryLbl (DynIdLabel n InfoTable) = DynIdLabel n Entry
413 infoLblToEntryLbl (DynIdLabel n ConInfoTable) = DynIdLabel n ConEntry
414 infoLblToEntryLbl (DynIdLabel n StaticInfoTable) = DynIdLabel n StaticConEntry
415 infoLblToEntryLbl (CaseLabel n CaseReturnInfo) = CaseLabel n CaseReturnPt
416 infoLblToEntryLbl (RtsLabel (RtsInfo s)) = RtsLabel (RtsEntry s)
417 infoLblToEntryLbl (RtsLabel (RtsRetInfo s)) = RtsLabel (RtsRet s)
418 infoLblToEntryLbl (RtsLabel (RtsInfoFS s)) = RtsLabel (RtsEntryFS s)
419 infoLblToEntryLbl (RtsLabel (RtsRetInfoFS s)) = RtsLabel (RtsRetFS s)
420 infoLblToEntryLbl _ = panic "CLabel.infoLblToEntryLbl"
422 entryLblToInfoLbl :: CLabel -> CLabel
423 entryLblToInfoLbl (IdLabel n Entry) = IdLabel n InfoTable
424 entryLblToInfoLbl (IdLabel n ConEntry) = IdLabel n ConInfoTable
425 entryLblToInfoLbl (IdLabel n StaticConEntry) = IdLabel n StaticInfoTable
426 entryLblToInfoLbl (DynIdLabel n Entry) = DynIdLabel n InfoTable
427 entryLblToInfoLbl (DynIdLabel n ConEntry) = DynIdLabel n ConInfoTable
428 entryLblToInfoLbl (DynIdLabel n StaticConEntry) = DynIdLabel n StaticInfoTable
429 entryLblToInfoLbl (CaseLabel n CaseReturnPt) = CaseLabel n CaseReturnInfo
430 entryLblToInfoLbl (RtsLabel (RtsEntry s)) = RtsLabel (RtsInfo s)
431 entryLblToInfoLbl (RtsLabel (RtsRet s)) = RtsLabel (RtsRetInfo s)
432 entryLblToInfoLbl (RtsLabel (RtsEntryFS s)) = RtsLabel (RtsInfoFS s)
433 entryLblToInfoLbl (RtsLabel (RtsRetFS s)) = RtsLabel (RtsRetInfoFS s)
434 entryLblToInfoLbl l = pprPanic "CLabel.entryLblToInfoLbl" (pprCLabel l)
436 -- -----------------------------------------------------------------------------
437 -- Does a CLabel need declaring before use or not?
439 needsCDecl :: CLabel -> Bool
440 -- False <=> it's pre-declared; don't bother
441 -- don't bother declaring SRT & Bitmap labels, we always make sure
442 -- they are defined before use.
443 needsCDecl (IdLabel _ SRT) = False
444 needsCDecl (IdLabel _ SRTDesc) = False
445 needsCDecl (IdLabel _ Bitmap) = False
446 needsCDecl (IdLabel _ _) = True
447 needsCDecl (DynIdLabel _ _) = True
448 needsCDecl (CaseLabel _ _) = True
449 needsCDecl (ModuleInitLabel _ _ _) = True
450 needsCDecl (PlainModuleInitLabel _ _) = True
451 needsCDecl ModuleRegdLabel = False
453 needsCDecl (CaseLabel _ _) = False
454 needsCDecl (StringLitLabel _) = False
455 needsCDecl (AsmTempLabel _) = False
456 needsCDecl (RtsLabel _) = False
457 needsCDecl (ForeignLabel _ _ _) = False
458 needsCDecl (CC_Label _) = True
459 needsCDecl (CCS_Label _) = True
461 -- Whether the label is an assembler temporary:
463 isAsmTemp :: CLabel -> Bool -- is a local temporary for native code generation
464 isAsmTemp (AsmTempLabel _) = True
467 -- -----------------------------------------------------------------------------
468 -- Is a CLabel visible outside this object file or not?
470 -- From the point of view of the code generator, a name is
471 -- externally visible if it has to be declared as exported
472 -- in the .o file's symbol table; that is, made non-static.
474 externallyVisibleCLabel :: CLabel -> Bool -- not C "static"
475 externallyVisibleCLabel (CaseLabel _ _) = False
476 externallyVisibleCLabel (StringLitLabel _) = False
477 externallyVisibleCLabel (AsmTempLabel _) = False
478 externallyVisibleCLabel (ModuleInitLabel _ _ _)= True
479 externallyVisibleCLabel (PlainModuleInitLabel _ _)= True
480 externallyVisibleCLabel ModuleRegdLabel = False
481 externallyVisibleCLabel (RtsLabel _) = True
482 externallyVisibleCLabel (ForeignLabel _ _ _) = True
483 externallyVisibleCLabel (IdLabel name _) = isExternalName name
484 externallyVisibleCLabel (DynIdLabel name _) = isExternalName name
485 externallyVisibleCLabel (CC_Label _) = True
486 externallyVisibleCLabel (CCS_Label _) = True
487 externallyVisibleCLabel (DynamicLinkerLabel _ _) = False
489 -- -----------------------------------------------------------------------------
490 -- Finding the "type" of a CLabel
492 -- For generating correct types in label declarations:
498 labelType :: CLabel -> CLabelType
499 labelType (RtsLabel (RtsSelectorInfoTable _ _)) = DataLabel
500 labelType (RtsLabel (RtsApInfoTable _ _)) = DataLabel
501 labelType (RtsLabel (RtsData _)) = DataLabel
502 labelType (RtsLabel (RtsCode _)) = CodeLabel
503 labelType (RtsLabel (RtsInfo _)) = DataLabel
504 labelType (RtsLabel (RtsEntry _)) = CodeLabel
505 labelType (RtsLabel (RtsRetInfo _)) = DataLabel
506 labelType (RtsLabel (RtsRet _)) = CodeLabel
507 labelType (RtsLabel (RtsDataFS _)) = DataLabel
508 labelType (RtsLabel (RtsCodeFS _)) = CodeLabel
509 labelType (RtsLabel (RtsInfoFS _)) = DataLabel
510 labelType (RtsLabel (RtsEntryFS _)) = CodeLabel
511 labelType (RtsLabel (RtsRetInfoFS _)) = DataLabel
512 labelType (RtsLabel (RtsRetFS _)) = CodeLabel
513 labelType (CaseLabel _ CaseReturnInfo) = DataLabel
514 labelType (CaseLabel _ _) = CodeLabel
515 labelType (ModuleInitLabel _ _ _) = CodeLabel
516 labelType (PlainModuleInitLabel _ _) = CodeLabel
518 labelType (IdLabel _ info) = idInfoLabelType info
519 labelType (DynIdLabel _ info) = idInfoLabelType info
520 labelType _ = DataLabel
522 idInfoLabelType info =
524 InfoTable -> DataLabel
527 ConInfoTable -> DataLabel
528 StaticInfoTable -> DataLabel
529 ClosureTable -> DataLabel
533 -- -----------------------------------------------------------------------------
534 -- Does a CLabel need dynamic linkage?
536 -- When referring to data in code, we need to know whether
537 -- that data resides in a DLL or not. [Win32 only.]
538 -- @labelDynamic@ returns @True@ if the label is located
539 -- in a DLL, be it a data reference or not.
541 labelDynamic :: CLabel -> Bool
544 RtsLabel _ -> not opt_Static -- i.e., is the RTS in a DLL or not?
546 DynIdLabel n k -> True
547 #if mingw32_TARGET_OS
548 ForeignLabel _ _ d -> d
550 -- On Mac OS X and on ELF platforms, false positives are OK,
551 -- so we claim that all foreign imports come from dynamic libraries
552 ForeignLabel _ _ _ -> True
554 ModuleInitLabel m _ dyn -> not opt_Static && dyn
555 PlainModuleInitLabel m dyn -> not opt_Static && dyn
557 -- Note that DynamicLinkerLabels do NOT require dynamic linking themselves.
561 OLD?: These GRAN functions are needed for spitting out GRAN_FETCH() at the
562 right places. It is used to detect when the abstractC statement of an
563 CCodeBlock actually contains the code for a slow entry point. -- HWL
565 We need at least @Eq@ for @CLabels@, because we want to avoid
566 duplicate declarations in generating C (see @labelSeenTE@ in
570 -----------------------------------------------------------------------------
571 -- Printing out CLabels.
578 where <name> is <Module>_<name> for external names and <unique> for
579 internal names. <type> is one of the following:
582 srt Static reference table
583 srtd Static reference table descriptor
584 entry Entry code (function, closure)
585 slow Slow entry code (if any)
586 ret Direct return address
588 <n>_alt Case alternative (tag n)
589 dflt Default case alternative
590 btm Large bitmap vector
591 closure Static closure
592 con_entry Dynamic Constructor entry code
593 con_info Dynamic Constructor info table
594 static_entry Static Constructor entry code
595 static_info Static Constructor info table
596 sel_info Selector info table
597 sel_entry Selector entry code
599 ccs Cost centre stack
601 Many of these distinctions are only for documentation reasons. For
602 example, _ret is only distinguished from _entry to make it easy to
603 tell whether a code fragment is a return point or a closure/function
607 pprCLabel :: CLabel -> SDoc
609 #if ! OMIT_NATIVE_CODEGEN
610 pprCLabel (AsmTempLabel u)
611 = getPprStyle $ \ sty ->
613 ptext asmTempLabelPrefix <> pprUnique u
615 char '_' <> pprUnique u
617 pprCLabel (DynamicLinkerLabel info lbl)
618 = pprDynamicLinkerAsmLabel info lbl
620 pprCLabel PicBaseLabel
625 #if ! OMIT_NATIVE_CODEGEN
626 getPprStyle $ \ sty ->
628 maybe_underscore (pprAsmCLbl lbl)
634 | underscorePrefix = pp_cSEP <> doc
637 #ifdef mingw32_TARGET_OS
638 -- In asm mode, we need to put the suffix on a stdcall ForeignLabel.
639 -- (The C compiler does this itself).
640 pprAsmCLbl (ForeignLabel fs (Just sz) _)
641 = ftext fs <> char '@' <> int sz
646 pprCLbl (StringLitLabel u)
647 = pprUnique u <> ptext SLIT("_str")
649 pprCLbl (CaseLabel u CaseReturnPt)
650 = hcat [pprUnique u, ptext SLIT("_ret")]
651 pprCLbl (CaseLabel u CaseReturnInfo)
652 = hcat [pprUnique u, ptext SLIT("_info")]
653 pprCLbl (CaseLabel u (CaseAlt tag))
654 = hcat [pprUnique u, pp_cSEP, int tag, ptext SLIT("_alt")]
655 pprCLbl (CaseLabel u CaseDefault)
656 = hcat [pprUnique u, ptext SLIT("_dflt")]
658 pprCLbl (RtsLabel (RtsCode str)) = ptext str
659 pprCLbl (RtsLabel (RtsData str)) = ptext str
660 pprCLbl (RtsLabel (RtsCodeFS str)) = ftext str
661 pprCLbl (RtsLabel (RtsDataFS str)) = ftext str
663 pprCLbl (RtsLabel (RtsSelectorInfoTable upd_reqd offset))
664 = hcat [ptext SLIT("stg_sel_"), text (show offset),
666 then SLIT("_upd_info")
667 else SLIT("_noupd_info"))
670 pprCLbl (RtsLabel (RtsSelectorEntry upd_reqd offset))
671 = hcat [ptext SLIT("stg_sel_"), text (show offset),
673 then SLIT("_upd_entry")
674 else SLIT("_noupd_entry"))
677 pprCLbl (RtsLabel (RtsApInfoTable upd_reqd arity))
678 = hcat [ptext SLIT("stg_ap_"), text (show arity),
680 then SLIT("_upd_info")
681 else SLIT("_noupd_info"))
684 pprCLbl (RtsLabel (RtsApEntry upd_reqd arity))
685 = hcat [ptext SLIT("stg_ap_"), text (show arity),
687 then SLIT("_upd_entry")
688 else SLIT("_noupd_entry"))
691 pprCLbl (RtsLabel (RtsInfo fs))
692 = ptext fs <> ptext SLIT("_info")
694 pprCLbl (RtsLabel (RtsEntry fs))
695 = ptext fs <> ptext SLIT("_entry")
697 pprCLbl (RtsLabel (RtsRetInfo fs))
698 = ptext fs <> ptext SLIT("_info")
700 pprCLbl (RtsLabel (RtsRet fs))
701 = ptext fs <> ptext SLIT("_ret")
703 pprCLbl (RtsLabel (RtsInfoFS fs))
704 = ftext fs <> ptext SLIT("_info")
706 pprCLbl (RtsLabel (RtsEntryFS fs))
707 = ftext fs <> ptext SLIT("_entry")
709 pprCLbl (RtsLabel (RtsRetInfoFS fs))
710 = ftext fs <> ptext SLIT("_info")
712 pprCLbl (RtsLabel (RtsRetFS fs))
713 = ftext fs <> ptext SLIT("_ret")
715 pprCLbl (RtsLabel (RtsPrimOp primop))
716 = ppr primop <> ptext SLIT("_fast")
718 pprCLbl (RtsLabel (RtsSlowTickyCtr pat))
719 = ptext SLIT("SLOW_CALL_") <> text pat <> ptext SLIT("_ctr")
721 pprCLbl ModuleRegdLabel
722 = ptext SLIT("_module_registered")
724 pprCLbl (ForeignLabel str _ _)
727 pprCLbl (IdLabel name flavor) = ppr name <> ppIdFlavor flavor
728 pprCLbl (DynIdLabel name flavor) = ppr name <> ppIdFlavor flavor
730 pprCLbl (CC_Label cc) = ppr cc
731 pprCLbl (CCS_Label ccs) = ppr ccs
733 pprCLbl (ModuleInitLabel mod way _)
734 = ptext SLIT("__stginit_") <> ftext (moduleFS mod)
735 <> char '_' <> text way
736 pprCLbl (PlainModuleInitLabel mod _)
737 = ptext SLIT("__stginit_") <> ftext (moduleFS mod)
739 ppIdFlavor :: IdLabelInfo -> SDoc
740 ppIdFlavor x = pp_cSEP <>
742 Closure -> ptext SLIT("closure")
743 SRT -> ptext SLIT("srt")
744 SRTDesc -> ptext SLIT("srtd")
745 InfoTable -> ptext SLIT("info")
746 Entry -> ptext SLIT("entry")
747 Slow -> ptext SLIT("slow")
748 RednCounts -> ptext SLIT("ct")
749 Bitmap -> ptext SLIT("btm")
750 ConEntry -> ptext SLIT("con_entry")
751 ConInfoTable -> ptext SLIT("con_info")
752 StaticConEntry -> ptext SLIT("static_entry")
753 StaticInfoTable -> ptext SLIT("static_info")
754 ClosureTable -> ptext SLIT("closure_tbl")
760 -- -----------------------------------------------------------------------------
761 -- Machine-dependent knowledge about labels.
763 underscorePrefix :: Bool -- leading underscore on assembler labels?
764 underscorePrefix = (cLeadingUnderscore == "YES")
766 asmTempLabelPrefix :: LitString -- for formatting labels
769 {- The alpha assembler likes temporary labels to look like $L123
770 instead of L123. (Don't toss the L, because then Lf28
774 #elif darwin_TARGET_OS
780 pprDynamicLinkerAsmLabel :: DynamicLinkerLabelInfo -> CLabel -> SDoc
783 pprDynamicLinkerAsmLabel SymbolPtr lbl
784 = char 'L' <> pprCLabel lbl <> text "$non_lazy_ptr"
785 pprDynamicLinkerAsmLabel CodeStub lbl
786 = char 'L' <> pprCLabel lbl <> text "$stub"
787 #elif powerpc_TARGET_ARCH && linux_TARGET_OS
788 pprDynamicLinkerAsmLabel CodeStub lbl
789 = pprCLabel lbl <> text "@plt"
790 pprDynamicLinkerAsmLabel SymbolPtr lbl
791 = text ".LC_" <> pprCLabel lbl
792 #elif linux_TARGET_OS
793 pprDynamicLinkerAsmLabel CodeStub lbl
794 = pprCLabel lbl <> text "@plt"
795 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
796 = pprCLabel lbl <> text "@got"
797 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
798 = pprCLabel lbl <> text "@gotoff"
799 #elif mingw32_TARGET_OS
800 pprDynamicLinkerAsmLabel SymbolPtr lbl
801 = text "__imp_" <> pprCLabel lbl
803 pprDynamicLinkerAsmLabel _ _
804 = panic "pprDynamicLinkerAsmLabel"