Skip to content

Commit e7b98cf

Browse files
runtime, os: fix the build on Solaris
Change-Id: Idcee121a6350cd2376c4ef95879e88fc0ba7df13 Reviewed-on: https://go-review.googlesource.com/137535 Reviewed-by: Cherry Zhang <[email protected]>
1 parent 652fbfb commit e7b98cf

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

libgo/go/os/executable_solaris.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44

55
package os
66

7-
import "syscall"
7+
import (
8+
"syscall"
9+
_ "unsafe" // for go:linkname
10+
)
811

9-
var executablePath string // set by sysauxv in ../runtime/os3_solaris.go
12+
// solarisExecutablePath is defined in the runtime package.
13+
func solarisExecutablePath() string
1014

1115
var initCwd, initCwdErr = Getwd()
1216

1317
func executable() (string, error) {
14-
path := executablePath
18+
path := solarisExecutablePath()
1519
if len(path) == 0 {
1620
path, err := syscall.Getexecname()
1721
if err != nil {

libgo/go/runtime/os3_solaris.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2011 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package runtime
6+
7+
import (
8+
"runtime/internal/sys"
9+
"unsafe"
10+
)
11+
12+
var executablePath string
13+
14+
func sysargs(argc int32, argv **byte) {
15+
n := argc + 1
16+
17+
// skip over argv, envp to get to auxv
18+
for argv_index(argv, n) != nil {
19+
n++
20+
}
21+
22+
// skip NULL separator
23+
n++
24+
25+
// now argv+n is auxv
26+
auxv := (*[1 << 28]uintptr)(add(unsafe.Pointer(argv), uintptr(n)*sys.PtrSize))
27+
sysauxv(auxv[:])
28+
}
29+
30+
const (
31+
_AT_NULL = 0 // Terminates the vector
32+
_AT_PAGESZ = 6 // Page size in bytes
33+
_AT_SUN_EXECNAME = 2014 // exec() path name
34+
)
35+
36+
func sysauxv(auxv []uintptr) {
37+
for i := 0; auxv[i] != _AT_NULL; i += 2 {
38+
tag, val := auxv[i], auxv[i+1]
39+
switch tag {
40+
case _AT_PAGESZ:
41+
physPageSize = val
42+
case _AT_SUN_EXECNAME:
43+
executablePath = gostringnocopy((*byte)(unsafe.Pointer(val)))
44+
}
45+
}
46+
}
47+
48+
//go:linkname solarisExecutablePath os.solarisExecutablePath
49+
50+
// solarisExecutablePath is called from the os package to fetch the
51+
// saved executable path.
52+
func solarisExecutablePath() string {
53+
return executablePath
54+
}

libgo/go/runtime/stubs3.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
// +build !plan9
6-
// +build !solaris
76
// +build !windows
87
// +build !nacl
98
// +build !freebsd

0 commit comments

Comments
 (0)