]> Cypherpunks repositories - gostls13.git/commitdiff
math/bits: add gccgo-friendly code for compiler bootstrap
authorThan McIntosh <thanm@google.com>
Thu, 4 Apr 2019 15:01:22 +0000 (11:01 -0400)
committerThan McIntosh <thanm@google.com>
Thu, 4 Apr 2019 18:17:30 +0000 (18:17 +0000)
When building as part of the bootstrap process, avoid
use of "go:linkname" applied to variables, since this
feature is ill-defined/unsupported for gccgo.

Updates #30771.

Change-Id: Id44d01b5c98d292702e5075674117518cb59e2d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/170737
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/math/bits/bits.go
src/math/bits/bits_errors.go [new file with mode: 0644]
src/math/bits/bits_errors_bootstrap.go [new file with mode: 0644]

index 6f367dcc930d56da105c93bd8d4874f89f6fbd62..24d910c27ea7cc52cd9e422026823904cabdccf8 100644 (file)
@@ -8,8 +8,6 @@
 // functions for the predeclared unsigned integer types.
 package bits
 
-import _ "unsafe" // for go:linkname
-
 const uintSize = 32 << (^uint(0) >> 32 & 1) // 32 or 64
 
 // UintSize is the size of a uint in bits.
@@ -524,9 +522,3 @@ func Div64(hi, lo, y uint64) (quo, rem uint64) {
 
        return q1*two32 + q0, (un21*two32 + un0 - q0*y) >> s
 }
-
-//go:linkname overflowError runtime.overflowError
-var overflowError error
-
-//go:linkname divideError runtime.divideError
-var divideError error
diff --git a/src/math/bits/bits_errors.go b/src/math/bits/bits_errors.go
new file mode 100644 (file)
index 0000000..192b4be
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2019 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.
+
+// +build !compiler_bootstrap
+
+package bits
+
+import _ "unsafe"
+
+//go:linkname overflowError runtime.overflowError
+var overflowError error
+
+//go:linkname divideError runtime.divideError
+var divideError error
diff --git a/src/math/bits/bits_errors_bootstrap.go b/src/math/bits/bits_errors_bootstrap.go
new file mode 100644 (file)
index 0000000..5df5738
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2019 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.
+
+// +build compiler_bootstrap
+
+// This version used only for bootstrap (on this path we want
+// to avoid use of go:linkname as applied to variables).
+
+package bits
+
+type errorString string
+
+func (e errorString) RuntimeError() {}
+
+func (e errorString) Error() string {
+       return "runtime error: " + string(e)
+}
+
+var overflowError = error(errorString("integer overflow"))
+
+var divideError = error(errorString("integer divide by zero"))