[commit: ghc] master: Make list of deprecated symbols on Windows weak. (9968502)

git at git.haskell.org git at git.haskell.org
Sun Feb 26 16:51:37 UTC 2017


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/9968502d075e3a714913e14cd96a7d6b7ac7b5e7/ghc

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

commit 9968502d075e3a714913e14cd96a7d6b7ac7b5e7
Author: Tamar Christina <tamar at zhox.com>
Date:   Thu Feb 23 18:33:15 2017 -0500

    Make list of deprecated symbols on Windows weak.
    
    We have a unfortunate workaround in place for the fact that most
    packages out there use POSIX names for symbols even on Windows.  This
    means that we have to recognize e.g. both `_ungetch` and `ungetch`.
    
    The former is the actual symbol name on windows and the latter is the
    POSIX variant. The problem is that on normal windows programs `ungetch`
    should not be in the global namespace.
    
    To work around this, we now mark the deprecated symbols as weak symbols
    in the global namespace. This provides the flexibility we need:
    
    * If you use the symbol without defining it, we assume you meant to use
      the POSIX variant.
    * If you actually define the symbol, we'll hence forth use that
      definition and assume you didn't mean to use POSIX code. This is how
      MingW64's wrapper also works.
    
    This requires D3028.
    
    Fixes #13210.
    
    Test Plan: ./validate
    
    Reviewers: austin, bgamari, erikd, simonmar
    
    Reviewed By: bgamari
    
    Subscribers: thomie, #ghc_windows_task_force
    
    Differential Revision: https://phabricator.haskell.org/D3154


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

9968502d075e3a714913e14cd96a7d6b7ac7b5e7
 rts/Linker.c     |  3 ++-
 rts/RtsSymbols.c | 16 ++++++++++------
 rts/RtsSymbols.h |  2 ++
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/rts/Linker.c b/rts/Linker.c
index 8945a96..247f246 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -444,7 +444,8 @@ initLinker_ (int retain_cafs)
     /* populate the symbol table with stuff from the RTS */
     for (sym = rtsSyms; sym->lbl != NULL; sym++) {
         if (! ghciInsertSymbolTable(WSTR("(GHCi built-in symbols)"),
-                                    symhash, sym->lbl, sym->addr, HS_BOOL_FALSE, NULL)) {
+                                    symhash, sym->lbl, sym->addr,
+                                    sym->weak, NULL)) {
             barf("ghciInsertSymbolTable failed");
         }
         IF_DEBUG(linker, debugBelch("initLinker: inserting rts symbol %s, %p\n", sym->lbl, sym->addr));
diff --git a/rts/RtsSymbols.c b/rts/RtsSymbols.c
index 3f7610c..0180554 100644
--- a/rts/RtsSymbols.c
+++ b/rts/RtsSymbols.c
@@ -14,6 +14,7 @@
 #include "HsFFI.h"
 
 #include "sm/Storage.h"
+#include <stdbool.h>
 
 #if !defined(mingw32_HOST_OS)
 #include "posix/Signals.h"
@@ -982,11 +983,11 @@ RTS_LIBFFI_SYMBOLS
 #undef SymE_NeedsDataProto
 
 #define SymI_HasProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
-                    (void*)(&(vvv)) },
+                    (void*)(&(vvv)), false },
 #define SymI_HasDataProto(vvv) \
                     SymI_HasProto(vvv)
 #define SymE_HasProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
-            (void*)DLL_IMPORT_DATA_REF(vvv) },
+            (void*)DLL_IMPORT_DATA_REF(vvv), false },
 #define SymE_HasDataProto(vvv) \
                     SymE_HasProto(vvv)
 
@@ -999,14 +1000,17 @@ RTS_LIBFFI_SYMBOLS
 // another symbol.  See newCAF/newRetainedCAF/newGCdCAF for an example.
 #define SymI_HasProto_redirect(vvv,xxx)   \
     { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
-      (void*)(&(xxx)) },
+      (void*)(&(xxx)), false },
 
 // SymI_HasProto_deprecated allows us to redirect references from their deprecated
 // names to the undeprecated ones. e.g. access -> _access.
 // We use the hexspeak for unallocated memory 0xBAADF00D to signal the RTS
 // that this needs to be loaded from somewhere else.
+// These are inserted as weak symbols to prevent us overriding packages that do
+// define them, since on Windows these functions shouldn't be in the top level
+// namespace, but we have them for POSIX compatibility.
 #define SymI_HasProto_deprecated(vvv)   \
-   { #vvv, (void*)0xBAADF00D },
+   { #vvv, (void*)0xBAADF00D, true },
 
 RtsSymbolVal rtsSyms[] = {
       RTS_SYMBOLS
@@ -1022,7 +1026,7 @@ RtsSymbolVal rtsSyms[] = {
       // dyld stub code contains references to this,
       // but it should never be called because we treat
       // lazy pointers as nonlazy.
-      { "dyld_stub_binding_helper", (void*)0xDEADBEEF },
+      { "dyld_stub_binding_helper", (void*)0xDEADBEEF, false },
 #endif
-      { 0, 0 } /* sentinel */
+      { 0, 0, false } /* sentinel */
 };
diff --git a/rts/RtsSymbols.h b/rts/RtsSymbols.h
index dab2373..7f7ac0f 100644
--- a/rts/RtsSymbols.h
+++ b/rts/RtsSymbols.h
@@ -11,6 +11,7 @@
 
 #include "ghcautoconf.h"
 #include "LinkerInternals.h"
+#include <stdbool.h>
 
 #ifdef LEADING_UNDERSCORE
 #define MAYBE_LEADING_UNDERSCORE_STR(s) ("_" s)
@@ -21,6 +22,7 @@
 typedef struct _RtsSymbolVal {
     const SymbolName* lbl;
     SymbolAddr* addr;
+    bool weak;
 } RtsSymbolVal;
 
 extern RtsSymbolVal rtsSyms[];



More information about the ghc-commits mailing list