Skip to content

Commit 3042a47

Browse files
committed
Fix linting errors
1 parent 4bdbd37 commit 3042a47

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

reporter/extract_symbols/main.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
2+
// Copyright 2024 Datadog, Inc.
3+
14
package main
25

36
import (
47
"context"
58
"fmt"
69
"os"
710

8-
"github.com/DataDog/dd-otel-host-profiler/reporter"
911
"go.opentelemetry.io/ebpf-profiler/libpf/pfelf"
12+
13+
"github.com/DataDog/dd-otel-host-profiler/reporter"
1014
)
1115

1216
func extractDebugInfos(elfFile, outFile string) error {
1317
ef, err := pfelf.Open(elfFile)
1418
if err != nil {
15-
return fmt.Errorf("failed to open elf file: %v", err)
19+
return fmt.Errorf("failed to open elf file: %w", err)
1620
}
1721
defer ef.Close()
1822
goPCLnTabInfo, err := reporter.FindGoPCLnTab(ef, true)
1923
if err != nil {
20-
return fmt.Errorf("failed to find pclntab: %v", err)
24+
return fmt.Errorf("failed to find pclntab: %w", err)
2125
}
2226

2327
if goPCLnTabInfo != nil {

reporter/pclntab.go

+27-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
2+
// Copyright 2024 Datadog, Inc.
3+
14
package reporter
25

36
import (
47
"bytes"
58
"debug/elf"
69
"encoding/binary"
10+
"errors"
711
"fmt"
812
"unsafe"
913

1014
"go.opentelemetry.io/ebpf-profiler/libpf"
1115
"go.opentelemetry.io/ebpf-profiler/libpf/pfelf"
1216
)
1317

14-
type version int
18+
type headerVersion int
1519

1620
const (
17-
verUnknown version = iota
21+
verUnknown headerVersion = iota
1822
ver12
1923
ver116
2024
ver118
@@ -30,9 +34,9 @@ const (
3034
)
3135

3236
type GoPCLnTabInfo struct {
33-
Address uint64 // goPCLnTab address
34-
Data []byte // goPCLnTab data
35-
Version version // gopclntab header version
37+
Address uint64 // goPCLnTab address
38+
Data []byte // goPCLnTab data
39+
Version headerVersion // gopclntab header version
3640
Offsets TableOffsets
3741
GoFuncAddr uint64 // goFunc address
3842
GoFuncData []byte // goFunc data
@@ -84,11 +88,13 @@ type pclntabHeader118 struct {
8488

8589
// pclntabFuncMap is the Golang function symbol table map entry
8690
type pclntabFuncMap struct {
87-
pc uint64
88-
funcOff uint64
91+
pc uint64 //nolint:unused
92+
funcOff uint64 //nolint:unused
8993
}
9094

9195
// pclntabFunc is the Golang function definition (struct _func in the spec) as before Go 1.18.
96+
//
97+
//nolint:unused
9298
type pclntabFunc struct {
9399
startPc uint64
94100
nameOff, argsSize, frameSize int32
@@ -99,6 +105,8 @@ type pclntabFunc struct {
99105
// pclntabFunc118 is the Golang function definition (struct _func in the spec)
100106
// starting with Go 1.18.
101107
// see: go/src/runtime/runtime2.go (struct _func)
108+
//
109+
//nolint:unused
102110
type pclntabFunc118 struct {
103111
entryoff uint32 // start pc, as offset from pcHeader.textStart
104112
nameOff, argsSize, frameSize int32
@@ -128,7 +136,7 @@ func sectionContaining(elfFile *pfelf.File, addr uint64) *pfelf.Section {
128136
return nil
129137
}
130138

131-
func goFuncOffset(v version) (uint32, error) {
139+
func goFuncOffset(v headerVersion) (uint32, error) {
132140
if v < ver118 {
133141
return 0, fmt.Errorf("unsupported version: %v", v)
134142
}
@@ -138,14 +146,14 @@ func goFuncOffset(v version) (uint32, error) {
138146
return 40 * ptrSize, nil
139147
}
140148

141-
func FindModuleData(ef *pfelf.File, goPCLnTabInfo *GoPCLnTabInfo, symtab *libpf.SymbolMap) ([]byte, uint64, error) {
149+
func FindModuleData(ef *pfelf.File, goPCLnTabInfo *GoPCLnTabInfo, symtab *libpf.SymbolMap) (data []byte, address uint64, returnedErr error) {
142150
// First try to locate module data by looking for runtime.firstmoduledata symbol.
143151
if symtab != nil {
144152
if symAddr, err := symtab.LookupSymbolAddress("runtime.firstmoduledata"); err == nil {
145153
addr := uint64(symAddr)
146154
section := sectionContaining(ef, addr)
147155
if section == nil {
148-
return nil, 0, fmt.Errorf("could not find section containing runtime.firstmoduledata")
156+
return nil, 0, errors.New("could not find section containing runtime.firstmoduledata")
149157
}
150158
data, err := section.Data(maxBytesGoPclntab)
151159
if err != nil {
@@ -163,8 +171,6 @@ func FindModuleData(ef *pfelf.File, goPCLnTabInfo *GoPCLnTabInfo, symtab *libpf.
163171
return nil, 0, fmt.Errorf("could not read .noptrdata section: %w", err)
164172
}
165173

166-
// asume here that pointer size is 8
167-
const ptrSize = 8
168174
var buf [2 * ptrSize]byte
169175
binary.NativeEndian.PutUint64(buf[:], goPCLnTabInfo.Address)
170176
binary.NativeEndian.PutUint64(buf[ptrSize:], goPCLnTabInfo.Address+goPCLnTabInfo.Offsets.FuncNameTabOffset)
@@ -194,10 +200,10 @@ func FindModuleData(ef *pfelf.File, goPCLnTabInfo *GoPCLnTabInfo, symtab *libpf.
194200
return noPtrSectionData[n:], noPtrSection.Addr + uint64(n), nil
195201
}
196202

197-
return nil, 0, fmt.Errorf("could not find moduledata")
203+
return nil, 0, errors.New("could not find moduledata")
198204
}
199205

200-
func FindGoFunc(ef *pfelf.File, goPCLnTabInfo *GoPCLnTabInfo, symtab *libpf.SymbolMap) ([]byte, uint64, error) {
206+
func FindGoFunc(ef *pfelf.File, goPCLnTabInfo *GoPCLnTabInfo, symtab *libpf.SymbolMap) (data []byte, address uint64, returnedErr error) {
201207
// First try to locate goFunc with go:func.* symbol.
202208
if symtab != nil {
203209
if goFuncAddr, err := symtab.LookupSymbolAddress("go:func.*"); err == nil {
@@ -227,7 +233,7 @@ func FindGoFunc(ef *pfelf.File, goPCLnTabInfo *GoPCLnTabInfo, symtab *libpf.Symb
227233
goFuncVal := binary.LittleEndian.Uint64(moduleData[goFuncOff:])
228234
sec := sectionContaining(ef, goFuncVal)
229235
if sec == nil {
230-
return nil, 0, fmt.Errorf("could not find section containing gofunc")
236+
return nil, 0, errors.New("could not find section containing gofunc")
231237
}
232238
secData, err := sec.Data(maxBytesGoPclntab)
233239
if err != nil {
@@ -256,7 +262,7 @@ func pclntabHeaderSignature(arch elf.Machine) []byte {
256262
return []byte{0xff, 0xff, 0xff, 0x00, 0x00, quantum, 0x08}
257263
}
258264

259-
func SearchGoPclntab(ef *pfelf.File) ([]byte, uint64, error) {
265+
func SearchGoPclntab(ef *pfelf.File) (data []byte, address uint64, err error) {
260266
signature := pclntabHeaderSignature(ef.Machine)
261267

262268
for i := range ef.Progs {
@@ -267,7 +273,7 @@ func SearchGoPclntab(ef *pfelf.File) ([]byte, uint64, error) {
267273
continue
268274
}
269275

270-
data, err := p.Data(maxBytesGoPclntab)
276+
data, err = p.Data(maxBytesGoPclntab)
271277
if err != nil {
272278
return nil, 0, err
273279
}
@@ -359,19 +365,22 @@ func FindGoPCLnTab(ef *pfelf.File, useHeuristicSearchAsFallback bool) (goPCLnTab
359365
return nil, nil
360366
}
361367

362-
version := verUnknown
368+
var version headerVersion
363369
var offsets TableOffsets
364370
hdrSize := uintptr(PclntabHeaderSize())
365371
mapSize := unsafe.Sizeof(pclntabFuncMap{})
372+
//nolint:gocritic
366373
// funSize := unsafe.Sizeof(pclntabFunc{})
367374
dataLen := uintptr(len(data))
368375
if dataLen < hdrSize {
369376
return nil, fmt.Errorf(".gopclntab is too short (%v)", len(data))
370377
}
378+
//nolint:gocritic
371379
// var textStart uintptr
372380
// var functab, funcdata, funcnametab, filetab, pctab, cutab []byte
373381

374382
hdr := (*pclntabHeader)(unsafe.Pointer(&data[0]))
383+
//nolint:gocritic
375384
// fieldSize := uintptr(hdr.ptrSize)
376385
switch hdr.magic {
377386
case magicGo1_2:

0 commit comments

Comments
 (0)