Commit f58c48f8 authored by Hiroshi Ioka's avatar Hiroshi Ioka Committed by Ian Lance Taylor

cmd/link: extract windows-specific code from dynrelocsym

No functional changes.

Change-Id: Ib31bb3f01b515aac6428ec61e0ef02b269623890
Reviewed-on: https://go-review.googlesource.com/62470Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 9dba7335
...@@ -759,49 +759,52 @@ func (ctxt *Link) reloc() { ...@@ -759,49 +759,52 @@ func (ctxt *Link) reloc() {
} }
} }
func dynrelocsym(ctxt *Link, s *Symbol) { func windynrelocsym(ctxt *Link, s *Symbol) {
if Headtype == objabi.Hwindows && Linkmode != LinkExternal { rel := ctxt.Syms.Lookup(".rel", 0)
rel := ctxt.Syms.Lookup(".rel", 0) if s == rel {
if s == rel { return
return }
for ri := 0; ri < len(s.R); ri++ {
r := &s.R[ri]
targ := r.Sym
if targ == nil {
continue
} }
for ri := 0; ri < len(s.R); ri++ { if !targ.Attr.Reachable() {
r := &s.R[ri] if r.Type == objabi.R_WEAKADDROFF {
targ := r.Sym
if targ == nil {
continue continue
} }
if !targ.Attr.Reachable() { Errorf(s, "dynamic relocation to unreachable symbol %s", targ.Name)
if r.Type == objabi.R_WEAKADDROFF { }
continue if r.Sym.Plt == -2 && r.Sym.Got != -2 { // make dynimport JMP table for PE object files.
} targ.Plt = int32(rel.Size)
Errorf(s, "dynamic relocation to unreachable symbol %s", targ.Name) r.Sym = rel
} r.Add = int64(targ.Plt)
if r.Sym.Plt == -2 && r.Sym.Got != -2 { // make dynimport JMP table for PE object files.
targ.Plt = int32(rel.Size) // jmp *addr
r.Sym = rel if SysArch.Family == sys.I386 {
r.Add = int64(targ.Plt) Adduint8(ctxt, rel, 0xff)
Adduint8(ctxt, rel, 0x25)
// jmp *addr Addaddr(ctxt, rel, targ)
if SysArch.Family == sys.I386 { Adduint8(ctxt, rel, 0x90)
Adduint8(ctxt, rel, 0xff) Adduint8(ctxt, rel, 0x90)
Adduint8(ctxt, rel, 0x25) } else {
Addaddr(ctxt, rel, targ) Adduint8(ctxt, rel, 0xff)
Adduint8(ctxt, rel, 0x90) Adduint8(ctxt, rel, 0x24)
Adduint8(ctxt, rel, 0x90) Adduint8(ctxt, rel, 0x25)
} else { addaddrplus4(ctxt, rel, targ, 0)
Adduint8(ctxt, rel, 0xff) Adduint8(ctxt, rel, 0x90)
Adduint8(ctxt, rel, 0x24)
Adduint8(ctxt, rel, 0x25)
addaddrplus4(ctxt, rel, targ, 0)
Adduint8(ctxt, rel, 0x90)
}
} else if r.Sym.Plt >= 0 {
r.Sym = rel
r.Add = int64(targ.Plt)
} }
} else if r.Sym.Plt >= 0 {
r.Sym = rel
r.Add = int64(targ.Plt)
} }
}
}
func dynrelocsym(ctxt *Link, s *Symbol) {
if Headtype == objabi.Hwindows && Linkmode != LinkExternal {
windynrelocsym(ctxt, s)
return return
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment