【问题标题】:unresolved symbol: llvm_trap from Emscripten未解析的符号:来自 Emscripten 的 llvm_trap
【发布时间】: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


【解决方案1】:

必须初始化变量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++

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-30
    • 2018-10-23
    • 2010-12-15
    • 1970-01-01
    • 1970-01-01
    • 2011-02-09
    相关资源
    最近更新 更多