Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo/internal/testshared: TestStd failing since CL 522318 #62277

Closed
mdempsky opened this issue Aug 25, 2023 · 10 comments
Closed

cmd/cgo/internal/testshared: TestStd failing since CL 522318 #62277

mdempsky opened this issue Aug 25, 2023 · 10 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mdempsky
Copy link
Member

The longtest builders are failing since 88cb17e (go.dev/cl/522318).

With golang.org/x/tools/cmd/bisect, I've narrowed it down to net/http/cgi's init function. Notably, disabling inlining avoids the issue too.

@mdempsky mdempsky added NeedsFix The path to resolution is known, but the work has not been done. Soon This needs to be done soon. (regressions, serious bugs, outages) labels Aug 25, 2023
@mdempsky mdempsky self-assigned this Aug 25, 2023
@mdempsky
Copy link
Member Author

The issue is the osDefaultInheritEnv initialization.

Notably even before CL 522318, changing the initialization from:

var osDefaultInheritEnv = func() []string { ... }()

to

var osDefaultInheritEnv []string

func init() { osDefaultInheritEnv = func() []string { ... }() }

causes the same linker failure.

Alternatively, changing the initialization to:

var osDefaultInheritEnv = getOSDefaultInheritEnv()

func getOSDefaultInheritEnv() []string { ... }

avoids the issue.

I think there's something weird about when closures are inlined into an init function. An effect of CL 522318 was basically to treat all package-scope initialization statements as though they were in an init statement, which is why the behavior is now the same as moving the assignment into an explicit func init() { ... } declaration.

@cuonglm Do you think this could be related to the IsDeadcodeClosure logic in inline/inl.go?

@gopherbot
Copy link

Change https://go.dev/cl/522935 mentions this issue: net/http/cgi: workaround for closure inlining issue

@cuonglm
Copy link
Member

cuonglm commented Aug 25, 2023

@cuonglm Do you think this could be related to the IsDeadcodeClosure logic in inline/inl.go?

It's very likely the culprit. Probably we need to visit typecheck.Target.Inits, too?

@mdempsky
Copy link
Member Author

Probably we need to visit typecheck.Target.Inits, too?

I don't think so. The functions in Target.Inits are in Target.Funcs too. Target.Inits is only necessary so pkginit.MakeTask can list them all in the inittask. Otherwise, they should just be normal functions.

(Clearly there's some way that they're not behaving just like normal functions though.)

@cuonglm
Copy link
Member

cuonglm commented Aug 25, 2023

Probably we need to visit typecheck.Target.Inits, too?

I don't think so. The functions in Target.Inits are in Target.Funcs too. Target.Inits is only necessary so pkginit.MakeTask can list them all in the inittask. Otherwise, they should just be normal functions.

(Clearly there's some way that they're not behaving just like normal functions though.)

Hmm, that's right. Have my laptop now, will take a look.

@cuonglm
Copy link
Member

cuonglm commented Aug 25, 2023

@mdempsky So the problem is that after https://go-review.googlesource.com/c/go/+/492016, we need to mark hidden closures produced by inlining as un-hidden, but we're only marking closure which is converted to global during static init (That's why we see this behavior after CL 522318).

Seems that we need to mark any closures as un-hidden why processing init function?

@gopherbot
Copy link

Change https://go.dev/cl/522956 mentions this issue: cmd/compile: un-hide closure func in init function

@dmitshur dmitshur added this to the Go1.22 milestone Aug 25, 2023
@bcmills bcmills added the compiler/runtime Issues related to the Go compiler and/or runtime. label Aug 25, 2023
gopherbot pushed a commit that referenced this issue Aug 25, 2023
This is a temporary workaround for issue #62277, to get the longtest
builders passing again. As mentioned on the issue, the underlying
issue was present even before CL 522318; it just now affects inlined
closures in initialization expressions too, not just explicit init
functions.

This CL can and should be reverted once that issue is fixed properly.

Change-Id: I612a501e131d1b5eea648aafeb1a3a3fe8fe8c83
Reviewed-on: https://go-review.googlesource.com/c/go/+/522935
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
@gopherbot
Copy link

Change https://go.dev/cl/523038 mentions this issue: Revert "net/http/cgi: workaround for closure inlining issue"

@gopherbot
Copy link

Change https://go.dev/cl/523037 mentions this issue: cmd/compile: retire "IsHiddenClosure" and "IsDeadcodeClosure"

@bcmills bcmills removed the Soon This needs to be done soon. (regressions, serious bugs, outages) label Aug 25, 2023
@gopherbot
Copy link

Change https://go.dev/cl/523175 mentions this issue: Revert "net/http/cgi: workaround for closure inlining issue"

gopherbot pushed a commit that referenced this issue Aug 26, 2023
This reverts CL 522935.

Issue #62277 is fixed, the workaround can be dropped.

Updates #62277

Change-Id: I7c69e35248942b4d4fcdd81121051cca9b098980
Reviewed-on: https://go-review.googlesource.com/c/go/+/523175
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants