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

Apple Silicon 11.x web assembly fails to load #27497

Closed
3 tasks done
wizebin opened this issue Jan 26, 2021 · 18 comments
Closed
3 tasks done

Apple Silicon 11.x web assembly fails to load #27497

wizebin opened this issue Jan 26, 2021 · 18 comments
Assignees
Labels
11-x-y Apple Silicon 🍎 bug 🪲 has-repro-gist Issue can be reproduced with code at https://gist.github.com/ platform/macOS

Comments

@wizebin
Copy link

wizebin commented Jan 26, 2021

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    • 11.2.1
  • Operating System:
    • macOS 11.1 - M1, Apple Silicon, ARM64

Expected Behavior

Web Assembly should work or at the very least throw a relevant error message

Actual Behavior

Creating a new WebAssembly.Module instance causes a complete loading failure of electron and does not provide any sort of relevant error message.

To Reproduce

Electron Fiddle with gist https://gist.github.com/34ba76d876169d5a101362f47451fba3

const wasmObjectCode = Buffer.from('0061736d01000000018580808000016000017f0382808080000100048480808000017000000583808080000100010681808080000007988080800002066d656d6f727902000b5f5a37676574466976657600000a8a808080000184808080000041050b', 'hex');

const wasmModule = new WebAssembly.Module(wasmObjectCode);

Additional Information

This only fails on 11.x on the m1 chip.

  • m1 chip electron 12.x: success
  • m1 chip electron 11.x: failure
  • x86 chip electron 12.x: success
  • x86 chip electron 11.x: success

This is likely a node issue according to dcodeIO/long.js#95

@ckerr ckerr added 11-x-y bug 🪲 has-repro-gist Issue can be reproduced with code at https://gist.github.com/ platform/macOS Apple Silicon 🍎 labels Jan 26, 2021
@jupp0r
Copy link

jupp0r commented Feb 1, 2021

I can confirm this, it’s currently preventing my team from releasing a darwin-arm64 build of an electron app to customers.

@alectrocute
Copy link

alectrocute commented Feb 3, 2021

+1. This is currently an issue as described above on the Apple DTK, FWIW.

@deepak1556
Copy link
Member

There were two issues with loading wasm in Electron on mac arm64

  1. OOM crash - this was fixed by build: remove no longer needed arm64 macos patches #26650 , as long as your renderer helper is codesigned with com.apple.security.cs.allow-jit it should load the module fine. This is available from v11.0.3

  2. with macOS > 11.2 , crash when loading wasm in node process spawned from the app - this is due to https://bugs.chromium.org/p/v8/issues/detail?id=11389 and is fixed by chore: cherry-pick 0c8b6e41 from v8 #27684

So depending on your use case, you might have to pick the version.

@Serena-zlh
Copy link

@deepak1556 I have tried v11.3.0, but still crash, this issue is not exists in the Electron 12 betas.

@jupp0r
Copy link

jupp0r commented Feb 23, 2021

I can confirm that this is not fixed in v11.3.0 but is fixed in v12.0.0-beta.26.

@ghost
Copy link

ghost commented Feb 23, 2021 via email

@deepak1556
Copy link
Member

@Serena-zlh @jupp0r can you provide the crash report generated with v11.3.0, you can add the following to the main process

const { crashReporter, app } = require('electron')
crashReporter.start({
  submitURL: "https://example.com",
  uploadToServer: false,
})
console.log(`Crash dumps directory: ${app.getPath('crashDumps')}`)

@Serena-zlh
Copy link

@deepak1556

Identifier: Electron Helper (Renderer)
Version: 0
Code Type: ARM-64 (Native)
Parent Process: Electron [97502]
Responsible: Terminal [748]
User ID: 501

Date/Time: 2021-02-24 17:27:23.876 +0800
OS Version: macOS 11.2 (20D64)
Report Version: 12
Anonymous UUID: C5DBA3ED-E095-1B33-B550-4E70AF196FA0

Sleep/Wake UUID: FF05B57F-78D9-48EB-969D-0B1429F53138

Time Awake Since Boot: 140000 seconds
Time Since Wake: 960 seconds

