0

I have tried to generate wasm file from the c program.

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

The content of test.c the file is as follows

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;
}

Encounter the following error message:

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)

I have updated content of the file as follows:

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;
}

Encounter the following error message, how to get rid of such errors. Can anyone please guide in this regard.

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.
3
  • why these extern "C" ? you are in C, not in C++ for instance. The fact these functions have a name starting by 2 '_' is very suspicious . Where these functions are supposing coming from, are they defined in a library ? if yes probably you have associated header to include Commented Aug 3, 2020 at 17:00
  • Yes, I have defined those functions in file extest.h. Can you please guide me on how to link files using options...I have tried "clang test.c --target=wasm32-unknown-unknown-wasm --sysroot =/../inlcude/ -nostartfiles -nostdlib -Wl,--no-entry -Wl,--export-all -o test.wasm". I have also tried option --include-directory Commented Aug 3, 2020 at 18:24
  • 1
    I have defined those functions in file extest.h I think you declared them, not defined, a declaration is just the signature without the body while a definition also has the body. extern void __VERIFIER_error(void); and ` void __VERIFIER_error(void);` are declaration, void __VERIFIER_error(void) { ... } is a definition, like you defined test Commented Aug 3, 2020 at 20:38

1 Answer 1

0

You have two functions without definitions. You do not link any libraries or other object files. So linker is not finding them and issues the error message.

Sign up to request clarification or add additional context in comments.

5 Comments

Can you please guide me on how to link header files using any option. Let's say all my header files are present in directory /../include. I have tried --sysroot =/../include and --include-directory =/../include options in my command
1. "clang test.c --target=wasm32-unknown-unknown-wasm --sysroot =/../inlcude/ -nostartfiles -nostdlib -Wl,--no-entry -Wl,--export-all -o test.wasm"
2. "clang test.c --target=wasm32-unknown-unknown-wasm --include-directory =/../inlcude/ -nostartfiles -nostdlib -Wl,--no-entry -Wl,--export-all -o test.wasm"
you cant link header files. You can only link object files.
you need to link object files with the"bodies" of those functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.