Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: add string constants to DWARF #67744

Open
Benoit12345 opened this issue May 31, 2024 · 7 comments
Open

cmd/compile: add string constants to DWARF #67744

Benoit12345 opened this issue May 31, 2024 · 7 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@Benoit12345
Copy link

Go version

go version go1.22.3 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/.cache/go-build'
GOENV='/home/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.3'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/user/1000/go-build3235747414=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I tried to view the value of different types of const values with dlv.
Code:

package main

import "fmt"

const myValueStr = "try"
const myValueInt = 12
const myValueFloat = 1.2

func main() {
fmt.Println(myValueStr, myValueInt, myValueFloat)
}

What did you see happen?

I obtain a different behavior depending of the type of the constant.

Debug:

dlv exec main
(dlv) print main.constValueInt
12
(dlv) print main.constValueStr
Command failed: could not find symbol value for main
(dlv) print main.constValueFloat
Command failed: could not find symbol value for main

Analyze:

objdump -W main | grep -i constV
<2547> DW_AT_name : main.constValueInt

By analyzing Go ompiler code, we can see into src/cmd/compile/internal/gc/obj.go:163 that's the func dumpGlobalConst exports only integer const "for now" (ie. comment line 172).

What did you expect to see?

I expect to see all const values.

Debug:

dlv exec main
(dlv) print main.constValueInt
12
(dlv) print main.constValueStr
"try"
(dlv) print main.constValueFloat
1.2

Analyze:

objdump -W main | grep -i constV
<2547> DW_AT_name : main.constValueInt
<2547> DW_AT_name : main.constValueStr
<2547> DW_AT_name : main.constValueFloat

@randall77
Copy link
Contributor

@aarzilli

@aarzilli
Copy link
Contributor

I think this had been discussed somewhere in another issue, but I can't find it, so I'll restate it: when I did the thing that exports integers to dwarf I didn't include string constants because I thought it would bloat too much the executable size.

@Benoit12345
Copy link
Author

I found your message about the binary size here: https://go-review.googlesource.com/c/go/+/61019 (comment Patchset 5 | Sep 08, 2017 10:01 PM ).
I understand the perf impact on binary size. In another hand, that's quite difficult to understand for developpers why some const are watched and some others cannot be consulted into an IDE debug session.
If I understand well (sorry, I'm not an expert of the Go compiler), the dwarf debug_info struct is still not compressed ? maybe it could be a solution if impacts on compile time are not so huge... And/Or maybe the increasing binary size could be "acceptable" while compiling optimizations are not enabled ?

@aarzilli
Copy link
Contributor

If I understand well (sorry, I'm not an expert of the Go compiler), the dwarf debug_info struct is still not compressed ?

It is compressed but it doesn't change my opinion on the matter: integer constants are useful because we can use them to the value of variables, which would otherwise be very opaque. The same does not go for string constants. But keep in mind that this is just my opinion.

@seankhliao seankhliao changed the title src/cmd/compile/internal/gc/obj.go: dumpGlobalConst dumps only integer constant cmd/compile: only integer consts are exported in DWARF Jun 2, 2024
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jun 2, 2024
@mknyszek
Copy link
Contributor

mknyszek commented Jun 3, 2024

CC @golang/compiler

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 3, 2024
@mknyszek mknyszek added this to the Backlog milestone Jun 3, 2024
@mknyszek mknyszek changed the title cmd/compile: only integer consts are exported in DWARF cmd/compile: add string constants to DWARF Jun 5, 2024
@mknyszek mknyszek modified the milestones: Backlog, Unplanned Jun 5, 2024
@Zxilly
Copy link
Contributor

Zxilly commented Jun 9, 2024

I'm working on go-size-analyzer and try to extract some info from dwarf. I also met this problem. Sometimes constant string can be very large if the programmer use the tool like bindata. But the info of this part was ommitted from dwarf.

@Zxilly
Copy link
Contributor

Zxilly commented Jun 9, 2024

Storing the full const string would lead to excessive size, maybe we could store the offset in const against go:string.*? Or create a new type of dwarf pointing to the StringHeader?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Development

No branches or pull requests

6 participants