<pre class="notranslate">go version go1.3beta2 +77632b0a1c94 Sun May 25 08:38:59 2014 +1000 linux/amd64

llgo crashes with:

bad pointer in frame github.com/go-llvm/llvm.Value.Type at 0xc2080d5418: 0x6
fatal error: bad pointer in scanbitvector

runtime stack:
runtime.throw(0x2f758ab)
    src/pkg/runtime/panic.c:520 +0x69 fp=0x7f7c315b49c0
scanbitvector(0x2613cb8, 0x2135d01, 0xc2080d5418, 0x7f7c315b4a78, 0x1, 0x7f7c315b4c68)
    src/pkg/runtime/mgc0.c:1492 +0x38d fp=0x7f7c315b4a28
scanframe(0x7f7c315b4ae8, 0x7f7c315b4c68)
    src/pkg/runtime/mgc0.c:1627 +0x198 fp=0x7f7c315b4aa0
runtime.gentraceback(0xaa2340, 0xc2080d5390, 0x0, 0xc208002120, 0x0, 0x0, 0x7fffffff,
0xaa6a10, 0x7f7c315b4c68, 0x5ff7c31dbb000)
    src/pkg/runtime/traceback_x86.c:206 +0x413 fp=0x7f7c315b4b68
addstackroots(0xc208002120, 0x7f7c315b4c68)
    src/pkg/runtime/mgc0.c:1688 +0x168 fp=0x7f7c315b4bf8
markroot(0xc208018480, 0x5)
    src/pkg/runtime/mgc0.c:1321 +0xbe fp=0x7f7c315b4c78
runtime.parfordo(0xc208018480)
    src/pkg/runtime/parfor.c:88 +0xa3 fp=0x7f7c315b4cf0
gc(0x7f7c33d53f20)
    src/pkg/runtime/mgc0.c:2403 +0x1d6 fp=0x7f7c315b4e20
mgc(0xc2080026c0)
    src/pkg/runtime/mgc0.c:2345 +0x2e fp=0x7f7c315b4e30
runtime.mcall(0xa9a43c)
    src/pkg/runtime/asm_amd64.s:181 +0x4b fp=0x7f7c315b4e40

goroutine 19 [garbage collection]:
runtime.gc(0x1)
    src/pkg/runtime/mgc0.c:2325 +0x1c6 fp=0x7f7c33d53f38
runfinq()
    src/pkg/runtime/mgc0.c:2699 +0x2ea fp=0x7f7c33d53fa8
runtime.goexit()
    src/pkg/runtime/proc.c:1445 fp=0x7f7c33d53fb0
created by runtime.gc
    src/pkg/runtime/mgc0.c:2264

goroutine 16 [runnable]:
endcgo()
    src/pkg/runtime/cgocall.c:153 fp=0xc2080d5398
runtime.cgocall(0xa98630, 0xc2080d53f8)
    src/pkg/runtime/cgocall.c:149 +0x13d fp=0xc2080d53e0
github.com/go-llvm/llvm._Cfunc_LLVMTypeOf(0x4064940, 0x4031b60)
    github.com/go-llvm/llvm/_obj/_cgo_defun.c:5081 +0x31 fp=0xc2080d53f8
github.com/go-llvm/llvm.Value.Type(0x4064940, 0x6)
    github.com/go-llvm/llvm/core.go:600 +0x27 fp=0xc2080d5410
github.com/go-llvm/llgo.(*TypeMap).globalStringPtr(0xc2080fe000, 0xc20814ea30, 0x6,
0x400ce30)
    github.com/go-llvm/llgo/typemap.go:1279 +0x4f fp=0xc2080d5488
github.com/go-llvm/llgo.(*TypeMap).makeCommonType(0xc2080fe000, 0x7f7c33eca4c0,
0xc2080a27e0, 0xc2080d5590)
    github.com/go-llvm/llgo/typemap.go:1020 +0x280 fp=0xc2080d5508
github.com/go-llvm/llgo.(*TypeMap).makeArrayType(0xc2080fe000, 0x7f7c33eca4c0,
0xc2080a27e0, 0xc2080a27e0, 0xa98401)
    github.com/go-llvm/llgo/typemap.go:1037 +0x55 fp=0xc2080d5578
github.com/go-llvm/llgo.(*TypeMap).makeTypeDescInitializer(0xc2080fe000, 0x7f7c33eca4c0,
0xc2080a27e0, 0x40648b0)
    github.com/go-llvm/llgo/typemap.go:757 +0x2e2 fp=0xc2080d5610
github.com/go-llvm/llgo.(*TypeMap).emitTypeDescInitializers(0xc2080fe000)
    github.com/go-llvm/llgo/typemap.go:742 +0x1a4 fp=0xc2080d5710
github.com/go-llvm/llgo.(*unit).translatePackage(0xc2080a4900, 0xc20805e070)
    github.com/go-llvm/llgo/ssa.go:119 +0x32f fp=0xc2080d5850
github.com/go-llvm/llgo.(*compiler).compile(0xc20804a210, 0xc208046980, 0x3, 0x4,
0x7fff8a58ceb0, 0x1, 0x0, 0x0, 0x0)
    github.com/go-llvm/llgo/compiler.go:221 +0xa5d fp=0xc2080d5a38
github.com/go-llvm/llgo.(*Compiler).Compile(0xc20805e8c0, 0xc208046980, 0x3, 0x4,
0x7fff8a58ceb0, 0x1, 0xc20801b0e0, 0x2f, 0x1)
    github.com/go-llvm/llgo/compiler.go:102 +0x12e fp=0xc2080d5aa0
main.performAction(0xc20802a0d0, 0x1, 0xc208046980, 0x3, 0x4, 0x7fff8a58cf28, 0x21, 0x0,
0x0)
    github.com/go-llvm/llgo/cmd/gllgo/gllgo.go:326 +0xf6 fp=0xc2080d5cd8
main.performActions(0xc20802a0d0, 0x0, 0x0)
    github.com/go-llvm/llgo/cmd/gllgo/gllgo.go:481 +0x2b0 fp=0xc2080d5e28
main.main()
    github.com/go-llvm/llgo/cmd/gllgo/gllgo.go:505 +0xf3 fp=0xc2080d5f50
runtime.main()
    src/pkg/runtime/proc.c:247 +0x11a fp=0xc2080d5fa8
runtime.goexit()
    src/pkg/runtime/proc.c:1445 fp=0xc2080d5fb0
created by _rt0_go
    src/pkg/runtime/asm_amd64.s:97 +0x120

goroutine 17 [syscall]:
runtime.notetsleepg(0x7f7c33d57f60, 0xdf8475800)
    src/pkg/runtime/lock_futex.c:198 +0x46 fp=0x7f7c33d57f38
runtime.MHeap_Scavenger()
    src/pkg/runtime/mheap.c:532 +0xa3 fp=0x7f7c33d57fa8
runtime.goexit()
    src/pkg/runtime/proc.c:1445 fp=0x7f7c33d57fb0
created by runtime.main
    src/pkg/runtime/proc.c:207

goroutine 18 [GC sweep wait]:
runtime.park(0xab1560, 0x2f8e6f8, 0x2f75ae0)
    src/pkg/runtime/proc.c:1369 +0x89 fp=0x7f7c33d55f70
runtime.parkunlock(0x2f8e6f8, 0x2f75ae0)
    src/pkg/runtime/proc.c:1385 +0x3b fp=0x7f7c33d55f90
bgsweep()
    src/pkg/runtime/mgc0.c:1989 +0x9a fp=0x7f7c33d55fa8
runtime.goexit()
    src/pkg/runtime/proc.c:1445 fp=0x7f7c33d55fb0
created by runtime.gc
    src/pkg/runtime/mgc0.c:2264

goroutine 17 [syscall]:
runtime.goexit()
    src/pkg/runtime/proc.c:1445 fp=0xc20806afb0


I can't describe how I built it.

But here is code of the offending function:

type Type struct {
    C C.LLVMTypeRef
}
func (v Value) Type() (t Type) {
    t.C = C.LLVMTypeOf(v.C)  /* line 600 */
}

Here is disass:

0000000000b46470 &lt;github.com/go-llvm/llvm.Value.Type&gt;:
  b46470:       64 48 8b 0c 25 f0 ff    mov    %fs:0xfffffffffffffff0,%rcx
  b46477:       ff ff 
  b46479:       48 3b 21                cmp    (%rcx),%rsp
  b4647c:       77 07                   ja     b46485 &lt;github.com/go-llvm/llvm.Value.Type+0x15&gt;
  b4647e:       e8 7d ff f7 ff          callq  ac6400 &lt;runtime.morestack16_noctxt&gt;
  b46483:       eb eb                   jmp    b46470 &lt;github.com/go-llvm/llvm.Value.Type&gt;
  b46485:       48 83 ec 10             sub    $0x10,%rsp
  b46489:       48 8b 5c 24 18          mov    0x18(%rsp),%rbx
  b4648e:       48 89 1c 24             mov    %rbx,(%rsp)
  b46492:       e8 89 2e 02 00          callq  b69320 &lt;github.com/go-llvm/llvm._Cfunc_LLVMTypeOf&gt;
  b46497:       48 8b 5c 24 08          mov    0x8(%rsp),%rbx
  b4649c:       48 89 5c 24 20          mov    %rbx,0x20(%rsp)
  b464a1:       48 83 c4 10             add    $0x10,%rsp
  b464a5:       c3                      retq   

And here is -live compiler output:
../../../llvm/core.go:600: live at entry to Value.Type: v
../../../llvm/core.go:600: live at call to _Cfunc_LLVMTypeOf: v t</pre>
<p dir="auto">Using suffixarray in the linker to de-duplicate strings saves a bunch of space in the binaries. <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/crawshaw/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/crawshaw">@crawshaw</a> did this in <a href="https://golang.org/cl/19987" rel="nofollow">https://golang.org/cl/19987</a> but it burns a lot of CPU.</p>
<p dir="auto">Running the benchmarks in index/suffixarray,</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ go test -v -bench=NewIndex -benchtime=3s -cpuprofile=prof.cpu index/suffixarray"><pre class="notranslate"><code class="notranslate">$ go test -v -bench=NewIndex -benchtime=3s -cpuprofile=prof.cpu index/suffixarray
</code></pre></div>
<p dir="auto">Shows 43% of the CPU time (50% before SSA!) is on a single line (the suffixSortable.Less) function:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="(pprof) top
7470ms of 7960ms total (93.84%)
Dropped 39 nodes (cum &lt;= 39.80ms)
Showing top 10 nodes out of 56 (cum &gt;= 110ms)
      flat  flat%   sum%        cum   cum%
    3470ms 43.59% 43.59%     3470ms 43.59%  index/suffixarray.(*suffixSortable).Less
    1900ms 23.87% 67.46%     5370ms 67.46%  sort.doPivot
     820ms 10.30% 77.76%      990ms 12.44%  index/suffixarray.(*suffixSortable).updateGroups
     310ms  3.89% 81.66%      310ms  3.89%  runtime.duffcopy
     210ms  2.64% 84.30%     7220ms 90.70%  index/suffixarray.qsufsort
     200ms  2.51% 86.81%      200ms  2.51%  runtime.deductSweepCredit
     190ms  2.39% 89.20%      220ms  2.76%  index/suffixarray.initGroups
     130ms  1.63% 90.83%      130ms  1.63%  runtime.usleep
     130ms  1.63% 92.46%      280ms  3.52%  sort.insertionSort
     110ms  1.38% 93.84%      110ms  1.38%  index/suffixarray.(*suffixSortable).Swap

