support WASI target (#1373)

* initial commit for WASI support

* merge "time" package with wasi build tag
* override syscall package with wasi build tag
* create runtime_wasm_{js,wasi}.go files
* create syscall_wasi.go file
* create time/zoneinfo_wasi.go file as the replacement of zoneinfo_js.go
* add targets/wasi.json target

* set visbility hidden for runtime extern variables

Accodring to the WASI docs (https://github.com/WebAssembly/WASI/blob/master/design/application-abi.md#current-unstable-abi),
none of exports of WASI executable(Command) should no be accessed.

v0.19.0 of bytecodealliance/wasmetime, which is often refered to as the reference implementation of WASI,
does not accept any exports except functions and the only limited variables like "table", "memory".

* merge syscall_{baremetal,wasi}.go

* fix js target build

* mv wasi functions to syscall/wasi && implement sleepTicks

* WASI: set visibility hidden for globals variables

* mv back syscall/wasi/* to runtime package

* WASI: add test

* unexport wasi types

* WASI test: fix wasmtime path

* stop changing visibility of runtime.alloc

* use GOOS=linux, GOARCH=arm for wasi target

Signed-off-by: mathetake <takeshi@tetrate.io>

* WASI: fix build tags for os/runtime packages

Signed-off-by: mathetake <takeshi@tetrate.io>

* run WASI test only on Linux

Signed-off-by: mathetake <takeshi@tetrate.io>

* set InternalLinkage instead of changing visibility

Signed-off-by: mathetake <takeshi@tetrate.io>
This commit is contained in:
Takeshi Yoneda
2020-09-30 04:58:03 +09:00
committed by GitHub
parent d39c7abb4d
commit f50ad3585d
17 changed files with 241 additions and 72 deletions
+5
View File
@@ -19,6 +19,7 @@ func MakeGCStackSlots(mod llvm.Module) bool {
}
stackChainStart := mod.NamedGlobal("runtime.stackChainStart")
if !stackChainStart.IsNil() {
stackChainStart.SetLinkage(llvm.InternalLinkage)
stackChainStart.SetInitializer(llvm.ConstNull(stackChainStart.Type().ElementType()))
stackChainStart.SetGlobalConstant(true)
}
@@ -94,6 +95,7 @@ func MakeGCStackSlots(mod llvm.Module) bool {
}
return false
}
stackChainStart.SetLinkage(llvm.InternalLinkage)
stackChainStartType := stackChainStart.Type().ElementType()
stackChainStart.SetInitializer(llvm.ConstNull(stackChainStartType))
@@ -333,11 +335,13 @@ func AddGlobalsBitmap(mod llvm.Module) bool {
// Update trackedGlobalsStart, which points to the globals bundle.
trackedGlobalsStart := llvm.ConstPtrToInt(globalsBundle, uintptrType)
mod.NamedGlobal("runtime.trackedGlobalsStart").SetInitializer(trackedGlobalsStart)
mod.NamedGlobal("runtime.trackedGlobalsStart").SetLinkage(llvm.InternalLinkage)
// Update trackedGlobalsLength, which contains the length (in words) of the
// globals bundle.
alignment := targetData.PrefTypeAlignment(llvm.PointerType(ctx.Int8Type(), 0))
trackedGlobalsLength := llvm.ConstInt(uintptrType, targetData.TypeAllocSize(globalsBundleType)/uint64(alignment), false)
mod.NamedGlobal("runtime.trackedGlobalsLength").SetLinkage(llvm.InternalLinkage)
mod.NamedGlobal("runtime.trackedGlobalsLength").SetInitializer(trackedGlobalsLength)
// Create a bitmap (a new global) that stores for each word in the globals
@@ -357,6 +361,7 @@ func AddGlobalsBitmap(mod llvm.Module) bool {
bitmapOld.ReplaceAllUsesWith(llvm.ConstBitCast(bitmapNew, bitmapOld.Type()))
bitmapNew.SetInitializer(bitmapArray)
bitmapNew.SetName("runtime.trackedGlobalsBitmap")
bitmapNew.SetLinkage(llvm.InternalLinkage)
return true // the IR was changed
}
+3 -3
View File
@@ -7,11 +7,11 @@ target triple = "wasm32-unknown-unknown-wasm"
@globalInt = global i32 5
@constString = constant %runtime._string zeroinitializer
@constInterface = constant %runtime._interface zeroinitializer
@runtime.trackedGlobalsLength = global i32 4
@runtime.trackedGlobalsLength = internal global i32 4
@runtime.trackedGlobalsBitmap = external global [0 x i8]
@runtime.trackedGlobalsStart = global i32 ptrtoint ({ %runtime._string, %runtime._interface }* @tinygo.trackedGlobals to i32)
@runtime.trackedGlobalsStart = internal global i32 ptrtoint ({ %runtime._string, %runtime._interface }* @tinygo.trackedGlobals to i32)
@tinygo.trackedGlobals = internal unnamed_addr global { %runtime._string, %runtime._interface } zeroinitializer
@runtime.trackedGlobalsBitmap.1 = global [1 x i8] c"\09"
@runtime.trackedGlobalsBitmap.1 = internal global [1 x i8] c"\09"
define void @main() {
%1 = load i32, i32* @globalInt
+1 -1
View File
@@ -3,7 +3,7 @@ target triple = "wasm32-unknown-unknown-wasm"
%runtime.stackChainObject = type { %runtime.stackChainObject*, i32 }
@runtime.stackChainStart = global %runtime.stackChainObject* null
@runtime.stackChainStart = internal global %runtime.stackChainObject* null
@someGlobal = global i8 3
declare void @runtime.trackPointer(i8* nocapture readonly)