1
0
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:
Jeremy Faller 2020-02-13 10:38:33 -05:00
parent 860f12a2fc
commit 9d673bf1db
2 changed files with 18 additions and 16 deletions

View File

@ -158,6 +158,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool {
if targ.Type != sym.SDYNIMPORT {
// have symbol
if r.Off >= 2 && s.P[r.Off-2] == 0x8b {
makeWritable(s)
// turn MOVQ of GOT entry into LEAQ of symbol itself
s.P[r.Off-2] = 0x8d

View File

@ -282,6 +282,7 @@ type ElfSect struct {
align uint64
entsize uint64
base []byte
readOnlyMem bool // Is this section in readonly memory?
sym loader.Sym
}
@ -600,7 +601,6 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
sect := &elfobj.sect[i]
if is64 != 0 {
var b ElfSectBytes64
if err := binary.Read(f, e, &b); err != nil {
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.SetAlign(int32(sect.align))
sb.SetReadOnly(sect.readOnlyMem)
sect.sym = sb.Sym()
}
@ -1016,9 +1017,9 @@ func elfmap(elfobj *ElfObj, sect *ElfSect) (err error) {
return err
}
sect.base = make([]byte, sect.size)
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)
}