-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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/gc: address &x.f is not resolved at link time #9355
Comments
I don't understand how other code can see y as nil. That sounds like a bug in the init dependency ordering. |
The problem only happens in runtime where runtime.init is delayed. |
In any case, it is worth fixing regardless. No need to compute this address at runtime when it is easily done at link time. |
Sure. https://gist.github.com/minux/69994348b4f06b1c324b If you like the approach, I can finish target-specific code for We also need a test, which is harder (other than perhaps verifying |
I have a competing CL to fix this bug. It's a bit more general, and it has a shiny test. |
When we do y = &x for global variables x and y, y gets initialized at link time. Do the same for y = &x.f if x is a struct and y=&x[5] if x is an array. fixes #9217 fixes #9355 Change-Id: Iea3c0ce2ce1b309e2b760e345608fd95460b5713 Reviewed-on: https://go-review.googlesource.com/1691 Reviewed-by: Minux Ma <[email protected]>
If you do
var y=&x
Then global y points to global x, and that reference is computed at link time.
If you do (where f is a field of x)
var y = &x.f
This reference is not computed at link time. Instead, it is set up dynamically by init(). This means that other code during init can see y as nil.
See #9354 for why this matters.
The text was updated successfully, but these errors were encountered: