mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/addr2line, cmd/objdump: fix pe text section starting address
fixes windows build LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/97500043
This commit is contained in:
parent
8e22903b46
commit
6c7bef551b
2 changed files with 20 additions and 2 deletions
|
|
@ -138,8 +138,17 @@ func loadTables(f *os.File) (textStart uint64, symtab, pclntab []byte, err error
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj, err := pe.NewFile(f); err == nil {
|
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 {
|
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 {
|
if pclntab, err = loadPETable(obj, "pclntab", "epclntab"); err != nil {
|
||||||
return 0, nil, nil, err
|
return 0, nil, nil, err
|
||||||
|
|
|
||||||
|
|
@ -318,8 +318,17 @@ func loadTables(f *os.File) (textStart uint64, textData, symtab, pclntab []byte,
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj, err := pe.NewFile(f); err == nil {
|
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 {
|
if sect := obj.Section(".text"); sect != nil {
|
||||||
textStart = uint64(sect.VirtualAddress)
|
textStart = imageBase + uint64(sect.VirtualAddress)
|
||||||
textData, _ = sect.Data()
|
textData, _ = sect.Data()
|
||||||
}
|
}
|
||||||
if pclntab, err = loadPETable(obj, "pclntab", "epclntab"); err != nil {
|
if pclntab, err = loadPETable(obj, "pclntab", "epclntab"); err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue