|
| 1 | +diff --git a/rts/Linker.c b/rts/Linker.c |
| 2 | +index 10b0764..587f16a 100644 |
| 3 | +--- a/rts/Linker.c |
| 4 | ++++ b/rts/Linker.c |
| 5 | +@@ -268,6 +268,7 @@ int ghciInsertSymbolTable( |
| 6 | + const SymbolName* key, |
| 7 | + SymbolAddr* data, |
| 8 | + HsBool weak, |
| 9 | ++ HsBool hidden, |
| 10 | + ObjectCode *owner) |
| 11 | + { |
| 12 | + RtsSymbolInfo *pinfo = lookupStrHashTable(table, key); |
| 13 | +@@ -277,6 +278,7 @@ int ghciInsertSymbolTable( |
| 14 | + pinfo->value = data; |
| 15 | + pinfo->owner = owner; |
| 16 | + pinfo->weak = weak; |
| 17 | ++ pinfo->hidden = hidden; |
| 18 | + insertStrHashTable(table, key, pinfo); |
| 19 | + return 1; |
| 20 | + } |
| 21 | +@@ -340,11 +342,23 @@ int ghciInsertSymbolTable( |
| 22 | + call this function again to trigger the duplicate error. */ |
| 23 | + return 1; |
| 24 | + } |
| 25 | ++ else if(pinfo->hidden && !hidden) |
| 26 | ++ { |
| 27 | ++ /* The existing symbol is hidden, let's replace it */ |
| 28 | ++ pinfo->value = data; |
| 29 | ++ pinfo->owner = owner; |
| 30 | ++ pinfo->weak = weak; |
| 31 | ++ |
| 32 | ++ pinfo->hidden = hidden; |
| 33 | ++ return 1; |
| 34 | ++ } |
| 35 | + |
| 36 | + pathchar* archiveName = NULL; |
| 37 | + debugBelch( |
| 38 | + "GHC runtime linker: fatal error: I found a duplicate definition for symbol\n" |
| 39 | + " %s\n" |
| 40 | ++ " new symbol is hidden: %d\n" |
| 41 | ++ " old symbol is hidden: %d\n" |
| 42 | + "whilst processing object file\n" |
| 43 | + " %" PATH_FMT "\n" |
| 44 | + "The symbol was previously defined in\n" |
| 45 | +@@ -355,6 +369,8 @@ int ghciInsertSymbolTable( |
| 46 | + " * An incorrect `package.conf' entry, causing some object to be\n" |
| 47 | + " loaded twice.\n", |
| 48 | + (char*)key, |
| 49 | ++ hidden ? 1 : 0, |
| 50 | ++ pinfo->hidden ? 1 : 0, |
| 51 | + obj_name, |
| 52 | + pinfo->owner == NULL ? WSTR("(GHCi built-in symbols)") : |
| 53 | + pinfo->owner->archiveMemberName ? archiveName = mkPath(pinfo->owner->archiveMemberName) |
| 54 | +@@ -451,7 +467,7 @@ initLinker_ (int retain_cafs) |
| 55 | + for (sym = rtsSyms; sym->lbl != NULL; sym++) { |
| 56 | + if (! ghciInsertSymbolTable(WSTR("(GHCi built-in symbols)"), |
| 57 | + symhash, sym->lbl, sym->addr, |
| 58 | +- sym->weak, NULL)) { |
| 59 | ++ sym->weak, HS_BOOL_FALSE, NULL)) { |
| 60 | + barf("ghciInsertSymbolTable failed"); |
| 61 | + } |
| 62 | + IF_DEBUG(linker, debugBelch("initLinker: inserting rts symbol %s, %p\n", sym->lbl, sym->addr)); |
| 63 | +@@ -463,7 +479,7 @@ initLinker_ (int retain_cafs) |
| 64 | + use an arbitrary (hopefully unique) address here. |
| 65 | + */ |
| 66 | + if (! ghciInsertSymbolTable(WSTR("(GHCi special symbols)"), |
| 67 | +- symhash, "__dso_handle", (void *)0x12345687, HS_BOOL_FALSE, NULL)) { |
| 68 | ++ symhash, "__dso_handle", (void *)0x12345687, HS_BOOL_FALSE, HS_BOOL_FALSE, NULL)) { |
| 69 | + barf("ghciInsertSymbolTable failed"); |
| 70 | + } |
| 71 | + |
| 72 | +@@ -471,7 +487,7 @@ initLinker_ (int retain_cafs) |
| 73 | + if (! ghciInsertSymbolTable(WSTR("(GHCi built-in symbols)"), symhash, |
| 74 | + MAYBE_LEADING_UNDERSCORE_STR("newCAF"), |
| 75 | + retain_cafs ? newRetainedCAF : newGCdCAF, |
| 76 | +- HS_BOOL_FALSE, NULL)) { |
| 77 | ++ HS_BOOL_FALSE, HS_BOOL_FALSE, NULL)) { |
| 78 | + barf("ghciInsertSymbolTable failed"); |
| 79 | + } |
| 80 | + |
| 81 | +@@ -845,7 +861,7 @@ HsBool removeLibrarySearchPath(HsPtr dll_path_index) |
| 82 | + HsInt insertSymbol(pathchar* obj_name, SymbolName* key, SymbolAddr* data) |
| 83 | + { |
| 84 | + return ghciInsertSymbolTable(obj_name, symhash, key, data, HS_BOOL_FALSE, |
| 85 | +- NULL); |
| 86 | ++ HS_BOOL_FALSE, NULL); |
| 87 | + } |
| 88 | + |
| 89 | + /* ----------------------------------------------------------------------------- |
| 90 | +@@ -1699,7 +1715,8 @@ int ocTryLoad (ObjectCode* oc) { |
| 91 | + if ( symbol.name |
| 92 | + && !ghciInsertSymbolTable(oc->fileName, symhash, symbol.name, |
| 93 | + symbol.addr, |
| 94 | +- isSymbolWeak(oc, symbol.name), oc)) { |
| 95 | ++ isSymbolWeak(oc, symbol.name), |
| 96 | ++ HS_BOOL_FALSE, oc)) { |
| 97 | + return 0; |
| 98 | + } |
| 99 | + } |
| 100 | +diff --git a/rts/LinkerInternals.h b/rts/LinkerInternals.h |
| 101 | +index f326a84..1bc082c 100644 |
| 102 | +--- a/rts/LinkerInternals.h |
| 103 | ++++ b/rts/LinkerInternals.h |
| 104 | +@@ -306,6 +306,7 @@ typedef struct _RtsSymbolInfo { |
| 105 | + SymbolAddr* value; |
| 106 | + ObjectCode *owner; |
| 107 | + HsBool weak; |
| 108 | ++ HsBool hidden; |
| 109 | + } RtsSymbolInfo; |
| 110 | + |
| 111 | + void exitLinker( void ); |
| 112 | +@@ -334,6 +335,7 @@ int ghciInsertSymbolTable( |
| 113 | + const SymbolName* key, |
| 114 | + SymbolAddr* data, |
| 115 | + HsBool weak, |
| 116 | ++ HsBool hidden, |
| 117 | + ObjectCode *owner); |
| 118 | + |
| 119 | + /* Lock-free version of lookupSymbol. When 'dependent' is not NULL, adds it as a |
| 120 | +diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c |
| 121 | +index fdfe87a..4a53687 100644 |
| 122 | +--- a/rts/linker/Elf.c |
| 123 | ++++ b/rts/linker/Elf.c |
| 124 | +@@ -976,7 +976,9 @@ ocGetNames_ELF ( ObjectCode* oc ) |
| 125 | + setWeakSymbol(oc, nm); |
| 126 | + } |
| 127 | + if (!ghciInsertSymbolTable(oc->fileName, symhash, |
| 128 | +- nm, symbol->addr, isWeak, oc) |
| 129 | ++ nm, symbol->addr, isWeak, |
| 130 | ++ ELF_ST_VISIBILITY(symbol->elf_sym->st_other) == STV_HIDDEN, |
| 131 | ++ oc) |
| 132 | + ) { |
| 133 | + goto fail; |
| 134 | + } |
| 135 | +diff --git a/rts/linker/ElfTypes.h b/rts/linker/ElfTypes.h |
| 136 | +index e5333d7..0a8e44a 100644 |
| 137 | +--- a/rts/linker/ElfTypes.h |
| 138 | ++++ b/rts/linker/ElfTypes.h |
| 139 | +@@ -32,6 +32,9 @@ |
| 140 | + #define Elf_Sym Elf64_Sym |
| 141 | + #define Elf_Rel Elf64_Rel |
| 142 | + #define Elf_Rela Elf64_Rela |
| 143 | ++#if !defined(ELF_ST_VISIBILITY) |
| 144 | ++#define ELF_ST_VISIBILITY ELF64_ST_VISIBILITY |
| 145 | ++#endif |
| 146 | + #if !defined(ELF_ST_TYPE) |
| 147 | + #define ELF_ST_TYPE ELF64_ST_TYPE |
| 148 | + #endif |
| 149 | +@@ -56,6 +59,9 @@ |
| 150 | + #define Elf_Sym Elf32_Sym |
| 151 | + #define Elf_Rel Elf32_Rel |
| 152 | + #define Elf_Rela Elf32_Rela |
| 153 | ++#if !defined(ELF_ST_VISIBILITY) |
| 154 | ++#define ELF_ST_VISIBILITY ELF32_ST_VISIBILITY |
| 155 | ++#endif /* ELF_ST_VISIBILITY */ |
| 156 | + #if !defined(ELF_ST_TYPE) |
| 157 | + #define ELF_ST_TYPE ELF32_ST_TYPE |
| 158 | + #endif /* ELF_ST_TYPE */ |
| 159 | +diff --git a/rts/linker/PEi386.c b/rts/linker/PEi386.c |
| 160 | +index 6d0d417..841faa8 100644 |
| 161 | +--- a/rts/linker/PEi386.c |
| 162 | ++++ b/rts/linker/PEi386.c |
| 163 | +@@ -292,7 +292,7 @@ const void* __rts_iob_func = (void*)&__acrt_iob_func; |
| 164 | + void initLinker_PEi386() |
| 165 | + { |
| 166 | + if (!ghciInsertSymbolTable(WSTR("(GHCi/Ld special symbols)"), |
| 167 | +- symhash, "__image_base__", __image_base, HS_BOOL_TRUE, NULL)) { |
| 168 | ++ symhash, "__image_base__", __image_base, HS_BOOL_TRUE, HS_BOOL_FALSE, NULL)) { |
| 169 | + barf("ghciInsertSymbolTable failed"); |
| 170 | + } |
| 171 | + |
| 172 | +@@ -1541,7 +1541,7 @@ ocGetNames_PEi386 ( ObjectCode* oc ) |
| 173 | + sname = strdup (sname); |
| 174 | + addr = strdup (addr); |
| 175 | + if (!ghciInsertSymbolTable(oc->fileName, symhash, sname, |
| 176 | +- addr, false, oc)) { |
| 177 | ++ addr, false, HS_BOOL_FALSE, oc)) { |
| 178 | + releaseOcInfo (oc); |
| 179 | + stgFree (oc->image); |
| 180 | + oc->image = NULL; |
| 181 | +@@ -1759,7 +1759,9 @@ ocGetNames_PEi386 ( ObjectCode* oc ) |
| 182 | + stgFree(tmp); |
| 183 | + sname = strdup (sname); |
| 184 | + if (!ghciInsertSymbolTable(oc->fileName, symhash, sname, |
| 185 | +- addr, false, oc)) |
| 186 | ++ addr, false, |
| 187 | ++ section->info->props & IMAGE_SCN_LNK_COMDAT, |
| 188 | ++ oc)) |
| 189 | + return false; |
| 190 | + |
| 191 | + break; |
| 192 | +@@ -1776,9 +1778,10 @@ ocGetNames_PEi386 ( ObjectCode* oc ) |
| 193 | + if (isWeak) { |
| 194 | + setWeakSymbol(oc, sname); |
| 195 | + } |
| 196 | +- |
| 197 | + if (! ghciInsertSymbolTable(oc->fileName, symhash, sname, addr, |
| 198 | +- isWeak, oc)) |
| 199 | ++ isWeak, |
| 200 | ++ section->info->props & IMAGE_SCN_LNK_COMDAT, |
| 201 | ++ oc)) |
| 202 | + return false; |
| 203 | + } else { |
| 204 | + /* We're skipping the symbol, but if we ever load this |
0 commit comments