(pprof) list Less
Total: 7.96s
ROUTINE ======================== index/suffixarray.(*suffixSortable).Less in /Users/bradfitz/go/src/index/suffixarray/qsufsort.go
     3.47s      3.47s (flat, cum) 43.59% of Total
         .          .    137:   h   int
         .          .    138:   buf []int // common scratch space
         .          .    139:}
         .          .    140:
         .          .    141:func (x *suffixSortable) Len() int           { return len(x.sa) }
     3.47s      3.47s    142:func (x *suffixSortable) Less(i, j int) bool { return x.inv[x.sa[i]+x.h] &lt; x.inv[x.sa[j]+x.h] }
         .          .    143:func (x *suffixSortable) Swap(i, j int)      { x.sa[i], x.sa[j] = x.sa[j], x.sa[i] }
         .          .    144:
         .          .    145:func (x *suffixSortable) updateGroups(offset int) {
         .          .    146:   bounds := x.buf[0:0]
         .          .    147:   group := x.inv[x.sa[0]+x.h]


(pprof) disasm Less
Total: 7.96s
ROUTINE ======================== index/suffixarray.(*suffixSortable).Less
     3.47s      3.47s (flat, cum) 43.59% of Total
      90ms       90ms      71210: GS MOVQ GS:0x8a0, CX
      70ms       70ms      71219: CMPQ 0x10(CX), SP
         .          .      7121d: JBE 0x7127e
     160ms      160ms      7121f: MOVQ 0x8(SP), CX
     100ms      100ms      71224: MOVQ 0(CX), DX
     100ms      100ms      71227: MOVQ 0x18(CX), BX
     130ms      130ms      7122b: MOVQ 0x20(CX), BP
      20ms       20ms      7122f: MOVQ 0x8(CX), SI
      80ms       80ms      71233: MOVQ 0x10(SP), DI
      80ms       80ms      71238: CMPQ SI, DI
         .          .      7123b: JAE 0x71277
     200ms      200ms      7123d: MOVQ 0(DX)(DI*8), AX
     140ms      140ms      71241: MOVQ 0x30(CX), CX
      80ms       80ms      71245: LEAQ 0(AX)(CX*1), DI
     110ms      110ms      71249: CMPQ BP, DI
         .          .      7124c: JAE 0x71277
     120ms      120ms      7124e: MOVQ 0(BX)(DI*8), DI
     320ms      320ms      71252: MOVQ 0x18(SP), R8
      30ms       30ms      71257: CMPQ SI, R8
         .          .      7125a: JAE 0x71277
      30ms       30ms      7125c: MOVQ 0(DX)(R8*8), AX
      50ms       50ms      71260: ADDQ AX, CX
     140ms      140ms      71263: CMPQ BP, CX
         .          .      71266: JAE 0x71277
      50ms       50ms      71268: MOVQ 0(BX)(CX*8), CX
     770ms      770ms      7126c: CMPQ CX, DI
     240ms      240ms      7126f: SETL AL
     160ms      160ms      71272: MOVL AL, 0x20(SP)
     200ms      200ms      71276: RET
         .          .      71277: CALL runtime.panicindex(SB)
         .          .      7127c: UD2
         .          .      7127e: CALL runtime.morestack_noctxt(SB)
         .          .      71283: JMP index/suffixarray.(*suffixSortable).Less(SB)
         .          .      71285: INT $0x3
         .          .      71286: INT $0x3
         .          .      71287: INT $0x3
         .          .      71288: INT $0x3
         .          .      71289: INT $0x3
         .          .      7128a: INT $0x3
         .          .      7128b: INT $0x3
         .          .      7128c: INT $0x3
         .          .      7128d: INT $0x3
         .          .      7128e: INT $0x3"><pre class="notranslate"><code class="notranslate">(pprof) top
7470ms of 7960ms total (93.84%)
Dropped 39 nodes (cum &lt;= 39.80ms)
Showing top 10 nodes out of 56 (cum &gt;= 110ms)
      flat  flat%   sum%        cum   cum%
    3470ms 43.59% 43.59%     3470ms 43.59%  index/suffixarray.(*suffixSortable).Less
    1900ms 23.87% 67.46%     5370ms 67.46%  sort.doPivot
     820ms 10.30% 77.76%      990ms 12.44%  index/suffixarray.(*suffixSortable).updateGroups
     310ms  3.89% 81.66%      310ms  3.89%  runtime.duffcopy
     210ms  2.64% 84.30%     7220ms 90.70%  index/suffixarray.qsufsort
     200ms  2.51% 86.81%      200ms  2.51%  runtime.deductSweepCredit
     190ms  2.39% 89.20%      220ms  2.76%  index/suffixarray.initGroups
     130ms  1.63% 90.83%      130ms  1.63%  runtime.usleep
     130ms  1.63% 92.46%      280ms  3.52%  sort.insertionSort
     110ms  1.38% 93.84%      110ms  1.38%  index/suffixarray.(*suffixSortable).Swap

(pprof) list Less
Total: 7.96s
ROUTINE ======================== index/suffixarray.(*suffixSortable).Less in /Users/bradfitz/go/src/index/suffixarray/qsufsort.go
     3.47s      3.47s (flat, cum) 43.59% of Total
         .          .    137:   h   int
         .          .    138:   buf []int // common scratch space
         .          .    139:}
         .          .    140:
         .          .    141:func (x *suffixSortable) Len() int           { return len(x.sa) }
     3.47s      3.47s    142:func (x *suffixSortable) Less(i, j int) bool { return x.inv[x.sa[i]+x.h] &lt; x.inv[x.sa[j]+x.h] }
         .          .    143:func (x *suffixSortable) Swap(i, j int)      { x.sa[i], x.sa[j] = x.sa[j], x.sa[i] }
         .          .    144:
         .          .    145:func (x *suffixSortable) updateGroups(offset int) {
         .          .    146:   bounds := x.buf[0:0]
         .          .    147:   group := x.inv[x.sa[0]+x.h]


(pprof) disasm Less
Total: 7.96s
ROUTINE ======================== index/suffixarray.(*suffixSortable).Less
     3.47s      3.47s (flat, cum) 43.59% of Total
      90ms       90ms      71210: GS MOVQ GS:0x8a0, CX
      70ms       70ms      71219: CMPQ 0x10(CX), SP
         .          .      7121d: JBE 0x7127e
     160ms      160ms      7121f: MOVQ 0x8(SP), CX
     100ms      100ms      71224: MOVQ 0(CX), DX
     100ms      100ms      71227: MOVQ 0x18(CX), BX
     130ms      130ms      7122b: MOVQ 0x20(CX), BP
      20ms       20ms      7122f: MOVQ 0x8(CX), SI
      80ms       80ms      71233: MOVQ 0x10(SP), DI
      80ms       80ms      71238: CMPQ SI, DI
         .          .      7123b: JAE 0x71277
     200ms      200ms      7123d: MOVQ 0(DX)(DI*8), AX
     140ms      140ms      71241: MOVQ 0x30(CX), CX
      80ms       80ms      71245: LEAQ 0(AX)(CX*1), DI
     110ms      110ms      71249: CMPQ BP, DI
         .          .      7124c: JAE 0x71277
     120ms      120ms      7124e: MOVQ 0(BX)(DI*8), DI
     320ms      320ms      71252: MOVQ 0x18(SP), R8
      30ms       30ms      71257: CMPQ SI, R8
         .          .      7125a: JAE 0x71277
      30ms       30ms      7125c: MOVQ 0(DX)(R8*8), AX
      50ms       50ms      71260: ADDQ AX, CX
     140ms      140ms      71263: CMPQ BP, CX
         .          .      71266: JAE 0x71277
      50ms       50ms      71268: MOVQ 0(BX)(CX*8), CX
     770ms      770ms      7126c: CMPQ CX, DI
     240ms      240ms      7126f: SETL AL
     160ms      160ms      71272: MOVL AL, 0x20(SP)
     200ms      200ms      71276: RET
         .          .      71277: CALL runtime.panicindex(SB)
         .          .      7127c: UD2
         .          .      7127e: CALL runtime.morestack_noctxt(SB)
         .          .      71283: JMP index/suffixarray.(*suffixSortable).Less(SB)
         .          .      71285: INT $0x3
         .          .      71286: INT $0x3
         .          .      71287: INT $0x3
         .          .      71288: INT $0x3
         .          .      71289: INT $0x3
         .          .      7128a: INT $0x3
         .          .      7128b: INT $0x3
         .          .      7128c: INT $0x3
         .          .      7128d: INT $0x3
         .          .      7128e: INT $0x3
</code></pre></div>
<p dir="auto">Any Go and/or SSA tweaks we can do to speed up suffixarray? Robert, how much has this been tuned over time?</p>
<p dir="auto">/cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/crawshaw/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/crawshaw">@crawshaw</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/randall77/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/randall77">@randall77</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/tzneal/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/tzneal">@tzneal</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/davecheney/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/davecheney">@davecheney</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ianlancetaylor/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ianlancetaylor">@ianlancetaylor</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/griesemer/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/griesemer">@griesemer</a></p>