Skip to content

Commit 4a745c4

Browse files
authored
Merge pull request #78 from parca-dev/fix-docker-warn
fix docker warn
2 parents 7878c19 + c035be1 commit 4a745c4

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

interpreter/golabels/golabels.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func Loader(_ interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interprete
6060
log.Debugf("file %s detected as go version %s", info.FileName(), goVersion)
6161

6262
offsets := getOffsets(goVersion)
63-
tlsOffset, err := extractTLSGOffset(file)
63+
tlsOffset, err := extractTLSGOffset(file, info.FileName())
6464
if err != nil {
6565
return nil, fmt.Errorf("failed to extract TLS offset: %w", err)
6666
}

interpreter/golabels/tls_amd64.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// storing the current g but "static" binaries it ends up as -80. There
1616
// may be dynamic relocating going on so just read it from a known
1717
// symbol if possible.
18-
func extractTLSGOffset(f *pfelf.File) (int32, error) {
18+
func extractTLSGOffset(f *pfelf.File, path string) (int32, error) {
1919
syms, err := f.ReadSymbols()
2020
if err != nil {
2121
return 0, err
@@ -25,10 +25,10 @@ func extractTLSGOffset(f *pfelf.File) (int32, error) {
2525
sym, err := syms.LookupSymbol("runtime.stackcheck.abi0")
2626
if err != nil {
2727
// Binary must be stripped, hope default is correct and warn.
28-
log.Warnf("Failed to find stackcheck symbol, Go labels might not work: %v", err)
28+
log.Warnf("Failed to find stackcheck symbol, Go labels might not work: %v (%s)", err, path)
2929
return -8, nil
3030
}
31-
b, err := f.VirtualMemory(int64(sym.Address), 10, 10)
31+
b, err := f.VirtualMemory(int64(sym.Address), 16, 16)
3232
if err != nil {
3333
return 0, err
3434
}
@@ -42,7 +42,25 @@ func extractTLSGOffset(f *pfelf.File) (int32, error) {
4242
if ok {
4343
return int32(mem.Disp), nil
4444
}
45+
// allow mov const to register as well to silence warnings on this:
46+
// 00000000002ed100 <runtime.stackcheck.abi0>:
47+
// 2ed100: 48 c7 c1 f8 ff ff ff movq $-0x8, %rcx
48+
// 2ed107: 64 48 8b 01 movq %fs:(%rcx), %rax
49+
if imm, ok := i.Args[1].(x86asm.Imm); ok {
50+
if reg, ok := i.Args[0].(x86asm.Reg); ok {
51+
i, err = x86asm.Decode(b[i.Len:], 64)
52+
if err != nil {
53+
goto exit
54+
}
55+
if i.Op == x86asm.MOV {
56+
if m, ok := i.Args[1].(x86asm.Mem); ok && m.Base == reg {
57+
return int32(imm), nil
58+
}
59+
}
60+
}
61+
}
4562
}
46-
log.Warnf("Failed to decode stackcheck symbol, Go label collection might not work")
63+
exit:
64+
log.Warnf("Failed to decode stackcheck symbol, Go label collection might not work %s", path)
4765
return -8, nil
4866
}

interpreter/golabels/tls_arm64.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
// 0x000000000007f270 <+16>: mov x27, #0x30 // #48
2222
// 0x000000000007f274 <+20>: ldr x28, [x0, x27]
2323
// 0x000000000007f278 <+24>: ret
24-
func extractTLSGOffset(f *pfelf.File) (int32, error) {
24+
func extractTLSGOffset(f *pfelf.File, path string) (int32, error) {
2525
iscgo, err := f.IsCgoEnabled()
2626
if err != nil || !iscgo {
2727
return 0, err
@@ -54,6 +54,6 @@ func extractTLSGOffset(f *pfelf.File) (int32, error) {
5454
}
5555
}
5656
}
57-
log.Warnf("Failed to decode load_g symbol, Go label collection might not work with CGO frames")
57+
log.Warnf("Failed to decode load_g symbol, Go label collection might not work with CGO frames (%s)", path)
5858
return 0, nil
5959
}

0 commit comments

Comments
 (0)