mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile, cmd/link: weak relocation for ptrTo
Introduce R_WEAKADDROFF, a "weak" variation of the R_ADDROFF relocation that will only reference the type described if it is in some other way reachable. Use this for the ptrToThis field in reflect type information where it is safe to do so (that is, types that don't need to be included for interface satisfaction, and types that won't cause the compiler to recursively generate an endless series of ptr-to-ptr-to-ptr-to... types). Also fix a small bug in reflect, where StructOf was not clearing the ptrToThis field of new types. Fixes #17931 Change-Id: I4d3b53cb9c916c97b3b16e367794eee142247281 Reviewed-on: https://go-review.googlesource.com/33427 Run-TryBot: David Crawshaw <crawshaw@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
aeaa4c3c1d
commit
6f31abd23a
8 changed files with 54 additions and 5 deletions
|
|
@ -413,7 +413,7 @@ func relocsym(ctxt *Link, s *Symbol) {
|
|||
Errorf(s, "unhandled relocation for %s (type %d rtype %d)", r.Sym.Name, r.Sym.Type, r.Type)
|
||||
}
|
||||
}
|
||||
if r.Sym != nil && r.Sym.Type != obj.STLSBSS && !r.Sym.Attr.Reachable() {
|
||||
if r.Sym != nil && r.Sym.Type != obj.STLSBSS && r.Type != obj.R_WEAKADDROFF && !r.Sym.Attr.Reachable() {
|
||||
Errorf(s, "unreachable sym in relocation: %s", r.Sym.Name)
|
||||
}
|
||||
|
||||
|
|
@ -588,6 +588,11 @@ func relocsym(ctxt *Link, s *Symbol) {
|
|||
}
|
||||
o = Symaddr(r.Sym) + r.Add - int64(r.Sym.Sect.Vaddr)
|
||||
|
||||
case obj.R_WEAKADDROFF:
|
||||
if !r.Sym.Attr.Reachable() {
|
||||
continue
|
||||
}
|
||||
fallthrough
|
||||
case obj.R_ADDROFF:
|
||||
// The method offset tables using this relocation expect the offset to be relative
|
||||
// to the start of the first text section, even if there are multiple.
|
||||
|
|
@ -748,6 +753,9 @@ func dynrelocsym(ctxt *Link, s *Symbol) {
|
|||
continue
|
||||
}
|
||||
if !targ.Attr.Reachable() {
|
||||
if r.Type == obj.R_WEAKADDROFF {
|
||||
continue
|
||||
}
|
||||
Errorf(s, "dynamic relocation to unreachable symbol %s", targ.Name)
|
||||
}
|
||||
if r.Sym.Plt == -2 && r.Sym.Got != -2 { // make dynimport JMP table for PE object files.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue