/* -----------------------------------------------------------------------------
- * $Id: Linker.c,v 1.146 2004/03/22 11:06:18 simonmar Exp $
+ * $Id: Linker.c,v 1.147 2004/05/15 15:35:47 dons Exp $
*
* (c) The GHC Team, 2000-2003
*
#include <sys/wait.h>
#endif
-#if defined(ia64_TARGET_ARCH)
+#if defined(ia64_TARGET_ARCH) || defined(openbsd_TARGET_OS)
#define USE_MMAP
#include <fcntl.h>
#include <sys/mman.h>
+
+#if defined(openbsd_TARGET_OS)
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#endif
+
#endif
#if defined(linux_TARGET_OS) || defined(solaris2_TARGET_OS) || defined(freebsd_TARGET_OS) || defined(netbsd_TARGET_OS) || defined(openbsd_TARGET_OS)
static void *dl_prog_handle;
#endif
+/* dlopen(NULL,..) doesn't work so we grab libc explicitly */
+#if defined(openbsd_TARGET_OS)
+static void *dl_libc_handle;
+#endif
+
void
initLinker( void )
{
dl_prog_handle = RTLD_DEFAULT;
# else
dl_prog_handle = dlopen(NULL, RTLD_LAZY);
+# if defined(openbsd_TARGET_OS)
+ dl_libc_handle = dlopen("libc.so", RTLD_LAZY);
+# endif
# endif // RTLD_DEFAULT
# endif
}
if (val == NULL) {
# if defined(OBJFORMAT_ELF)
+# if defined(openbsd_TARGET_OS)
+ val = dlsym(dl_prog_handle, lbl);
+ return (val != NULL) ? val : dlsym(dl_libc_handle,lbl);
+# else /* not openbsd */
return dlsym(dl_prog_handle, lbl);
+# endif
# elif defined(OBJFORMAT_MACHO)
if(NSIsSymbolNameDefined(lbl)) {
NSSymbol symbol = NSLookupAndBindSymbol(lbl);
/* On many architectures malloc'd memory isn't executable, so we need to use mmap. */
+#if defined(openbsd_TARGET_OS)
+ fd = open(path, O_RDONLY, S_IRUSR);
+#else
fd = open(path, O_RDONLY);
+#endif
if (fd == -1)
barf("loadObj: can't open `%s'", path);