Git Product home page Git Product logo

Comments (4)

ggreif avatar ggreif commented on July 26, 2024

Just for the record, I tried to reproduce this with https://webassembly.sh:

File uploaded successfully to /tmp
→ /tmp/log.c
$ cat /tmp/log.c
int main(void) { extern double log(double); printf("%f ---> %f\n", 7.4225, log(7.4225)); return 0; }
$ clang -cc1 -triple wasm32-unkown-wasi -isysroot /sys -internal-isystem /sys/include -emit-obj -o ./log.o /tmp/log.c
/tmp/log.c:1:45: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)'
int main(void) { extern double log(double); printf("%f ---> %f\n", 7.4225, log(7.4225)); return 0; }
                                            ^
/tmp/log.c:1:45: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
1 warning generated.
$ wasm-ld -L/sys/lib/wasm32-wasi /sys/lib/wasm32-wasi/crt1.o ./log.o -lc -o ./log.wasm
$ wasmer log.wasm
7.422500 ---> 2.004516

And there it produces the correct result.

from wasi-libc.

sunfishcode avatar sunfishcode commented on July 26, 2024

I don't have a nix machine handy, but at a quick try with the latest clang and wasi-libc, the testcase produces the correct result for me. Would it be possible to upload the wasm file somwhere?

from wasi-libc.

ggreif avatar ggreif commented on July 26, 2024

Compiled as

clang-10 --compile -fpic -fvisibility=hidden --std=c11 --target=wasm32-emscripten -fvisibility=hidden -fno-builtin -ffreestanding --optimize=3  -isystem /nix/store/n2zmrqyhm1avzwz9jf8kliz4ws29pph1-source/libc-top-half/musl/arch/wasm32 -isystem /nix/store/n2zmrqyhm1avzwz9jf8kliz4ws29pph1-source/libc-top-half/musl/src/include -isystem /nix/store/n2zmrqyhm1avzwz9jf8kliz4ws29pph1-source/libc-top-half/musl/src/internal -isystem /nix/store/mz8fajfb2sq5v9czy4rn70v7fz409l8n-musl-wasi-sysroot/include -I /nix/store/n2zmrqyhm1avzwz9jf8kliz4ws29pph1-source/libc-top-half/musl/../headers/private -D_ERRNO_H -DEOVERFLOW=75 -DEINVAL=22 -Derrno='(*({ static int bla = 0; &bla; }))' -DNL_ARGMAX=9 -D'TOKENPASTE0(x, y)=x ## y' -D'TOKENPASTE(x, y)=TOKENPASTE0(x, y)' -D'__fwritex=TOKENPASTE(__fwritex_,__COUNTER__)' -D'__fwritex_2(s, l, f)=(f->write((f), (s), (l)))' -D'__towrite=TOKENPASTE(__towrite_,__COUNTER__)' -D'__towrite_3(f)=(0)' -D__wasilibc_printscan_no_long_double -D__wasilibc_printscan_full_support_option='""' -D__wasi__ -D__NEED_va_list -D__NEED_off_t -Dsqrt=__builtin_sqrt -Dfabs=__builtin_fabs /nix/store/n2zmrqyhm1avzwz9jf8kliz4ws29pph1-source/libc-top-half/musl/src/math/log.c --output _build/wasm/musl_log.o

(Yes, I know about --target=wasm32-emscripten, that is needed in my setup for technical reasons (i.e. dynamic linking), but I'd be surprised if that turned out to be the problem).
musl_log.o.zip

from wasi-libc.

ggreif avatar ggreif commented on July 26, 2024

Oops, I found my error. The file log_data.c was not linked into my library. Sorry for the noise!

from wasi-libc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.