[Git][ghc/ghc][wip/marge_bot_batch_merge_job] 50 commits: ghci: mitigate host/target word size mismatch in BCOByteArray serialization

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Thu Oct 17 12:21:30 UTC 2024



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


Commits:
b0e7b7e3 by Cheng Shao at 2024-10-17T08:21:17-04: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.

- - - - -
a1135946 by Cheng Shao at 2024-10-17T08:21:17-04: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.

- - - - -
ac65afdc by Cheng Shao at 2024-10-17T08:21:17-04: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.

- - - - -
a4db0679 by Cheng Shao at 2024-10-17T08:21:17-04: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.

- - - - -
f0eb6f67 by Cheng Shao at 2024-10-17T08:21:17-04: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.

- - - - -
0baf127e by Cheng Shao at 2024-10-17T08:21:17-04:00
rts: correct stale link in comment

- - - - -
cd7a5c43 by Cheng Shao at 2024-10-17T08:21:17-04: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.

- - - - -
e33fdf29 by Cheng Shao at 2024-10-17T08:21:17-04: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.

- - - - -
bbcb1520 by Cheng Shao at 2024-10-17T08:21:17-04: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.

- - - - -
b4ab64ed by Cheng Shao at 2024-10-17T08:21:17-04: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.

- - - - -
9e3f8f3d by Cheng Shao at 2024-10-17T08:21:17-04: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.

- - - - -
b865b6ae by Cheng Shao at 2024-10-17T08:21:17-04: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.

- - - - -
4c52be8d by Cheng Shao at 2024-10-17T08:21:17-04: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.

- - - - -
e3375654 by Cheng Shao at 2024-10-17T08:21:17-04: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.

- - - - -
4d3fcac0 by Cheng Shao at 2024-10-17T08:21:17-04: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.

- - - - -
07089b17 by Cheng Shao at 2024-10-17T08:21:17-04: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.

- - - - -
428f020b by Cheng Shao at 2024-10-17T08:21:17-04: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).

- - - - -
ed08b7d3 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
7d342a15 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
ee227950 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
0c8931fb by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
756bc177 by Cheng Shao at 2024-10-17T08:21:18-04:00
testsuite: bump T17572 timeout

- - - - -
65b8a5c7 by Cheng Shao at 2024-10-17T08:21:18-04:00
testsuite: bump T22744 pre_cmd timeout

- - - - -
3262a5b7 by Cheng Shao at 2024-10-17T08:21:18-04:00
testsuite: skip terminfo_so for cross ghc

- - - - -
8a7812a9 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
bd89f26d by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
11d01de6 by Cheng Shao at 2024-10-17T08:21:18-04:00
testsuite: skip T22840 due to broken -dtag-inference-checks on wasm

- - - - -
5de14d79 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
57a9635a by Cheng Shao at 2024-10-17T08:21:18-04:00
testsuite: skip rdynamic on wasm

- - - - -
4494e5cc by Cheng Shao at 2024-10-17T08:21:18-04:00
testsuite: skip T2615 on wasm

This commit marks T2615 as skip on wasm, given LD_* environment
variables aren't supported on wasm anyway.

- - - - -
8fee655d by Cheng Shao at 2024-10-17T08:21:18-04:00
testsuite: mark MultiLayerModulesTH_Make/MultiLayerModulesTH_OneShot as fragile on wasm

- - - - -
49d41da3 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
16cef0d3 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
ca549bfa by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
bc52a146 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
738e75f7 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
d523a32b by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
c0d23718 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
15f4af71 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
0b531fe3 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
63763f57 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
3462ca24 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
0169289a by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
c4d89f70 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
de186605 by Cheng Shao at 2024-10-17T08:21:18-04:00
driver: add wasm backend iserv logic

This commit adds wasm backend iserv logic to the driver, see added
comments for explanation.

- - - - -
0b480f9f by Cheng Shao at 2024-10-17T08:21:18-04:00
compiler: add PIC support to wasm backend NCG

This commit adds support for generating PIC to the wasm backend NCG.

- - - - -
d5dd5685 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
c5415ee1 by Cheng Shao at 2024-10-17T08:21:18-04: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.

- - - - -
9271ffac by Cheng Shao at 2024-10-17T08:21:22-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.

- - - - -
d7d1da7d by Cheng Shao at 2024-10-17T08:21:22-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.

- - - - -


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/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.cabal.in
- ghc/Main.hs
- hadrian/bindist/Makefile
- hadrian/bindist/config.mk.in
- hadrian/doc/flavours.md
- hadrian/src/Base.hs


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/72e8f628cecf5502541b3ef9f6d30f71f74f4a6f...d7d1da7d919d7f52867977edb8a721a306fb1cec

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/72e8f628cecf5502541b3ef9f6d30f71f74f4a6f...d7d1da7d919d7f52867977edb8a721a306fb1cec
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/20241017/627f681a/attachment-0001.html>


More information about the ghc-commits mailing list