WebAssembly / binaryen

Optimizer and compiler/toolchain library for WebAssembly
Apache License 2.0
7.4k stars 729 forks source link

s2wasm can't build wast of `dlmalloc.c` #534

Closed petamoriken closed 7 years ago

petamoriken commented 8 years ago

I want to build dlmalloc.c to wasm, but I can't.

clang -emit-llvm --target=wasm32 -S dlmalloc.c
llc dlmalloc.ll -march=wasm32
s2wasm dlmalloc.s > dlmalloc.wast
s2wasm: /home/moriken/binaryen/src/wasm-linker.cpp:134: void wasm::Linker::layout(): Assertion `symbolAddress != staticAddresses.end()' failed.
clang -v
clang version 3.9.0 (http://llvm.org/git/clang.git 56ce09324f4e8e9cacc03b02c6c9ba97b42331fb) (http://llvm.org/git/llvm.git 35f771e8a97616c3f7234d5c12114b1129b78ee8)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.3.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.0.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.3.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
llc -version
LLVM (http://llvm.org/):
  LLVM version 3.9.0svn
  DEBUG build with assertions.
  Built Apr 18 2016 (13:00:39).
  Default target: x86_64-unknown-linux-gnu
  Host CPU: sandybridge

  Registered Targets:
    aarch64    - AArch64 (little endian)
    aarch64_be - AArch64 (big endian)
    amdgcn     - AMD GCN GPUs
    arm        - ARM
    arm64      - ARM64 (little endian)
    armeb      - ARM (big endian)
    bpf        - BPF (host endian)
    bpfeb      - BPF (big endian)
    bpfel      - BPF (little endian)
    cpp        - C++ backend
    hexagon    - Hexagon
    mips       - Mips
    mips64     - Mips64 [experimental]
    mips64el   - Mips64el [experimental]
    mipsel     - Mipsel
    msp430     - MSP430 [experimental]
    nvptx      - NVIDIA PTX 32-bit
    nvptx64    - NVIDIA PTX 64-bit
    ppc32      - PowerPC 32
    ppc64      - PowerPC 64
    ppc64le    - PowerPC 64 LE
    r600       - AMD GPUs HD2XXX-HD6XXX
    sparc      - Sparc
    sparcel    - Sparc LE
    sparcv9    - Sparc V9
    systemz    - SystemZ
    thumb      - Thumb
    thumbeb    - Thumb (big endian)
    wasm32     - WebAssembly 32-bit
    wasm64     - WebAssembly 64-bit
    x86        - 32-bit X86: Pentium-Pro and above
    x86-64     - 64-bit X86: EM64T and AMD64
    xcore      - XCore
kripken commented 8 years ago

Not sure what's going wrong, but in general when you run something like clang -emit-llvm --target=wasm32 -S dlmalloc.c then you are compiling using the local system settings. For example, you get the local system headers that define basic types and so forth. That might be messing things up. (When you use emcc to build, it uses portable libc headers and also handles the triple stuff for you.)

petamoriken commented 7 years ago

Sorry for my late reply. https://github.com/guybedford/wasm-stdlib-hack solved this issue.

Thanks!