gpt4 book ai didi

javascript - 未解析的符号 : llvm_trap from Emscripten

转载 作者:行者123 更新时间:2023-11-30 16:39:10 24 4
gpt4 key购买 nike

当我尝试将以下代码片段编译为 WebAssembly 二进制文件时,我不断遇到 未解析的符号:llvm_trap 警告,这使得 JS 无法使用 wasm 代码。

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必须初始化。如果它表示“映射”到 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 函数的更多详细信息,请参阅以下问题:

How to access WebAssembly linear memory from C/C++

关于javascript - 未解析的符号 : llvm_trap from Emscripten,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47171012/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com