Skip to content

cmd/compile: add string constants to DWARF #67744

Open
@Benoit12345

Description

@Benoit12345

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

Activity

randall77

randall77 commented on May 31, 2024

@randall77
Contributor
aarzilli

aarzilli commented on May 31, 2024

@aarzilli
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

Benoit12345 commented on May 31, 2024

@Benoit12345
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

aarzilli commented on May 31, 2024

@aarzilli
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.

changed the title [-]src/cmd/compile/internal/gc/obj.go: dumpGlobalConst dumps only integer constant[/-] [+]cmd/compile: only integer consts are exported in DWARF[/+] on Jun 2, 2024
mknyszek

mknyszek commented on Jun 3, 2024

@mknyszek
Contributor

CC @golang/compiler

added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Jun 3, 2024
added this to the Backlog milestone on Jun 3, 2024
changed the title [-]cmd/compile: only integer consts are exported in DWARF[/-] [+]cmd/compile: add string constants to DWARF[/+] on Jun 5, 2024
added
FeatureRequestIssues asking for a new feature that does not need a proposal.
on Jun 5, 2024
modified the milestones: Backlog, Unplanned on Jun 5, 2024
Zxilly

Zxilly commented on Jun 9, 2024

@Zxilly
Member

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

Zxilly commented on Jun 9, 2024

@Zxilly
Member

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?

gopherbot

gopherbot commented on Aug 9, 2024

@gopherbot
Contributor

Change https://go.dev/cl/604101 mentions this issue: cmd/compile,cmd/link: export string global consts to DWARF

linked a pull request that will close this issue on Jun 1, 2025
gopherbot

gopherbot commented on Jun 1, 2025

@gopherbot
Contributor

Change https://go.dev/cl/677915 mentions this issue: cmd: emit dwarf for string constants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

      Participants

      @aarzilli@mknyszek@randall77@gopherbot@Zxilly

      Issue actions

        cmd/compile: add string constants to DWARF · Issue #67744 · golang/go