Skip to content

cmd/compiler,cmd/link: cannot distinguish between parameters and return values of DW_TAG_subroutine_type #48812

@u2386

Description

@u2386

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

$ go version
go version go1.16.5 linux/amd64

Does this issue reproduce with the latest release?

haven't tried yet.

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/hugo/.cache/go-build"
GOENV="/home/hugo/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/hugo/.gvm/pkgsets/go1.16.5/global/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/hugo/.gvm/pkgsets/go1.16.5/global"
GOPRIVATE=""
GOPROXY="https://goproxy.io,direct"
GOROOT="/home/hugo/.gvm/gos/go1.16.5"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/hugo/.gvm/gos/go1.16.5/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/hugo/Repository/go-sample/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2173517011=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Build the code below with go build -gcflags='-l -N':

package main

type Foo struct {
	FooBar func(int) int
}

func main() {
	_ = Foo{
		FooBar: func(i int) int { return i + 1 },
	}
}

The DWARF information for main.Foo.FooBar is DW_TAG_subroutine_type which has two DW_TAG_formal_parameter children and one TAG 0 (invalid).

It is difficult to distinguish the parameters of a function from the return value just from the DWARF data.

What did you expect to see?

Q: Is there an attribute or something to indicate whether or not a tag is a parameter or a return value.

What did you see instead?

DWARF data related:

 <1><3e201>: Abbrev Number: 30 (DW_TAG_subroutine_type)
    <3e202>   DW_AT_name        : func(int) int
    <3e210>   DW_AT_byte_size   : 8
    <3e211>   Unknown AT value: 2900: 19
    <3e212>   Unknown AT value: 2904: 0x0
 <2><3e21a>: Abbrev Number: 23 (DW_TAG_formal_parameter)
    <3e21b>   DW_AT_type        : <0x3e238>
 <2><3e21f>: Abbrev Number: 23 (DW_TAG_formal_parameter)
    <3e220>   DW_AT_type        : <0x3e248>
 <2><3e224>: Abbrev Number: 0

 <1><3e225>: Abbrev Number: 38 (DW_TAG_typedef)
    <3e226>   DW_AT_name        : func(int) int
    <3e234>   DW_AT_type        : <0x3e201>

...

 <1><3e1d0>: Abbrev Number: 37 (DW_TAG_structure_type)
    <3e1d1>   DW_AT_name        : main.Foo
    <3e1da>   DW_AT_byte_size   : 8
    <3e1db>   Unknown AT value: 2900: 25
    <3e1dc>   Unknown AT value: 2904: 0x0
 <2><3e1e4>: Abbrev Number: 22 (DW_TAG_member)
    <3e1e5>   DW_AT_name        : FooBar
    <3e1ec>   DW_AT_data_member_location: 0
    <3e1ed>   DW_AT_type        : <0x3e225>
    <3e1f1>   Unknown AT value: 2903: 0
 <2><3e1f2>: Abbrev Number: 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions