Skip to content

Commit 1e69040

Browse files
committed
cmd/link: split text sections for arm 32-bit
This CL is a roll-forward (tweaked slightly) of CL 467715, which turned on text section splitting for GOARCH=arm. The intent is to avoid recurrent problems with external linking where there is a disagreement between the Go linker and the external linker over whether a given branch will reach. In the past our approach has been to tweak the reachability calculations slightly to try to work around potential linker problems, but this hasn't proven to be very robust; section splitting seems to offer a better long term fix. Fixes #58425. Change-Id: I7372d41abce84097906a3d0805b6b9c486f345d6 Reviewed-on: https://go-review.googlesource.com/c/go/+/531795 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
1 parent fa4f951 commit 1e69040

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,15 +2615,22 @@ func assignAddress(ctxt *Link, sect *sym.Section, n int, s loader.Sym, va uint64
26152615

26162616
// Return whether we may need to split text sections.
26172617
//
2618-
// On PPC64x whem external linking a text section should not be larger than 2^25 bytes
2619-
// due to the size of call target offset field in the bl instruction. Splitting into
2620-
// smaller text sections smaller than this limit allows the system linker to modify the long
2621-
// calls appropriately. The limit allows for the space needed for tables inserted by the
2622-
// linker.
2618+
// On PPC64x, when external linking, a text section should not be
2619+
// larger than 2^25 bytes due to the size of call target offset field
2620+
// in the 'bl' instruction. Splitting into smaller text sections
2621+
// smaller than this limit allows the system linker to modify the long
2622+
// calls appropriately. The limit allows for the space needed for
2623+
// tables inserted by the linker.
26232624
//
26242625
// The same applies to Darwin/ARM64, with 2^27 byte threshold.
2626+
//
2627+
// Similarly for ARM, we split sections (at 2^25 bytes) to avoid
2628+
// inconsistencies between the Go linker's reachability calculations
2629+
// (e.g. will direct call from X to Y need a trampoline) and similar
2630+
// machinery in the external linker; see #58425 for more on the
2631+
// history here.
26252632
func splitTextSections(ctxt *Link) bool {
2626-
return (ctxt.IsPPC64() || (ctxt.IsARM64() && ctxt.IsDarwin())) && ctxt.IsExternal()
2633+
return (ctxt.IsARM() || ctxt.IsPPC64() || (ctxt.IsARM64() && ctxt.IsDarwin())) && ctxt.IsExternal()
26272634
}
26282635

26292636
// On Wasm, we reserve 4096 bytes for zero page, then 8192 bytes for wasm_exec.js

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestArchiveBuildInvokeWithExec(t *testing.T) {
136136

137137
func TestLargeTextSectionSplitting(t *testing.T) {
138138
switch runtime.GOARCH {
139-
case "ppc64", "ppc64le":
139+
case "ppc64", "ppc64le", "arm":
140140
case "arm64":
141141
if runtime.GOOS == "darwin" {
142142
break

0 commit comments

Comments
 (0)