X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FnativeGen%2FPIC.hs;h=eb233e0459d1fbc9ba74a270e1417df701c5686f;hb=e5fba2f55f560b41e27047bf59958729d51aca84;hp=98e4f9f2d58f47e85cce39fa213f8323e86829eb;hpb=b04a210e26ca57242fd052f2aa91011a80b76299;p=ghc-hetmet.git diff --git a/compiler/nativeGen/PIC.hs b/compiler/nativeGen/PIC.hs index 98e4f9f..eb233e0 100644 --- a/compiler/nativeGen/PIC.hs +++ b/compiler/nativeGen/PIC.hs @@ -192,16 +192,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 @@ -300,9 +324,9 @@ howToAccessLabel dflags arch OSLinux DataReference lbl -- In most cases, we have to avoid symbol stubs on ELF, for the following reasons: - -- * on i386, the position-independent symbol stubs in the Procedure Linkage Table + -- on i386, the position-independent symbol stubs in the Procedure Linkage Table -- require the address of the GOT to be loaded into register %ebx on entry. - -- * The linker will take any reference to the symbol stub as a hint that + -- The linker will take any reference to the symbol stub as a hint that -- the label in question is a code label. When linking executables, this -- will cause the linker to replace even data references to the label with -- references to the symbol stub. @@ -445,9 +469,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.