Skip to content

Update cranelift#122

Open
ghuls wants to merge 4 commits intoezrosent:masterfrom
ghuls:update_cranelift
Open

Update cranelift#122
ghuls wants to merge 4 commits intoezrosent:masterfrom
ghuls:update_cranelift

Conversation

@ghuls
Copy link
Contributor

@ghuls ghuls commented Sep 11, 2025

Update Cranelift to 0.123.2:

Never inlining pub(crate) unsafe extern "C" functions from "codegen::intrinsics"
as this can give different addresses for the same function when the address is
requested in "codegen::intrinsics" or "codegen::clif".

Expecially mathematical _frawk_* functions can have this issue.

For example the address of _frawk_sin function when calling register_all
and external!(_frawk_sin) in codegen::clif" was different when the function
get inlined, and call_inst would fail with the address given by
external!(_frawk_sin) in codegen::clif".

Replace mem:transmute in wrap_args with safer options

Without it:

$ frawk -Bcranelift 'BEGIN { printf("%d\t%f\t%s\n", integer, float, string); }'

would crash with:

failure in runtime invalid type code passed to printf_impl_file: 2. Halting execution

or with invalid opcode after cranelift update.

Fixes: #121

@ghuls
Copy link
Contributor Author

ghuls commented Sep 11, 2025

Preferably #120 gets merged first as ad64963 is likely needed to satisfy recent rustc versions.

Copy link
Owner

@ezrosent ezrosent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change (and the others!)

Left some minor comments then I think they're good to merge.

ghuls added 4 commits October 14, 2025 11:07
Update Cranelift to 0.123.2:
  - `is_pic` option needs to be false for jit from Cranelift 0.122.0:
        bytecodealliance/wasmtime#2735
  - `declare_var(type)` will now return a new variable entity and
    the variable does not need to be created first anymore:
        bytecodealliance/wasmtime@8236a07
…odegen::intrinsics"

Never inline `pub(crate) unsafe extern "C"` functions from "codegen::intrinsics"
as this can give different addresses for the same function when the address is
requested in "codegen::intrinsics" or in "codegen::clif".

Especially mathematical `_frawk_*` functions can have this issue as they are
very small.

For example the address of `_frawk_sin` function when calling `register_all`
and `external!(_frawk_sin)` in codegen::clif" was different when the function
gets inlined, and `call_inst` would fail with the address given by
`external!(_frawk_sin)` in codegen::clif".
Replace `mem:transmute` in `wrap_args` with safer options as without it:

    $ frawk -Bcranelift 'BEGIN { printf("%d\t%f\t%s\n", integer, float, string); }'

would crash with:

    failure in runtime invalid type code passed to printf_impl_file: 2. Halting execution

or with `invalid opcode` after cranelift update.

Fixes: ezrosent#121
@ghuls ghuls requested a review from ezrosent October 14, 2025 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

String format specifier do not work with cranelift backend.

2 participants