]> Cypherpunks repositories - gostls13.git/commit
cmd/gc: fix liveness vs regopt mismatch for input variables
authorRuss Cox <rsc@golang.org>
Mon, 12 May 2014 21:19:02 +0000 (17:19 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 12 May 2014 21:19:02 +0000 (17:19 -0400)
commit26ad5d4ff021e7784dca22e76c43494e76913911
tree04f139bc9432f4fd95047358c3361ae01ea3494e
parent03c0f3fea9c2e92794210e01987b3b024bf1c980
cmd/gc: fix liveness vs regopt mismatch for input variables

The inputs to a function are marked live at all times in the
liveness bitmaps, so that the garbage collector will not free
the things they point at and reuse the pointers, so that the
pointers shown in stack traces are guaranteed not to have
been recycled.

Unfortunately, no one told the register optimizer that the
inputs need to be preserved at all call sites. If a function
is done with a particular input value, the optimizer will stop
preserving it across calls. For single-word values this just
means that the value recorded might be stale. For multi-word
values like slices, the value recorded could be only partially stale:
it can happen that, say, the cap was updated but not the len,
or that the len was updated but not the base pointer.
Either of these possibilities (and others) would make the
garbage collector misinterpret memory, leading to memory
corruption.

This came up in a real program, in which the garbage collector's
'slice len ≤ slice cap' check caught the inconsistency.

Fixes #7944.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews, khr
https://golang.org/cl/100370045
src/cmd/5g/opt.h
src/cmd/5g/reg.c
src/cmd/6g/opt.h
src/cmd/6g/reg.c
src/cmd/8g/opt.h
src/cmd/8g/reg.c
test/fixedbugs/issue7944.go [new file with mode: 0644]