]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/link/internal/ld: fix text section splitting for ARM
authorThan McIntosh <thanm@google.com>
Mon, 13 Feb 2023 15:13:57 +0000 (10:13 -0500)
committerThan McIntosh <thanm@google.com>
Mon, 13 Feb 2023 20:23:57 +0000 (20:23 +0000)
Fix a problem with trampoline generation for ARM that was causing link
failures when building selected k8s targets. Representative error
(this is coming from the external linker):

  go.go:(.text+...): relocation truncated to fit: R_ARM_CALL against `runtime.duffcopy'

The Go linker is supposed to be limiting text section size for ARM to
0x1c00000 bytes, however due to a problem in the tramp generation
phase this limit wasn't being enforced.

Updates #58428.
Fixes #58425.

Change-Id: I4e778bdcbebeab607a6e626b354ca5109e52a1aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/467715
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/link/internal/ld/data.go

index 05c6da3e3bbf43c6174186823f03c7647b199efb..e161a0a29187baa13f6f56091f6a99a24f54b604 100644 (file)
@@ -84,6 +84,9 @@ func maxSizeTrampolines(ctxt *Link, ldr *loader.Loader, s loader.Sym, isTramp bo
                }
        }
 
+       if ctxt.IsARM() {
+               return n * 20 // Trampolines in ARM range from 3 to 5 instructions.
+       }
        if ctxt.IsPPC64() {
                return n * 16 // Trampolines in PPC64 are 4 instructions.
        }
@@ -2533,7 +2536,7 @@ func assignAddress(ctxt *Link, sect *sym.Section, n int, s loader.Sym, va uint64
 //
 // The same applies to Darwin/ARM64, with 2^27 byte threshold.
 func splitTextSections(ctxt *Link) bool {
-       return (ctxt.IsPPC64() || (ctxt.IsARM64() && ctxt.IsDarwin())) && ctxt.IsExternal()
+       return (ctxt.IsARM() || ctxt.IsPPC64() || (ctxt.IsARM64() && ctxt.IsDarwin())) && ctxt.IsExternal()
 }
 
 // On Wasm, we reserve 4096 bytes for zero page, then 8192 bytes for wasm_exec.js