diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go index 046f508545..e8257131a9 100644 --- a/src/cmd/go/internal/load/pkg.go +++ b/src/cmd/go/internal/load/pkg.go @@ -2346,6 +2346,15 @@ func (p *Package) setBuildInfo(includeVCS bool) { if BuildAsmflags.present { appendSetting("-asmflags", BuildAsmflags.String()) } + buildmode := cfg.BuildBuildmode + if buildmode == "default" { + if p.Name == "main" { + buildmode = "exe" + } else { + buildmode = "archive" + } + } + appendSetting("-buildmode", buildmode) appendSetting("-compiler", cfg.BuildContext.Compiler) if gccgoflags := BuildGccgoflags.String(); gccgoflags != "" && cfg.BuildContext.Compiler == "gccgo" { appendSetting("-gccgoflags", gccgoflags) diff --git a/src/cmd/go/testdata/script/mod_list_command_line_arguments.txt b/src/cmd/go/testdata/script/mod_list_command_line_arguments.txt index fd99ae84b2..25c68c5a82 100644 --- a/src/cmd/go/testdata/script/mod_list_command_line_arguments.txt +++ b/src/cmd/go/testdata/script/mod_list_command_line_arguments.txt @@ -14,7 +14,7 @@ go build -o a.exe a.go go version -m a.exe stdout '^\tpath\tcommand-line-arguments$' stdout '^\tdep\ta\t\(devel\)\t$' -! stdout mod +! stdout mod[^e] -- a/go.mod -- module a diff --git a/src/cmd/go/testdata/script/version.txt b/src/cmd/go/testdata/script/version.txt index f7ead395c0..a928067a7e 100644 --- a/src/cmd/go/testdata/script/version.txt +++ b/src/cmd/go/testdata/script/version.txt @@ -32,15 +32,17 @@ go build -o fortune.exe rsc.io/fortune go version fortune.exe stdout '^fortune.exe: .+' go version -m fortune.exe +stdout -buildmode=exe stdout '^\tpath\trsc.io/fortune' stdout '^\tmod\trsc.io/fortune\tv1.0.0' # Check the build info of a binary built from $GOROOT/src/cmd go build -o test2json.exe cmd/test2json go version -m test2json.exe +stdout -buildmode=exe stdout '^test2json.exe: .+' stdout '^\tpath\tcmd/test2json$' -! stdout 'mod' +! stdout 'mod[^e]' # Repeat the test with -buildmode=pie. [!buildmode:pie] stop @@ -48,6 +50,7 @@ go build -buildmode=pie -o external.exe rsc.io/fortune go version external.exe stdout '^external.exe: .+' go version -m external.exe +stdout -buildmode=pie stdout '^\tpath\trsc.io/fortune' stdout '^\tmod\trsc.io/fortune\tv1.0.0' @@ -59,6 +62,7 @@ go build -buildmode=pie -ldflags=-linkmode=internal -o internal.exe rsc.io/fortu go version internal.exe stdout '^internal.exe: .+' go version -m internal.exe +stdout -buildmode=pie stdout '^\tpath\trsc.io/fortune' stdout '^\tmod\trsc.io/fortune\tv1.0.0' @@ -67,4 +71,4 @@ module m -- empty.go -- package main -func main(){} +func main(){} \ No newline at end of file