Skip to content

Commit 8808ecf

Browse files
authored
feat: support go 1.24 and swiss table feature (#35)
* feat: support go 1.24 * feat: support swiss table * fix: bugs * feat: map fallback searching * fix: classic map bug * ci: fix issue * ci: fix issue * ci: fix issue * chore: update version * chore: add test data
1 parent 770b82c commit 8808ecf

13 files changed

Lines changed: 906 additions & 471 deletions

File tree

.github/workflows/pr-check.yml

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,34 @@ on: [ pull_request ]
44

55
jobs:
66
compliant:
7-
runs-on: [ self-hosted, X64 ]
7+
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
9+
- uses: actions/checkout@v4
1010

1111
- name: Check License Header
1212
uses: apache/skywalking-eyes/header@v0.4.0
1313
env:
1414
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1515

1616
- name: Check Spell
17-
uses: crate-ci/typos@master
17+
uses: crate-ci/typos@v1.13.14
1818

19-
staticcheck:
20-
runs-on: [ self-hosted, X64 ]
19+
golangci-lint:
20+
runs-on: [ Linux, X64 ]
2121
steps:
22-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@v4
2323
- name: Set up Go
24-
uses: actions/setup-go@v3
24+
uses: actions/setup-go@v5
2525
with:
26-
go-version: "1.22"
27-
28-
- uses: actions/cache@v3
29-
with:
30-
path: ~/go/pkg/mod
31-
key: reviewdog-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
32-
restore-keys: |
33-
reviewdog-${{ runner.os }}-go-
34-
35-
- uses: reviewdog/action-staticcheck@v1
36-
with:
37-
github_token: ${{ secrets.github_token }}
38-
# Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
39-
reporter: github-pr-review
40-
# Report all results.
41-
filter_mode: nofilter
42-
# Exit with 1 when it finds at least one finding.
43-
fail_on_error: true
44-
# Set staticcheck flags
45-
staticcheck_flags: -checks=inherit,-SA1029
46-
47-
lint:
48-
runs-on: [ self-hosted, X64 ]
49-
steps:
50-
- uses: actions/checkout@v3
51-
- name: Set up Go
52-
uses: actions/setup-go@v3
53-
with:
54-
go-version: "1.22"
26+
go-version: stable
27+
# for self-hosted, the cache path is shared across projects
28+
# and it works well without the cache of github actions
29+
# Enable it if we're going to use Github only
30+
cache: false
5531

5632
- name: Golangci Lint
5733
# https://golangci-lint.run/
58-
uses: golangci/golangci-lint-action@v3
34+
uses: golangci/golangci-lint-action@v6
5935
with:
6036
version: latest
37+
only-new-issues: true

.github/workflows/tests.yml

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,53 @@ name: Tests
33
on: [ push, pull_request ]
44

55
jobs:
6-
unit-benchmark-test:
6+
unit-test-x64:
77
strategy:
88
matrix:
9-
go: [ "1.21", "1.22", "1.23" ]
10-
os: [ X64 ]
11-
runs-on: ${{ matrix.os }}
9+
go: [ "1.21", "1.22", "1.23", "1.24" ]
10+
runs-on: [ Linux, X64 ]
1211
steps:
13-
- uses: actions/checkout@v3
14-
12+
- uses: actions/checkout@v4
1513
- name: Set up Go
16-
uses: actions/setup-go@v3
14+
uses: actions/setup-go@v5
1715
with:
1816
go-version: ${{ matrix.go }}
19-
17+
cache: false # don't use cache for self-hosted runners
2018
- name: Unit Test
21-
run: go test -race -covermode=atomic -coverprofile=coverage.out ./...
19+
run: go test -race ./...
20+
- name: Benchmark
21+
run: go test -bench=. -benchmem -run=none ./...
2222

23+
unit-test-arm:
24+
strategy:
25+
matrix:
26+
go: [ "1.21", "1.22", "1.23", "1.24" ]
27+
runs-on: [ ARM64 ] # It's OK under Linux or macOS
28+
steps:
29+
- uses: actions/checkout@v4
30+
- name: Set up Go
31+
uses: actions/setup-go@v5
32+
with:
33+
go-version: ${{ matrix.go }}
34+
cache: false # don't use cache for self-hosted runners
35+
- name: Unit Test
36+
run: go test -race ./...
2337
- name: Benchmark
2438
run: go test -bench=. -benchmem -run=none ./...
39+
40+
codecov:
41+
needs: [ unit-test-x64, unit-test-arm ]
42+
runs-on: [ Linux, X64 ]
43+
steps:
44+
- uses: actions/checkout@v4
45+
- name: Set up Go
46+
uses: actions/setup-go@v5
47+
with:
48+
go-version: "1.23"
49+
cache: false # don't use cache for self-hosted runners
50+
- name: Run coverage
51+
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
52+
- name: Upload coverage to Codecov
53+
uses: codecov/codecov-action@v5
54+
with:
55+
flags: unit

.golangci.yaml

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,29 @@
11
# Options for analysis running.
22
run:
3-
# include `vendor` `third_party` `testdata` `examples` `Godeps` `builtin`
4-
skip-dirs-use-default: true
5-
skip-dirs:
6-
skip-files:
7-
- ".*\\.mock\\.go$"
8-
# output configuration options
9-
output:
10-
# Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
11-
format: colored-line-number
12-
# All available settings of specific linters.
3+
timeout: 3m
4+
5+
linters: # https://golangci-lint.run/usage/linters/
6+
disable-all: true
7+
enable:
8+
- gosimple
9+
- govet
10+
- ineffassign
11+
- staticcheck
12+
- unused
13+
- unconvert
14+
- goimports
15+
- gofumpt
16+
1317
# Refer to https://golangci-lint.run/usage/linters
1418
linters-settings:
1519
gofumpt:
1620
# Choose whether to use the extra rules.
1721
# Default: false
1822
extra-rules: true
19-
govet:
20-
# Disable analyzers by name.
21-
# Run `go tool vet help` to see all analyzers.
22-
disable:
23-
- stdmethods
24-
linters:
25-
enable:
26-
- gofumpt
27-
- goimports
28-
- gofmt
29-
disable:
30-
- errcheck
31-
- typecheck
32-
- deadcode
33-
- varcheck
34-
- staticcheck
23+
goimports:
24+
# Put imports beginning with prefix after 3rd-party packages.
25+
# It's a comma-separated list of prefixes.
26+
local-prefixes: github.com/cloudwego/goref
27+
3528
issues:
3629
exclude-use-default: true

.licenserc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ header:
1313
- pkg/proc/protobuf.go
1414
- pkg/proc/region.go
1515
- pkg/proc/variables.go
16+
- pkg/proc/mapiter.go
1617
- testdata
1718

1819
comment: on-failure

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ successfully output to `grf.out`
4444

4545
## Go Version Constraints
4646

47-
- Executable file: go1.17 ~ go1.23.
47+
- Executable file: go1.17 ~ go1.24.
4848
- Compile goref tool: >= go1.21.
4949

5050

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ go 1.21
55
toolchain go1.22.2
66

77
require (
8-
github.com/go-delve/delve v1.23.0
8+
github.com/go-delve/delve v1.24.1
99
github.com/modern-go/reflect2 v1.0.2
10-
github.com/spf13/cobra v1.8.1
10+
github.com/spf13/cobra v1.9.1
1111
)
1212

1313
require (
1414
github.com/cilium/ebpf v0.16.0 // indirect
1515
github.com/hashicorp/golang-lru v1.0.2 // indirect
1616
github.com/inconshreveable/mousetrap v1.1.0 // indirect
1717
github.com/mattn/go-isatty v0.0.20 // indirect
18-
github.com/sirupsen/logrus v1.9.3 // indirect
19-
github.com/spf13/pflag v1.0.5 // indirect
20-
golang.org/x/arch v0.9.0 // indirect
18+
github.com/spf13/pflag v1.0.6 // indirect
19+
golang.org/x/arch v0.11.0 // indirect
2120
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
22-
golang.org/x/sys v0.23.0 // indirect
21+
golang.org/x/sys v0.26.0 // indirect
22+
golang.org/x/telemetry v0.0.0-20241106142447-58a1122356f5 // indirect
2323
gopkg.in/yaml.v3 v3.0.1 // indirect
2424
)

go.sum

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
github.com/cilium/ebpf v0.16.0 h1:+BiEnHL6Z7lXnlGUsXQPPAE7+kenAd4ES8MQ5min0Ok=
22
github.com/cilium/ebpf v0.16.0/go.mod h1:L7u2Blt2jMM/vLAVgjxluxtBKlz3/GWjB0dMOEngfwE=
3-
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
3+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
44
github.com/creack/pty v1.1.20 h1:VIPb/a2s17qNeQgDnkfZC35RScx+blkKF8GV68n80J4=
55
github.com/creack/pty v1.1.20/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
6-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
8-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9-
github.com/go-delve/delve v1.23.0 h1:jYgZISZ14KAO3ys8kD07kjrowrygE9F9SIwnpz9xXys=
10-
github.com/go-delve/delve v1.23.0/go.mod h1:S3SLuEE2mn7wipKilTvk1p9HdTMnXXElcEpiZ+VcuqU=
6+
github.com/go-delve/delve v1.24.1 h1:RjR/fbsxsPFpvFl3cGtQbM8asNrKEiG9mVp4RtU+tnE=
7+
github.com/go-delve/delve v1.24.1/go.mod h1:kJk12wo6PqzWknTP6M+Pg3/CrNhFMZvNq1iHESKkhv8=
118
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=
129
github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
1310
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
@@ -32,35 +29,27 @@ github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U
3229
github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA=
3330
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
3431
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
35-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
36-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3732
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
3833
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
3934
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
40-
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
41-
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
42-
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
43-
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
44-
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
45-
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
46-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
47-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
48-
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
49-
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
50-
golang.org/x/arch v0.9.0 h1:ub9TgUInamJ8mrZIGlBG6/4TqWeMszd4N8lNorbrr6k=
51-
golang.org/x/arch v0.9.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
35+
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
36+
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
37+
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
38+
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
39+
golang.org/x/arch v0.11.0 h1:KXV8WWKCXm6tRpLirl2szsO5j/oOODwZf4hATmGVNs4=
40+
golang.org/x/arch v0.11.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
5241
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
5342
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
5443
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
5544
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
56-
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
57-
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
58-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
45+
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
46+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
5947
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
60-
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
61-
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
48+
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
49+
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
50+
golang.org/x/telemetry v0.0.0-20241106142447-58a1122356f5 h1:TCDqnvbBsFapViksHcHySl/sW4+rTGNIAoJJesHRuMM=
51+
golang.org/x/telemetry v0.0.0-20241106142447-58a1122356f5/go.mod h1:8nZWdGp9pq73ZI//QJyckMQab3yq7hoWi7SI0UIusVI=
6252
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
6353
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
64-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6554
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
6655
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

pkg/proc/heap.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ type HeapScope struct {
161161
finalMarks []finalMarkParam
162162

163163
funcExtraMap map[*proc.Function]funcExtra
164+
165+
// for go1.24+, offset field of runtime.special type is uintptr
166+
specialOffsetUintptrType uint8 // 0: not sure, 1: uintptr, 2: uint16
164167
}
165168

166169
func (s *HeapScope) readHeap() error {
@@ -596,7 +599,19 @@ func (s *HeapScope) addSpecial(sp *region, spi *spanInfo, kindSpecialFinalizer u
596599
continue
597600
}
598601
var fin finalizer
599-
p := spi.base.Add(int64(special.Field("offset").Uint16()) / spi.elemSize * spi.elemSize)
602+
if s.specialOffsetUintptrType == 0 {
603+
if t, ok := special.Field("offset").typ.(*godwarf.UintType); ok && t.Size() == 8 {
604+
s.specialOffsetUintptrType = 1
605+
} else {
606+
s.specialOffsetUintptrType = 2
607+
}
608+
}
609+
var p Address
610+
if s.specialOffsetUintptrType == 1 {
611+
p = spi.base.Add(int64(special.Field("offset").Uintptr()) / spi.elemSize * spi.elemSize)
612+
} else {
613+
p = spi.base.Add(int64(special.Field("offset").Uint16()) / spi.elemSize * spi.elemSize)
614+
}
600615
fin.p = p
601616
spf := *special
602617
spf.typ = spty

0 commit comments

Comments
 (0)