[commit: ghc] master: Win64 linker: fix loading foreign imports (#2283) (25821cc)

git at git.haskell.org git at git.haskell.org
Tue Jan 28 14:43:40 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/25821cc9793c15e9860b3dcddf50aebf0eb718f7/ghc

>---------------------------------------------------------------

commit 25821cc9793c15e9860b3dcddf50aebf0eb718f7
Author: Kyrill Briantsev <kyrab at mail.ru>
Date:   Tue Jan 28 08:42:40 2014 -0600

    Win64 linker: fix loading foreign imports (#2283)
    
    Signed-off-by: Austin Seipp <austin at well-typed.com>


>---------------------------------------------------------------

25821cc9793c15e9860b3dcddf50aebf0eb718f7
 rts/Linker.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/rts/Linker.c b/rts/Linker.c
index 5110ea1..bdd4746 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -3671,6 +3671,23 @@ lookupSymbolInDLLs ( UChar *lbl )
                 return sym;
             }
         }
+
+        /* Ticket #2283.
+           Long description: http://support.microsoft.com/kb/132044
+           tl;dr:
+             If C/C++ compiler sees __declspec(dllimport) ... foo ...
+             it generates call __imp_foo, and __imp_foo here has exactly
+             the same semantics as in __imp_foo = GetProcAddress(..., "foo")
+         */
+        if (sym == NULL && strncmp ((const char*)lbl, "__imp_", 6) == 0) {
+            sym = GetProcAddress(o_dll->instance, (char*)(lbl+6));
+            if (sym != NULL) {
+                errorBelch("warning: %s from %S is linked instead of %s",
+                              (char*)(lbl+6), o_dll->name, (char*)lbl);
+                return sym;
+               }
+        }
+
         sym = GetProcAddress(o_dll->instance, (char*)lbl);
         if (sym != NULL) {
             /*debugBelch("found %s in %s\n", lbl,o_dll->name);*/



More information about the ghc-commits mailing list