System Integrity Protection: enabled

Crashed Thread: 0 CrRendererMain Dispatch queue: com.apple.main-thread

Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY

Application Specific Information:
abort() called

Thread 0 Crashed:: CrRendererMain Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00000001821b4cec __pthread_kill + 8
1 libsystem_pthread.dylib 0x00000001821e5c24 pthread_kill + 292
2 libsystem_c.dylib 0x000000018212d864 abort + 104
3 com.github.Electron.framework 0x0000000106a0bed8 v8::internal::compiler::ZoneStats::GetCurrentAllocatedBytes() const + 10508608
4 com.github.Electron.framework 0x000000010772c59c v8::internal::compiler::ZoneStats::GetCurrentAllocatedBytes() const + 24272900
5 com.github.Electron.framework 0x000000010772c07c v8::internal::compiler::ZoneStats::GetCurrentAllocatedBytes() const + 24271588
6 com.github.Electron.framework 0x0000000105bfc7b0 v8::internal::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*) + 700
7 com.github.Electron.framework 0x0000000105bfc770 v8::internal::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*) + 636
8 com.github.Electron.framework 0x0000000105e82e80 v8::internal::wasm::WasmCodeManager::Commit(v8::base::AddressRegion) + 180
9 com.github.Electron.framework 0x00000001034a7fcc v8::internal::wasm::NativeModule::AddCodeSpace(v8::base::AddressRegion, v8::internal::wasm::WasmCodeAllocator::OptionalLock const&) + 1356
10 com.github.Electron.framework 0x00000001034a8864 v8::internal::wasm::NativeModule::CreateEmptyJumpTableInRegion(int, v8::base::AddressRegion, v8::internal::wasm::WasmCodeAllocator::OptionalLock const&) + 64
11 com.github.Electron.framework 0x00000001034a7b78 v8::internal::wasm::NativeModule::AddCodeSpace(v8::base::AddressRegion, v8::internal::wasm::WasmCodeAllocator::OptionalLock const&) + 248
12 com.github.Electron.framework 0x00000001034a86fc v8::internal::wasm::NativeModule::NativeModule(v8::internal::wasm::WasmEngine*, v8::internal::wasm::WasmFeatures const&, v8::internal::VirtualMemory, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>, std::__1::shared_ptrv8::internal::Counters, std::__1::shared_ptrv8::internal::wasm::NativeModule) + 544
13 com.github.Electron.framework 0x0000000105e83e8c v8::internal::wasm::WasmCodeManager::NewNativeModule(v8::internal::wasm::WasmEngine
, v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, unsigned long, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) + 400
14 com.github.Electron.framework 0x0000000105e909e4 v8::internal::wasm::WasmEngine::NewNativeModule(v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, std::_1::shared_ptr<v8::internal::wasm::WasmModule const>, unsigned long) + 76
15 com.github.Electron.framework 0x0000000105e67814 v8::internal::wasm::CompilationState::recompilation_finished() const + 2624
16 com.github.Electron.framework 0x00000001034ac1cc v8::internal::wasm::WasmEngine::SyncCompile(v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, v8::internal::wasm::ErrorThrower*, v8::internal::wasm::ModuleWireBytes const&) + 440
17 com.github.Electron.framework 0x00000001034b11fc v8::internal::WasmJs::Install(v8::internal::Isolate*, bool) + 5584
18 com.github.Electron.framework 0x00000001031ab908 v8::internal::Accessors::MakeAccessor(v8::internal::Isolate*, v8::internal::Handlev8::internal::Name, void ()(v8::Localv8::Name, v8::PropertyCallbackInfov8::Value const&), void ()(v8::Localv8::Name, v8::Localv8::Value, v8::PropertyCallbackInfov8::Boolean const&)) + 13228
19 com.github.Electron.framework 0x00000001031ab318 v8::internal::Accessors::MakeAccessor(v8::internal::Isolate*, v8::internal::Handlev8::internal::Name, void ()(v8::Localv8::Name, v8::PropertyCallbackInfov8::Value const&), void ()(v8::Localv8::Name, v8::Localv8::Value, v8::PropertyCallbackInfov8::Boolean const&)) + 11708
20 com.github.Electron.framework 0x00000001031aaeec v8::internal::Accessors::MakeAccessor(v8::internal::Isolate*, v8::internal::Handlev8::internal::Name, void ()(v8::Localv8::Name, v8::PropertyCallbackInfov8::Value const&), void ()(v8::Localv8::Name, v8::Localv8::Value, v8::PropertyCallbackInfov8::Boolean const&)) + 10640
21 com.github.Electron.framework 0x0000000103774e2c v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 497004
22 com.github.Electron.framework 0x0000000103701a08 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 24904
23 com.github.Electron.framework 0x00000001038072f0 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 1096240
24 com.github.Electron.framework 0x0000000103704fb4 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 38644
25 com.github.Electron.framework 0x000000010370272c v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 28268
26 com.github.Electron.framework 0x00000001037023c8 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 27400
27 ??? 0x0000000109fd48e0 v8::internal::SoleReadOnlyHeap::shared_ro_heap
+ 152

