Skip to content

Commit 4c97e88

Browse files
cherrymuijoedian
authored andcommitted
[release-branch.go1.22] 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. Updates #65169. Fixes #67945. 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]> (cherry picked from commit b589478) Reviewed-on: https://go-review.googlesource.com/c/go/+/592478
1 parent 179ccb7 commit 4c97e88

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed
Lines changed: 28 additions & 0 deletions
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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,6 @@ func (state *dodataState) allocateDataSections(ctxt *Link) {
19151915
sect = state.allocateNamedSectionAndAssignSyms(&Segdata, ".noptrbss", sym.SNOPTRBSS, sym.Sxxx, 06)
19161916
ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.noptrbss", 0), sect)
19171917
ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.enoptrbss", 0), sect)
1918-
ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.end", 0), sect)
19191918

19201919
// Code coverage counters are assigned to the .noptrbss section.
19211920
// We assign them in a separate pass so that they stay aggregated
@@ -1935,6 +1934,9 @@ func (state *dodataState) allocateDataSections(ctxt *Link) {
19351934
ldr.SetSymSect(ldr.LookupOrCreateSym("internal/fuzz._ecounters", 0), sect)
19361935
}
19371936

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

0 commit comments

Comments
 (0)