]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix missing unsafe-points
authorAustin Clements <austin@google.com>
Fri, 18 Oct 2019 19:45:52 +0000 (15:45 -0400)
committerAustin Clements <austin@google.com>
Sat, 2 Nov 2019 21:51:09 +0000 (21:51 +0000)
Currently, the compiler fails to mark any unsafe-points in the initial
instructions of a function as unsafe points. This happens because
unsafe points are encoded as a stack map index of -2 and the compiler
emits PCDATA instructions when there's a change in the stack map
index, but I had set the initial stack map index to -2. The actual
initial PCDATA value assumed by the PCDATA encoder and the runtime is
-1. Hence, if the first instructions had a stack map index of -2, no
PCDATA was emitted, which cause the runtime to assume the index was -1
instead.

This was particularly problematic in the runtime, where the compiler
was supposed to mark only calls as safe-points and everything else as
unsafe-points. Runtime leaf functions, for example, should have been
marked as entirely unsafe-points, but were instead marked entirely as
safe-points.

Fix this by making the PCDATA instruction generator assume the initial
PCDATA value is -1 instead of -2, so it will emit a PCDATA instruction
right away if the first real instruction is an unsafe-point.

This increases the size of the cmd/go binary by 0.02% since we now
emit slightly more PCDATA than before.

For #10958, #24543.

Change-Id: I92222107f799130072b36d49098d2686f1543699
Reviewed-on: https://go-review.googlesource.com/c/go/+/202084
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/gc/gsubr.go

index 1e15a67bbd6d19d5168e081bd93e9c4f3690dbdb..2894d8d014be99ad56408ad3200ef9e7b8b00987 100644 (file)
@@ -71,7 +71,8 @@ func newProgs(fn *Node, worker int) *Progs {
        pp.pos = fn.Pos
        pp.settext(fn)
        pp.nextLive = LivenessInvalid
-       pp.prevLive = LivenessInvalid
+       // PCDATA tables implicitly start with index -1.
+       pp.prevLive = LivenessIndex{-1, -1}
        return pp
 }