Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
5500cbf
debug/elf: prevent offset overflow
callthingsoff Sep 25, 2025
6d51f93
runtime: jump instead of branch in netbsd/arm64 entry point
qmuntal Sep 29, 2025
d42d56b
encoding/xml: make use of reflect.TypeAssert
apocelipes Sep 24, 2025
fe3ba74
cmd/link: skip TestFlagW on platforms without DWARF symbol table
millerresearch Sep 27, 2025
ae8eba0
cmd/link: use correct length for pcln.cutab
ianlancetaylor Sep 29, 2025
047c2ab
cmd/link: don't pass -Wl,-S on Solaris
cherrymui Sep 26, 2025
4e9006a
crypto/tls: quote protocols in ALPN error message
rolandshoemaker Sep 29, 2025
4b77733
internal/syscall/windows: regenerate GetFileSizeEx
qmuntal Sep 29, 2025
eaf2345
cmd/link: use a .def file to mark exported symbols on Windows
qmuntal Sep 22, 2025
690fc2f
internal/poll: remove buf field from operation
qmuntal Sep 16, 2025
db3cb3f
runtime: correct reference to getStackMap in comment
ianlancetaylor Sep 29, 2025
db4fade
crypto/internal/fips140/mlkem: make CAST conditional
FiloSottile Sep 22, 2025
fc88e18
crypto/internal/fips140/entropy: add CPU jitter-based entropy source
FiloSottile Sep 11, 2025
75c87df
internal/poll: pass the I/O mode instead of an overlapped object in e…
qmuntal Sep 16, 2025
db10db6
internal/poll: remove operation fields from FD
qmuntal Sep 16, 2025
742f920
cmd/compile, runtime: always enable Wasm signext and satconv features
cherrymui Sep 29, 2025
6e95748
cmd/link/internal/arm64: support Mach-O ARM64_RELOC_POINTER_TO_GOT in…
qmuntal Sep 12, 2025
7c8166d
cmd/link/internal/arm64: support Mach-O ARM64_RELOC_SUBTRACTOR in int…
qmuntal Sep 12, 2025
a846bb0
errors: add AsType
jub0bs Sep 29, 2025
300d9d2
runtime: initialise debug settings much earlier in startup process
9muir Sep 18, 2025
97da068
cmd/compile: eliminate nil checks on .dict arg
jakebailey Sep 8, 2025
08afc50
mime: extend "builtinTypes" to include a more complete list of common…
AidanWelch Sep 25, 2025
19cc102
mime: reduce allocs incurred by ParseMediaType
jub0bs Sep 22, 2025
fcb893f
cmd/compile/internal/ssa: remove redundant "type:" prefix check
fengyoulin Sep 5, 2025
4ff8a45
test/codegen: codify handling of floating point constants on arm64
4a6f656c Sep 15, 2025
c925715
runtime: unify ppc64/ppc64le library entry point
qmuntal Sep 24, 2025
eb1c7f6
runtime: move loong64 library entry point to os-agnostic file
qmuntal Sep 24, 2025
be0fed8
cmd/go/testdata/script/test_fuzz_fuzztime.txt: disable
adonovan Sep 30, 2025
3f451f2
testing/synctest: fix inverted test failure message in TestContextAft…
fgm Oct 1, 2025
8ad27fb
doc/go_spec.html: update date
adonovan Oct 1, 2025
633dd1d
encoding/json: fix Decoder.InputOffset regression in goexperiment.jsonv2
dsnet Sep 15, 2025
5799c13
crypto/tls: rm marshalEncryptedClientHelloConfigList dead code
cpu Sep 29, 2025
84db201
cmd/compile: propagate len([]T{}) to make builtin to allow stack allo…
mateusz834 Sep 26, 2025
8c68a1c
runtime,net/http/pprof: goroutine leak detection by using the garbage…
VladSaiocUber Oct 2, 2025
707454b
cmd/go: update `go help mod edit` with the tool and ignore sections
mvdan Aug 30, 2025
f03c392
runtime: fix aix/ppc64 library initialization
qmuntal Oct 1, 2025
0e4e2e6
runtime: skip TestGoroutineLeakProfile under mayMoreStackPreempt
mknyszek Oct 2, 2025
4008e07
io/fs: move path name documentation up to the package doc comment
neild Oct 2, 2025
bbdff9e
net/http: update bundled x/net/http2 and delete obsolete http2inTests
nicholashusin Oct 2, 2025
5384500
net/http/httputil: deprecate ReverseProxy.Director
neild Oct 2, 2025
d5b9503
cmd/cgo: fix unaligned arguments typedmemmove crash on iOS
timcooijmans Sep 30, 2025
adce7f1
cmd/link: support .def file with MSVC clang toolchain
cherrymui Oct 2, 2025
630799c
crypto/tls: add flag to render HTML BoGo report
cpu Jun 30, 2025
a7917ee
internal/buildcfg: enable specializedmalloc experiment
matloob Mar 17, 2025
c54dc14
runtime: support valgrind (but not asan) in specialized malloc functions
matloob Oct 1, 2025
ebb72be
cmd/compile: don't treat devel compiler as a released compiler
cherrymui Jun 20, 2025
ab04395
cmd/compile: minor tweak for race detector
dr2chase Jul 2, 2025
10e7968
cmd/compile: accounts rematerialize ops's output reginfo
JunyangShao Aug 12, 2025
ec70d19
cmd/compile: rewrite to elide Slicemask from len==c>0 slicing
dr2chase Aug 20, 2025
1caa95a
cmd/compile: enhance prove to deal with double-offset IsInBounds checks
dr2chase Sep 3, 2025
18cd4a1
cmd/compile: use the right type for spill slot
cherrymui Sep 16, 2025
ad3db25
cmd/compile: handle rematerialized op for incompatible reg constraint
JunyangShao Sep 16, 2025
20c9377
cmd/compile: enhance the chunked indexing case to include reslicing
dr2chase Sep 17, 2025
d91148c
cmd/compile: enhance prove to infer bounds in slice len/cap calculations
dr2chase Sep 17, 2025
003b5ce
cmd/compile: fix SIMD const rematerialization condition
JunyangShao Sep 19, 2025
38b26f2
cmd/compile: remove stores to unread parameters
cherrymui Sep 22, 2025
1bca4c1
cmd/compile: improve slicemask removal
dr2chase Sep 17, 2025
ee5369b
cmd/link: add LIBRARY statement only with -buildmode=cshared
qmuntal Oct 3, 2025
2a71af1
net/url: improve URL docs
mateusz834 Sep 24, 2025
3a05e7b
spec: close tag
eikemeier Oct 5, 2025
e74b224
crypto/tls: streamline BoGo testing w/ -bogo-local-dir
cpu Jul 11, 2025
ac2ec82
runtime: bump thread count slack for TestReadMetricsSched
mknyszek Oct 3, 2025
c2fb151
testing/synctest: remove Run
seankhliao Oct 5, 2025
2441645
cmd/go: export type State
jitsu-net Aug 20, 2025
f331212
runtime: remove batching from spanSPMC free
prattmic Oct 6, 2025
719dfcf
cmd/compile: redo arm64 LR/FP save and restore
randall77 May 17, 2025
4fca798
runtime: delete redundant code in the page allocator
Sep 29, 2025
1d62e92
test/codegen: make sure assignment results are used.
cherrymui Oct 4, 2025
7bfeb43
cmd/go: refactor usage of `initialized`
jitsu-net Aug 20, 2025
7fbf54b
internal/buildcfg: enable greenteagc experiment by default
mknyszek Mar 9, 2025
c1e6e49
fmt: reduce Errorf("x") allocations to match errors.New("x")
thepudds Oct 3, 2025
4c0fd3a
internal/goexperiment: remove the synctest GOEXPERIMENT
mateusz834 Oct 6, 2025
6469954
runtime: assert p.destroy runs with GC not running
prattmic Oct 6, 2025
c938051
Revert "cmd/compile: redo arm64 LR/FP save and restore"
randall77 Oct 7, 2025
f86ddb5
cmd/go: refactor usage of `ForceUseModules`
jitsu-net Aug 20, 2025
2e52060
cmd/go: refactor usage of `RootMode`
jitsu-net Aug 20, 2025
11d5484
runtime: fix self-deadlock on sbrk platforms
mknyszek Oct 7, 2025
6f79265
cmd/go: refactor usage of `modRoots`
jitsu-net Aug 20, 2025
6e4007e
crypto/x509: mitigate DoS vector when intermediate certificate contai…
thatnealpatel Sep 11, 2025
3fc4c79
crypto/x509: improve domain name verification
thatnealpatel Sep 15, 2025
9b9d02c
net/http: add httpcookiemaxnum GODEBUG option to limit number of cook…
nicholashusin Sep 30, 2025
8709a41
encoding/asn1: prevent memory exhaustion when parsing using internal/…
nicholashusin Sep 3, 2025
3ee7617
runtime: free spanQueue on P destroy
prattmic Oct 6, 2025
7dd54e1
runtime: make work.spanSPMCs.all doubly-linked
prattmic Oct 6, 2025
f6f4e8b
net/url: enforce stricter parsing of bracketed IPv6 hostnames
ethanalee-work Aug 29, 2025
5ce8cd1
encoding/pem: make Decode complexity linear
rolandshoemaker Sep 30, 2025
5ede095
net/textproto: avoid quadratic complexity in Reader.ReadResponse
neild Sep 30, 2025
4631656
net/mail: avoid quadratic behavior in mail address parsing
neild Sep 25, 2025
f7a68d3
archive/tar: set a limit on the size of GNU sparse file 1.0 regions
neild Sep 11, 2025
f2d0d05
cmd/go: refactor usage of `MainModules`
jitsu-net Aug 20, 2025
cb81270
Revert "crypto/internal/fips140/subtle: add assembly implementation o…
randall77 Oct 7, 2025
a1661e7
Revert "crypto/internal/fips140/subtle: add assembly implementation o…
randall77 Oct 7, 2025
1623927
cmd/go: refactor usage of `requirements`
jitsu-net Aug 21, 2025
bb1ca7a
cmd/go, testing: add TB.ArtifactDir and -artifacts flag
neild Aug 15, 2025
78b4303
cmd/go: refactor usage of `workFilePath`
jitsu-net Aug 21, 2025
97fd6bd
cmd/compile: fuse NaN checks with other comparisons
Aug 18, 2025
e5d004c
net/http: update HTTP/2 documentation to reference new config features
neild Oct 7, 2025
e1ca1de
net/http: format pprof.go
VladSaiocUber Oct 6, 2025
d4830c6
cmd/internal/obj: fix Link.Diag printf errors
adonovan Oct 8, 2025
d945600
cmd/gofmt: change -d to exit 1 if diffs exist
robbiemcmichael Oct 6, 2025
941e591
runtime: cleanup comments from asm_ppc64x.s improvements
pmur Oct 1, 2025
ae094a1
crypto/internal/fips140test: make entropy file pair names match
FiloSottile Sep 29, 2025
de9da0d
cmd/compile/internal/devirtualize: improve concrete type analysis
mateusz834 Oct 7, 2025
ee16319
path/filepath: return cleaned path from Rel
guerinoni Oct 6, 2025
4837fbe
net/http/httptest: check whether response bodies are allowed
seankhliao Oct 5, 2025
0e466a8
cmd/compile: modify float-to-[u]int so that amd64 and arm64 match
dr2chase Jul 21, 2025
78d75b3
cmd/compile: make 386 float-to-int conversions match amd64
dr2chase Sep 30, 2025
b9f3acc
runtime: adjust softfloat corner cases to match amd64/arm64
dr2chase Oct 6, 2025
8d81028
cmd/compile: make wasm match other platforms for FP->int32/64 convers…
dr2chase Oct 1, 2025
9db7e30
net/url: allow IP-literals with IPv4-mapped IPv6 addresses
rolandshoemaker Oct 9, 2025
80f3bb5
reflect: remove timeout in TestChanOfGC
mknyszek Oct 9, 2025
19a30ea
cmd/compile: call generated size-specialized malloc functions directly
matloob Sep 29, 2025
954fdcc
cmd/compile: declare no output register for loong64 LoweredAtomic{And…
xen0n Oct 9, 2025
c53cb64
internal/buildcfg: enable greenteagc experiment for loong64
xen0n Oct 9, 2025
5368e77
net/http: run TestRequestWriteTransport with fake time to avoid flakes
neild Oct 9, 2025
955a5a0
runtime: support arm64 Neon in async preemption
Aug 13, 2025
6f4c63b
cmd/go: unify "go fix" and "go vet"
adonovan Sep 26, 2025
69e8279
net/http: set cookie host to Request.Host when available
seankhliao Oct 8, 2025
584a89f
all: omit unnecessary reassignment
cuishuang Oct 10, 2025
aced4c7
net/http: strip request body headers on POST to GET redirects
seankhliao Oct 9, 2025
e3be2d1
net/url: disallow raw IPv6 addresses in host
seankhliao Oct 9, 2025
e8a5353
runtime: fail TestGoroutineLeakProfile on data race
mknyszek Oct 9, 2025
48bb7a6
cmd/compile: repair bisection behavior for float-to-unsigned conversion
dr2chase Oct 10, 2025
b497a29
encoding/json: fix regression in quoted numbers under goexperiment.js…
dsnet Oct 6, 2025
8aa1efa
cmd/link: in TestFallocate, only check number of blocks on Darwin
cherrymui Oct 11, 2025
1cd7168
crypto/x509: rework fix for CVE-2025-58187
rolandshoemaker Oct 9, 2025
6bcd97d
all: replace calls to errors.As with errors.AsType
jub0bs Oct 1, 2025
0e64ee1
encoding/json/v2: report EOF for top-level values in UnmarshalDecode
dsnet Oct 11, 2025
2309801
net/url: add benchmarks for Encode
jub0bs Oct 13, 2025
569f3ff
net/url: eschew iterators in Encode
jub0bs Oct 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions api/next/51945.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg errors, func AsType[$0 error](error) ($0, bool) #51945
4 changes: 4 additions & 0 deletions api/next/71287.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pkg testing, method (*B) ArtifactDir() string #71287
pkg testing, method (*F) ArtifactDir() string #71287
pkg testing, method (*T) ArtifactDir() string #71287
pkg testing, type TB interface, ArtifactDir() string #71287
1 change: 1 addition & 0 deletions api/next/73161.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg net/http/httputil, type ReverseProxy struct, Director //deprecated #73161
12 changes: 6 additions & 6 deletions doc/go_spec.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Language version go1.25 (Feb 25, 2025)",
"Subtitle": "Language version go1.26 (Oct 1, 2025)",
"Path": "/ref/spec"
}-->

Expand Down Expand Up @@ -3173,7 +3173,7 @@ <h3 id="Composite_literals">Composite literals</h3>

<p>
Unless the LiteralType is a type parameter,
its <a href="#Underlying_types">underlying type
its <a href="#Underlying_types">underlying type</a>
must be a struct, array, slice, or map type
(the syntax enforces this constraint except when the type is given
as a TypeName).
Expand Down Expand Up @@ -4873,7 +4873,7 @@ <h4 id="Operator_precedence">Operator precedence</h4>
x &lt;= f() // x &lt;= f()
^a &gt;&gt; b // (^a) >> b
f() || g() // f() || g()
x == y+1 &amp;&amp; &lt;-chanInt &gt; 0 // (x == (y+1)) && ((<-chanInt) > 0)
x == y+1 &amp;&amp; &lt;-chanInt &gt; 0 // (x == (y+1)) && ((&lt;-chanInt) > 0)
</pre>


Expand Down Expand Up @@ -6635,7 +6635,7 @@ <h4 id="For_clause">For statements with <code>for</code> clause</h4>

<pre>
var prints []func()
for i := 0; i < 5; i++ {
for i := 0; i &lt; 5; i++ {
prints = append(prints, func() { println(i) })
i++
}
Expand Down Expand Up @@ -6772,7 +6772,7 @@ <h4 id="For_range">For statements with <code>range</code> clause</h4>
variable, which must be of integer type.
Otherwise, if the iteration variable is declared by the "range" clause or is absent,
the type of the iteration values is the <a href="#Constants">default type</a> for <code>n</code>.
If <code>n</code> &lt= 0, the loop does not run any iterations.
If <code>n</code> &lt;= 0, the loop does not run any iterations.
</li>

<li>
Expand Down Expand Up @@ -7799,7 +7799,7 @@ <h3 id="Min_and_max">Min and max</h3>
</p>

<pre>
min(x, y) == if x <= y then x else y
min(x, y) == if x &lt;= y then x else y
min(x, y, z) == min(min(x, y), z)
</pre>

Expand Down
10 changes: 10 additions & 0 deletions doc/godebug.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ for example,
see the [runtime documentation](/pkg/runtime#hdr-Environment_Variables)
and the [go command documentation](/cmd/go#hdr-Build_and_test_caching).

### Go 1.26

Go 1.26 added a new `httpcookiemaxnum` setting that controls the maximum number
of cookies that net/http will accept when parsing HTTP headers. If the number of
cookie in a header exceeds the number set in `httpcookiemaxnum`, cookie parsing
will fail early. The default value is `httpcookiemaxnum=3000`. Setting
`httpcookiemaxnum=0` will allow the cookie parsing to accept an indefinite
number of cookies. To avoid denial of service attacks, this setting and default
was backported to Go 1.25.2 and Go 1.24.8.

### Go 1.25

Go 1.25 added a new `decoratemappings` setting that controls whether the Go
Expand Down
10 changes: 10 additions & 0 deletions doc/next/3-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,15 @@
a replacement for `go tool doc`: it takes the same flags and arguments and
has the same behavior.

<!-- go.dev/issue/75432 -->
The `go fix` command, following the pattern of `go vet` in Go 1.10,
now uses the Go analysis framework (`golang.org/x/tools/go/analysis`).
This means the same analyzers that provide diagnostics in `go vet`
can be used to suggest and apply fixes in `go fix`.
The `go fix` command's historical fixers, all of which were obsolete,
have been removed and replaced by a suite of new analyzers that
offer fixes to use newer features of the language and library.
<!-- I'll write a blog post that discusses this at length. --adonovan -->

### Cgo {#cgo}

2 changes: 2 additions & 0 deletions doc/next/6-stdlib/99-minor/errors/51945.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The new [AsType] function is a generic version of [As]. It is type-safe, faster,
and, in most cases, easier to use.
11 changes: 11 additions & 0 deletions doc/next/6-stdlib/99-minor/net/http/httputil/73161.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
The [ReverseProxy.Director] configuration field is deprecated
in favor of [ReverseProxy.Rewrite].

A malicious client can remove headers added by a `Director` function
by designating those headers as hop-by-hop. Since there is no way to address
this problem within the scope of the `Director` API, we added a new
`Rewrite` hook in Go 1.20. `Rewrite` hooks are provided with both the
unmodified inbound request received by the proxy and the outbound request
which will be sent by the proxy.

Since the `Director` hook is fundamentally unsafe, we are now deprecating it.
18 changes: 18 additions & 0 deletions doc/next/6-stdlib/99-minor/testing/71287.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
The new methods [T.ArtifactDir], [B.ArtifactDir], and [F.ArtifactDir]
return a directory in which to write test output files (artifacts).

When the `-artifacts` flag is provided to `go test`,
this directory will be located under the output directory
(specified with `-outputdir`, or the current directory by default).
Otherwise, artifacts are stored in a temporary directory
which is removed after the test completes.

The first call to `ArtifactDir` when `-artifacts` is provided
writes the location of the directory to the test log.

For example, in a test named `TestArtifacts`,
`t.ArtifactDir()` emits:

```
=== ARTIFACTS Test /path/to/artifact/dir
```
1 change: 1 addition & 0 deletions src/archive/tar/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
errMissData = errors.New("archive/tar: sparse file references non-existent data")
errUnrefData = errors.New("archive/tar: sparse file contains unreferenced data")
errWriteHole = errors.New("archive/tar: write non-NUL byte in sparse hole")
errSparseTooLong = errors.New("archive/tar: sparse map too long")
)

type headerError []string
Expand Down
9 changes: 7 additions & 2 deletions src/archive/tar/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,17 @@ func readGNUSparseMap1x0(r io.Reader) (sparseDatas, error) {
cntNewline int64
buf bytes.Buffer
blk block
totalSize int
)

// feedTokens copies data in blocks from r into buf until there are
// at least cnt newlines in buf. It will not read more blocks than needed.
feedTokens := func(n int64) error {
for cntNewline < n {
totalSize += len(blk)
if totalSize > maxSpecialFileSize {
return errSparseTooLong
}
if _, err := mustReadFull(r, blk[:]); err != nil {
return err
}
Expand Down Expand Up @@ -569,8 +574,8 @@ func readGNUSparseMap1x0(r io.Reader) (sparseDatas, error) {
}

// Parse for all member entries.
// numEntries is trusted after this since a potential attacker must have
// committed resources proportional to what this library used.
// numEntries is trusted after this since feedTokens limits the number of
// tokens based on maxSpecialFileSize.
if err := feedTokens(2 * numEntries); err != nil {
return nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions src/archive/tar/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,11 @@ func TestReader(t *testing.T) {
},
Format: FormatPAX,
}},
}, {
// Small compressed file that uncompresses to
// a file with a very large GNU 1.0 sparse map.
file: "testdata/gnu-sparse-many-zeros.tar.bz2",
err: errSparseTooLong,
}}

for _, v := range vectors {
Expand Down
Binary file not shown.
75 changes: 31 additions & 44 deletions src/cmd/cgo/internal/testcshared/cshared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bufio"
"bytes"
"cmd/cgo/internal/cgotest"
"cmp"
"debug/elf"
"debug/pe"
"encoding/binary"
Expand Down Expand Up @@ -272,7 +273,7 @@ func createHeaders() error {
// which results in the linkers output implib getting overwritten at each step. So instead build the
// import library the traditional way, using a def file.
err = os.WriteFile("libgo.def",
[]byte("LIBRARY libgo.dll\nEXPORTS\n\tDidInitRun\n\tDidMainRun\n\tDivu\n\tFromPkg\n\t_cgo_dummy_export\n"),
[]byte("LIBRARY libgo.dll\nEXPORTS\n\tDidInitRun\n\tDidMainRun\n\tDivu\n\tFromPkg\n"),
0644)
if err != nil {
return fmt.Errorf("unable to write def file: %v", err)
Expand Down Expand Up @@ -375,9 +376,23 @@ func TestExportedSymbols(t *testing.T) {
}
}

func checkNumberOfExportedFunctionsWindows(t *testing.T, prog string, exportedFunctions int, wantAll bool) {
func checkNumberOfExportedSymbolsWindows(t *testing.T, exportedSymbols int, wantAll bool) {
t.Parallel()
tmpdir := t.TempDir()

prog := `
package main
import "C"
func main() {}
`

for i := range exportedSymbols {
prog += fmt.Sprintf(`
//export GoFunc%d
func GoFunc%d() {}
`, i, i)
}

srcfile := filepath.Join(tmpdir, "test.go")
objfile := filepath.Join(tmpdir, "test.dll")
if err := os.WriteFile(srcfile, []byte(prog), 0666); err != nil {
Expand Down Expand Up @@ -443,18 +458,19 @@ func checkNumberOfExportedFunctionsWindows(t *testing.T, prog string, exportedFu
t.Fatalf("binary.Read failed: %v", err)
}

// Only the two exported functions and _cgo_dummy_export should be exported.
exportedSymbols = cmp.Or(exportedSymbols, 1) // _cgo_stub_export is exported if there are no other symbols exported

// NumberOfNames is the number of functions exported with a unique name.
// NumberOfFunctions can be higher than that because it also counts
// functions exported only by ordinal, a unique number asigned by the linker,
// and linkers might add an unknown number of their own ordinal-only functions.
if wantAll {
if e.NumberOfNames <= uint32(exportedFunctions) {
t.Errorf("got %d exported names, want > %d", e.NumberOfNames, exportedFunctions)
if e.NumberOfNames <= uint32(exportedSymbols) {
t.Errorf("got %d exported names, want > %d", e.NumberOfNames, exportedSymbols)
}
} else {
if e.NumberOfNames > uint32(exportedFunctions) {
t.Errorf("got %d exported names, want <= %d", e.NumberOfNames, exportedFunctions)
if e.NumberOfNames != uint32(exportedSymbols) {
t.Errorf("got %d exported names, want %d", e.NumberOfNames, exportedSymbols)
}
}
}
Expand All @@ -470,43 +486,14 @@ func TestNumberOfExportedFunctions(t *testing.T) {

t.Parallel()

const prog0 = `
package main

import "C"

func main() {
}
`

const prog2 = `
package main

import "C"

//export GoFunc
func GoFunc() {
println(42)
}

//export GoFunc2
func GoFunc2() {
println(24)
}

func main() {
}
`
// All programs export _cgo_dummy_export, so add 1 to the expected counts.
t.Run("OnlyExported/0", func(t *testing.T) {
checkNumberOfExportedFunctionsWindows(t, prog0, 0+1, false)
})
t.Run("OnlyExported/2", func(t *testing.T) {
checkNumberOfExportedFunctionsWindows(t, prog2, 2+1, false)
})
t.Run("All", func(t *testing.T) {
checkNumberOfExportedFunctionsWindows(t, prog2, 2+1, true)
})
for i := range 3 {
t.Run(fmt.Sprintf("OnlyExported/%d", i), func(t *testing.T) {
checkNumberOfExportedSymbolsWindows(t, i, false)
})
t.Run(fmt.Sprintf("All/%d", i), func(t *testing.T) {
checkNumberOfExportedSymbolsWindows(t, i, true)
})
}
}

// test1: shared library can be dynamically loaded and exported symbols are accessible.
Expand Down
Loading