mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.link] cmd/link: use new sym format in pe loader
Change-Id: Ib784b8432ff4355b7ff4068801a0bcfcaf108950 Reviewed-on: https://go-review.googlesource.com/c/go/+/216718 Run-TryBot: Jeremy Faller <jeremy@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
8e2b5d3e71
commit
83ba044be6
7 changed files with 152 additions and 122 deletions
|
|
@ -228,6 +228,8 @@ type Loader struct {
|
|||
extname map[Sym]string // stores Extname symbol attribute
|
||||
elfType map[Sym]elf.SymType // stores elf type symbol property
|
||||
symFile map[Sym]string // stores file for shlib-derived syms
|
||||
plt map[Sym]int32 // stores dynimport for pe objects
|
||||
got map[Sym]int32 // stores got for pe objects
|
||||
|
||||
// Used to implement field tracking; created during deadcode if
|
||||
// field tracking is enabled. Reachparent[K] contains the index of
|
||||
|
|
@ -282,6 +284,8 @@ func NewLoader(flags uint32, elfsetstring elfsetstringFunc) *Loader {
|
|||
attrReadOnly: make(map[Sym]bool),
|
||||
elfType: make(map[Sym]elf.SymType),
|
||||
symFile: make(map[Sym]string),
|
||||
plt: make(map[Sym]int32),
|
||||
got: make(map[Sym]int32),
|
||||
attrTopFrame: make(map[Sym]struct{}),
|
||||
attrSpecial: make(map[Sym]struct{}),
|
||||
attrCgoExportDynamic: make(map[Sym]struct{}),
|
||||
|
|
@ -1154,7 +1158,7 @@ func (l *Loader) SymElfType(i Sym) elf.SymType {
|
|||
return elf.STT_NOTYPE
|
||||
}
|
||||
|
||||
// SetSymElfType sets the elf type attribute for a symbol.
|
||||
// SetSymElfType sets the elf type attribute for a symbol.
|
||||
func (l *Loader) SetSymElfType(i Sym, et elf.SymType) {
|
||||
// reject bad symbols
|
||||
if i > l.max || i == 0 {
|
||||
|
|
@ -1167,6 +1171,30 @@ func (l *Loader) SetSymElfType(i Sym, et elf.SymType) {
|
|||
}
|
||||
}
|
||||
|
||||
// SetPlt sets the plt value for pe symbols.
|
||||
func (l *Loader) SetPlt(i Sym, v int32) {
|
||||
if i > l.max || i == 0 {
|
||||
panic("bad symbol for SetPlt")
|
||||
}
|
||||
if v == 0 {
|
||||
delete(l.plt, i)
|
||||
} else {
|
||||
l.plt[i] = v
|
||||
}
|
||||
}
|
||||
|
||||
// SetGot sets the got value for pe symbols.
|
||||
func (l *Loader) SetGot(i Sym, v int32) {
|
||||
if i > l.max || i == 0 {
|
||||
panic("bad symbol for SetPlt")
|
||||
}
|
||||
if v == 0 {
|
||||
delete(l.got, i)
|
||||
} else {
|
||||
l.got[i] = v
|
||||
}
|
||||
}
|
||||
|
||||
// SymGoType returns the 'Gotype' property for a given symbol (set by
|
||||
// the Go compiler for variable symbols). This version relies on
|
||||
// reading aux symbols for the target sym -- it could be that a faster
|
||||
|
|
@ -2078,6 +2106,14 @@ func (l *Loader) migrateAttributes(src Sym, dst *sym.Symbol) {
|
|||
if et, ok := l.elfType[src]; ok {
|
||||
dst.SetElfType(et)
|
||||
}
|
||||
|
||||
// Copy pe objects values if set.
|
||||
if plt, ok := l.plt[src]; ok {
|
||||
dst.SetPlt(plt)
|
||||
}
|
||||
if got, ok := l.got[src]; ok {
|
||||
dst.SetGot(got)
|
||||
}
|
||||
}
|
||||
|
||||
// CreateExtSym creates a new external symbol with the specified name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue