From ca017a6fb9b46860ab0b5054ca07feea3d711a36 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Fri, 10 Apr 2020 22:11:51 -0400 Subject: [PATCH] cmd/link: don't split container symbols when write blocks We split the output into blocks and write them in parallel. The block boundary is placed at symbol boundary. In the case of outer symbols and sub symbols, currently we may split an outer symbol into two blocks. This will be bad, as the two blocks will have overlapping address range, since outer symbol and its sub symbols occupies the same address range. Make sure we place block boundary only at top-level symbol boundaries. Fix boringcrypto build. Change-Id: I56811d3969c65c6be97672d8e1f1ea36b2447465 Reviewed-on: https://go-review.googlesource.com/c/go/+/227957 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Than McIntosh (cherry picked from commit 636fa3148fe149923839a86e648dd87dc4d1537a) Reviewed-on: https://go-review.googlesource.com/c/go/+/228138 --- src/cmd/link/internal/ld/data.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index 7c4b08a805..f98cbcc285 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -812,6 +812,10 @@ func writeBlocks(out *OutBuf, sem chan int, syms []*sym.Symbol, addr, size int64 // Find the last symbol we'd write. idx := -1 for i, s := range syms { + if s.Attr.SubSymbol() { + continue + } + // If the next symbol's size would put us out of bounds on the total length, // stop looking. if s.Value+s.Size > lastAddr { @@ -839,7 +843,15 @@ func writeBlocks(out *OutBuf, sem chan int, syms []*sym.Symbol, addr, size int64 // blocks or at the end. length := int64(0) if idx+1 < len(syms) { - length = syms[idx+1].Value - addr + // Find the next top-level symbol. + // Skip over sub symbols so we won't split a containter symbol + // into two blocks. + next := syms[idx+1] + for next.Attr.SubSymbol() { + idx++ + next = syms[idx+1] + } + length = next.Value - addr } if length == 0 || length > lastAddr-addr { length = lastAddr - addr