[Git][ghc/ghc][wip/andreask/mkTickUnsafeCoerce] 51 commits: ghci: mitigate host/target word size mismatch in BCOByteArray serialization
Andreas Klebinger (@AndreasK)
gitlab at gitlab.haskell.org
Fri Oct 18 13:22:38 UTC 2024
Andreas Klebinger pushed to branch wip/andreask/mkTickUnsafeCoerce at Glasgow Haskell Compiler / GHC
Commits:
90891962 by Cheng Shao at 2024-10-17T16:41:18+00:00
ghci: mitigate host/target word size mismatch in BCOByteArray serialization
This patch mitigates a severe host/target word size mismatch issue in
BCOByteArray serialization logic introduced since !12142, see added
note for detailed explanation.
- - - - -
839ac52e by Cheng Shao at 2024-10-17T16:41:18+00:00
ghci: use plain malloc for mkConInfoTable on non-TNTC platforms
This patch avoids using mmap() to allocate executable memory for
mkConInfoTable on platforms without tables-next-to-code, see added
comment for explanation.
- - - - -
a998f69d by Cheng Shao at 2024-10-17T16:41:18+00:00
ghc-internal: add missing CPPs for wasm
This patch adds some missing CPP guards to ghc-internal, given those
functions are non existent on wasm and would cause linking issues.
- - - - -
71a471e7 by Cheng Shao at 2024-10-17T16:41:18+00:00
rts: rename prelude.js to prelude.mjs
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.
- - - - -
33d9db17 by Cheng Shao at 2024-10-17T16:41:18+00:00
rts: add __wrapped_freeJSVal
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.
- - - - -
0d0a16a8 by Cheng Shao at 2024-10-17T16:41:18+00:00
rts: correct stale link in comment
- - - - -
90a35c41 by Cheng Shao at 2024-10-17T16:41:18+00:00
rts: drop interpretBCO support from non-dyn ways on wasm
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.
- - - - -
98a32ec5 by Cheng Shao at 2024-10-17T16:41:18+00:00
rts: don't build predefined GloblRegs for wasm PIC mode
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.
- - - - -
bef94bde by Cheng Shao at 2024-10-17T16:41:18+00:00
rts: fix conflicting StgRun definitions on wasm
This commit fixes conflicting StgRun definition when building dynamic
ways of RTS for wasm in unregisterised mode.
- - - - -
a6a82cdb by Cheng Shao at 2024-10-17T16:41:18+00:00
hadrian: use targetSupportsRPaths predicate
This commit changes the hostSupportsRPaths predicate to
targetSupportsRPaths and use that to decide whether to pass
RPATH-related link-time options. It's not applied to stage0, we should
just use the default link-time options of stageBoot ghc.
- - - - -
f232c872 by Cheng Shao at 2024-10-17T16:41:18+00:00
hadrian: disable internal-interpreter of ghc library when cross compiling
This commit disable the internal-interpreter flag of ghc library when
cross compiling, only external interpreter works in such cases.
- - - - -
577c1819 by Cheng Shao at 2024-10-17T16:41:18+00:00
hadrian: enable internal-interpreter for ghc-bin stage0
This commit enables internal-interpreter flag for ghc-bin even when
compiling stage0, as long as target supports ghci. It enables ghci
functionality for cross targets that support ghci, since cross ghc-bin
is really stage0.
- - - - -
c247f2ee by Cheng Shao at 2024-10-17T16:41:18+00:00
hadrian: fix CFLAGS for gmp shared objs on wasm
This commit adds -fvisibility=default to CFLAGS of gmp when building
for wasm. This is required to generate the ghc-bignum shared library
without linking errors. Clang defaults to -fvisibility=hidden for wasm
targets, which will cause issues when a symbol is expected to be
exported in a shared library but without explicit visibility attribute
annotation.
- - - - -
775410fd by Cheng Shao at 2024-10-17T16:41:18+00:00
hadrian: re-enable PIC for gmp on wasm
This commit re-enables --with-pic=yes configuration option of gmp when
building for wasm, given we're about to include support for shared
libraries, TH and ghci.
- - - - -
b45080a3 by Cheng Shao at 2024-10-17T16:41:18+00:00
hadrian: add the host_fully_static flavour transformer
This commit adds the host_fully_static flavour transformer to hadrian,
which ensures stage0 is fully statically linked while still permitting
stage1 libdir to contain shared libraries. This is intended to be used
by the wasm backend to build portable linux bindists that contain wasm
shared libraries.
- - - - -
5043507c by Cheng Shao at 2024-10-17T16:41:18+00:00
ci: update wasm jobs configuration
This commit bumps ci-image revision to use updated wasm toolchain, and
use host_fully_static instead of fully_static for wasm jobs so to
ensure wasm shared libraries can be properly built.
- - - - -
2956a3f7 by Cheng Shao at 2024-10-17T16:41:18+00:00
hadrian/testsuite: implement config.cross logic
This commit implements the config.cross field in the testsuite driver.
It comes from the "cross compiling" ghc info field for both
in-tree/out-of-tree GHC, and is an accurate predicate of whether we're
cross-compiling or not (compared to the precense of target emulator),
and is useful to implement predicates to assert the precense of
internal interpreter (only available on non-cross GHC) for tests that
do require it (e.g. plugins).
- - - - -
8c74a0ed by Cheng Shao at 2024-10-17T16:41:18+00:00
hadrian/compiler: implement targetRTSLinkerOnlySupportsSharedLibs
This patch implements the targetRTSLinkerOnlySupportsSharedLibs
predicate in hadrian. Its definition in hadrian is the single source
of truth, and the information propagates to ghc settings file, ghc
driver and testsuite driver. It is used in various places to ensure
dynamic dependency is selected when the target RTS linker only
supports loading dynamic code.
- - - - -
b4c3c340 by Cheng Shao at 2024-10-17T16:41:18+00:00
testsuite: don't use host cpu features when testing cross ghc
This patch disables CPU feature detection logic when testing cross
GHC, since those features don't make sense for the target anyway.
- - - - -
3c21b696 by Cheng Shao at 2024-10-17T16:41:19+00:00
testsuite: implement & use req_plugins predicate
This commit implements req_plugins predicate to indicate that the test
requires plugin functionality. Currently this means cross GHC is
disabled since internal-interpreter doesn't work in cross GHC yet.
- - - - -
93b8af80 by Cheng Shao at 2024-10-17T16:41:19+00:00
testsuite: make use of config.interp_force_dyn
This commit takes config.interp_force_dyn into consideration when
setting up TH/ghci way flags.
- - - - -
94673d41 by Cheng Shao at 2024-10-17T16:41:19+00:00
testsuite: bump T17572 timeout
- - - - -
2b5efc2d by Cheng Shao at 2024-10-17T16:41:19+00:00
testsuite: bump T22744 pre_cmd timeout
- - - - -
45102e2a by Cheng Shao at 2024-10-17T16:41:19+00:00
testsuite: skip terminfo_so for cross ghc
- - - - -
05e40406 by Cheng Shao at 2024-10-17T16:41:19+00:00
testsuite: fix shared library size tests for cross ghc
This commit fixes shared library size tests (e.g. array_so in
testsuite/tests/perf/size/all.T) when testing cross ghc. Previously,
if shared library file extension of host and target differs, those
tests will fail with framework errors due to not finding the right
files.
- - - - -
fa68f833 by Cheng Shao at 2024-10-17T16:41:19+00:00
testsuite: skip ghc api tests that attempt to spawn processes inside wasm
This commit skips a few ghc api tests on wasm, since they would
attempt to spawn processes inside wasm, which is not supported at all.
- - - - -
1241c04e by Cheng Shao at 2024-10-17T16:41:19+00:00
testsuite: skip T22840 due to broken -dtag-inference-checks on wasm
- - - - -
78c8b900 by Cheng Shao at 2024-10-17T16:41:19+00:00
testsuite: ensure $(ghciWayFlags) can be overridden
This commit revises boilerplate.mk in testsuite as well as a few other
places, to ensure the tests that do make use of $(ghciWayFlags) can
receive the right $(ghciWayFlags) from testsuite driver config.
- - - - -
47989ecc by Cheng Shao at 2024-10-17T16:41:24+00:00
testsuite: skip rdynamic on wasm
- - - - -
fefb4ea1 by Cheng Shao at 2024-10-17T16:41:24+00:00
testsuite: skip T2615 on wasm
This commit marks T2615 as skip on wasm, given LD_* environment
variables aren't supported on wasm anyway.
- - - - -
77c79762 by Cheng Shao at 2024-10-17T16:41:24+00:00
testsuite: mark MultiLayerModulesTH_Make/MultiLayerModulesTH_OneShot as fragile on wasm
- - - - -
69bb4745 by Cheng Shao at 2024-10-17T16:41:24+00:00
testsuite: fix T16180 on wasm
This commit fixes T16180 on wasm once TH support is flipped on. The
fix is simply adding right asm code for wasm.
- - - - -
621c753d by Cheng Shao at 2024-10-17T16:41:24+00:00
driver: fix -fexternal-interpreter flag for JS backend
Previously, -fexternal-interpreter is broken for JS backend, since GHC
would attempt to launch a non-existent ghc-iserv* executable. This
commit fixes it by adjusting pattern matching order in
setTopSessionDynFlags.
- - - - -
80aa8983 by Cheng Shao at 2024-10-17T16:41:24+00:00
driver: use interpreterDynamic predicate in preloadLib
This commit use the interpreterDynamic predicate in preloadLib to
decide if we should do dynLoadObjs instead of loadObj. Previously we
used hostIsDynamic which was only written with non-cross internal
interpreter in mind.
The testsuite is also adjusted to remove hard-wired -fPIC flag for
cbits (doesn't work in i386 RTS linker in vanilla way, #25260) and
properly pass ghc_th_way_flags to ghc.
- - - - -
74411461 by Cheng Shao at 2024-10-17T16:41:24+00:00
compiler: fix Cmm dynamic CLabels for wasm
This commit fixes the handling of dynamic CLabels for the wasm
backend. Just do the simplest handling: preserve the original CLabel,
both unreg/NCG backends can handle them properly without issue.
- - - - -
f6abaf13 by Cheng Shao at 2024-10-17T16:41:24+00:00
driver: add necessary compile-time flags for wasm PIC mode
This commit adds necessary compile-time flags when compiling for wasm
PIC mode, see added comment for detailed explanation.
- - - - -
9745fcfb by Cheng Shao at 2024-10-17T16:41:24+00:00
driver: add necessary link-time flags for wasm shared libs
This commit adds necessary link-time flags for wasm shared libs, see
added comments for detailed explanation.
- - - - -
649aae00 by Cheng Shao at 2024-10-17T16:41:24+00:00
driver: enforce -fno-use-rpaths for wasm
This commit ensures the GHC driver never passes any RPATH-related
link-time flags on wasm, which is not supported at all.
- - - - -
47baa904 by Cheng Shao at 2024-10-17T16:41:24+00:00
driver: ensure static archives are picked when linking static .wasm modules
This commit ensures static archives are picked when linking .wasm
modules which are supposed to be fully static, even when ghc may be
invoked with -dynamic, see added comment for explanation.
- - - - -
fc3a5591 by Cheng Shao at 2024-10-17T16:41:24+00:00
compiler: fix dynamic_too_enable for targets that require dynamic libraries
This commit fixes dynamic_too_enable for targets whose RTS linker can
only load dynamic code.
- - - - -
94ef949e by Cheng Shao at 2024-10-17T16:41:24+00:00
compiler: fix checkNonStdWay for targets that require dynamic libraries
This commit fixes checkNonStdWay to ensure that for targets whose RTS
linker can only load dynamic code, the dynamic way of object is
selected.
- - - - -
88e99248 by Cheng Shao at 2024-10-17T16:41:24+00:00
ghc-bin: enforce dynamic way when the target requires so
This commit makes ghc-bin use dynamic way when it is doing interactive
stuff on certain targets whose RTS linker can only handle dynamic
code.
- - - - -
549582ef by Cheng Shao at 2024-10-17T16:41:24+00:00
hadrian/ghci: add wasm dyld
This commit adds the wasm dynamic linker implementation, as well as
ghci logic to call it and hadrian logic to install it to the correct
location. See the top-level note in utils/jsffi/dyld.mjs for more
details.
- - - - -
b562e3a6 by Cheng Shao at 2024-10-17T16:41:29+00:00
driver: fix getGccSearchDirectory for wasm target
This commit fixes getGccSearchDirectory logic for wasm target, ensures
the correct search directory containing libc.so etc can be found by
GHC. getGccSearchDirectory is also exported so it can be used
elsewhere to obtain the wasi-sdk libdir and pass to the dyld script.
- - - - -
2d6107dc by Cheng Shao at 2024-10-17T16:41:29+00:00
driver: add wasm backend iserv logic
This commit adds wasm backend iserv logic to the driver, see added
comments for explanation.
- - - - -
61f5baa5 by Cheng Shao at 2024-10-17T16:41:29+00:00
compiler: add PIC support to wasm backend NCG
This commit adds support for generating PIC to the wasm backend NCG.
- - - - -
652e7239 by Cheng Shao at 2024-10-17T16:41:29+00:00
hadrian/compiler: flip on support for shared libs & ghci for wasm
This commit flips on the support for shared libs and ghci for the wasm
target, given all required support logic has been added in previous
commits.
- - - - -
74a1f681 by Cheng Shao at 2024-10-17T16:41:29+00:00
testsuite: flip on support for shared libs, TH & ghci for wasm
This commit flips on support for shared libs, TH & ghci for wasm in
the testsuite, given support has been landed in previous commits.
- - - - -
525d451e by Cheng Shao at 2024-10-17T23:03:34-04:00
Revert "compiler: start deprecating cmmToRawCmmHook"
This reverts commit 1c064ef1f3e1aa2afc996e962ad53effa99ec5f4. Turns
out the GHC-WPC project does use it to observe Cmm in the pipeline,
see #25363.
- - - - -
5bcfefd5 by Cheng Shao at 2024-10-17T23:04:09-04:00
rts: fix pointer overflow undefined behavior in bytecode interpreter
This patch fixes an unnoticed undefined behavior in the bytecode
interpreter. It can be caught by building `rts/Interpreter.c` with
`-fsanitize=pointer-overflow`, the warning message is something like:
```
rts/Interpreter.c:1369:13: runtime error: addition of unsigned offset to 0x004200197660 overflowed to 0x004200197658
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior rts/Interpreter.c:1369:13
rts/Interpreter.c:1265:13: runtime error: addition of unsigned offset to 0x004200197660 overflowed to 0x004200197658
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior rts/Interpreter.c:1265:13
rts/Interpreter.c:1645:13: runtime error: addition of unsigned offset to 0x0042000b22f8 overflowed to 0x0042000b22f0
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior rts/Interpreter.c:1645:13
```
Whenever we do something like `SpW(-1)`, the negative argument is
implicitly converted to an unsigned integer type and causes pointer
arithmetic overflow. It happens to be harmless for most targets since
overflowing would wrap the result to desired value, but it's still
coincidental and undefined behavior. Furthermore, it causes real
damage to the wasm backend, given clang-20 will emit invalid wasm code
that crashes at run-time for this kind of C code! (see
https://github.com/llvm/llvm-project/issues/108770)
The fix here is adding some explicit casts to ensure we always use the
signed `ptrdiff_t` type as right hand operand of pointer arithmetic.
- - - - -
9c28ea87 by Andreas Klebinger at 2024-10-18T15:03:11+02:00
mkTick: Push ticks through unsafeCoerce#.
unsafeCoerce# doesn't exist at runtime so we should treat it like a Cast
for the purpose of mkTick.
This means if we have `{-# SCC foo #-} (unsafeCoerce# trivial_expr))` we
now push the scope part of the cost centre up to `trivial_expr` at which
point we can discard it completely if the expression is trivial enough.
This fixes #25212.
- - - - -
30 changed files:
- .gitlab-ci.yml
- .gitlab/generate-ci/gen_ci.hs
- .gitlab/jobs.yaml
- CODEOWNERS
- compiler/GHC.hs
- compiler/GHC/CmmToAsm/PIC.hs
- compiler/GHC/CmmToAsm/Wasm.hs
- compiler/GHC/CmmToAsm/Wasm/Asm.hs
- compiler/GHC/CmmToAsm/Wasm/Types.hs
- compiler/GHC/Core/Utils.hs
- compiler/GHC/Driver/Config/CmmToAsm.hs
- compiler/GHC/Driver/Hooks.hs
- compiler/GHC/Driver/Main.hs
- compiler/GHC/Driver/Make.hs
- compiler/GHC/Driver/Session.hs
- compiler/GHC/Linker/Deps.hs
- compiler/GHC/Linker/Dynamic.hs
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/Linker/Static.hs
- compiler/GHC/Platform.hs
- compiler/GHC/Runtime/Interpreter.hs
- compiler/GHC/Runtime/Interpreter/Types.hs
- + compiler/GHC/Runtime/Interpreter/Wasm.hs
- compiler/GHC/Settings.hs
- compiler/GHC/Settings/IO.hs
- compiler/GHC/Types/Tickish.hs
- compiler/ghc.cabal.in
- ghc/Main.hs
- hadrian/bindist/Makefile
- hadrian/bindist/config.mk.in
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/1328fe354923e2cbf84a5cd34bf1e47215f25141...9c28ea87b6ecaa54d895abd91dabcfaa38d25223
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/1328fe354923e2cbf84a5cd34bf1e47215f25141...9c28ea87b6ecaa54d895abd91dabcfaa38d25223
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/20241018/c3e39695/attachment-0001.html>
More information about the ghc-commits
mailing list