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

写 Pure 过程中的问题记录 #45

Open
xiaoxiaojx opened this issue Oct 16, 2022 · 0 comments
Open

写 Pure 过程中的问题记录 #45

xiaoxiaojx opened this issue Oct 16, 2022 · 0 comments
Labels
C++ C++

Comments

@xiaoxiaojx
Copy link
Owner

Pure

Pure 是我写的一个轻量级的 JavaScript runtime, 写的动机是最近先后出现了 Next.js Edge Runtimecloudflare workerdNoslate JavaScript worker 等 3 个相似的产品, 所以我想通过写 Pure 与写完后它的性能表现来感受为何大家都会投入进来 🤔

由于本人 C++ 段位仅为初级 👷, 所以记录一下写 Pure 遇见的一些坑与解决的办法

常见问题

v8 编译问题见: MacBook M1 编译 v8 问题记录

Embedder-vs-V8 build configuration mismatch.

# Fatal error in , line 0
# Embedder-vs-V8 build configuration mismatch. On embedder side pointer compression is DISABLED while on V8 side it's ENABLED.
#
#
#
#FailureMessage Object: 0x16fc2a918

问题解决: 编译参数加上 -DV8_COMPRESS_POINTERS -DV8_ENABLE_SANDBOX

g++ src/pure.cc -g -I deps/v8/include/ -o pure -L lib/ -lv8_monolith -pthread -std=c++17 -DV8_COMPRESS_POINTERS -DV8_ENABLE_SANDBOX

FailureMessage Object: 0x16fdfed98Process 97650 stopped

#
# Fatal error in , line 0
# Check failed: GetProcessWidePtrComprCage()->IsReserved().
#
#
#
#FailureMessage Object: 0x16fc4aea8/bin/sh: line 1: 95665 Abort trap: 6           ./pure

问题解决:

  1. 运行如下命令使用lldb 开始调试
lldb -- ./pure

将会打印如下日志

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00000001877799b8 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`__pthread_kill:
->  0x1877799b8 <+8>:  b.lo   0x1877799d8               ; <+40>
    0x1877799bc <+12>: pacibsp 
    0x1877799c0 <+16>: stp    x29, x30, [sp, #-0x10]!
    0x1877799c4 <+20>: mov    x29, sp
Target 0: (pure) stopped.
  1. 运行如下命令显示当前线程的堆栈回溯
thread backtrace

将会打印如下日志, 即可找到源码开始报错的地方进行修复

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x00000001877799b8 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x00000001877aceb0 libsystem_pthread.dylib`pthread_kill + 288
    frame #2: 0x00000001876ea314 libsystem_c.dylib`abort + 164
    frame #3: 0x00000001000250b0 pure`v8::base::OS::Abort() at platform-posix.cc:677:3 [opt]
    frame #4: 0x000000010001aa30 pure`V8_Fatal(format=<unavailable>) at logging.cc:167:3 [opt]
    frame #5: 0x000000010037fce4 pure`v8::internal::IsolateAllocator::IsolateAllocator(this=0x0000000102704250) at isolate-allocator.cc:0 [opt]
    frame #6: 0x00000001001f92c4 pure`v8::internal::Isolate::New() [inlined] std::__1::__unique_if<v8::internal::IsolateAllocator>::__unique_single std::__1::make_unique<v8::internal::IsolateAllocator>() at unique_ptr.h:728:32 [opt]
    frame #7: 0x00000001001f92b8 pure`v8::internal::Isolate::New() [inlined] v8::internal::Isolate::Allocate(is_shared=false) at isolate.cc:3353:7 [opt]
    frame #8: 0x00000001001f92b8 pure`v8::internal::Isolate::New() at isolate.cc:3335:22 [opt]
    frame #9: 0x000000010000b380 pure`pure::PureMainInstance::PureMainInstance(this=0x000000016fdff128, event_loop=0x0000000101236858, args=size=0, exec_args=size=0) at pure_main_instance.cc:90:16
    frame #10: 0x000000010000b574 pure`pure::PureMainInstance::PureMainInstance(this=0x000000016fdff128, event_loop=0x0000000101236858, args=size=0, exec_args=size=0) at pure_main_instance.cc:88:3
    frame #11: 0x00000001000080e0 pure`pure::Start(argc=1, argv=0x000000016fdff398) at pure.cc:80:26
    frame #12: 0x000000010000b164 pure`main(argc=1, argv=0x000000016fdff398) at pure_main.cc:10:12
    frame #13: 0x00000001023050f4 dyld`start + 520

Undefined symbols for architecture arm64

Undefined symbols for architecture arm64:
  "pure::Environment::GetCurrent(v8::Isolate*)", referenced from:
      pure::errors::PerIsolateMessageListener(v8::Local<v8::Message>, v8::Local<v8::Value>) in pure_errors-ecfe77.o
  "pure::Environment::context() const", referenced from:
      pure::errors::PerIsolateMessageListener(v8::Local<v8::Message>, v8::Local<v8::Value>) in pure_errors-ecfe77.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

问题解决: 通常是头文件中定义了类型, 却没有具体实现。找到未实现的定义, 在 .cc 或者 .inl.h 中实现即可。

@xiaoxiaojx xiaoxiaojx added v8 V8 JavaScript Engine C++ C++ labels Oct 16, 2022
@xiaoxiaojx xiaoxiaojx removed the v8 V8 JavaScript Engine label Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ C++
Projects
None yet
Development

No branches or pull requests

1 participant