Commit f41dc711 authored by Richard Musiol's avatar Richard Musiol Committed by Brad Fitzpatrick

cmd/link: add wasm architecture

This commit adds the wasm architecture to the link command.

Design doc: https://docs.google.com/document/d/131vjr4DH6JFnb-blm_uRdaC0_Nv3OUwjEY5qVCxCup4

Updates #18892

Change-Id: I5aef29954984537f2979679b5d393209e462f564
Reviewed-on: https://go-review.googlesource.com/103795
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarCherry Zhang <cherryyz@google.com>
parent 406886b5
......@@ -145,7 +145,7 @@ async function compile(source) {
async function run() {
let importObject = {
js: {
go: {
// func wasmexit(code int32)
"runtime.wasmexit": function (sp) {
process.exit(mem().getInt32(sp + 8, true));
......
......@@ -68,12 +68,14 @@ var okgoarch = []string{
"ppc64",
"ppc64le",
"s390x",
"wasm",
}
// The known operating systems.
var okgoos = []string{
"darwin",
"dragonfly",
"js",
"linux",
"android",
"solaris",
......
......@@ -80,6 +80,7 @@ var bootstrapDirs = []string{
"cmd/link/internal/s390x",
"cmd/link/internal/sym",
"cmd/link/internal/x86",
"cmd/link/internal/wasm",
"container/heap",
"debug/dwarf",
"debug/elf",
......
......@@ -1852,6 +1852,10 @@ func (ctxt *Link) textaddress() {
// Note: once we have trampoline insertion support for external linking, this function
// will not need to create new text sections, and so no need to return sect and n.
func assignAddress(ctxt *Link, sect *sym.Section, n int, s *sym.Symbol, va uint64, isTramp bool) (*sym.Section, int, uint64) {
if thearch.AssignAddress != nil {
return thearch.AssignAddress(ctxt, sect, n, s, va, isTramp)
}
s.Sect = sect
if s.Attr.SubSymbol() {
return sect, n, va
......
......@@ -1675,7 +1675,7 @@ func dwarfgeneratedebugsyms(ctxt *Link) {
if *FlagS && ctxt.HeadType != objabi.Hdarwin {
return
}
if ctxt.HeadType == objabi.Hplan9 {
if ctxt.HeadType == objabi.Hplan9 || ctxt.HeadType == objabi.Hjs {
return
}
......
......@@ -121,6 +121,9 @@ type Arch struct {
// symbol in an executable, which is typical when internally
// linking PIE binaries.
TLSIEtoLE func(s *sym.Symbol, off, size int)
// optional override for assignAddress
AssignAddress func(ctxt *Link, sect *sym.Section, n int, s *sym.Symbol, va uint64, isTramp bool) (*sym.Section, int, uint64)
}
var (
......
......@@ -60,6 +60,12 @@ func (out *OutBuf) Write8(v uint8) {
}
}
// WriteByte is an alias for Write8 to fulfill the io.ByteWriter interface.
func (out *OutBuf) WriteByte(v byte) error {
out.Write8(v)
return nil
}
func (out *OutBuf) Write16(v uint16) {
out.arch.ByteOrder.PutUint16(out.encbuf[:], v)
out.Write(out.encbuf[:2])
......
......@@ -66,7 +66,7 @@ func (ctxt *Link) computeTLSOffset() {
default:
log.Fatalf("unknown thread-local storage offset for %v", ctxt.HeadType)
case objabi.Hplan9, objabi.Hwindows:
case objabi.Hplan9, objabi.Hwindows, objabi.Hjs:
break
/*
......
This diff is collapsed.
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package wasm
import (
"cmd/internal/sys"
"cmd/link/internal/ld"
)
func Init() (*sys.Arch, ld.Arch) {
theArch := ld.Arch{
Funcalign: 16,
Maxalign: 32,
Minalign: 1,
Archinit: archinit,
AssignAddress: assignAddress,
Asmb: asmb,
Gentext: gentext,
}
return sys.ArchWasm, theArch
}
func archinit(ctxt *ld.Link) {
if *ld.FlagRound == -1 {
*ld.FlagRound = 4096
}
if *ld.FlagTextAddr == -1 {
*ld.FlagTextAddr = 0
}
}
......@@ -15,6 +15,7 @@ import (
"cmd/link/internal/mips64"
"cmd/link/internal/ppc64"
"cmd/link/internal/s390x"
"cmd/link/internal/wasm"
"cmd/link/internal/x86"
"fmt"
"os"
......@@ -58,6 +59,8 @@ func main() {
arch, theArch = ppc64.Init()
case "s390x":
arch, theArch = s390x.Init()
case "wasm":
arch, theArch = wasm.Init()
}
ld.Main(arch, theArch)
}
......@@ -25,6 +25,9 @@ GLOBL runtime·memstats(SB), NOPTR, $0
#ifdef GOARCH_amd64p32
#define SKIP4 BYTE $0x90; BYTE $0x90; BYTE $0x90; BYTE $0x90
#endif
#ifdef GOARCH_wasm
#define SKIP4 UNDEF; UNDEF; UNDEF; UNDEF
#endif
#ifndef SKIP4
#define SKIP4 WORD $0
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment