summaryrefslogtreecommitdiff
path: root/rts
diff options
context:
space:
mode:
authorClemens Fruhwirth <clemens@endorphin.org>2007-08-08 06:50:43 +0000
committerClemens Fruhwirth <clemens@endorphin.org>2007-08-08 06:50:43 +0000
commit006a18ea83799c0d4255071a2f8c08d3e9c7d84f (patch)
treebf73abdd6f0d50df5dc991a0d8c39d6c6a8a1be6 /rts
parent90ef8ab26efb2fc4172944f1066f122d3a6e7c7d (diff)
downloadhaskell-006a18ea83799c0d4255071a2f8c08d3e9c7d84f.tar.gz
Build RTS as dynamic library
Diffstat (limited to 'rts')
-rw-r--r--rts/Linker.c8
-rw-r--r--rts/Makefile73
-rw-r--r--rts/Prelude.h94
-rw-r--r--rts/RetainerProfile.c3
-rw-r--r--rts/RtsDllMain.c5
-rw-r--r--rts/StgMiscClosures.cmm2
-rw-r--r--rts/sm/Scav.c2
7 files changed, 89 insertions, 98 deletions
diff --git a/rts/Linker.c b/rts/Linker.c
index 672828c424..6d5a8cf021 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -766,7 +766,7 @@ typedef struct _RtsSymbolVal {
/* entirely bogus claims about types of these symbols */
#define Sym(vvv) extern void vvv(void);
-#ifdef ENABLE_WIN32_DLL_SUPPORT
+#if defined(__PIC__) && defined(mingw32_TARGET_OS)
#define SymExtern(vvv) extern void _imp__ ## vvv (void);
#else
#define SymExtern(vvv) SymX(vvv)
@@ -795,12 +795,8 @@ RTS_LIBGCC_SYMBOLS
#define Sym(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
(void*)(&(vvv)) },
#define SymX(vvv) Sym(vvv)
-#ifdef ENABLE_WIN32_DLL_SUPPORT
#define SymExtern(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
- (void*)(_imp__ ## vvv) },
-#else
-#define SymExtern(vvv) Sym(vvv)
-#endif
+ (void*)DLL_IMPORT_DATA_REF(vvv) },
// SymX_redirect allows us to redirect references to one symbol to
// another symbol. See newCAF/newDynCAF for an example.
diff --git a/rts/Makefile b/rts/Makefile
index 7b17ce3b86..6e8ca5401e 100644
--- a/rts/Makefile
+++ b/rts/Makefile
@@ -49,10 +49,20 @@ else
ALL_DIRS += posix
endif
-ifneq "$(DLLized)" "YES"
-EXCLUDED_SRCS += RtsDllMain.c
+ifneq "$(findstring dyn, $(way))" ""
+DYNAMIC_RTS=YES
else
+DYNAMIC_RTS=NO
+endif
+
+ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
EXCLUDED_SRCS += Main.c
+# It's not included in the DLL, but we need to compile it up separately.
+
+all :: Main.$(way_)o
+INSTALL_LIBS += Main.$(way_)o
+else
+EXCLUDED_SRCS += RtsDllMain.c
endif
# This file ends up being empty unless we're building for a powerpc
@@ -114,17 +124,29 @@ SRC_CC_OPTS += $(WARNING_OPTS)
SRC_CC_OPTS += $(STANDARD_OPTS)
SRC_CC_OPTS += $(GhcRtsCcOpts)
-SRC_HC_OPTS += $(GhcRtsHcOpts)
+SRC_HC_OPTS += $(GhcRtsHcOpts) -package-name rts
ifneq "$(GhcWithSMP)" "YES"
SRC_CC_OPTS += -DNOSMP
SRC_HC_OPTS += -optc-DNOSMP
endif
-ifneq "$(DLLized)" "YES"
+ifneq "$(DYNAMIC_RTS)" "YES"
SRC_HC_OPTS += -static
+else
+LIB_LD_OPTS += -ignore-package base -ignore-package rts
+ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
+BASE_VERSION=$(strip $(shell grep version: $(TOP)/libraries/base/base.cabal | cut -f2 -d:))
+BASE_NAME=HSbase-$(BASE_VERSION)-ghc$(ProjectVersion)$(soext)
+BASE_DIST_LIB=$(TOP)/libraries/base/dist/build
+BASE_IMPORT_LIBRARY=$(BASE_DIST_LIB)/lib$(BASE_NAME).a
+LIB_DEPS=$(BASE_IMPORT_LIBRARY)
+LIB_LD_OPTS += -L$(BASE_DIST_LIB) -l$(BASE_NAME)
+# We extract a good bit of information out of the rts package.conf by going via ghc-pkg
+LIB_LD_OPTS += $(foreach lib,$(shell $(GHC_PKG_INPLACE) field rts extra-libraries | sed -e s/extra-libraries://),"-l$(lib)")
+LIB_LD_OPTS += $(foreach libdir,$(shell $(GHC_PKG_INPLACE) field rts library-dirs | sed -e s/library-dirs://),"-L$(libdir)")
+endif
endif
-# SRC_HC_OPTS += -fPIC
RtsMessages_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
RtsFlags_CC_OPTS += -DProjectVersion=\"$(ProjectVersion)\"
@@ -228,31 +250,6 @@ CLEAN_FILES += $(AUTO_APPLY_CMM)
endif
# -----------------------------------------------------------------------------
-#
-# Building DLLs is only supported on mingw32 at the moment.
-#
-ifeq "$(DLLized)" "YES"
-SRC_BLD_DLL_OPTS += -lHS_imp_stub -lgmp_imp
-
-# It's not included in the DLL, but we need to compile it up separately.
-all :: Main.dll_o
-
-# Need an import library containing the symbols the RTS uses from the Prelude.
-# So, to avoid bootstrapping trouble, we build one containing just the syms
-# we need. Weirdly named to avoid clashing later on when compiling the contents
-# of ghc/lib/..
-#
-# Note: if you do change the name of the Prelude DLL, the "--dllname <nm>.dll"
-# below will need to be updated as well.
-
-$(DLL_PEN)/HSrts$(_way).dll :: libHS_imp_stub.a
-
-libHS_imp_stub.a :
- dlltool --output-lib libHS_imp_stub.a --def HSprel.def --dllname HSstd.dll
-
-endif
-
-# -----------------------------------------------------------------------------
# Compile GMP only if we don't have it already
#
# We use GMP's own configuration stuff, because it's all rather hairy
@@ -336,9 +333,6 @@ sm/Compact_HC_OPTS += -optc-finline-limit=2500
# upd_evacee() assigments get moved before the object copy.
SRC_CC_OPTS += -fno-strict-aliasing
-# Cmm must be compiled via-C for now, because the NCG can't handle loops
-SRC_HC_OPTS += -fvia-C
-
# We *want* type-checking of hand-written cmm.
SRC_HC_OPTS += -dcmm-lint
@@ -362,17 +356,20 @@ endif
#
# Just libHSrts is installed uniformly across ways
#
-ifeq "$(DLLized)" "YES"
-INSTALL_PROGS += gmp/gmp.dll
-INSTALL_LIBS += gmp/libgmp_imp.a Main.dll_o
+
+include $(TOP)/mk/target.mk
+
+ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
+$(BASE_IMPORT_LIBRARY): $(LIBRARY).a
+ $(MAKE) -C ../libraries/ make.library.base
+# just for the timestamps
+ touch $(BASE_IMPORT_LIBRARY)
endif
#-----------------------------------------------------------------------------
#
# binary-dist
-include $(TOP)/mk/target.mk
-
binary-dist:
$(INSTALL_DIR) $(BIN_DIST_DIR)/rts
$(INSTALL_DIR) $(BIN_DIST_DIR)/rts/gmp
diff --git a/rts/Prelude.h b/rts/Prelude.h
index 2a6ca9158d..31fe136d36 100644
--- a/rts/Prelude.h
+++ b/rts/Prelude.h
@@ -16,8 +16,8 @@
#define PRELUDE_INFO(i) extern W_(i)[]
#define PRELUDE_CLOSURE(i) extern W_(i)[]
#else
-#define PRELUDE_INFO(i) extern DLL_IMPORT const StgInfoTable i
-#define PRELUDE_CLOSURE(i) extern DLL_IMPORT StgClosure i
+#define PRELUDE_INFO(i) extern const StgInfoTable DLL_IMPORT_DATA_VARNAME(i)
+#define PRELUDE_CLOSURE(i) extern StgClosure DLL_IMPORT_DATA_VARNAME(i)
#endif
/* Define canonical names so we can abstract away from the actual
@@ -79,53 +79,53 @@ PRELUDE_INFO(base_GHCziWord_W64zh_con_info);
PRELUDE_INFO(base_GHCziStable_StablePtr_static_info);
PRELUDE_INFO(base_GHCziStable_StablePtr_con_info);
-#define True_closure (&base_GHCziBase_True_closure)
-#define False_closure (&base_GHCziBase_False_closure)
-#define unpackCString_closure (&base_GHCziPack_unpackCString_closure)
-#define runFinalizerBatch_closure (&base_GHCziWeak_runFinalizzerBatch_closure)
+#define True_closure DLL_IMPORT_DATA_REF(base_GHCziBase_True_closure)
+#define False_closure DLL_IMPORT_DATA_REF(base_GHCziBase_False_closure)
+#define unpackCString_closure DLL_IMPORT_DATA_REF(base_GHCziPack_unpackCString_closure)
+#define runFinalizerBatch_closure DLL_IMPORT_DATA_REF(base_GHCziWeak_runFinalizzerBatch_closure)
#define mainIO_closure (&ZCMain_main_closure)
-#define stackOverflow_closure (&base_GHCziIOBase_stackOverflow_closure)
-#define heapOverflow_closure (&base_GHCziIOBase_heapOverflow_closure)
-#define BlockedOnDeadMVar_closure (&base_GHCziIOBase_BlockedOnDeadMVar_closure)
-#define BlockedIndefinitely_closure (&base_GHCziIOBase_BlockedIndefinitely_closure)
-#define NonTermination_closure (&base_GHCziIOBase_NonTermination_closure)
-#define NestedAtomically_closure (&base_GHCziIOBase_NestedAtomically_closure)
+#define stackOverflow_closure DLL_IMPORT_DATA_REF(base_GHCziIOBase_stackOverflow_closure)
+#define heapOverflow_closure DLL_IMPORT_DATA_REF(base_GHCziIOBase_heapOverflow_closure)
+#define BlockedOnDeadMVar_closure DLL_IMPORT_DATA_REF(base_GHCziIOBase_BlockedOnDeadMVar_closure)
+#define BlockedIndefinitely_closure DLL_IMPORT_DATA_REF(base_GHCziIOBase_BlockedIndefinitely_closure)
+#define NonTermination_closure DLL_IMPORT_DATA_REF(base_GHCziIOBase_NonTermination_closure)
+#define NestedAtomically_closure DLL_IMPORT_DATA_REF(base_GHCziIOBase_NestedAtomically_closure)
-#define Czh_static_info (&base_GHCziBase_Czh_static_info)
-#define Fzh_static_info (&base_GHCziFloat_Fzh_static_info)
-#define Dzh_static_info (&base_GHCziFloat_Dzh_static_info)
-#define Azh_static_info (&base_Addr_Azh_static_info)
-#define Izh_static_info (&base_GHCziBase_Izh_static_info)
-#define I8zh_static_info (&base_GHCziInt_I8zh_static_info)
-#define I16zh_static_info (&base_GHCziInt_I16zh_static_info)
-#define I32zh_static_info (&base_GHCziInt_I32zh_static_info)
-#define I64zh_static_info (&base_GHCziInt_I64zh_static_info)
-#define Wzh_static_info (&base_GHCziWord_Wzh_static_info)
-#define W8zh_static_info (&base_GHCziWord_W8zh_static_info)
-#define W16zh_static_info (&base_GHCziWord_W16zh_static_info)
-#define W32zh_static_info (&base_GHCziWord_W32zh_static_info)
-#define W64zh_static_info (&base_GHCziWord_W64zh_static_info)
-#define Ptr_static_info (&base_GHCziPtr_Ptr_static_info)
-#define FunPtr_static_info (&base_GHCziPtr_FunPtr_static_info)
-#define Czh_con_info (&base_GHCziBase_Czh_con_info)
-#define Izh_con_info (&base_GHCziBase_Izh_con_info)
-#define Fzh_con_info (&base_GHCziFloat_Fzh_con_info)
-#define Dzh_con_info (&base_GHCziFloat_Dzh_con_info)
-#define Azh_con_info (&base_Addr_Azh_con_info)
-#define Wzh_con_info (&base_GHCziWord_Wzh_con_info)
-#define W8zh_con_info (&base_GHCziWord_W8zh_con_info)
-#define W16zh_con_info (&base_GHCziWord_W16zh_con_info)
-#define W32zh_con_info (&base_GHCziWord_W32zh_con_info)
-#define W64zh_con_info (&base_GHCziWord_W64zh_con_info)
-#define I8zh_con_info (&base_GHCziInt_I8zh_con_info)
-#define I16zh_con_info (&base_GHCziInt_I16zh_con_info)
-#define I32zh_con_info (&base_GHCziInt_I32zh_con_info)
-#define I64zh_con_info (&base_GHCziInt_I64zh_con_info)
-#define I64zh_con_info (&base_GHCziInt_I64zh_con_info)
-#define Ptr_con_info (&base_GHCziPtr_Ptr_con_info)
-#define FunPtr_con_info (&base_GHCziPtr_FunPtr_con_info)
-#define StablePtr_static_info (&base_GHCziStable_StablePtr_static_info)
-#define StablePtr_con_info (&base_GHCziStable_StablePtr_con_info)
+#define Czh_static_info DLL_IMPORT_DATA_REF(base_GHCziBase_Czh_static_info)
+#define Fzh_static_info DLL_IMPORT_DATA_REF(base_GHCziFloat_Fzh_static_info)
+#define Dzh_static_info DLL_IMPORT_DATA_REF(base_GHCziFloat_Dzh_static_info)
+#define Azh_static_info DLL_IMPORT_DATA_REF(base_Addr_Azh_static_info)
+#define Izh_static_info DLL_IMPORT_DATA_REF(base_GHCziBase_Izh_static_info)
+#define I8zh_static_info DLL_IMPORT_DATA_REF(base_GHCziInt_I8zh_static_info)
+#define I16zh_static_info DLL_IMPORT_DATA_REF(base_GHCziInt_I16zh_static_info)
+#define I32zh_static_info DLL_IMPORT_DATA_REF(base_GHCziInt_I32zh_static_info)
+#define I64zh_static_info DLL_IMPORT_DATA_REF(base_GHCziInt_I64zh_static_info)
+#define Wzh_static_info DLL_IMPORT_DATA_REF(base_GHCziWord_Wzh_static_info)
+#define W8zh_static_info DLL_IMPORT_DATA_REF(base_GHCziWord_W8zh_static_info)
+#define W16zh_static_info DLL_IMPORT_DATA_REF(base_GHCziWord_W16zh_static_info)
+#define W32zh_static_info DLL_IMPORT_DATA_REF(base_GHCziWord_W32zh_static_info)
+#define W64zh_static_info DLL_IMPORT_DATA_REF(base_GHCziWord_W64zh_static_info)
+#define Ptr_static_info DLL_IMPORT_DATA_REF(base_GHCziPtr_Ptr_static_info)
+#define FunPtr_static_info DLL_IMPORT_DATA_REF(base_GHCziPtr_FunPtr_static_info)
+#define Czh_con_info DLL_IMPORT_DATA_REF(base_GHCziBase_Czh_con_info)
+#define Izh_con_info DLL_IMPORT_DATA_REF(base_GHCziBase_Izh_con_info)
+#define Fzh_con_info DLL_IMPORT_DATA_REF(base_GHCziFloat_Fzh_con_info)
+#define Dzh_con_info DLL_IMPORT_DATA_REF(base_GHCziFloat_Dzh_con_info)
+#define Azh_con_info DLL_IMPORT_DATA_REF(base_Addr_Azh_con_info)
+#define Wzh_con_info DLL_IMPORT_DATA_REF(base_GHCziWord_Wzh_con_info)
+#define W8zh_con_info DLL_IMPORT_DATA_REF(base_GHCziWord_W8zh_con_info)
+#define W16zh_con_info DLL_IMPORT_DATA_REF(base_GHCziWord_W16zh_con_info)
+#define W32zh_con_info DLL_IMPORT_DATA_REF(base_GHCziWord_W32zh_con_info)
+#define W64zh_con_info DLL_IMPORT_DATA_REF(base_GHCziWord_W64zh_con_info)
+#define I8zh_con_info DLL_IMPORT_DATA_REF(base_GHCziInt_I8zh_con_info)
+#define I16zh_con_info DLL_IMPORT_DATA_REF(base_GHCziInt_I16zh_con_info)
+#define I32zh_con_info DLL_IMPORT_DATA_REF(base_GHCziInt_I32zh_con_info)
+#define I64zh_con_info DLL_IMPORT_DATA_REF(base_GHCziInt_I64zh_con_info)
+#define I64zh_con_info DLL_IMPORT_DATA_REF(base_GHCziInt_I64zh_con_info)
+#define Ptr_con_info DLL_IMPORT_DATA_REF(base_GHCziPtr_Ptr_con_info)
+#define FunPtr_con_info DLL_IMPORT_DATA_REF(base_GHCziPtr_FunPtr_con_info)
+#define StablePtr_static_info DLL_IMPORT_DATA_REF(base_GHCziStable_StablePtr_static_info)
+#define StablePtr_con_info DLL_IMPORT_DATA_REF(base_GHCziStable_StablePtr_con_info)
#endif /* PRELUDE_H */
diff --git a/rts/RetainerProfile.c b/rts/RetainerProfile.c
index 2613b9e4bc..553f7e7ad1 100644
--- a/rts/RetainerProfile.c
+++ b/rts/RetainerProfile.c
@@ -364,8 +364,7 @@ find_srt( stackPos *info )
bitmap = info->next.srt.srt_bitmap;
while (bitmap != 0) {
if ((bitmap & 1) != 0) {
-#ifdef ENABLE_WIN32_DLL_SUPPORT
-
+#if defined(__PIC__) && defined(mingw32_TARGET_OS)
if ((unsigned long)(*(info->next.srt.srt)) & 0x1)
c = (* (StgClosure **)((unsigned long)*(info->next.srt.srt)) & ~0x1);
else
diff --git a/rts/RtsDllMain.c b/rts/RtsDllMain.c
index af3c5090de..250b63ea68 100644
--- a/rts/RtsDllMain.c
+++ b/rts/RtsDllMain.c
@@ -15,8 +15,7 @@
#endif
/* I'd be mildly surprised if this wasn't defined, but still. */
-#ifdef ENABLE_WIN32_DLL_SUPPORT
-
+#if defined(__PIC__) && defined(mingw32_TARGET_OS)
BOOL
WINAPI
DllMain ( HINSTANCE hInstance
@@ -36,4 +35,4 @@ DllMain ( HINSTANCE hInstance
return TRUE;
}
-#endif /* ENABLE_WIN32_DLL_SUPPORT */
+#endif /* defined(__PIC__) && defined(mingw32_TARGET_OS) */
diff --git a/rts/StgMiscClosures.cmm b/rts/StgMiscClosures.cmm
index 58cbaf9d56..ebf9e922ae 100644
--- a/rts/StgMiscClosures.cmm
+++ b/rts/StgMiscClosures.cmm
@@ -592,7 +592,7 @@ CLOSURE(stg_dummy_ret_closure,stg_dummy_ret);
replace them with references to the static objects.
------------------------------------------------------------------------- */
-#if defined(ENABLE_WIN32_DLL_SUPPORT)
+#if defined(__PIC__) && defined(mingw32_TARGET_OS)
/*
* When sticking the RTS in a DLL, we delay populating the
* Charlike and Intlike tables until load-time, which is only
diff --git a/rts/sm/Scav.c b/rts/sm/Scav.c
index f211401b05..00faff1d84 100644
--- a/rts/sm/Scav.c
+++ b/rts/sm/Scav.c
@@ -77,7 +77,7 @@ scavenge_srt (StgClosure **srt, nat srt_bitmap)
while (bitmap != 0) {
if ((bitmap & 1) != 0) {
-#ifdef ENABLE_WIN32_DLL_SUPPORT
+#if defined(__PIC__) && defined(mingw32_TARGET_OS)
// Special-case to handle references to closures hiding out in DLLs, since
// double indirections required to get at those. The code generator knows
// which is which when generating the SRT, so it stores the (indirect)