2 This module handles generation of position independent code and
3 dynamic-linking related issues for the native code generator.
5 This depends both the architecture and OS, so we define it here
6 instead of in one of the architecture specific modules.
8 Things outside this module which are related to this:
11 - PIC base label (pretty printed as local label 1)
12 - DynamicLinkerLabels - several kinds:
13 CodeStub, SymbolPtr, GotSymbolPtr, GotSymbolOffset
14 - labelDynamic predicate
16 - The GlobalReg datatype has a PicBaseReg constructor
17 - The CmmLit datatype has a CmmLabelDiffOff constructor
19 - When tablesNextToCode, no absolute addresses are stored in info tables
20 any more. Instead, offsets from the info label are used.
21 - For Win32 only, SRTs might contain addresses of __imp_ symbol pointers
22 because Win32 doesn't support external references in data sections.
23 TODO: make sure this still works, it might be bitrotted
25 - The cmmToCmm pass in AsmCodeGen calls cmmMakeDynamicReference for all
27 - nativeCodeGen calls pprImportedSymbol and pprGotDeclaration to output
28 all the necessary stuff for imported symbols.
29 - The NCG monad keeps track of a list of imported symbols.
30 - MachCodeGen invokes initializePicBase to generate code to initialize
31 the PIC base register when needed.
32 - MachCodeGen calls cmmMakeDynamicReference whenever it uses a CLabel
33 that wasn't in the original Cmm code (e.g. floating point literals).
35 - The mangler converts absolure refs to relative refs in info tables
36 - Symbol pointers, stub code and PIC calculations that are generated
37 by GCC are left intact by the mangler (so far only on ppc-darwin
42 cmmMakeDynamicReference,
48 initializePicBase_ppc,
54 import qualified PPC.Instr as PPC
55 import qualified PPC.Regs as PPC
57 import qualified X86.Instr as X86
67 import CLabel ( CLabel, ForeignLabelSource(..), pprCLabel,
68 mkDynamicLinkerLabel, DynamicLinkerLabelInfo(..),
69 dynamicLinkerLabelInfo, mkPicBaseLabel,
70 labelDynamic, externallyVisibleCLabel )
72 import CLabel ( mkForeignLabel )
75 import StaticFlags ( opt_PIC, opt_Static )
79 import qualified Outputable
81 import Panic ( panic )
87 --------------------------------------------------------------------------------
88 -- It gets called by the cmmToCmm pass for every CmmLabel in the Cmm
89 -- code. It does The Right Thing(tm) to convert the CmmLabel into a
90 -- position-independent, dynamic-linking-aware reference to the thing
92 -- Note that this also has to be called from MachCodeGen in order to
93 -- access static data like floating point literals (labels that were
94 -- created after the cmmToCmm pass).
95 -- The function must run in a monad that can keep track of imported symbols
96 -- A function for recording an imported symbol must be passed in:
97 -- - addImportCmmOpt for the CmmOptM monad
98 -- - addImportNat for the NatM monad.
107 cmmMakeDynamicReference, cmmMakeDynamicReference'
108 :: Monad m => DynFlags
109 -> (CLabel -> m ()) -- a monad & a function
110 -- used for recording imported symbols
111 -> ReferenceKind -- whether this is the target of a jump
112 -> CLabel -- the label
115 cmmMakeDynamicReference = cmmMakeDynamicReference'
117 cmmMakeDynamicReference' dflags addImport referenceKind lbl
118 | Just _ <- dynamicLinkerLabelInfo lbl
119 = return $ CmmLit $ CmmLabel lbl -- already processed it, pass through
122 = case howToAccessLabel
124 (platformArch $ targetPlatform dflags)
125 (platformOS $ targetPlatform dflags)
129 let stub = mkDynamicLinkerLabel CodeStub lbl
131 return $ CmmLit $ CmmLabel stub
133 AccessViaSymbolPtr -> do
134 let symbolPtr = mkDynamicLinkerLabel SymbolPtr lbl
136 return $ CmmLoad (cmmMakePicReference dflags symbolPtr) bWord
138 AccessDirectly -> case referenceKind of
139 -- for data, we might have to make some calculations:
140 DataReference -> return $ cmmMakePicReference dflags lbl
141 -- all currently supported processors support
142 -- PC-relative branch and call instructions,
143 -- so just jump there if it's a call or a jump
144 _ -> return $ CmmLit $ CmmLabel lbl
147 -- -----------------------------------------------------------------------------
148 -- Create a position independent reference to a label.
149 -- (but do not bother with dynamic linking).
150 -- We calculate the label's address by adding some (platform-dependent)
151 -- offset to our base register; this offset is calculated by
152 -- the function picRelative in the platform-dependent part below.
154 cmmMakePicReference :: DynFlags -> CLabel -> CmmExpr
155 cmmMakePicReference dflags lbl
157 -- Windows doesn't need PIC,
158 -- everything gets relocated at runtime
159 | OSMinGW32 <- platformOS $ targetPlatform dflags
160 = CmmLit $ CmmLabel lbl
163 | (opt_PIC || not opt_Static) && absoluteLabel lbl
164 = CmmMachOp (MO_Add wordWidth)
165 [ CmmReg (CmmGlobal PicBaseReg)
166 , CmmLit $ picRelative
167 (platformArch $ targetPlatform dflags)
168 (platformOS $ targetPlatform dflags)
172 = CmmLit $ CmmLabel lbl
175 absoluteLabel :: CLabel -> Bool
177 = case dynamicLinkerLabelInfo lbl of
178 Just (GotSymbolPtr, _) -> False
179 Just (GotSymbolOffset, _) -> False
183 --------------------------------------------------------------------------------
184 -- Knowledge about how special dynamic linker labels like symbol
185 -- pointers, code stubs and GOT offsets look like is located in the
188 -- We have to decide which labels need to be accessed
189 -- indirectly or via a piece of stub code.
190 data LabelAccessStyle
196 :: DynFlags -> Arch -> OS -> ReferenceKind -> CLabel -> LabelAccessStyle
200 -- In Windows speak, a "module" is a set of objects linked into the
201 -- same Portable Exectuable (PE) file. (both .exe and .dll files are PEs).
203 -- If we're compiling a multi-module program then symbols from other modules
204 -- are accessed by a symbol pointer named __imp_SYMBOL. At runtime we have the
207 -- (in the local module)
208 -- __imp_SYMBOL: addr of SYMBOL
210 -- (in the other module)
211 -- SYMBOL: the real function / data.
213 -- To access the function at SYMBOL from our local module, we just need to
214 -- dereference the local __imp_SYMBOL.
216 -- If opt_Static is set then we assume that all our code will be linked
217 -- into the same .exe file. In this case we always access symbols directly,
218 -- and never use __imp_SYMBOL.
220 howToAccessLabel dflags _ OSMinGW32 _ lbl
222 -- Assume all symbols will be in the same PE, so just access them directly.
226 -- If the target symbol is in another PE we need to access it via the
227 -- appropriate __imp_SYMBOL pointer.
228 | labelDynamic (thisPackage dflags) lbl
231 -- Target symbol is in the same PE as the caller, so just access it directly.
236 -- Mach-O (Darwin, Mac OS X)
238 -- Indirect access is required in the following cases:
239 -- * things imported from a dynamic library
240 -- * (not on x86_64) data from a different module, if we're generating PIC code
241 -- It is always possible to access something indirectly,
242 -- even when it's not necessary.
244 howToAccessLabel dflags arch OSDarwin DataReference lbl
245 -- data access to a dynamic library goes via a symbol pointer
246 | labelDynamic (thisPackage dflags) lbl
249 -- when generating PIC code, all cross-module data references must
250 -- must go via a symbol pointer, too, because the assembler
251 -- cannot generate code for a label difference where one
252 -- label is undefined. Doesn't apply t x86_64.
253 -- Unfortunately, we don't know whether it's cross-module,
254 -- so we do it for all externally visible labels.
255 -- This is a slight waste of time and space, but otherwise
256 -- we'd need to pass the current Module all the way in to
259 , opt_PIC && externallyVisibleCLabel lbl
265 howToAccessLabel dflags arch OSDarwin JumpReference lbl
266 -- dyld code stubs don't work for tailcalls because the
267 -- stack alignment is only right for regular calls.
268 -- Therefore, we have to go via a symbol pointer:
269 | arch == ArchX86 || arch == ArchX86_64
270 , labelDynamic (thisPackage dflags) lbl
274 howToAccessLabel dflags arch OSDarwin _ lbl
275 -- Code stubs are the usual method of choice for imported code;
276 -- not needed on x86_64 because Apple's new linker, ld64, generates
277 -- them automatically.
279 , labelDynamic (thisPackage dflags) lbl
287 -- ELF tries to pretend to the main application code that dynamic linking does
288 -- not exist. While this may sound convenient, it tends to mess things up in
289 -- very bad ways, so we have to be careful when we generate code for the main
290 -- program (-dynamic but no -fPIC).
292 -- Indirect access is required for references to imported symbols
293 -- from position independent code. It is also required from the main program
294 -- when dynamic libraries containing Haskell code are used.
296 howToAccessLabel _ ArchPPC_64 os kind _
298 = if kind == DataReference
299 -- ELF PPC64 (powerpc64-linux), AIX, MacOS 9, BeOS/PPC
300 then AccessViaSymbolPtr
301 -- actually, .label instead of label
304 howToAccessLabel _ _ os _ _
305 -- no PIC -> the dynamic linker does everything for us;
306 -- if we don't dynamically link to Haskell code,
307 -- it actually manages to do so without messing thins up.
309 , not opt_PIC && opt_Static
312 howToAccessLabel dflags arch os DataReference lbl
315 -- A dynamic label needs to be accessed via a symbol pointer.
316 _ | labelDynamic (thisPackage dflags) lbl
317 -> AccessViaSymbolPtr
319 -- For PowerPC32 -fPIC, we have to access even static data
320 -- via a symbol pointer (see below for an explanation why
321 -- PowerPC32 Linux is especially broken).
324 -> AccessViaSymbolPtr
330 -- In most cases, we have to avoid symbol stubs on ELF, for the following reasons:
331 -- on i386, the position-independent symbol stubs in the Procedure Linkage Table
332 -- require the address of the GOT to be loaded into register %ebx on entry.
333 -- The linker will take any reference to the symbol stub as a hint that
334 -- the label in question is a code label. When linking executables, this
335 -- will cause the linker to replace even data references to the label with
336 -- references to the symbol stub.
338 -- This leaves calling a (foreign) function from non-PIC code
339 -- (AccessDirectly, because we get an implicit symbol stub)
340 -- and calling functions from PIC code on non-i386 platforms (via a symbol stub)
342 howToAccessLabel dflags arch os CallReference lbl
344 , labelDynamic (thisPackage dflags) lbl && not opt_PIC
349 , labelDynamic (thisPackage dflags) lbl && opt_PIC
352 howToAccessLabel dflags _ os _ lbl
354 = if labelDynamic (thisPackage dflags) lbl
355 then AccessViaSymbolPtr
358 -- all other platforms
359 howToAccessLabel _ _ _ _ _
364 = panic "howToAccessLabel: PIC not defined for this platform"
368 -- -------------------------------------------------------------------
369 -- | Says what we we have to add to our 'PIC base register' in order to
370 -- get the address of a label.
372 picRelative :: Arch -> OS -> CLabel -> CmmLit
374 -- Darwin, but not x86_64:
375 -- The PIC base register points to the PIC base label at the beginning
376 -- of the current CmmTop. We just have to use a label difference to
378 -- We have already made sure that all labels that are not from the current
379 -- module are accessed indirectly ('as' can't calculate differences between
380 -- undefined labels).
381 picRelative arch OSDarwin lbl
383 = CmmLabelDiffOff lbl mkPicBaseLabel 0
387 -- The PIC base register points to our fake GOT. Use a label difference
388 -- to get the offset.
389 -- We have made sure that *everything* is accessed indirectly, so this
390 -- is only used for offsets from the GOT to symbol pointers inside the
392 picRelative ArchPPC os lbl
394 = CmmLabelDiffOff lbl gotLabel 0
397 -- Most Linux versions:
398 -- The PIC base register points to the GOT. Use foo@got for symbol
399 -- pointers, and foo@gotoff for everything else.
400 -- Linux and Darwin on x86_64:
401 -- The PIC base register is %rip, we use foo@gotpcrel for symbol pointers,
402 -- and a GotSymbolOffset label for other things.
403 -- For reasons of tradition, the symbol offset label is written as a plain label.
404 picRelative arch os lbl
405 | osElfTarget os || (os == OSDarwin && arch == ArchX86_64)
407 | Just (SymbolPtr, lbl') <- dynamicLinkerLabelInfo lbl
408 = CmmLabel $ mkDynamicLinkerLabel GotSymbolPtr lbl'
411 = CmmLabel $ mkDynamicLinkerLabel GotSymbolOffset lbl
416 = panic "PositionIndependentCode.picRelative undefined for this platform"
420 --------------------------------------------------------------------------------
422 -- utility function for pretty-printing asm-labels,
423 -- copied from PprMach
425 asmSDoc :: Outputable.SDoc -> Doc
427 = Outputable.withPprStyleDoc
428 (Outputable.mkCodeStyle Outputable.AsmStyle) d
430 pprCLabel_asm :: CLabel -> Doc
432 = asmSDoc (pprCLabel l)
435 needImportedSymbols :: Arch -> OS -> Bool
436 needImportedSymbols arch os
441 -- PowerPC Linux: -fPIC or -dynamic
444 = opt_PIC || not opt_Static
446 -- i386 (and others?): -dynamic but not -fPIC
449 = not opt_Static && not opt_PIC
455 -- The label used to refer to our "fake GOT" from
456 -- position-independent code.
459 -- HACK: this label isn't really foreign
462 Nothing ForeignLabelInThisPackage IsData
466 --------------------------------------------------------------------------------
467 -- We don't need to declare any offset tables.
468 -- However, for PIC on x86, we need a small helper function.
469 pprGotDeclaration :: Arch -> OS -> Doc
470 pprGotDeclaration ArchX86 OSDarwin
473 ptext (sLit ".section __TEXT,__textcoal_nt,coalesced,no_toc"),
474 ptext (sLit ".weak_definition ___i686.get_pc_thunk.ax"),
475 ptext (sLit ".private_extern ___i686.get_pc_thunk.ax"),
476 ptext (sLit "___i686.get_pc_thunk.ax:"),
477 ptext (sLit "\tmovl (%esp), %eax"),
478 ptext (sLit "\tret") ]
480 pprGotDeclaration _ OSDarwin
484 -- Output whatever needs to be output once per .s file.
485 -- The .LCTOC1 label is defined to point 32768 bytes into the table,
486 -- to make the most of the PPC's 16-bit displacements.
487 -- Only needed for PIC.
488 pprGotDeclaration arch os
497 ptext (sLit ".section \".got2\",\"aw\""),
498 ptext (sLit ".LCTOC1 = .+32768") ]
500 pprGotDeclaration _ _
501 = panic "pprGotDeclaration: no match"
504 --------------------------------------------------------------------------------
505 -- On Darwin, we have to generate our own stub code for lazy binding..
506 -- For each processor architecture, there are two versions, one for PIC
507 -- and one for non-PIC.
509 -- Whenever you change something in this assembler output, make sure
510 -- the splitter in driver/split/ghc-split.lprl recognizes the new output
512 pprImportedSymbol :: Arch -> OS -> CLabel -> Doc
513 pprImportedSymbol ArchPPC OSDarwin importedLbl
514 | Just (CodeStub, lbl) <- dynamicLinkerLabelInfo importedLbl
518 ptext (sLit ".symbol_stub"),
519 ptext (sLit "L") <> pprCLabel_asm lbl <> ptext (sLit "$stub:"),
520 ptext (sLit "\t.indirect_symbol") <+> pprCLabel_asm lbl,
521 ptext (sLit "\tlis r11,ha16(L") <> pprCLabel_asm lbl
522 <> ptext (sLit "$lazy_ptr)"),
523 ptext (sLit "\tlwz r12,lo16(L") <> pprCLabel_asm lbl
524 <> ptext (sLit "$lazy_ptr)(r11)"),
525 ptext (sLit "\tmtctr r12"),
526 ptext (sLit "\taddi r11,r11,lo16(L") <> pprCLabel_asm lbl
527 <> ptext (sLit "$lazy_ptr)"),
528 ptext (sLit "\tbctr")
532 ptext (sLit ".section __TEXT,__picsymbolstub1,")
533 <> ptext (sLit "symbol_stubs,pure_instructions,32"),
534 ptext (sLit "\t.align 2"),
535 ptext (sLit "L") <> pprCLabel_asm lbl <> ptext (sLit "$stub:"),
536 ptext (sLit "\t.indirect_symbol") <+> pprCLabel_asm lbl,
537 ptext (sLit "\tmflr r0"),
538 ptext (sLit "\tbcl 20,31,L0$") <> pprCLabel_asm lbl,
539 ptext (sLit "L0$") <> pprCLabel_asm lbl <> char ':',
540 ptext (sLit "\tmflr r11"),
541 ptext (sLit "\taddis r11,r11,ha16(L") <> pprCLabel_asm lbl
542 <> ptext (sLit "$lazy_ptr-L0$") <> pprCLabel_asm lbl <> char ')',
543 ptext (sLit "\tmtlr r0"),
544 ptext (sLit "\tlwzu r12,lo16(L") <> pprCLabel_asm lbl
545 <> ptext (sLit "$lazy_ptr-L0$") <> pprCLabel_asm lbl
546 <> ptext (sLit ")(r11)"),
547 ptext (sLit "\tmtctr r12"),
548 ptext (sLit "\tbctr")
551 ptext (sLit ".lazy_symbol_pointer"),
552 ptext (sLit "L") <> pprCLabel_asm lbl <> ptext (sLit "$lazy_ptr:"),
553 ptext (sLit "\t.indirect_symbol") <+> pprCLabel_asm lbl,
554 ptext (sLit "\t.long dyld_stub_binding_helper")]
556 | Just (SymbolPtr, lbl) <- dynamicLinkerLabelInfo importedLbl
558 ptext (sLit ".non_lazy_symbol_pointer"),
559 char 'L' <> pprCLabel_asm lbl <> ptext (sLit "$non_lazy_ptr:"),
560 ptext (sLit "\t.indirect_symbol") <+> pprCLabel_asm lbl,
561 ptext (sLit "\t.long\t0")]
567 pprImportedSymbol ArchX86 OSDarwin importedLbl
568 | Just (CodeStub, lbl) <- dynamicLinkerLabelInfo importedLbl
572 ptext (sLit ".symbol_stub"),
573 ptext (sLit "L") <> pprCLabel_asm lbl <> ptext (sLit "$stub:"),
574 ptext (sLit "\t.indirect_symbol") <+> pprCLabel_asm lbl,
575 ptext (sLit "\tjmp *L") <> pprCLabel_asm lbl
576 <> ptext (sLit "$lazy_ptr"),
577 ptext (sLit "L") <> pprCLabel_asm lbl
578 <> ptext (sLit "$stub_binder:"),
579 ptext (sLit "\tpushl $L") <> pprCLabel_asm lbl
580 <> ptext (sLit "$lazy_ptr"),
581 ptext (sLit "\tjmp dyld_stub_binding_helper")
585 ptext (sLit ".section __TEXT,__picsymbolstub2,")
586 <> ptext (sLit "symbol_stubs,pure_instructions,25"),
587 ptext (sLit "L") <> pprCLabel_asm lbl <> ptext (sLit "$stub:"),
588 ptext (sLit "\t.indirect_symbol") <+> pprCLabel_asm lbl,
589 ptext (sLit "\tcall ___i686.get_pc_thunk.ax"),
591 ptext (sLit "\tmovl L") <> pprCLabel_asm lbl
592 <> ptext (sLit "$lazy_ptr-1b(%eax),%edx"),
593 ptext (sLit "\tjmp *%edx"),
594 ptext (sLit "L") <> pprCLabel_asm lbl
595 <> ptext (sLit "$stub_binder:"),
596 ptext (sLit "\tlea L") <> pprCLabel_asm lbl
597 <> ptext (sLit "$lazy_ptr-1b(%eax),%eax"),
598 ptext (sLit "\tpushl %eax"),
599 ptext (sLit "\tjmp dyld_stub_binding_helper")
601 $+$ vcat [ ptext (sLit ".section __DATA, __la_sym_ptr")
602 <> (if opt_PIC then int 2 else int 3)
603 <> ptext (sLit ",lazy_symbol_pointers"),
604 ptext (sLit "L") <> pprCLabel_asm lbl <> ptext (sLit "$lazy_ptr:"),
605 ptext (sLit "\t.indirect_symbol") <+> pprCLabel_asm lbl,
606 ptext (sLit "\t.long L") <> pprCLabel_asm lbl
607 <> ptext (sLit "$stub_binder")]
609 | Just (SymbolPtr, lbl) <- dynamicLinkerLabelInfo importedLbl
611 ptext (sLit ".non_lazy_symbol_pointer"),
612 char 'L' <> pprCLabel_asm lbl <> ptext (sLit "$non_lazy_ptr:"),
613 ptext (sLit "\t.indirect_symbol") <+> pprCLabel_asm lbl,
614 ptext (sLit "\t.long\t0")]
620 pprImportedSymbol _ OSDarwin _
626 -- In theory, we don't need to generate any stubs or symbol pointers
627 -- by hand for Linux.
629 -- Reality differs from this in two areas.
631 -- 1) If we just use a dynamically imported symbol directly in a read-only
632 -- section of the main executable (as GCC does), ld generates R_*_COPY
633 -- relocations, which are fundamentally incompatible with reversed info
634 -- tables. Therefore, we need a table of imported addresses in a writable
636 -- The "official" GOT mechanism (label@got) isn't intended to be used
637 -- in position dependent code, so we have to create our own "fake GOT"
638 -- when not opt_PIC && not opt_Static.
640 -- 2) PowerPC Linux is just plain broken.
641 -- While it's theoretically possible to use GOT offsets larger
642 -- than 16 bit, the standard crt*.o files don't, which leads to
643 -- linker errors as soon as the GOT size exceeds 16 bit.
644 -- Also, the assembler doesn't support @gotoff labels.
645 -- In order to be able to use a larger GOT, we have to circumvent the
646 -- entire GOT mechanism and do it ourselves (this is also what GCC does).
649 -- When needImportedSymbols is defined,
650 -- the NCG will keep track of all DynamicLinkerLabels it uses
651 -- and output each of them using pprImportedSymbol.
653 pprImportedSymbol ArchPPC_64 os _
657 pprImportedSymbol _ os importedLbl
659 = case dynamicLinkerLabelInfo importedLbl of
660 Just (SymbolPtr, lbl)
661 -> let symbolSize = case wordWidth of
662 W32 -> sLit "\t.long"
663 W64 -> sLit "\t.quad"
664 _ -> panic "Unknown wordRep in pprImportedSymbol"
667 ptext (sLit ".section \".got2\", \"aw\""),
668 ptext (sLit ".LC_") <> pprCLabel_asm lbl <> char ':',
669 ptext symbolSize <+> pprCLabel_asm lbl ]
671 -- PLT code stubs are generated automatically by the dynamic linker.
674 pprImportedSymbol _ _ _
675 = panic "PIC.pprImportedSymbol: no match"
677 --------------------------------------------------------------------------------
678 -- Generate code to calculate the address that should be put in the
679 -- PIC base register.
680 -- This is called by MachCodeGen for every CmmProc that accessed the
681 -- PIC base register. It adds the appropriate instructions to the
682 -- top of the CmmProc.
684 -- It is assumed that the first NatCmmTop in the input list is a Proc
685 -- and the rest are CmmDatas.
687 -- Darwin is simple: just fetch the address of a local label.
688 -- The FETCHPC pseudo-instruction is expanded to multiple instructions
689 -- during pretty-printing so that we don't have to deal with the
702 -- Get a pointer to our own fake GOT, which is defined on a per-module basis.
703 -- This is exactly how GCC does it, and it's quite horrible:
704 -- We first fetch the address of a local label (mkPicBaseLabel).
705 -- Then we add a 16-bit offset to that to get the address of a .long that we
706 -- define in .text space right next to the proc. This .long literal contains
707 -- the (32-bit) offset from our local label to our global offset table
708 -- (.LCTOC1 aka gotOffLabel).
710 initializePicBase_ppc
712 -> [NatCmmTop PPC.Instr]
713 -> NatM [NatCmmTop PPC.Instr]
715 initializePicBase_ppc ArchPPC os picReg
716 (CmmProc info lab (ListGraph blocks) : statics)
719 gotOffLabel <- getNewLabelNat
720 tmp <- getNewRegNat $ intSize wordWidth
722 gotOffset = CmmData Text [
723 CmmDataLabel gotOffLabel,
724 CmmStaticLit (CmmLabelDiffOff gotLabel
729 = PPC.ImmConstantDiff
730 (PPC.ImmCLbl gotOffLabel)
731 (PPC.ImmCLbl mkPicBaseLabel)
736 b' = BasicBlock bID (PPC.FETCHPC picReg
737 : PPC.LD PPC.archWordSize tmp
738 (PPC.AddrRegImm picReg offsetToOffset)
739 : PPC.ADD picReg picReg (PPC.RIReg tmp)
742 return (CmmProc info lab (ListGraph (b' : tail blocks)) : gotOffset : statics)
744 initializePicBase_ppc ArchPPC OSDarwin picReg
745 (CmmProc info lab (ListGraph blocks) : statics)
746 = return (CmmProc info lab (ListGraph (b':tail blocks)) : statics)
748 where BasicBlock bID insns = head blocks
749 b' = BasicBlock bID (PPC.FETCHPC picReg : insns)
752 initializePicBase_ppc _ _ _ _
753 = panic "initializePicBase_ppc: not needed"
756 -- We cheat a bit here by defining a pseudo-instruction named FETCHGOT
757 -- which pretty-prints as:
760 -- addl __GLOBAL_OFFSET_TABLE__+.-1b, %picReg
763 initializePicBase_x86
765 -> [NatCmmTop X86.Instr]
766 -> NatM [NatCmmTop X86.Instr]
768 initializePicBase_x86 ArchX86 os picReg
769 (CmmProc info lab (ListGraph blocks) : statics)
771 = return (CmmProc info lab (ListGraph (b':tail blocks)) : statics)
772 where BasicBlock bID insns = head blocks
773 b' = BasicBlock bID (X86.FETCHGOT picReg : insns)
775 initializePicBase_x86 ArchX86 OSDarwin picReg
776 (CmmProc info lab (ListGraph blocks) : statics)
777 = return (CmmProc info lab (ListGraph (b':tail blocks)) : statics)
779 where BasicBlock bID insns = head blocks
780 b' = BasicBlock bID (X86.FETCHPC picReg : insns)
782 initializePicBase_x86 _ _ _ _
783 = panic "initializePicBase_x86: not needed"