From: Cherry Mui Date: Thu, 23 Mar 2023 20:10:05 +0000 (-0400) Subject: cmd/link: add padding after runtime.etext X-Git-Tag: go1.21rc1~1163 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a6c382eaa8eaa611d71232aa4d5391b56a5c2693;p=gostls13.git cmd/link: add padding after runtime.etext The runtime.etext symbol is a marker symbol that marks the end of (Go's) text section. Currently it has 0 size on some platforms. Especially in external linking mode, this may cause the next symbol (e.g. a C function) to have the same address as runtime.etext, which may confuse some symbolizer. Add some padding bytes to avoid address collision. Change-Id: Ic450bab72e4ac79a3b6b891729831d4148b89234 Reviewed-on: https://go-review.googlesource.com/c/go/+/479075 Run-TryBot: Cherry Mui Reviewed-by: Nicolas Hillegeer Run-TryBot: Nicolas Hillegeer Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot --- diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index bd8d17b110..01f9bc7099 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -2416,7 +2416,9 @@ func (ctxt *Link) textaddress() { } } - sect.Length = va - sect.Vaddr + // Add MinLC size after etext, so it won't collide with the next symbol + // (which may confuse some symbolizer). + sect.Length = va - sect.Vaddr + uint64(ctxt.Arch.MinLC) ldr.SetSymSect(etext, sect) if ldr.SymValue(etext) == 0 { // Set the address of the start/end symbols, if not already