Skip to content
Snippets Groups Projects
  1. Oct 18, 2024
    • Cheng Shao's avatar
      rts: don't build predefined GloblRegs for wasm PIC mode · cc67ef51
      Cheng Shao authored
      This commit wraps the predefined GlobalRegs in Wasm.S under a CPP
      guard to prevent building for PIC mode. When building dynamic ways of
      RTS, the wasm globals that represent STG GlobalRegs will be created
      and supplied by dyld.mjs. The current wasm dylink convention doesn't
      properly support exporting relocatable wasm globals at all, any wasm
      global exported by a .so is assumed to be a GOT.mem entry.
      
      (cherry picked from commit 98a32ec5)
      cc67ef51
    • Cheng Shao's avatar
      rts: drop interpretBCO support from non-dyn ways on wasm · 7a16cf7c
      Cheng Shao authored
      This commit drops interpretBCO support from non dynamic rts ways on
      wasm. The bytecode interpreter is only useful when the RTS linker also
      works, and on wasm it only works for dynamic ways anyway. An
      additional benefit of dropping interpretBCO is reduction in code size
      of linked wasm modules, especially since interpretBCO references
      ffi_call which is an auto-generated large function in libffi-wasm and
      unused by most user applications.
      
      (cherry picked from commit 90a35c41)
      7a16cf7c
    • Cheng Shao's avatar
      rts: correct stale link in comment · 9b67f849
      Cheng Shao authored
      (cherry picked from commit 0d0a16a8)
      9b67f849
    • Cheng Shao's avatar
      rts: add __wrapped_freeJSVal · fb77ea4a
      Cheng Shao authored
      This commit wraps imported freeJSVal in a __wrapped_freeJSVal C
      function for wasm backend RTS. In general, wasm imports are only
      supposed to be directly called by C; they shouldn't be used as
      function pointers, which confuses wasm-ld at link-time when generating
      shared libraries.
      
      (cherry picked from commit 33d9db17)
      fb77ea4a
    • Cheng Shao's avatar
      rts: rename prelude.js to prelude.mjs · d7a35d19
      Cheng Shao authored
      This commit renames prelude.js to prelude.mjs for wasm backend rts
      jsbits, and slightly adjusts the jsbits contents. This is for
      preparing the implementation of dyld.mjs that contains wasm dynamic
      linker logic, which needs to import prelude.mjs as a proper ESM
      module.
      
      (cherry picked from commit 71a471e7)
      d7a35d19
    • Cheng Shao's avatar
      ghc-internal: add missing CPPs for wasm · cf36ba7f
      Cheng Shao authored
      This patch adds some missing CPP guards to ghc-internal, given those
      functions are non existent on wasm and would cause linking issues.
      
      (cherry picked from commit a998f69d)
      cf36ba7f
    • Cheng Shao's avatar
      ghci: use plain malloc for mkConInfoTable on non-TNTC platforms · e54e3335
      Cheng Shao authored
      This patch avoids using mmap() to allocate executable memory for
      mkConInfoTable on platforms without tables-next-to-code, see added
      comment for explanation.
      
      (cherry picked from commit 839ac52e)
      e54e3335
    • Cheng Shao's avatar
      Drop obsolete libffi Makefile · 81ddb1e7
      Cheng Shao authored
      This patch drops obsolete libffi Makefile from the tree, given it's
      completely unused since removal of make build system in !7094.
      
      (cherry picked from commit 3fe843c7)
      81ddb1e7
    • Cheng Shao's avatar
      hadrian: remove unused ghciWithDebugger field from flavour config · 022d7565
      Cheng Shao authored
      This patch removes the ghciWithDebugger field from flavour config
      since it's actually not used anywhere.
      
      (cherry picked from commit c6e5fd3d)
      022d7565
    • Cheng Shao's avatar
      driver: fix runWorkerLimit on wasm · d769afff
      Cheng Shao authored
      This commit fixes link-time unresolved symbol errors for sem_open etc
      on wasm, by making runWorkerLimit always behave single-threaded. This
      avoids introducing the jobserver logic into the final wasm module and
      thus avoids referencing the posix semaphore symbols.
      
      (cherry picked from commit ceca9efb)
      d769afff
    • Cheng Shao's avatar
      rts: fix checkClosure error message · b1e8ca3d
      Cheng Shao authored
      This patch fixes an error message in checkClosure() when the closure
      has already been evacuated. The previous logic was meant to print the
      evacuated closure's type in the error message, but it was completely
      wrong, given info was not really an info table, but a tagged pointer
      that points to the closure's new address.
      
      (cherry picked from commit 0d3bc2fa)
      b1e8ca3d
    • Cheng Shao's avatar
      git: remove a.out and include it in .gitignore · 8abb0f19
      Cheng Shao authored
      a.out is a configure script byproduct. It was mistakenly checked into
      the tree in !13118. This patch removes it, and include it in
      .gitignore to prevent a similar error in the future.
      
      (cherry picked from commit f0408eeb)
      8abb0f19
    • Cheng Shao's avatar
      ghci: fix isMinTTY.h casing for Windows targets · 7bcc3dc6
      Cheng Shao authored
      This commit fixes isMinTTY.h casing in isMinTTY.c that's compiled for
      Windows targets. While this looks harmless given Windows filesystems
      are case-insensitive by default, it does cause a compilation warning
      with recent versions of clang, so we might as well fix the casing:
      
      ```
      driver\ghci\isMinTTY.c:10:10: error:
           warning: non-portable path to file '"isMinTTY.h"'; specified path differs in case from file name on disk [-Wnonportable-include-path]
         |
      10 | #include "isMINTTY.h"
         |          ^
      
       #include "isMINTTY.h"
               ^~~~~~~~~~~~
               "isMinTTY.h"
      1 warning generated.
      ```
      
      (cherry picked from commit 3a145315)
      7bcc3dc6
    • Cheng Shao's avatar
      testsuite: remove undesired -fasm flag from test ways · f603ac9c
      Cheng Shao authored
      This patch removes the -fasm flag from test ways, except ways like
      optasm that explicitly state they are meant to be compiled with NCG
      backend. Most test ways should use the default codegen backend, and
      the precense of -fasm can cause stderr mismatches like this when GHC
      is configured with the unregisterised backend:
      
      ```
      --- /dev/null
      +++ /tmp/ghctest-3hydwldj/test   spaces/testsuite/tests/profiling/should_compile/prof-late-cc.run/prof-late-cc.comp.stderr.normalised
      @@ -0,0 +1,2 @@
      +when making flags consistent: warning: [GHC-74335] [-Winconsistent-flags (in -Wdefault)]
      +    Target platform uses unregisterised ABI, so compiling via C
      *** unexpected failure for prof-late-cc(prof_no_auto)
      ```
      
      This has been breaking the wasm unreg nightly job since !12595 landed.
      
      (cherry picked from commit 88488847)
      f603ac9c
    • Cheng Shao's avatar
      testsuite: bump T17572 timeout on wasm32 · b35707a9
      Cheng Shao authored
      (cherry picked from commit 64fba310)
      b35707a9
    • Cheng Shao's avatar
      rts: use page sized mblocks on wasm · f3ea9fb8
      Cheng Shao authored
      This patch changes mblock size to page size on wasm. It allows us to
      simplify our wasi-libc fork, makes it much easier to test third party
      libc allocators like emmalloc/mimalloc, as well as experimenting with
      threaded RTS in wasm.
      
      (cherry picked from commit 558353f4)
      f3ea9fb8
    • Cheng Shao's avatar
      rts: replace ad-hoc MYTASK_USE_TLV with proper CC_SUPPORTS_TLS · 36629369
      Cheng Shao authored
      This patch replaces the ad-hoc `MYTASK_USE_TLV` with the
      `CC_SUPPORTS_TLS` macro. If TLS support is detected by autoconf, then
      we should use that for managing `myTask` in the threaded RTS.
      
      (cherry picked from commit f3017dd3)
      36629369
    • Cheng Shao's avatar
      rts: cleanup inlining logic · 241f401d
      Cheng Shao authored
      This patch removes pre-C11 legacy code paths related to
      INLINE_HEADER/STATIC_INLINE/EXTERN_INLINE macros, ensure EXTERN_INLINE
      is treated as static inline in most cases (fixes #24945), and also
      corrects the comments accordingly.
      
      (cherry picked from commit 35a64220)
      241f401d
    • Cheng Shao's avatar
      testsuite: skip objc-hi/objcxx-hi when cross compiling · 5273d3d0
      Cheng Shao authored
      objc-hi/objcxx-hi should be skipped when cross compiling. The existing
      opsys('darwin') predicate only asserts the host system is darwin but
      tells us nothing about the target, hence the oversight.
      
      (cherry picked from commit 595c0894)
      5273d3d0
    • Cheng Shao's avatar
      testsuite: bump T7653 timeout for wasm · 3f7b718f
      Cheng Shao authored
      (cherry picked from commit 2eee65e1)
      3f7b718f
    • Cheng Shao's avatar
      compiler: remove unused CompilerInfo/LinkerInfo types · db957a4d
      Cheng Shao authored
      This patch removes CompilerInfo/LinkerInfo types from the compiler
      since they aren't actually used anywhere.
      
      (cherry picked from commit 98ad1ea5)
      db957a4d
    • Cheng Shao's avatar
      compiler: emit NaturallyAligned when element type & index type are the same width · b6fce5bf
      Cheng Shao authored
      This commit fixes a subtle mistake in alignmentFromTypes that used to
      generate Unaligned when element type & index type are the same width.
      Fixes #24930.
      
      (cherry picked from commit 0cff083a)
      b6fce5bf
    • Cheng Shao's avatar
      testsuite: mark T7773 as fragile on wasm · b7e93bc9
      Cheng Shao authored
      (cherry picked from commit ae50a8eb)
      b7e93bc9
    • Cheng Shao's avatar
      hadrian: build in-tree GMP with malloc-notreentrant on wasm32 · 0f9a8aaf
      Cheng Shao authored
      This patch makes hadrian build in-tree GMP with the
      --enable-alloca=malloc-notreentrant configure option. We will only
      need malloc-reentrant when we have threaded RTS and SMP support on
      wasm32, which will take some time to happen, before which we should
      use malloc-notreentrant to avoid undesired runtime overhead.
      
      (cherry picked from commit 06277d56)
      0f9a8aaf
    • Cheng Shao's avatar
      hadrian: disable in-tree gmp fft code path for wasm32 · 097ea6e2
      Cheng Shao authored
      This patch disables in-tree GMP FFT code paths for wasm32 target in
      order to give up some performance of multiplying very large operands
      in exchange for reduced code size.
      
      (cherry picked from commit 1a32f828)
      097ea6e2
    • Cheng Shao's avatar
      hadrian: disable PIC for in-tree GMP on wasm32 · 5f728fc4
      Cheng Shao authored
      This patch disables PIC for in-tree GMP on wasm32 target. Enabling PIC
      unconditionally adds undesired code size and runtime overhead for
      wasm32.
      
      (cherry picked from commit f9c1ae12)
      5f728fc4
    • Cheng Shao's avatar
      compiler: fix -ddump-cmm-raw when compiling .cmm · e5a1dd43
      Cheng Shao authored
      This patch fixes missing -ddump-cmm-raw output when compiling .cmm,
      which is useful for debugging cmm related codegen issues.
      
      (cherry picked from commit 6346c669)
      e5a1dd43
    • Cheng Shao's avatar
      configure: do not set LLC/OPT/LLVMAS fallback values when FIND_LLVM_PROG fails · 76b7ae55
      Cheng Shao authored
      When configure fails to find LLC/OPT/LLVMAS within supported version
      range, it used to set "llc"/"opt"/"clang" as fallback values. This
      behavior is particularly troublesome when the user has llc/opt/clang
      with other versions in their PATH and run the testsuite, since hadrian
      will incorrectly assume have_llvm=True and pass that to the testsuite
      driver, resulting in annoying optllvm test failures (#23186). If
      configure determines llc/opt/clang wouldn't work, then we shouldn't
      pretend it'll work at all, and the bindist configure will invoke
      FIND_LLVM_PROG check again at install time anyway.
      
      (cherry picked from commit 4eb5ad09)
      76b7ae55
    • Cheng Shao's avatar
      hadrian: handle findExecutable "" gracefully · 78150bfc
      Cheng Shao authored
      hadrian may invoke findExecutable "" at run-time due to a certain
      program is not found by configure script. Which is fine and
      findExecutable is supposed to return Nothing in this case. However, on
      Windows there's a directory bug that throws an exception (see
      https://github.com/haskell/directory/issues/180), so we might as well
      use a wrapper for findExecutable and handle exceptions gracefully.
      
      (cherry picked from commit 1e5752f6)
      78150bfc
    • Cheng Shao's avatar
      utils: add hie.yaml config file for ghc-config · ed81a875
      Cheng Shao authored
      Add hie.yaml to ghc-config project directory so it can be edited using
      HLS.
      
      (cherry picked from commit 7eda4bd2)
      ed81a875
    • Cheng Shao's avatar
      compiler: remove ArchWasm32 special case in cmmDoCmmSwitchPlans · 8bd28cf2
      Cheng Shao authored
      This patch removes special consideration for ArchWasm32 in
      cmmDoCmmSwitchPlans, which means the compiler will now disable
      cmmImplementSwitchPlans for wasm unreg backend, just like unreg
      backend of other targets. We enabled it in the past to workaround some
      compile-time panic in older versions of LLVM, but those panics are no
      longer present, hence no need to keep this workaround.
      
      (cherry picked from commit bf0737c0)
      8bd28cf2
    • Cheng Shao's avatar
      testsuite: mark process005 as fragile on JS · 19e450a5
      Cheng Shao authored
      (cherry picked from commit fd47e2e3)
      19e450a5
    • Cheng Shao's avatar
      driver: build C/C++ with -ffunction-sections -fdata-sections when split sections is enabled · 74cdf564
      Cheng Shao authored
      When -fsplit-sections is passed to GHC, pass -ffunction-sections
      -fdata-sections to gcc/clang when building C/C++. Previously,
      -fsplit-sections was only respected by the NCG/LLVM backends, but not
      the unregisterised backend; the GHC driver did not pass
      -fdata-sections and -ffunction-sections to the C compiler, which
      resulted in excessive executable sizes.
      
      Fixes #23381.
      
      -------------------------
      Metric Decrease:
          size_hello_artifact
          size_hello_unicode
      -------------------------
      
      (cherry picked from commit 02b1f91e)
      74cdf564
    • Cheng Shao's avatar
      hadrian: build C/C++ with split sections when enabled · 7d5a22c2
      Cheng Shao authored
      When split sections is enabled, ensure -fsplit-sections is passed to
      GHC as well when invoking GHC to compile C/C++; and pass
      -ffunction-sections -fdata-sections to gcc/clang when compiling C/C++
      with the hadrian Cc builder. Fixes #23381.
      
      (cherry picked from commit 0958937e)
      7d5a22c2
    • Cheng Shao's avatar
      rts: use __builtin_offsetof to implement STG_FIELD_OFFSET · e18ea578
      Cheng Shao authored
      This patch fixes the STG_FIELD_OFFSET macro definition by using
      __builtin_offsetof, which is what gcc/clang uses to implement offsetof
      in standard C. The previous definition that uses NULL pointer involves
      subtle undefined behavior in C and thus reported by
      UndefinedBehaviorSanitizer as well:
      
      ```
      rts/Capability.h:243:58: runtime error: member access within null pointer of type 'Capability' (aka 'struct Capability_')
      SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior rts/Capability.h:243:58
      ```
      
      (cherry picked from commit 05c4fafb)
      e18ea578
    • Cheng Shao's avatar
      rts: fix an unaligned load in nonmoving gc · b18aa8e2
      Cheng Shao authored
      This patch fixes an unaligned load in nonmoving gc by ensuring the
      closure address is properly untagged first before attempting to
      prefetch its header. The unaligned load is reported by
      UndefinedBehaviorSanitizer:
      
      ```
      rts/sm/NonMovingMark.c:921:9: runtime error: member access within misaligned address 0x0042005f3a71 for type 'StgClosure' (aka 'struct StgClosure_'), which requires 8 byte alignment
      0x0042005f3a71: note: pointer points here
       00 00 00  98 43 13 8e 12 7f 00 00  50 3c 5f 00 42 00 00 00  58 17 b7 92 12 7f 00 00  89 cb 5e 00 42
                    ^
      SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior rts/sm/NonMovingMark.c:921:9
      ```
      
      This issue had previously gone unnoticed since it didn't really harm
      runtime correctness, the invalid header address directly loaded from a
      tagged pointer is only used as prefetch address and will not cause
      segfaults. However, it still should be corrected because the prefetch
      would be rendered useless by this issue, and untagging only involves a
      single bitwise operation without memory access so it's cheap enough to
      add.
      
      (cherry picked from commit c77a48af)
      b18aa8e2
    • Cheng Shao's avatar
      rts: ensure gc_thread/gen_workspace is allocated with proper alignment · f77369b9
      Cheng Shao authored
      gc_thread/gen_workspace are required to be aligned by 64 bytes.
      However, this property has not been properly enforced before, and
      numerous alignment violations at runtime has been caught by
      UndefinedBehaviorSanitizer that look like:
      
      ```
      rts/sm/GC.c:1167:8: runtime error: member access within misaligned address 0x0000027a3390 for type 'gc_thread' (aka 'struct gc_thread_'), which requires 64 byte alignment
      0x0000027a3390: note: pointer points here
       00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
                    ^
      SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior rts/sm/GC.c:1167:8
      
      rts/sm/GC.c:1184:13: runtime error: member access within misaligned address 0x0000027a3450 for type 'gen_workspace' (aka 'struct gen_workspace_'), which requires 64 byte alignment
      0x0000027a3450: note: pointer points here
       00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
                    ^
      SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior rts/sm/GC.c:1184:13
      ```
      
      This patch fixes the gc_thread/gen_workspace misalignment issue by
      explicitly allocating them with alignment constraint.
      
      (cherry picked from commit 7a660042)
      f77369b9
    • Cheng Shao's avatar
      testsuite: bump MultiLayerModulesDefsGhciReload timeout to 10x · 9a2f3313
      Cheng Shao authored
      (cherry picked from commit e17f2df9)
      9a2f3313
    • Cheng Shao's avatar
      rts: fix missing function prototypes in ClosureMacros.h · 952dd3f4
      Cheng Shao authored
      (cherry picked from commit 3ca72ad9)
      952dd3f4
    • Cheng Shao's avatar
      testsuite: add callee-no-local regression test · e33a21a4
      Cheng Shao authored
      (cherry picked from commit 986df1ab)
      e33a21a4
Loading