Commit 9968502d authored by Tamar Christina's avatar Tamar Christina Committed by Ben Gamari
Browse files

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:
parent 41e54b4b
......@@ -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));
......@@ -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) \
#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) \
......@@ -999,14 +1000,17 @@ RTS_LIBFFI_SYMBOLS
// another symbol. See newCAF/newRetainedCAF/newGCdCAF for an example.
#define SymI_HasProto_redirect(vvv,xxx) \
(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[] = {
......@@ -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 },
{ 0, 0 } /* sentinel */
{ 0, 0, false } /* sentinel */
......@@ -11,6 +11,7 @@
#include "ghcautoconf.h"
#include "LinkerInternals.h"
#include <stdbool.h>
......@@ -21,6 +22,7 @@
typedef struct _RtsSymbolVal {
const SymbolName* lbl;
SymbolAddr* addr;
bool weak;
} RtsSymbolVal;
extern RtsSymbolVal rtsSyms[];
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment