Bug 262916 - Valgrind segfaults with Go binary
Summary: Valgrind segfaults with Go binary
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (show other bugs)
Version: 3.6.0
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-12 07:40 UTC by Albert Strasheim
Modified: 2011-07-29 20:03 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Albert Strasheim 2011-01-12 07:40:03 UTC
Follow instructions at http://golang.org/doc/install.html

cd $GOROOT/src/pkg/ebnf
make test
valgrind ./6.out
...
Segmentation fault

gdb says:


Program received signal SIGSEGV, Segmentation fault.
vgPlain_get_StackTrace_wrk (tid_if_known=<value optimized out>, ips=0x403989af0, max_n_ips=12, sps=0x0, fps=0x0, startRegs=<value optimized out>, fp_max_orig=34342965240) at m_stacktrace.c:333
333              uregs.xip = (((UWord*)uregs.xbp)[1]);
(gdb) bt
#0  vgPlain_get_StackTrace_wrk (tid_if_known=<value optimized out>, ips=0x403989af0, max_n_ips=12, sps=0x0, fps=0x0, startRegs=<value optimized out>, fp_max_orig=34342965240) at m_stacktrace.c:333
#1  0x000000003805da75 in vgPlain_get_StackTrace (tid=1, ips=0x403989af0, max_n_ips=12, sps=0x0, fps=<value optimized out>, first_ip_delta=0) at m_stacktrace.c:738
#2  0x0000000038049276 in record_ExeContext_wrk (tid=1, first_ip_delta=0, first_ip_only=0 '\000') at m_execontext.c:316
#3  0x0000000038047597 in construct_error (err=0x403989d00, tid=<value optimized out>, ekind=<value optimized out>, a=<value optimized out>, s=<value optimized out>, extra=<value optimized out>, where=0x0) at m_errormgr.c:608
#4  0x0000000038047bf1 in vgPlain_maybe_record_error (tid=<value optimized out>, ekind=1, a=<value optimized out>, s=<value optimized out>, extra=<value optimized out>) at m_errormgr.c:696
#5  0x0000000038045be8 in vgMemCheck_record_cond_error (tid=<value optimized out>, otag=<value optimized out>) at mc_errors.c:852
#6  0x00000004039f5363 in ?? ()
#7  0x0000000000011d39 in ?? ()
#8  0x0000000038fec220 in vgPlain_threads ()
#9  0x0000000000000000 in ?? ()
Comment 1 Rich Coe 2011-07-29 20:03:47 UTC
>> I think the initialization or updating of either the stack frame or bp
>> register is suspect in the implemenation of go.  

>> I don't think this failure is preventable or a failure in V.  
>> Rather I think it's go's runtime.initdone is not correctly initializing
>> the stack.


# from go/src/pkg/reflect

: gdb /usr/local/src/vg1/.in_place/memcheck-amd64-linux
> run --log-file=vg.out ./6.out

Program received signal SIGSEGV, Segmentation fault.
0x000000003804b7aa in vgPlain_get_StackTrace_wrk (tid_if_known=1, ips=0x403a859d0, max_n_ips=12, sps=0x0, 
    fps=0x0, startRegs=0x403a85970, fp_max_orig=34342965240) at m_stacktrace.c:334
334              uregs.xip = (((UWord*)uregs.xbp)[1]);
(gdb) bt
#0  0x000000003804b7aa in vgPlain_get_StackTrace_wrk (tid_if_known=1, ips=0x403a859d0, max_n_ips=12, sps=0x0, 
    fps=0x0, startRegs=0x403a85970, fp_max_orig=34342965240) at m_stacktrace.c:334
#1  0x000000003804ba92 in vgPlain_get_StackTrace (tid=1, ips=0x403a859d0, max_n_ips=12, sps=0x0, fps=0x0, 
    first_ip_delta=0) at m_stacktrace.c:818
#2  0x000000003802c612 in record_ExeContext_wrk (tid=1, first_ip_delta=0, first_ip_only=0 '\000')
    at m_execontext.c:317
#3  0x000000003802caef in vgPlain_record_ExeContext (tid=1, first_ip_delta=0) at m_execontext.c:430
#4  0x0000000038029c50 in construct_error (err=0x403a85c10, tid=1, ekind=3, a=1066225685508, s=0x0, 
    extra=0x403a85c90, where=0x0) at m_errormgr.c:625
#5  0x0000000038029e83 in vgPlain_maybe_record_error (tid=1, ekind=3, a=1066225685508, s=0x0, 
    extra=0x403a85c90) at m_errormgr.c:713
#6  0x0000000038027d64 in vgMemCheck_record_address_error (tid=1, a=1066225685508, szB=1, isWrite=0 '\000')
    at mc_errors.c:834
#7  0x0000000038009807 in mc_LOADVn_slow (a=1066225685508, nBits=<value optimized out>, bigendian=0 '\000')
    at mc_main.c:1184
#8  0x0000000403c7bf97 in ?? ()
#9  0x000000000000f677 in ?? ()
#10 0x00000000390aca80 in vgPlain_threads ()
#11 0x0000000000000000 in ?? ()

(gdb) p i
$1 = 7

(gdb) p/x uregs
$2 = {xip = 0xa00000003, xsp = 0x4842f30, xbp = 0x4400002e8}

(gdb) x/i $pc
=> 0x3804b7aa <vgPlain_get_StackTrace_wrk+642>: mov    (%rax),%rax

(gdb) p/x $rax
$3 = 0x4400002f0

(gdb) x/x $3
0x4400002f0:    Cannot access memory at address 0x4400002f0

(gdb) p/x ips[0] through ips[6]
$4 = 0x412e16
$5 = 0x412ec5
$6 = 0x4165de
$7 = 0x42d119
$8 = 0x40e049
$9 = 0xf8400121ff
$10 = 0xa00000003

(gdb) p/x *startRegs
$11 = {r_pc = 0x412e16, r_sp = 0x4842ea8, misc = {X86 = {r_ebp = 0x4842f20}, AMD64 = {r_rbp = 0x4842f20}, 
    PPC32 = {r_lr = 0x4842f20}, PPC64 = {r_lr = 0x4842f20}, ARM = {r14 = 0x4842f20, r12 = 0x0, r11 = 0x0, 
      r7 = 0x0}, S390X = {r_fp = 0x4842f20, r_lr = 0x0}}}

(gdb) p/x startRegs.misc.AMD64.r_rbp
$12 = 0x4842f20

==2895== Invalid read of size 8
==2895==    at 0x409A05: runtime.memmove (/usr/local/ext/src/google/go/src/pkg/runtime/amd64/memmove.s:46)
==2895==    by 0x412D70: concatstring (/usr/local/ext/src/google/go/src/pkg/runtime/string.goc:137)
==2895==    by 0x412DDE: runtime.concatstring (/usr/local/ext/src/google/go/src/pkg/runtime/string.goc:147)
==2895==    by 0x4276E7: /usr/local/ext/src/google/go/src/pkg/reflect/_xtest_.valueToString (/usr/local/ext/src/google/go/src/pkg/reflect/tostring_test.go:81)
==2895==    by 0x415CF2: /usr/local/ext/src/google/go/src/pkg/reflect/_xtest_.TestSetValue (/usr/local/ext/src/google/go/src/pkg/reflect/all_test.go:297)
==2895==    by 0x42D119: testing.tRunner (/usr/local/ext/src/google/go/src/pkg/testing/testing.go:156)
==2895==    by 0x40E049: runtime.initdone (/usr/local/ext/src/google/go/src/pkg/runtime/proc.c:240)
==2895==    by 0xF84002FCDF: ???
==2895==    by 0x2E: ???
==2895==    by 0x4BEA23: ??? (in /usr/local/ext/src/google/go/src/pkg/reflect/6.out)
==2895==    by 0x202C00000001: ???
==2895==    by 0xF84000D14F: ???
==2895==  Address 0xf84000d150 is not stack'd, malloc'd or (recently) free'd
==2895== 
==2895== 
==2895== More than 100 errors detected.  Subsequent errors
==2895== will still be recorded, but in less detail than before.

