-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/link: go 1.16 plugin does not initialize global variables correctly when not used directly #44956
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
Comments
The code you attached doesn't include package "base". Could you include that? Thanks. |
Sorry, my mistake using zip on unix O_o |
Thanks. I can reproduce the problem. I think I understand the cause now. Will work on a fix. |
Thanks. I already have a simple workaround, I just declare the global variable var Containers map[string]*Container // without assignation and I assign it into the init() function. func init() { Works like a charm.
|
@gopherbot please backport this to Go 1.16. This is a mis-compilation bug in Go 1.16. Thanks. |
Change https://golang.org/cl/301793 mentions this issue: |
Backport issue(s) opened: #45030 (for 1.16). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases. |
Change https://golang.org/cl/302449 mentions this issue: |
…table static tmps Static tmps are private to a package, but with plugins a package can be shared among multiple DSOs. They need to have a consistent view of the static tmps, especially for writable ones. So export them. (Read-only static tmps have the same values anyway, so it doesn't matter. Also Mach-O doesn't support dynamically exporting read-only symbols anyway.) Updates #44956. Fixes #45030. Change-Id: I921e25b7ab73cd5d5347800eccdb7931e3448779 Reviewed-on: https://go-review.googlesource.com/c/go/+/301793 Trust: Cherry Zhang <[email protected]> Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Than McIntosh <[email protected]> (cherry picked from commit de012bc095359e1b552d4ea6fb6b2995f3ab04f5) Reviewed-on: https://go-review.googlesource.com/c/go/+/302449
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
It actually appeared with the latest issue, was not happening in older versions ( <= 1.15)
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have build 2 plugins, using the same import module
The import module file set up a &map[string]*struct{} as a global variable, set by Containers = &map[string]*Container{}
Container can be any random struct
It exists another global variable Others = 123
The first plugin, just make a print of global variable 'Others' without addressing Containers from the import module
The second plugin uses the Containers global variable.
Strangely on this scheme, the second plugin gets a *map[string]*Container as NIL instead of a pointer to the structure.
When the Containers variable is used from the first plugin, anything works correctly and all the global variables are correctly set.
This error appreats in Go 1.16, was not happening in any previous version (tested to work correctly on 1.15 and 1.14)
What did you expect to see?
A correct implementation of the *map[string]*struct , pointing an existing map instead of a NIL of the map
What did you see instead?
a pointer to the NIL of the map instead of the map
I join the gzip of the 6 files environment
On GO 1.15.8:
[root@mexico test]# ./start.sh
213
START PLUG 2: &base.ContainersList{} 0x7fe6cb390b80 0xc000094210
Works correctly, the *Containers contains the pointer to the map
On GO 1.16.1:
[root@mexico test]# ./start.sh
213
START PLUG 2: &base.ContainersList(nil) 0x7f02a2329ca0 0x0
You will note the 0x0 as the NIL pointer of the *base.Containers contents. which is not initialized correctly
Code to reproduce the error:
test.zip
The text was updated successfully, but these errors were encountered: