From b194b5151fdac0c33da0b7359c97f92781ab3b5e Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Tue, 17 Nov 2020 19:10:51 -0500 Subject: [PATCH] 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. For #42082. Change-Id: Icb3e4e1c7bf7d1fd3d76a2e0d7dfcb319c661534 Reviewed-on: https://go-review.googlesource.com/c/go/+/270941 Trust: Cherry Zhang Run-TryBot: Cherry Zhang TryBot-Result: Go Bot Reviewed-by: Than McIntosh --- src/cmd/link/internal/ld/outbuf.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cmd/link/internal/ld/outbuf.go b/src/cmd/link/internal/ld/outbuf.go index fa4d183337..36ec394077 100644 --- a/src/cmd/link/internal/ld/outbuf.go +++ b/src/cmd/link/internal/ld/outbuf.go @@ -183,7 +183,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)...) } -- 2.48.1