{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/28969","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/28969/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/28969/comments","events_url":"https://api.github.com/repos/golang/go/issues/28969/events","html_url":"https://github.com/golang/go/issues/28969","id":384889716,"node_id":"MDU6SXNzdWUzODQ4ODk3MTY=","number":28969,"title":"cmd/compile: initialization optimization fails when using -ldflags=-X=VAL","user":{"login":"tjamet","id":6061440,"node_id":"MDQ6VXNlcjYwNjE0NDA=","avatar_url":"https://avatars1.githubusercontent.com/u/6061440?v=4","gravatar_id":"","url":"https://api.github.com/users/tjamet","html_url":"https://github.com/tjamet","followers_url":"https://api.github.com/users/tjamet/followers","following_url":"https://api.github.com/users/tjamet/following{/other_user}","gists_url":"https://api.github.com/users/tjamet/gists{/gist_id}","starred_url":"https://api.github.com/users/tjamet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tjamet/subscriptions","organizations_url":"https://api.github.com/users/tjamet/orgs","repos_url":"https://api.github.com/users/tjamet/repos","events_url":"https://api.github.com/users/tjamet/events{/privacy}","received_events_url":"https://api.github.com/users/tjamet/received_events","type":"User","site_admin":false},"labels":[{"id":373399998,"node_id":"MDU6TGFiZWwzNzMzOTk5OTg=","url":"https://api.github.com/repos/golang/go/labels/NeedsFix","name":"NeedsFix","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/83","html_url":"https://github.com/golang/go/milestone/83","labels_url":"https://api.github.com/repos/golang/go/milestones/83/labels","id":3730798,"node_id":"MDk6TWlsZXN0b25lMzczMDc5OA==","number":83,"title":"Go1.13","description":null,"creator":{"login":"rsc","id":104030,"node_id":"MDQ6VXNlcjEwNDAzMA==","avatar_url":"https://avatars1.githubusercontent.com/u/104030?v=4","gravatar_id":"","url":"https://api.github.com/users/rsc","html_url":"https://github.com/rsc","followers_url":"https://api.github.com/users/rsc/followers","following_url":"https://api.github.com/users/rsc/following{/other_user}","gists_url":"https://api.github.com/users/rsc/gists{/gist_id}","starred_url":"https://api.github.com/users/rsc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsc/subscriptions","organizations_url":"https://api.github.com/users/rsc/orgs","repos_url":"https://api.github.com/users/rsc/repos","events_url":"https://api.github.com/users/rsc/events{/privacy}","received_events_url":"https://api.github.com/users/rsc/received_events","type":"User","site_admin":false},"open_issues":179,"closed_issues":12,"state":"open","created_at":"2018-10-11T15:30:19Z","updated_at":"2018-11-28T08:25:48Z","due_on":null,"closed_at":null},"comments":7,"created_at":"2018-11-27T16:51:02Z","updated_at":"2018-11-28T08:34:17Z","closed_at":null,"author_association":"NONE","body":"<!-- Please answer these questions before submitting your issue. Thanks! -->\r\n\r\n### What version of Go are you using (`go version`)?\r\n\r\n<pre>\r\n$ go version\r\ngo version go1.11.1 darwin/amd64\r\n</pre>\r\n\r\n### Does this issue reproduce with the latest release?\r\nyes, tested with `go version go1.11.2 darwin/amd64`\r\n\r\n\r\n### What operating system and processor architecture are you using (`go env`)?\r\n\r\n<details><summary><code>go env</code> Output</summary><br><pre>\r\n$ go env\r\nGOARCH=\"amd64\"\r\nGOBIN=\"\"\r\nGOCACHE=\"/Users/thibault.jamet/Library/Caches/go-build\"\r\nGOEXE=\"\"\r\nGOFLAGS=\"\"\r\nGOHOSTARCH=\"amd64\"\r\nGOHOSTOS=\"darwin\"\r\nGOOS=\"darwin\"\r\nGOPATH=\"/Users/thibault.jamet/dev/\"\r\nGOPROXY=\"\"\r\nGORACE=\"\"\r\nGOROOT=\"/usr/local/go\"\r\nGOTMPDIR=\"\"\r\nGOTOOLDIR=\"/usr/local/go/pkg/tool/darwin_amd64\"\r\nGCCGO=\"gccgo\"\r\nCC=\"clang\"\r\nCXX=\"clang++\"\r\nCGO_ENABLED=\"1\"\r\nGOMOD=\"\"\r\nCGO_CFLAGS=\"-g -O2\"\r\nCGO_CPPFLAGS=\"\"\r\nCGO_CXXFLAGS=\"-g -O2\"\r\nCGO_FFLAGS=\"-g -O2\"\r\nCGO_LDFLAGS=\"-g -O2\"\r\nPKG_CONFIG=\"pkg-config\"\r\nGOGCCFLAGS=\"-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/z3/r2mc8fw12vb83952716284n00000gq/T/go-build606665018=/tmp/go-build -gno-record-gcc-switches -fno-common\"\r\n</pre></details>\r\n\r\n### What did you do?\r\n\r\n<!--\r\nIf possible, provide a recipe for reproducing the error.\r\nA complete runnable program is good.\r\nA link on play.golang.org is best.\r\n-->\r\nI narrowed down the problem to a simple go program:\r\n```package main\r\n\r\nimport \"fmt\"\r\n\r\nvar version = \"dev\"\r\nvar versions = struct {\r\n    API  string\r\n    Code string\r\n}{\"0.1.0\", version}\r\n\r\nfunc main() {\r\n    fmt.Println(version)\r\n    fmt.Println(versions)\r\n}\r\n```\r\nThen build it using the specific flag described in the [toolchain tricks](https://github.com/golang/go/wiki/GcToolchainTricks#including-build-information-in-the-executable), `go build -o test -ldflags \"-X main.version=1.0.0\" .`\r\n\r\n\r\n### What did you expect to see?\r\nWhen running `./test` I would expect to get an output of \r\n```\r\n1.0.0\r\n{0.1.0 1.0.0}\r\n```\r\n\r\n### What did you see instead?\r\nAn output of\r\n```\r\n1.0.0\r\n{0.1.0 dev}\r\n```\r\n\r\nI suspect this is related to when `main.version` is evaluated, using ldflags makes the version resolved at link time, where the compiler may have already inlined its use and thus remove the reference used by the linker"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/442362914","html_url":"https://github.com/golang/go/issues/28969#issuecomment-442362914","issue_url":"https://api.github.com/repos/golang/go/issues/28969","id":442362914,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MjM2MjkxNA==","user":{"login":"tjamet","id":6061440,"node_id":"MDQ6VXNlcjYwNjE0NDA=","avatar_url":"https://avatars1.githubusercontent.com/u/6061440?v=4","gravatar_id":"","url":"https://api.github.com/users/tjamet","html_url":"https://github.com/tjamet","followers_url":"https://api.github.com/users/tjamet/followers","following_url":"https://api.github.com/users/tjamet/following{/other_user}","gists_url":"https://api.github.com/users/tjamet/gists{/gist_id}","starred_url":"https://api.github.com/users/tjamet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tjamet/subscriptions","organizations_url":"https://api.github.com/users/tjamet/orgs","repos_url":"https://api.github.com/users/tjamet/repos","events_url":"https://api.github.com/users/tjamet/events{/privacy}","received_events_url":"https://api.github.com/users/tjamet/received_events","type":"User","site_admin":false},"created_at":"2018-11-28T08:34:17Z","updated_at":"2018-11-28T08:34:17Z","author_association":"NONE","body":"I see, would another option be to provide a compile option to disable `cmd/compile/internal/gc/sinit.go:sstaticcopy` and document the limitation with the work around?"}}
{"actor":{"display_login":"tjamet"}}