Skip to content
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

[bug] Abort option isn't working #676

Closed
DieMyst opened this issue Jun 19, 2019 · 11 comments
Closed

[bug] Abort option isn't working #676

DieMyst opened this issue Jun 19, 2019 · 11 comments

Comments

@DieMyst
Copy link

DieMyst commented Jun 19, 2019

For example, there https://webassembly.studio/?f=ayvoyj2s81 if we run build, this warning will occur:
WARN: Unknown option '--use abort='''
and this error on run:
[error]: LinkError: WebAssembly Instantiation: Import #0 module="env" function="abort" error: function import requires a callable

@dcodeIO
Copy link
Member

dcodeIO commented Jun 19, 2019

The correct syntax there is

  asc.main([
    ...
    "--use", "abort=",
  ], callback);

but this will then lead to an assertion error of ERROR: missing abort because the compiler expects that at least some abort routine is present that it can use.

Adding a custom abort to main.ts and using that instead of the built-in abort should work, though:

function myAbort(
  message: string | null,
  fileName: string | null,
  lineNumber: u32,
  columnNumber: u32
): void {}
  asc.main([
    ...
    "--use", "abort=main/myAbort",
  ], callback);

In this case, whenever an abort happens, the custom function will be called right before a trap occurs. If that function does nothing, optimizing the module should remove it as dead code.

@MaxGraey
Copy link
Member

@dcodeIO I tried "--use", "abort=" but this caused to WARN: Unknown option '--use abort=' and doesn't have effect.

https://webassembly.studio/?f=u15n0gyad7

@dcodeIO
Copy link
Member

dcodeIO commented Jun 19, 2019

When I run "Build" there, I get ERROR: missing abort. The error you mention would match "--use abort=" as a single argument, not two.

@dcodeIO
Copy link
Member

dcodeIO commented Jun 19, 2019

Might well be that this worked differently in earlier versions of the compiler, and allowing the user to disable the abort routine entirely instead of having to provide an alternative seems like something worth to support.

@MaxGraey
Copy link
Member

It seems this should be:

for (let [name, alias] of globalAliases) {

instead:

for (let [alias, name] of globalAliases) {

@dcodeIO
Copy link
Member

dcodeIO commented Jun 19, 2019

Consider --use Math=NativeMath. There, Math is the alias and NativeMath the internal name to be aliased. Should be correct this way.

@MaxGraey
Copy link
Member

Hmm, but here using globalAliases[name] = alias:

globalAliases.set(name, alias);

@dcodeIO
Copy link
Member

dcodeIO commented Jun 19, 2019

Yeah, the naming is off there, but the order is not changed. name and alias should be switched there I think.

@dcodeIO
Copy link
Member

dcodeIO commented Jun 19, 2019

PR linked above should fix all of this :)

@MaxGraey
Copy link
Member

MaxGraey commented Jun 19, 2019

Great! Also will be great mention how use abort properly in docs I guess :)

@dcodeIO
Copy link
Member

dcodeIO commented Jun 19, 2019

Added here: https://docs.assemblyscript.org/details/debugging#overriding-abort

@dcodeIO dcodeIO closed this as completed Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants