Skip to content

Commit 0eacf8c

Browse files
committed
cmd/compile: add DWARF reg defs & fix 32-bit location list bug
Before DWARF location lists can be turned on, 3 bugs need fixing. This CL addresses two -- lack of register definitions for various architectures, and bugs on 32-bit platforms. The third bug comes later. Passes GO_GCFLAGS=-dwarflocationlists ./run.bash -no-rebuild (-no-rebuild because the map dependence causes trouble) Change-Id: I4223b48ade84763e4b048e4aeb81149f082c7bc7 Reviewed-on: https://go-review.googlesource.com/99255 Run-TryBot: David Chase <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 99c3021 commit 0eacf8c

File tree

9 files changed

+132
-43
lines changed

9 files changed

+132
-43
lines changed

src/cmd/compile/internal/ssa/debug.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ func decodeValue(ctxt *obj.Link, word uint64) (ID, ID) {
10011001
if ctxt.Arch.PtrSize != 4 {
10021002
panic("unexpected pointer size")
10031003
}
1004-
return ID(word >> 16), ID(word)
1004+
return ID(word >> 16), ID(int16(word))
10051005
}
10061006

10071007
// Append a pointer-sized uint to buf.

src/cmd/internal/obj/arm/a.out.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ const (
110110
FREGTMP = REG_F15
111111
)
112112

113+
// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0040b/IHI0040B_aadwarf.pdf
114+
var ARMDWARFRegisters = map[int16]int16{}
115+
116+
func init() {
117+
// f assigns dwarfregisters[from:to] = (base):(step*(to-from)+base)
118+
f := func(from, to, base, step int16) {
119+
for r := int16(from); r <= to; r++ {
120+
ARMDWARFRegisters[r] = step*(r-from) + base
121+
}
122+
}
123+
f(REG_R0, REG_R15, 0, 1)
124+
f(REG_F0, REG_F15, 64, 2) // Use d0 through D15, aka S0, S2, ..., S30
125+
}
126+
113127
const (
114128
C_NONE = iota
115129
C_REG

src/cmd/internal/obj/arm/obj5.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -885,10 +885,11 @@ var unaryDst = map[obj.As]bool{
885885
}
886886

887887
var Linkarm = obj.LinkArch{
888-
Arch: sys.ArchARM,
889-
Init: buildop,
890-
Preprocess: preprocess,
891-
Assemble: span5,
892-
Progedit: progedit,
893-
UnaryDst: unaryDst,
888+
Arch: sys.ArchARM,
889+
Init: buildop,
890+
Preprocess: preprocess,
891+
Assemble: span5,
892+
Progedit: progedit,
893+
UnaryDst: unaryDst,
894+
DWARFRegisters: ARMDWARFRegisters,
894895
}

src/cmd/internal/obj/mips/a.out.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,24 @@ const (
201201
FREGRET = REG_F0
202202
)
203203

204+
// https://llvm.org/svn/llvm-project/llvm/trunk/lib/Target/Mips/MipsRegisterInfo.td search for DwarfRegNum
205+
// https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/config/mips/mips.c?view=co&revision=258099&content-type=text%2Fplain search for mips_dwarf_regno
206+
// For now, this is adequate for both 32 and 64 bit.
207+
var MIPSDWARFRegisters = map[int16]int16{}
208+
209+
func init() {
210+
// f assigns dwarfregisters[from:to] = (base):(to-from+base)
211+
f := func(from, to, base int16) {
212+
for r := int16(from); r <= to; r++ {
213+
MIPSDWARFRegisters[r] = (r - from) + base
214+
}
215+
}
216+
f(REG_R0, REG_R31, 0)
217+
f(REG_F0, REG_F31, 32) // For 32-bit MIPS, compiler only uses even numbered registers -- see cmd/compile/internal/ssa/gen/MIPSOps.go
218+
MIPSDWARFRegisters[REG_HI] = 64
219+
MIPSDWARFRegisters[REG_LO] = 65
220+
}
221+
204222
const (
205223
BIG = 32766
206224
)

src/cmd/internal/obj/mips/obj0.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,33 +1411,37 @@ func (c *ctxt0) compound(p *obj.Prog) bool {
14111411
}
14121412

14131413
var Linkmips64 = obj.LinkArch{
1414-
Arch: sys.ArchMIPS64,
1415-
Init: buildop,
1416-
Preprocess: preprocess,
1417-
Assemble: span0,
1418-
Progedit: progedit,
1414+
Arch: sys.ArchMIPS64,
1415+
Init: buildop,
1416+
Preprocess: preprocess,
1417+
Assemble: span0,
1418+
Progedit: progedit,
1419+
DWARFRegisters: MIPSDWARFRegisters,
14191420
}
14201421

14211422
var Linkmips64le = obj.LinkArch{
1422-
Arch: sys.ArchMIPS64LE,
1423-
Init: buildop,
1424-
Preprocess: preprocess,
1425-
Assemble: span0,
1426-
Progedit: progedit,
1423+
Arch: sys.ArchMIPS64LE,
1424+
Init: buildop,
1425+
Preprocess: preprocess,
1426+
Assemble: span0,
1427+
Progedit: progedit,
1428+
DWARFRegisters: MIPSDWARFRegisters,
14271429
}
14281430

14291431
var Linkmips = obj.LinkArch{
1430-
Arch: sys.ArchMIPS,
1431-
Init: buildop,
1432-
Preprocess: preprocess,
1433-
Assemble: span0,
1434-
Progedit: progedit,
1432+
Arch: sys.ArchMIPS,
1433+
Init: buildop,
1434+
Preprocess: preprocess,
1435+
Assemble: span0,
1436+
Progedit: progedit,
1437+
DWARFRegisters: MIPSDWARFRegisters,
14351438
}
14361439

14371440
var Linkmipsle = obj.LinkArch{
1438-
Arch: sys.ArchMIPSLE,
1439-
Init: buildop,
1440-
Preprocess: preprocess,
1441-
Assemble: span0,
1442-
Progedit: progedit,
1441+
Arch: sys.ArchMIPSLE,
1442+
Init: buildop,
1443+
Preprocess: preprocess,
1444+
Assemble: span0,
1445+
Progedit: progedit,
1446+
DWARFRegisters: MIPSDWARFRegisters,
14431447
}

src/cmd/internal/obj/ppc64/a.out.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,29 @@ const (
255255
FREGEXT = REG_F26 /* first external register */
256256
)
257257

258+
// OpenPOWER ABI for Linux Supplement Power Architecture 64-Bit ELF V2 ABI
259+
// https://openpowerfoundation.org/?resource_lib=64-bit-elf-v2-abi-specification-power-architecture
260+
var PPC64DWARFRegisters = map[int16]int16{}
261+
262+
func init() {
263+
// f assigns dwarfregister[from:to] = (base):(to-from+base)
264+
f := func(from, to, base int16) {
265+
for r := int16(from); r <= to; r++ {
266+
PPC64DWARFRegisters[r] = r - from + base
267+
}
268+
}
269+
f(REG_R0, REG_R31, 0)
270+
f(REG_F0, REG_F31, 32)
271+
f(REG_V0, REG_V31, 77)
272+
f(REG_CR0, REG_CR7, 68)
273+
274+
f(REG_VS0, REG_VS31, 32) // overlaps F0-F31
275+
f(REG_VS32, REG_VS63, 77) // overlaps V0-V31
276+
PPC64DWARFRegisters[REG_LR] = 65
277+
PPC64DWARFRegisters[REG_CTR] = 66
278+
PPC64DWARFRegisters[REG_XER] = 76
279+
}
280+
258281
/*
259282
* GENERAL:
260283
*

src/cmd/internal/obj/ppc64/obj9.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,17 +1056,19 @@ func (c *ctxt9) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
10561056
}
10571057

10581058
var Linkppc64 = obj.LinkArch{
1059-
Arch: sys.ArchPPC64,
1060-
Init: buildop,
1061-
Preprocess: preprocess,
1062-
Assemble: span9,
1063-
Progedit: progedit,
1059+
Arch: sys.ArchPPC64,
1060+
Init: buildop,
1061+
Preprocess: preprocess,
1062+
Assemble: span9,
1063+
Progedit: progedit,
1064+
DWARFRegisters: PPC64DWARFRegisters,
10641065
}
10651066

10661067
var Linkppc64le = obj.LinkArch{
1067-
Arch: sys.ArchPPC64LE,
1068-
Init: buildop,
1069-
Preprocess: preprocess,
1070-
Assemble: span9,
1071-
Progedit: progedit,
1068+
Arch: sys.ArchPPC64LE,
1069+
Init: buildop,
1070+
Preprocess: preprocess,
1071+
Assemble: span9,
1072+
Progedit: progedit,
1073+
DWARFRegisters: PPC64DWARFRegisters,
10721074
}

src/cmd/internal/obj/s390x/a.out.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,32 @@ const (
149149
REGSP = REG_R15 // stack pointer
150150
)
151151

152+
// LINUX for zSeries ELF Application Binary Interface Supplement
153+
// http://refspecs.linuxfoundation.org/ELF/zSeries/lzsabi0_zSeries/x1472.html
154+
var S390XDWARFRegisters = map[int16]int16{}
155+
156+
func init() {
157+
// f assigns dwarfregisters[from:to by step] = (base):((to-from)/step+base)
158+
f := func(from, step, to, base int16) {
159+
for r := int16(from); r <= to; r += step {
160+
S390XDWARFRegisters[r] = (r-from)/step + base
161+
}
162+
}
163+
f(REG_R0, 1, REG_R15, 0)
164+
165+
f(REG_F0, 2, REG_F6, 16)
166+
f(REG_F1, 2, REG_F7, 20)
167+
f(REG_F8, 2, REG_F14, 24)
168+
f(REG_F9, 2, REG_F15, 28)
169+
170+
f(REG_V0, 2, REG_V6, 16) // V0:15 aliased to F0:15
171+
f(REG_V1, 2, REG_V7, 20) // TODO what about V16:31?
172+
f(REG_V8, 2, REG_V14, 24)
173+
f(REG_V9, 2, REG_V15, 28)
174+
175+
f(REG_AR0, 1, REG_AR15, 48)
176+
}
177+
152178
const (
153179
BIG = 32768 - 8
154180
DISP12 = 4096

src/cmd/internal/obj/s390x/objz.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -720,10 +720,11 @@ var unaryDst = map[obj.As]bool{
720720
}
721721

722722
var Links390x = obj.LinkArch{
723-
Arch: sys.ArchS390X,
724-
Init: buildop,
725-
Preprocess: preprocess,
726-
Assemble: spanz,
727-
Progedit: progedit,
728-
UnaryDst: unaryDst,
723+
Arch: sys.ArchS390X,
724+
Init: buildop,
725+
Preprocess: preprocess,
726+
Assemble: spanz,
727+
Progedit: progedit,
728+
UnaryDst: unaryDst,
729+
DWARFRegisters: S390XDWARFRegisters,
729730
}

0 commit comments

Comments
 (0)