oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.18k stars 2.77k forks source link

`illegal hardware instruction` on M1 max cpu #7717

Open ice-chillios opened 10 months ago

ice-chillios commented 10 months ago

What version of Bun is running?

1.0.18 (retested with 1.0.29 with no success)

What platform is your computer?

Darwin 23.2.0 arm64 arm

What steps can reproduce the bug?

  1. Clone repo https://github.com/chillios-dev/bun-build-swapkit-issue
  2. Run bun install.
  3. Run bun build on one of the cases in code -> it crashes.
  4. (optional) -> run bun run index.ts in case with "Cosmos" chain -> it also crashes in this case

What is the expected behavior?

Pass and bundle code properly

What do you see instead?

Crash with illegal hardware instruction error

Additional information

Hi πŸ‘‹ I'm co-creator of some crypto oss project and as we wanted to switch to bun in some use-cases like build and release pipeline we've met a few issues with building and sometimes running code via bun.

Here's repo with reproduction and additional comments but I'm happy debug it further more if only I could get any help in case of deeper debugging as I couldn't find anything useful with --inspect on my own - it just crashes whenever reaches some part of code.

Additional stuff what I found that might be useful is:

P.S. Current setup of @swapkit packages is bundled, build by vite and split into cjs & esm. I've tried switch to bun but got the same crash on some packages so I assume that there is some issue there but I can't figure it out or how to dig further beyond Bun built-in debug tools.

yovanoc commented 10 months ago

same but only with --minify

sroussey commented 8 months ago

I ran on debug version:

❯ ../bun/build/bun-debug build node_modules/@swapkit/toolbox-cosmos/dist/index-qNhBHUBJ.js
[SYS] read(3[/Users/steve/Code/bun/build/bun-debug], 4096) = 4096 (0.067ms)
[fs] close(3[/Users/steve/Code/bun/build/bun-debug])
[SYS] openat(-2, /Users/steve/Code/bun-build-swapkit-issue/bunfig.toml) = -1
[SYS] openat(7[/Users/steve/Code/bun-build-swapkit-issue], package.json) = 8
[fs] openat(7[/Users/steve/Code/bun-build-swapkit-issue], /Users/steve/Code/bun-build-swapkit-issue/package.json) = 8
[fs] close(8[/Users/steve/Code/bun-build-swapkit-issue/package.json])
[SYS] openat(7[/Users/steve/Code/bun-build-swapkit-issue], tsconfig.json) = 8
[fs] openat(7[/Users/steve/Code/bun-build-swapkit-issue], /Users/steve/Code/bun-build-swapkit-issue/tsconfig.json) = 8
[fs] close(8[/Users/steve/Code/bun-build-swapkit-issue/tsconfig.json])
[fs] close(3[/])
[fs] close(4[/Users])
[fs] close(5[/Users/steve])
[fs] close(6[/Users/steve/Code])
[fs] close(7[/Users/steve/Code/bun-build-swapkit-issue])
[ThreadPool] 12 workers
[fs] close(4[/Users/steve/Code/bun-build-swapkit-issue/node_modules])
[SYS] openat(-2, /Users/steve/Code/bun-build-swapkit-issue/node_modules/node_modules/@swapkit/toolbox-cosmos/dist/) = -1
[SYS] openat(5[/Users/steve/Code/bun-build-swapkit-issue/node_modules/@swapkit/toolbox-cosmos], package.json) = 6
[fs] openat(5[/Users/steve/Code/bun-build-swapkit-issue/node_modules/@swapkit/toolbox-cosmos], /Users/steve/Code/bun-build-swapkit-issue/node_modules/@swapkit/toolbox-cosmos/package.json) = 6
[fs] close(6[/Users/steve/Code/bun-build-swapkit-issue/node_modules/@swapkit/toolbox-cosmos/package.json])
[fs] close(4[/Users/steve/Code/bun-build-swapkit-issue/node_modules/@swapkit])
[fs] close(5[/Users/steve/Code/bun-build-swapkit-issue/node_modules/@swapkit/toolbox-cosmos])
[fs] close(6[/Users/steve/Code/bun-build-swapkit-issue/node_modules/@swapkit/toolbox-cosmos/dist])
[ThreadPool] Worker.create()
[SYS] openat(-2, /Users/steve/Code/bun-build-swapkit-issue/node_modules/@swapkit/toolbox-cosmos/dist/index-qNhBHUBJ.js) = 4
[fs] openat(0, /Users/steve/Code/bun-build-swapkit-issue/node_modules/@swapkit/toolbox-cosmos/dist/index-qNhBHUBJ.js) = 4
[ThreadPool] Worker.create()
[fs] close(4[/Users/steve/Code/bun-build-swapkit-issue/node_modules/@swapkit/toolbox-cosmos/dist/index-qNhBHUBJ.js])
[Bundle] onParse(0, runtime) = 0 imports, 22 exports
[1]    30061 illegal hardware instruction  ../bun/build/bun-debug build 
image

Looks like problem in parsing the ASMJS version of libsodium.

File node_modules/@swapkit/toolbox-cosmos/dist/index-qNhBHUBJ.js and line #20000

The subexpressions are well over 100 deep, making the stack at least 4x that.

dylan-conway commented 8 months ago

Yeah, looks like stack overflow due to recursion. We will need to experiment with decreasing the amount of recursion/memory needed for parseExpr/Suffix/Prefix or experiment with increasing stack size for parser threads