[llvm-bugs] [Bug 30862] New: WebAssembly alias stack pointer not initialized

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Nov 1 11:26:19 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=30862

            Bug ID: 30862
           Summary: WebAssembly alias stack pointer not initialized
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: WebAssembly
          Assignee: unassignedbugs at nondot.org
          Reporter: timo.savola at iki.fi
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 17529
  --> https://llvm.org/bugs/attachment.cgi?id=17529&action=edit
Small demo program

LLVM seems to use the 32-bit value at WebAssembly linear memory offset 4 as
__stack_pointer, which is used to access the secondary stack within the linear
memory.  However, while it's correctly maintained by function prologue and
epilogue, it's not initialized at the start of the program.

If the size of the WebAssembly memory would be constant, and indexing the
linear memory would wrap according to the memory size, things would work by
default.  But neither of those is the case.

Perhaps the memory location is supposed to be initialized by some WebAssembly C
runtime library that needs to be linked to the program?  Or is the WebAssembly
runtime environment expected to set that up somehow (seems wrong)?

I've managed to run LLVM-compiled WebAssembly programs (in a custom runtime) by
initializing the stack pointer with the size of the initial memory limit (and
thus assuming that the stack is located at the end of the initial linear
memory).

The attached test.c can be compiled to a valid WebAssembly program using
LLVM/clang compiled with the experimental WebAssembly target and the tools from
https://github.com/WebAssembly/binaryen and
https://github.com/WebAssembly/wabt:

    $ clang --target=wasm32 -Os -S -o test.s test.c
    $ s2wasm --start=main test.s > test.wast
    $ wast2wasm -o test.wasm test.wast

I located the stack management code in
lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp, but could't find a place
which attempts to initialize the __stack_pointer.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20161101/e9bd79d5/attachment-0001.html>


More information about the llvm-bugs mailing list