/* -----------------------------------------------------------------------------
- * $Id: Linker.c,v 1.115 2003/02/21 05:34:15 sof Exp $
+ * $Id: Linker.c,v 1.120 2003/05/30 09:06:24 simonmar Exp $
*
- * (c) The GHC Team, 2000, 2001
+ * (c) The GHC Team, 2000-2003
*
* RTS Object Linker
*
#include <sys/mman.h>
#endif
-#if defined(linux_TARGET_OS) || defined(solaris2_TARGET_OS) || defined(freebsd_TARGET_OS)
+#if defined(linux_TARGET_OS) || defined(solaris2_TARGET_OS) || defined(freebsd_TARGET_OS) || defined(netbsd_TARGET_OS)
# define OBJFORMAT_ELF
#elif defined(cygwin32_TARGET_OS) || defined (mingw32_TARGET_OS)
# define OBJFORMAT_PEi386
static int ocGetNames_MachO ( ObjectCode* oc );
static int ocResolve_MachO ( ObjectCode* oc );
-static void machoInitSymbolsWithoutUnderscore();
+static void machoInitSymbolsWithoutUnderscore( void );
#endif
/* -----------------------------------------------------------------------------
SymX(uname) \
SymX(unlink) \
SymX(utime) \
- SymX(waitpid) \
- Sym(__divdi3) \
- Sym(__udivdi3) \
- Sym(__moddi3) \
- Sym(__umoddi3)
+ SymX(waitpid)
#elif !defined(mingw32_TARGET_OS)
#define RTS_MINGW_ONLY_SYMBOLS /**/
#define RTS_POSIX_ONLY_SYMBOLS /**/
#define RTS_CYGWIN_ONLY_SYMBOLS /**/
+/* Extra syms gen'ed by mingw-2's gcc-3.2: */
+#if __GNUC__>=3
+#define RTS_MINGW_EXTRA_SYMS \
+ Sym(_imp____mb_cur_max) \
+ Sym(_imp___pctype)
+#else
+#define RTS_MINGW_EXTRA_SYMS
+#endif
+
/* These are statically linked from the mingw libraries into the ghc
executable, so we have to employ this hack. */
#define RTS_MINGW_ONLY_SYMBOLS \
Sym(opendir) \
Sym(readdir) \
Sym(rewinddir) \
- Sym(closedir) \
- Sym(__divdi3) \
- Sym(__udivdi3) \
- Sym(__moddi3) \
- Sym(__umoddi3)
+ RTS_MINGW_EXTRA_SYMS \
+ Sym(closedir)
#endif
#ifndef SMP
#define RTS_LONG_LONG_SYMS /* nothing */
#endif
-#ifdef ia64_TARGET_ARCH
-/* force these symbols to be present */
-#define RTS_EXTRA_SYMBOLS \
- Sym(__divsf3)
-#elif defined(powerpc_TARGET_ARCH)
-#define RTS_EXTRA_SYMBOLS \
+// 64-bit support functions in libgcc.a
+#if defined(__GNUC__) && SIZEOF_VOID_P <= 4
+#define RTS_LIBGCC_SYMBOLS \
Sym(__divdi3) \
Sym(__udivdi3) \
Sym(__moddi3) \
Sym(__ashrdi3) \
Sym(__lshrdi3) \
Sym(__eprintf)
-
+#else
+#define RTS_LIBGCC_SYMBOLS
+#endif
+
+#ifdef ia64_TARGET_ARCH
+/* force these symbols to be present */
+#define RTS_EXTRA_SYMBOLS \
+ Sym(__divsf3)
+#else
+#define RTS_EXTRA_SYMBOLS /* nothing */
+#endif
+
+#ifdef darwin_TARGET_OS
// Symbols that don't have a leading underscore
// on Mac OS X. They have to receive special treatment,
// see machoInitSymbolsWithoutUnderscore()
#define RTS_MACHO_NOUNDERLINE_SYMBOLS \
Sym(saveFP) \
Sym(restFP)
-#else
-#define RTS_EXTRA_SYMBOLS /* nothing */
#endif
/* entirely bogus claims about types of these symbols */
RTS_POSIX_ONLY_SYMBOLS
RTS_MINGW_ONLY_SYMBOLS
RTS_CYGWIN_ONLY_SYMBOLS
+RTS_LIBGCC_SYMBOLS
#undef Sym
#undef SymX
#undef SymX_redirect
RTS_POSIX_ONLY_SYMBOLS
RTS_MINGW_ONLY_SYMBOLS
RTS_CYGWIN_ONLY_SYMBOLS
+ RTS_LIBGCC_SYMBOLS
{ 0, 0 } /* sentinel */
};
sprintf(buf, "%s.DRV", dll_name); // KAA: allow loading of drivers (like winspool.drv)
instance = LoadLibrary(buf);
if (instance == NULL) {
- free(buf);
+ stgFree(buf);
/* LoadLibrary failed; return a ptr to the error msg. */
return "addDLL: unknown error";
}
}
- free(buf);
+ stgFree(buf);
/* Add this DLL to the list of DLLs in which to search for symbols. */
o_dll = stgMallocBytes( sizeof(OpenedDLL), "addDLL" );
# elif defined(OBJFORMAT_MACHO)
oc->formatName = "Mach-O";
# else
- free(oc);
+ stgFree(oc);
barf("loadObj: not implemented on this platform");
# endif
/* We're going to leave this in place, in case there are
any pointers from the heap into it: */
- /* free(oc->image); */
- free(oc->fileName);
- free(oc->symbols);
- free(oc->sections);
+ /* stgFree(oc->image); */
+ stgFree(oc->fileName);
+ stgFree(oc->symbols);
+ stgFree(oc->sections);
/* The local hash table should have been freed at the end
of the ocResolve_ call on it. */
ASSERT(oc->lochash == NULL);
- free(oc);
+ stgFree(oc);
return 1;
}
}