1 -----------------------------------------------------------------------------
3 -- Object-file symbols (called CLabel for histerical raisins).
5 -- (c) The University of Glasgow 2004-2006
7 -----------------------------------------------------------------------------
10 CLabel, -- abstract type
18 mkStaticConEntryLabel,
21 mkStaticInfoTableLabel,
28 mkLocalInfoTableLabel,
31 mkLocalStaticConEntryLabel,
32 mkLocalConInfoTableLabel,
33 mkLocalStaticInfoTableLabel,
34 mkLocalClosureTableLabel,
46 mkPlainModuleInitLabel,
49 mkDirty_MUT_VAR_Label,
52 mkMainCapabilityLabel,
53 mkMAP_FROZEN_infoLabel,
54 mkMAP_DIRTY_infoLabel,
55 mkEMPTY_MVAR_infoLabel,
58 mkCAFBlackHoleInfoTableLabel,
59 mkSECAFBlackHoleInfoTableLabel,
61 mkRtsSlowTickyCtrLabel,
86 mkCCLabel, mkCCSLabel,
88 DynamicLinkerLabelInfo(..),
90 dynamicLinkerLabelInfo,
98 infoLblToEntryLbl, entryLblToInfoLbl,
99 needsCDecl, isAsmTemp, maybeAsmTemp, externallyVisibleCLabel,
100 CLabelType(..), labelType, labelDynamic,
106 #include "HsVersions.h"
122 -- -----------------------------------------------------------------------------
126 CLabel is an abstract type that supports the following operations:
130 - In a C file, does it need to be declared before use? (i.e. is it
131 guaranteed to be already in scope in the places we need to refer to it?)
133 - If it needs to be declared, what type (code or data) should it be
136 - Is it visible outside this object file or not?
138 - Is it "dynamic" (see details below)
140 - Eq and Ord, so that we can make sets of CLabels (currently only
141 used in outputting C as far as I can tell, to avoid generating
142 more than one declaration for any given label).
144 - Converting an info table label into an entry label.
148 = IdLabel -- A family of labels related to the
149 Name -- definition of a particular Id or Con
152 | CaseLabel -- A family of labels related to a particular
154 {-# UNPACK #-} !Unique -- Unique says which case expression
158 {-# UNPACK #-} !Unique
161 {-# UNPACK #-} !Unique
164 Module -- the module name
166 -- at some point we might want some kind of version number in
167 -- the module init label, to guard against compiling modules in
168 -- the wrong order. We can't use the interface file version however,
169 -- because we don't always recompile modules which depend on a module
170 -- whose version has changed.
172 | PlainModuleInitLabel -- without the vesrion & way info
177 | RtsLabel RtsLabelInfo
179 | ForeignLabel FastString -- a 'C' (or otherwise foreign) label
180 (Maybe Int) -- possible '@n' suffix for stdcall functions
181 -- When generating C, the '@n' suffix is omitted, but when
182 -- generating assembler we must add it to the label.
183 Bool -- True <=> is dynamic
185 | CC_Label CostCentre
186 | CCS_Label CostCentreStack
188 -- Dynamic Linking in the NCG:
189 -- generated and used inside the NCG only,
190 -- see module PositionIndependentCode for details.
192 | DynamicLinkerLabel DynamicLinkerLabelInfo CLabel
193 -- special variants of a label used for dynamic linking
195 | PicBaseLabel -- a label used as a base for PIC calculations
196 -- on some platforms.
197 -- It takes the form of a local numeric
198 -- assembler label '1'; it is pretty-printed
199 -- as 1b, referring to the previous definition
200 -- of 1: in the assembler source file.
202 | DeadStripPreventer CLabel
203 -- label before an info table to prevent excessive dead-stripping on darwin
205 | HpcTicksLabel Module -- Per-module table of tick locations
206 | HpcModuleNameLabel -- Per-module name of the module for Hpc
208 | LargeSRTLabel -- Label of an StgLargeSRT
209 {-# UNPACK #-} !Unique
211 | LargeBitmapLabel -- A bitmap (function or case return)
212 {-# UNPACK #-} !Unique
217 = Closure -- Label for closure
218 | SRT -- Static reference table
219 | InfoTable -- Info tables for closures; always read-only
220 | Entry -- entry point
221 | Slow -- slow entry point
223 | RednCounts -- Label of place to keep Ticky-ticky info for
226 | ConEntry -- constructor entry point
227 | ConInfoTable -- corresponding info table
228 | StaticConEntry -- static constructor entry point
229 | StaticInfoTable -- corresponding info table
231 | ClosureTable -- table of closures for Enum tycons
245 = RtsSelectorInfoTable Bool{-updatable-} Int{-offset-} -- Selector thunks
246 | RtsSelectorEntry Bool{-updatable-} Int{-offset-}
248 | RtsApInfoTable Bool{-updatable-} Int{-arity-} -- AP thunks
249 | RtsApEntry Bool{-updatable-} Int{-arity-}
253 | RtsInfo LitString -- misc rts info tables
254 | RtsEntry LitString -- misc rts entry points
255 | RtsRetInfo LitString -- misc rts ret info tables
256 | RtsRet LitString -- misc rts return points
257 | RtsData LitString -- misc rts data bits, eg CHARLIKE_closure
258 | RtsCode LitString -- misc rts code
260 | RtsInfoFS FastString -- misc rts info tables
261 | RtsEntryFS FastString -- misc rts entry points
262 | RtsRetInfoFS FastString -- misc rts ret info tables
263 | RtsRetFS FastString -- misc rts return points
264 | RtsDataFS FastString -- misc rts data bits, eg CHARLIKE_closure
265 | RtsCodeFS FastString -- misc rts code
267 | RtsApFast LitString -- _fast versions of generic apply
269 | RtsSlowTickyCtr String
272 -- NOTE: Eq on LitString compares the pointer only, so this isn't
275 data DynamicLinkerLabelInfo
276 = CodeStub -- MachO: Lfoo$stub, ELF: foo@plt
277 | SymbolPtr -- MachO: Lfoo$non_lazy_ptr, Windows: __imp_foo
278 | GotSymbolPtr -- ELF: foo@got
279 | GotSymbolOffset -- ELF: foo@gotoff
283 -- -----------------------------------------------------------------------------
284 -- Constructing CLabels
286 -- These are always local:
287 mkSRTLabel name = IdLabel name SRT
288 mkSlowEntryLabel name = IdLabel name Slow
289 mkRednCountsLabel name = IdLabel name RednCounts
291 -- These have local & (possibly) external variants:
292 mkLocalClosureLabel name = IdLabel name Closure
293 mkLocalInfoTableLabel name = IdLabel name InfoTable
294 mkLocalEntryLabel name = IdLabel name Entry
295 mkLocalClosureTableLabel name = IdLabel name ClosureTable
297 mkClosureLabel name = IdLabel name Closure
298 mkInfoTableLabel name = IdLabel name InfoTable
299 mkEntryLabel name = IdLabel name Entry
300 mkClosureTableLabel name = IdLabel name ClosureTable
301 mkLocalConInfoTableLabel con = IdLabel con ConInfoTable
302 mkLocalConEntryLabel con = IdLabel con ConEntry
303 mkLocalStaticInfoTableLabel con = IdLabel con StaticInfoTable
304 mkLocalStaticConEntryLabel con = IdLabel con StaticConEntry
305 mkConInfoTableLabel name = IdLabel name ConInfoTable
306 mkStaticInfoTableLabel name = IdLabel name StaticInfoTable
308 mkConEntryLabel name = IdLabel name ConEntry
309 mkStaticConEntryLabel name = IdLabel name StaticConEntry
311 mkLargeSRTLabel uniq = LargeSRTLabel uniq
312 mkBitmapLabel uniq = LargeBitmapLabel uniq
314 mkReturnPtLabel uniq = CaseLabel uniq CaseReturnPt
315 mkReturnInfoLabel uniq = CaseLabel uniq CaseReturnInfo
316 mkAltLabel uniq tag = CaseLabel uniq (CaseAlt tag)
317 mkDefaultLabel uniq = CaseLabel uniq CaseDefault
319 mkStringLitLabel = StringLitLabel
320 mkAsmTempLabel = AsmTempLabel
322 mkModuleInitLabel :: Module -> String -> CLabel
323 mkModuleInitLabel mod way = ModuleInitLabel mod way
325 mkPlainModuleInitLabel :: Module -> CLabel
326 mkPlainModuleInitLabel mod = PlainModuleInitLabel mod
328 -- Some fixed runtime system labels
330 mkSplitMarkerLabel = RtsLabel (RtsCode SLIT("__stg_split_marker"))
331 mkDirty_MUT_VAR_Label = RtsLabel (RtsCode SLIT("dirty_MUT_VAR"))
332 mkUpdInfoLabel = RtsLabel (RtsInfo SLIT("stg_upd_frame"))
333 mkIndStaticInfoLabel = RtsLabel (RtsInfo SLIT("stg_IND_STATIC"))
334 mkMainCapabilityLabel = RtsLabel (RtsData SLIT("MainCapability"))
335 mkMAP_FROZEN_infoLabel = RtsLabel (RtsInfo SLIT("stg_MUT_ARR_PTRS_FROZEN0"))
336 mkMAP_DIRTY_infoLabel = RtsLabel (RtsInfo SLIT("stg_MUT_ARR_PTRS_DIRTY"))
337 mkEMPTY_MVAR_infoLabel = RtsLabel (RtsInfo SLIT("stg_EMPTY_MVAR"))
339 mkTopTickyCtrLabel = RtsLabel (RtsData SLIT("top_ct"))
340 mkCAFBlackHoleInfoTableLabel = RtsLabel (RtsInfo SLIT("stg_CAF_BLACKHOLE"))
341 mkSECAFBlackHoleInfoTableLabel = if opt_DoTickyProfiling then
342 RtsLabel (RtsInfo SLIT("stg_SE_CAF_BLACKHOLE"))
343 else -- RTS won't have info table unless -ticky is on
344 panic "mkSECAFBlackHoleInfoTableLabel requires -ticky"
345 mkRtsPrimOpLabel primop = RtsLabel (RtsPrimOp primop)
347 moduleRegdLabel = ModuleRegdLabel
349 mkSelectorInfoLabel upd off = RtsLabel (RtsSelectorInfoTable upd off)
350 mkSelectorEntryLabel upd off = RtsLabel (RtsSelectorEntry upd off)
352 mkApInfoTableLabel upd off = RtsLabel (RtsApInfoTable upd off)
353 mkApEntryLabel upd off = RtsLabel (RtsApEntry upd off)
357 mkForeignLabel :: FastString -> Maybe Int -> Bool -> CLabel
358 mkForeignLabel str mb_sz is_dynamic = ForeignLabel str mb_sz is_dynamic
362 mkCCLabel cc = CC_Label cc
363 mkCCSLabel ccs = CCS_Label ccs
365 mkRtsInfoLabel str = RtsLabel (RtsInfo str)
366 mkRtsEntryLabel str = RtsLabel (RtsEntry str)
367 mkRtsRetInfoLabel str = RtsLabel (RtsRetInfo str)
368 mkRtsRetLabel str = RtsLabel (RtsRet str)
369 mkRtsCodeLabel str = RtsLabel (RtsCode str)
370 mkRtsDataLabel str = RtsLabel (RtsData str)
372 mkRtsInfoLabelFS str = RtsLabel (RtsInfoFS str)
373 mkRtsEntryLabelFS str = RtsLabel (RtsEntryFS str)
374 mkRtsRetInfoLabelFS str = RtsLabel (RtsRetInfoFS str)
375 mkRtsRetLabelFS str = RtsLabel (RtsRetFS str)
376 mkRtsCodeLabelFS str = RtsLabel (RtsCodeFS str)
377 mkRtsDataLabelFS str = RtsLabel (RtsDataFS str)
379 mkRtsApFastLabel str = RtsLabel (RtsApFast str)
381 mkRtsSlowTickyCtrLabel :: String -> CLabel
382 mkRtsSlowTickyCtrLabel pat = RtsLabel (RtsSlowTickyCtr pat)
386 mkHpcTicksLabel = HpcTicksLabel
387 mkHpcModuleNameLabel = HpcModuleNameLabel
391 mkDynamicLinkerLabel :: DynamicLinkerLabelInfo -> CLabel -> CLabel
392 mkDynamicLinkerLabel = DynamicLinkerLabel
394 dynamicLinkerLabelInfo :: CLabel -> Maybe (DynamicLinkerLabelInfo, CLabel)
395 dynamicLinkerLabelInfo (DynamicLinkerLabel info lbl) = Just (info, lbl)
396 dynamicLinkerLabelInfo _ = Nothing
398 -- Position independent code
400 mkPicBaseLabel :: CLabel
401 mkPicBaseLabel = PicBaseLabel
403 mkDeadStripPreventer :: CLabel -> CLabel
404 mkDeadStripPreventer lbl = DeadStripPreventer lbl
406 -- -----------------------------------------------------------------------------
407 -- Converting between info labels and entry/ret labels.
409 infoLblToEntryLbl :: CLabel -> CLabel
410 infoLblToEntryLbl (IdLabel n InfoTable) = IdLabel n Entry
411 infoLblToEntryLbl (IdLabel n ConInfoTable) = IdLabel n ConEntry
412 infoLblToEntryLbl (IdLabel n StaticInfoTable) = IdLabel n StaticConEntry
413 infoLblToEntryLbl (CaseLabel n CaseReturnInfo) = CaseLabel n CaseReturnPt
414 infoLblToEntryLbl (RtsLabel (RtsInfo s)) = RtsLabel (RtsEntry s)
415 infoLblToEntryLbl (RtsLabel (RtsRetInfo s)) = RtsLabel (RtsRet s)
416 infoLblToEntryLbl (RtsLabel (RtsInfoFS s)) = RtsLabel (RtsEntryFS s)
417 infoLblToEntryLbl (RtsLabel (RtsRetInfoFS s)) = RtsLabel (RtsRetFS s)
418 infoLblToEntryLbl _ = panic "CLabel.infoLblToEntryLbl"
420 entryLblToInfoLbl :: CLabel -> CLabel
421 entryLblToInfoLbl (IdLabel n Entry) = IdLabel n InfoTable
422 entryLblToInfoLbl (IdLabel n ConEntry) = IdLabel n ConInfoTable
423 entryLblToInfoLbl (IdLabel n StaticConEntry) = IdLabel n StaticInfoTable
424 entryLblToInfoLbl (CaseLabel n CaseReturnPt) = CaseLabel n CaseReturnInfo
425 entryLblToInfoLbl (RtsLabel (RtsEntry s)) = RtsLabel (RtsInfo s)
426 entryLblToInfoLbl (RtsLabel (RtsRet s)) = RtsLabel (RtsRetInfo s)
427 entryLblToInfoLbl (RtsLabel (RtsEntryFS s)) = RtsLabel (RtsInfoFS s)
428 entryLblToInfoLbl (RtsLabel (RtsRetFS s)) = RtsLabel (RtsRetInfoFS s)
429 entryLblToInfoLbl l = pprPanic "CLabel.entryLblToInfoLbl" (pprCLabel l)
431 -- -----------------------------------------------------------------------------
432 -- Does a CLabel need declaring before use or not?
434 needsCDecl :: CLabel -> Bool
435 -- False <=> it's pre-declared; don't bother
436 -- don't bother declaring SRT & Bitmap labels, we always make sure
437 -- they are defined before use.
438 needsCDecl (IdLabel _ SRT) = False
439 needsCDecl (LargeSRTLabel _) = False
440 needsCDecl (LargeBitmapLabel _) = False
441 needsCDecl (IdLabel _ _) = True
442 needsCDecl (CaseLabel _ _) = True
443 needsCDecl (ModuleInitLabel _ _) = True
444 needsCDecl (PlainModuleInitLabel _) = True
445 needsCDecl ModuleRegdLabel = False
447 needsCDecl (StringLitLabel _) = False
448 needsCDecl (AsmTempLabel _) = False
449 needsCDecl (RtsLabel _) = False
450 needsCDecl (ForeignLabel _ _ _) = False
451 needsCDecl (CC_Label _) = True
452 needsCDecl (CCS_Label _) = True
453 needsCDecl (HpcTicksLabel _) = True
454 needsCDecl HpcModuleNameLabel = False
456 -- Whether the label is an assembler temporary:
458 isAsmTemp :: CLabel -> Bool -- is a local temporary for native code generation
459 isAsmTemp (AsmTempLabel _) = True
462 maybeAsmTemp :: CLabel -> Maybe Unique
463 maybeAsmTemp (AsmTempLabel uq) = Just uq
464 maybeAsmTemp _ = Nothing
466 -- -----------------------------------------------------------------------------
467 -- Is a CLabel visible outside this object file or not?
469 -- From the point of view of the code generator, a name is
470 -- externally visible if it has to be declared as exported
471 -- in the .o file's symbol table; that is, made non-static.
473 externallyVisibleCLabel :: CLabel -> Bool -- not C "static"
474 externallyVisibleCLabel (CaseLabel _ _) = False
475 externallyVisibleCLabel (StringLitLabel _) = False
476 externallyVisibleCLabel (AsmTempLabel _) = False
477 externallyVisibleCLabel (ModuleInitLabel _ _) = True
478 externallyVisibleCLabel (PlainModuleInitLabel _)= True
479 externallyVisibleCLabel ModuleRegdLabel = False
480 externallyVisibleCLabel (RtsLabel _) = True
481 externallyVisibleCLabel (ForeignLabel _ _ _) = True
482 externallyVisibleCLabel (IdLabel name _) = isExternalName name
483 externallyVisibleCLabel (CC_Label _) = True
484 externallyVisibleCLabel (CCS_Label _) = True
485 externallyVisibleCLabel (DynamicLinkerLabel _ _) = False
486 externallyVisibleCLabel (HpcTicksLabel _) = True
487 externallyVisibleCLabel HpcModuleNameLabel = False
488 externallyVisibleCLabel (LargeBitmapLabel _) = False
489 externallyVisibleCLabel (LargeSRTLabel _) = False
491 -- -----------------------------------------------------------------------------
492 -- Finding the "type" of a CLabel
494 -- For generating correct types in label declarations:
500 labelType :: CLabel -> CLabelType
501 labelType (RtsLabel (RtsSelectorInfoTable _ _)) = DataLabel
502 labelType (RtsLabel (RtsApInfoTable _ _)) = DataLabel
503 labelType (RtsLabel (RtsData _)) = DataLabel
504 labelType (RtsLabel (RtsCode _)) = CodeLabel
505 labelType (RtsLabel (RtsInfo _)) = DataLabel
506 labelType (RtsLabel (RtsEntry _)) = CodeLabel
507 labelType (RtsLabel (RtsRetInfo _)) = DataLabel
508 labelType (RtsLabel (RtsRet _)) = CodeLabel
509 labelType (RtsLabel (RtsDataFS _)) = DataLabel
510 labelType (RtsLabel (RtsCodeFS _)) = CodeLabel
511 labelType (RtsLabel (RtsInfoFS _)) = DataLabel
512 labelType (RtsLabel (RtsEntryFS _)) = CodeLabel
513 labelType (RtsLabel (RtsRetInfoFS _)) = DataLabel
514 labelType (RtsLabel (RtsRetFS _)) = CodeLabel
515 labelType (RtsLabel (RtsApFast _)) = CodeLabel
516 labelType (CaseLabel _ CaseReturnInfo) = DataLabel
517 labelType (CaseLabel _ _) = CodeLabel
518 labelType (ModuleInitLabel _ _) = CodeLabel
519 labelType (PlainModuleInitLabel _) = CodeLabel
520 labelType (LargeSRTLabel _) = DataLabel
521 labelType (LargeBitmapLabel _) = DataLabel
523 labelType (IdLabel _ info) = idInfoLabelType info
524 labelType _ = DataLabel
526 idInfoLabelType info =
528 InfoTable -> DataLabel
530 ConInfoTable -> DataLabel
531 StaticInfoTable -> DataLabel
532 ClosureTable -> DataLabel
533 -- krc: aie! a ticky counter label is data
534 RednCounts -> DataLabel
538 -- -----------------------------------------------------------------------------
539 -- Does a CLabel need dynamic linkage?
541 -- When referring to data in code, we need to know whether
542 -- that data resides in a DLL or not. [Win32 only.]
543 -- @labelDynamic@ returns @True@ if the label is located
544 -- in a DLL, be it a data reference or not.
546 labelDynamic :: PackageId -> CLabel -> Bool
547 labelDynamic this_pkg lbl =
549 RtsLabel _ -> not opt_Static && (this_pkg /= rtsPackageId) -- i.e., is the RTS in a DLL or not?
550 IdLabel n k -> isDllName this_pkg n
551 #if mingw32_TARGET_OS
552 ForeignLabel _ _ d -> d
554 -- On Mac OS X and on ELF platforms, false positives are OK,
555 -- so we claim that all foreign imports come from dynamic libraries
556 ForeignLabel _ _ _ -> True
558 ModuleInitLabel m _ -> not opt_Static && this_pkg /= (modulePackageId m)
559 PlainModuleInitLabel m -> not opt_Static && this_pkg /= (modulePackageId m)
561 -- Note that DynamicLinkerLabels do NOT require dynamic linking themselves.
565 OLD?: These GRAN functions are needed for spitting out GRAN_FETCH() at the
566 right places. It is used to detect when the abstractC statement of an
567 CCodeBlock actually contains the code for a slow entry point. -- HWL
569 We need at least @Eq@ for @CLabels@, because we want to avoid
570 duplicate declarations in generating C (see @labelSeenTE@ in
574 -----------------------------------------------------------------------------
575 -- Printing out CLabels.
582 where <name> is <Module>_<name> for external names and <unique> for
583 internal names. <type> is one of the following:
586 srt Static reference table
587 srtd Static reference table descriptor
588 entry Entry code (function, closure)
589 slow Slow entry code (if any)
590 ret Direct return address
592 <n>_alt Case alternative (tag n)
593 dflt Default case alternative
594 btm Large bitmap vector
595 closure Static closure
596 con_entry Dynamic Constructor entry code
597 con_info Dynamic Constructor info table
598 static_entry Static Constructor entry code
599 static_info Static Constructor info table
600 sel_info Selector info table
601 sel_entry Selector entry code
603 ccs Cost centre stack
605 Many of these distinctions are only for documentation reasons. For
606 example, _ret is only distinguished from _entry to make it easy to
607 tell whether a code fragment is a return point or a closure/function
611 instance Outputable CLabel where
614 pprCLabel :: CLabel -> SDoc
616 #if ! OMIT_NATIVE_CODEGEN
617 pprCLabel (AsmTempLabel u)
618 = getPprStyle $ \ sty ->
620 ptext asmTempLabelPrefix <> pprUnique u
622 char '_' <> pprUnique u
624 pprCLabel (DynamicLinkerLabel info lbl)
625 = pprDynamicLinkerAsmLabel info lbl
627 pprCLabel PicBaseLabel
630 pprCLabel (DeadStripPreventer lbl)
631 = pprCLabel lbl <> ptext SLIT("_dsp")
635 #if ! OMIT_NATIVE_CODEGEN
636 getPprStyle $ \ sty ->
638 maybe_underscore (pprAsmCLbl lbl)
644 | underscorePrefix = pp_cSEP <> doc
647 #ifdef mingw32_TARGET_OS
648 -- In asm mode, we need to put the suffix on a stdcall ForeignLabel.
649 -- (The C compiler does this itself).
650 pprAsmCLbl (ForeignLabel fs (Just sz) _)
651 = ftext fs <> char '@' <> int sz
656 pprCLbl (StringLitLabel u)
657 = pprUnique u <> ptext SLIT("_str")
659 pprCLbl (CaseLabel u CaseReturnPt)
660 = hcat [pprUnique u, ptext SLIT("_ret")]
661 pprCLbl (CaseLabel u CaseReturnInfo)
662 = hcat [pprUnique u, ptext SLIT("_info")]
663 pprCLbl (CaseLabel u (CaseAlt tag))
664 = hcat [pprUnique u, pp_cSEP, int tag, ptext SLIT("_alt")]
665 pprCLbl (CaseLabel u CaseDefault)
666 = hcat [pprUnique u, ptext SLIT("_dflt")]
668 pprCLbl (LargeSRTLabel u) = pprUnique u <> pp_cSEP <> ptext SLIT("srtd")
669 pprCLbl (LargeBitmapLabel u) = text "b" <> pprUnique u <> pp_cSEP <> ptext SLIT("btm")
670 -- Some bitsmaps for tuple constructors have a numeric tag (e.g. '7')
671 -- until that gets resolved we'll just force them to start
672 -- with a letter so the label will be legal assmbly code.
675 pprCLbl (RtsLabel (RtsCode str)) = ptext str
676 pprCLbl (RtsLabel (RtsData str)) = ptext str
677 pprCLbl (RtsLabel (RtsCodeFS str)) = ftext str
678 pprCLbl (RtsLabel (RtsDataFS str)) = ftext str
680 pprCLbl (RtsLabel (RtsApFast str)) = ptext str <> ptext SLIT("_fast")
682 pprCLbl (RtsLabel (RtsSelectorInfoTable upd_reqd offset))
683 = hcat [ptext SLIT("stg_sel_"), text (show offset),
685 then SLIT("_upd_info")
686 else SLIT("_noupd_info"))
689 pprCLbl (RtsLabel (RtsSelectorEntry upd_reqd offset))
690 = hcat [ptext SLIT("stg_sel_"), text (show offset),
692 then SLIT("_upd_entry")
693 else SLIT("_noupd_entry"))
696 pprCLbl (RtsLabel (RtsApInfoTable upd_reqd arity))
697 = hcat [ptext SLIT("stg_ap_"), text (show arity),
699 then SLIT("_upd_info")
700 else SLIT("_noupd_info"))
703 pprCLbl (RtsLabel (RtsApEntry upd_reqd arity))
704 = hcat [ptext SLIT("stg_ap_"), text (show arity),
706 then SLIT("_upd_entry")
707 else SLIT("_noupd_entry"))
710 pprCLbl (RtsLabel (RtsInfo fs))
711 = ptext fs <> ptext SLIT("_info")
713 pprCLbl (RtsLabel (RtsEntry fs))
714 = ptext fs <> ptext SLIT("_entry")
716 pprCLbl (RtsLabel (RtsRetInfo fs))
717 = ptext fs <> ptext SLIT("_info")
719 pprCLbl (RtsLabel (RtsRet fs))
720 = ptext fs <> ptext SLIT("_ret")
722 pprCLbl (RtsLabel (RtsInfoFS fs))
723 = ftext fs <> ptext SLIT("_info")
725 pprCLbl (RtsLabel (RtsEntryFS fs))
726 = ftext fs <> ptext SLIT("_entry")
728 pprCLbl (RtsLabel (RtsRetInfoFS fs))
729 = ftext fs <> ptext SLIT("_info")
731 pprCLbl (RtsLabel (RtsRetFS fs))
732 = ftext fs <> ptext SLIT("_ret")
734 pprCLbl (RtsLabel (RtsPrimOp primop))
735 = ppr primop <> ptext SLIT("_fast")
737 pprCLbl (RtsLabel (RtsSlowTickyCtr pat))
738 = ptext SLIT("SLOW_CALL_") <> text pat <> ptext SLIT("_ctr")
740 pprCLbl ModuleRegdLabel
741 = ptext SLIT("_module_registered")
743 pprCLbl (ForeignLabel str _ _)
746 pprCLbl (IdLabel name flavor) = ppr name <> ppIdFlavor flavor
748 pprCLbl (CC_Label cc) = ppr cc
749 pprCLbl (CCS_Label ccs) = ppr ccs
751 pprCLbl (ModuleInitLabel mod way)
752 = ptext SLIT("__stginit_") <> ppr mod
753 <> char '_' <> text way
754 pprCLbl (PlainModuleInitLabel mod)
755 = ptext SLIT("__stginit_") <> ppr mod
757 pprCLbl (HpcTicksLabel mod)
758 = ptext SLIT("_hpc_tickboxes_") <> ppr mod <> ptext SLIT("_hpc")
760 pprCLbl HpcModuleNameLabel
761 = ptext SLIT("_hpc_module_name_str")
763 ppIdFlavor :: IdLabelInfo -> SDoc
764 ppIdFlavor x = pp_cSEP <>
766 Closure -> ptext SLIT("closure")
767 SRT -> ptext SLIT("srt")
768 InfoTable -> ptext SLIT("info")
769 Entry -> ptext SLIT("entry")
770 Slow -> ptext SLIT("slow")
771 RednCounts -> ptext SLIT("ct")
772 ConEntry -> ptext SLIT("con_entry")
773 ConInfoTable -> ptext SLIT("con_info")
774 StaticConEntry -> ptext SLIT("static_entry")
775 StaticInfoTable -> ptext SLIT("static_info")
776 ClosureTable -> ptext SLIT("closure_tbl")
782 -- -----------------------------------------------------------------------------
783 -- Machine-dependent knowledge about labels.
785 underscorePrefix :: Bool -- leading underscore on assembler labels?
786 underscorePrefix = (cLeadingUnderscore == "YES")
788 asmTempLabelPrefix :: LitString -- for formatting labels
791 {- The alpha assembler likes temporary labels to look like $L123
792 instead of L123. (Don't toss the L, because then Lf28
796 #elif darwin_TARGET_OS
802 pprDynamicLinkerAsmLabel :: DynamicLinkerLabelInfo -> CLabel -> SDoc
804 #if x86_64_TARGET_ARCH && darwin_TARGET_OS
805 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
806 = pprCLabel lbl <> text "@GOTPCREL"
807 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
809 pprDynamicLinkerAsmLabel _ _
810 = panic "pprDynamicLinkerAsmLabel"
811 #elif darwin_TARGET_OS
812 pprDynamicLinkerAsmLabel CodeStub lbl
813 = char 'L' <> pprCLabel lbl <> text "$stub"
814 pprDynamicLinkerAsmLabel SymbolPtr lbl
815 = char 'L' <> pprCLabel lbl <> text "$non_lazy_ptr"
816 pprDynamicLinkerAsmLabel _ _
817 = panic "pprDynamicLinkerAsmLabel"
818 #elif powerpc_TARGET_ARCH && linux_TARGET_OS
819 pprDynamicLinkerAsmLabel CodeStub lbl
820 = pprCLabel lbl <> text "@plt"
821 pprDynamicLinkerAsmLabel SymbolPtr lbl
822 = text ".LC_" <> pprCLabel lbl
823 pprDynamicLinkerAsmLabel _ _
824 = panic "pprDynamicLinkerAsmLabel"
825 #elif x86_64_TARGET_ARCH && linux_TARGET_OS
826 pprDynamicLinkerAsmLabel CodeStub lbl
827 = pprCLabel lbl <> text "@plt"
828 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
829 = pprCLabel lbl <> text "@gotpcrel"
830 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
832 pprDynamicLinkerAsmLabel SymbolPtr lbl
833 = text ".LC_" <> pprCLabel lbl
834 #elif linux_TARGET_OS
835 pprDynamicLinkerAsmLabel CodeStub lbl
836 = pprCLabel lbl <> text "@plt"
837 pprDynamicLinkerAsmLabel SymbolPtr lbl
838 = text ".LC_" <> pprCLabel lbl
839 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
840 = pprCLabel lbl <> text "@got"
841 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
842 = pprCLabel lbl <> text "@gotoff"
843 #elif mingw32_TARGET_OS
844 pprDynamicLinkerAsmLabel SymbolPtr lbl
845 = text "__imp_" <> pprCLabel lbl
846 pprDynamicLinkerAsmLabel _ _
847 = panic "pprDynamicLinkerAsmLabel"
849 pprDynamicLinkerAsmLabel _ _
850 = panic "pprDynamicLinkerAsmLabel"