1
0
mirror of https://github.com/golang/go synced 2024-11-18 20:04:52 -07:00

[dev.link] cmd/link: panic if HeadType is not set

In the code there are conditions like !ctxt.IsDarwin(). This will
accidentally be true if HeadType is not yet set. Panic when
HeadType is not set, to catch errors.

Change-Id: Ic891123f27f0276fff5a4b5d29e5b1f7ebbb94ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/229869
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Cherry Zhang 2020-04-24 13:02:37 -04:00
parent f2d8da1a35
commit 880ef2da7b

View File

@ -61,6 +61,7 @@ func (t *Target) CanUsePlugins() bool {
} }
func (t *Target) IsElf() bool { func (t *Target) IsElf() bool {
t.mustSetHeadType()
return t.IsELF return t.IsELF
} }
@ -112,37 +113,51 @@ func (t *Target) IsWasm() bool {
// //
func (t *Target) IsLinux() bool { func (t *Target) IsLinux() bool {
t.mustSetHeadType()
return t.HeadType == objabi.Hlinux return t.HeadType == objabi.Hlinux
} }
func (t *Target) IsDarwin() bool { func (t *Target) IsDarwin() bool {
t.mustSetHeadType()
return t.HeadType == objabi.Hdarwin return t.HeadType == objabi.Hdarwin
} }
func (t *Target) IsWindows() bool { func (t *Target) IsWindows() bool {
t.mustSetHeadType()
return t.HeadType == objabi.Hwindows return t.HeadType == objabi.Hwindows
} }
func (t *Target) IsPlan9() bool { func (t *Target) IsPlan9() bool {
t.mustSetHeadType()
return t.HeadType == objabi.Hplan9 return t.HeadType == objabi.Hplan9
} }
func (t *Target) IsAIX() bool { func (t *Target) IsAIX() bool {
t.mustSetHeadType()
return t.HeadType == objabi.Haix return t.HeadType == objabi.Haix
} }
func (t *Target) IsSolaris() bool { func (t *Target) IsSolaris() bool {
t.mustSetHeadType()
return t.HeadType == objabi.Hsolaris return t.HeadType == objabi.Hsolaris
} }
func (t *Target) IsNetbsd() bool { func (t *Target) IsNetbsd() bool {
t.mustSetHeadType()
return t.HeadType == objabi.Hnetbsd return t.HeadType == objabi.Hnetbsd
} }
func (t *Target) IsOpenbsd() bool { func (t *Target) IsOpenbsd() bool {
t.mustSetHeadType()
return t.HeadType == objabi.Hopenbsd return t.HeadType == objabi.Hopenbsd
} }
func (t *Target) mustSetHeadType() {
if t.HeadType == objabi.Hunknown {
panic("HeadType is not set")
}
}
// //
// MISC // MISC
// //