@@ -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}
0 commit comments