【发布时间】:2017-11-08 03:16:11
【问题描述】:
当我尝试将以下 sn-p 编译为 WebAssembly 二进制文件时,我一直遇到 unresolved symbol: llvm_trap 警告,这使得 wasm 代码无法从 JS 中使用。
emcc test.c -s WASM=1 -s ONLY_MY_CODE=1 -s "EXPORTED_FUNCTIONS=['_test']" -O2 -g -o test.js
test.c(这是在不做有意义的工作的情况下重现问题的测试代码。)
int test(int *buf) {
int C = 1;
// Assuming WebAssembly.Memory buffer has been preloaed with data.
// *T represents the preloaded data here. And We know *T and *buf
// won't overlap in memory.
int *T = 0;
int index = C ^ buf[5];
int right = T[index];
int left = (unsigned)C >> 8;
// warning disappears if this is commented out. But why?
C = left ^ right;
return C;
}
我没有写任何llvm_trap相关的代码。有人知道这是什么意思吗?
【问题讨论】:
-
这是错误的,因为
T为 NULL。int right = T[index];. -
@MFisherKDX 在 WebAssembly 中,我们可以将数据预加载到
WebAssembly.Memory缓冲区。*T这里只是一个指向缓冲区中特定位置的指针。
标签: javascript c emscripten webassembly