Duncan Coutts pushed to branch wip/dcoutts/windows-dlls at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • rts/Linker.c
    ... ... @@ -472,16 +472,7 @@ initLinker_ (int retain_cafs)
    472 472
         symhash = allocStrHashTable();
    
    473 473
     
    
    474 474
         /* populate the symbol table with stuff from the RTS */
    
    475
    -    IF_DEBUG(linker, debugBelch("populating linker symbol table with built-in RTS symbols\n"));
    
    476
    -    for (const RtsSymbolVal *sym = rtsSyms; sym->lbl != NULL; sym++) {
    
    477
    -        IF_DEBUG(linker, debugBelch("initLinker: inserting rts symbol %s, %p\n", sym->lbl, sym->addr));
    
    478
    -        if (! ghciInsertSymbolTable(WSTR("(GHCi built-in symbols)"),
    
    479
    -                                    symhash, sym->lbl, sym->addr,
    
    480
    -                                    sym->strength, sym->type, NULL)) {
    
    481
    -            barf("ghciInsertSymbolTable failed");
    
    482
    -        }
    
    483
    -    }
    
    484
    -    IF_DEBUG(linker, debugBelch("done with built-in RTS symbols\n"));
    
    475
    +    initLinkerRtsSyms(symhash);
    
    485 476
     
    
    486 477
         /* Add extra symbols. rtsExtraSyms() is a weakly defined symbol in the rts,
    
    487 478
          * 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"
    
    ... ... @@ -50,6 +51,18 @@ extern char **environ;
    50 51
     
    
    51 52
     /* -----------------------------------------------------------------------------
    
    52 53
      * Symbols to be inserted into the RTS symbol table.
    
    54
    + *
    
    55
    + * Note [Naming Scheme for Symbol Macros]
    
    56
    + *
    
    57
    + * SymI_*: symbol is internal to the RTS. It resides in an object
    
    58
    + *         file/library that is statically.
    
    59
    + * SymE_*: symbol is external to the RTS library. It might be linked
    
    60
    + *         dynamically.
    
    61
    + *
    
    62
    + * Sym*_HasProto  : the symbol prototype is imported in an include file
    
    63
    + *                  or defined explicitly
    
    64
    + * Sym*_NeedsProto: the symbol is undefined and we add a dummy
    
    65
    + *                  default proto extern void sym(void);
    
    53 66
      */
    
    54 67
     
    
    55 68
     #define Maybe_Stable_Names      SymI_HasProto(stg_mkWeakzh)                   \
    
    ... ... @@ -1127,12 +1140,21 @@ extern char **environ;
    1127 1140
           SymI_HasProto(hs_word2float64)
    
    1128 1141
     
    
    1129 1142
     
    
    1130
    -/* entirely bogus claims about types of these symbols */
    
    1131
    -#define SymI_NeedsProto(vvv)  extern void vvv(void);
    
    1132
    -#define SymI_NeedsDataProto(vvv)  extern StgWord vvv[];
    
    1133
    -#define SymE_NeedsProto(vvv)  SymI_NeedsProto(vvv);
    
    1134
    -#define SymE_NeedsDataProto(vvv)  SymI_NeedsDataProto(vvv);
    
    1135
    -#define SymE_HasProto(vvv)    SymI_HasProto(vvv);
    
    1143
    +/* Declare prototypes for the symbols that need it, so we can refer
    
    1144
    + * to them in the rtsSyms table below.
    
    1145
    + *
    
    1146
    + * In particular, for the external ones (SymE_*) we use the dllimport attribute
    
    1147
    + * to indicate that (on Windows) they come from external DLLs. This attribute
    
    1148
    + * is ignored on other platforms.
    
    1149
    + *
    
    1150
    + * The claims about the types of these symbols are entirely bogus.
    
    1151
    + */
    
    1152
    +#define SymI_NeedsProto(vvv)      extern                            void vvv(void);
    
    1153
    +#define SymI_NeedsDataProto(vvv)  extern                            StgWord vvv[];
    
    1154
    +#define SymE_NeedsProto(vvv)      extern __attribute__((dllimport)) void vvv(void);
    
    1155
    +#define SymE_NeedsDataProto(vvv)  extern __attribute__((dllimport)) StgWord vvv[];
    
    1156
    +
    
    1157
    +#define SymE_HasProto(vvv) /**/
    
    1136 1158
     #define SymI_HasProto(vvv) /**/
    
    1137 1159
     #define SymI_HasDataProto(vvv) /**/
    
    1138 1160
     #define SymI_HasProto_redirect(vvv,xxx,strength,ty) /**/
    
    ... ... @@ -1161,6 +1183,8 @@ RTS_SYMBOLS_PRIM
    1161 1183
     #undef SymE_NeedsProto
    
    1162 1184
     #undef SymE_NeedsDataProto
    
    1163 1185
     
    
    1186
    +/* See Note [Naming Scheme for Symbol Macros] */
    
    1187
    +
    
    1164 1188
     #define SymI_HasProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
    
    1165 1189
                         (void*)(&(vvv)), STRENGTH_NORMAL, SYM_TYPE_CODE },
    
    1166 1190
     #define SymI_HasDataProto(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
    
    ... ... @@ -1181,7 +1205,16 @@ RTS_SYMBOLS_PRIM
    1181 1205
         { MAYBE_LEADING_UNDERSCORE_STR(#vvv),    \
    
    1182 1206
           (void*)(&(xxx)), strength, ty },
    
    1183 1207
     
    
    1184
    -RtsSymbolVal rtsSyms[] = {
    
    1208
    +
    
    1209
    +/* Populate the symbol table with stuff from the RTS. */
    
    1210
    +void initLinkerRtsSyms (StrHashTable *symhash) {
    
    1211
    +
    
    1212
    +    /* The address of data symbols with the dllimport attribute are not
    
    1213
    +     * compile-time constants and so cannot be used in constant initialisers.
    
    1214
    +     * For this reason, rtsSyms is a local variable within this function
    
    1215
    +     * rather than a global constant (as it was historically).
    
    1216
    +     */
    
    1217
    +    const RtsSymbolVal rtsSyms[] = {
    
    1185 1218
           RTS_SYMBOLS
    
    1186 1219
           RTS_RET_SYMBOLS
    
    1187 1220
           RTS_POSIX_ONLY_SYMBOLS
    
    ... ... @@ -1196,7 +1229,19 @@ RtsSymbolVal rtsSyms[] = {
    1196 1229
           RTS_SYMBOLS_PRIM
    
    1197 1230
           SymI_HasDataProto(nonmoving_write_barrier_enabled)
    
    1198 1231
           { 0, 0, STRENGTH_NORMAL, SYM_TYPE_CODE } /* sentinel */
    
    1199
    -};
    
    1232
    +    };
    
    1233
    +
    
    1234
    +    IF_DEBUG(linker, debugBelch("populating linker symbol table with built-in RTS symbols\n"));
    
    1235
    +    for (const RtsSymbolVal *sym = rtsSyms; sym->lbl != NULL; sym++) {
    
    1236
    +        IF_DEBUG(linker, debugBelch("initLinker: inserting rts symbol %s, %p\n", sym->lbl, sym->addr));
    
    1237
    +        if (! ghciInsertSymbolTable(WSTR("(GHCi built-in symbols)"),
    
    1238
    +                                    symhash, sym->lbl, sym->addr,
    
    1239
    +                                    sym->strength, sym->type, NULL)) {
    
    1240
    +            barf("ghciInsertSymbolTable failed");
    
    1241
    +        }
    
    1242
    +    }
    
    1243
    +    IF_DEBUG(linker, debugBelch("done with built-in RTS symbols\n"));
    
    1244
    +}
    
    1200 1245
     
    
    1201 1246
     
    
    1202 1247
     // 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