aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/objfile
diff options
context:
space:
mode:
authorAlex Brainman <alex.brainman@gmail.com>2020-06-28 16:28:52 +1000
committerAlex Brainman <alex.brainman@gmail.com>2020-08-22 00:56:53 +0000
commitea51acbabc687a2270438b05bf765ada2968b69a (patch)
tree3f3525ab5a650901fb5346699d7a17d6c5e6b958 /src/cmd/internal/objfile
parente5da468c51ad13a08730dc7890311915eefd2199 (diff)
downloadgo-ea51acbabc687a2270438b05bf765ada2968b69a.tar.xz
cmd/internal/objfile: use pe.FileHeader.Machine to reliably determine GOARCH
Current peFile.goarch looks for symbols like "_rt0_386_windows" to determine GOARCH. But "_rt0_386_windows" is not present in executables built with cgo. Use pe.FileHeader.Machine instead. This should work with any Windows executable, not just with Go built executable. Fixes #39682 Change-Id: Ie0ffce664f4b8b8fed69b2ecc482425b042a38d5 Reviewed-on: https://go-review.googlesource.com/c/go/+/240957 Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Diffstat (limited to 'src/cmd/internal/objfile')
-rw-r--r--src/cmd/internal/objfile/pe.go14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/cmd/internal/objfile/pe.go b/src/cmd/internal/objfile/pe.go
index 259b59a4f4..b20cda9a44 100644
--- a/src/cmd/internal/objfile/pe.go
+++ b/src/cmd/internal/objfile/pe.go
@@ -182,18 +182,16 @@ func loadPETable(f *pe.File, sname, ename string) ([]byte, error) {
}
func (f *peFile) goarch() string {
- // Not sure how to get the info we want from PE header.
- // Look in symbol table for telltale rt0 symbol.
- if _, err := findPESymbol(f.pe, "_rt0_386_windows"); err == nil {
+ switch f.pe.Machine {
+ case pe.IMAGE_FILE_MACHINE_I386:
return "386"
- }
- if _, err := findPESymbol(f.pe, "_rt0_amd64_windows"); err == nil {
+ case pe.IMAGE_FILE_MACHINE_AMD64:
return "amd64"
- }
- if _, err := findPESymbol(f.pe, "_rt0_arm_windows"); err == nil {
+ case pe.IMAGE_FILE_MACHINE_ARMNT:
return "arm"
+ default:
+ return ""
}
- return ""
}
func (f *peFile) loadAddress() (uint64, error) {