From 6b0b7aca8aab3c09ccb4e683eb99977a33af5591 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Fri, 13 Dec 2019 14:21:13 -0500 Subject: [PATCH] [dev.link] cmd/link: add some new loader decode type sym utilities Add some new utility functions for decoding "type.*" symbol data using loader.Sym instead of sym.Symbol. These are needed for DWARF type DIE generation. Change-Id: I9a4f81d9c8ea975569ea9a9920d728f1e37d1d15 Reviewed-on: https://go-review.googlesource.com/c/go/+/208229 Reviewed-by: Cherry Zhang --- src/cmd/link/internal/ld/decodesym2.go | 90 ++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/src/cmd/link/internal/ld/decodesym2.go b/src/cmd/link/internal/ld/decodesym2.go index 113c09fded..78967406bf 100644 --- a/src/cmd/link/internal/ld/decodesym2.go +++ b/src/cmd/link/internal/ld/decodesym2.go @@ -55,3 +55,93 @@ func decodetypeFuncInType2(ldr *loader.Loader, arch *sys.Arch, symIdx loader.Sym func decodetypeFuncOutType2(ldr *loader.Loader, arch *sys.Arch, symIdx loader.Sym, symRelocs []loader.Reloc, i int) loader.Sym { return decodetypeFuncInType2(ldr, arch, symIdx, symRelocs, i+decodetypeFuncInCount(arch, ldr.Data(symIdx))) } + +func decodetypeArrayElem2(ldr *loader.Loader, arch *sys.Arch, symIdx loader.Sym) loader.Sym { + // FIXME: it's inefficient to read the relocations each time. Add some + // sort of cache here, or pass in the relocs. Alternatively we could + // switch to relocs.At() to see if that performs better. + relocs := ldr.Relocs(symIdx) + rslice := relocs.ReadAll(nil) + return decodeRelocSym2(ldr, symIdx, rslice, int32(commonsize(arch))) // 0x1c / 0x30 +} + +func decodetypeArrayLen2(ldr *loader.Loader, arch *sys.Arch, symIdx loader.Sym) int64 { + data := ldr.Data(symIdx) + return int64(decodeInuxi(arch, data[commonsize(arch)+2*arch.PtrSize:], arch.PtrSize)) +} + +func decodetypeChanElem2(ldr *loader.Loader, arch *sys.Arch, symIdx loader.Sym) loader.Sym { + // FIXME: it's inefficient to read the relocations each time. Add some + // sort of cache here, or pass in the relocs. + relocs := ldr.Relocs(symIdx) + rslice := relocs.ReadAll(nil) + return decodeRelocSym2(ldr, symIdx, rslice, int32(commonsize(arch))) // 0x1c / 0x30 +} + +func decodetypeMapKey2(ldr *loader.Loader, arch *sys.Arch, symIdx loader.Sym) loader.Sym { + // FIXME: it's inefficient to read the relocations each time. Add some + // sort of cache here, or pass in the relocs. Alternatively we could + // switch to relocs.At() to see if that performs better. + relocs := ldr.Relocs(symIdx) + rslice := relocs.ReadAll(nil) + return decodeRelocSym2(ldr, symIdx, rslice, int32(commonsize(arch))) // 0x1c / 0x30 +} + +func decodetypeMapValue2(ldr *loader.Loader, arch *sys.Arch, symIdx loader.Sym) loader.Sym { + // FIXME: it's inefficient to read the relocations each time. Add some + // sort of cache here, or pass in the relocs. Alternatively we could + // switch to relocs.At() to see if that performs better. + relocs := ldr.Relocs(symIdx) + rslice := relocs.ReadAll(nil) + return decodeRelocSym2(ldr, symIdx, rslice, int32(commonsize(arch))+int32(arch.PtrSize)) // 0x20 / 0x38 +} + +func decodetypePtrElem2(ldr *loader.Loader, arch *sys.Arch, symIdx loader.Sym) loader.Sym { + // FIXME: it's inefficient to read the relocations each time. Add some + // sort of cache here, or pass in the relocs. Alternatively we could + // switch to relocs.At() to see if that performs better. + relocs := ldr.Relocs(symIdx) + rslice := relocs.ReadAll(nil) + return decodeRelocSym2(ldr, symIdx, rslice, int32(commonsize(arch))) // 0x1c / 0x30 +} + +func decodetypeStructFieldCount2(ldr *loader.Loader, arch *sys.Arch, symIdx loader.Sym) int { + data := ldr.Data(symIdx) + return int(decodeInuxi(arch, data[commonsize(arch)+2*arch.PtrSize:], arch.PtrSize)) +} + +func decodetypeStructFieldArrayOff2(ldr *loader.Loader, arch *sys.Arch, symIdx loader.Sym, i int) int { + data := ldr.Data(symIdx) + off := commonsize(arch) + 4*arch.PtrSize + if decodetypeHasUncommon(arch, data) { + off += uncommonSize() + } + off += i * structfieldSize(arch) + return off +} + +func decodetypeStructFieldName2(ldr *loader.Loader, arch *sys.Arch, symIdx loader.Sym, i int) string { + off := decodetypeStructFieldArrayOff2(ldr, arch, symIdx, i) + // FIXME: it's inefficient to read the relocations each time. Add some + // sort of cache here, or pass in the relocs. Alternatively we could + // switch to relocs.At() to see if that performs better. + relocs := ldr.Relocs(symIdx) + rslice := relocs.ReadAll(nil) + return decodetypeName2(ldr, symIdx, rslice, off) +} + +func decodetypeStructFieldType2(ldr *loader.Loader, arch *sys.Arch, symIdx loader.Sym, i int) loader.Sym { + off := decodetypeStructFieldArrayOff2(ldr, arch, symIdx, i) + // FIXME: it's inefficient to read the relocations each time. Add some + // sort of cache here, or pass in the relocs. Alternatively we could + // switch to relocs.At() to see if that performs better. + relocs := ldr.Relocs(symIdx) + rslice := relocs.ReadAll(nil) + return decodeRelocSym2(ldr, symIdx, rslice, int32(off+arch.PtrSize)) +} + +func decodetypeStructFieldOffsAnon2(ldr *loader.Loader, arch *sys.Arch, symIdx loader.Sym, i int) int64 { + off := decodetypeStructFieldArrayOff2(ldr, arch, symIdx, i) + data := ldr.Data(symIdx) + return int64(decodeInuxi(arch, data[off+2*arch.PtrSize:], arch.PtrSize)) +} -- 2.48.1