mirror of
https://github.com/golang/go
synced 2024-11-06 08:26:12 -07:00
[dev.link] cmd/link: use RO memory (when avail) in elf loader
Recreation of CL 206139 in the new symbol hierarchy. Change-Id: Ic20c5c1b5db8f7eadf4c6ee4638e3c1a4e10ef3a Reviewed-on: https://go-review.googlesource.com/c/go/+/219317 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
860f12a2fc
commit
9d673bf1db
@ -158,6 +158,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool {
|
|||||||
if targ.Type != sym.SDYNIMPORT {
|
if targ.Type != sym.SDYNIMPORT {
|
||||||
// have symbol
|
// have symbol
|
||||||
if r.Off >= 2 && s.P[r.Off-2] == 0x8b {
|
if r.Off >= 2 && s.P[r.Off-2] == 0x8b {
|
||||||
|
makeWritable(s)
|
||||||
// turn MOVQ of GOT entry into LEAQ of symbol itself
|
// turn MOVQ of GOT entry into LEAQ of symbol itself
|
||||||
s.P[r.Off-2] = 0x8d
|
s.P[r.Off-2] = 0x8d
|
||||||
|
|
||||||
|
@ -270,19 +270,20 @@ type ElfSymBytes64 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ElfSect struct {
|
type ElfSect struct {
|
||||||
name string
|
name string
|
||||||
nameoff uint32
|
nameoff uint32
|
||||||
type_ uint32
|
type_ uint32
|
||||||
flags uint64
|
flags uint64
|
||||||
addr uint64
|
addr uint64
|
||||||
off uint64
|
off uint64
|
||||||
size uint64
|
size uint64
|
||||||
link uint32
|
link uint32
|
||||||
info uint32
|
info uint32
|
||||||
align uint64
|
align uint64
|
||||||
entsize uint64
|
entsize uint64
|
||||||
base []byte
|
base []byte
|
||||||
sym loader.Sym
|
readOnlyMem bool // Is this section in readonly memory?
|
||||||
|
sym loader.Sym
|
||||||
}
|
}
|
||||||
|
|
||||||
type ElfObj struct {
|
type ElfObj struct {
|
||||||
@ -600,7 +601,6 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
|||||||
sect := &elfobj.sect[i]
|
sect := &elfobj.sect[i]
|
||||||
if is64 != 0 {
|
if is64 != 0 {
|
||||||
var b ElfSectBytes64
|
var b ElfSectBytes64
|
||||||
|
|
||||||
if err := binary.Read(f, e, &b); err != nil {
|
if err := binary.Read(f, e, &b); err != nil {
|
||||||
return errorf("malformed elf file: %v", err)
|
return errorf("malformed elf file: %v", err)
|
||||||
}
|
}
|
||||||
@ -750,6 +750,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
|||||||
|
|
||||||
sb.SetSize(int64(sect.size))
|
sb.SetSize(int64(sect.size))
|
||||||
sb.SetAlign(int32(sect.align))
|
sb.SetAlign(int32(sect.align))
|
||||||
|
sb.SetReadOnly(sect.readOnlyMem)
|
||||||
|
|
||||||
sect.sym = sb.Sym()
|
sect.sym = sb.Sym()
|
||||||
}
|
}
|
||||||
@ -1016,9 +1017,9 @@ func elfmap(elfobj *ElfObj, sect *ElfSect) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
sect.base = make([]byte, sect.size)
|
|
||||||
elfobj.f.MustSeek(int64(uint64(elfobj.base)+sect.off), 0)
|
elfobj.f.MustSeek(int64(uint64(elfobj.base)+sect.off), 0)
|
||||||
if _, err := io.ReadFull(elfobj.f, sect.base); err != nil {
|
sect.base, sect.readOnlyMem, err = elfobj.f.Slice(uint64(sect.size))
|
||||||
|
if err != nil {
|
||||||
return fmt.Errorf("short read: %v", err)
|
return fmt.Errorf("short read: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user