当我尝试将以下代码段编译成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
相关代码。有人有想法是什么意思吗?
答案 0 :(得分:0)
必须初始化变量T
。如果它代表一个映射'映射'对于WebAssembly线性存储器,您可以将其定义为全局,如下所示:
int T[1000];
int test(int *buf) {
int C = 1;
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警告。
有关如何使用线性内存将数据传递到WASM函数的更多详细信息,请参阅以下问题: