$OpenBSD: patch-ghc_rts_Linker_c,v 1.4 2003/09/01 20:32:14 espie Exp $
sprintf.
preliminary attempts to get object file loading working, so that
ghci will work. Needs revisiting, to check all lib interfaces

--- ghc/rts/Linker.c.orig	Wed Apr 30 07:37:31 2003
+++ ghc/rts/Linker.c	Sun Jul  6 21:29:55 2003
@@ -59,7 +59,7 @@
 #include <sys/mman.h>
 #endif
 
-#if defined(linux_TARGET_OS) || defined(solaris2_TARGET_OS) || defined(freebsd_TARGET_OS) || defined(netbsd_TARGET_OS)
+#if defined(linux_TARGET_OS) || defined(solaris2_TARGET_OS) || defined(freebsd_TARGET_OS) || defined(netbsd_TARGET_OS) || defined(openbsd_TARGET_OS)
 #  define OBJFORMAT_ELF
 #elif defined(cygwin32_TARGET_OS) || defined (mingw32_TARGET_OS)
 #  define OBJFORMAT_PEi386
@@ -724,7 +724,11 @@
 
    initLinker();
 
+#if !defined(openbsd_TARGET_OS)
    hdl= dlopen(dll_name, RTLD_NOW | RTLD_GLOBAL);
+#else
+   hdl= dlopen(dll_name, RTLD_LAZY);
+#endif
    if (hdl == NULL) {
       /* dlopen failed; return a ptr to the error msg. */
       errmsg = dlerror();
@@ -763,10 +767,10 @@
       	extension. */
 
    buf = stgMallocBytes(strlen(dll_name) + 10, "addDLL");
-   sprintf(buf, "%s.DLL", dll_name);
+   snprintf(buf, strlen(dll_name) + 10, "%s.DLL", dll_name);
    instance = LoadLibrary(buf);
    if (instance == NULL) {
-	 sprintf(buf, "%s.DRV", dll_name);	// KAA: allow loading of drivers (like winspool.drv)
+	 snprintf(buf, strlen(dll_name) + 10, "%s.DRV", dll_name);	// KAA: allow loading of drivers (like winspool.drv)
 	 instance = LoadLibrary(buf);
 	 if (instance == NULL) {
 		stgFree(buf);
@@ -2001,7 +2005,15 @@
 #  define ELF_NEED_PLT      /* needs Procedure Linkage Tables */
 #endif
 
+#if !defined(openbsd_TARGET_OS)
 #include <elf.h>
+#else
+/* openbsd elf has things in different places, with diff names */
+#include <elf_abi.h>
+#include <machine/reloc.h>
+#define R_386_32    RELOC_32
+#define R_386_PC32  RELOC_PC32
+#endif
 
 /*
  * Define a set of types which can be used for both ELF32 and ELF64
