при компиляции clang в целевой wasm он возвращает ошибку для объявления функции - PullRequest
0 голосов
/ 03 августа 2020

Я попытался сгенерировать файл wasm из программы c.

тест clang. c --target = wasm32-unknown-unknown-wasm -nostartfiles -nostdlib -Wl, - -no-entry -Wl, - export-all -o test.wasm

Содержимое test.c файла выглядит следующим образом

extern void __VERIFIER_error(void);
extern void __VERIFIER_assume(int);
void __VERIFIER_assert(int cond) {
  if (!(cond)) {
      ERROR: __VERIFIER_error();
  }
  return;
}
int __VERIFIER_nondet_int();

int test() {
    int x = 1;
    int y = 0;
    while (y < 1000 && __VERIFIER_nondet_int()) {
        x = x + y;
        y = y + 1;
    }
    __VERIFIER_assert(x >= y);
    return 0;
}

Встречается следующее сообщение об ошибке:

clang test.c  --target=wasm32-unknown-unknown-wasm -nostartfiles -nostdlib -Wl,--no-entry -Wl,--export-all -o test.wasm
wasm-ld: error: /tmp/test-e520f3.o: undefined symbol: __VERIFIER_error
wasm-ld: error: /tmp/test-e520f3.o: undefined symbol: __VERIFIER_nondet_int
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)

Я обновил содержимое файла следующим образом:

extern "C" void __VERIFIER_error(void);
extern "C" void __VERIFIER_assume(int);
extern "C" void __VERIFIER_assert(int cond) {
  if (!(cond)) {
      ERROR: __VERIFIER_error();
  }
  return;
}
extern "C" int __VERIFIER_nondet_int();

int test() {
    int x = 1;
    int y = 0;
    while (y < 1000 && __VERIFIER_nondet_int()) {
        x = x + y;
        y = y + 1;
    }
    __VERIFIER_assert(x >= y);
    return 0;
}

Появляется следующее сообщение об ошибке, как избавиться от таких ошибок. Может ли кто-нибудь помочь в этом отношении.

test/test.c:1:8: error: expected identifier or '('
extern "C" void __VERIFIER_error(void);
       ^
test/test.c:2:8: error: expected identifier or '('
extern "C" void __VERIFIER_assume(int);
       ^
test/test.c:3:8: error: expected identifier or '('
extern "C" void __VERIFIER_assert(int cond) {
       ^
test/test.c:9:8: error: expected identifier or '('
extern "C" int __VERIFIER_nondet_int();
       ^
test/test.c:13:24: warning: implicit declaration of function '__VERIFIER_nondet_int' is invalid in C99 [-Wimplicit-function-declaration]
    while (y < 1000 && __VERIFIER_nondet_int()) {
                       ^
test/test.c:17:5: warning: implicit declaration of function '__VERIFIER_assert' is invalid in C99 [-Wimplicit-function-declaration]
    __VERIFIER_assert(x >= y);
    ^
2 warnings and 4 errors generated.

1 Ответ

0 голосов
/ 03 августа 2020

У вас есть две функции без определений. Вы не связываете никакие библиотеки или другие объектные файлы. Таким образом, компоновщик не находит их и выдает сообщение об ошибке.

...