Commit 0a2083ed authored by Aram Hăvărneanu's avatar Aram Hăvărneanu

debug/plan9obj, cmd/addr2line: on Plan 9 use a.out header

size instead of abusing text symbol

cmd/addr2line needs to know the virtual address of the start
of the text segment (load address plus header size). For
this, it used the text symbol added by the linker. This is
wrong on amd64. Header size is 40 bytes, not 32 like on 386
and arm. Function alignment is 16 bytes causing text to be
at 0x200030.

debug/plan9obj now exports both the load address and the
header size; cmd/addr2line uses this new information and
doesn't rely on text anymore.

LGTM=0intro
R=0intro, gobot, ality
CC=ality, golang-codereviews, jas, mischief
https://golang.org/cl/106460044
parent fa113cf7
...@@ -237,10 +237,6 @@ func loadPlan9Table(f *plan9obj.File, sname, ename string) ([]byte, error) { ...@@ -237,10 +237,6 @@ func loadPlan9Table(f *plan9obj.File, sname, ename string) ([]byte, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
text, err := findPlan9Symbol(f, "text")
if err != nil {
return nil, err
}
sect := f.Section("text") sect := f.Section("text")
if sect == nil { if sect == nil {
return nil, err return nil, err
...@@ -249,5 +245,5 @@ func loadPlan9Table(f *plan9obj.File, sname, ename string) ([]byte, error) { ...@@ -249,5 +245,5 @@ func loadPlan9Table(f *plan9obj.File, sname, ename string) ([]byte, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return data[ssym.Value-text.Value : esym.Value-text.Value], nil return data[ssym.Value-(f.LoadAddress+f.HdrSize) : esym.Value-(f.LoadAddress+f.HdrSize)], nil
} }
...@@ -15,10 +15,12 @@ import ( ...@@ -15,10 +15,12 @@ import (
// A FileHeader represents a Plan 9 a.out file header. // A FileHeader represents a Plan 9 a.out file header.
type FileHeader struct { type FileHeader struct {
Magic uint32 Magic uint32
Bss uint32 Bss uint32
Entry uint64 Entry uint64
PtrSize int PtrSize int
LoadAddress uint64
HdrSize uint64
} }
// A File represents an open Plan 9 a.out file. // A File represents an open Plan 9 a.out file.
...@@ -148,20 +150,21 @@ func NewFile(r io.ReaderAt) (*File, error) { ...@@ -148,20 +150,21 @@ func NewFile(r io.ReaderAt) (*File, error) {
} }
f := &File{FileHeader: FileHeader{ f := &File{FileHeader: FileHeader{
Magic: ph.Magic, Magic: ph.Magic,
Bss: ph.Bss, Bss: ph.Bss,
Entry: uint64(ph.Entry), Entry: uint64(ph.Entry),
PtrSize: 4, PtrSize: 4,
LoadAddress: 0x1000,
HdrSize: 4 * 8,
}} }}
hdrSize := 4 * 8
if ph.Magic&Magic64 != 0 { if ph.Magic&Magic64 != 0 {
if err := binary.Read(sr, binary.BigEndian, &f.Entry); err != nil { if err := binary.Read(sr, binary.BigEndian, &f.Entry); err != nil {
return nil, err return nil, err
} }
f.PtrSize = 8 f.PtrSize = 8
hdrSize += 8 f.LoadAddress = 0x200000
f.HdrSize += 8
} }
var sects = []struct { var sects = []struct {
...@@ -177,7 +180,7 @@ func NewFile(r io.ReaderAt) (*File, error) { ...@@ -177,7 +180,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
f.Sections = make([]*Section, 5) f.Sections = make([]*Section, 5)
off := uint32(hdrSize) off := uint32(f.HdrSize)
for i, sect := range sects { for i, sect := range sects {
s := new(Section) s := new(Section)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment