]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: fix end-of-block padding (again)
authorCherry Zhang <cherryyz@google.com>
Tue, 31 Mar 2020 22:53:17 +0000 (18:53 -0400)
committerCherry Zhang <cherryyz@google.com>
Wed, 1 Apr 2020 14:42:51 +0000 (14:42 +0000)
Make sure we never overrun the end address.

Should fix AIX build.

Change-Id: I9926387d4512ec8b4acc32b7f32cee2b2aca25b4
Reviewed-on: https://go-review.googlesource.com/c/go/+/226718
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/cmd/link/internal/ld/data.go

index bf9c112e0372a8b5c786fe770e69323f01706d4e..bff29fb568ff185948af876b72424c1a5c08a231 100644 (file)
@@ -811,7 +811,6 @@ func writeBlocks(out *OutBuf, sem chan int, syms []*sym.Symbol, addr, size int64
        for addr < lastAddr {
                // Find the last symbol we'd write.
                idx := -1
-               length := int64(0)
                for i, s := range syms {
                        // If the next symbol's size would put us out of bounds on the total length,
                        // stop looking.
@@ -834,9 +833,15 @@ func writeBlocks(out *OutBuf, sem chan int, syms []*sym.Symbol, addr, size int64
                }
 
                // Compute the length to write, including padding.
+               // We need to write to the end address (lastAddr), or the next symbol's
+               // start address, whichever comes first. If there is no more symbols,
+               // just write to lastAddr. This ensures we don't leave holes between the
+               // blocks or at the end.
+               length := int64(0)
                if idx+1 < len(syms) {
                        length = syms[idx+1].Value - addr
-               } else {
+               }
+               if length == 0 || length > lastAddr-addr {
                        length = lastAddr - addr
                }