[Git][ghc/ghc][wip/marge_bot_batch_merge_job] 6 commits: compiler: use fromAscList when applicable

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Sat Feb 22 01:50:42 UTC 2025



Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC


Commits:
1c8e608a by Cheng Shao at 2025-02-21T20:18:41-05:00
compiler: use fromAscList when applicable

This patch uses fromAscList (with O(n) complexity) instead of fromList
(with O(nlogn) complexity) in certain Binary instances. It's safe to
do so since the corresponding serialization logic is based on toList
(same as toAscList).

- - - - -
549e0aff by Ben Gamari at 2025-02-21T20:19:18-05:00
rts/linker/MachO: Mark internal symbols as static

There is no reason why these should have external linkage.

- - - - -
55f5e32a by Cheng Shao at 2025-02-21T20:50:27-05:00
libffi: update to 3.4.7

- - - - -
f623e805 by Cheng Shao at 2025-02-21T20:50:28-05:00
wasm: bump dyld v8 heap size limit

This patch sets `--max-old-space-size=65536` as wasm dyld shebang
arguments to lessen v8 heap pressure in certain workloads that load
the full ghc package. It doesn't really commit 64G memory but it does
help reduce v8 gc overhead.

- - - - -
06fa5844 by Cheng Shao at 2025-02-21T20:50:28-05:00
wasm: fix dyld for shared libraries created by llvm 20.x

This patch fixes wasm dyld script for shared libraries created by llvm
20.x. The __wasm_apply_data_relocs function is now optional and may be
omitted for shared libraries without any runtime relocatable data
segments, so only call __wasm_apply_data_relocs when it's present.

- - - - -
c585d8b9 by Cheng Shao at 2025-02-21T20:50:28-05:00
driver: fix wasm backend sysroot lookup logic when -flto is passed

For the wasm target, the driver calls `wasm32-wasi-clang
--print-search-dirs` and finds the sysroot directory that contains
libc.so etc, then passes the directory path to dyld. However, when GHC
is configured with -flto as a part of C/C++ compiler flags, the clang
driver would insert a llvm-lto specific directory in the
--print-search-dirs output and the driver didn't take that into
account. This patch fixes it and always selects the non-lto sysroot
directory to be passed to dyld. This is one small step towards
supporting building all cbits with lto for wasm.

- - - - -


5 changed files:

- compiler/GHC.hs
- compiler/GHC/Utils/Binary.hs
- libffi-tarballs
- rts/linker/MachO.c
- utils/jsffi/dyld.mjs


Changes:

=====================================
compiler/GHC.hs
=====================================
@@ -717,11 +717,7 @@ setTopSessionDynFlags dflags = do
 #if defined(wasm32_HOST_ARCH)
         let libdir = sorry "cannot spawn child process on wasm"
 #else
-        libdir <- liftIO $ do
-          libdirs <- Loader.getGccSearchDirectory logger dflags "libraries"
-          case libdirs of
-            [_, libdir] -> pure libdir
-            _ -> panic "corrupted wasi-sdk installation"
+        libdir <- liftIO $ last <$> Loader.getGccSearchDirectory logger dflags "libraries"
 #endif
         let profiled = ways dflags `hasWay` WayProf
             way_tag = if profiled then "_p" else ""


=====================================
compiler/GHC/Utils/Binary.hs
=====================================
@@ -940,8 +940,8 @@ instance Binary a => Binary [a] where
 -- | This instance doesn't rely on the determinism of the keys' 'Ord' instance,
 -- so it works e.g. for 'Name's too.
 instance (Binary a, Ord a) => Binary (Set a) where
-  put_ bh s = put_ bh (Set.toList s)
-  get bh = Set.fromList <$> get bh
+  put_ bh s = put_ bh (Set.toAscList s)
+  get bh = Set.fromAscList <$> get bh
 
 instance Binary a => Binary (NonEmpty a) where
     put_ bh = put_ bh . NonEmpty.toList
@@ -2086,5 +2086,5 @@ source location as part of a larger structure.
 --------------------------------------------------------------------------------
 
 instance (Binary v) => Binary (IntMap v) where
-  put_ bh m = put_ bh (IntMap.toList m)
-  get bh = IntMap.fromList <$> get bh
+  put_ bh m = put_ bh (IntMap.toAscList m)
+  get bh = IntMap.fromAscList <$> get bh


=====================================
libffi-tarballs
=====================================
@@ -1 +1 @@
-Subproject commit 89a9b01c5647c8f0d3899435b99df690f582e9f1
+Subproject commit cb280851187d7b509d341be7b50c9a239810feb0


=====================================
rts/linker/MachO.c
=====================================
@@ -51,7 +51,7 @@
 /* often times we need to extend some value of certain number of bits
  * int an int64_t for e.g. relative offsets.
  */
-int64_t signExtend(uint64_t val, uint8_t bits);
+static int64_t signExtend(uint64_t val, uint8_t bits);
 /* Helper functions to check some instruction properties */
 static bool isVectorOp(uint32_t *p);
 static bool isLoadStore(uint32_t *p);
@@ -60,17 +60,17 @@ static bool isLoadStore(uint32_t *p);
  * where we want to write the address offset to. Thus decoding as well
  * as encoding is needed.
  */
