Skip to content

Commit 236c07c

Browse files
thanmgopherbot
authored andcommitted
[release-branch.go1.21] 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. Updates #58425. Fixes #63317. Change-Id: I7372d41abce84097906a3d0805b6b9c486f345d6 Reviewed-on: https://go-review.googlesource.com/c/go/+/531795 Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Than McIntosh <[email protected]> TryBot-Result: Gopher Robot <[email protected]> (cherry picked from commit 1e69040) Reviewed-on: https://go-review.googlesource.com/c/go/+/532096 Auto-Submit: Dmitri Shuralyov <[email protected]>
1 parent 9465990 commit 236c07c

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
@@ -2599,15 +2599,22 @@ func assignAddress(ctxt *Link, sect *sym.Section, n int, s loader.Sym, va uint64
25992599

26002600
// Return whether we may need to split text sections.
26012601
//
2602-
// On PPC64x whem external linking a text section should not be larger than 2^25 bytes
2603-
// due to the size of call target offset field in the bl instruction. Splitting into
2604-
// smaller text sections smaller than this limit allows the system linker to modify the long
2605-
// calls appropriately. The limit allows for the space needed for tables inserted by the
2606-
// linker.
2602+
// On PPC64x, when external linking, a text section should not be
2603+
// larger than 2^25 bytes due to the size of call target offset field
2604+
// in the 'bl' instruction. Splitting into smaller text sections
2605+
// smaller than this limit allows the system linker to modify the long
2606+
// calls appropriately. The limit allows for the space needed for
2607+
// tables inserted by the linker.
26072608
//
26082609
// The same applies to Darwin/ARM64, with 2^27 byte threshold.
2610+
//
2611+
// Similarly for ARM, we split sections (at 2^25 bytes) to avoid
2612+
// inconsistencies between the Go linker's reachability calculations
2613+
// (e.g. will direct call from X to Y need a trampoline) and similar
2614+
// machinery in the external linker; see #58425 for more on the
2615+
// history here.
26092616
func splitTextSections(ctxt *Link) bool {
2610-
return (ctxt.IsPPC64() || (ctxt.IsARM64() && ctxt.IsDarwin())) && ctxt.IsExternal()
2617+
return (ctxt.IsARM() || ctxt.IsPPC64() || (ctxt.IsARM64() && ctxt.IsDarwin())) && ctxt.IsExternal()
26112618
}
26122619

26132620
// 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)