Skip to content

Commit

Permalink
cmd/link: recompute heapPos after copyHeap
Browse files Browse the repository at this point in the history
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 <[email protected]>
Run-TryBot: Cherry Zhang <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Than McIntosh <[email protected]>
  • Loading branch information
cherrymui committed Nov 18, 2020
1 parent 64ef848 commit b194b51
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/cmd/link/internal/ld/outbuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)...)
}
Expand Down

0 comments on commit b194b51

Please sign in to comment.