Skip to content

Commit f41dc71

Browse files
neelancebradfitz
authored andcommitted
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: Cherry Zhang <cherryyz@google.com>
1 parent 406886b commit f41dc71

File tree

12 files changed

+544
-3
lines changed

12 files changed

+544
-3
lines changed

misc/wasm/wasm_exec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ async function compile(source) {
145145

146146
async function run() {
147147
let importObject = {
148-
js: {
148+
go: {
149149
// func wasmexit(code int32)
150150
"runtime.wasmexit": function (sp) {
151151
process.exit(mem().getInt32(sp + 8, true));

src/cmd/dist/build.go

+2
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ var okgoarch = []string{
6868
"ppc64",
6969
"ppc64le",
7070
"s390x",
71+
"wasm",
7172
}
7273

7374
// The known operating systems.
7475
var okgoos = []string{
7576
"darwin",
7677
"dragonfly",
78+
"js",
7779
"linux",
7880
"android",
7981
"solaris",

src/cmd/dist/buildtool.go

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ var bootstrapDirs = []string{
8080
"cmd/link/internal/s390x",
8181
"cmd/link/internal/sym",
8282
"cmd/link/internal/x86",
83+
"cmd/link/internal/wasm",
8384
"container/heap",
8485
"debug/dwarf",
8586
"debug/elf",

src/cmd/link/internal/ld/data.go

+4
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,10 @@ func (ctxt *Link) textaddress() {
18521852
// Note: once we have trampoline insertion support for external linking, this function
18531853
// will not need to create new text sections, and so no need to return sect and n.
18541854
func assignAddress(ctxt *Link, sect *sym.Section, n int, s *sym.Symbol, va uint64, isTramp bool) (*sym.Section, int, uint64) {
1855+
if thearch.AssignAddress != nil {
1856+
return thearch.AssignAddress(ctxt, sect, n, s, va, isTramp)
1857+
}
1858+
18551859
s.Sect = sect
18561860
if s.Attr.SubSymbol() {
18571861
return sect, n, va

src/cmd/link/internal/ld/dwarf.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,7 @@ func dwarfgeneratedebugsyms(ctxt *Link) {
16751675
if *FlagS && ctxt.HeadType != objabi.Hdarwin {
16761676
return
16771677
}
1678-
if ctxt.HeadType == objabi.Hplan9 {
1678+
if ctxt.HeadType == objabi.Hplan9 || ctxt.HeadType == objabi.Hjs {
16791679
return
16801680
}
16811681

src/cmd/link/internal/ld/lib.go

+3
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ type Arch struct {
121121
// symbol in an executable, which is typical when internally
122122
// linking PIE binaries.
123123
TLSIEtoLE func(s *sym.Symbol, off, size int)
124+
125+
// optional override for assignAddress
126+
AssignAddress func(ctxt *Link, sect *sym.Section, n int, s *sym.Symbol, va uint64, isTramp bool) (*sym.Section, int, uint64)
124127
}
125128

126129
var (

src/cmd/link/internal/ld/outbuf.go

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ func (out *OutBuf) Write8(v uint8) {
6060
}
6161
}
6262

63+
// WriteByte is an alias for Write8 to fulfill the io.ByteWriter interface.
64+
func (out *OutBuf) WriteByte(v byte) error {
65+
out.Write8(v)
66+
return nil
67+
}
68+
6369
func (out *OutBuf) Write16(v uint16) {
6470
out.arch.ByteOrder.PutUint16(out.encbuf[:], v)
6571
out.Write(out.encbuf[:2])

src/cmd/link/internal/ld/sym.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (ctxt *Link) computeTLSOffset() {
6666
default:
6767
log.Fatalf("unknown thread-local storage offset for %v", ctxt.HeadType)
6868

69-
case objabi.Hplan9, objabi.Hwindows:
69+
case objabi.Hplan9, objabi.Hwindows, objabi.Hjs:
7070
break
7171

7272
/*

0 commit comments

Comments
 (0)