2015-02-13 14:40:36 -05:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package gc
|
|
|
|
|
|
|
|
|
|
import (
|
2016-10-03 12:26:25 -07:00
|
|
|
"cmd/compile/internal/ssa"
|
2017-03-06 07:32:37 -08:00
|
|
|
"cmd/internal/dwarf"
|
2015-02-13 14:40:36 -05:00
|
|
|
"cmd/internal/obj"
|
2016-12-06 17:08:06 -08:00
|
|
|
"cmd/internal/src"
|
2016-04-06 12:01:40 -07:00
|
|
|
"cmd/internal/sys"
|
2015-02-13 14:40:36 -05:00
|
|
|
"fmt"
|
2016-02-25 10:35:19 -08:00
|
|
|
"sort"
|
2015-02-13 14:40:36 -05:00
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// "Portable" code generation.
|
|
|
|
|
|
2016-03-19 18:17:58 -07:00
|
|
|
var makefuncdatasym_nsym int
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-19 18:17:58 -07:00
|
|
|
func makefuncdatasym(nameprefix string, funcdatakind int64) *Sym {
|
2016-09-15 15:45:10 +10:00
|
|
|
sym := lookupN(nameprefix, makefuncdatasym_nsym)
|
2015-02-13 14:40:36 -05:00
|
|
|
makefuncdatasym_nsym++
|
2015-02-23 16:07:24 -05:00
|
|
|
pnod := newname(sym)
|
2015-02-13 14:40:36 -05:00
|
|
|
pnod.Class = PEXTERN
|
2016-09-29 16:22:43 -07:00
|
|
|
p := Gins(obj.AFUNCDATA, nil, pnod)
|
|
|
|
|
Addrconst(&p.From, funcdatakind)
|
2015-02-13 14:40:36 -05:00
|
|
|
return sym
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// gvardef inserts a VARDEF for n into the instruction stream.
|
|
|
|
|
// VARDEF is an annotation for the liveness analysis, marking a place
|
|
|
|
|
// where a complete initialization (definition) of a variable begins.
|
|
|
|
|
// Since the liveness analysis can see initialization of single-word
|
|
|
|
|
// variables quite easy, gvardef is usually only called for multi-word
|
|
|
|
|
// or 'fat' variables, those satisfying isfat(n->type).
|
|
|
|
|
// However, gvardef is also called when a non-fat variable is initialized
|
|
|
|
|
// via a block move; the only time this happens is when you have
|
|
|
|
|
// return f()
|
|
|
|
|
// for a function with multiple return values exactly matching the return
|
|
|
|
|
// types of the current function.
|
|
|
|
|
//
|
|
|
|
|
// A 'VARDEF x' annotation in the instruction stream tells the liveness
|
|
|
|
|
// analysis to behave as though the variable x is being initialized at that
|
|
|
|
|
// point in the instruction stream. The VARDEF must appear before the
|
|
|
|
|
// actual (multi-instruction) initialization, and it must also appear after
|
|
|
|
|
// any uses of the previous value, if any. For example, if compiling:
|
|
|
|
|
//
|
|
|
|
|
// x = x[1:]
|
|
|
|
|
//
|
|
|
|
|
// it is important to generate code like:
|
|
|
|
|
//
|
|
|
|
|
// base, len, cap = pieces of x[1:]
|
|
|
|
|
// VARDEF x
|
|
|
|
|
// x = {base, len, cap}
|
|
|
|
|
//
|
|
|
|
|
// If instead the generated code looked like:
|
|
|
|
|
//
|
|
|
|
|
// VARDEF x
|
|
|
|
|
// base, len, cap = pieces of x[1:]
|
|
|
|
|
// x = {base, len, cap}
|
|
|
|
|
//
|
|
|
|
|
// then the liveness analysis would decide the previous value of x was
|
|
|
|
|
// unnecessary even though it is about to be used by the x[1:] computation.
|
|
|
|
|
// Similarly, if the generated code looked like:
|
|
|
|
|
//
|
|
|
|
|
// base, len, cap = pieces of x[1:]
|
|
|
|
|
// x = {base, len, cap}
|
|
|
|
|
// VARDEF x
|
|
|
|
|
//
|
|
|
|
|
// then the liveness analysis will not preserve the new value of x, because
|
|
|
|
|
// the VARDEF appears to have "overwritten" it.
|
|
|
|
|
//
|
|
|
|
|
// VARDEF is a bit of a kludge to work around the fact that the instruction
|
|
|
|
|
// stream is working on single-word values but the liveness analysis
|
|
|
|
|
// wants to work on individual variables, which might be multi-word
|
|
|
|
|
// aggregates. It might make sense at some point to look into letting
|
|
|
|
|
// the liveness analysis work on single-word values as well, although
|
|
|
|
|
// there are complications around interface values, slices, and strings,
|
|
|
|
|
// all of which cannot be treated as individual words.
|
|
|
|
|
//
|
|
|
|
|
// VARKILL is the opposite of VARDEF: it marks a value as no longer needed,
|
|
|
|
|
// even if its address has been taken. That is, a VARKILL annotation asserts
|
|
|
|
|
// that its argument is certainly dead, for use when the liveness analysis
|
|
|
|
|
// would not otherwise be able to deduce that fact.
|
|
|
|
|
|
2016-03-07 18:00:08 -08:00
|
|
|
func gvardefx(n *Node, as obj.As) {
|
2015-02-13 14:40:36 -05:00
|
|
|
if n == nil {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("gvardef nil")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if n.Op != ONAME {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("gvardef %#v; %v", n.Op, n)
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch n.Class {
|
2015-04-01 09:38:44 -07:00
|
|
|
case PAUTO, PPARAM, PPARAMOUT:
|
2017-02-27 19:56:38 +02:00
|
|
|
if !n.Used() {
|
2016-10-03 12:26:25 -07:00
|
|
|
Prog(obj.ANOP)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: recognize Syscall-like functions for liveness analysis
Consider this code:
func f(*int)
func g() {
p := new(int)
f(p)
}
where f is an assembly function.
In general liveness analysis assumes that during the call to f, p is dead
in this frame. If f has retained p, p will be found alive in f's frame and keep
the new(int) from being garbage collected. This is all correct and works.
We use the Go func declaration for f to give the assembly function
liveness information (the arguments are assumed live for the entire call).
Now consider this code:
func h1() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
}
Here syscall.Syscall is taking the place of f, but because its arguments
are uintptr, the liveness analysis and the garbage collector ignore them.
Since p is no longer live in h once the call starts, if the garbage collector
scans the stack while the system call is blocked, it will find no reference
to the new(int) and reclaim it. If the kernel is going to write to *p once
the call finishes, reclaiming the memory is a mistake.
We can't change the arguments or the liveness information for
syscall.Syscall itself, both for compatibility and because sometimes the
arguments really are integers, and the garbage collector will get quite upset
if it finds an integer where it expects a pointer. The problem is that
these arguments are fundamentally untyped.
The solution we have taken in the syscall package's wrappers in past
releases is to insert a call to a dummy function named "use", to make
it look like the argument is live during the call to syscall.Syscall:
func h2() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
use(unsafe.Pointer(p))
}
Keeping p alive during the call means that if the garbage collector
scans the stack during the system call now, it will find the reference to p.
Unfortunately, this approach is not available to users outside syscall,
because 'use' is unexported, and people also have to realize they need
to use it and do so. There is much existing code using syscall.Syscall
without a 'use'-like function. That code will fail very occasionally in
mysterious ways (see #13372).
This CL fixes all that existing code by making the compiler do the right
thing automatically, without any code modifications. That is, it takes h1
above, which is incorrect code today, and makes it correct code.
Specifically, if the compiler sees a foreign func definition (one
without a body) that has uintptr arguments, it marks those arguments
as "unsafe uintptrs". If it later sees the function being called
with uintptr(unsafe.Pointer(x)) as an argument, it arranges to mark x
as having escaped, and it makes sure to hold x in a live temporary
variable until the call returns, so that the garbage collector cannot
reclaim whatever heap memory x points to.
For now I am leaving the explicit calls to use in package syscall,
but they can be removed early in a future cycle (likely Go 1.7).
The rule has no effect on escape analysis, only on liveness analysis.
Fixes #13372.
Change-Id: I2addb83f70d08db08c64d394f9d06ff0a063c500
Reviewed-on: https://go-review.googlesource.com/18584
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-01-13 00:46:28 -05:00
|
|
|
if as == obj.AVARLIVE {
|
2016-09-15 08:07:54 -07:00
|
|
|
Gins(as, n, nil)
|
cmd/compile: recognize Syscall-like functions for liveness analysis
Consider this code:
func f(*int)
func g() {
p := new(int)
f(p)
}
where f is an assembly function.
In general liveness analysis assumes that during the call to f, p is dead
in this frame. If f has retained p, p will be found alive in f's frame and keep
the new(int) from being garbage collected. This is all correct and works.
We use the Go func declaration for f to give the assembly function
liveness information (the arguments are assumed live for the entire call).
Now consider this code:
func h1() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
}
Here syscall.Syscall is taking the place of f, but because its arguments
are uintptr, the liveness analysis and the garbage collector ignore them.
Since p is no longer live in h once the call starts, if the garbage collector
scans the stack while the system call is blocked, it will find no reference
to the new(int) and reclaim it. If the kernel is going to write to *p once
the call finishes, reclaiming the memory is a mistake.
We can't change the arguments or the liveness information for
syscall.Syscall itself, both for compatibility and because sometimes the
arguments really are integers, and the garbage collector will get quite upset
if it finds an integer where it expects a pointer. The problem is that
these arguments are fundamentally untyped.
The solution we have taken in the syscall package's wrappers in past
releases is to insert a call to a dummy function named "use", to make
it look like the argument is live during the call to syscall.Syscall:
func h2() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
use(unsafe.Pointer(p))
}
Keeping p alive during the call means that if the garbage collector
scans the stack during the system call now, it will find the reference to p.
Unfortunately, this approach is not available to users outside syscall,
because 'use' is unexported, and people also have to realize they need
to use it and do so. There is much existing code using syscall.Syscall
without a 'use'-like function. That code will fail very occasionally in
mysterious ways (see #13372).
This CL fixes all that existing code by making the compiler do the right
thing automatically, without any code modifications. That is, it takes h1
above, which is incorrect code today, and makes it correct code.
Specifically, if the compiler sees a foreign func definition (one
without a body) that has uintptr arguments, it marks those arguments
as "unsafe uintptrs". If it later sees the function being called
with uintptr(unsafe.Pointer(x)) as an argument, it arranges to mark x
as having escaped, and it makes sure to hold x in a live temporary
variable until the call returns, so that the garbage collector cannot
reclaim whatever heap memory x points to.
For now I am leaving the explicit calls to use in package syscall,
but they can be removed early in a future cycle (likely Go 1.7).
The rule has no effect on escape analysis, only on liveness analysis.
Fixes #13372.
Change-Id: I2addb83f70d08db08c64d394f9d06ff0a063c500
Reviewed-on: https://go-review.googlesource.com/18584
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-01-13 00:46:28 -05:00
|
|
|
} else {
|
2016-09-15 08:07:54 -07:00
|
|
|
Gins(as, nil, n)
|
cmd/compile: recognize Syscall-like functions for liveness analysis
Consider this code:
func f(*int)
func g() {
p := new(int)
f(p)
}
where f is an assembly function.
In general liveness analysis assumes that during the call to f, p is dead
in this frame. If f has retained p, p will be found alive in f's frame and keep
the new(int) from being garbage collected. This is all correct and works.
We use the Go func declaration for f to give the assembly function
liveness information (the arguments are assumed live for the entire call).
Now consider this code:
func h1() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
}
Here syscall.Syscall is taking the place of f, but because its arguments
are uintptr, the liveness analysis and the garbage collector ignore them.
Since p is no longer live in h once the call starts, if the garbage collector
scans the stack while the system call is blocked, it will find no reference
to the new(int) and reclaim it. If the kernel is going to write to *p once
the call finishes, reclaiming the memory is a mistake.
We can't change the arguments or the liveness information for
syscall.Syscall itself, both for compatibility and because sometimes the
arguments really are integers, and the garbage collector will get quite upset
if it finds an integer where it expects a pointer. The problem is that
these arguments are fundamentally untyped.
The solution we have taken in the syscall package's wrappers in past
releases is to insert a call to a dummy function named "use", to make
it look like the argument is live during the call to syscall.Syscall:
func h2() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
use(unsafe.Pointer(p))
}
Keeping p alive during the call means that if the garbage collector
scans the stack during the system call now, it will find the reference to p.
Unfortunately, this approach is not available to users outside syscall,
because 'use' is unexported, and people also have to realize they need
to use it and do so. There is much existing code using syscall.Syscall
without a 'use'-like function. That code will fail very occasionally in
mysterious ways (see #13372).
This CL fixes all that existing code by making the compiler do the right
thing automatically, without any code modifications. That is, it takes h1
above, which is incorrect code today, and makes it correct code.
Specifically, if the compiler sees a foreign func definition (one
without a body) that has uintptr arguments, it marks those arguments
as "unsafe uintptrs". If it later sees the function being called
with uintptr(unsafe.Pointer(x)) as an argument, it arranges to mark x
as having escaped, and it makes sure to hold x in a live temporary
variable until the call returns, so that the garbage collector cannot
reclaim whatever heap memory x points to.
For now I am leaving the explicit calls to use in package syscall,
but they can be removed early in a future cycle (likely Go 1.7).
The rule has no effect on escape analysis, only on liveness analysis.
Fixes #13372.
Change-Id: I2addb83f70d08db08c64d394f9d06ff0a063c500
Reviewed-on: https://go-review.googlesource.com/18584
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-01-13 00:46:28 -05:00
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Gvardef(n *Node) {
|
|
|
|
|
gvardefx(n, obj.AVARDEF)
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-12 14:07:40 -08:00
|
|
|
func Gvarkill(n *Node) {
|
2015-02-13 14:40:36 -05:00
|
|
|
gvardefx(n, obj.AVARKILL)
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-12 14:07:40 -08:00
|
|
|
func Gvarlive(n *Node) {
|
cmd/compile: recognize Syscall-like functions for liveness analysis
Consider this code:
func f(*int)
func g() {
p := new(int)
f(p)
}
where f is an assembly function.
In general liveness analysis assumes that during the call to f, p is dead
in this frame. If f has retained p, p will be found alive in f's frame and keep
the new(int) from being garbage collected. This is all correct and works.
We use the Go func declaration for f to give the assembly function
liveness information (the arguments are assumed live for the entire call).
Now consider this code:
func h1() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
}
Here syscall.Syscall is taking the place of f, but because its arguments
are uintptr, the liveness analysis and the garbage collector ignore them.
Since p is no longer live in h once the call starts, if the garbage collector
scans the stack while the system call is blocked, it will find no reference
to the new(int) and reclaim it. If the kernel is going to write to *p once
the call finishes, reclaiming the memory is a mistake.
We can't change the arguments or the liveness information for
syscall.Syscall itself, both for compatibility and because sometimes the
arguments really are integers, and the garbage collector will get quite upset
if it finds an integer where it expects a pointer. The problem is that
these arguments are fundamentally untyped.
The solution we have taken in the syscall package's wrappers in past
releases is to insert a call to a dummy function named "use", to make
it look like the argument is live during the call to syscall.Syscall:
func h2() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
use(unsafe.Pointer(p))
}
Keeping p alive during the call means that if the garbage collector
scans the stack during the system call now, it will find the reference to p.
Unfortunately, this approach is not available to users outside syscall,
because 'use' is unexported, and people also have to realize they need
to use it and do so. There is much existing code using syscall.Syscall
without a 'use'-like function. That code will fail very occasionally in
mysterious ways (see #13372).
This CL fixes all that existing code by making the compiler do the right
thing automatically, without any code modifications. That is, it takes h1
above, which is incorrect code today, and makes it correct code.
Specifically, if the compiler sees a foreign func definition (one
without a body) that has uintptr arguments, it marks those arguments
as "unsafe uintptrs". If it later sees the function being called
with uintptr(unsafe.Pointer(x)) as an argument, it arranges to mark x
as having escaped, and it makes sure to hold x in a live temporary
variable until the call returns, so that the garbage collector cannot
reclaim whatever heap memory x points to.
For now I am leaving the explicit calls to use in package syscall,
but they can be removed early in a future cycle (likely Go 1.7).
The rule has no effect on escape analysis, only on liveness analysis.
Fixes #13372.
Change-Id: I2addb83f70d08db08c64d394f9d06ff0a063c500
Reviewed-on: https://go-review.googlesource.com/18584
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-01-13 00:46:28 -05:00
|
|
|
gvardefx(n, obj.AVARLIVE)
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
func removevardef(firstp *obj.Prog) {
|
2015-02-23 16:07:24 -05:00
|
|
|
for p := firstp; p != nil; p = p.Link {
|
cmd/compile: recognize Syscall-like functions for liveness analysis
Consider this code:
func f(*int)
func g() {
p := new(int)
f(p)
}
where f is an assembly function.
In general liveness analysis assumes that during the call to f, p is dead
in this frame. If f has retained p, p will be found alive in f's frame and keep
the new(int) from being garbage collected. This is all correct and works.
We use the Go func declaration for f to give the assembly function
liveness information (the arguments are assumed live for the entire call).
Now consider this code:
func h1() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
}
Here syscall.Syscall is taking the place of f, but because its arguments
are uintptr, the liveness analysis and the garbage collector ignore them.
Since p is no longer live in h once the call starts, if the garbage collector
scans the stack while the system call is blocked, it will find no reference
to the new(int) and reclaim it. If the kernel is going to write to *p once
the call finishes, reclaiming the memory is a mistake.
We can't change the arguments or the liveness information for
syscall.Syscall itself, both for compatibility and because sometimes the
arguments really are integers, and the garbage collector will get quite upset
if it finds an integer where it expects a pointer. The problem is that
these arguments are fundamentally untyped.
The solution we have taken in the syscall package's wrappers in past
releases is to insert a call to a dummy function named "use", to make
it look like the argument is live during the call to syscall.Syscall:
func h2() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
use(unsafe.Pointer(p))
}
Keeping p alive during the call means that if the garbage collector
scans the stack during the system call now, it will find the reference to p.
Unfortunately, this approach is not available to users outside syscall,
because 'use' is unexported, and people also have to realize they need
to use it and do so. There is much existing code using syscall.Syscall
without a 'use'-like function. That code will fail very occasionally in
mysterious ways (see #13372).
This CL fixes all that existing code by making the compiler do the right
thing automatically, without any code modifications. That is, it takes h1
above, which is incorrect code today, and makes it correct code.
Specifically, if the compiler sees a foreign func definition (one
without a body) that has uintptr arguments, it marks those arguments
as "unsafe uintptrs". If it later sees the function being called
with uintptr(unsafe.Pointer(x)) as an argument, it arranges to mark x
as having escaped, and it makes sure to hold x in a live temporary
variable until the call returns, so that the garbage collector cannot
reclaim whatever heap memory x points to.
For now I am leaving the explicit calls to use in package syscall,
but they can be removed early in a future cycle (likely Go 1.7).
The rule has no effect on escape analysis, only on liveness analysis.
Fixes #13372.
Change-Id: I2addb83f70d08db08c64d394f9d06ff0a063c500
Reviewed-on: https://go-review.googlesource.com/18584
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-01-13 00:46:28 -05:00
|
|
|
for p.Link != nil && (p.Link.As == obj.AVARDEF || p.Link.As == obj.AVARKILL || p.Link.As == obj.AVARLIVE) {
|
2015-02-13 14:40:36 -05:00
|
|
|
p.Link = p.Link.Link
|
|
|
|
|
}
|
|
|
|
|
if p.To.Type == obj.TYPE_BRANCH {
|
cmd/compile: recognize Syscall-like functions for liveness analysis
Consider this code:
func f(*int)
func g() {
p := new(int)
f(p)
}
where f is an assembly function.
In general liveness analysis assumes that during the call to f, p is dead
in this frame. If f has retained p, p will be found alive in f's frame and keep
the new(int) from being garbage collected. This is all correct and works.
We use the Go func declaration for f to give the assembly function
liveness information (the arguments are assumed live for the entire call).
Now consider this code:
func h1() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
}
Here syscall.Syscall is taking the place of f, but because its arguments
are uintptr, the liveness analysis and the garbage collector ignore them.
Since p is no longer live in h once the call starts, if the garbage collector
scans the stack while the system call is blocked, it will find no reference
to the new(int) and reclaim it. If the kernel is going to write to *p once
the call finishes, reclaiming the memory is a mistake.
We can't change the arguments or the liveness information for
syscall.Syscall itself, both for compatibility and because sometimes the
arguments really are integers, and the garbage collector will get quite upset
if it finds an integer where it expects a pointer. The problem is that
these arguments are fundamentally untyped.
The solution we have taken in the syscall package's wrappers in past
releases is to insert a call to a dummy function named "use", to make
it look like the argument is live during the call to syscall.Syscall:
func h2() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
use(unsafe.Pointer(p))
}
Keeping p alive during the call means that if the garbage collector
scans the stack during the system call now, it will find the reference to p.
Unfortunately, this approach is not available to users outside syscall,
because 'use' is unexported, and people also have to realize they need
to use it and do so. There is much existing code using syscall.Syscall
without a 'use'-like function. That code will fail very occasionally in
mysterious ways (see #13372).
This CL fixes all that existing code by making the compiler do the right
thing automatically, without any code modifications. That is, it takes h1
above, which is incorrect code today, and makes it correct code.
Specifically, if the compiler sees a foreign func definition (one
without a body) that has uintptr arguments, it marks those arguments
as "unsafe uintptrs". If it later sees the function being called
with uintptr(unsafe.Pointer(x)) as an argument, it arranges to mark x
as having escaped, and it makes sure to hold x in a live temporary
variable until the call returns, so that the garbage collector cannot
reclaim whatever heap memory x points to.
For now I am leaving the explicit calls to use in package syscall,
but they can be removed early in a future cycle (likely Go 1.7).
The rule has no effect on escape analysis, only on liveness analysis.
Fixes #13372.
Change-Id: I2addb83f70d08db08c64d394f9d06ff0a063c500
Reviewed-on: https://go-review.googlesource.com/18584
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-01-13 00:46:28 -05:00
|
|
|
for p.To.Val.(*obj.Prog) != nil && (p.To.Val.(*obj.Prog).As == obj.AVARDEF || p.To.Val.(*obj.Prog).As == obj.AVARKILL || p.To.Val.(*obj.Prog).As == obj.AVARLIVE) {
|
2015-03-16 15:54:44 -04:00
|
|
|
p.To.Val = p.To.Val.(*obj.Prog).Link
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func emitptrargsmap() {
|
2015-11-04 15:54:41 -05:00
|
|
|
if Curfn.Func.Nname.Sym.Name == "_" {
|
|
|
|
|
return
|
|
|
|
|
}
|
2016-09-15 15:45:10 +10:00
|
|
|
sym := lookup(fmt.Sprintf("%s.args_stackmap", Curfn.Func.Nname.Sym.Name))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-28 14:31:57 -07:00
|
|
|
nptr := int(Curfn.Type.ArgWidth() / int64(Widthptr))
|
2015-02-23 16:07:24 -05:00
|
|
|
bv := bvalloc(int32(nptr) * 2)
|
|
|
|
|
nbitmap := 1
|
2016-03-17 01:47:16 -07:00
|
|
|
if Curfn.Type.Results().NumFields() > 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
nbitmap = 2
|
|
|
|
|
}
|
2015-02-23 16:07:24 -05:00
|
|
|
off := duint32(sym, 0, uint32(nbitmap))
|
2015-02-13 14:40:36 -05:00
|
|
|
off = duint32(sym, off, uint32(bv.n))
|
2015-02-23 16:07:24 -05:00
|
|
|
var xoffset int64
|
2016-09-11 14:43:37 -07:00
|
|
|
if Curfn.IsMethod() {
|
2015-02-13 14:40:36 -05:00
|
|
|
xoffset = 0
|
2016-03-09 20:54:59 -08:00
|
|
|
onebitwalktype1(Curfn.Type.Recvs(), &xoffset, bv)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-17 01:47:16 -07:00
|
|
|
if Curfn.Type.Params().NumFields() > 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
xoffset = 0
|
2016-03-08 16:31:28 -08:00
|
|
|
onebitwalktype1(Curfn.Type.Params(), &xoffset, bv)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-10-11 10:23:14 -07:00
|
|
|
off = dbvec(sym, off, bv)
|
2016-03-17 01:47:16 -07:00
|
|
|
if Curfn.Type.Results().NumFields() > 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
xoffset = 0
|
2016-03-08 16:31:28 -08:00
|
|
|
onebitwalktype1(Curfn.Type.Results(), &xoffset, bv)
|
2016-10-11 10:23:14 -07:00
|
|
|
off = dbvec(sym, off, bv)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-04-18 08:14:08 +12:00
|
|
|
ggloblsym(sym, int32(off), obj.RODATA|obj.LOCAL)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-09-15 21:43:53 +02:00
|
|
|
// cmpstackvarlt reports whether the stack variable a sorts before b.
|
2015-09-19 23:55:27 +02:00
|
|
|
//
|
2015-02-13 14:40:36 -05:00
|
|
|
// Sort the list of stack variables. Autos after anything else,
|
|
|
|
|
// within autos, unused after used, within used, things with
|
|
|
|
|
// pointers first, zeroed things first, and then decreasing size.
|
|
|
|
|
// Because autos are laid out in decreasing addresses
|
|
|
|
|
// on the stack, pointers first, zeroed things first and decreasing size
|
|
|
|
|
// really means, in memory, things with pointers needing zeroing at
|
|
|
|
|
// the top of the stack and increasing in size.
|
|
|
|
|
// Non-autos sort on offset.
|
2015-09-19 23:55:27 +02:00
|
|
|
func cmpstackvarlt(a, b *Node) bool {
|
2016-02-20 21:36:12 -08:00
|
|
|
if (a.Class == PAUTO) != (b.Class == PAUTO) {
|
|
|
|
|
return b.Class == PAUTO
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if a.Class != PAUTO {
|
2016-02-20 21:36:12 -08:00
|
|
|
return a.Xoffset < b.Xoffset
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2017-02-27 19:56:38 +02:00
|
|
|
if a.Used() != b.Used() {
|
|
|
|
|
return a.Used()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-09-19 23:55:27 +02:00
|
|
|
ap := haspointers(a.Type)
|
|
|
|
|
bp := haspointers(b.Type)
|
2015-02-13 14:40:36 -05:00
|
|
|
if ap != bp {
|
2015-09-19 23:55:27 +02:00
|
|
|
return ap
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2017-02-27 19:56:38 +02:00
|
|
|
ap = a.Name.Needzero()
|
|
|
|
|
bp = b.Name.Needzero()
|
2015-02-13 14:40:36 -05:00
|
|
|
if ap != bp {
|
2015-09-19 23:55:27 +02:00
|
|
|
return ap
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-02-20 21:36:12 -08:00
|
|
|
if a.Type.Width != b.Type.Width {
|
|
|
|
|
return a.Type.Width > b.Type.Width
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-09-19 23:55:27 +02:00
|
|
|
return a.Sym.Name < b.Sym.Name
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-02-25 10:35:19 -08:00
|
|
|
// byStackvar implements sort.Interface for []*Node using cmpstackvarlt.
|
|
|
|
|
type byStackVar []*Node
|
|
|
|
|
|
|
|
|
|
func (s byStackVar) Len() int { return len(s) }
|
|
|
|
|
func (s byStackVar) Less(i, j int) bool { return cmpstackvarlt(s[i], s[j]) }
|
|
|
|
|
func (s byStackVar) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
|
|
|
|
|
2016-10-03 12:26:25 -07:00
|
|
|
var scratchFpMem *Node
|
|
|
|
|
|
|
|
|
|
func (s *ssaExport) AllocFrame(f *ssa.Func) {
|
2015-02-13 14:40:36 -05:00
|
|
|
Stksize = 0
|
|
|
|
|
stkptrsize = 0
|
|
|
|
|
|
|
|
|
|
// Mark the PAUTO's unused.
|
2016-02-25 10:35:19 -08:00
|
|
|
for _, ln := range Curfn.Func.Dcl {
|
|
|
|
|
if ln.Class == PAUTO {
|
2017-02-27 19:56:38 +02:00
|
|
|
ln.SetUsed(false)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-03 12:26:25 -07:00
|
|
|
for _, l := range f.RegAlloc {
|
|
|
|
|
if ls, ok := l.(ssa.LocalSlot); ok {
|
2017-02-27 19:56:38 +02:00
|
|
|
ls.N.(*Node).SetUsed(true)
|
2016-10-03 12:26:25 -07:00
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-10-03 12:26:25 -07:00
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-10-03 12:26:25 -07:00
|
|
|
scratchUsed := false
|
|
|
|
|
for _, b := range f.Blocks {
|
|
|
|
|
for _, v := range b.Values {
|
|
|
|
|
switch a := v.Aux.(type) {
|
|
|
|
|
case *ssa.ArgSymbol:
|
2017-02-27 19:56:38 +02:00
|
|
|
a.Node.(*Node).SetUsed(true)
|
2016-10-03 12:26:25 -07:00
|
|
|
case *ssa.AutoSymbol:
|
2017-02-27 19:56:38 +02:00
|
|
|
a.Node.(*Node).SetUsed(true)
|
2016-10-03 12:26:25 -07:00
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-10-04 13:00:21 -07:00
|
|
|
if !scratchUsed {
|
|
|
|
|
scratchUsed = v.Op.UsesScratch()
|
2016-10-03 12:26:25 -07:00
|
|
|
}
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-10-03 12:26:25 -07:00
|
|
|
if f.Config.NeedsFpScratch {
|
|
|
|
|
scratchFpMem = temp(Types[TUINT64])
|
2017-02-27 19:56:38 +02:00
|
|
|
scratchFpMem.SetUsed(scratchUsed)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-10-03 12:26:25 -07:00
|
|
|
sort.Sort(byStackVar(Curfn.Func.Dcl))
|
|
|
|
|
|
|
|
|
|
// Reassign stack offsets of the locals that are used.
|
|
|
|
|
for i, n := range Curfn.Func.Dcl {
|
|
|
|
|
if n.Op != ONAME || n.Class != PAUTO {
|
2015-02-13 14:40:36 -05:00
|
|
|
continue
|
|
|
|
|
}
|
2017-02-27 19:56:38 +02:00
|
|
|
if !n.Used() {
|
2016-10-03 12:26:25 -07:00
|
|
|
Curfn.Func.Dcl = Curfn.Func.Dcl[:i]
|
|
|
|
|
break
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
dowidth(n.Type)
|
2016-10-03 12:26:25 -07:00
|
|
|
w := n.Type.Width
|
2015-02-13 14:40:36 -05:00
|
|
|
if w >= Thearch.MAXWIDTH || w < 0 {
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("bad width")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
Stksize += w
|
|
|
|
|
Stksize = Rnd(Stksize, int64(n.Type.Align))
|
|
|
|
|
if haspointers(n.Type) {
|
|
|
|
|
stkptrsize = Stksize
|
|
|
|
|
}
|
2016-10-18 23:50:40 +02:00
|
|
|
if Thearch.LinkArch.InFamily(sys.MIPS, sys.MIPS64, sys.ARM, sys.ARM64, sys.PPC64, sys.S390X) {
|
2015-02-13 14:40:36 -05:00
|
|
|
Stksize = Rnd(Stksize, int64(Widthptr))
|
|
|
|
|
}
|
|
|
|
|
if Stksize >= 1<<31 {
|
|
|
|
|
setlineno(Curfn)
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("stack frame too large (>2GB)")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-09-29 19:09:36 -07:00
|
|
|
n.Xoffset = -Stksize
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Stksize = Rnd(Stksize, int64(Widthreg))
|
|
|
|
|
stkptrsize = Rnd(stkptrsize, int64(Widthreg))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func compile(fn *Node) {
|
|
|
|
|
if Newproc == nil {
|
2017-02-06 14:46:48 -08:00
|
|
|
Newproc = Sysfunc("newproc")
|
|
|
|
|
Deferproc = Sysfunc("deferproc")
|
|
|
|
|
Deferreturn = Sysfunc("deferreturn")
|
|
|
|
|
Duffcopy = Sysfunc("duffcopy")
|
|
|
|
|
Duffzero = Sysfunc("duffzero")
|
|
|
|
|
panicindex = Sysfunc("panicindex")
|
|
|
|
|
panicslice = Sysfunc("panicslice")
|
|
|
|
|
panicdivide = Sysfunc("panicdivide")
|
|
|
|
|
growslice = Sysfunc("growslice")
|
2017-01-03 16:15:38 -08:00
|
|
|
panicdottypeE = Sysfunc("panicdottypeE")
|
|
|
|
|
panicdottypeI = Sysfunc("panicdottypeI")
|
2017-02-06 14:46:48 -08:00
|
|
|
panicnildottype = Sysfunc("panicnildottype")
|
|
|
|
|
assertE2I = Sysfunc("assertE2I")
|
|
|
|
|
assertE2I2 = Sysfunc("assertE2I2")
|
|
|
|
|
assertI2I = Sysfunc("assertI2I")
|
|
|
|
|
assertI2I2 = Sysfunc("assertI2I2")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-12-15 17:17:01 -08:00
|
|
|
defer func(lno src.XPos) {
|
2016-03-07 22:05:49 -08:00
|
|
|
lineno = lno
|
|
|
|
|
}(setlineno(fn))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
Curfn = fn
|
|
|
|
|
dowidth(Curfn.Type)
|
|
|
|
|
|
2016-04-24 13:50:26 -07:00
|
|
|
if fn.Nbody.Len() == 0 {
|
2016-04-13 18:37:18 -07:00
|
|
|
if pure_go || strings.HasPrefix(fn.Func.Nname.Sym.Name, "init.") {
|
2016-09-15 15:45:10 +10:00
|
|
|
yyerror("missing function body for %q", fn.Func.Nname.Sym.Name)
|
2016-03-07 22:05:49 -08:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emitptrargsmap()
|
2016-03-07 22:05:49 -08:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveerrors()
|
|
|
|
|
|
|
|
|
|
order(Curfn)
|
|
|
|
|
if nerrors != 0 {
|
2016-03-07 22:05:49 -08:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-09-07 22:19:30 +02:00
|
|
|
hasdefer = false
|
2015-02-13 14:40:36 -05:00
|
|
|
walk(Curfn)
|
|
|
|
|
if nerrors != 0 {
|
2016-03-07 22:05:49 -08:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-10-20 10:00:07 -07:00
|
|
|
if instrumenting {
|
|
|
|
|
instrument(Curfn)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if nerrors != 0 {
|
2016-03-07 22:05:49 -08:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-06-12 11:01:13 -07:00
|
|
|
// Build an SSA backend function.
|
2016-09-14 10:01:05 -07:00
|
|
|
ssafn := buildssa(Curfn)
|
|
|
|
|
if nerrors != 0 {
|
|
|
|
|
return
|
2015-10-19 11:36:07 -04:00
|
|
|
}
|
2015-04-15 15:51:25 -07:00
|
|
|
|
2017-02-17 16:52:16 -05:00
|
|
|
plist := new(obj.Plist)
|
|
|
|
|
pc = Ctxt.NewProg()
|
|
|
|
|
Clearp(pc)
|
|
|
|
|
plist.Firstpc = pc
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
setlineno(Curfn)
|
|
|
|
|
|
2016-03-07 22:05:49 -08:00
|
|
|
nam := Curfn.Func.Nname
|
2015-02-13 14:40:36 -05:00
|
|
|
if isblank(nam) {
|
|
|
|
|
nam = nil
|
|
|
|
|
}
|
2016-09-29 16:22:43 -07:00
|
|
|
ptxt := Gins(obj.ATEXT, nam, nil)
|
2017-03-03 14:27:24 -08:00
|
|
|
fnsym := ptxt.From.Sym
|
|
|
|
|
|
2015-05-27 15:01:44 -04:00
|
|
|
ptxt.From3 = new(obj.Addr)
|
2017-02-27 19:56:38 +02:00
|
|
|
if fn.Func.Dupok() {
|
2015-02-13 14:40:36 -05:00
|
|
|
ptxt.From3.Offset |= obj.DUPOK
|
|
|
|
|
}
|
2017-02-27 19:56:38 +02:00
|
|
|
if fn.Func.Wrapper() {
|
2015-02-13 14:40:36 -05:00
|
|
|
ptxt.From3.Offset |= obj.WRAPPER
|
|
|
|
|
}
|
2017-02-27 19:56:38 +02:00
|
|
|
if fn.Func.NoFramePointer() {
|
2016-11-30 16:15:32 -08:00
|
|
|
ptxt.From3.Offset |= obj.NOFRAME
|
|
|
|
|
}
|
2017-02-27 19:56:38 +02:00
|
|
|
if fn.Func.Needctxt() {
|
2015-02-13 14:40:36 -05:00
|
|
|
ptxt.From3.Offset |= obj.NEEDCTXT
|
|
|
|
|
}
|
2016-02-26 13:32:28 -08:00
|
|
|
if fn.Func.Pragma&Nosplit != 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
ptxt.From3.Offset |= obj.NOSPLIT
|
|
|
|
|
}
|
2017-02-27 19:56:38 +02:00
|
|
|
if fn.Func.ReflectMethod() {
|
2016-03-10 16:15:26 -05:00
|
|
|
ptxt.From3.Offset |= obj.REFLECTMETHOD
|
|
|
|
|
}
|
2016-02-26 13:32:28 -08:00
|
|
|
if fn.Func.Pragma&Systemstack != 0 {
|
2016-10-24 23:15:41 +03:00
|
|
|
ptxt.From.Sym.Set(obj.AttrCFunc, true)
|
2017-02-09 17:08:27 -05:00
|
|
|
if fn.Func.Pragma&Nosplit != 0 {
|
|
|
|
|
yyerror("go:nosplit and go:systemstack cannot be combined")
|
|
|
|
|
}
|
2015-06-07 21:45:39 -04:00
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// Clumsy but important.
|
|
|
|
|
// See test/recover.go for test cases and src/reflect/value.go
|
|
|
|
|
// for the actual functions being considered.
|
2016-03-07 22:05:49 -08:00
|
|
|
if myimportpath == "reflect" {
|
2015-05-27 10:42:55 -04:00
|
|
|
if Curfn.Func.Nname.Sym.Name == "callReflect" || Curfn.Func.Nname.Sym.Name == "callMethod" {
|
2015-02-13 14:40:36 -05:00
|
|
|
ptxt.From3.Offset |= obj.WRAPPER
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-19 18:17:58 -07:00
|
|
|
gcargs := makefuncdatasym("gcargs·", obj.FUNCDATA_ArgsPointerMaps)
|
|
|
|
|
gclocals := makefuncdatasym("gclocals·", obj.FUNCDATA_LocalsPointerMaps)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2017-02-06 17:06:02 -08:00
|
|
|
genssa(ssafn, ptxt, gcargs, gclocals)
|
|
|
|
|
ssafn.Free()
|
2017-03-03 14:27:24 -08:00
|
|
|
|
2017-02-17 16:52:16 -05:00
|
|
|
obj.Flushplist(Ctxt, plist) // convert from Prog list to machine code
|
2017-03-03 14:27:24 -08:00
|
|
|
ptxt = nil // nil to prevent misuse; Prog may have been freed by Flushplist
|
|
|
|
|
|
|
|
|
|
fieldtrack(fnsym, fn.Func.FieldTrack)
|
2017-02-06 17:06:02 -08:00
|
|
|
}
|
|
|
|
|
|
2017-03-06 07:32:37 -08:00
|
|
|
func debuginfo(fnsym *obj.LSym) []*dwarf.Var {
|
|
|
|
|
if expect := Linksym(Curfn.Func.Nname.Sym); fnsym != expect {
|
|
|
|
|
Fatalf("unexpected fnsym: %v != %v", fnsym, expect)
|
2017-03-03 16:45:21 -08:00
|
|
|
}
|
|
|
|
|
|
2017-03-06 07:32:37 -08:00
|
|
|
var vars []*dwarf.Var
|
|
|
|
|
for _, n := range Curfn.Func.Dcl {
|
2015-02-13 14:40:36 -05:00
|
|
|
if n.Op != ONAME { // might be OTYPE or OLITERAL
|
|
|
|
|
continue
|
|
|
|
|
}
|
2017-02-06 17:06:02 -08:00
|
|
|
|
2017-02-13 13:34:30 -08:00
|
|
|
var name obj.AddrName
|
2017-03-06 07:32:37 -08:00
|
|
|
var abbrev int
|
|
|
|
|
offs := n.Xoffset
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
switch n.Class {
|
2016-10-03 12:26:25 -07:00
|
|
|
case PAUTO:
|
2017-02-27 19:56:38 +02:00
|
|
|
if !n.Used() {
|
2016-10-03 12:26:25 -07:00
|
|
|
continue
|
|
|
|
|
}
|
2017-02-06 17:06:02 -08:00
|
|
|
name = obj.NAME_AUTO
|
2017-03-06 07:32:37 -08:00
|
|
|
|
|
|
|
|
abbrev = dwarf.DW_ABRV_AUTO
|
|
|
|
|
if Ctxt.FixedFrameSize() == 0 {
|
|
|
|
|
offs -= int64(Widthptr)
|
|
|
|
|
}
|
|
|
|
|
if obj.Framepointer_enabled(obj.GOOS, obj.GOARCH) {
|
|
|
|
|
offs -= int64(Widthptr)
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-03 12:26:25 -07:00
|
|
|
case PPARAM, PPARAMOUT:
|
2017-02-06 17:06:02 -08:00
|
|
|
name = obj.NAME_PARAM
|
2017-03-06 07:32:37 -08:00
|
|
|
|
|
|
|
|
abbrev = dwarf.DW_ABRV_PARAM
|
|
|
|
|
offs += Ctxt.FixedFrameSize()
|
|
|
|
|
|
2017-02-06 17:06:02 -08:00
|
|
|
default:
|
|
|
|
|
continue
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2017-03-06 07:32:37 -08:00
|
|
|
gotype := Linksym(ngotype(n))
|
|
|
|
|
fnsym.Autom = append(fnsym.Autom, &obj.Auto{
|
2017-02-06 17:06:02 -08:00
|
|
|
Asym: obj.Linklookup(Ctxt, n.Sym.Name, 0),
|
|
|
|
|
Aoffset: int32(n.Xoffset),
|
|
|
|
|
Name: name,
|
2017-03-06 07:32:37 -08:00
|
|
|
Gotype: gotype,
|
|
|
|
|
})
|
2017-02-06 17:06:02 -08:00
|
|
|
|
2017-03-07 10:57:55 -08:00
|
|
|
if n.IsAutoTmp() {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-06 07:32:37 -08:00
|
|
|
typename := dwarf.InfoPrefix + gotype.Name[len("type."):]
|
|
|
|
|
vars = append(vars, &dwarf.Var{
|
|
|
|
|
Name: n.Sym.Name,
|
|
|
|
|
Abbrev: abbrev,
|
|
|
|
|
Offset: int32(offs),
|
|
|
|
|
Type: obj.Linklookup(Ctxt, typename, 0),
|
|
|
|
|
})
|
2017-03-03 16:45:21 -08:00
|
|
|
}
|
2017-03-06 07:32:37 -08:00
|
|
|
|
|
|
|
|
// Stable sort so that ties are broken with declaration order.
|
|
|
|
|
sort.Stable(dwarf.VarsByOffset(vars))
|
|
|
|
|
|
|
|
|
|
return vars
|
2017-03-03 14:27:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fieldtrack adds R_USEFIELD relocations to fnsym to record any
|
|
|
|
|
// struct fields that it used.
|
|
|
|
|
func fieldtrack(fnsym *obj.LSym, tracked map[*Sym]struct{}) {
|
|
|
|
|
if fnsym == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if obj.Fieldtrack_enabled == 0 || len(tracked) == 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trackSyms := make([]*Sym, 0, len(tracked))
|
|
|
|
|
for sym := range tracked {
|
|
|
|
|
trackSyms = append(trackSyms, sym)
|
|
|
|
|
}
|
|
|
|
|
sort.Sort(symByName(trackSyms))
|
|
|
|
|
for _, sym := range trackSyms {
|
|
|
|
|
r := obj.Addrel(fnsym)
|
|
|
|
|
r.Sym = Linksym(sym)
|
|
|
|
|
r.Type = obj.R_USEFIELD
|
2017-02-06 17:06:02 -08:00
|
|
|
}
|
2016-03-07 22:05:49 -08:00
|
|
|
}
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
type symByName []*Sym
|
|
|
|
|
|
|
|
|
|
func (a symByName) Len() int { return len(a) }
|
|
|
|
|
func (a symByName) Less(i, j int) bool { return a[i].Name < a[j].Name }
|
|
|
|
|
func (a symByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|