[project @ 2001-06-22 12:35:28 by rrt]
[ghc-hetmet.git] / ghc / rts / Linker.c
index b0bafde..8589a4a 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Linker.c,v 1.40 2001/05/15 15:29:03 sewardj Exp $
+ * $Id: Linker.c,v 1.44 2001/06/22 12:35:28 rrt Exp $
  *
  * (c) The GHC Team, 2000
  *
@@ -81,6 +81,22 @@ typedef struct _RtsSymbolVal {
 
 #define RTS_POSIX_ONLY_SYMBOLS
 #define RTS_MINGW_ONLY_SYMBOLS                  \
+      SymX(abort)                               \
+      Sym(_alloca)                              \
+      Sym(isxdigit)                             \
+      Sym(isupper)                              \
+      Sym(ispunct)                              \
+      Sym(islower)                              \
+      Sym(isspace)                              \
+      Sym(isprint)                              \
+      Sym(isdigit)                              \
+      Sym(iscntrl)                              \
+      Sym(isalpha)                              \
+      Sym(isalnum)                              \
+      SymX(memset)                              \
+      SymX(strncpy)                             \
+      SymX(strcpy)                              \
+      SymX(strcmp)                              \
       Sym(mktime)                               \
       Sym(gmtime)                               \
       Sym(strftime)                             \
@@ -137,6 +153,7 @@ typedef struct _RtsSymbolVal {
       Sym(stg_gc_f1)                           \
       Sym(stg_gc_ut_1_0)                       \
       Sym(stg_gc_ut_0_1)                       \
+      Sym(stg_gc_unpt_r1)                      \
       Sym(stg_gc_unbx_r1)                      \
       Sym(stg_chk_0)                           \
       Sym(stg_chk_1)                           \
@@ -422,15 +439,20 @@ static OpenedDLL* opened_dlls = NULL;
 
 
 char*
-addDLL ( char* dll_name )
+addDLL ( char* path, char* dll_name )
 {
 #  if defined(OBJFORMAT_ELF)
    void *hdl;
    char *buf;
    char *errmsg;
 
-   buf = stgMallocBytes(strlen(dll_name) + 10, "addDll");
-   sprintf(buf, "lib%s.so", dll_name);
+   if (path == NULL || strlen(path) == 0) {
+      buf = stgMallocBytes(strlen(dll_name) + 10, "addDll");
+      sprintf(buf, "lib%s.so", dll_name);
+   } else {
+      buf = stgMallocBytes(strlen(path) + 1 + strlen(dll_name) + 10, "addDll");
+      sprintf(buf, "%s/lib%s.so", path, dll_name);
+   }
    hdl = dlopen(buf, RTLD_NOW | RTLD_GLOBAL );
    free(buf);
    if (hdl == NULL) {
@@ -444,26 +466,42 @@ addDLL ( char* dll_name )
    ASSERT(0); /*NOTREACHED*/
 #  elif defined(OBJFORMAT_PEi386)
 
-   HINSTANCE instance;
-   char* buf;
-   char* errmsg;
+   /* Add this DLL to the list of DLLs in which to search for symbols.
+      The first time through, also add the executable to the list,
+      since we need to search that too.  The path argument is ignored. */
+   char*      buf;
    OpenedDLL* o_dll;
-
+   HINSTANCE  instance;
    /* fprintf(stderr, "addDLL %s\n", dll_name ); */
+
+#if 0
+   /* Later ... can't figure out why this doesn't work.  So retain the
+      RTS_MINGW_ONLY_SYMBOLS hack for the time being.  */
+   if (opened_dlls == NULL) {
+      /* First time through ... */
+      instance = GetModuleHandle(NULL);
+      if (instance == NULL)
+         return "addDLL: can't get handle to the executable";
+      o_dll = stgMallocBytes( sizeof(OpenedDLL), "addDLL-init" );
+      o_dll->instance = instance;
+      o_dll->next     = opened_dlls;
+      opened_dlls     = o_dll;
+   }
+#endif
+
    buf = stgMallocBytes(strlen(dll_name) + 10, "addDll");
    sprintf(buf, "%s.DLL", dll_name);
    instance = LoadLibrary(buf);
    free(buf);
    if (instance == NULL) {
      /* LoadLibrary failed; return a ptr to the error msg. */
-     errmsg = "addDLL: unknown error";
-     return errmsg;
+     return "addDLL: unknown error";
    }
 
    o_dll = stgMallocBytes( sizeof(OpenedDLL), "addDLL" );
    o_dll->instance = instance;
-   o_dll->next = opened_dlls;
-   opened_dlls = o_dll;
+   o_dll->next     = opened_dlls;
+   opened_dlls     = o_dll;
 
    return NULL;
 #  else
@@ -1166,7 +1204,7 @@ ocGetNames_PEi386 ( ObjectCode* oc )
       COFF_section* sectab_i
          = (COFF_section*)
            myindex ( sizeof_COFF_section, sectab, i );
-      IF_DEBUG(linker, belchf("section name = %s\n", sectab_i->Name ));
+      IF_DEBUG(linker, belch("section name = %s\n", sectab_i->Name ));
 
 #if 0
       /* I'm sure this is the Right Way to do it.  However, the