| ... |
... |
@@ -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,20 @@ 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 linked into the RTS library (as a static
|
|
|
62
|
+ * archive or dynamic shared library).
|
|
|
63
|
+ * SymE_*: symbol is external to the RTS library. It might be linked
|
|
|
64
|
+ * dynamically.
|
|
|
65
|
+ *
|
|
|
66
|
+ * Sym*_HasProto : the symbol prototype is imported in an include file
|
|
|
67
|
+ * or defined explicitly
|
|
|
68
|
+ * Sym*_NeedsProto: the symbol is undefined and we add a dummy
|
|
|
69
|
+ * default proto extern void sym(void);
|
|
54
|
70
|
*/
|
|
55
|
71
|
|
|
56
|
72
|
#define Maybe_Stable_Names SymI_HasProto(stg_mkWeakzh) \
|
| ... |
... |
@@ -162,7 +178,7 @@ extern char **environ; |
|
162
|
178
|
SymI_HasProto(stg_asyncWritezh) \
|
|
163
|
179
|
SymI_HasProto(stg_asyncDoProczh) \
|
|
164
|
180
|
SymI_HasProto(rts_InstallConsoleEvent) \
|
|
165
|
|
- SymI_HasProto(rts_IOManagerIsWin32Native) \
|
|
|
181
|
+ SymI_HasDataProto(rts_IOManagerIsWin32Native) \
|
|
166
|
182
|
SymI_HasProto(rts_ConsoleHandlerDone) \
|
|
167
|
183
|
SymI_NeedsProto(__mingw_module_is_dll) \
|
|
168
|
184
|
RTS_WIN64_ONLY(SymI_NeedsProto(___chkstk_ms)) \
|
| ... |
... |
@@ -913,7 +929,7 @@ extern char **environ; |
|
913
|
929
|
SymI_HasProto(freeExecPage) \
|
|
914
|
930
|
SymI_HasProto(getAllocations) \
|
|
915
|
931
|
SymI_HasProto(revertCAFs) \
|
|
916
|
|
- SymI_HasProto(RtsFlags) \
|
|
|
932
|
+ SymI_HasDataProto(RtsFlags) \
|
|
917
|
933
|
SymI_NeedsDataProto(rts_breakpoint_io_action) \
|
|
918
|
934
|
SymI_NeedsDataProto(rts_stop_next_breakpoint) \
|
|
919
|
935
|
SymI_NeedsDataProto(rts_stop_on_exception) \
|
| ... |
... |
@@ -924,9 +940,9 @@ extern char **environ; |
|
924
|
940
|
SymI_NeedsProto(rts_enableStopAfterReturn) \
|
|
925
|
941
|
SymI_NeedsProto(rts_disableStopAfterReturn) \
|
|
926
|
942
|
SymI_HasProto(stopTimer) \
|
|
927
|
|
- SymI_HasProto(n_capabilities) \
|
|
928
|
|
- SymI_HasProto(max_n_capabilities) \
|
|
929
|
|
- SymI_HasProto(enabled_capabilities) \
|
|
|
943
|
+ SymI_HasDataProto(n_capabilities) \
|
|
|
944
|
+ SymI_HasDataProto(max_n_capabilities) \
|
|
|
945
|
+ SymI_HasDataProto(enabled_capabilities) \
|
|
930
|
946
|
SymI_HasDataProto(stg_traceEventzh) \
|
|
931
|
947
|
SymI_HasDataProto(stg_traceMarkerzh) \
|
|
932
|
948
|
SymI_HasDataProto(stg_traceBinaryEventzh) \
|
| ... |
... |
@@ -1144,12 +1160,27 @@ extern char **environ; |
|
1144
|
1160
|
SymI_HasProto(hs_word2float64)
|
|
1145
|
1161
|
|
|
1146
|
1162
|
|
|
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);
|
|
|
1163
|
+/* Declare prototypes for the symbols that need it, so we can refer
|
|
|
1164
|
+ * to them in the rtsSyms table below.
|
|
|
1165
|
+ *
|
|
|
1166
|
+ * In particular, for the external ones (SymE_*) we use the dllimport attribute
|
|
|
1167
|
+ * to indicate that (on Windows) they come from external DLLs. This attribute
|
|
|
1168
|
+ * is ignored on other platforms.
|
|
|
1169
|
+ *
|
|
|
1170
|
+ * The claims about the types of these symbols are entirely bogus.
|
|
|
1171
|
+ */
|
|
|
1172
|
+#if defined(mingw32_HOST_OS) && defined(DYNAMIC)
|
|
|
1173
|
+#define DLLIMPORT __attribute__((dllimport))
|
|
|
1174
|
+#else
|
|
|
1175
|
+#define DLLIMPORT /**/
|
|
|
1176
|
+#endif
|
|
|
1177
|
+
|
|
|
1178
|
+#define SymI_NeedsProto(vvv) extern void vvv(void);
|
|
|
1179
|
+#define SymI_NeedsDataProto(vvv) extern StgWord vvv[];
|
|
|
1180
|
+#define SymE_NeedsProto(vvv) extern DLLIMPORT void vvv(void);
|
|
|
1181
|
+#define SymE_NeedsDataProto(vvv) extern DLLIMPORT StgWord vvv[];
|
|
|
1182
|
+
|
|
|
1183
|
+#define SymE_HasProto(vvv) /**/
|
|
1153
|
1184
|
#define SymI_HasProto(vvv) /**/
|
|
1154
|
1185
|
#define SymI_HasDataProto(vvv) /**/
|
|
1155
|
1186
|
#define SymI_HasProto_redirect(vvv,xxx,strength,ty) /**/
|
| ... |
... |
@@ -1178,6 +1209,8 @@ RTS_SYMBOLS_PRIM |
|
1178
|
1209
|
#undef SymE_NeedsProto
|
|
1179
|
1210
|
#undef SymE_NeedsDataProto
|
|
1180
|
1211
|
|
|
|
1212
|
+/* See Note [Naming Scheme for Symbol Macros] */
|
|
|
1213
|
+
|
|
1181
|
1214
|
#define SymI_HasProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
|
|
1182
|
1215
|
(void*)(&(vvv)), STRENGTH_NORMAL, SYM_TYPE_CODE },
|
|
1183
|
1216
|
#define SymI_HasDataProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
|
| ... |
... |
@@ -1198,22 +1231,40 @@ RTS_SYMBOLS_PRIM |
|
1198
|
1231
|
{ MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
|
|
1199
|
1232
|
(void*)(&(xxx)), strength, ty },
|
|
1200
|
1233
|
|
|
1201
|
|
-RtsSymbolVal rtsSyms[] = {
|
|
1202
|
|
- RTS_SYMBOLS
|
|
1203
|
|
- RTS_RET_SYMBOLS
|
|
1204
|
|
- RTS_POSIX_ONLY_SYMBOLS
|
|
1205
|
|
- RTS_MINGW_ONLY_SYMBOLS
|
|
1206
|
|
- RTS_DARWIN_ONLY_SYMBOLS
|
|
1207
|
|
- RTS_OPENBSD_ONLY_SYMBOLS
|
|
1208
|
|
- RTS_LIBGCC_SYMBOLS
|
|
1209
|
|
- RTS_ARCH_LIBGCC_SYMBOLS
|
|
1210
|
|
- RTS_FINI_ARRAY_SYMBOLS
|
|
1211
|
|
- RTS_LIBFFI_SYMBOLS
|
|
1212
|
|
- RTS_ARM_OUTLINE_ATOMIC_SYMBOLS
|
|
1213
|
|
- RTS_SYMBOLS_PRIM
|
|
1214
|
|
- SymI_HasDataProto(nonmoving_write_barrier_enabled)
|
|
1215
|
|
- { 0, 0, STRENGTH_NORMAL, SYM_TYPE_CODE } /* sentinel */
|
|
1216
|
|
-};
|
|
|
1234
|
+
|
|
|
1235
|
+static RtsSymbolVal* rtsSyms;
|
|
|
1236
|
+
|
|
|
1237
|
+/* Initialize (if not already initialized) and return an array of symbols with stuff from the RTS. */
|
|
|
1238
|
+RtsSymbolVal* initRtsSyms(void) {
|
|
|
1239
|
+ if(!rtsSyms) {
|
|
|
1240
|
+ /* The address of data symbols with the dllimport attribute are not
|
|
|
1241
|
+ * compile-time constants and so cannot be used in constant initialisers.
|
|
|
1242
|
+ * For this reason, rtsSyms is a local variable within this function
|
|
|
1243
|
+ * rather than a global constant (as it was historically).
|
|
|
1244
|
+ */
|
|
|
1245
|
+ const RtsSymbolVal localRtsSyms[] = {
|
|
|
1246
|
+ RTS_SYMBOLS
|
|
|
1247
|
+ RTS_RET_SYMBOLS
|
|
|
1248
|
+ RTS_POSIX_ONLY_SYMBOLS
|
|
|
1249
|
+ RTS_MINGW_ONLY_SYMBOLS
|
|
|
1250
|
+ RTS_DARWIN_ONLY_SYMBOLS
|
|
|
1251
|
+ RTS_OPENBSD_ONLY_SYMBOLS
|
|
|
1252
|
+ RTS_LIBGCC_SYMBOLS
|
|
|
1253
|
+ RTS_ARCH_LIBGCC_SYMBOLS
|
|
|
1254
|
+ RTS_FINI_ARRAY_SYMBOLS
|
|
|
1255
|
+ RTS_LIBFFI_SYMBOLS
|
|
|
1256
|
+ RTS_ARM_OUTLINE_ATOMIC_SYMBOLS
|
|
|
1257
|
+ RTS_SYMBOLS_PRIM
|
|
|
1258
|
+ SymI_HasDataProto(nonmoving_write_barrier_enabled)
|
|
|
1259
|
+ { 0, 0, STRENGTH_NORMAL, SYM_TYPE_CODE } /* sentinel */
|
|
|
1260
|
+ };
|
|
|
1261
|
+
|
|
|
1262
|
+ rtsSyms = malloc(sizeof(localRtsSyms));
|
|
|
1263
|
+ memcpy(rtsSyms, localRtsSyms, sizeof(localRtsSyms));
|
|
|
1264
|
+ }
|
|
|
1265
|
+
|
|
|
1266
|
+ return rtsSyms;
|
|
|
1267
|
+}
|
|
1217
|
1268
|
|
|
1218
|
1269
|
|
|
1219
|
1270
|
// Note [Extra RTS symbols]
|