Skip to content

Commit 480da60

Browse files
cherrymuicagedmantis
authored andcommitted
[release-branch.go1.15] cmd/link: recompute heapPos after copyHeap
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 <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Jeremy Faller <[email protected]> Trust: Cherry Zhang <[email protected]>
1 parent a2adbc8 commit 480da60

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ func (out *OutBuf) writeLoc(lenToWrite int64) (int64, []byte) {
187187
// See if our heap would grow to be too large, and if so, copy it to the end
188188
// of the mmapped area.
189189
if heapLen > maxOutBufHeapLen && out.copyHeap() {
190-
heapPos, heapLen, lenNeeded = 0, 0, lenToWrite
190+
heapPos -= heapLen
191+
lenNeeded = heapPos + lenToWrite
192+
heapLen = 0
191193
}
192194
out.heap = append(out.heap, make([]byte, lenNeeded-heapLen)...)
193195
}

0 commit comments

Comments
 (0)