2016-04-11 17:35:55 +03:00
|
|
|
// Copyright 2013 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 obj
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Plist struct {
|
|
|
|
|
Firstpc *Prog
|
2017-03-23 16:39:04 -07:00
|
|
|
Curfn interface{} // holds a *gc.Node, if non-nil
|
2016-04-11 17:35:55 +03:00
|
|
|
}
|
|
|
|
|
|
2017-04-04 14:31:55 -07:00
|
|
|
// ProgAlloc is a function that allocates Progs.
|
|
|
|
|
// It is used to provide access to cached/bulk-allocated Progs to the assemblers.
|
|
|
|
|
type ProgAlloc func() *Prog
|
|
|
|
|
|
2017-04-05 07:05:35 -07:00
|
|
|
func Flushplist(ctxt *Link, plist *Plist, newprog ProgAlloc) {
|
2016-04-11 17:35:55 +03:00
|
|
|
// Build list of symbols, and assign instructions to lists.
|
|
|
|
|
var curtext *LSym
|
|
|
|
|
var etext *Prog
|
|
|
|
|
var text []*LSym
|
|
|
|
|
|
2017-02-17 16:52:16 -05:00
|
|
|
var plink *Prog
|
|
|
|
|
for p := plist.Firstpc; p != nil; p = plink {
|
2017-03-20 15:01:20 -07:00
|
|
|
if ctxt.Debugasm && ctxt.Debugvlog {
|
2017-02-17 16:52:16 -05:00
|
|
|
fmt.Printf("obj: %v\n", p)
|
|
|
|
|
}
|
|
|
|
|
plink = p.Link
|
|
|
|
|
p.Link = nil
|
2016-04-11 17:35:55 +03:00
|
|
|
|
2017-02-17 16:52:16 -05:00
|
|
|
switch p.As {
|
|
|
|
|
case AEND:
|
|
|
|
|
continue
|
2016-04-11 17:35:55 +03:00
|
|
|
|
2017-02-17 16:52:16 -05:00
|
|
|
case ATEXT:
|
|
|
|
|
s := p.From.Sym
|
|
|
|
|
if s == nil {
|
|
|
|
|
// func _() { }
|
|
|
|
|
curtext = nil
|
2016-04-11 17:35:55 +03:00
|
|
|
continue
|
2017-02-17 16:52:16 -05:00
|
|
|
}
|
|
|
|
|
text = append(text, s)
|
|
|
|
|
etext = p
|
|
|
|
|
curtext = s
|
|
|
|
|
continue
|
2016-04-11 17:35:55 +03:00
|
|
|
|
2017-02-17 16:52:16 -05:00
|
|
|
case AFUNCDATA:
|
|
|
|
|
// Rewrite reference to go_args_stackmap(SB) to the Go-provided declaration information.
|
|
|
|
|
if curtext == nil { // func _() {}
|
2016-04-11 17:35:55 +03:00
|
|
|
continue
|
|
|
|
|
}
|
2017-02-17 16:52:16 -05:00
|
|
|
if p.To.Sym.Name == "go_args_stackmap" {
|
|
|
|
|
if p.From.Type != TYPE_CONST || p.From.Offset != FUNCDATA_ArgsPointerMaps {
|
|
|
|
|
ctxt.Diag("FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps")
|
|
|
|
|
}
|
2017-04-06 09:54:14 -07:00
|
|
|
p.To.Sym = ctxt.Lookup(fmt.Sprintf("%s.args_stackmap", curtext.Name), int(curtext.Version))
|
2017-02-17 16:52:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if curtext == nil {
|
|
|
|
|
etext = nil
|
|
|
|
|
continue
|
2016-04-11 17:35:55 +03:00
|
|
|
}
|
2017-02-17 16:52:16 -05:00
|
|
|
etext.Link = p
|
|
|
|
|
etext = p
|
2016-04-11 17:35:55 +03:00
|
|
|
}
|
|
|
|
|
|
2017-04-05 07:05:35 -07:00
|
|
|
if newprog == nil {
|
|
|
|
|
newprog = ctxt.NewProg
|
|
|
|
|
}
|
2017-04-04 14:31:55 -07:00
|
|
|
|
2016-04-11 17:35:55 +03:00
|
|
|
// Add reference to Go arguments for C or assembly functions without them.
|
|
|
|
|
for _, s := range text {
|
|
|
|
|
if !strings.HasPrefix(s.Name, "\"\".") {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
found := false
|
2017-03-19 22:31:02 -07:00
|
|
|
for p := s.Text; p != nil; p = p.Link {
|
2016-04-11 17:35:55 +03:00
|
|
|
if p.As == AFUNCDATA && p.From.Type == TYPE_CONST && p.From.Offset == FUNCDATA_ArgsPointerMaps {
|
|
|
|
|
found = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !found {
|
2017-04-04 14:31:55 -07:00
|
|
|
p := Appendp(s.Text, newprog)
|
2016-04-11 17:35:55 +03:00
|
|
|
p.As = AFUNCDATA
|
|
|
|
|
p.From.Type = TYPE_CONST
|
|
|
|
|
p.From.Offset = FUNCDATA_ArgsPointerMaps
|
|
|
|
|
p.To.Type = TYPE_MEM
|
|
|
|
|
p.To.Name = NAME_EXTERN
|
2017-04-06 09:54:14 -07:00
|
|
|
p.To.Sym = ctxt.Lookup(fmt.Sprintf("%s.args_stackmap", s.Name), int(s.Version))
|
2016-04-11 17:35:55 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Turn functions into machine code images.
|
|
|
|
|
for _, s := range text {
|
|
|
|
|
mkfwd(s)
|
2017-04-04 14:31:55 -07:00
|
|
|
linkpatch(ctxt, s, newprog)
|
|
|
|
|
ctxt.Arch.Preprocess(ctxt, s, newprog)
|
|
|
|
|
ctxt.Arch.Assemble(ctxt, s, newprog)
|
2016-04-11 17:35:55 +03:00
|
|
|
linkpcln(ctxt, s)
|
2017-04-13 05:57:59 -07:00
|
|
|
ctxt.populateDWARF(plist.Curfn, s)
|
2016-04-11 17:35:55 +03:00
|
|
|
}
|
|
|
|
|
}
|
2016-09-16 15:31:04 -07:00
|
|
|
|
2017-04-12 13:23:07 -07:00
|
|
|
func (ctxt *Link) InitTextSym(s *LSym, flag int) {
|
2017-04-10 16:57:06 -07:00
|
|
|
if s == nil {
|
|
|
|
|
// func _() { }
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if s.FuncInfo != nil {
|
|
|
|
|
ctxt.Diag("InitTextSym double init for %s", s.Name)
|
|
|
|
|
}
|
|
|
|
|
s.FuncInfo = new(FuncInfo)
|
|
|
|
|
if s.Text != nil {
|
|
|
|
|
ctxt.Diag("duplicate TEXT for %s", s.Name)
|
|
|
|
|
}
|
|
|
|
|
if s.OnList() {
|
|
|
|
|
ctxt.Diag("symbol %s listed multiple times", s.Name)
|
|
|
|
|
}
|
|
|
|
|
s.Set(AttrOnList, true)
|
cmd/internal/obj: stop storing Text flags in From3
Prior to this CL, flags such as NOSPLIT
on ATEXT Progs were stored in From3.Offset.
Some but not all of those flags were also
duplicated into From.Sym.Attribute.
This CL migrates all of those flags into
From.Sym.Attribute and stops creating a From3.
A side-effect of this is that printing an
ATEXT Prog can no longer simply dump From3.Offset.
That's kind of good, since the raw flag value
wasn't very informative anyway, but it did
necessitate a bunch of updates to the cmd/asm tests.
The reason I'm doing this work now is that
avoiding storing flags in both From.Sym and From3.Offset
simplifies some other changes to fix the data
race first described in CL 40254.
This CL almost passes toolstash-check -all.
The only changes are in cases where the assembler
has decided that a function's flags may be altered,
e.g. to make a function with no calls in it NOSPLIT.
Prior to this CL, that information was not printed.
Sample before:
"".Ctz64 t=1 size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB)
Sample after:
"".Ctz64 t=1 nosplit size=63 args=0x10 locals=0x0
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) TEXT "".Ctz64(SB), NOSPLIT, $0-16
0x0000 00000 (/Users/josh/go/tip/src/runtime/internal/sys/intrinsics.go:35) FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB)
Observe the additional "nosplit" in the first line
and the additional "NOSPLIT" in the second line.
Updates #15756
Change-Id: I5c59bd8f3bdc7c780361f801d94a261f0aef3d13
Reviewed-on: https://go-review.googlesource.com/40495
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-04-11 15:15:04 -07:00
|
|
|
s.Set(AttrDuplicateOK, flag&DUPOK != 0)
|
|
|
|
|
s.Set(AttrNoSplit, flag&NOSPLIT != 0)
|
|
|
|
|
s.Set(AttrReflectMethod, flag&REFLECTMETHOD != 0)
|
|
|
|
|
s.Set(AttrWrapper, flag&WRAPPER != 0)
|
|
|
|
|
s.Set(AttrNeedCtxt, flag&NEEDCTXT != 0)
|
|
|
|
|
s.Set(AttrNoFrame, flag&NOFRAME != 0)
|
2017-04-10 16:57:06 -07:00
|
|
|
s.Type = STEXT
|
2017-04-12 17:43:30 -07:00
|
|
|
ctxt.Text = append(ctxt.Text, s)
|
2017-04-13 05:57:59 -07:00
|
|
|
|
|
|
|
|
// Set up DWARF entry for s.
|
|
|
|
|
dsym := ctxt.dwarfSym(s)
|
|
|
|
|
dsym.Type = SDWARFINFO
|
|
|
|
|
dsym.Set(AttrDuplicateOK, s.DuplicateOK())
|
|
|
|
|
ctxt.Data = append(ctxt.Data, dsym)
|
2017-04-14 06:35:53 -07:00
|
|
|
|
|
|
|
|
// Set up the function's gcargs and gclocals.
|
|
|
|
|
// They will be filled in later if needed.
|
|
|
|
|
gcargs := &s.FuncInfo.GCArgs
|
|
|
|
|
gcargs.Set(AttrDuplicateOK, true)
|
|
|
|
|
gcargs.Type = SRODATA
|
|
|
|
|
gclocals := &s.FuncInfo.GCLocals
|
|
|
|
|
gclocals.Set(AttrDuplicateOK, true)
|
|
|
|
|
gclocals.Type = SRODATA
|
2017-04-10 16:57:06 -07:00
|
|
|
}
|
|
|
|
|
|
2016-09-16 15:31:04 -07:00
|
|
|
func (ctxt *Link) Globl(s *LSym, size int64, flag int) {
|
2016-10-24 23:15:41 +03:00
|
|
|
if s.SeenGlobl() {
|
2016-09-16 15:31:04 -07:00
|
|
|
fmt.Printf("duplicate %v\n", s)
|
|
|
|
|
}
|
2016-10-24 23:15:41 +03:00
|
|
|
s.Set(AttrSeenGlobl, true)
|
|
|
|
|
if s.OnList() {
|
2017-04-10 16:57:06 -07:00
|
|
|
ctxt.Diag("symbol %s listed multiple times", s.Name)
|
2016-09-16 15:31:04 -07:00
|
|
|
}
|
2016-10-24 23:15:41 +03:00
|
|
|
s.Set(AttrOnList, true)
|
2016-09-16 15:31:04 -07:00
|
|
|
ctxt.Data = append(ctxt.Data, s)
|
|
|
|
|
s.Size = size
|
|
|
|
|
if s.Type == 0 || s.Type == SXREF {
|
|
|
|
|
s.Type = SBSS
|
|
|
|
|
}
|
|
|
|
|
if flag&DUPOK != 0 {
|
2016-10-24 23:15:41 +03:00
|
|
|
s.Set(AttrDuplicateOK, true)
|
2016-09-16 15:31:04 -07:00
|
|
|
}
|
|
|
|
|
if flag&RODATA != 0 {
|
|
|
|
|
s.Type = SRODATA
|
|
|
|
|
} else if flag&NOPTR != 0 {
|
|
|
|
|
s.Type = SNOPTRBSS
|
|
|
|
|
} else if flag&TLSBSS != 0 {
|
|
|
|
|
s.Type = STLSBSS
|
|
|
|
|
}
|
|
|
|
|
}
|