Skip to content

Commit

Permalink
debug/pe: recognize arm64 executables
Browse files Browse the repository at this point in the history
We still need to add test data, but as yet we haven't identified
a good Windows arm64 compiler to produce small binaries.

This CL is part of a stack adding windows/arm64
support (#36439), intended to land in the Go 1.17 cycle.

Change-Id: Ifbecb9a6e25f7af38e20b7d7830df7f5efe2798a
Reviewed-on: https://go-review.googlesource.com/c/go/+/288820
Trust: Russ Cox <rsc@golang.org>
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
  • Loading branch information
rsc committed Feb 19, 2021
1 parent 0c63312 commit 0ca0551
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/debug/pe/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
var sign [4]byte
r.ReadAt(sign[:], signoff)
if !(sign[0] == 'P' && sign[1] == 'E' && sign[2] == 0 && sign[3] == 0) {
return nil, fmt.Errorf("Invalid PE COFF file signature of %v.", sign)
return nil, fmt.Errorf("invalid PE file signature: % x", sign)
}
base = signoff + 4
} else {
Expand All @@ -86,9 +86,14 @@ func NewFile(r io.ReaderAt) (*File, error) {
return nil, err
}
switch f.FileHeader.Machine {
case IMAGE_FILE_MACHINE_UNKNOWN, IMAGE_FILE_MACHINE_ARMNT, IMAGE_FILE_MACHINE_AMD64, IMAGE_FILE_MACHINE_I386:
case IMAGE_FILE_MACHINE_AMD64,
IMAGE_FILE_MACHINE_ARM64,
IMAGE_FILE_MACHINE_ARMNT,
IMAGE_FILE_MACHINE_I386,
IMAGE_FILE_MACHINE_UNKNOWN:
// ok
default:
return nil, fmt.Errorf("Unrecognised COFF file header machine value of 0x%x.", f.FileHeader.Machine)
return nil, fmt.Errorf("unrecognized PE machine: %#x", f.FileHeader.Machine)
}

var err error
Expand All @@ -112,7 +117,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
// Seek past file header.
_, err = sr.Seek(base+int64(binary.Size(f.FileHeader)), seekStart)
if err != nil {
return nil, fmt.Errorf("failure to seek past the file header: %v", err)
return nil, err
}

// Read optional header.
Expand Down Expand Up @@ -309,7 +314,7 @@ func (f *File) ImportedSymbols() ([]string, error) {
return nil, nil
}

pe64 := f.Machine == IMAGE_FILE_MACHINE_AMD64
pe64 := f.Machine == IMAGE_FILE_MACHINE_AMD64 || f.Machine == IMAGE_FILE_MACHINE_ARM64

// grab the number of data directory entries
var dd_length uint32
Expand Down

0 comments on commit 0ca0551

Please sign in to comment.