From 5915b86a1895c533e943e002f9de4a951d170814 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Wed, 4 Dec 2024 16:01:01 +1300 Subject: [PATCH] Fix patches for GHC 8.10 --- overlays/bootstrap.nix | 8 +- ...s-support-for-Hidden-symbols-android.patch | 233 ++++++++++++++++++ 2 files changed, 239 insertions(+), 2 deletions(-) create mode 100644 overlays/patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols-android.patch diff --git a/overlays/bootstrap.nix b/overlays/bootstrap.nix index f7e2af24f..1878e404f 100644 --- a/overlays/bootstrap.nix +++ b/overlays/bootstrap.nix @@ -271,8 +271,12 @@ in { ++ fromUntil "9.8" "9.9" ./patches/ghc/docs-sphinx-7-ghc98.patch # These two patches are needed for libblst, which has now hidden symbols, which the linker doesn't know how to deal with. - ++ until "9.0" ./patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols.patch - ++ until "9.0" ./patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols-2.patch + ++ ( + if final.stdenv.targetPlatform.isAndroid + then until "9.0" ./patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols-android.patch + else until "9.0" ./patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols.patch + ++ until "9.0" ./patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols-2.patch + ) ++ onWindowsOrMusl (fromUntil "9.6" "9.7" ./patches/ghc/ghc-9.6-0006-Adds-support-for-Hidden-symbols.patch) ++ onWindowsOrMusl (fromUntil "9.8.2" "9.11" ./patches/ghc/ghc-9.6-0006-Adds-support-for-Hidden-symbols.patch) ++ onWindowsOrMusl (fromUntil "9.6" "9.7" ./patches/ghc/ghc-9.6-0006-Adds-support-for-Hidden-symbols-2.patch) diff --git a/overlays/patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols-android.patch b/overlays/patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols-android.patch new file mode 100644 index 000000000..69bba7d9c --- /dev/null +++ b/overlays/patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols-android.patch @@ -0,0 +1,233 @@ +diff --git a/rts/Linker.c b/rts/Linker.c +index 3428a010da..6eb43be959 100644 +--- a/rts/Linker.c ++++ b/rts/Linker.c +@@ -267,9 +267,12 @@ int ghciInsertSymbolTable( + HashTable *table, + const SymbolName* key, + SymbolAddr* data, +- HsBool weak, ++ int flags, + ObjectCode *owner) + { ++ HsBool weak = flags & 1; ++ HsBool hidden = flags & 2; ++ + RtsSymbolInfo *pinfo = lookupStrHashTable(table, key); + if (!pinfo) /* new entry */ + { +@@ -277,6 +280,7 @@ int ghciInsertSymbolTable( + pinfo->value = data; + pinfo->owner = owner; + pinfo->weak = weak; ++ pinfo->hidden = hidden; + insertStrHashTable(table, key, pinfo); + return 1; + } +@@ -340,11 +344,22 @@ int ghciInsertSymbolTable( + call this function again to trigger the duplicate error. */ + return 1; + } ++ else if(pinfo->hidden && !hidden) ++ { ++ /* The existing symbol is hidden, let's replace it */ ++ pinfo->value = data; ++ pinfo->owner = owner; ++ pinfo->weak = weak; + ++ pinfo->hidden = hidden; ++ return 1; ++ } + pathchar* archiveName = NULL; + debugBelch( + "GHC runtime linker: fatal error: I found a duplicate definition for symbol\n" + " %s\n" ++ " new symbol is hidden: %d\n" ++ " old symbol is hidden: %d\n" + "whilst processing object file\n" + " %" PATH_FMT "\n" + "The symbol was previously defined in\n" +@@ -355,6 +370,8 @@ int ghciInsertSymbolTable( + " * An incorrect `package.conf' entry, causing some object to be\n" + " loaded twice.\n", + (char*)key, ++ hidden ? 1 : 0, ++ pinfo->hidden ? 1 : 0, + obj_name, + pinfo->owner == NULL ? WSTR("(GHCi built-in symbols)") : + pinfo->owner->archiveMemberName ? archiveName = mkPath(pinfo->owner->archiveMemberName) +@@ -451,7 +468,7 @@ initLinker_ (int retain_cafs) + for (sym = rtsSyms; sym->lbl != NULL; sym++) { + if (! ghciInsertSymbolTable(WSTR("(GHCi built-in symbols)"), + symhash, sym->lbl, sym->addr, +- sym->weak, NULL)) { ++ sym->weak | (HS_BOOL_FALSE << 1), NULL)) { + barf("ghciInsertSymbolTable failed"); + } + IF_DEBUG(linker, debugBelch("initLinker: inserting rts symbol %s, %p\n", sym->lbl, sym->addr)); +@@ -463,7 +480,7 @@ initLinker_ (int retain_cafs) + use an arbitrary (hopefully unique) address here. + */ + if (! ghciInsertSymbolTable(WSTR("(GHCi special symbols)"), +- symhash, "__dso_handle", (void *)0x12345687, HS_BOOL_FALSE, NULL)) { ++ symhash, "__dso_handle", (void *)0x12345687, HS_BOOL_FALSE | (HS_BOOL_FALSE << 1), NULL)) { + barf("ghciInsertSymbolTable failed"); + } + +@@ -471,7 +488,7 @@ initLinker_ (int retain_cafs) + if (! ghciInsertSymbolTable(WSTR("(GHCi built-in symbols)"), symhash, + MAYBE_LEADING_UNDERSCORE_STR("newCAF"), + retain_cafs ? newRetainedCAF : newGCdCAF, +- HS_BOOL_FALSE, NULL)) { ++ HS_BOOL_FALSE | (HS_BOOL_FALSE << 1), NULL)) { + barf("ghciInsertSymbolTable failed"); + } + +@@ -844,8 +861,8 @@ HsBool removeLibrarySearchPath(HsPtr dll_path_index) + */ + HsInt insertSymbol(pathchar* obj_name, SymbolName* key, SymbolAddr* data) + { +- return ghciInsertSymbolTable(obj_name, symhash, key, data, HS_BOOL_FALSE, +- NULL); ++ return ghciInsertSymbolTable(obj_name, symhash, key, data, ++ HS_BOOL_FALSE | (HS_BOOL_FALSE << 1), NULL); + } + + /* ----------------------------------------------------------------------------- +@@ -1696,7 +1713,8 @@ int ocTryLoad (ObjectCode* oc) { + if ( symbol.name + && !ghciInsertSymbolTable(oc->fileName, symhash, symbol.name, + symbol.addr, +- isSymbolWeak(oc, symbol.name), oc)) { ++ isSymbolWeak(oc, symbol.name) | (HS_BOOL_FALSE << 1), ++ oc)) { + return 0; + } + } +diff --git a/rts/LinkerInternals.h b/rts/LinkerInternals.h +index a846bf5ca7..acba66828b 100644 +--- a/rts/LinkerInternals.h ++++ b/rts/LinkerInternals.h +@@ -310,6 +310,7 @@ typedef struct _RtsSymbolInfo { + SymbolAddr* value; + ObjectCode *owner; + HsBool weak; ++ HsBool hidden; + } RtsSymbolInfo; + + void exitLinker( void ); +@@ -337,7 +338,7 @@ int ghciInsertSymbolTable( + HashTable *table, + const SymbolName* key, + SymbolAddr* data, +- HsBool weak, ++ int flags, + ObjectCode *owner); + + /* Lock-free version of lookupSymbol. When 'dependent' is not NULL, adds it as a +diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c +index c3f9110509..5bf7f00f31 100644 +--- a/rts/linker/Elf.c ++++ b/rts/linker/Elf.c +@@ -1013,7 +1013,9 @@ ocGetNames_ELF ( ObjectCode* oc ) + setWeakSymbol(oc, nm); + } + if (!ghciInsertSymbolTable(oc->fileName, symhash, +- nm, symbol->addr, isWeak, oc)) { ++ nm, symbol->addr, ++ isWeak | ((ELF_ST_VISIBILITY(symbol->elf_sym->st_other) == STV_HIDDEN) << 1), ++ oc)) { + goto fail; + } + oc->symbols[curSymbol++].name = nm; +diff --git a/rts/linker/ElfTypes.h b/rts/linker/ElfTypes.h +index e5333d71a7..0a8e44a076 100644 +--- a/rts/linker/ElfTypes.h ++++ b/rts/linker/ElfTypes.h +@@ -32,6 +32,9 @@ + #define Elf_Sym Elf64_Sym + #define Elf_Rel Elf64_Rel + #define Elf_Rela Elf64_Rela ++#if !defined(ELF_ST_VISIBILITY) ++#define ELF_ST_VISIBILITY ELF64_ST_VISIBILITY ++#endif + #if !defined(ELF_ST_TYPE) + #define ELF_ST_TYPE ELF64_ST_TYPE + #endif +@@ -56,6 +59,9 @@ + #define Elf_Sym Elf32_Sym + #define Elf_Rel Elf32_Rel + #define Elf_Rela Elf32_Rela ++#if !defined(ELF_ST_VISIBILITY) ++#define ELF_ST_VISIBILITY ELF32_ST_VISIBILITY ++#endif /* ELF_ST_VISIBILITY */ + #if !defined(ELF_ST_TYPE) + #define ELF_ST_TYPE ELF32_ST_TYPE + #endif /* ELF_ST_TYPE */ +diff --git a/rts/linker/MachO.c b/rts/linker/MachO.c +index 00b0dce04c..d63369972d 100644 +--- a/rts/linker/MachO.c ++++ b/rts/linker/MachO.c +@@ -1336,7 +1336,7 @@ ocGetNames_MachO(ObjectCode* oc) + , symhash + , nm + , addr +- , HS_BOOL_FALSE ++ , HS_BOOL_FALSE | (HS_BOOL_FALSE << 1) + , oc); + + oc->symbols[curSymbol].name = nm; +@@ -1376,7 +1376,7 @@ ocGetNames_MachO(ObjectCode* oc) + + IF_DEBUG(linker, debugBelch("ocGetNames_MachO: inserting common symbol: %s\n", nm)); + ghciInsertSymbolTable(oc->fileName, symhash, nm, +- (void*)commonCounter, HS_BOOL_FALSE, oc); ++ (void*)commonCounter, HS_BOOL_FALSE | (HS_BOOL_FALSE << 1), oc); + oc->symbols[curSymbol].name = nm; + oc->symbols[curSymbol].addr = oc->info->macho_symbols[i].addr; + curSymbol++; +diff --git a/rts/linker/PEi386.c b/rts/linker/PEi386.c +index c73d858d52..74b7fd1009 100644 +--- a/rts/linker/PEi386.c ++++ b/rts/linker/PEi386.c +@@ -292,7 +292,7 @@ const void* __rts_iob_func = (void*)&__acrt_iob_func; + void initLinker_PEi386() + { + if (!ghciInsertSymbolTable(WSTR("(GHCi/Ld special symbols)"), +- symhash, "__image_base__", __image_base, HS_BOOL_TRUE, NULL)) { ++ symhash, "__image_base__", __image_base, HS_BOOL_TRUE | (HS_BOOL_FALSE << 1), NULL)) { + barf("ghciInsertSymbolTable failed"); + } + +@@ -1533,7 +1533,7 @@ ocGetNames_PEi386 ( ObjectCode* oc ) + sname = strdup (sname); + addr = strdup (addr); + if (!ghciInsertSymbolTable(oc->fileName, symhash, sname, +- addr, false, oc)) { ++ addr, HS_BOOL_FALSE | (HS_BOOL_FALSE << 1), oc)) { + releaseOcInfo (oc); + stgFree (oc->image); + oc->image = NULL; +@@ -1751,7 +1751,9 @@ ocGetNames_PEi386 ( ObjectCode* oc ) + stgFree(tmp); + sname = strdup (sname); + if (!ghciInsertSymbolTable(oc->fileName, symhash, sname, +- addr, false, oc)) ++ addr, ++ HS_BOOL_FALSE | ((secNumber == IMAGE_SYM_UNDEFINED) << 1), ++ oc)) + return false; + + break; +@@ -1768,9 +1770,9 @@ ocGetNames_PEi386 ( ObjectCode* oc ) + if (isWeak) { + setWeakSymbol(oc, sname); + } +- + if (! ghciInsertSymbolTable(oc->fileName, symhash, sname, addr, +- isWeak, oc)) ++ isWeak | ((secNumber == IMAGE_SYM_UNDEFINED) << 1), ++ oc)) + return false; + } else { + /* We're skipping the symbol, but if we ever load this