X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FnativeGen%2FPIC.hs;h=a573b6b5db866ae1d552846d2f7b3ca1e7c36aa3;hb=572a047bcf7001a4a2b916cfec618082652f2ae6;hp=6fda1e3f3c4e14bccac3b6d8f479f12c993cea2b;hpb=1d2677930d8de34b37dc2ec0b85d5c212bcea7eb;p=ghc-hetmet.git diff --git a/compiler/nativeGen/PIC.hs b/compiler/nativeGen/PIC.hs index 6fda1e3..a573b6b 100644 --- a/compiler/nativeGen/PIC.hs +++ b/compiler/nativeGen/PIC.hs @@ -64,12 +64,12 @@ import NCGMonad import Cmm -import CLabel ( CLabel, pprCLabel, +import CLabel ( CLabel, ForeignLabelSource(..), pprCLabel, mkDynamicLinkerLabel, DynamicLinkerLabelInfo(..), dynamicLinkerLabelInfo, mkPicBaseLabel, labelDynamic, externallyVisibleCLabel ) -import CLabel ( mkForeignLabel ) +import CLabel ( mkForeignLabel, pprDebugCLabel ) import StaticFlags ( opt_PIC, opt_Static ) @@ -83,6 +83,7 @@ import DynFlags import FastString + -------------------------------------------------------------------------------- -- It gets called by the cmmToCmm pass for every CmmLabel in the Cmm -- code. It does The Right Thing(tm) to convert the CmmLabel into a @@ -110,8 +111,12 @@ cmmMakeDynamicReference -> ReferenceKind -- whether this is the target of a jump -> CLabel -- the label -> m CmmExpr - + cmmMakeDynamicReference dflags addImport referenceKind lbl + = cmmMakeDynamicReference' dflags addImport referenceKind lbl + + +cmmMakeDynamicReference' dflags addImport referenceKind lbl | Just _ <- dynamicLinkerLabelInfo lbl = return $ CmmLit $ CmmLabel lbl -- already processed it, pass through @@ -192,16 +197,40 @@ data LabelAccessStyle howToAccessLabel :: DynFlags -> Arch -> OS -> ReferenceKind -> CLabel -> LabelAccessStyle + -- Windows --- --- We need to use access *exactly* those things that --- are imported from a DLL via an __imp_* label. --- There are no stubs for imported code. +-- In Windows speak, a "module" is a set of objects linked into the +-- same Portable Exectuable (PE) file. (both .exe and .dll files are PEs). +-- +-- If we're compiling a multi-module program then symbols from other modules +-- are accessed by a symbol pointer named __imp_SYMBOL. At runtime we have the +-- following. +-- +-- (in the local module) +-- __imp_SYMBOL: addr of SYMBOL +-- +-- (in the other module) +-- SYMBOL: the real function / data. +-- +-- To access the function at SYMBOL from our local module, we just need to +-- dereference the local __imp_SYMBOL. +-- +-- If opt_Static is set then we assume that all our code will be linked +-- into the same .exe file. In this case we always access symbols directly, +-- and never use __imp_SYMBOL. -- howToAccessLabel dflags _ OSMinGW32 _ lbl + + -- Assume all symbols will be in the same PE, so just access them directly. + | opt_Static + = AccessDirectly + + -- If the target symbol is in another PE we need to access it via the + -- appropriate __imp_SYMBOL pointer. | labelDynamic (thisPackage dflags) lbl = AccessViaSymbolPtr + -- Target symbol is in the same PE as the caller, so just access it directly. | otherwise = AccessDirectly @@ -426,8 +455,10 @@ needImportedSymbols arch os -- position-independent code. gotLabel :: CLabel gotLabel - = mkForeignLabel -- HACK: it's not really foreign - (fsLit ".LCTOC1") Nothing False IsData + -- HACK: this label isn't really foreign + = mkForeignLabel + (fsLit ".LCTOC1") + Nothing ForeignLabelInThisPackage IsData @@ -445,9 +476,8 @@ pprGotDeclaration ArchX86 OSDarwin ptext (sLit "\tmovl (%esp), %eax"), ptext (sLit "\tret") ] - | otherwise - = empty - +pprGotDeclaration _ OSDarwin + = Pretty.empty -- pprGotDeclaration -- Output whatever needs to be output once per .s file.