{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/7599","labels_url":"https://api.github.com/repos/golang/go/issues/7599/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/7599/comments","events_url":"https://api.github.com/repos/golang/go/issues/7599/events","html_url":"https://github.com/golang/go/issues/7599","id":51286943,"number":7599,"title":"cmd/gc: do more static initialization at compile time rather than runtime","user":{"login":"josharian","id":67496,"avatar_url":"https://avatars.githubusercontent.com/u/67496?v=3","gravatar_id":"","url":"https://api.github.com/users/josharian","html_url":"https://github.com/josharian","followers_url":"https://api.github.com/users/josharian/followers","following_url":"https://api.github.com/users/josharian/following{/other_user}","gists_url":"https://api.github.com/users/josharian/gists{/gist_id}","starred_url":"https://api.github.com/users/josharian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josharian/subscriptions","organizations_url":"https://api.github.com/users/josharian/orgs","repos_url":"https://api.github.com/users/josharian/repos","events_url":"https://api.github.com/users/josharian/events{/privacy}","received_events_url":"https://api.github.com/users/josharian/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/1","html_url":"https://github.com/golang/go/milestones/Go1.5","labels_url":"https://api.github.com/repos/golang/go/milestones/1/labels","id":905105,"number":1,"title":"Go1.5","description":"","creator":{"login":"bradfitz","id":2621,"avatar_url":"https://avatars.githubusercontent.com/u/2621?v=3","gravatar_id":"","url":"https://api.github.com/users/bradfitz","html_url":"https://github.com/bradfitz","followers_url":"https://api.github.com/users/bradfitz/followers","following_url":"https://api.github.com/users/bradfitz/following{/other_user}","gists_url":"https://api.github.com/users/bradfitz/gists{/gist_id}","starred_url":"https://api.github.com/users/bradfitz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradfitz/subscriptions","organizations_url":"https://api.github.com/users/bradfitz/orgs","repos_url":"https://api.github.com/users/bradfitz/repos","events_url":"https://api.github.com/users/bradfitz/events{/privacy}","received_events_url":"https://api.github.com/users/bradfitz/received_events","type":"User","site_admin":false},"open_issues":290,"closed_issues":521,"state":"open","created_at":"2014-12-16T02:26:41Z","updated_at":"2015-05-21T21:41:58Z","due_on":"2015-07-31T04:00:00Z","closed_at":null},"comments":4,"created_at":"2014-03-20T19:37:46Z","updated_at":"2015-05-21T23:56:22Z","closed_at":null,"body":"<pre>Staticly initialized global variables are given bss symbols that are populated using\nautogenerated init code. However, in most cases (maps are the only exception I can think\nof), these variables could be given pre-populated symbols instead, using linker-resolved\ndata.\n\nThis would save space -- populated data symbols are smaller than the code generated to\npopulate them. This would also save run time -- no need to populate the bss symbols on\neach program startup.\n\nAt the least, there should be a few special cases added for common, simple cases like\ncreating a slice.\n\nExample using tip:\n\n\n$ cat sinit.go\n\npackage main\n\nvar (\n\ta = [...]uint16{0, 1, 2, 3}\n\ts = a[:]\n)\n\nfunc main() {\n\t_ = s\n}\n\n\n$ go tool 6g -S sinit.go\n\n&quot;&quot;.main t=1 size=16 value=0 args=0 locals=0\n\t000000 00000 (i.go:8)\tTEXT\t&quot;&quot;.main+0(SB),4,$0-0\n\t000000 00000 (i.go:8)\tNOP\t,\n\t000000 00000 (i.go:8)\tNOP\t,\n\t000000 00000 (i.go:8)\tFUNCDATA\t$2,&quot;&quot;.gcargs·0+0(SB)\n\t000000 00000 (i.go:8)\tFUNCDATA\t$3,&quot;&quot;.gclocals·1+0(SB)\n\t000000 00000 (i.go:10)\tRET\t,\n\t000000 c3                                               .\n&quot;&quot;.init t=1 size=144 value=0 args=0 locals=0x10\n\t000000 00000 (i.go:10)\tTEXT\t&quot;&quot;.init+0(SB),$16-0\n\t000000 00000 (i.go:10)\tMOVQ\t2208(GS),CX\n\t0x0009 00009 (i.go:10)\tCMPQ\tSP,(CX)\n\t0x000c 00012 (i.go:10)\tJHI\t,21\n\t0x000e 00014 (i.go:10)\tCALL\t,runtime.morestack00_noctxt(SB)\n\t0x0013 00019 (i.go:10)\tJMP\t,0\n\t0x0015 00021 (i.go:10)\tSUBQ\t$16,SP\n\t0x0019 00025 (i.go:10)\tMOVQ\t$0,8(SP)\n\t0x0022 00034 (i.go:10)\tMOVBQZX\t&quot;&quot;.initdone·+0(SB),AX\n\t0x002b 00043 (i.go:10)\tFUNCDATA\t$2,&quot;&quot;.gcargs·2+0(SB)\n\t0x002b 00043 (i.go:10)\tFUNCDATA\t$3,&quot;&quot;.gclocals·3+0(SB)\n\t0x002b 00043 (i.go:10)\tCMPB\tAL,$0\n\t0x002d 00045 (i.go:10)\tJEQ\t,63\n\t0x002f 00047 (i.go:10)\tCMPB\tAL,$2\n\t0x0031 00049 (i.go:10)\tJNE\t,56\n\t0x0033 00051 (i.go:10)\tADDQ\t$16,SP\n\t0x0037 00055 (i.go:10)\tRET\t,\n\t0x0038 00056 (i.go:10)\tPCDATA\t$0,$0\n\t0x0038 00056 (i.go:10)\tPCDATA\t$1,$1\n\t0x0038 00056 (i.go:10)\tCALL\t,runtime.throwinit(SB)\n\t0x003d 00061 (i.go:10)\tUNDEF\t,\n\t0x003f 00063 (i.go:10)\tMOVB\t$1,&quot;&quot;.initdone·+0(SB)\n\t0x0047 00071 (i.go:5)\tLEAQ\t&quot;&quot;.a+0(SB),BX\n\t0x004f 00079 (i.go:5)\tMOVQ\tBX,&quot;&quot;.autotmp_0000+8(SP)\n\t0x0054 00084 (i.go:5)\tMOVQ\t&quot;&quot;.autotmp_0000+8(SP),BX\n\t0x0059 00089 (i.go:5)\tCMPQ\tBX,$0\n\t0x005d 00093 (i.go:5)\tJEQ\t$1,140\n\t0x005f 00095 (i.go:5)\tMOVQ\tBX,&quot;&quot;.s+0(SB)\n\t0x0067 00103 (i.go:5)\tMOVQ\t$4,&quot;&quot;.s+8(SB)\n\t0x0073 00115 (i.go:5)\tMOVQ\t$4,&quot;&quot;.s+16(SB)\n\t0x007f 00127 (i.go:10)\tMOVB\t$2,&quot;&quot;.initdone·+0(SB)\n\t0x0087 00135 (i.go:10)\tADDQ\t$16,SP\n\t0x008b 00139 (i.go:10)\tRET\t,\n\t0x008c 00140 (i.go:5)\tMOVL\tAX,(BX)\n\t0x008e 00142 (i.go:5)\tJMP\t,95\n\t000000 65 48 8b 0c 25 a0 08 00 00 48 3b 21 77 07 e8 00  eH..%....H;!w...\n\t0x0010 00 00 00 eb eb 48 83 ec 10 48 c7 44 24 08 00 00  .....H...H.D$...\n\t0x0020 00 00 48 0f b6 04 25 00 00 00 00 3c 00 74 10 3c  ..H...%....&lt;.t.&lt;\n\t0x0030 02 75 05 48 83 c4 10 c3 e8 00 00 00 00 0f 0b c6  .u.H............\n\t0x0040 04 25 00 00 00 00 01 48 8d 1c 25 00 00 00 00 48  .%.....H..%....H\n\t0x0050 89 5c 24 08 48 8b 5c 24 08 48 83 fb 00 74 2d 48  .\\$.H.\\$.H...t-H\n\t0x0060 89 1c 25 00 00 00 00 48 c7 04 25 00 00 00 00 04  ..%....H..%.....\n\t0x0070 00 00 00 48 c7 04 25 00 00 00 00 04 00 00 00 c6  ...H..%.........\n\t0x0080 04 25 00 00 00 00 02 48 83 c4 10 c3 89 03 eb cf  .%.....H........\n\trel 15+4 t=247 runtime.morestack00_noctxt+0\n\trel 39+4 t=120 &quot;&quot;.initdone·+0\n\trel 57+4 t=247 runtime.throwinit+0\n\trel 66+4 t=120 &quot;&quot;.initdone·+0\n\trel 75+4 t=120 &quot;&quot;.a+0\n\trel 99+4 t=120 &quot;&quot;.s+0\n\trel 107+4 t=120 &quot;&quot;.s+8\n\trel 119+4 t=120 &quot;&quot;.s+16\n\trel 130+4 t=120 &quot;&quot;.initdone·+0\n&quot;&quot;.gclocals·1 t=7 size=8 value=0\n\t000000 01 00 00 00 00 00 00 00                          ........\n&quot;&quot;.gcargs·0 t=7 size=8 value=0\n\t000000 01 00 00 00 00 00 00 00                          ........\n&quot;&quot;.gclocals·3 t=7 size=20 value=0\n\t000000 02 00 00 00 02 00 00 00 00 00 00 00 02 00 00 00  ................\n\t0x0010 00 00 00 00                                      ....\n&quot;&quot;.gcargs·2 t=7 size=12 value=0\n\t000000 02 00 00 00 00 00 00 00 00 00 00 00              ............\n&quot;&quot;.a t=22 size=8 value=0\n\t000000 00 00 01 00 02 00 03 00                          ........\n&quot;&quot;.s t=21 size=24 value=0\n&quot;&quot;.initdone· t=22 size=1 value=0\n&quot;&quot;.main·f t=7 dupok size=8 value=0\n\t000000 00 00 00 00 00 00 00 00                          ........\n\trel 0+8 t=120 &quot;&quot;.main+0\n&quot;&quot;.init·f t=7 dupok size=8 value=0\n\t000000 00 00 00 00 00 00 00 00                          ........\n\trel 0+8 t=120 &quot;&quot;.init+0\nruntime.throwinit·f t=7 dupok size=8 value=0\n\t000000 00 00 00 00 00 00 00 00                          ........\n\trel 0+8 t=120 runtime.throwinit+0\ntype..gc.uint16 t=7 dupok size=16 value=0\n\t000000 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................\ntype..gc.[]uint16 t=7 dupok size=40 value=0\n\t000000 18 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00  ................\n\t0x0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................\n\t0x0020 00 00 00 00 00 00 00 00                          ........\n\trel 24+8 t=120 type..gc.uint16+0\ngo.string.&quot;[]uint16&quot; t=7 dupok size=32 value=0\n\t000000 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00  ................\n\t0x0010 5b 5d 75 69 6e 74 31 36 00                       []uint16.\n\trel 0+8 t=120 go.string.&quot;[]uint16&quot;+16\ntype.[]uint16 t=7 dupok size=72 value=0\n\t000000 18 00 00 00 00 00 00 00 e7 8e e3 20 00 08 08 17  ........... ....\n\t0x0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................\n\t0x0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................\n\t0x0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................\n\t0x0040 00 00 00 00 00 00 00 00                          ........\n\trel 16+8 t=120 runtime.algarray+544\n\trel 24+8 t=120 type..gc.[]uint16+0\n\trel 32+8 t=120 go.string.&quot;[]uint16&quot;+0\n\trel 48+8 t=120 go.weak.type.*[]uint16+0\n\trel 56+8 t=120 runtime.zerovalue+0\n\trel 64+8 t=120 type.uint16+0\ngo.typelink.[]uint16/[]uint16 t=7 dupok size=8 value=0\n\t000000 00 00 00 00 00 00 00 00                          ........\n\trel 0+8 t=120 type.[]uint16+0\ntype..gc.[4]uint16 t=7 dupok size=16 value=0\n\t000000 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................\ngo.string.&quot;[4]uint16&quot; t=7 dupok size=32 value=0\n\t000000 00 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00  ................\n\t0x0010 5b 34 5d 75 69 6e 74 31 36 00                    [4]uint16.\n\trel 0+8 t=120 go.string.&quot;[4]uint16&quot;+16\ntype.[4]uint16 t=7 dupok size=88 value=0\n\t000000 08 00 00 00 00 00 00 00 3f 77 35 8e 00 02 02 91  ........?w5.....\n\t0x0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................\n\t0x0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................\n\t0x0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................\n\t0x0040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................\n\t0x0050 04 00 00 00 00 00 00 00                          ........\n\trel 16+8 t=120 runtime.algarray+160\n\trel 24+8 t=120 type..gc.[4]uint16+0\n\trel 32+8 t=120 go.string.&quot;[4]uint16&quot;+0\n\trel 48+8 t=120 go.weak.type.*[4]uint16+0\n\trel 56+8 t=120 runtime.zerovalue+0\n\trel 64+8 t=120 type.uint16+0\n\trel 72+8 t=120 type.[]uint16+0\ngo.typelink.[4]uint16/[4]uint16 t=7 dupok size=8 value=0\n\t000000 00 00 00 00 00 00 00 00                          ........\n\trel 0+8 t=120 type.[4]uint16+0\ntype..gc.*[4]uint16 t=7 dupok size=32 value=0\n\t000000 08 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00  ................\n\t0x0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................\ngo.string.&quot;*[4]uint16&quot; t=7 dupok size=32 value=0\n\t000000 00 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00  ................\n\t0x0010 2a 5b 34 5d 75 69 6e 74 31 36 00                 *[4]uint16.\n\trel 0+8 t=120 go.string.&quot;*[4]uint16&quot;+16\ntype.*[4]uint16 t=7 dupok size=72 value=0\n\t000000 08 00 00 00 00 00 00 00 42 a7 e4 3c 00 08 08 16  ........B..&lt;....\n\t0x0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................\n\t0x0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................\n\t0x0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................\n\t0x0040 00 00 00 00 00 00 00 00                          ........\n\trel 16+8 t=120 runtime.algarray+160\n\trel 24+8 t=120 type..gc.*[4]uint16+0\n\trel 32+8 t=120 go.string.&quot;*[4]uint16&quot;+0\n\trel 48+8 t=120 go.weak.type.**[4]uint16+0\n\trel 56+8 t=120 runtime.zerovalue+0\n\trel 64+8 t=120 type.[4]uint16+0\ngo.string.&quot;runtime&quot; t=7 dupok size=24 value=0\n\t000000 00 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00  ................\n\t0x0010 72 75 6e 74 69 6d 65 00                          runtime.\n\trel 0+8 t=120 go.string.&quot;runtime&quot;+16\ngo.importpath.runtime. t=7 dupok size=16 value=0\n\t000000 00 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00  ................\n\trel 0+8 t=120 go.string.&quot;runtime&quot;+16\nruntime.zerovalue t=7 dupok size=0 value=0\n\n\nIn this case, the 144 byte &quot;&quot;.init is used to populate the 24 byte s to read\n&lt;&amp;a, 4, 4&gt;.</pre>"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/104453067","html_url":"https://github.com/golang/go/issues/7599#issuecomment-104453067","issue_url":"https://api.github.com/repos/golang/go/issues/7599","id":104453067,"user":{"login":"josharian","id":67496,"avatar_url":"https://avatars.githubusercontent.com/u/67496?v=3","gravatar_id":"","url":"https://api.github.com/users/josharian","html_url":"https://github.com/josharian","followers_url":"https://api.github.com/users/josharian/followers","following_url":"https://api.github.com/users/josharian/following{/other_user}","gists_url":"https://api.github.com/users/josharian/gists{/gist_id}","starred_url":"https://api.github.com/users/josharian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josharian/subscriptions","organizations_url":"https://api.github.com/users/josharian/orgs","repos_url":"https://api.github.com/users/josharian/repos","events_url":"https://api.github.com/users/josharian/events{/privacy}","received_events_url":"https://api.github.com/users/josharian/received_events","type":"User","site_admin":false},"created_at":"2015-05-21T23:56:22Z","updated_at":"2015-05-21T23:56:22Z","body":"I started on this but given the extent of the changes, I'd prefer to rewrite sinit.go to be idiomatic first, to make it easier to work with. That puts this out of scope for 1.5. Moving to 1.6; holler if you disagree."}}