cmd/internal/obj: print relocation type by name in -S output

The compiler/assembler's -S output prints relocation type
numerically, which is hard to understand. Every time I need to
count the relocation type constants to figure out which relocation
it actually is. Print the symbolic name instead.

Change-Id: I4866873bbae8b3dc0ee212609cb00280f9164243
Reviewed-on: https://go-review.googlesource.com/c/go/+/501856
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Cherry Mui 2023-06-07 22:28:20 -04:00
parent 66c8410c73
commit 5f9412911b
2 changed files with 6 additions and 6 deletions

View File

@ -914,9 +914,9 @@ func (ctxt *Link) writeSymDebugNamed(s *LSym, name string) {
name = "TLS"
}
if ctxt.Arch.InFamily(sys.ARM, sys.PPC64) {
fmt.Fprintf(ctxt.Bso, "\trel %d+%d t=%d %s%s+%x\n", int(r.Off), r.Siz, r.Type, name, ver, uint64(r.Add))
fmt.Fprintf(ctxt.Bso, "\trel %d+%d t=%v %s%s+%x\n", int(r.Off), r.Siz, r.Type, name, ver, uint64(r.Add))
} else {
fmt.Fprintf(ctxt.Bso, "\trel %d+%d t=%d %s%s+%d\n", int(r.Off), r.Siz, r.Type, name, ver, r.Add)
fmt.Fprintf(ctxt.Bso, "\trel %d+%d t=%v %s%s+%d\n", int(r.Off), r.Siz, r.Type, name, ver, r.Add)
}
}
}

View File

@ -32,10 +32,10 @@ func main() {
// 6g/8g print the offset as dec, but 5g/9g print the offset as hex.
patterns := []string{
`rel 0\+\d t=1 p\.x\+8\r?\n`, // y = &x.b
`rel 0\+\d t=1 p\.x\+(28|1c)\r?\n`, // z = &x.d.q
`rel 0\+\d t=1 p\.b\+5\r?\n`, // c = &b[5]
`rel 0\+\d t=1 p\.x\+(88|58)\r?\n`, // w = &x.f[3].r
`rel 0\+\d t=R_ADDR p\.x\+8\r?\n`, // y = &x.b
`rel 0\+\d t=R_ADDR p\.x\+(28|1c)\r?\n`, // z = &x.d.q
`rel 0\+\d t=R_ADDR p\.b\+5\r?\n`, // c = &b[5]
`rel 0\+\d t=R_ADDR p\.x\+(88|58)\r?\n`, // w = &x.f[3].r
}
for _, p := range patterns {
if ok, err := regexp.Match(p, out); !ok || err != nil {