Skip to content

Commit b589478

Browse files
committed
cmd/link: put runtime.end in the last section of data segment
Currently the runtime.end symbol is put into the noptrbss section, which is usually the last section, except that when fuzzing is enabled, the last section is actually .go.fuzzcntrs. The runtime.end symbol has the value pointing to the end of the data segment, so if it is not in the last section, the value will not actually be in the range of the section. This causes an assertion failure in the new Apple linker. This CL fixes this by putting it in the last section. Fixes #65169. Change-Id: I5c991c46a0483a96e5f6e0255a3b444953676026 Reviewed-on: https://go-review.googlesource.com/c/go/+/592095 Reviewed-by: Than McIntosh <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent b788e91 commit b589478

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[!fuzz] skip
2+
[!cgo] skip
3+
[short] skip
4+
env GOCACHE=$WORK/cache
5+
6+
# Test that fuzzing works with cgo (issue 65169)
7+
8+
go test -fuzz=. -fuzztime=1x
9+
stdout ok
10+
! stdout FAIL
11+
12+
-- go.mod --
13+
module example.com/p
14+
15+
go 1.20
16+
-- c.go --
17+
package p
18+
19+
import "C"
20+
-- c_test.go --
21+
package p
22+
23+
import "testing"
24+
25+
func Fuzz(f *testing.F) {
26+
f.Add(0)
27+
f.Fuzz(func(t *testing.T, x int) {})
28+
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,6 @@ func (state *dodataState) allocateDataSections(ctxt *Link) {
19181918
sect = state.allocateNamedSectionAndAssignSyms(&Segdata, ".noptrbss", sym.SNOPTRBSS, sym.Sxxx, 06)
19191919
ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.noptrbss", 0), sect)
19201920
ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.enoptrbss", 0), sect)
1921-
ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.end", 0), sect)
19221921

19231922
// Code coverage counters are assigned to the .noptrbss section.
19241923
// We assign them in a separate pass so that they stay aggregated
@@ -1938,6 +1937,9 @@ func (state *dodataState) allocateDataSections(ctxt *Link) {
19381937
ldr.SetSymSect(ldr.LookupOrCreateSym("internal/fuzz._ecounters", 0), sect)
19391938
}
19401939

1940+
// Assign runtime.end to the last section of data segment.
1941+
ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.end", 0), Segdata.Sections[len(Segdata.Sections)-1])
1942+
19411943
if len(state.data[sym.STLSBSS]) > 0 {
19421944
var sect *sym.Section
19431945
// FIXME: not clear why it is sometimes necessary to suppress .tbss section creation.

0 commit comments

Comments
 (0)