| ... |
... |
@@ -9,6 +9,8 @@ |
|
9
|
9
|
#include "ghcplatform.h"
|
|
10
|
10
|
#include "Rts.h"
|
|
11
|
11
|
#include "RtsSymbols.h"
|
|
|
12
|
+#include "LinkerInternals.h"
|
|
|
13
|
+#include "PathUtils.h"
|
|
12
|
14
|
|
|
13
|
15
|
#include "TopHandler.h"
|
|
14
|
16
|
#include "HsFFI.h"
|
| ... |
... |
@@ -51,6 +53,19 @@ extern char **environ; |
|
51
|
53
|
|
|
52
|
54
|
/* -----------------------------------------------------------------------------
|
|
53
|
55
|
* Symbols to be inserted into the RTS symbol table.
|
|
|
56
|
+ *
|
|
|
57
|
+ * Note [Naming Scheme for Symbol Macros]
|
|
|
58
|
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
59
|
+ *
|
|
|
60
|
+ * SymI_*: symbol is internal to the RTS. It resides in an object
|
|
|
61
|
+ * file/library that is statically.
|
|
|
62
|
+ * SymE_*: symbol is external to the RTS library. It might be linked
|
|
|
63
|
+ * dynamically.
|
|
|
64
|
+ *
|
|
|
65
|
+ * Sym*_HasProto : the symbol prototype is imported in an include file
|
|
|
66
|
+ * or defined explicitly
|
|
|
67
|
+ * Sym*_NeedsProto: the symbol is undefined and we add a dummy
|
|
|
68
|
+ * default proto extern void sym(void);
|
|
54
|
69
|
*/
|
|
55
|
70
|
|
|
56
|
71
|
#define Maybe_Stable_Names SymI_HasProto(stg_mkWeakzh) \
|
| ... |
... |
@@ -162,7 +177,7 @@ extern char **environ; |
|
162
|
177
|
SymI_HasProto(stg_asyncWritezh) \
|
|
163
|
178
|
SymI_HasProto(stg_asyncDoProczh) \
|
|
164
|
179
|
SymI_HasProto(rts_InstallConsoleEvent) \
|
|
165
|
|
- SymI_HasProto(rts_IOManagerIsWin32Native) \
|
|
|
180
|
+ SymI_HasDataProto(rts_IOManagerIsWin32Native) \
|
|
166
|
181
|
SymI_HasProto(rts_ConsoleHandlerDone) \
|
|
167
|
182
|
SymI_NeedsProto(__mingw_module_is_dll) \
|
|
168
|
183
|
RTS_WIN64_ONLY(SymI_NeedsProto(___chkstk_ms)) \
|
| ... |
... |
@@ -913,7 +928,7 @@ extern char **environ; |
|
913
|
928
|
SymI_HasProto(freeExecPage) \
|
|
914
|
929
|
SymI_HasProto(getAllocations) \
|
|
915
|
930
|
SymI_HasProto(revertCAFs) \
|
|
916
|
|
- SymI_HasProto(RtsFlags) \
|
|
|
931
|
+ SymI_HasDataProto(RtsFlags) \
|
|
917
|
932
|
SymI_NeedsDataProto(rts_breakpoint_io_action) \
|
|
918
|
933
|
SymI_NeedsDataProto(rts_stop_next_breakpoint) \
|
|
919
|
934
|
SymI_NeedsDataProto(rts_stop_on_exception) \
|
| ... |
... |
@@ -924,9 +939,9 @@ extern char **environ; |
|
924
|
939
|
SymI_NeedsProto(rts_enableStopAfterReturn) \
|
|
925
|
940
|
SymI_NeedsProto(rts_disableStopAfterReturn) \
|
|
926
|
941
|
SymI_HasProto(stopTimer) \
|
|
927
|
|
- SymI_HasProto(n_capabilities) \
|
|
928
|
|
- SymI_HasProto(max_n_capabilities) \
|
|
929
|
|
- SymI_HasProto(enabled_capabilities) \
|
|
|
942
|
+ SymI_HasDataProto(n_capabilities) \
|
|
|
943
|
+ SymI_HasDataProto(max_n_capabilities) \
|
|
|
944
|
+ SymI_HasDataProto(enabled_capabilities) \
|
|
930
|
945
|
SymI_HasDataProto(stg_traceEventzh) \
|
|
931
|
946
|
SymI_HasDataProto(stg_traceMarkerzh) \
|
|
932
|
947
|
SymI_HasDataProto(stg_traceBinaryEventzh) \
|
| ... |
... |
@@ -1144,12 +1159,27 @@ extern char **environ; |
|
1144
|
1159
|
SymI_HasProto(hs_word2float64)
|
|
1145
|
1160
|
|
|
1146
|
1161
|
|
|
1147
|
|
-/* entirely bogus claims about types of these symbols */
|
|
1148
|
|
-#define SymI_NeedsProto(vvv) extern void vvv(void);
|
|
1149
|
|
-#define SymI_NeedsDataProto(vvv) extern StgWord vvv[];
|
|
1150
|
|
-#define SymE_NeedsProto(vvv) SymI_NeedsProto(vvv);
|
|
1151
|
|
-#define SymE_NeedsDataProto(vvv) SymI_NeedsDataProto(vvv);
|
|
1152
|
|
-#define SymE_HasProto(vvv) SymI_HasProto(vvv);
|
|
|
1162
|
+/* Declare prototypes for the symbols that need it, so we can refer
|
|
|
1163
|
+ * to them in the rtsSyms table below.
|
|
|
1164
|
+ *
|
|
|
1165
|
+ * In particular, for the external ones (SymE_*) we use the dllimport attribute
|
|
|
1166
|
+ * to indicate that (on Windows) they come from external DLLs. This attribute
|
|
|
1167
|
+ * is ignored on other platforms.
|
|
|
1168
|
+ *
|
|
|
1169
|
+ * The claims about the types of these symbols are entirely bogus.
|
|
|
1170
|
+ */
|
|
|
1171
|
+#if defined(mingw32_HOST_OS) && defined(DYNAMIC)
|
|
|
1172
|
+#define DLLIMPORT __attribute__((dllimport))
|
|
|
1173
|
+#else
|
|
|
1174
|
+#define DLLIMPORT /**/
|
|
|
1175
|
+#endif
|
|
|
1176
|
+
|
|
|
1177
|
+#define SymI_NeedsProto(vvv) extern void vvv(void);
|
|
|
1178
|
+#define SymI_NeedsDataProto(vvv) extern StgWord vvv[];
|
|
|
1179
|
+#define SymE_NeedsProto(vvv) extern DLLIMPORT void vvv(void);
|
|
|
1180
|
+#define SymE_NeedsDataProto(vvv) extern DLLIMPORT StgWord vvv[];
|
|
|
1181
|
+
|
|
|
1182
|
+#define SymE_HasProto(vvv) /**/
|
|
1153
|
1183
|
#define SymI_HasProto(vvv) /**/
|
|
1154
|
1184
|
#define SymI_HasDataProto(vvv) /**/
|
|
1155
|
1185
|
#define SymI_HasProto_redirect(vvv,xxx,strength,ty) /**/
|
| ... |
... |
@@ -1178,6 +1208,8 @@ RTS_SYMBOLS_PRIM |
|
1178
|
1208
|
#undef SymE_NeedsProto
|
|
1179
|
1209
|
#undef SymE_NeedsDataProto
|
|
1180
|
1210
|
|
|
|
1211
|
+/* See Note [Naming Scheme for Symbol Macros] */
|
|
|
1212
|
+
|
|
1181
|
1213
|
#define SymI_HasProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
|
|
1182
|
1214
|
(void*)(&(vvv)), STRENGTH_NORMAL, SYM_TYPE_CODE },
|
|
1183
|
1215
|
#define SymI_HasDataProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
|
| ... |
... |
@@ -1198,7 +1230,16 @@ RTS_SYMBOLS_PRIM |
|
1198
|
1230
|
{ MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
|
|
1199
|
1231
|
(void*)(&(xxx)), strength, ty },
|
|
1200
|
1232
|
|
|
1201
|
|
-RtsSymbolVal rtsSyms[] = {
|
|
|
1233
|
+
|
|
|
1234
|
+/* Populate the symbol table with stuff from the RTS. */
|
|
|
1235
|
+void initLinkerRtsSyms (StrHashTable *symhash) {
|
|
|
1236
|
+
|
|
|
1237
|
+ /* The address of data symbols with the dllimport attribute are not
|
|
|
1238
|
+ * compile-time constants and so cannot be used in constant initialisers.
|
|
|
1239
|
+ * For this reason, rtsSyms is a local variable within this function
|
|
|
1240
|
+ * rather than a global constant (as it was historically).
|
|
|
1241
|
+ */
|
|
|
1242
|
+ const RtsSymbolVal rtsSyms[] = {
|
|
1202
|
1243
|
RTS_SYMBOLS
|
|
1203
|
1244
|
RTS_RET_SYMBOLS
|
|
1204
|
1245
|
RTS_POSIX_ONLY_SYMBOLS
|
| ... |
... |
@@ -1213,7 +1254,19 @@ RtsSymbolVal rtsSyms[] = { |
|
1213
|
1254
|
RTS_SYMBOLS_PRIM
|
|
1214
|
1255
|
SymI_HasDataProto(nonmoving_write_barrier_enabled)
|
|
1215
|
1256
|
{ 0, 0, STRENGTH_NORMAL, SYM_TYPE_CODE } /* sentinel */
|
|
1216
|
|
-};
|
|
|
1257
|
+ };
|
|
|
1258
|
+
|
|
|
1259
|
+ IF_DEBUG(linker, debugBelch("populating linker symbol table with built-in RTS symbols\n"));
|
|
|
1260
|
+ for (const RtsSymbolVal *sym = rtsSyms; sym->lbl != NULL; sym++) {
|
|
|
1261
|
+ IF_DEBUG(linker, debugBelch("initLinker: inserting rts symbol %s, %p\n", sym->lbl, sym->addr));
|
|
|
1262
|
+ if (! ghciInsertSymbolTable(WSTR("(GHCi built-in symbols)"),
|
|
|
1263
|
+ symhash, sym->lbl, sym->addr,
|
|
|
1264
|
+ sym->strength, sym->type, 0, NULL)) {
|
|
|
1265
|
+ barf("ghciInsertSymbolTable failed");
|
|
|
1266
|
+ }
|
|
|
1267
|
+ }
|
|
|
1268
|
+ IF_DEBUG(linker, debugBelch("done with built-in RTS symbols\n"));
|
|
|
1269
|
+}
|
|
1217
|
1270
|
|
|
1218
|
1271
|
|
|
1219
|
1272
|
// Note [Extra RTS symbols]
|