]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.15] cmd/link: recompute heapPos after copyHeap
authorCherry Zhang <cherryyz@google.com>
Wed, 18 Nov 2020 00:10:51 +0000 (19:10 -0500)
committerCarlos Amedee <carlos@golang.org>
Thu, 3 Dec 2020 14:06:12 +0000 (14:06 +0000)
Immediately after a forward Seek, the offset we're writing to is
beyond len(buf)+len(heap):

|<--- buf --->|<--- heap --->|
                                    ^
                                    off

If we do a copyHeap at this point, the new heapPos should not be
0:

|<---------- buf ----------->|<-heap->|
                                    ^
                                    off

Recompute it.

Updates #42082
Fixes #42948

Change-Id: Icb3e4e1c7bf7d1fd3d76a2e0d7dfcb319c661534
Reviewed-on: https://go-review.googlesource.com/c/go/+/270942
Run-TryBot: Carlos Amedee <carlos@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Trust: Cherry Zhang <cherryyz@google.com>

src/cmd/link/internal/ld/outbuf.go

index 09162ae90f594b7a8361e237e782361be0ce26ed..7bc89540c696e0da5108b19c994a61e0d774974f 100644 (file)
@@ -187,7 +187,9 @@ func (out *OutBuf) writeLoc(lenToWrite int64) (int64, []byte) {
                // See if our heap would grow to be too large, and if so, copy it to the end
                // of the mmapped area.
                if heapLen > maxOutBufHeapLen && out.copyHeap() {
-                       heapPos, heapLen, lenNeeded = 0, 0, lenToWrite
+                       heapPos -= heapLen
+                       lenNeeded = heapPos + lenToWrite
+                       heapLen = 0
                }
                out.heap = append(out.heap, make([]byte, lenNeeded-heapLen)...)
        }