@@ -81,7 +81,7 @@ func (s *Schedule) tryStaticInit(nn ir.Node) bool {
81
81
func (s * Schedule ) staticcopy (l * ir.Name , loff int64 , rn * ir.Name , typ * types.Type ) bool {
82
82
if rn .Class == ir .PFUNC {
83
83
// TODO if roff != 0 { panic }
84
- staticdata .InitFunc (l , loff , rn )
84
+ staticdata .InitAddr (l , loff , staticdata . FuncLinksym ( rn ) )
85
85
return true
86
86
}
87
87
if rn .Class != ir .PEXTERN || rn .Sym ().Pkg != types .LocalPkg {
@@ -138,9 +138,8 @@ func (s *Schedule) staticcopy(l *ir.Name, loff int64, rn *ir.Name, typ *types.Ty
138
138
139
139
case ir .OADDR :
140
140
r := r .(* ir.AddrExpr )
141
- if a := r .X ; a .Op () == ir .ONAME {
142
- a := a .(* ir.Name )
143
- staticdata .InitAddr (l , loff , a , 0 )
141
+ if a , ok := r .X .(* ir.Name ); ok && a .Op () == ir .ONAME {
142
+ staticdata .InitAddr (l , loff , staticdata .GlobalLinksym (a ))
144
143
return true
145
144
}
146
145
@@ -149,14 +148,14 @@ func (s *Schedule) staticcopy(l *ir.Name, loff int64, rn *ir.Name, typ *types.Ty
149
148
switch r .X .Op () {
150
149
case ir .OARRAYLIT , ir .OSLICELIT , ir .OSTRUCTLIT , ir .OMAPLIT :
151
150
// copy pointer
152
- staticdata .InitAddr (l , loff , s .Temps [r ], 0 )
151
+ staticdata .InitAddr (l , loff , staticdata . GlobalLinksym ( s .Temps [r ]) )
153
152
return true
154
153
}
155
154
156
155
case ir .OSLICELIT :
157
156
r := r .(* ir.CompLitExpr )
158
157
// copy slice
159
- staticdata .InitSlice (l , loff , s .Temps [r ], r .Len )
158
+ staticdata .InitSlice (l , loff , staticdata . GlobalLinksym ( s .Temps [r ]) , r .Len )
160
159
return true
161
160
162
161
case ir .OARRAYLIT , ir .OSTRUCTLIT :
@@ -235,8 +234,8 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
235
234
236
235
case ir .OADDR :
237
236
r := r .(* ir.AddrExpr )
238
- if name , offset , ok := StaticLoc (r .X ); ok {
239
- staticdata .InitAddr (l , loff , name , offset )
237
+ if name , offset , ok := StaticLoc (r .X ); ok && name . Class == ir . PEXTERN {
238
+ staticdata .InitAddrOffset (l , loff , name . Linksym () , offset )
240
239
return true
241
240
}
242
241
fallthrough
@@ -249,7 +248,7 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
249
248
a := StaticName (r .X .Type ())
250
249
251
250
s .Temps [r ] = a
252
- staticdata .InitAddr (l , loff , a , 0 )
251
+ staticdata .InitAddr (l , loff , a . Linksym () )
253
252
254
253
// Init underlying literal.
255
254
assign (base .Pos , a , 0 , r .X )
@@ -273,7 +272,7 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
273
272
ta .SetNoalg (true )
274
273
a := StaticName (ta )
275
274
s .Temps [r ] = a
276
- staticdata .InitSlice (l , loff , a , r .Len )
275
+ staticdata .InitSlice (l , loff , a . Linksym () , r .Len )
277
276
// Fall through to init underlying array.
278
277
l = a
279
278
loff = 0
@@ -308,7 +307,7 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
308
307
// Closures with no captured variables are globals,
309
308
// so the assignment can be done at link time.
310
309
// TODO if roff != 0 { panic }
311
- staticdata .InitFunc (l , loff , r .Func .Nname )
310
+ staticdata .InitAddr (l , loff , staticdata . FuncLinksym ( r .Func .Nname ) )
312
311
return true
313
312
}
314
313
ir .ClosureDebugRuntimeCheck (r )
@@ -345,7 +344,7 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
345
344
// Create a copy of l to modify while we emit data.
346
345
347
346
// Emit itab, advance offset.
348
- staticdata .InitAddr (l , loff , itab .X .(* ir.Name ), 0 )
347
+ staticdata .InitAddr (l , loff , itab .X .(* ir.Name ). Linksym () )
349
348
350
349
// Emit data.
351
350
if types .IsDirectIface (val .Type ()) {
@@ -361,7 +360,7 @@ func (s *Schedule) StaticAssign(l *ir.Name, loff int64, r ir.Node, typ *types.Ty
361
360
a := StaticName (val .Type ())
362
361
s .Temps [val ] = a
363
362
assign (base .Pos , a , 0 , val )
364
- staticdata .InitAddr (l , loff + int64 (types .PtrSize ), a , 0 )
363
+ staticdata .InitAddr (l , loff + int64 (types .PtrSize ), a . Linksym () )
365
364
}
366
365
367
366
return true
0 commit comments