Skip to content

Commit 0067d81

Browse files
ianlancetaylorgopherbot
authored andcommitted
cmd/link: rewrite (*BuildMode).Set to use platform.BuildModeSupported
Change-Id: I7aa2bb4560198a7d9d9e4321f60dec38f6834bdc Reviewed-on: https://go-review.googlesource.com/c/go/+/463745 Reviewed-by: Than McIntosh <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 55a33d8 commit 0067d81

File tree

1 file changed

+5
-68
lines changed

1 file changed

+5
-68
lines changed

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

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ const (
3030
// Set implements flag.Value to set the build mode based on the argument
3131
// to the -buildmode flag.
3232
func (mode *BuildMode) Set(s string) error {
33-
badmode := func() error {
34-
return fmt.Errorf("buildmode %s not supported on %s/%s", s, buildcfg.GOOS, buildcfg.GOARCH)
35-
}
3633
switch s {
3734
default:
3835
return fmt.Errorf("invalid buildmode: %q", s)
@@ -44,81 +41,21 @@ func (mode *BuildMode) Set(s string) error {
4441
*mode = BuildModeExe
4542
}
4643
case "pie":
47-
switch buildcfg.GOOS {
48-
case "aix", "android", "linux", "windows", "darwin", "ios":
49-
case "freebsd":
50-
switch buildcfg.GOARCH {
51-
case "amd64":
52-
default:
53-
return badmode()
54-
}
55-
default:
56-
return badmode()
57-
}
5844
*mode = BuildModePIE
5945
case "c-archive":
60-
switch buildcfg.GOOS {
61-
case "aix", "darwin", "ios", "linux":
62-
case "freebsd":
63-
switch buildcfg.GOARCH {
64-
case "amd64":
65-
default:
66-
return badmode()
67-
}
68-
case "windows":
69-
switch buildcfg.GOARCH {
70-
case "amd64", "386", "arm", "arm64":
71-
default:
72-
return badmode()
73-
}
74-
default:
75-
return badmode()
76-
}
7746
*mode = BuildModeCArchive
7847
case "c-shared":
79-
switch buildcfg.GOARCH {
80-
case "386", "amd64", "arm", "arm64", "ppc64le", "riscv64", "s390x":
81-
default:
82-
return badmode()
83-
}
8448
*mode = BuildModeCShared
8549
case "shared":
86-
switch buildcfg.GOOS {
87-
case "linux":
88-
switch buildcfg.GOARCH {
89-
case "386", "amd64", "arm", "arm64", "ppc64le", "s390x":
90-
default:
91-
return badmode()
92-
}
93-
default:
94-
return badmode()
95-
}
9650
*mode = BuildModeShared
9751
case "plugin":
98-
switch buildcfg.GOOS {
99-
case "linux":
100-
switch buildcfg.GOARCH {
101-
case "386", "amd64", "arm", "arm64", "s390x", "ppc64le":
102-
default:
103-
return badmode()
104-
}
105-
case "darwin":
106-
switch buildcfg.GOARCH {
107-
case "amd64", "arm64":
108-
default:
109-
return badmode()
110-
}
111-
case "freebsd":
112-
switch buildcfg.GOARCH {
113-
case "amd64":
114-
default:
115-
return badmode()
116-
}
117-
default:
118-
return badmode()
119-
}
12052
*mode = BuildModePlugin
12153
}
54+
55+
if !platform.BuildModeSupported("gc", s, buildcfg.GOOS, buildcfg.GOARCH) {
56+
return fmt.Errorf("buildmode %s not supported on %s/%s", s, buildcfg.GOOS, buildcfg.GOARCH)
57+
}
58+
12259
return nil
12360
}
12461

0 commit comments

Comments
 (0)