Commit 712ffc08 authored by Michael Hudson-Doyle's avatar Michael Hudson-Doyle

cmd/link: look at the R_AARCH64_RELATIVE relocs to find the gcdata on arm64

Change-Id: I5a1864a27ad917aa65c8e65a133f6cc0a980d05f
Reviewed-on: https://go-review.googlesource.com/13998Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 3a9bc571
...@@ -110,6 +110,14 @@ func decodetype_gcprog(s *LSym) []byte { ...@@ -110,6 +110,14 @@ func decodetype_gcprog(s *LSym) []byte {
} }
func decodetype_gcprog_shlib(s *LSym) uint64 { func decodetype_gcprog_shlib(s *LSym) uint64 {
if Thearch.Thechar == '7' {
for _, shlib := range Ctxt.Shlibs {
if shlib.Path == s.File {
return shlib.gcdata_addresses[s]
}
}
return 0
}
return decode_inuxi(s.P[2*int32(Thearch.Ptrsize)+8+1*int32(Thearch.Ptrsize):], Thearch.Ptrsize) return decode_inuxi(s.P[2*int32(Thearch.Ptrsize)+8+1*int32(Thearch.Ptrsize):], Thearch.Ptrsize)
} }
......
...@@ -1400,6 +1400,7 @@ func ldshlibsyms(shlib string) { ...@@ -1400,6 +1400,7 @@ func ldshlibsyms(shlib string) {
Diag("cannot read symbols from shared library: %s", libpath) Diag("cannot read symbols from shared library: %s", libpath)
return return
} }
gcdata_locations := make(map[uint64]*LSym)
for _, elfsym := range syms { for _, elfsym := range syms {
if elf.ST_TYPE(elfsym.Info) == elf.STT_NOTYPE || elf.ST_TYPE(elfsym.Info) == elf.STT_SECTION { if elf.ST_TYPE(elfsym.Info) == elf.STT_NOTYPE || elf.ST_TYPE(elfsym.Info) == elf.STT_SECTION {
continue continue
...@@ -1428,6 +1429,32 @@ func ldshlibsyms(shlib string) { ...@@ -1428,6 +1429,32 @@ func ldshlibsyms(shlib string) {
// the type data. // the type data.
if strings.HasPrefix(lsym.Name, "type.") && !strings.HasPrefix(lsym.Name, "type..") { if strings.HasPrefix(lsym.Name, "type.") && !strings.HasPrefix(lsym.Name, "type..") {
lsym.P = readelfsymboldata(f, &elfsym) lsym.P = readelfsymboldata(f, &elfsym)
gcdata_locations[elfsym.Value+2*uint64(Thearch.Ptrsize)+8+1*uint64(Thearch.Ptrsize)] = lsym
}
}
}
gcdata_addresses := make(map[*LSym]uint64)
if Thearch.Thechar == '7' {
for _, sect := range f.Sections {
if sect.Type == elf.SHT_RELA {
var rela elf.Rela64
rdr := sect.Open()
for {
err := binary.Read(rdr, f.ByteOrder, &rela)
if err == io.EOF {
break
} else if err != nil {
Diag("reading relocation failed %v", err)
return
}
t := elf.R_AARCH64(rela.Info & 0xffff)
if t != elf.R_AARCH64_RELATIVE {
continue
}
if lsym, ok := gcdata_locations[rela.Off]; ok {
gcdata_addresses[lsym] = uint64(rela.Addend)
}
}
} }
} }
} }
...@@ -1459,7 +1486,7 @@ func ldshlibsyms(shlib string) { ...@@ -1459,7 +1486,7 @@ func ldshlibsyms(shlib string) {
Ctxt.Etextp = last Ctxt.Etextp = last
} }
Ctxt.Shlibs = append(Ctxt.Shlibs, Shlib{Path: libpath, Hash: hash, Deps: deps, File: f}) Ctxt.Shlibs = append(Ctxt.Shlibs, Shlib{Path: libpath, Hash: hash, Deps: deps, File: f, gcdata_addresses: gcdata_addresses})
} }
func mywhatsys() { func mywhatsys() {
......
...@@ -128,6 +128,7 @@ type Shlib struct { ...@@ -128,6 +128,7 @@ type Shlib struct {
Hash []byte Hash []byte
Deps []string Deps []string
File *elf.File File *elf.File
gcdata_addresses map[*LSym]uint64
} }
type Link struct { type Link struct {
......
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