Skip to content

cmd: emit dwarf for string constants #73940

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
keep type name
  • Loading branch information
Zxilly committed Jun 3, 2025
commit 182a289ef3d4d9bdf05ceef4c02d4e71f567583f
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func dumpGlobalConst(n *ir.Name) {
if t.IsInteger() {
base.Ctxt.DwarfIntConst(n.Sym().Name, types.TypeSymName(t), ir.IntVal(t, v))
} else if t.IsString() {
base.Ctxt.DwarfStringConst(n.Sym().Name, ir.StringVal(n))
base.Ctxt.DwarfStringConst(n.Sym().Name, types.TypeSymName(t), ir.StringVal(n))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/cmd/internal/dwarf/dwarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const InfoPrefix = "go:info."
const ConstInfoPrefix = "go:constinfo."

// ConstStringInfoPrefix is the prefix for all symbols containing
// DWARF info entries that referred by string constants.
const ConstStringInfoPrefix = "string$const."
// DWARF info entries that are referred by string constants.
const ConstStringInfoPrefix = "$const."

// CUInfoPrefix is the prefix for symbols containing information to
// populate the DWARF compilation unit info entries.
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/internal/obj/dwarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,12 @@ func (ctxt *Link) DwarfIntConst(name, typename string, val int64) {

// DwarfStringConst creates a link symbol for a string constant with the
// given name and value.
func (ctxt *Link) DwarfStringConst(name, value string) {
func (ctxt *Link) DwarfStringConst(name, typename, value string) {
s := ctxt.ensureConstInfoSym()
if s == nil {
return
}
typSym := ctxt.Lookup(dwarf.InfoPrefix + dwarf.ConstStringInfoPrefix + strconv.Itoa(len(value)))
typSym := ctxt.Lookup(dwarf.InfoPrefix + dwarf.ConstStringInfoPrefix + typename + "." + strconv.Itoa(len(value)))
dwarf.PutStringConst(dwCtxt{ctxt}, s, typSym, ctxt.Pkgpath+"."+name, value)
}

Expand Down
10 changes: 7 additions & 3 deletions src/cmd/link/internal/ld/dwarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -1188,12 +1188,16 @@ func (d *dwctxt) genConstStringType(name string) {
if d.find(name) != 0 {
return
}
size, err := strconv.Atoi(name[len(dwarf.ConstStringInfoPrefix):])
i := strings.LastIndex(name, ".")
if i < 0 {
log.Fatalf("error: invalid constant string type name %q", name)
}
size, err := strconv.ParseInt(name[i+1:], 10, 64)
if err != nil {
log.Fatalf("error: invalid constant string size %q: %v", name, err)
log.Fatalf("error: invalid constant string type name %q: %v", name, err)
}
die := d.newdie(&dwtypes, dwarf.DW_ABRV_CONSTANT_STRINGTYPE, name)
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, int64(size), 0)
newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, size, 0)
}

func (d *dwctxt) importInfoSymbol(dsym loader.Sym) {
Expand Down