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

Commits:

3 changed files:

Changes:

  • 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,7 @@
    9 9
     #include "ghcplatform.h"
    
    10 10
     #include "Rts.h"
    
    11 11
     #include "RtsSymbols.h"
    
    12
    +#include "LinkerInternals.h"
    
    12 13
     
    
    13 14
     #include "TopHandler.h"
    
    14 15
     #include "HsFFI.h"
    
    ... ... @@ -51,6 +52,18 @@ extern char **environ;
    51 52
     
    
    52 53
     /* -----------------------------------------------------------------------------
    
    53 54
      * Symbols to be inserted into the RTS symbol table.
    
    55
    + *
    
    56
    + * Note [Naming Scheme for Symbol Macros]
    
    57
    + *
    
    58
    + * SymI_*: symbol is internal to the RTS. It resides in an object
    
    59
    + *         file/library that is statically.
    
    60
    + * SymE_*: symbol is external to the RTS library. It might be linked
    
    61
    + *         dynamically.
    
    62
    + *
    
    63
    + * Sym*_HasProto  : the symbol prototype is imported in an include file
    
    64
    + *                  or defined explicitly
    
    65
    + * Sym*_NeedsProto: the symbol is undefined and we add a dummy
    
    66
    + *                  default proto extern void sym(void);
    
    54 67
      */
    
    55 68
     
    
    56 69
     #define Maybe_Stable_Names      SymI_HasProto(stg_mkWeakzh)                   \
    
    ... ... @@ -1144,12 +1157,21 @@ extern char **environ;
    1144 1157
           SymI_HasProto(hs_word2float64)
    
    1145 1158
     
    
    1146 1159
     
    
    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);
    
    1160
    +/* Declare prototypes for the symbols that need it, so we can refer
    
    1161
    + * to them in the rtsSyms table below.
    
    1162
    + *
    
    1163
    + * In particular, for the external ones (SymE_*) we use the dllimport attribute
    
    1164
    + * to indicate that (on Windows) they come from external DLLs. This attribute
    
    1165
    + * is ignored on other platforms.
    
    1166
    + *
    
    1167
    + * The claims about the types of these symbols are entirely bogus.
    
    1168
    + */
    
    1169
    +#define SymI_NeedsProto(vvv)      extern                            void vvv(void);
    
    1170
    +#define SymI_NeedsDataProto(vvv)  extern                            StgWord vvv[];
    
    1171
    +#define SymE_NeedsProto(vvv)      extern __attribute__((dllimport)) void vvv(void);
    
    1172
    +#define SymE_NeedsDataProto(vvv)  extern __attribute__((dllimport)) StgWord vvv[];
    
    1173
    +
    
    1174
    +#define SymE_HasProto(vvv) /**/
    
    1153 1175
     #define SymI_HasProto(vvv) /**/
    
    1154 1176
     #define SymI_HasDataProto(vvv) /**/
    
    1155 1177
     #define SymI_HasProto_redirect(vvv,xxx,strength,ty) /**/
    
    ... ... @@ -1178,6 +1200,8 @@ RTS_SYMBOLS_PRIM
    1178 1200
     #undef SymE_NeedsProto
    
    1179 1201
     #undef SymE_NeedsDataProto
    
    1180 1202
     
    
    1203
    +/* See Note [Naming Scheme for Symbol Macros] */
    
    1204
    +
    
    1181 1205
     #define SymI_HasProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
    
    1182 1206
                         (void*)(&(vvv)), STRENGTH_NORMAL, SYM_TYPE_CODE },
    
    1183 1207
     #define SymI_HasDataProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
    
    ... ... @@ -1198,7 +1222,16 @@ RTS_SYMBOLS_PRIM
    1198 1222
         { MAYBE_LEADING_UNDERSCORE_STR(#vvv),    \
    
    1199 1223
           (void*)(&(xxx)), strength, ty },
    
    1200 1224
     
    
    1201
    -RtsSymbolVal rtsSyms[] = {
    
    1225
    +
    
    1226
    +/* Populate the symbol table with stuff from the RTS. */
    
    1227
    +void initLinkerRtsSyms (StrHashTable *symhash) {
    
    1228
    +
    
    1229
    +    /* The address of data symbols with the dllimport attribute are not
    
    1230
    +     * compile-time constants and so cannot be used in constant initialisers.
    
    1231
    +     * For this reason, rtsSyms is a local variable within this function
    
    1232
    +     * rather than a global constant (as it was historically).
    
    1233
    +     */
    
    1234
    +    const RtsSymbolVal rtsSyms[] = {
    
    1202 1235
           RTS_SYMBOLS
    
    1203 1236
           RTS_RET_SYMBOLS
    
    1204 1237
           RTS_POSIX_ONLY_SYMBOLS
    
    ... ... @@ -1213,7 +1246,19 @@ RtsSymbolVal rtsSyms[] = {
    1213 1246
           RTS_SYMBOLS_PRIM
    
    1214 1247
           SymI_HasDataProto(nonmoving_write_barrier_enabled)
    
    1215 1248
           { 0, 0, STRENGTH_NORMAL, SYM_TYPE_CODE } /* sentinel */
    
    1216
    -};
    
    1249
    +    };
    
    1250
    +
    
    1251
    +    IF_DEBUG(linker, debugBelch("populating linker symbol table with built-in RTS symbols\n"));
    
    1252
    +    for (const RtsSymbolVal *sym = rtsSyms; sym->lbl != NULL; sym++) {
    
    1253
    +        IF_DEBUG(linker, debugBelch("initLinker: inserting rts symbol %s, %p\n", sym->lbl, sym->addr));
    
    1254
    +        if (! ghciInsertSymbolTable(WSTR("(GHCi built-in symbols)"),
    
    1255
    +                                    symhash, sym->lbl, sym->addr,
    
    1256
    +                                    sym->strength, sym->type, 0, NULL)) {
    
    1257
    +            barf("ghciInsertSymbolTable failed");
    
    1258
    +        }
    
    1259
    +    }
    
    1260
    +    IF_DEBUG(linker, debugBelch("done with built-in RTS symbols\n"));
    
    1261
    +}
    
    1217 1262
     
    
    1218 1263
     
    
    1219 1264
     // 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