GithubHelp home page GithubHelp logo

wdamron / wag Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gate-computer/wag

0.0 1.0 0.0 2.76 MB

WebAssembly compiler implemented in Go

Home Page: https://godoc.org/github.com/tsavola/wag

License: BSD 3-Clause "New" or "Revised" License

Go 87.67% Assembly 9.11% Makefile 0.04% WebAssembly 2.14% C 0.94% Rust 0.11%

wag's Introduction

wag is a WebAssembly compiler implemented as a Go package.

Features

  • The input is a wasm32 binary module.

  • The output is executable x86-64 or ARM64 machine code. (ARM64 support is incomplete. Support for 32-bit or big-endian CPU architectures isn't planned.)

  • It is only a compiler. A runtime environment for the compiled program, including all import functions, needs to be implemented separately. (But see wasys for a combined compiler and runtime.)

  • Single-pass, fast ahead-of-time compilation. Early functions can be executed while the latter functions are still being compiled, even while the source is still being downloaded.

  • The generated code requires minimal runtime support; it's designed to be executed in an isolated environment. Calling standard library ABIs is not supported, but see wasys for an example program which exposes syscalls as WebAssembly import functions.

  • Supports snapshot-and-restore across compiler versions and CPU architectures. Could also support limited form of code swapping during snapshot and restore.

  • Cross-compilaton is supported via Go build tags. If wagamd64 is specified, the x86-64 code generator is used regardless of host architecture, and CPU feature detection is disabled with pessimistic assumptions. Likewise for wagarm64, but feature detection is never used for ARM64.

Status

  • Supports WebAssembly version 1 (MVP).

  • Generated x86-64 code requires SSE4.1 ROUNDSS/ROUNDSD instructions.

  • ARM64 backend supports "hello, world" but not much else.

  • The Go package API hasn't been finalized (but it's getting there).

Security

Spectre variant 1: Out-of-bounds linear memory access detection requires that addressable but unallocated memory is inaccessible. It naturally prevents conditional branch exploitation.

Spectre variant 2: On x86, Retpoline is used to protect the runtime environment (although user programs shouldn't be able to inject arbitrary addresses into the branch target buffer).

Testing

Requires Linux, Go, make, clang and libcapstone. About 75% of the WebAssembly spec testsuite is run, by first converting the tests to binary format:

  1. go get -t github.com/tsavola/wag
  2. make -C $GOPATH/src/github.com/tsavola/wag/testdata/wabt
  3. go test -ldflags="-linkmode=internal" -bench=. github.com/tsavola/wag/...

Screenshot #1

$ go get github.com/tsavola/wag/cmd/wasys
$ wasys -v $GOPATH/src/github.com/tsavola/wag/testdata/hello.wasm
import write(i32, i32, i32) i32
import openat(i32, i32, i32, i32) i32
import read(i32, i32, i32) i32
import close(i32) i32
import pipe2(i32, i32) i32
import _exit(i32)
hello, world

Screenshot #2

=== RUN   TestSnapshot
--- PASS: TestSnapshot (0.00s)
    snapshot_test.go:80: print output:
        10
        --- snapshotting ---
        current memory limit: 0x6a96051ca000
        current stack ptr:    0x6a960533ffc0
        globals+memory addr:  0x6a96051ba000
        stack addr:           0x6a960533f000
        globals+memory size:  65536
        memory size:          65536
        stack offset:         4032
        stacktrace:
        #1  func-3
        #2  func-2
        --- shot snapped ---
        20
    snapshot_test.go:88: resuming
    snapshot_test.go:100: print output:
        20
        30
        330
        40
        440

wag's People

Contributors

tsavola avatar

Watchers

James Cloos avatar

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.