@deepak1556
Copy link
Member

Thanks that would be https://bugs.chromium.org/p/chromium/issues/detail?id=1150060 , is the renderer helper codesigned with com.apple.security.cs.allow-jit entitlement ?

@KishanBagaria
Copy link
Contributor

@deepak1556 I ran codesign --deep --force --verbose --sign - node_modules/electron/dist/Electron.app but it still crashes

@deepak1556
Copy link
Member

deepak1556 commented Feb 24, 2021

You need to sign the renderer with the above mentioned entitlement otherwise MAP_JIT allocations will fail, please use https://github.com/electron/electron-osx-sign to properly handle signing the helper executables.

@Serena-zlh
Copy link

Serena-zlh commented Feb 25, 2021

@deepak1556 App crashed during local development, just run electron . , you mean the app has to be signed even though
local development?

@deepak1556
Copy link
Member

deepak1556 commented Feb 25, 2021

Yes on the M1 device you need to sign the helper even in development for electron 11.x to avoid the crash.

This is a workaround for when mprotect fails on a JIT region that needs rwx permission. Will investigate on the fix from upstream that made it into 12-beta. Most likely the refactor in page discard https://chromium-review.googlesource.com/c/chromium/src/+/2563052.

@deepak1556 deepak1556 self-assigned this Feb 25, 2021
@KishanBagaria
Copy link
Contributor

KishanBagaria commented Feb 25, 2021

A colleague tried both codesign --deep --force --verbose --sign - node_modules/electron/dist/Electron.app and electron-osx-sign node_modules/electron/dist/Electron.app with no change as I understand – crashes on both.

@deepak1556
Copy link
Member

@KishanBagaria what is the output of codesign -d --entitlements :- <path-to>/Electron.app/Contents/Frameworks/Electron Helper (Renderer).app ?

@KishanBagaria
Copy link
Contributor

@deepak1556 On my x64 Mac:

$ codesign -d --entitlements :- "node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Helper (Renderer).app"
Executable=$PROJECT_DIR/node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Helper (Renderer).app/Contents/MacOS/Electron Helper (Renderer)

Will get back with the arm64 Mac output.

@KishanBagaria
Copy link
Contributor

Seems to work fine on arm64 Mac after running codesign -d --entitlements :- "node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Helper (Renderer).app"

@clavin
Copy link
Member

clavin commented Apr 26, 2022

This issue seems to have been fixed at some point. Was not able to reproduce this crash on macOS 12.3.1 (M1 Max, so arm64), with Electron 19.0.0-alpha.1 (likely was fixed before this, I just happened to have this version selected in fiddle). Further, the code worked as expected.

Updated test gist: https://gist.github.com/clavin/92bd14a3078274ac731048402fd580ac

I'll close this now since it seems to have resolved itself. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
11-x-y Apple Silicon 🍎 bug 🪲 has-repro-gist Issue can be reproduced with code at https://gist.github.com/ platform/macOS
Projects
None yet
Development

No branches or pull requests

8 participants