]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/addr2line, cmd/objdump: fix pe text section starting address
authorAlex Brainman <alex.brainman@gmail.com>
Thu, 15 May 2014 02:44:29 +0000 (12:44 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Thu, 15 May 2014 02:44:29 +0000 (12:44 +1000)
fixes windows build

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/97500043

src/cmd/addr2line/main.go
src/cmd/objdump/main.go

index d6d14a7330b49397002e15432a98d3686b650eb0..f4a7789f9b485ad5b8712307640391eab2738f11 100644 (file)
@@ -138,8 +138,17 @@ func loadTables(f *os.File) (textStart uint64, symtab, pclntab []byte, err error
        }
 
        if obj, err := pe.NewFile(f); err == nil {
+               var imageBase uint64
+               switch oh := obj.OptionalHeader.(type) {
+               case *pe.OptionalHeader32:
+                       imageBase = uint64(oh.ImageBase)
+               case *pe.OptionalHeader64:
+                       imageBase = oh.ImageBase
+               default:
+                       return 0, nil, nil, fmt.Errorf("pe file format not recognized")
+               }
                if sect := obj.Section(".text"); sect != nil {
-                       textStart = uint64(sect.VirtualAddress)
+                       textStart = imageBase + uint64(sect.VirtualAddress)
                }
                if pclntab, err = loadPETable(obj, "pclntab", "epclntab"); err != nil {
                        return 0, nil, nil, err
index 1b6b3d0fc4406e0289f916f52c540b035b887dcf..fb79ba3a2a226c4e1c81a086d1b404512c862e42 100644 (file)
@@ -318,8 +318,17 @@ func loadTables(f *os.File) (textStart uint64, textData, symtab, pclntab []byte,
        }
 
        if obj, err := pe.NewFile(f); err == nil {
+               var imageBase uint64
+               switch oh := obj.OptionalHeader.(type) {
+               case *pe.OptionalHeader32:
+                       imageBase = uint64(oh.ImageBase)
+               case *pe.OptionalHeader64:
+                       imageBase = oh.ImageBase
+               default:
+                       return 0, nil, nil, nil, fmt.Errorf("pe file format not recognized")
+               }
                if sect := obj.Section(".text"); sect != nil {
-                       textStart = uint64(sect.VirtualAddress)
+                       textStart = imageBase + uint64(sect.VirtualAddress)
                        textData, _ = sect.Data()
                }
                if pclntab, err = loadPETable(obj, "pclntab", "epclntab"); err != nil {