<pre class="notranslate">We're getting occasional failures in the garbage collector when it tries to scan an
interface and gets a bad interface table pointer.

sync to tip
set GOEXPERIMENT=precisestack
set GOGC=0
run all.bash

With GOGC=0 it crashes reliably.

SIGSEGV: segmentation violation
PC=0x46daa4

scaninterfacedata(0x2, 0x7f7c76899290, 0x1, 0x7f7c769b5dc0)
    /usr/local/google/home/khr/sandbox/go-ro2/src/pkg/runtime/mgc0.c:1428 +0x84
scanbitvector(0x7f7c76899290, 0x732f0c, 0x4c4501, 0x7f7c769b5dc0)
    /usr/local/google/home/khr/sandbox/go-ro2/src/pkg/runtime/mgc0.c:1461 +0x11e
scanframe(0x7f7c769b5c50, 0x7f7c769b5dc0)
    /usr/local/google/home/khr/sandbox/go-ro2/src/pkg/runtime/mgc0.c:1525 +0x16e
runtime.gentraceback(0x46eed2, 0x7f7c76899108, 0x0, 0xc20812eb40, 0x0, ...)
    /usr/local/google/home/khr/sandbox/go-ro2/src/pkg/runtime/traceback_x86.c:155 +0x3ff
addstackroots(0xc20812eb40, 0x7f7c769b5dc0)
    /usr/local/google/home/khr/sandbox/go-ro2/src/pkg/runtime/mgc0.c:1581 +0x168
markroot(0xc20802e000, 0x9)
    /usr/local/google/home/khr/sandbox/go-ro2/src/pkg/runtime/mgc0.c:1278 +0xbe
runtime.parfordo(0xc20802e000)
    /usr/local/google/home/khr/sandbox/go-ro2/src/pkg/runtime/parfor.c:105 +0xa3
gc(0x7f7c76899130)
    /usr/local/google/home/khr/sandbox/go-ro2/src/pkg/runtime/mgc0.c:2170 +0x259
mgc(0xc20812eb40)
    /usr/local/google/home/khr/sandbox/go-ro2/src/pkg/runtime/mgc0.c:2111 +0x2e
runtime.mcall(0x47e1f7)
    /usr/local/google/home/khr/sandbox/go-ro2/src/pkg/runtime/asm_amd64.s:181 +0x4b

goroutine 21 [garbage collection]:
runtime.gc(0xc200000000)
    /usr/local/google/home/khr/sandbox/go-ro2/src/pkg/runtime/mgc0.c:2082 +0x1b2 fp=0x7f7c76899140
runtime.mallocgc(0x8, 0x66df00, 0x0)
    /usr/local/google/home/khr/sandbox/go-ro2/src/pkg/runtime/malloc.goc:218 +0x1b8 fp=0x7f7c768991b8
runtime.new(0x66df00, 0x47f6c8)
    /usr/local/google/home/khr/sandbox/go-ro2/src/pkg/runtime/malloc.goc:815 +0x32 fp=0x7f7c768991d8
os/exec.(*Cmd).stdin(0xc208165040, 0xc2080561c8, 0xc208087600, 0x3d)
    /usr/local/google/home/khr/sandbox/go-ro2/src/pkg/os/exec/exec.go:148 +0x40 fp=0x7f7c76899280
...

It is dying here:

            tab = *(Itab**)scanp;
            if(tab-&gt;type-&gt;size &lt;= sizeof(void*) &amp;&amp; (tab-&gt;type-&gt;kind &amp; KindNoPointers))
                return;

  46da9d:   48 8b 0a                mov    (%rdx),%rcx     ; tab = *(Itab**)scanp;
  46daa0:   48 8b 41 08             mov    0x8(%rcx),%rax  ; tab-&gt;type
  46daa4:   48 8b 00                mov    (%rax),%rax     ; tab-&gt;type-&gt;size --- faults here
  46daa7:   48 83 f8 08             cmp    $0x8,%rax
  46daab:   77 a2                   ja     46da4f &lt;scaninterfacedata+0x2f&gt;

rax is junk (0x672f6c61636f6c2f) at the faulting instruction.  rcx is 0xc208087600,
which is apparently not an *Itab like it should be.

Possibly related to <a href="https://golang.org/issue/7205" rel="nofollow">issue #7205</a>.</pre>
<p dir="auto">This statement causes numerous confusion in mailing lists, people try to tie it to thread-safety and inability to assign to string variables. And it does not have any formal meaning behind it. The formal part here is that string indexing operation cannot be assigned to and is not addressable. And that is stated right in the next paragraph: "if s[i] is the i'th byte of a string, &amp;s[i] is invalid" and duplicated in description of addressability and assignment statement.</p>
<p dir="auto">The kind of "immutability" that statement refers to is implementation ground. And so better be described in Effective Go in extended form with implications to thread-safety and string copying.</p>
<p dir="auto">The proposed changes:</p>
<ol dir="auto">
<li>Remove "Strings are immutable: once created, it is impossible to change the contents of a string".</li>
<li>Add it is illegal to assign to s[i] right after "if s[i] is the i'th byte of a string, &amp;s[i] is invalid" for consistency.</li>
<li>Remove "non-constant" in "a[x] is the non-constant byte value at index x and the type of a[x] is byte".</li>
<li>Add a section to Effective Go with the discussion of string "immutability".</li>
</ol>