Refactoring: reduce usage of mkConInfo, with a view to killing it
[ghc.git] / compiler / cmm / CLabel.hs
1 {-# OPTIONS -w #-}
2 -- The above warning supression flag is a temporary kludge.
3 -- While working on this module you are encouraged to remove it and fix
4 -- any warnings in the module. See
5 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
6 -- for details
7
8 -----------------------------------------------------------------------------
9 --
10 -- Object-file symbols (called CLabel for histerical raisins).
11 --
12 -- (c) The University of Glasgow 2004-2006
13 --
14 -----------------------------------------------------------------------------
15
16 module CLabel (
17 CLabel, -- abstract type
18 ForeignLabelSource(..),
19 pprDebugCLabel,
20
21 mkClosureLabel,
22 mkSRTLabel,
23 mkInfoTableLabel,
24 mkEntryLabel,
25 mkSlowEntryLabel, slowEntryFromInfoLabel,
26 mkConEntryLabel,
27 mkStaticConEntryLabel,
28 mkRednCountsLabel,
29 mkConInfoTableLabel,
30 mkStaticInfoTableLabel,
31 mkLargeSRTLabel,
32 mkApEntryLabel,
33 mkApInfoTableLabel,
34 mkClosureTableLabel,
35
36 mkLocalClosureLabel,
37 mkLocalInfoTableLabel,
38 mkLocalEntryLabel,
39 mkLocalConEntryLabel,
40 mkLocalStaticConEntryLabel,
41 mkLocalConInfoTableLabel,
42 mkLocalStaticInfoTableLabel,
43 mkLocalClosureTableLabel,
44
45 mkReturnPtLabel,
46 mkReturnInfoLabel,
47 mkAltLabel,
48 mkDefaultLabel,
49 mkBitmapLabel,
50 mkStringLitLabel,
51
52 mkAsmTempLabel,
53
54 mkPlainModuleInitLabel,
55
56 mkSplitMarkerLabel,
57 mkDirty_MUT_VAR_Label,
58 mkUpdInfoLabel,
59 mkBHUpdInfoLabel,
60 mkIndStaticInfoLabel,
61 mkMainCapabilityLabel,
62 mkMAP_FROZEN_infoLabel,
63 mkMAP_DIRTY_infoLabel,
64 mkEMPTY_MVAR_infoLabel,
65
66 mkTopTickyCtrLabel,
67 mkCAFBlackHoleInfoTableLabel,
68 mkCAFBlackHoleEntryLabel,
69 mkRtsPrimOpLabel,
70 mkRtsSlowTickyCtrLabel,
71
72 mkSelectorInfoLabel,
73 mkSelectorEntryLabel,
74
75 mkCmmInfoLabel,
76 mkCmmEntryLabel,
77 mkCmmRetInfoLabel,
78 mkCmmRetLabel,
79 mkCmmCodeLabel,
80 mkCmmDataLabel,
81 mkCmmGcPtrLabel,
82
83 mkRtsApFastLabel,
84
85 mkPrimCallLabel,
86
87 mkForeignLabel,
88 addLabelSize,
89 foreignLabelStdcallInfo,
90
91 mkCCLabel, mkCCSLabel,
92
93 DynamicLinkerLabelInfo(..),
94 mkDynamicLinkerLabel,
95 dynamicLinkerLabelInfo,
96
97 mkPicBaseLabel,
98 mkDeadStripPreventer,
99
100 mkHpcTicksLabel,
101
102 hasCAF,
103 cvtToClosureLbl,
104 needsCDecl, isAsmTemp, maybeAsmTemp, externallyVisibleCLabel,
105 isMathFun,
106 isCFunctionLabel, isGcPtrLabel, labelDynamic,
107 infoLblToEntryLbl, entryLblToInfoLbl,
108
109 pprCLabel
110 ) where
111
112 #include "HsVersions.h"
113
114 import IdInfo
115 import StaticFlags
116 import BasicTypes
117 import Literal
118 import Packages
119 import DataCon
120 import PackageConfig
121 import Module
122 import Name
123 import Unique
124 import PrimOp
125 import Config
126 import CostCentre
127 import Outputable
128 import FastString
129 import DynFlags
130 import UniqSet
131
132 -- -----------------------------------------------------------------------------
133 -- The CLabel type
134
135 {-
136 | CLabel is an abstract type that supports the following operations:
137
138 - Pretty printing
139
140 - In a C file, does it need to be declared before use? (i.e. is it
141 guaranteed to be already in scope in the places we need to refer to it?)
142
143 - If it needs to be declared, what type (code or data) should it be
144 declared to have?
145
146 - Is it visible outside this object file or not?
147
148 - Is it "dynamic" (see details below)
149
150 - Eq and Ord, so that we can make sets of CLabels (currently only
151 used in outputting C as far as I can tell, to avoid generating
152 more than one declaration for any given label).
153
154 - Converting an info table label into an entry label.
155 -}
156
157 data CLabel
158 = -- | A label related to the definition of a particular Id or Con in a .hs file.
159 IdLabel
160 Name
161 CafInfo
162 IdLabelInfo -- encodes the suffix of the label
163
164 -- | A label from a .cmm file that is not associated with a .hs level Id.
165 | CmmLabel
166 PackageId -- what package the label belongs to.
167 FastString -- identifier giving the prefix of the label
168 CmmLabelInfo -- encodes the suffix of the label
169
170 -- | A label with a baked-in \/ algorithmically generated name that definitely
171 -- comes from the RTS. The code for it must compile into libHSrts.a \/ libHSrts.so
172 -- If it doesn't have an algorithmically generated name then use a CmmLabel
173 -- instead and give it an appropriate PackageId argument.
174 | RtsLabel
175 RtsLabelInfo
176
177 -- | A 'C' (or otherwise foreign) label.
178 --
179 | ForeignLabel
180 FastString -- name of the imported label.
181
182 (Maybe Int) -- possible '@n' suffix for stdcall functions
183 -- When generating C, the '@n' suffix is omitted, but when
184 -- generating assembler we must add it to the label.
185
186 ForeignLabelSource -- what package the foreign label is in.
187
188 FunctionOrData
189
190 -- | A family of labels related to a particular case expression.
191 | CaseLabel
192 {-# UNPACK #-} !Unique -- Unique says which case expression
193 CaseLabelInfo
194
195 | AsmTempLabel
196 {-# UNPACK #-} !Unique
197
198 | StringLitLabel
199 {-# UNPACK #-} !Unique
200
201 | PlainModuleInitLabel -- without the version & way info
202 Module
203
204 | CC_Label CostCentre
205 | CCS_Label CostCentreStack
206
207
208 -- | These labels are generated and used inside the NCG only.
209 -- They are special variants of a label used for dynamic linking
210 -- see module PositionIndependentCode for details.
211 | DynamicLinkerLabel DynamicLinkerLabelInfo CLabel
212
213 -- | This label is generated and used inside the NCG only.
214 -- It is used as a base for PIC calculations on some platforms.
215 -- It takes the form of a local numeric assembler label '1'; and
216 -- is pretty-printed as 1b, referring to the previous definition
217 -- of 1: in the assembler source file.
218 | PicBaseLabel
219
220 -- | A label before an info table to prevent excessive dead-stripping on darwin
221 | DeadStripPreventer CLabel
222
223
224 -- | Per-module table of tick locations
225 | HpcTicksLabel Module
226
227 -- | Label of an StgLargeSRT
228 | LargeSRTLabel
229 {-# UNPACK #-} !Unique
230
231 -- | A bitmap (function or case return)
232 | LargeBitmapLabel
233 {-# UNPACK #-} !Unique
234
235 deriving (Eq, Ord)
236
237
238 -- | Record where a foreign label is stored.
239 data ForeignLabelSource
240
241 -- | Label is in a named package
242 = ForeignLabelInPackage PackageId
243
244 -- | Label is in some external, system package that doesn't also
245 -- contain compiled Haskell code, and is not associated with any .hi files.
246 -- We don't have to worry about Haskell code being inlined from
247 -- external packages. It is safe to treat the RTS package as "external".
248 | ForeignLabelInExternalPackage
249
250 -- | Label is in the package currenly being compiled.
251 -- This is only used for creating hacky tmp labels during code generation.
252 -- Don't use it in any code that might be inlined across a package boundary
253 -- (ie, core code) else the information will be wrong relative to the
254 -- destination module.
255 | ForeignLabelInThisPackage
256
257 deriving (Eq, Ord)
258
259
260 -- | For debugging problems with the CLabel representation.
261 -- We can't make a Show instance for CLabel because lots of its components don't have instances.
262 -- The regular Outputable instance only shows the label name, and not its other info.
263 --
264 pprDebugCLabel :: CLabel -> SDoc
265 pprDebugCLabel lbl
266 = case lbl of
267 IdLabel{} -> ppr lbl <> (parens $ text "IdLabel")
268 CmmLabel pkg name _info
269 -> ppr lbl <> (parens $ text "CmmLabel" <+> ppr pkg)
270
271 RtsLabel{} -> ppr lbl <> (parens $ text "RtsLabel")
272
273 ForeignLabel name mSuffix src funOrData
274 -> ppr lbl <> (parens
275 $ text "ForeignLabel"
276 <+> ppr mSuffix
277 <+> ppr src
278 <+> ppr funOrData)
279
280 _ -> ppr lbl <> (parens $ text "other CLabel)")
281
282
283 -- True if a local IdLabel that we won't mark as exported
284 type IsLocal = Bool
285
286 data IdLabelInfo
287 = Closure -- ^ Label for closure
288 | SRT -- ^ Static reference table
289 | InfoTable -- ^ Info tables for closures; always read-only
290 | Entry -- ^ Entry point
291 | Slow -- ^ Slow entry point
292
293 | LocalInfoTable -- ^ Like InfoTable but not externally visible
294 | LocalEntry -- ^ Like Entry but not externally visible
295
296 | RednCounts -- ^ Label of place to keep Ticky-ticky info for this Id
297
298 | ConEntry -- ^ Constructor entry point
299 | ConInfoTable -- ^ Corresponding info table
300 | StaticConEntry -- ^ Static constructor entry point
301 | StaticInfoTable -- ^ Corresponding info table
302
303 | ClosureTable -- ^ Table of closures for Enum tycons
304
305 deriving (Eq, Ord)
306
307
308 data CaseLabelInfo
309 = CaseReturnPt
310 | CaseReturnInfo
311 | CaseAlt ConTag
312 | CaseDefault
313 deriving (Eq, Ord)
314
315
316 data RtsLabelInfo
317 = RtsSelectorInfoTable Bool{-updatable-} Int{-offset-} -- ^ Selector thunks
318 | RtsSelectorEntry Bool{-updatable-} Int{-offset-}
319
320 | RtsApInfoTable Bool{-updatable-} Int{-arity-} -- ^ AP thunks
321 | RtsApEntry Bool{-updatable-} Int{-arity-}
322
323 | RtsPrimOp PrimOp
324 | RtsApFast FastString -- ^ _fast versions of generic apply
325 | RtsSlowTickyCtr String
326
327 deriving (Eq, Ord)
328 -- NOTE: Eq on LitString compares the pointer only, so this isn't
329 -- a real equality.
330
331
332 -- | What type of Cmm label we're dealing with.
333 -- Determines the suffix appended to the name when a CLabel.CmmLabel
334 -- is pretty printed.
335 data CmmLabelInfo
336 = CmmInfo -- ^ misc rts info tabless, suffix _info
337 | CmmEntry -- ^ misc rts entry points, suffix _entry
338 | CmmRetInfo -- ^ misc rts ret info tables, suffix _info
339 | CmmRet -- ^ misc rts return points, suffix _ret
340 | CmmData -- ^ misc rts data bits, eg CHARLIKE_closure
341 | CmmCode -- ^ misc rts code
342 | CmmGcPtr -- ^ GcPtrs eg CHARLIKE_closure
343 | CmmPrimCall -- ^ a prim call to some hand written Cmm code
344 deriving (Eq, Ord)
345
346 data DynamicLinkerLabelInfo
347 = CodeStub -- MachO: Lfoo$stub, ELF: foo@plt
348 | SymbolPtr -- MachO: Lfoo$non_lazy_ptr, Windows: __imp_foo
349 | GotSymbolPtr -- ELF: foo@got
350 | GotSymbolOffset -- ELF: foo@gotoff
351
352 deriving (Eq, Ord)
353
354
355 -- -----------------------------------------------------------------------------
356 -- Constructing CLabels
357 -- -----------------------------------------------------------------------------
358
359 -- Constructing IdLabels
360 -- These are always local:
361 mkSlowEntryLabel name c = IdLabel name c Slow
362 slowEntryFromInfoLabel (IdLabel n c _) = IdLabel n c Slow
363
364 mkSRTLabel name c = IdLabel name c SRT
365 mkRednCountsLabel name c = IdLabel name c RednCounts
366
367 -- These have local & (possibly) external variants:
368 mkLocalClosureLabel name c = IdLabel name c Closure
369 mkLocalInfoTableLabel name c = IdLabel name c LocalInfoTable
370 mkLocalEntryLabel name c = IdLabel name c LocalEntry
371 mkLocalClosureTableLabel name c = IdLabel name c ClosureTable
372
373 mkClosureLabel name c = IdLabel name c Closure
374 mkInfoTableLabel name c = IdLabel name c InfoTable
375 mkEntryLabel name c = IdLabel name c Entry
376 mkClosureTableLabel name c = IdLabel name c ClosureTable
377 mkLocalConInfoTableLabel c con = IdLabel con c ConInfoTable
378 mkLocalConEntryLabel c con = IdLabel con c ConEntry
379 mkLocalStaticInfoTableLabel c con = IdLabel con c StaticInfoTable
380 mkLocalStaticConEntryLabel c con = IdLabel con c StaticConEntry
381 mkConInfoTableLabel name c = IdLabel name c ConInfoTable
382 mkStaticInfoTableLabel name c = IdLabel name c StaticInfoTable
383
384 mkConEntryLabel name c = IdLabel name c ConEntry
385 mkStaticConEntryLabel name c = IdLabel name c StaticConEntry
386
387 -- Constructing Cmm Labels
388 mkSplitMarkerLabel = CmmLabel rtsPackageId (fsLit "__stg_split_marker") CmmCode
389 mkDirty_MUT_VAR_Label = CmmLabel rtsPackageId (fsLit "dirty_MUT_VAR") CmmCode
390 mkUpdInfoLabel = CmmLabel rtsPackageId (fsLit "stg_upd_frame") CmmInfo
391 mkBHUpdInfoLabel = CmmLabel rtsPackageId (fsLit "stg_bh_upd_frame" ) CmmInfo
392 mkIndStaticInfoLabel = CmmLabel rtsPackageId (fsLit "stg_IND_STATIC") CmmInfo
393 mkMainCapabilityLabel = CmmLabel rtsPackageId (fsLit "MainCapability") CmmData
394 mkMAP_FROZEN_infoLabel = CmmLabel rtsPackageId (fsLit "stg_MUT_ARR_PTRS_FROZEN0") CmmInfo
395 mkMAP_DIRTY_infoLabel = CmmLabel rtsPackageId (fsLit "stg_MUT_ARR_PTRS_DIRTY") CmmInfo
396 mkEMPTY_MVAR_infoLabel = CmmLabel rtsPackageId (fsLit "stg_EMPTY_MVAR") CmmInfo
397 mkTopTickyCtrLabel = CmmLabel rtsPackageId (fsLit "top_ct") CmmData
398 mkCAFBlackHoleInfoTableLabel = CmmLabel rtsPackageId (fsLit "stg_CAF_BLACKHOLE") CmmInfo
399 mkCAFBlackHoleEntryLabel = CmmLabel rtsPackageId (fsLit "stg_CAF_BLACKHOLE") CmmEntry
400
401 -----
402 mkCmmInfoLabel, mkCmmEntryLabel, mkCmmRetInfoLabel, mkCmmRetLabel,
403 mkCmmCodeLabel, mkCmmDataLabel, mkCmmGcPtrLabel
404 :: PackageId -> FastString -> CLabel
405
406 mkCmmInfoLabel pkg str = CmmLabel pkg str CmmInfo
407 mkCmmEntryLabel pkg str = CmmLabel pkg str CmmEntry
408 mkCmmRetInfoLabel pkg str = CmmLabel pkg str CmmRetInfo
409 mkCmmRetLabel pkg str = CmmLabel pkg str CmmRet
410 mkCmmCodeLabel pkg str = CmmLabel pkg str CmmCode
411 mkCmmDataLabel pkg str = CmmLabel pkg str CmmData
412 mkCmmGcPtrLabel pkg str = CmmLabel pkg str CmmGcPtr
413
414
415 -- Constructing RtsLabels
416 mkRtsPrimOpLabel primop = RtsLabel (RtsPrimOp primop)
417
418 mkSelectorInfoLabel upd off = RtsLabel (RtsSelectorInfoTable upd off)
419 mkSelectorEntryLabel upd off = RtsLabel (RtsSelectorEntry upd off)
420
421 mkApInfoTableLabel upd off = RtsLabel (RtsApInfoTable upd off)
422 mkApEntryLabel upd off = RtsLabel (RtsApEntry upd off)
423
424
425 -- A call to some primitive hand written Cmm code
426 mkPrimCallLabel :: PrimCall -> CLabel
427 mkPrimCallLabel (PrimCall str pkg)
428 = CmmLabel pkg str CmmPrimCall
429
430
431 -- Constructing ForeignLabels
432
433 -- | Make a foreign label
434 mkForeignLabel
435 :: FastString -- name
436 -> Maybe Int -- size prefix
437 -> ForeignLabelSource -- what package it's in
438 -> FunctionOrData
439 -> CLabel
440
441 mkForeignLabel str mb_sz src fod
442 = ForeignLabel str mb_sz src fod
443
444
445 -- | Update the label size field in a ForeignLabel
446 addLabelSize :: CLabel -> Int -> CLabel
447 addLabelSize (ForeignLabel str _ src fod) sz
448 = ForeignLabel str (Just sz) src fod
449 addLabelSize label _
450 = label
451
452 -- | Get the label size field from a ForeignLabel
453 foreignLabelStdcallInfo :: CLabel -> Maybe Int
454 foreignLabelStdcallInfo (ForeignLabel _ info _ _) = info
455 foreignLabelStdcallInfo _lbl = Nothing
456
457
458 -- Constructing Large*Labels
459 mkLargeSRTLabel uniq = LargeSRTLabel uniq
460 mkBitmapLabel uniq = LargeBitmapLabel uniq
461
462
463 -- Constructin CaseLabels
464 mkReturnPtLabel uniq = CaseLabel uniq CaseReturnPt
465 mkReturnInfoLabel uniq = CaseLabel uniq CaseReturnInfo
466 mkAltLabel uniq tag = CaseLabel uniq (CaseAlt tag)
467 mkDefaultLabel uniq = CaseLabel uniq CaseDefault
468
469 -- Constructing Cost Center Labels
470 mkCCLabel cc = CC_Label cc
471 mkCCSLabel ccs = CCS_Label ccs
472
473 mkRtsApFastLabel str = RtsLabel (RtsApFast str)
474
475 mkRtsSlowTickyCtrLabel :: String -> CLabel
476 mkRtsSlowTickyCtrLabel pat = RtsLabel (RtsSlowTickyCtr pat)
477
478
479 -- Constructing Code Coverage Labels
480 mkHpcTicksLabel = HpcTicksLabel
481
482
483 -- Constructing labels used for dynamic linking
484 mkDynamicLinkerLabel :: DynamicLinkerLabelInfo -> CLabel -> CLabel
485 mkDynamicLinkerLabel = DynamicLinkerLabel
486
487 dynamicLinkerLabelInfo :: CLabel -> Maybe (DynamicLinkerLabelInfo, CLabel)
488 dynamicLinkerLabelInfo (DynamicLinkerLabel info lbl) = Just (info, lbl)
489 dynamicLinkerLabelInfo _ = Nothing
490
491 mkPicBaseLabel :: CLabel
492 mkPicBaseLabel = PicBaseLabel
493
494
495 -- Constructing miscellaneous other labels
496 mkDeadStripPreventer :: CLabel -> CLabel
497 mkDeadStripPreventer lbl = DeadStripPreventer lbl
498
499 mkStringLitLabel :: Unique -> CLabel
500 mkStringLitLabel = StringLitLabel
501
502 mkAsmTempLabel :: Uniquable a => a -> CLabel
503 mkAsmTempLabel a = AsmTempLabel (getUnique a)
504
505 mkPlainModuleInitLabel :: Module -> CLabel
506 mkPlainModuleInitLabel mod = PlainModuleInitLabel mod
507
508 -- -----------------------------------------------------------------------------
509 -- Brutal method of obtaining a closure label
510
511 cvtToClosureLbl (IdLabel n c InfoTable) = IdLabel n c Closure
512 cvtToClosureLbl (IdLabel n c LocalInfoTable) = IdLabel n c Closure -- XXX?
513 cvtToClosureLbl (IdLabel n c Entry) = IdLabel n c Closure
514 cvtToClosureLbl (IdLabel n c LocalEntry) = IdLabel n c Closure -- XXX?
515 cvtToClosureLbl (IdLabel n c ConEntry) = IdLabel n c Closure
516 cvtToClosureLbl (IdLabel n c RednCounts) = IdLabel n c Closure
517 cvtToClosureLbl l@(IdLabel n c Closure) = l
518 cvtToClosureLbl l
519 = pprPanic "cvtToClosureLbl" (pprCLabel l)
520
521 infoLblToEntryLbl :: CLabel -> CLabel
522 infoLblToEntryLbl (IdLabel n c LocalInfoTable) = IdLabel n c LocalEntry
523 infoLblToEntryLbl (IdLabel n c InfoTable) = IdLabel n c Entry
524 infoLblToEntryLbl (IdLabel n c ConInfoTable) = IdLabel n c ConEntry
525 infoLblToEntryLbl (IdLabel n c StaticInfoTable) = IdLabel n c StaticConEntry
526 infoLblToEntryLbl (CaseLabel n CaseReturnInfo) = CaseLabel n CaseReturnPt
527 infoLblToEntryLbl (CmmLabel m str CmmInfo) = CmmLabel m str CmmEntry
528 infoLblToEntryLbl (CmmLabel m str CmmRetInfo) = CmmLabel m str CmmRet
529 infoLblToEntryLbl _
530 = panic "CLabel.infoLblToEntryLbl"
531
532 entryLblToInfoLbl :: CLabel -> CLabel
533 entryLblToInfoLbl (IdLabel n c Entry) = IdLabel n c InfoTable
534 entryLblToInfoLbl (IdLabel n c LocalEntry) = IdLabel n c LocalInfoTable
535 entryLblToInfoLbl (IdLabel n c ConEntry) = IdLabel n c ConInfoTable
536 entryLblToInfoLbl (IdLabel n c StaticConEntry) = IdLabel n c StaticInfoTable
537 entryLblToInfoLbl (CaseLabel n CaseReturnPt) = CaseLabel n CaseReturnInfo
538 entryLblToInfoLbl (CmmLabel m str CmmEntry) = CmmLabel m str CmmInfo
539 entryLblToInfoLbl (CmmLabel m str CmmRet) = CmmLabel m str CmmRetInfo
540 entryLblToInfoLbl l
541 = pprPanic "CLabel.entryLblToInfoLbl" (pprCLabel l)
542
543 -- -----------------------------------------------------------------------------
544 -- Does a CLabel refer to a CAF?
545 hasCAF :: CLabel -> Bool
546 hasCAF (IdLabel _ MayHaveCafRefs _) = True
547 hasCAF _ = False
548
549
550 -- -----------------------------------------------------------------------------
551 -- Does a CLabel need declaring before use or not?
552 --
553 -- See wiki:Commentary/Compiler/Backends/PprC#Prototypes
554
555 needsCDecl :: CLabel -> Bool
556 -- False <=> it's pre-declared; don't bother
557 -- don't bother declaring SRT & Bitmap labels, we always make sure
558 -- they are defined before use.
559 needsCDecl (IdLabel _ _ SRT) = False
560 needsCDecl (LargeSRTLabel _) = False
561 needsCDecl (LargeBitmapLabel _) = False
562 needsCDecl (IdLabel _ _ _) = True
563 needsCDecl (CaseLabel _ _) = True
564 needsCDecl (PlainModuleInitLabel _) = True
565
566 needsCDecl (StringLitLabel _) = False
567 needsCDecl (AsmTempLabel _) = False
568 needsCDecl (RtsLabel _) = False
569
570 needsCDecl (CmmLabel pkgId _ _)
571 -- Prototypes for labels defined in the runtime system are imported
572 -- into HC files via includes/Stg.h.
573 | pkgId == rtsPackageId = False
574
575 -- For other labels we inline one into the HC file directly.
576 | otherwise = True
577
578 needsCDecl l@(ForeignLabel{}) = not (isMathFun l)
579 needsCDecl (CC_Label _) = True
580 needsCDecl (CCS_Label _) = True
581 needsCDecl (HpcTicksLabel _) = True
582
583
584 -- | Check whether a label is a local temporary for native code generation
585 isAsmTemp :: CLabel -> Bool
586 isAsmTemp (AsmTempLabel _) = True
587 isAsmTemp _ = False
588
589
590 -- | If a label is a local temporary used for native code generation
591 -- then return just its unique, otherwise nothing.
592 maybeAsmTemp :: CLabel -> Maybe Unique
593 maybeAsmTemp (AsmTempLabel uq) = Just uq
594 maybeAsmTemp _ = Nothing
595
596
597 -- | Check whether a label corresponds to a C function that has
598 -- a prototype in a system header somehere, or is built-in
599 -- to the C compiler. For these labels we avoid generating our
600 -- own C prototypes.
601 isMathFun :: CLabel -> Bool
602 isMathFun (ForeignLabel fs _ _ _) = fs `elementOfUniqSet` math_funs
603 isMathFun _ = False
604
605 math_funs = mkUniqSet [
606 -- _ISOC99_SOURCE
607 (fsLit "acos"), (fsLit "acosf"), (fsLit "acosh"),
608 (fsLit "acoshf"), (fsLit "acoshl"), (fsLit "acosl"),
609 (fsLit "asin"), (fsLit "asinf"), (fsLit "asinl"),
610 (fsLit "asinh"), (fsLit "asinhf"), (fsLit "asinhl"),
611 (fsLit "atan"), (fsLit "atanf"), (fsLit "atanl"),
612 (fsLit "atan2"), (fsLit "atan2f"), (fsLit "atan2l"),
613 (fsLit "atanh"), (fsLit "atanhf"), (fsLit "atanhl"),
614 (fsLit "cbrt"), (fsLit "cbrtf"), (fsLit "cbrtl"),
615 (fsLit "ceil"), (fsLit "ceilf"), (fsLit "ceill"),
616 (fsLit "copysign"), (fsLit "copysignf"), (fsLit "copysignl"),
617 (fsLit "cos"), (fsLit "cosf"), (fsLit "cosl"),
618 (fsLit "cosh"), (fsLit "coshf"), (fsLit "coshl"),
619 (fsLit "erf"), (fsLit "erff"), (fsLit "erfl"),
620 (fsLit "erfc"), (fsLit "erfcf"), (fsLit "erfcl"),
621 (fsLit "exp"), (fsLit "expf"), (fsLit "expl"),
622 (fsLit "exp2"), (fsLit "exp2f"), (fsLit "exp2l"),
623 (fsLit "expm1"), (fsLit "expm1f"), (fsLit "expm1l"),
624 (fsLit "fabs"), (fsLit "fabsf"), (fsLit "fabsl"),
625 (fsLit "fdim"), (fsLit "fdimf"), (fsLit "fdiml"),
626 (fsLit "floor"), (fsLit "floorf"), (fsLit "floorl"),
627 (fsLit "fma"), (fsLit "fmaf"), (fsLit "fmal"),
628 (fsLit "fmax"), (fsLit "fmaxf"), (fsLit "fmaxl"),
629 (fsLit "fmin"), (fsLit "fminf"), (fsLit "fminl"),
630 (fsLit "fmod"), (fsLit "fmodf"), (fsLit "fmodl"),
631 (fsLit "frexp"), (fsLit "frexpf"), (fsLit "frexpl"),
632 (fsLit "hypot"), (fsLit "hypotf"), (fsLit "hypotl"),
633 (fsLit "ilogb"), (fsLit "ilogbf"), (fsLit "ilogbl"),
634 (fsLit "ldexp"), (fsLit "ldexpf"), (fsLit "ldexpl"),
635 (fsLit "lgamma"), (fsLit "lgammaf"), (fsLit "lgammal"),
636 (fsLit "llrint"), (fsLit "llrintf"), (fsLit "llrintl"),
637 (fsLit "llround"), (fsLit "llroundf"), (fsLit "llroundl"),
638 (fsLit "log"), (fsLit "logf"), (fsLit "logl"),
639 (fsLit "log10l"), (fsLit "log10"), (fsLit "log10f"),
640 (fsLit "log1pl"), (fsLit "log1p"), (fsLit "log1pf"),
641 (fsLit "log2"), (fsLit "log2f"), (fsLit "log2l"),
642 (fsLit "logb"), (fsLit "logbf"), (fsLit "logbl"),
643 (fsLit "lrint"), (fsLit "lrintf"), (fsLit "lrintl"),
644 (fsLit "lround"), (fsLit "lroundf"), (fsLit "lroundl"),
645 (fsLit "modf"), (fsLit "modff"), (fsLit "modfl"),
646 (fsLit "nan"), (fsLit "nanf"), (fsLit "nanl"),
647 (fsLit "nearbyint"), (fsLit "nearbyintf"), (fsLit "nearbyintl"),
648 (fsLit "nextafter"), (fsLit "nextafterf"), (fsLit "nextafterl"),
649 (fsLit "nexttoward"), (fsLit "nexttowardf"), (fsLit "nexttowardl"),
650 (fsLit "pow"), (fsLit "powf"), (fsLit "powl"),
651 (fsLit "remainder"), (fsLit "remainderf"), (fsLit "remainderl"),
652 (fsLit "remquo"), (fsLit "remquof"), (fsLit "remquol"),
653 (fsLit "rint"), (fsLit "rintf"), (fsLit "rintl"),
654 (fsLit "round"), (fsLit "roundf"), (fsLit "roundl"),
655 (fsLit "scalbln"), (fsLit "scalblnf"), (fsLit "scalblnl"),
656 (fsLit "scalbn"), (fsLit "scalbnf"), (fsLit "scalbnl"),
657 (fsLit "sin"), (fsLit "sinf"), (fsLit "sinl"),
658 (fsLit "sinh"), (fsLit "sinhf"), (fsLit "sinhl"),
659 (fsLit "sqrt"), (fsLit "sqrtf"), (fsLit "sqrtl"),
660 (fsLit "tan"), (fsLit "tanf"), (fsLit "tanl"),
661 (fsLit "tanh"), (fsLit "tanhf"), (fsLit "tanhl"),
662 (fsLit "tgamma"), (fsLit "tgammaf"), (fsLit "tgammal"),
663 (fsLit "trunc"), (fsLit "truncf"), (fsLit "truncl"),
664 -- ISO C 99 also defines these function-like macros in math.h:
665 -- fpclassify, isfinite, isinf, isnormal, signbit, isgreater,
666 -- isgreaterequal, isless, islessequal, islessgreater, isunordered
667
668 -- additional symbols from _BSD_SOURCE
669 (fsLit "drem"), (fsLit "dremf"), (fsLit "dreml"),
670 (fsLit "finite"), (fsLit "finitef"), (fsLit "finitel"),
671 (fsLit "gamma"), (fsLit "gammaf"), (fsLit "gammal"),
672 (fsLit "isinf"), (fsLit "isinff"), (fsLit "isinfl"),
673 (fsLit "isnan"), (fsLit "isnanf"), (fsLit "isnanl"),
674 (fsLit "j0"), (fsLit "j0f"), (fsLit "j0l"),
675 (fsLit "j1"), (fsLit "j1f"), (fsLit "j1l"),
676 (fsLit "jn"), (fsLit "jnf"), (fsLit "jnl"),
677 (fsLit "lgamma_r"), (fsLit "lgammaf_r"), (fsLit "lgammal_r"),
678 (fsLit "scalb"), (fsLit "scalbf"), (fsLit "scalbl"),
679 (fsLit "significand"), (fsLit "significandf"), (fsLit "significandl"),
680 (fsLit "y0"), (fsLit "y0f"), (fsLit "y0l"),
681 (fsLit "y1"), (fsLit "y1f"), (fsLit "y1l"),
682 (fsLit "yn"), (fsLit "ynf"), (fsLit "ynl")
683 ]
684
685 -- -----------------------------------------------------------------------------
686 -- | Is a CLabel visible outside this object file or not?
687 -- From the point of view of the code generator, a name is
688 -- externally visible if it has to be declared as exported
689 -- in the .o file's symbol table; that is, made non-static.
690 externallyVisibleCLabel :: CLabel -> Bool -- not C "static"
691 externallyVisibleCLabel (CaseLabel _ _) = False
692 externallyVisibleCLabel (StringLitLabel _) = False
693 externallyVisibleCLabel (AsmTempLabel _) = False
694 externallyVisibleCLabel (PlainModuleInitLabel _)= True
695 externallyVisibleCLabel (RtsLabel _) = True
696 externallyVisibleCLabel (CmmLabel _ _ _) = True
697 externallyVisibleCLabel (ForeignLabel{}) = True
698 externallyVisibleCLabel (IdLabel name _ info) = isExternalName name && externallyVisibleIdLabel info
699 externallyVisibleCLabel (CC_Label _) = True
700 externallyVisibleCLabel (CCS_Label _) = True
701 externallyVisibleCLabel (DynamicLinkerLabel _ _) = False
702 externallyVisibleCLabel (HpcTicksLabel _) = True
703 externallyVisibleCLabel (LargeBitmapLabel _) = False
704 externallyVisibleCLabel (LargeSRTLabel _) = False
705
706 externallyVisibleIdLabel :: IdLabelInfo -> Bool
707 externallyVisibleIdLabel SRT = False
708 externallyVisibleIdLabel LocalInfoTable = False
709 externallyVisibleIdLabel LocalEntry = False
710 externallyVisibleIdLabel _ = True
711
712 -- -----------------------------------------------------------------------------
713 -- Finding the "type" of a CLabel
714
715 -- For generating correct types in label declarations:
716
717 data CLabelType
718 = CodeLabel -- Address of some executable instructions
719 | DataLabel -- Address of data, not a GC ptr
720 | GcPtrLabel -- Address of a (presumably static) GC object
721
722 isCFunctionLabel :: CLabel -> Bool
723 isCFunctionLabel lbl = case labelType lbl of
724 CodeLabel -> True
725 _other -> False
726
727 isGcPtrLabel :: CLabel -> Bool
728 isGcPtrLabel lbl = case labelType lbl of
729 GcPtrLabel -> True
730 _other -> False
731
732
733 -- | Work out the general type of data at the address of this label
734 -- whether it be code, data, or static GC object.
735 labelType :: CLabel -> CLabelType
736 labelType (CmmLabel _ _ CmmData) = DataLabel
737 labelType (CmmLabel _ _ CmmGcPtr) = GcPtrLabel
738 labelType (CmmLabel _ _ CmmCode) = CodeLabel
739 labelType (CmmLabel _ _ CmmInfo) = DataLabel
740 labelType (CmmLabel _ _ CmmEntry) = CodeLabel
741 labelType (CmmLabel _ _ CmmRetInfo) = DataLabel
742 labelType (CmmLabel _ _ CmmRet) = CodeLabel
743 labelType (RtsLabel (RtsSelectorInfoTable _ _)) = DataLabel
744 labelType (RtsLabel (RtsApInfoTable _ _)) = DataLabel
745 labelType (RtsLabel (RtsApFast _)) = CodeLabel
746 labelType (CaseLabel _ CaseReturnInfo) = DataLabel
747 labelType (CaseLabel _ _) = CodeLabel
748 labelType (PlainModuleInitLabel _) = CodeLabel
749 labelType (LargeSRTLabel _) = DataLabel
750 labelType (LargeBitmapLabel _) = DataLabel
751 labelType (ForeignLabel _ _ _ IsFunction) = CodeLabel
752 labelType (IdLabel _ _ info) = idInfoLabelType info
753 labelType _ = DataLabel
754
755 idInfoLabelType info =
756 case info of
757 InfoTable -> DataLabel
758 LocalInfoTable -> DataLabel
759 Closure -> GcPtrLabel
760 ConInfoTable -> DataLabel
761 StaticInfoTable -> DataLabel
762 ClosureTable -> DataLabel
763 RednCounts -> DataLabel
764 _ -> CodeLabel
765
766
767 -- -----------------------------------------------------------------------------
768 -- Does a CLabel need dynamic linkage?
769
770 -- When referring to data in code, we need to know whether
771 -- that data resides in a DLL or not. [Win32 only.]
772 -- @labelDynamic@ returns @True@ if the label is located
773 -- in a DLL, be it a data reference or not.
774
775 labelDynamic :: PackageId -> CLabel -> Bool
776 labelDynamic this_pkg lbl =
777 case lbl of
778 -- is the RTS in a DLL or not?
779 RtsLabel _ -> not opt_Static && (this_pkg /= rtsPackageId)
780
781 IdLabel n _ k -> isDllName this_pkg n
782
783 #if mingw32_TARGET_OS
784 -- When compiling in the "dyn" way, eack package is to be linked into its own shared library.
785 CmmLabel pkg _ _
786 -> not opt_Static && (this_pkg /= pkg)
787
788 -- Foreign label is in some un-named foreign package (or DLL)
789 ForeignLabel _ _ ForeignLabelInExternalPackage _ -> True
790
791 -- Foreign label is linked into the same package as the source file currently being compiled.
792 ForeignLabel _ _ ForeignLabelInThisPackage _ -> False
793
794 -- Foreign label is in some named package.
795 -- When compiling in the "dyn" way, each package is to be linked into its own DLL.
796 ForeignLabel _ _ (ForeignLabelInPackage pkgId) _
797 -> (not opt_Static) && (this_pkg /= pkgId)
798
799 #else
800 -- On Mac OS X and on ELF platforms, false positives are OK,
801 -- so we claim that all foreign imports come from dynamic libraries
802 ForeignLabel _ _ _ _ -> True
803
804 CmmLabel pkg _ _ -> True
805
806 #endif
807 PlainModuleInitLabel m -> not opt_Static && this_pkg /= (modulePackageId m)
808
809 -- Note that DynamicLinkerLabels do NOT require dynamic linking themselves.
810 _ -> False
811
812 {-
813 OLD?: These GRAN functions are needed for spitting out GRAN_FETCH() at the
814 right places. It is used to detect when the abstractC statement of an
815 CCodeBlock actually contains the code for a slow entry point. -- HWL
816
817 We need at least @Eq@ for @CLabels@, because we want to avoid
818 duplicate declarations in generating C (see @labelSeenTE@ in
819 @PprAbsC@).
820 -}
821
822 -----------------------------------------------------------------------------
823 -- Printing out CLabels.
824
825 {-
826 Convention:
827
828 <name>_<type>
829
830 where <name> is <Module>_<name> for external names and <unique> for
831 internal names. <type> is one of the following:
832
833 info Info table
834 srt Static reference table
835 srtd Static reference table descriptor
836 entry Entry code (function, closure)
837 slow Slow entry code (if any)
838 ret Direct return address
839 vtbl Vector table
840 <n>_alt Case alternative (tag n)
841 dflt Default case alternative
842 btm Large bitmap vector
843 closure Static closure
844 con_entry Dynamic Constructor entry code
845 con_info Dynamic Constructor info table
846 static_entry Static Constructor entry code
847 static_info Static Constructor info table
848 sel_info Selector info table
849 sel_entry Selector entry code
850 cc Cost centre
851 ccs Cost centre stack
852
853 Many of these distinctions are only for documentation reasons. For
854 example, _ret is only distinguished from _entry to make it easy to
855 tell whether a code fragment is a return point or a closure/function
856 entry.
857
858 Note [Closure and info labels]
859 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
860 For a function 'foo, we have:
861 foo_info : Points to the info table describing foo's closure
862 (and entry code for foo with tables next to code)
863 foo_closure : Static (no-free-var) closure only:
864 points to the statically-allocated closure
865
866 For a data constructor (such as Just or Nothing), we have:
867 Just_con_info: Info table for the data constructor itself
868 the first word of a heap-allocated Just
869 Just_info: Info table for the *worker function*, an
870 ordinary Haskell function of arity 1 that
871 allocates a (Just x) box:
872 Just = \x -> Just x
873 Just_closure: The closure for this worker
874
875 Nothing_closure: a statically allocated closure for Nothing
876 Nothing_static_info: info table for Nothing_closure
877
878 All these must be exported symbol, EXCEPT Just_info. We don't need to
879 export this because in other modules we either have
880 * A reference to 'Just'; use Just_closure
881 * A saturated call 'Just x'; allocate using Just_con_info
882 Not exporting these Just_info labels reduces the number of symbols
883 somewhat.
884 -}
885
886 instance Outputable CLabel where
887 ppr = pprCLabel
888 instance PlatformOutputable CLabel where
889 pprPlatform _ = pprCLabel
890
891 pprCLabel :: CLabel -> SDoc
892
893 pprCLabel (AsmTempLabel u)
894 | cGhcWithNativeCodeGen == "YES"
895 = getPprStyle $ \ sty ->
896 if asmStyle sty then
897 ptext asmTempLabelPrefix <> pprUnique u
898 else
899 char '_' <> pprUnique u
900
901 pprCLabel (DynamicLinkerLabel info lbl)
902 | cGhcWithNativeCodeGen == "YES"
903 = pprDynamicLinkerAsmLabel info lbl
904
905 pprCLabel PicBaseLabel
906 | cGhcWithNativeCodeGen == "YES"
907 = ptext (sLit "1b")
908
909 pprCLabel (DeadStripPreventer lbl)
910 | cGhcWithNativeCodeGen == "YES"
911 = pprCLabel lbl <> ptext (sLit "_dsp")
912
913 pprCLabel lbl
914 = getPprStyle $ \ sty ->
915 if cGhcWithNativeCodeGen == "YES" && asmStyle sty
916 then maybe_underscore (pprAsmCLbl lbl)
917 else pprCLbl lbl
918
919 maybe_underscore doc
920 | underscorePrefix = pp_cSEP <> doc
921 | otherwise = doc
922
923 #ifdef mingw32_TARGET_OS
924 -- In asm mode, we need to put the suffix on a stdcall ForeignLabel.
925 -- (The C compiler does this itself).
926 pprAsmCLbl (ForeignLabel fs (Just sz) _ _)
927 = ftext fs <> char '@' <> int sz
928 #endif
929 pprAsmCLbl lbl
930 = pprCLbl lbl
931
932 pprCLbl (StringLitLabel u)
933 = pprUnique u <> ptext (sLit "_str")
934
935 pprCLbl (CaseLabel u CaseReturnPt)
936 = hcat [pprUnique u, ptext (sLit "_ret")]
937 pprCLbl (CaseLabel u CaseReturnInfo)
938 = hcat [pprUnique u, ptext (sLit "_info")]
939 pprCLbl (CaseLabel u (CaseAlt tag))
940 = hcat [pprUnique u, pp_cSEP, int tag, ptext (sLit "_alt")]
941 pprCLbl (CaseLabel u CaseDefault)
942 = hcat [pprUnique u, ptext (sLit "_dflt")]
943
944 pprCLbl (LargeSRTLabel u) = pprUnique u <> pp_cSEP <> ptext (sLit "srtd")
945 pprCLbl (LargeBitmapLabel u) = text "b" <> pprUnique u <> pp_cSEP <> ptext (sLit "btm")
946 -- Some bitsmaps for tuple constructors have a numeric tag (e.g. '7')
947 -- until that gets resolved we'll just force them to start
948 -- with a letter so the label will be legal assmbly code.
949
950
951 pprCLbl (CmmLabel _ str CmmCode) = ftext str
952 pprCLbl (CmmLabel _ str CmmData) = ftext str
953 pprCLbl (CmmLabel _ str CmmGcPtr) = ftext str
954 pprCLbl (CmmLabel _ str CmmPrimCall) = ftext str
955
956 pprCLbl (RtsLabel (RtsApFast str)) = ftext str <> ptext (sLit "_fast")
957
958 pprCLbl (RtsLabel (RtsSelectorInfoTable upd_reqd offset))
959 = hcat [ptext (sLit "stg_sel_"), text (show offset),
960 ptext (if upd_reqd
961 then (sLit "_upd_info")
962 else (sLit "_noupd_info"))
963 ]
964
965 pprCLbl (RtsLabel (RtsSelectorEntry upd_reqd offset))
966 = hcat [ptext (sLit "stg_sel_"), text (show offset),
967 ptext (if upd_reqd
968 then (sLit "_upd_entry")
969 else (sLit "_noupd_entry"))
970 ]
971
972 pprCLbl (RtsLabel (RtsApInfoTable upd_reqd arity))
973 = hcat [ptext (sLit "stg_ap_"), text (show arity),
974 ptext (if upd_reqd
975 then (sLit "_upd_info")
976 else (sLit "_noupd_info"))
977 ]
978
979 pprCLbl (RtsLabel (RtsApEntry upd_reqd arity))
980 = hcat [ptext (sLit "stg_ap_"), text (show arity),
981 ptext (if upd_reqd
982 then (sLit "_upd_entry")
983 else (sLit "_noupd_entry"))
984 ]
985
986 pprCLbl (CmmLabel _ fs CmmInfo)
987 = ftext fs <> ptext (sLit "_info")
988
989 pprCLbl (CmmLabel _ fs CmmEntry)
990 = ftext fs <> ptext (sLit "_entry")
991
992 pprCLbl (CmmLabel _ fs CmmRetInfo)
993 = ftext fs <> ptext (sLit "_info")
994
995 pprCLbl (CmmLabel _ fs CmmRet)
996 = ftext fs <> ptext (sLit "_ret")
997
998 pprCLbl (RtsLabel (RtsPrimOp primop))
999 = ptext (sLit "stg_") <> ppr primop
1000
1001 pprCLbl (RtsLabel (RtsSlowTickyCtr pat))
1002 = ptext (sLit "SLOW_CALL_") <> text pat <> ptext (sLit "_ctr")
1003
1004 pprCLbl (ForeignLabel str _ _ _)
1005 = ftext str
1006
1007 pprCLbl (IdLabel name cafs flavor) = ppr name <> ppIdFlavor flavor
1008
1009 pprCLbl (CC_Label cc) = ppr cc
1010 pprCLbl (CCS_Label ccs) = ppr ccs
1011
1012 pprCLbl (PlainModuleInitLabel mod)
1013 = ptext (sLit "__stginit_") <> ppr mod
1014
1015 pprCLbl (HpcTicksLabel mod)
1016 = ptext (sLit "_hpc_tickboxes_") <> ppr mod <> ptext (sLit "_hpc")
1017
1018 ppIdFlavor :: IdLabelInfo -> SDoc
1019 ppIdFlavor x = pp_cSEP <>
1020 (case x of
1021 Closure -> ptext (sLit "closure")
1022 SRT -> ptext (sLit "srt")
1023 InfoTable -> ptext (sLit "info")
1024 LocalInfoTable -> ptext (sLit "info")
1025 Entry -> ptext (sLit "entry")
1026 LocalEntry -> ptext (sLit "entry")
1027 Slow -> ptext (sLit "slow")
1028 RednCounts -> ptext (sLit "ct")
1029 ConEntry -> ptext (sLit "con_entry")
1030 ConInfoTable -> ptext (sLit "con_info")
1031 StaticConEntry -> ptext (sLit "static_entry")
1032 StaticInfoTable -> ptext (sLit "static_info")
1033 ClosureTable -> ptext (sLit "closure_tbl")
1034 )
1035
1036
1037 pp_cSEP = char '_'
1038
1039
1040 instance Outputable ForeignLabelSource where
1041 ppr fs
1042 = case fs of
1043 ForeignLabelInPackage pkgId -> parens $ text "package: " <> ppr pkgId
1044 ForeignLabelInThisPackage -> parens $ text "this package"
1045 ForeignLabelInExternalPackage -> parens $ text "external package"
1046
1047 -- -----------------------------------------------------------------------------
1048 -- Machine-dependent knowledge about labels.
1049
1050 underscorePrefix :: Bool -- leading underscore on assembler labels?
1051 underscorePrefix = (cLeadingUnderscore == "YES")
1052
1053 asmTempLabelPrefix :: LitString -- for formatting labels
1054 asmTempLabelPrefix =
1055 #if alpha_TARGET_OS
1056 {- The alpha assembler likes temporary labels to look like $L123
1057 instead of L123. (Don't toss the L, because then Lf28
1058 turns into $f28.)
1059 -}
1060 (sLit "$")
1061 #elif darwin_TARGET_OS
1062 (sLit "L")
1063 #else
1064 (sLit ".L")
1065 #endif
1066
1067 pprDynamicLinkerAsmLabel :: DynamicLinkerLabelInfo -> CLabel -> SDoc
1068
1069 #if x86_64_TARGET_ARCH && darwin_TARGET_OS
1070 pprDynamicLinkerAsmLabel CodeStub lbl
1071 = char 'L' <> pprCLabel lbl <> text "$stub"
1072 pprDynamicLinkerAsmLabel SymbolPtr lbl
1073 = char 'L' <> pprCLabel lbl <> text "$non_lazy_ptr"
1074 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
1075 = pprCLabel lbl <> text "@GOTPCREL"
1076 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
1077 = pprCLabel lbl
1078 pprDynamicLinkerAsmLabel _ _
1079 = panic "pprDynamicLinkerAsmLabel"
1080
1081 #elif darwin_TARGET_OS
1082 pprDynamicLinkerAsmLabel CodeStub lbl
1083 = char 'L' <> pprCLabel lbl <> text "$stub"
1084 pprDynamicLinkerAsmLabel SymbolPtr lbl
1085 = char 'L' <> pprCLabel lbl <> text "$non_lazy_ptr"
1086 pprDynamicLinkerAsmLabel _ _
1087 = panic "pprDynamicLinkerAsmLabel"
1088
1089 #elif powerpc_TARGET_ARCH && elf_OBJ_FORMAT
1090 pprDynamicLinkerAsmLabel CodeStub lbl
1091 = pprCLabel lbl <> text "@plt"
1092 pprDynamicLinkerAsmLabel SymbolPtr lbl
1093 = text ".LC_" <> pprCLabel lbl
1094 pprDynamicLinkerAsmLabel _ _
1095 = panic "pprDynamicLinkerAsmLabel"
1096
1097 #elif x86_64_TARGET_ARCH && elf_OBJ_FORMAT
1098 pprDynamicLinkerAsmLabel CodeStub lbl
1099 = pprCLabel lbl <> text "@plt"
1100 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
1101 = pprCLabel lbl <> text "@gotpcrel"
1102 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
1103 = pprCLabel lbl
1104 pprDynamicLinkerAsmLabel SymbolPtr lbl
1105 = text ".LC_" <> pprCLabel lbl
1106
1107 #elif elf_OBJ_FORMAT
1108 pprDynamicLinkerAsmLabel CodeStub lbl
1109 = pprCLabel lbl <> text "@plt"
1110 pprDynamicLinkerAsmLabel SymbolPtr lbl
1111 = text ".LC_" <> pprCLabel lbl
1112 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
1113 = pprCLabel lbl <> text "@got"
1114 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
1115 = pprCLabel lbl <> text "@gotoff"
1116
1117 #elif mingw32_TARGET_OS
1118 pprDynamicLinkerAsmLabel SymbolPtr lbl
1119 = text "__imp_" <> pprCLabel lbl
1120 pprDynamicLinkerAsmLabel _ _
1121 = panic "pprDynamicLinkerAsmLabel"
1122
1123 #else
1124 pprDynamicLinkerAsmLabel _ _
1125 = panic "pprDynamicLinkerAsmLabel"
1126 #endif