Same as CL 492135, but for init function.
Fixes #62277
Change-Id: If5ff9bc2ce2a73193b1f7ee5f7f14045d1354f56
Reviewed-on: https://go-review.googlesource.com/c/go/+/522956
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
goCmd(t, "run", "-linkshared", "./issue47837/main")
}
+func TestIssue62277(t *testing.T) {
+ globalSkip(t)
+ goCmd(t, "install", "-buildmode=shared", "-linkshared", "./issue62277/p")
+ goCmd(t, "test", "-linkshared", "./issue62277")
+}
+
// Test that we can build std in shared mode.
func TestStd(t *testing.T) {
if testing.Short() {
--- /dev/null
+// Copyright 2023 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 issue62277_test
+
+import (
+ "testing"
+
+ "testshared/issue62277/p"
+)
+
+func TestIssue62277(t *testing.T) {
+ t.Log(p.S)
+ t.Log(p.T)
+}
--- /dev/null
+// Copyright 2023 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 p
+
+var S = func() []string {
+ return []string{"LD_LIBRARY_PATH"}
+}()
+
+var T []string
+
+func init() {
+ T = func() []string {
+ return []string{"LD_LIBRARY_PATH"}
+ }()
+}
r.addBody(fn, nil)
+ // un-hide closures belong to init function.
+ if (r.curfn.IsPackageInit() || strings.HasPrefix(r.curfn.Sym().Name, "init.")) && ir.IsTrivialClosure(fn.OClosure) {
+ fn.SetIsHiddenClosure(false)
+ }
+
return fn.OClosure
}