mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/link: do not directly embed Symbols in Link
Mostly done with sed. Change-Id: Ic8c534a3fdd332b5420d062ee85bb77a30ad1efb Reviewed-on: https://go-review.googlesource.com/29346 Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
d284d4ff92
commit
d41a7f77c5
16 changed files with 32 additions and 32 deletions
|
|
@ -99,7 +99,7 @@ func hostArchive(ctxt *Link, name string) {
|
||||||
any := true
|
any := true
|
||||||
for any {
|
for any {
|
||||||
var load []uint64
|
var load []uint64
|
||||||
for _, s := range ctxt.Allsym {
|
for _, s := range ctxt.Syms.Allsym {
|
||||||
for _, r := range s.R {
|
for _, r := range s.R {
|
||||||
if r.Sym != nil && r.Sym.Type&obj.SMASK == obj.SXREF {
|
if r.Sym != nil && r.Sym.Type&obj.SMASK == obj.SXREF {
|
||||||
if off := armap[r.Sym.Name]; off != 0 && !loaded[off] {
|
if off := armap[r.Sym.Name]; off != 0 && !loaded[off] {
|
||||||
|
|
|
||||||
|
|
@ -1060,7 +1060,7 @@ func addinitarrdata(ctxt *Link, s *Symbol) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func dosymtype(ctxt *Link) {
|
func dosymtype(ctxt *Link) {
|
||||||
for _, s := range ctxt.Allsym {
|
for _, s := range ctxt.Syms.Allsym {
|
||||||
if len(s.P) > 0 {
|
if len(s.P) > 0 {
|
||||||
if s.Type == obj.SBSS {
|
if s.Type == obj.SBSS {
|
||||||
s.Type = obj.SDATA
|
s.Type = obj.SDATA
|
||||||
|
|
@ -1208,7 +1208,7 @@ func (ctxt *Link) dodata() {
|
||||||
|
|
||||||
// Collect data symbols by type into data.
|
// Collect data symbols by type into data.
|
||||||
var data [obj.SXREF][]*Symbol
|
var data [obj.SXREF][]*Symbol
|
||||||
for _, s := range ctxt.Allsym {
|
for _, s := range ctxt.Syms.Allsym {
|
||||||
if !s.Attr.Reachable() || s.Attr.Special() {
|
if !s.Attr.Reachable() || s.Attr.Special() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ func deadcode(ctxt *Link) {
|
||||||
if Buildmode != BuildmodeShared {
|
if Buildmode != BuildmodeShared {
|
||||||
// Keep a typelink or itablink if the symbol it points at is being kept.
|
// Keep a typelink or itablink if the symbol it points at is being kept.
|
||||||
// (When BuildmodeShared, always keep typelinks and itablinks.)
|
// (When BuildmodeShared, always keep typelinks and itablinks.)
|
||||||
for _, s := range ctxt.Allsym {
|
for _, s := range ctxt.Syms.Allsym {
|
||||||
if strings.HasPrefix(s.Name, "go.typelink.") ||
|
if strings.HasPrefix(s.Name, "go.typelink.") ||
|
||||||
strings.HasPrefix(s.Name, "go.itablink.") {
|
strings.HasPrefix(s.Name, "go.itablink.") {
|
||||||
s.Attr.Set(AttrReachable, len(s.R) == 1 && s.R[0].Sym.Attr.Reachable())
|
s.Attr.Set(AttrReachable, len(s.R) == 1 && s.R[0].Sym.Attr.Reachable())
|
||||||
|
|
@ -232,7 +232,7 @@ func (d *deadcodepass) init() {
|
||||||
if Buildmode == BuildmodeShared {
|
if Buildmode == BuildmodeShared {
|
||||||
// Mark all symbols defined in this library as reachable when
|
// Mark all symbols defined in this library as reachable when
|
||||||
// building a shared library.
|
// building a shared library.
|
||||||
for _, s := range d.ctxt.Allsym {
|
for _, s := range d.ctxt.Syms.Allsym {
|
||||||
if s.Type != 0 && s.Type != obj.SDYNIMPORT {
|
if s.Type != 0 && s.Type != obj.SDYNIMPORT {
|
||||||
d.mark(s, nil)
|
d.mark(s, nil)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1462,7 +1462,7 @@ func elfdynhash(ctxt *Link) {
|
||||||
buckets := make([]uint32, nbucket)
|
buckets := make([]uint32, nbucket)
|
||||||
|
|
||||||
var b int
|
var b int
|
||||||
for _, sy := range ctxt.Allsym {
|
for _, sy := range ctxt.Syms.Allsym {
|
||||||
if sy.Dynid <= 0 {
|
if sy.Dynid <= 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,7 @@ func Adddynsym(ctxt *Link, s *Symbol) {
|
||||||
func fieldtrack(ctxt *Link) {
|
func fieldtrack(ctxt *Link) {
|
||||||
// record field tracking references
|
// record field tracking references
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
for _, s := range ctxt.Allsym {
|
for _, s := range ctxt.Syms.Allsym {
|
||||||
if strings.HasPrefix(s.Name, "go.track.") {
|
if strings.HasPrefix(s.Name, "go.track.") {
|
||||||
s.Attr |= AttrSpecial // do not lay out in data segment
|
s.Attr |= AttrSpecial // do not lay out in data segment
|
||||||
s.Attr |= AttrHidden
|
s.Attr |= AttrHidden
|
||||||
|
|
|
||||||
|
|
@ -445,7 +445,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||||
ctxt.Logf("%5.2f ldelf %s\n", obj.Cputime(), pn)
|
ctxt.Logf("%5.2f ldelf %s\n", obj.Cputime(), pn)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt.IncVersion()
|
ctxt.Syms.IncVersion()
|
||||||
base := f.Offset()
|
base := f.Offset()
|
||||||
|
|
||||||
var add uint64
|
var add uint64
|
||||||
|
|
@ -702,7 +702,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
name = fmt.Sprintf("%s(%s)", pkg, sect.name)
|
name = fmt.Sprintf("%s(%s)", pkg, sect.name)
|
||||||
s = Linklookup(ctxt, name, ctxt.Version)
|
s = Linklookup(ctxt, name, ctxt.Syms.Version)
|
||||||
|
|
||||||
switch int(sect.flags) & (ElfSectFlagAlloc | ElfSectFlagWrite | ElfSectFlagExec) {
|
switch int(sect.flags) & (ElfSectFlagAlloc | ElfSectFlagWrite | ElfSectFlagExec) {
|
||||||
default:
|
default:
|
||||||
|
|
@ -1059,7 +1059,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int) (er
|
||||||
// We need to be able to look this up,
|
// We need to be able to look this up,
|
||||||
// so put it in the hash table.
|
// so put it in the hash table.
|
||||||
if needSym != 0 {
|
if needSym != 0 {
|
||||||
s = Linklookup(ctxt, sym.name, ctxt.Version)
|
s = Linklookup(ctxt, sym.name, ctxt.Syms.Version)
|
||||||
s.Type |= obj.SHIDDEN
|
s.Type |= obj.SHIDDEN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1070,7 +1070,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int) (er
|
||||||
// local names and hidden global names are unique
|
// local names and hidden global names are unique
|
||||||
// and should only be referenced by their index, not name, so we
|
// and should only be referenced by their index, not name, so we
|
||||||
// don't bother to add them into the hash table
|
// don't bother to add them into the hash table
|
||||||
s = linknewsym(ctxt, sym.name, ctxt.Version)
|
s = linknewsym(ctxt, sym.name, ctxt.Syms.Version)
|
||||||
|
|
||||||
s.Type |= obj.SHIDDEN
|
s.Type |= obj.SHIDDEN
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -444,7 +444,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||||
var rp *Reloc
|
var rp *Reloc
|
||||||
var name string
|
var name string
|
||||||
|
|
||||||
ctxt.IncVersion()
|
ctxt.Syms.IncVersion()
|
||||||
base := f.Offset()
|
base := f.Offset()
|
||||||
if _, err := io.ReadFull(f, hdr[:]); err != nil {
|
if _, err := io.ReadFull(f, hdr[:]); err != nil {
|
||||||
goto bad
|
goto bad
|
||||||
|
|
@ -587,7 +587,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
name = fmt.Sprintf("%s(%s/%s)", pkg, sect.segname, sect.name)
|
name = fmt.Sprintf("%s(%s/%s)", pkg, sect.segname, sect.name)
|
||||||
s = Linklookup(ctxt, name, ctxt.Version)
|
s = Linklookup(ctxt, name, ctxt.Syms.Version)
|
||||||
if s.Type != 0 {
|
if s.Type != 0 {
|
||||||
err = fmt.Errorf("duplicate %s/%s", sect.segname, sect.name)
|
err = fmt.Errorf("duplicate %s/%s", sect.segname, sect.name)
|
||||||
goto bad
|
goto bad
|
||||||
|
|
@ -634,7 +634,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||||
}
|
}
|
||||||
v := 0
|
v := 0
|
||||||
if sym.type_&N_EXT == 0 {
|
if sym.type_&N_EXT == 0 {
|
||||||
v = ctxt.Version
|
v = ctxt.Syms.Version
|
||||||
}
|
}
|
||||||
s = Linklookup(ctxt, name, v)
|
s = Linklookup(ctxt, name, v)
|
||||||
if sym.type_&N_EXT == 0 {
|
if sym.type_&N_EXT == 0 {
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var sect *PeSect
|
var sect *PeSect
|
||||||
ctxt.IncVersion()
|
ctxt.Syms.IncVersion()
|
||||||
base := f.Offset()
|
base := f.Offset()
|
||||||
|
|
||||||
peobj := new(PeObj)
|
peobj := new(PeObj)
|
||||||
|
|
@ -246,7 +246,7 @@ func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
name = fmt.Sprintf("%s(%s)", pkg, sect.name)
|
name = fmt.Sprintf("%s(%s)", pkg, sect.name)
|
||||||
s = Linklookup(ctxt, name, ctxt.Version)
|
s = Linklookup(ctxt, name, ctxt.Syms.Version)
|
||||||
|
|
||||||
switch sect.sh.Characteristics & (IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE) {
|
switch sect.sh.Characteristics & (IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE) {
|
||||||
case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ: //.rdata
|
case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ: //.rdata
|
||||||
|
|
@ -514,7 +514,7 @@ func readpesym(ctxt *Link, peobj *PeObj, i int, y **PeSym) (err error) {
|
||||||
s = Linklookup(ctxt, name, 0)
|
s = Linklookup(ctxt, name, 0)
|
||||||
|
|
||||||
case IMAGE_SYM_CLASS_NULL, IMAGE_SYM_CLASS_STATIC, IMAGE_SYM_CLASS_LABEL:
|
case IMAGE_SYM_CLASS_NULL, IMAGE_SYM_CLASS_STATIC, IMAGE_SYM_CLASS_LABEL:
|
||||||
s = Linklookup(ctxt, name, ctxt.Version)
|
s = Linklookup(ctxt, name, ctxt.Syms.Version)
|
||||||
s.Attr |= AttrDuplicateOK
|
s.Attr |= AttrDuplicateOK
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -461,7 +461,7 @@ func (ctxt *Link) loadlib() {
|
||||||
if Linkmode == LinkInternal {
|
if Linkmode == LinkInternal {
|
||||||
// Drop all the cgo_import_static declarations.
|
// Drop all the cgo_import_static declarations.
|
||||||
// Turns out we won't be needing them.
|
// Turns out we won't be needing them.
|
||||||
for _, s := range ctxt.Allsym {
|
for _, s := range ctxt.Syms.Allsym {
|
||||||
if s.Type == obj.SHOSTOBJ {
|
if s.Type == obj.SHOSTOBJ {
|
||||||
// If a symbol was marked both
|
// If a symbol was marked both
|
||||||
// cgo_import_static and cgo_import_dynamic,
|
// cgo_import_static and cgo_import_dynamic,
|
||||||
|
|
@ -553,7 +553,7 @@ func (ctxt *Link) loadlib() {
|
||||||
// If we have any undefined symbols in external
|
// If we have any undefined symbols in external
|
||||||
// objects, try to read them from the libgcc file.
|
// objects, try to read them from the libgcc file.
|
||||||
any := false
|
any := false
|
||||||
for _, s := range ctxt.Allsym {
|
for _, s := range ctxt.Syms.Allsym {
|
||||||
for _, r := range s.R {
|
for _, r := range s.R {
|
||||||
if r.Sym != nil && r.Sym.Type&obj.SMASK == obj.SXREF && r.Sym.Name != ".got" {
|
if r.Sym != nil && r.Sym.Type&obj.SMASK == obj.SXREF && r.Sym.Name != ".got" {
|
||||||
any = true
|
any = true
|
||||||
|
|
@ -1817,7 +1817,7 @@ func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, SymbolType, int64, *
|
||||||
put(ctxt, s, s.Name, TextSym, s.Value, nil)
|
put(ctxt, s, s.Name, TextSym, s.Value, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range ctxt.Allsym {
|
for _, s := range ctxt.Syms.Allsym {
|
||||||
if s.Attr.Hidden() {
|
if s.Attr.Hidden() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ type Shlib struct {
|
||||||
// Link holds the context for writing object code from a compiler
|
// Link holds the context for writing object code from a compiler
|
||||||
// or for reading that input into the linker.
|
// or for reading that input into the linker.
|
||||||
type Link struct {
|
type Link struct {
|
||||||
Symbols
|
Syms *Symbols
|
||||||
|
|
||||||
Arch *sys.Arch
|
Arch *sys.Arch
|
||||||
Debugvlog int
|
Debugvlog int
|
||||||
|
|
|
||||||
|
|
@ -658,7 +658,7 @@ func (x machoscmp) Less(i, j int) bool {
|
||||||
|
|
||||||
func machogenasmsym(ctxt *Link) {
|
func machogenasmsym(ctxt *Link) {
|
||||||
genasmsym(ctxt, addsym)
|
genasmsym(ctxt, addsym)
|
||||||
for _, s := range ctxt.Allsym {
|
for _, s := range ctxt.Syms.Allsym {
|
||||||
if s.Type == obj.SDYNIMPORT || s.Type == obj.SHOSTOBJ {
|
if s.Type == obj.SDYNIMPORT || s.Type == obj.SHOSTOBJ {
|
||||||
if s.Attr.Reachable() {
|
if s.Attr.Reachable() {
|
||||||
addsym(ctxt, s, "", DataSym, 0, nil)
|
addsym(ctxt, s, "", DataSym, 0, nil)
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,7 @@ func Main() {
|
||||||
ctxt.archive()
|
ctxt.archive()
|
||||||
if ctxt.Debugvlog != 0 {
|
if ctxt.Debugvlog != 0 {
|
||||||
ctxt.Logf("%5.2f cpu time\n", obj.Cputime())
|
ctxt.Logf("%5.2f cpu time\n", obj.Cputime())
|
||||||
ctxt.Logf("%d symbols\n", len(ctxt.Allsym))
|
ctxt.Logf("%d symbols\n", len(ctxt.Syms.Allsym))
|
||||||
ctxt.Logf("%d liveness data\n", liveness)
|
ctxt.Logf("%d liveness data\n", liveness)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ func LoadObjFile(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string)
|
||||||
|
|
||||||
func (r *objReader) loadObjFile() {
|
func (r *objReader) loadObjFile() {
|
||||||
// Increment context version, versions are used to differentiate static files in different packages
|
// Increment context version, versions are used to differentiate static files in different packages
|
||||||
r.ctxt.IncVersion()
|
r.ctxt.Syms.IncVersion()
|
||||||
|
|
||||||
// Magic header
|
// Magic header
|
||||||
var buf [8]uint8
|
var buf [8]uint8
|
||||||
|
|
@ -452,7 +452,7 @@ func (r *objReader) readRef() {
|
||||||
log.Fatalf("invalid symbol version %d", v)
|
log.Fatalf("invalid symbol version %d", v)
|
||||||
}
|
}
|
||||||
if v == 1 {
|
if v == 1 {
|
||||||
v = r.ctxt.Version
|
v = r.ctxt.Syms.Version
|
||||||
}
|
}
|
||||||
s := Linklookup(r.ctxt, name, v)
|
s := Linklookup(r.ctxt, name, v)
|
||||||
r.refs = append(r.refs, s)
|
r.refs = append(r.refs, s)
|
||||||
|
|
|
||||||
|
|
@ -477,7 +477,7 @@ func initdynimport(ctxt *Link) *Dll {
|
||||||
|
|
||||||
dr = nil
|
dr = nil
|
||||||
var m *Imp
|
var m *Imp
|
||||||
for _, s := range ctxt.Allsym {
|
for _, s := range ctxt.Syms.Allsym {
|
||||||
if !s.Attr.Reachable() || s.Type != obj.SDYNIMPORT {
|
if !s.Attr.Reachable() || s.Type != obj.SDYNIMPORT {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -681,7 +681,7 @@ func (s byExtname) Less(i, j int) bool { return s[i].Extname < s[j].Extname }
|
||||||
|
|
||||||
func initdynexport(ctxt *Link) {
|
func initdynexport(ctxt *Link) {
|
||||||
nexport = 0
|
nexport = 0
|
||||||
for _, s := range ctxt.Allsym {
|
for _, s := range ctxt.Syms.Allsym {
|
||||||
if !s.Attr.Reachable() || !s.Attr.CgoExportDynamic() {
|
if !s.Attr.Reachable() || !s.Attr.CgoExportDynamic() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ import (
|
||||||
|
|
||||||
func linknew(arch *sys.Arch) *Link {
|
func linknew(arch *sys.Arch) *Link {
|
||||||
ctxt := &Link{
|
ctxt := &Link{
|
||||||
Symbols: Symbols{
|
Syms: &Symbols{
|
||||||
hash: []map[string]*Symbol{
|
hash: []map[string]*Symbol{
|
||||||
// preallocate about 2mb for hash of
|
// preallocate about 2mb for hash of
|
||||||
// non static symbols
|
// non static symbols
|
||||||
|
|
@ -134,14 +134,14 @@ func (ctxt *Link) computeTLSOffset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func linknewsym(ctxt *Link, name string, v int) *Symbol {
|
func linknewsym(ctxt *Link, name string, v int) *Symbol {
|
||||||
return ctxt.newsym(name, v)
|
return ctxt.Syms.newsym(name, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Linklookup(ctxt *Link, name string, v int) *Symbol {
|
func Linklookup(ctxt *Link, name string, v int) *Symbol {
|
||||||
return ctxt.Lookup(name, v)
|
return ctxt.Syms.Lookup(name, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// read-only lookup
|
// read-only lookup
|
||||||
func Linkrlookup(ctxt *Link, name string, v int) *Symbol {
|
func Linkrlookup(ctxt *Link, name string, v int) *Symbol {
|
||||||
return ctxt.ROLookup(name, v)
|
return ctxt.Syms.ROLookup(name, v)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -413,7 +413,7 @@ func (ctxt *Link) symtab() {
|
||||||
// within a type they sort by size, so the .* symbols
|
// within a type they sort by size, so the .* symbols
|
||||||
// just defined above will be first.
|
// just defined above will be first.
|
||||||
// hide the specific symbols.
|
// hide the specific symbols.
|
||||||
for _, s := range ctxt.Allsym {
|
for _, s := range ctxt.Syms.Allsym {
|
||||||
if !s.Attr.Reachable() || s.Attr.Special() || s.Type != obj.SRODATA {
|
if !s.Attr.Reachable() || s.Attr.Special() || s.Type != obj.SRODATA {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue