diff options
author | Cherry Zhang <cherryyz@google.com> | 2020-03-31 18:53:17 -0400 |
---|---|---|
committer | Cherry Zhang <cherryyz@google.com> | 2020-04-01 14:42:51 +0000 |
commit | 1cb582fe026d22cc886634f49ec0be63bcca911f (patch) | |
tree | 56f4c7f62af19220ab435b8c1c6ff260ccda9105 | |
parent | 0e0ee115c5110f83c763af5c8797759887fe0cb3 (diff) | |
download | go-1cb582fe026d22cc886634f49ec0be63bcca911f.tar.gz go-1cb582fe026d22cc886634f49ec0be63bcca911f.zip |
[dev.link] cmd/link: fix end-of-block padding (again)
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>
-rw-r--r-- | src/cmd/link/internal/ld/data.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index bf9c112e03..bff29fb568 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -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 } |