summaryrefslogtreecommitdiff
path: root/libgo/go/debug/pe
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/debug/pe')
-rw-r--r--libgo/go/debug/pe/file.go2
-rw-r--r--libgo/go/debug/pe/file_test.go87
-rw-r--r--libgo/go/debug/pe/pe.go1
3 files changed, 79 insertions, 11 deletions
diff --git a/libgo/go/debug/pe/file.go b/libgo/go/debug/pe/file.go
index 2f5efae4e67..1c308b3dc3b 100644
--- a/libgo/go/debug/pe/file.go
+++ b/libgo/go/debug/pe/file.go
@@ -91,7 +91,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
return nil, err
}
switch f.FileHeader.Machine {
- case IMAGE_FILE_MACHINE_UNKNOWN, IMAGE_FILE_MACHINE_AMD64, IMAGE_FILE_MACHINE_I386:
+ case IMAGE_FILE_MACHINE_UNKNOWN, IMAGE_FILE_MACHINE_ARMNT, IMAGE_FILE_MACHINE_AMD64, IMAGE_FILE_MACHINE_I386:
default:
return nil, fmt.Errorf("Unrecognised COFF file header machine value of 0x%x.", f.FileHeader.Machine)
}
diff --git a/libgo/go/debug/pe/file_test.go b/libgo/go/debug/pe/file_test.go
index 24cd673254e..9613af3a3c3 100644
--- a/libgo/go/debug/pe/file_test.go
+++ b/libgo/go/debug/pe/file_test.go
@@ -298,6 +298,17 @@ const (
linkCgoExternal
)
+func getImageBase(f *File) uintptr {
+ switch oh := f.OptionalHeader.(type) {
+ case *OptionalHeader32:
+ return uintptr(oh.ImageBase)
+ case *OptionalHeader64:
+ return uintptr(oh.ImageBase)
+ default:
+ panic("unexpected optionalheader type")
+ }
+}
+
func testDWARF(t *testing.T, linktype int) {
if runtime.GOOS != "windows" {
t.Skip("skipping windows only test")
@@ -347,14 +358,15 @@ func testDWARF(t *testing.T, linktype int) {
if err != nil {
t.Fatalf("running test executable failed: %s %s", err, out)
}
+ t.Logf("Testprog output:\n%s", string(out))
- matches := regexp.MustCompile("main=(.*)\n").FindStringSubmatch(string(out))
+ matches := regexp.MustCompile("offset=(.*)\n").FindStringSubmatch(string(out))
if len(matches) < 2 {
t.Fatalf("unexpected program output: %s", out)
}
- wantaddr, err := strconv.ParseUint(matches[1], 0, 64)
+ wantoffset, err := strconv.ParseUint(matches[1], 0, 64)
if err != nil {
- t.Fatalf("unexpected main address %q: %s", matches[1], err)
+ t.Fatalf("unexpected main offset %q: %s", matches[1], err)
}
f, err := Open(exe)
@@ -363,6 +375,8 @@ func testDWARF(t *testing.T, linktype int) {
}
defer f.Close()
+ imageBase := getImageBase(f)
+
var foundDebugGDBScriptsSection bool
for _, sect := range f.Sections {
if sect.Name == ".debug_gdb_scripts" {
@@ -389,10 +403,20 @@ func testDWARF(t *testing.T, linktype int) {
break
}
if e.Tag == dwarf.TagSubprogram {
- if name, ok := e.Val(dwarf.AttrName).(string); ok && name == "main.main" {
- if addr, ok := e.Val(dwarf.AttrLowpc).(uint64); ok && addr == wantaddr {
- return
+ name, ok := e.Val(dwarf.AttrName).(string)
+ if ok && name == "main.main" {
+ t.Logf("Found main.main")
+ addr, ok := e.Val(dwarf.AttrLowpc).(uint64)
+ if !ok {
+ t.Fatal("Failed to get AttrLowpc")
+ }
+ offset := uintptr(addr) - imageBase
+ if offset != uintptr(wantoffset) {
+ t.Fatal("Runtime offset (0x%x) did "+
+ "not match dwarf offset "+
+ "(0x%x)", wantoffset, offset)
}
+ return
}
}
}
@@ -479,11 +503,52 @@ const testprog = `
package main
import "fmt"
+import "syscall"
+import "unsafe"
{{if .}}import "C"
{{end}}
+// struct MODULEINFO from the Windows SDK
+type moduleinfo struct {
+ BaseOfDll uintptr
+ SizeOfImage uint32
+ EntryPoint uintptr
+}
+
+func add(p unsafe.Pointer, x uintptr) unsafe.Pointer {
+ return unsafe.Pointer(uintptr(p) + x)
+}
+
+func funcPC(f interface{}) uintptr {
+ var a uintptr
+ return **(**uintptr)(add(unsafe.Pointer(&f), unsafe.Sizeof(a)))
+}
+
func main() {
+ kernel32 := syscall.MustLoadDLL("kernel32.dll")
+ psapi := syscall.MustLoadDLL("psapi.dll")
+ getModuleHandle := kernel32.MustFindProc("GetModuleHandleW")
+ getCurrentProcess := kernel32.MustFindProc("GetCurrentProcess")
+ getModuleInformation := psapi.MustFindProc("GetModuleInformation")
+
+ procHandle, _, _ := getCurrentProcess.Call()
+ moduleHandle, _, err := getModuleHandle.Call(0)
+ if moduleHandle == 0 {
+ panic(fmt.Sprintf("GetModuleHandle() failed: %d", err))
+ }
+
+ var info moduleinfo
+ ret, _, err := getModuleInformation.Call(procHandle, moduleHandle,
+ uintptr(unsafe.Pointer(&info)), unsafe.Sizeof(info))
+
+ if ret == 0 {
+ panic(fmt.Sprintf("GetModuleInformation() failed: %d", err))
+ }
+
+ offset := funcPC(main) - info.BaseOfDll
+ fmt.Printf("base=0x%x\n", info.BaseOfDll)
fmt.Printf("main=%p\n", main)
+ fmt.Printf("offset=0x%x\n", offset)
}
`
@@ -535,13 +600,15 @@ func TestBuildingWindowsGUI(t *testing.T) {
func TestImportTableInUnknownSection(t *testing.T) {
if runtime.GOOS != "windows" {
- t.Skip("skipping windows only test")
+ t.Skip("skipping Windows-only test")
}
- // first we need to find this font driver
- path, err := exec.LookPath("atmfd.dll")
+ // ws2_32.dll import table is located in ".rdata" section,
+ // so it is good enough to test issue #16103.
+ const filename = "ws2_32.dll"
+ path, err := exec.LookPath(filename)
if err != nil {
- t.Fatalf("unable to locate required file %q in search path: %s", "atmfd.dll", err)
+ t.Fatalf("unable to locate required file %q in search path: %s", filename, err)
}
f, err := Open(path)
diff --git a/libgo/go/debug/pe/pe.go b/libgo/go/debug/pe/pe.go
index e933ae1c2aa..3f8099dfab1 100644
--- a/libgo/go/debug/pe/pe.go
+++ b/libgo/go/debug/pe/pe.go
@@ -91,6 +91,7 @@ const (
IMAGE_FILE_MACHINE_AM33 = 0x1d3
IMAGE_FILE_MACHINE_AMD64 = 0x8664
IMAGE_FILE_MACHINE_ARM = 0x1c0
+ IMAGE_FILE_MACHINE_ARMNT = 0x1c4
IMAGE_FILE_MACHINE_ARM64 = 0xaa64
IMAGE_FILE_MACHINE_EBC = 0xebc
IMAGE_FILE_MACHINE_I386 = 0x14c