-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is call_ext_last opcode argument properly computed? #7152
Comments
No, but we don't care as an exception is thrown right away which makes the argument redundant. This lets us reduce code size by allowing jumps to exit BIFs regardless of how the stack looks, although I suppose the optimization has become less effective since line numbers were added. Perhaps we should revisit it. We only do this for |
@jhogberg I realize the This is referred to in this comment: otp/lib/compiler/src/beam_validator.erl Lines 1339 to 1342 in 98e3bf2
If I change the erlang:throw/1 call by altering the module or the function name, the validator rejects the asm. So I understand the proper asm here should be: - {call_ext_last,1,{extfunc,erlang,throw,1},3}.
+ {call_ext_last,1,{extfunc,erlang,throw,1},2}. Do you mean that for some optimization reason (?) |
For the record:
Strictly speaking I am not sure we have to call this a bug as opcodes are not documented, but it will certainly require some workaround in AtomVM which doesn't rewrite |
BEAM's compiler and especially beam_trim optimization pass can generate an incorrect deallocation `n_words` parameter for `call_ext_last/3`. As a workaround, deallocate after the nif call, and before any error handling that may need the stack to find catch handlers. See: erlang/otp#7152 Add test that currently crashes on master without this change Signed-off-by: Paul Guyot <pguyot@kallisys.net>
I just checked (
Sort of: we consider it valid in this specific case. :-) I agree that it's ugly that the pass doesn't fix the stack size argument, but in some cases it can't and it won't be used either way, so we've just let it be. |
…_base Add workaround for crash related to `call_ext_last/3` BEAM's compiler and especially beam_trim optimization pass can generate an incorrect deallocation `n_words` parameter for `call_ext_last/3`. As a workaround, deallocate after the nif call, and before any error handling that may need the stack to find catch handlers. See: erlang/otp#7152 Add test that currently crashes on master without this change These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
Describe the bug
With OTP23 and OTP25 compilers, I do not understand the n_remaining value of call_ext_last opcode with the following code:
Function start/0 is compiled as follows (OTP25):
There are two execution paths with different stack allocations.
If condition goes to the throw clause (label,3), the path is:
If it doesn't, the path is:
Should
call_ext_last
really have 3 (and not 2) as its last argument?The text was updated successfully, but these errors were encountered: