Skip to content

cmd/compile: mangled DWARF location for incoming string parameter #47354

@thanm

Description

@thanm

What version of Go are you using (go version)?

This is with Go 1.17/tip.

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

Build this program:

package main

var G int

//go:noinline
func docall(f func()) {
	f()
}

//go:noinline
func another(x int) {
	println(G)
}

//go:noinline
func livestring(s string) {
	docall(func() {
		println("s is", s)
	})
	G++
	another(0)
}

//go:noinline
func livestring2(s string) {
	docall(func() {
		println("s is", s)
	})
	G++
	another(int(s[0]))
}

func main() {
	livestring("foo")
	livestring2("bar")
}

If you stop in 'livestring2", the DWARF location expression emitted for the parameter 's' is damaged/incorrect.

$ gdb livestring
...
(gdb) b main.livestring2
Breakpoint 1 at 0x455680: file /usr/local/google/home/thanm/livestring.go, line 25.
(gdb) run
Starting program: /usr/local/google/home/thanm/livestring 
...
Thread 1 "livestring" hit Breakpoint 1, main.livestring2 (s=<error reading variable: access outside bounds of object referenced via synthetic pointer>) at /usr/local/google/home/thanm/livestring.go:25
25	func livestring2(s string) {
(gdb) p s
access outside bounds of object referenced via synthetic pointer
(gdb) info address s
Symbol "s" is multi-location:
  Base address 0x455680  Range 0x455680-0x4556c8: a variable in $rax [8-byte piece], and a variable in $rax [8-byte piece], and a complex DWARF expression:
     0: DW_OP_fbreg 8
    [8-byte piece], and a complex DWARF expression:
     0: DW_OP_fbreg 8
    [8-byte piece]
  Range 0x4556c8-0x45571b: a complex DWARF expression:
     0: DW_OP_call_frame_cfa
    [8-byte piece], and a complex DWARF expression:
     0: DW_OP_call_frame_cfa
    [8-byte piece], and a complex DWARF expression:
     0: DW_OP_fbreg 8
    [8-byte piece], and a complex DWARF expression:
     0: DW_OP_fbreg 8
    [8-byte piece]
.
(gdb) 

What did you expect to see?

Sane location expression

What did you see instead?

Malformed location expression. We should not be seeing 4 pieces, this is only a 2-piece variable. Something is going wrong somewhere along the line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions