David Eichmann pushed to branch wip/27162/rts-explicit-dllimport at Glasgow Haskell Compiler / GHC

Commits:

5 changed files:

Changes:

  • hadrian/src/Settings/Packages.hs
    ... ... @@ -321,6 +321,7 @@ rtsPackageArgs = package rts ? do
    321 321
               , Profiling `wayUnit` way          ? arg "-DPROFILING"
    
    322 322
               , Threaded  `wayUnit` way          ? arg "-DTHREADED_RTS"
    
    323 323
               , notM targetSupportsSMP           ? arg "-optc-DNOSMP"
    
    324
    +          , isWinHost                        ? arg "-optl-Wl,--disable-runtime-pseudo-reloc"
    
    324 325
     
    
    325 326
                 -- See Note [AutoApply.cmm for vectors] in genapply/Main.hs
    
    326 327
                 --
    

  • rts/IOManager.h
    ... ... @@ -21,6 +21,15 @@
    21 21
     
    
    22 22
     #include "sm/GC.h" // for evac_fn
    
    23 23
     
    
    24
    +#if defined(mingw32_HOST_OS)
    
    25
    +/* Global var (only on Windows) that is exported (hence before BeginPrivate.h)
    
    26
    + * to be shared with the I/O code in the base library to tell us which style
    
    27
    + * of I/O manager we are using: one that uses the Windows native API HANDLEs,
    
    28
    + * or one that uses Posix style fds.
    
    29
    + */
    
    30
    +extern bool rts_IOManagerIsWin32Native;
    
    31
    +#endif
    
    32
    +
    
    24 33
     #include "BeginPrivate.h"
    
    25 34
     
    
    26 35
     /* The ./configure gives us a set of CPP flags, one for each named I/O manager:
    
    ... ... @@ -160,14 +169,6 @@ typedef enum {
    160 169
     /* Global var to tell us which I/O manager impl we are using */
    
    161 170
     extern IOManagerType iomgr_type;
    
    162 171
     
    
    163
    -#if defined(mingw32_HOST_OS)
    
    164
    -/* Global var (only on Windows) that is exported to be shared with the I/O code
    
    165
    - * in the base library to tell us which style of I/O manager we are using: one
    
    166
    - * that uses the Windows native API HANDLEs, or one that uses Posix style fds.
    
    167
    - */
    
    168
    -extern bool rts_IOManagerIsWin32Native;
    
    169
    -#endif
    
    170
    -
    
    171 172
     
    
    172 173
     /* The CapIOManager is the per-capability data structure belonging to the I/O
    
    173 174
      * manager. It is defined in full in IOManagerInternals.h. The opaque forward
    

  • rts/Linker.c
    ... ... @@ -478,16 +478,7 @@ initLinker_ (int retain_cafs)
    478 478
         symhash = allocStrHashTable();
    
    479 479
     
    
    480 480
         /* populate the symbol table with stuff from the RTS */
    
    481
    -    IF_DEBUG(linker, debugBelch("populating linker symbol table with built-in RTS symbols\n"));
    
    482
    -    for (const RtsSymbolVal *sym = rtsSyms; sym->lbl != NULL; sym++) {
    
    483
    -        IF_DEBUG(linker, debugBelch("initLinker: inserting rts symbol %s, %p\n", sym->lbl, sym->addr));
    
    484
    -        if (! ghciInsertSymbolTable(WSTR("(GHCi built-in symbols)"),
    
    485
    -                                    symhash, sym->lbl, sym->addr,
    
    486
    -                                    sym->strength, sym->type, 0, NULL)) {
    
    487
    -            barf("ghciInsertSymbolTable failed");
    
    488
    -        }
    
    489
    -    }
    
    490
    -    IF_DEBUG(linker, debugBelch("done with built-in RTS symbols\n"));
    
    481
    +    initLinkerRtsSyms(symhash);
    
    491 482
     
    
    492 483
         /* Add extra symbols. rtsExtraSyms() is a weakly defined symbol in the rts,
    
    493 484
          * that can be overrided by linking in an object with a corresponding
    

  • rts/RtsSymbols.c
    ... ... @@ -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]
    

  • rts/RtsSymbols.h
    ... ... @@ -9,6 +9,7 @@
    9 9
     #pragma once
    
    10 10
     
    
    11 11
     #include "ghcautoconf.h"
    
    12
    +#include "Hash.h"
    
    12 13
     
    
    13 14
     #if defined(LEADING_UNDERSCORE)
    
    14 15
     #define MAYBE_LEADING_UNDERSCORE_STR(s) ("_" s)
    
    ... ... @@ -46,7 +47,7 @@ typedef struct _RtsSymbolVal {
    46 47
         SymType type;
    
    47 48
     } RtsSymbolVal;
    
    48 49
     
    
    49
    -extern RtsSymbolVal rtsSyms[];
    
    50
    +void initLinkerRtsSyms (StrHashTable *symhash);
    
    50 51
     
    
    51 52
     extern RtsSymbolVal* __attribute__((weak)) rtsExtraSyms(void);
    
    52 53