]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.22] cmd/link: put runtime.end in the last section of data segment
authorCherry Mui <cherryyz@google.com>
Tue, 11 Jun 2024 22:39:19 +0000 (18:39 -0400)
committerJoedian Reid <joedian@google.com>
Mon, 24 Jun 2024 17:00:28 +0000 (17:00 +0000)
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 <thanm@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
(cherry picked from commit b589478af7f4b09cc9c4d5f76fbbf5cad2b2b7bb)
Reviewed-on: https://go-review.googlesource.com/c/go/+/592478

src/cmd/go/testdata/script/test_fuzz_cgo.txt [new file with mode: 0644]
src/cmd/link/internal/ld/data.go

diff --git a/src/cmd/go/testdata/script/test_fuzz_cgo.txt b/src/cmd/go/testdata/script/test_fuzz_cgo.txt
new file mode 100644 (file)
index 0000000..1a04877
--- /dev/null
@@ -0,0 +1,28 @@
+[!fuzz] skip
+[!cgo] skip
+[short] skip
+env GOCACHE=$WORK/cache
+
+# Test that fuzzing works with cgo (issue 65169)
+
+go test -fuzz=. -fuzztime=1x
+stdout ok
+! stdout FAIL
+
+-- go.mod --
+module example.com/p
+
+go 1.20
+-- c.go --
+package p
+
+import "C"
+-- c_test.go --
+package p
+
+import "testing"
+
+func Fuzz(f *testing.F) {
+       f.Add(0)
+       f.Fuzz(func(t *testing.T, x int) {})
+}
index f4ea8407c83d057d163bb5d71c6dce2dabec81ee..a5a0615c8dff8d4fa42a587c5b7966e3bb80baf2 100644 (file)
@@ -1915,7 +1915,6 @@ func (state *dodataState) allocateDataSections(ctxt *Link) {
        sect = state.allocateNamedSectionAndAssignSyms(&Segdata, ".noptrbss", sym.SNOPTRBSS, sym.Sxxx, 06)
        ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.noptrbss", 0), sect)
        ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.enoptrbss", 0), sect)
-       ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.end", 0), sect)
 
        // Code coverage counters are assigned to the .noptrbss section.
        // We assign them in a separate pass so that they stay aggregated
@@ -1935,6 +1934,9 @@ func (state *dodataState) allocateDataSections(ctxt *Link) {
                ldr.SetSymSect(ldr.LookupOrCreateSym("internal/fuzz._ecounters", 0), sect)
        }
 
+       // Assign runtime.end to the last section of data segment.
+       ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.end", 0), Segdata.Sections[len(Segdata.Sections)-1])
+
        if len(state.data[sym.STLSBSS]) > 0 {
                var sect *sym.Section
                // FIXME: not clear why it is sometimes necessary to suppress .tbss section creation.