Program received signal SIGSEGV, Segmentation fault.
0x000000003804b7aa in vgPlain_get_StackTrace_wrk (tid_if_known=1, ips=0x403a859d0, max_n_ips=12, sps=0x0, 
    fps=0x0, startRegs=0x403a85970, fp_max_orig=34342965240) at m_stacktrace.c:334
334              uregs.xip = (((UWord*)uregs.xbp)[1]);

### with debug enabled
Breakpoint 2, vgPlain_get_StackTrace_wrk (tid_if_known=1, ips=0x403a859d0, max_n_ips=12, sps=0x0, fps=0x0, 
    startRegs=0x403a85970, fp_max_orig=34342965240) at m_stacktrace.c:252
252        fp_max = VG_PGROUNDUP(fp_max_orig);
max_n_ips=12 fp_min=0x4842ea8 fp_max_orig=0x7ff000ff8, fp_max=0x7ff000ff8 ip=0x412e16 fp=0x4842f20
     ipsC[1]=0x00412ec5
     ipsC[2]=0x004165de
     ipsC[3]=0x0042d119
     ipsC[4]=0x0040e049
     ipsC[5]=0xf8400121ff
     ipsF[6]=0xa00000003

Program received signal SIGSEGV, Segmentation fault.
0x000000003804b7aa in vgPlain_get_StackTrace_wrk (tid_if_known=1, ips=0x403a859d0, max_n_ips=12, sps=0x0, 
    fps=0x0, startRegs=0x403a85970, fp_max_orig=34342965240) at m_stacktrace.c:334
334              uregs.xip = (((UWord*)uregs.xbp)[1]);


>> I set br's where each frame is decoded.  On the SEGV condition, it's
>> the second time xbp is used to get a frame.  

252        fp_max = VG_PGROUNDUP(fp_max_orig);
max_n_ips=12 fp_min=0x4842ea8 fp_max_orig=0x7ff000ff8, fp_max=0x7ff000ff8 ip=0x412e16 fp=0x4842f20

280        ips[0] = uregs.xip;
$18 = {xip = 0x412e16, xsp = 0x4842ea8, xbp = 0x4842f20}
     ipsC[1]=0x00412ec5

316              uregs.xip = uregs.xip - 1; /* as per comment at the head of this loop */
$19 = {xip = 0x412ec6, xsp = 0x4842ec8, xbp = 0x4842f20}
     ipsC[2]=0x004165de

316              uregs.xip = uregs.xip - 1; /* as per comment at the head of this loop */
$20 = {xip = 0x4165df, xsp = 0x4842ef8, xbp = 0x4842f20}
     ipsC[3]=0x0042d119

316              uregs.xip = uregs.xip - 1; /* as per comment at the head of this loop */
$21 = {xip = 0x42d11a, xsp = 0x4842f90, xbp = 0x4842f20}
     ipsC[4]=0x0040e049

316              uregs.xip = uregs.xip - 1; /* as per comment at the head of this loop */
$22 = {xip = 0x40e04a, xsp = 0x4842fa8, xbp = 0x4842f20}
     ipsC[5]=0xf8400121ff

316              uregs.xip = uregs.xip - 1; /* as per comment at the head of this loop */
$23 = {xip = 0xf840012200, xsp = 0x4842fb0, xbp = 0x4842f20}

336              uregs.xsp = uregs.xbp + sizeof(Addr) /*saved %rbp*/
$24 = {xip = 0xa00000004, xsp = 0x4842fb0, xbp = 0x4842f20}

334              uregs.xip = (((UWord*)uregs.xbp)[1]);
$3 = {xip = 0xa00000003, xsp = 0x4842f30, xbp = 0x4400002e8}