-bool fitsBits(size_t bits, int64_t value);
-int64_t decodeAddend(ObjectCode * oc, Section * section,
+static bool fitsBits(size_t bits, int64_t value);
+static int64_t decodeAddend(ObjectCode * oc, Section * section,
                      MachORelocationInfo * ri);
-void encodeAddend(ObjectCode * oc, Section * section,
+static void encodeAddend(ObjectCode * oc, Section * section,
                   MachORelocationInfo * ri, int64_t addend);
 
 /* Global Offset Table logic */
-bool isGotLoad(MachORelocationInfo * ri);
-bool needGotSlot(MachONList * symbol);
-bool makeGot(ObjectCode * oc);
-void freeGot(ObjectCode * oc);
+static bool isGotLoad(MachORelocationInfo * ri);
+static bool needGotSlot(MachONList * symbol);
+static bool makeGot(ObjectCode * oc);
+static void freeGot(ObjectCode * oc);
 #endif /* aarch64_HOST_ARCH */
 
 /*
@@ -265,7 +265,7 @@ resolveImports(
 #if defined(aarch64_HOST_ARCH)
 /* aarch64 linker by moritz angermann <moritz at lichtzwerge.de> */
 
-int64_t
+static int64_t
 signExtend(uint64_t val, uint8_t bits) {
     return (int64_t)(val << (64-bits)) >> (64-bits);
 }
@@ -280,7 +280,7 @@ isLoadStore(uint32_t *p) {
     return (*p & 0x3B000000) == 0x39000000;
 }
 
-int64_t
+static int64_t
 decodeAddend(ObjectCode * oc, Section * section, MachORelocationInfo * ri) {
 
     /* the instruction. It is 32bit wide */
@@ -350,7 +350,7 @@ decodeAddend(ObjectCode * oc, Section * section, MachORelocationInfo * ri) {
     barf("unsupported relocation type: %d\n", ri->r_type);
 }
 
-inline bool
+inline static bool
 fitsBits(size_t bits, int64_t value) {
     if(bits == 64) return true;
     if(bits > 64) barf("fits_bits with %zu bits and an 64bit integer!", bits);
@@ -358,7 +358,7 @@ fitsBits(size_t bits, int64_t value) {
         || -1 == (value >> bits);  // All bits on: -1
 }
 
-void
+static void
 encodeAddend(ObjectCode * oc, Section * section,
              MachORelocationInfo * ri, int64_t addend) {
     uint32_t * p = (uint32_t*)((uint8_t*)section->start + ri->r_address);
@@ -440,7 +440,7 @@ encodeAddend(ObjectCode * oc, Section * section,
     barf("unsupported relocation type: %d\n", ri->r_type);
 }
 
-bool
+static bool
 isGotLoad(struct relocation_info * ri) {
     return ri->r_type == ARM64_RELOC_GOT_LOAD_PAGE21
     ||  ri->r_type == ARM64_RELOC_GOT_LOAD_PAGEOFF12;
@@ -450,7 +450,7 @@ isGotLoad(struct relocation_info * ri) {
  * Check if we need a global offset table slot for a
  * given symbol
  */
-bool
+static bool
 needGotSlot(MachONList * symbol) {
     return (symbol->n_type & N_EXT)             /* is an external symbol      */
         && (N_UNDF == (symbol->n_type & N_TYPE) /* and is undefined           */
@@ -458,7 +458,7 @@ needGotSlot(MachONList * symbol) {
                                                  *        different section   */
 }
 
-bool
+static bool
 makeGot(ObjectCode * oc) {
     size_t got_slots = 0;
 
@@ -484,7 +484,7 @@ makeGot(ObjectCode * oc) {
     return EXIT_SUCCESS;
 }
 
-void
+static void
 freeGot(ObjectCode * oc) {
     /* sanity check */
     if(NULL != oc->info->got_start && oc->info->got_size > 0) {


=====================================
utils/jsffi/dyld.mjs
=====================================
@@ -1,4 +1,4 @@
-#!/usr/bin/env -S node --disable-warning=ExperimentalWarning --experimental-wasm-type-reflection --max-old-space-size=8192 --no-turbo-fast-api-calls --wasm-lazy-validation
+#!/usr/bin/env -S node --disable-warning=ExperimentalWarning --experimental-wasm-type-reflection --max-old-space-size=65536 --no-turbo-fast-api-calls --wasm-lazy-validation
 
 // Note [The Wasm Dynamic Linker]
 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -796,12 +796,17 @@ class DyLD {
 
       const init = () => {
         // See
-        // https://github.com/llvm/llvm-project/blob/llvmorg-19.1.1/lld/wasm/Writer.cpp#L1430,
-        // there's also __wasm_init_memory (not relevant yet, we don't
+        // https://gitlab.haskell.org/haskell-wasm/llvm-project/-/blob/release/20.x/lld/wasm/Writer.cpp#L1450,
+        // __wasm_apply_data_relocs is now optional so only call it if
+        // it exists (we know for sure it exists for libc.so though).
+        // There's also __wasm_init_memory (not relevant yet, we don't
         // use passive segments) & __wasm_apply_global_relocs but
         // those are included in the start function and should have
-        // been called upon instantiation.
-        instance.exports.__wasm_apply_data_relocs();
+        // been called upon instantiation, see
+        // Writer::createStartFunction().
+        if (instance.exports.__wasm_apply_data_relocs) {
+          instance.exports.__wasm_apply_data_relocs();
+        }
 
         instance.exports._initialize();
       };



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/790cec9a908e4d9d866c7877a233453f07eab28b...c585d8b92c954f24a804e918d32eaea19e438aff

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/790cec9a908e4d9d866c7877a233453f07eab28b...c585d8b92c954f24a804e918d32eaea19e438aff
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20250221/cb738b98/attachment-0001.html>


More information about the ghc-commits mailing list