Skip to content

Commit 88e5d89

Browse files
authored
Merge pull request #55 from parca-dev/go-mem-fix
Go version detection tweaks
2 parents af4ab26 + ede5993 commit 88e5d89

File tree

3 files changed

+12
-39
lines changed

3 files changed

+12
-39
lines changed

interpreter/golang/golang.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,14 @@ func Loader(_ interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interprete
6666

6767
offsets, ok := allOffsets[majorMinor]
6868
if !ok {
69-
// Info instead of warn: this is often going to be fine,
70-
// as the offsets tend not to change every release cycle.
71-
//
72-
// TODO: Reword the message if we upstream this,
73-
// since it mentions `parca-agent` by name.
74-
log.Infof("version %s unknown; using offsets for latest known Go version %s."+
69+
// If we don't know this version its probably a new version and the latest offsets
70+
// are our best bet.
71+
log.Warnf("version %s unknown; using offsets for latest known Go version %s."+
7572
"If Go traceID integration and other custom labels support is buggy,"+
76-
" try upgrading parca-agent to the latest version.", goVersion, defaultVersion)
73+
" try upgrading to the latest profiler version.", goVersion, latestVersion)
7774
return data{
7875
goVersion: goVersion,
79-
offsets: allOffsets[defaultVersion],
76+
offsets: allOffsets[latestVersion],
8077
}, nil
8178
}
8279

interpreter/golang/readelf.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,13 @@ package golang // import "go.opentelemetry.io/ebpf-profiler/interpreter/golang"
22

33
import (
44
"bytes"
5-
"debug/elf"
65
"encoding/binary"
76
"errors"
87
"io"
98

109
"go.opentelemetry.io/ebpf-profiler/libpf/pfelf"
1110
)
1211

13-
func getVersionSection(f *pfelf.File) io.ReaderAt {
14-
if sec := f.Section(".go.buildinfo"); sec != nil {
15-
return sec
16-
}
17-
for _, seg := range f.Progs {
18-
if seg.Type == elf.PT_LOAD && seg.Flags&(elf.PF_X|elf.PF_W) == elf.PF_W {
19-
return &seg
20-
}
21-
}
22-
return nil
23-
}
24-
2512
var ErrNoGoVersion = errors.New("go version not found")
2613
var buildInfoMagic = []byte("\xff Go buildinf:")
2714

@@ -94,7 +81,7 @@ func readString(x *pfelf.File, ptrSize int,
9481
//
9582
// It is guaranteed not to consume more than 1 MiB of memory.
9683
func ReadGoVersion(f *pfelf.File) (string, error) {
97-
vs := getVersionSection(f)
84+
vs := f.Section(".go.buildinfo")
9885
if vs == nil {
9986
return "", ErrNoGoVersion
10087
}

interpreter/golang/runtime_data.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,14 @@ import "C"
66

77
// defaultVersion is used if the go binary has an unrecognized major+minor version.
88
// Consider bumping this whenever a new version of Go is released.
9-
var defaultVersion = "go1.23"
9+
var latestVersion = "go1.24"
1010

11+
// Offsets come from DWARF debug information:
12+
// https://github.com/parca-dev/parca-agent/blob/2815ded21704934c/pkg/runtime/golang/golang.go#L85
13+
// However since DWARF information can be stripped we record them here.
14+
// TODO: Should we look for DWARF information to support new versions
15+
// automatically when available?
1116
var allOffsets = map[string]C.GoCustomLabelsOffsets{
12-
"go1.11": {
13-
m_offset: 48,
14-
curg: 192,
15-
labels: 344,
16-
hmap_count: 0,
17-
hmap_log2_bucket_count: 9,
18-
hmap_buckets: 16,
19-
},
20-
"go1.12": {
21-
m_offset: 48,
22-
curg: 192,
23-
labels: 344,
24-
hmap_count: 0,
25-
hmap_log2_bucket_count: 9,
26-
hmap_buckets: 16,
27-
},
2817
"go1.13": {
2918
m_offset: 48,
3019
curg: 192,

0 commit comments

Comments
 (0)