Fix building of the RTS with the NCG under Windows
authorBen.Lippmeier@anu.edu.au <unknown>
Sat, 26 Sep 2009 07:55:07 +0000 (07:55 +0000)
committerBen.Lippmeier@anu.edu.au <unknown>
Sat, 26 Sep 2009 07:55:07 +0000 (07:55 +0000)
compiler/nativeGen/PIC.hs
rts/ghc.mk

index 74c8bb3..eb233e0 100644 (file)
@@ -192,16 +192,40 @@ data LabelAccessStyle
 howToAccessLabel 
        :: DynFlags -> Arch -> OS -> ReferenceKind -> CLabel -> LabelAccessStyle
 
 howToAccessLabel 
        :: DynFlags -> Arch -> OS -> ReferenceKind -> CLabel -> LabelAccessStyle
 
+
 -- Windows
 -- 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
 --
 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
 
        | labelDynamic (thisPackage dflags) lbl 
        = AccessViaSymbolPtr
 
+       -- Target symbol is in the same PE as the caller, so just access it directly.
        | otherwise
        = AccessDirectly
 
        | otherwise
        = AccessDirectly
 
index 970adaa..3a746a9 100644 (file)
@@ -173,12 +173,6 @@ ifeq "$(UseLibFFIForAdjustors)" "YES"
 rts_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
 endif
 
 rts_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
 endif
 
-ifeq "$(Windows)" "YES"
-# SDM: when compiled with -fasm the RTS currently has bogus references to 
-# __imp_base_ things, so working around for now:
-rts_HC_OPTS += -fvia-C
-endif
-
 ifneq "$(DYNAMIC_RTS)" "YES"
 rts_HC_OPTS += -static
 else
 ifneq "$(DYNAMIC_RTS)" "YES"
 rts_HC_OPTS += -static
 else