]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: correct ABI information for all functions
authorAustin Clements <austin@google.com>
Thu, 1 Nov 2018 16:25:41 +0000 (12:25 -0400)
committerAustin Clements <austin@google.com>
Mon, 12 Nov 2018 20:27:18 +0000 (20:27 +0000)
There are three cases where we don't currently have the visibility to
get the ABIs of runtime symbols right, which this CL fixes:

1. For Go functions referenced from non-Go code in other packages.
   This is runtime.morestackc (which is referenced from function
   prologues) and a few syscall symbols. For these we need to generate
   ABI0 wrappers, so this CL adds dummy calls in the assembly code to
   force wrapper generation. There are many other cross-package
   references to runtime and runtime/internal/atomic, but these are
   handled specially by cmd/go.

2. For calls generated by the compiler to runtime Go functions, there
   are a few symbols that aren't declared in builtins.go because we've
   never needed their type information before. Now we at least need
   their ABI information, so these are added to builtins.go.

3. For calls generated by the compiler to runtime assembly functions,
   the compiler is going to assume the internal ABI is available, so
   we add Go stubs to the runtime to trigger wrapper generation. For
   these we're probably going to want to provide internal ABI
   definitions directly in the assembly for performance, but for now
   the ABIs are the same so it doesn't matter.

For #27539.

Change-Id: I9c224e7408d2ef4dd9b0e4c9d7e962ddfe111245
Reviewed-on: https://go-review.googlesource.com/c/146822
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/cmd/vet/all/whitelist/386.txt
src/runtime/asm.s
src/runtime/os_nacl.go
src/runtime/race.go
src/runtime/stubs_386.go [new file with mode: 0644]
src/syscall/asm_windows.s [new file with mode: 0644]

index 2495d831aa43772c57a81033813c56f092abb004..3dbb340cbd6d1910cee4be7b9f1a10ccb13c4855 100644 (file)
@@ -18,6 +18,3 @@ runtime/asm_386.s: [386] aeshashbody: function aeshashbody missing Go declaratio
 runtime/asm_386.s: [386] addmoduledata: function addmoduledata missing Go declaration
 runtime/duff_386.s: [386] duffzero: function duffzero missing Go declaration
 runtime/duff_386.s: [386] duffcopy: function duffcopy missing Go declaration
-
-runtime/asm_386.s: [386] uint32tofloat64: function uint32tofloat64 missing Go declaration
-runtime/asm_386.s: [386] float64touint32: function float64touint32 missing Go declaration
index 6b209b2d1f463a52e4289325fbf88e7770164472..314f99d69be4feb7d6d7f2d8b843e704978da0d7 100644 (file)
@@ -38,3 +38,11 @@ GLOBL runtime·memstats(SB), NOPTR, $0
 // This function must be sizeofSkipFunction bytes.
 TEXT runtime·skipPleaseUseCallersFrames(SB),NOSPLIT,$0-0
        SKIP64; SKIP64; SKIP64; SKIP64
+
+// abi0Syms is a dummy symbol that creates ABI0 wrappers for Go
+// functions called from assembly in other packages.
+TEXT abi0Syms<>(SB),NOSPLIT,$0-0
+       // obj assumes it can call morestack* using ABI0, but
+       // morestackc is actually defined in Go.
+       CALL ·morestackc(SB)
+       // References from syscall are automatically collected by cmd/go.
index ac7bf69582533edaf7c6ce156c51a5bc1054dc47..155b763c3d7fe26301be1142666a7b9bf5a751ea 100644 (file)
@@ -317,3 +317,12 @@ int8 nacl_irt_thread_v0_1_str[] = "nacl-irt-thread-0.1";
 void *nacl_irt_thread_v0_1[3]; // thread_create, thread_exit, thread_nice
 int32 nacl_irt_thread_v0_1_size = sizeof(nacl_irt_thread_v0_1);
 */
+
+// The following functions are implemented in runtime assembly.
+// Provide a Go declaration to go with its assembly definitions.
+
+//go:linkname syscall_naclWrite syscall.naclWrite
+func syscall_naclWrite(fd int, b []byte) int
+
+//go:linkname syscall_now syscall.now
+func syscall_now() (sec int64, nsec int32)
index 4420c5df2be03ab85c603b25ab1653aeb46cee59..08d53a10d2ba53471ce2daf43b69931b4cb33840 100644 (file)
@@ -294,6 +294,10 @@ var racearenaend uintptr
 func racefuncenter(uintptr)
 func racefuncenterfp()
 func racefuncexit()
+func raceread(uintptr)
+func racewrite(uintptr)
+func racereadrange(addr, size uintptr)
+func racewriterange(addr, size uintptr)
 func racereadrangepc1(uintptr, uintptr, uintptr)
 func racewriterangepc1(uintptr, uintptr, uintptr)
 func racecallbackthunk(uintptr)
diff --git a/src/runtime/stubs_386.go b/src/runtime/stubs_386.go
new file mode 100644 (file)
index 0000000..01d92d3
--- /dev/null
@@ -0,0 +1,8 @@
+// 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 runtime
+
+func float64touint32(a float64) uint32
+func uint32tofloat64(a uint32) float64
diff --git a/src/syscall/asm_windows.s b/src/syscall/asm_windows.s
new file mode 100644 (file)
index 0000000..e965914
--- /dev/null
@@ -0,0 +1,11 @@
+// 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.
+
+#include "textflag.h"
+
+// abi0Syms is a dummy symbol that creates ABI0 wrappers for Go
+// functions called from assembly in other packages.
+TEXT abi0Syms<>(SB),NOSPLIT,$0-0
+       CALL ·getprocaddress(SB)
+       CALL ·loadlibrary(SB)