Commit d24a36cc authored by Russ Cox's avatar Russ Cox

debug/elf: make safe for Go 1.4 compilers

We're going to start building cmd/cgo as part of the bootstrap,
and with it debug/elf, so the copy here needs to work with Go 1.4.
It does except for the use of the new io.SeekStart etc constants,
so remove that use.

Change-Id: Ib7fcf46e1e9060f96d2bacaaf349c9b0df347550
Reviewed-on: https://go-review.googlesource.com/68337
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: 's avatarDavid Crawshaw <crawshaw@golang.org>
parent 8ec18897
......@@ -17,6 +17,17 @@ import (
"strings"
)
// seekStart, seekCurrent, seekEnd are copies of
// io.SeekStart, io.SeekCurrent, and io.SeekEnd.
// We can't use the ones from package io because
// we want this code to build with Go 1.4 during
// cmd/dist bootstrap.
const (
seekStart int = 0
seekCurrent int = 1
seekEnd int = 2
)
// TODO: error reporting detail
/*
......@@ -269,7 +280,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
switch f.Class {
case ELFCLASS32:
hdr := new(Header32)
sr.Seek(0, io.SeekStart)
sr.Seek(0, seekStart)
if err := binary.Read(sr, f.ByteOrder, hdr); err != nil {
return nil, err
}
......@@ -288,7 +299,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
shstrndx = int(hdr.Shstrndx)
case ELFCLASS64:
hdr := new(Header64)
sr.Seek(0, io.SeekStart)
sr.Seek(0, seekStart)
if err := binary.Read(sr, f.ByteOrder, hdr); err != nil {
return nil, err
}
......@@ -315,7 +326,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
f.Progs = make([]*Prog, phnum)
for i := 0; i < phnum; i++ {
off := phoff + int64(i)*int64(phentsize)
sr.Seek(off, io.SeekStart)
sr.Seek(off, seekStart)
p := new(Prog)
switch f.Class {
case ELFCLASS32:
......@@ -359,7 +370,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
names := make([]uint32, shnum)
for i := 0; i < shnum; i++ {
off := shoff + int64(i)*int64(shentsize)
sr.Seek(off, io.SeekStart)
sr.Seek(off, seekStart)
s := new(Section)
switch f.Class {
case ELFCLASS32:
......
......@@ -63,11 +63,11 @@ func (r *readSeekerFromReader) Read(p []byte) (n int, err error) {
func (r *readSeekerFromReader) Seek(offset int64, whence int) (int64, error) {
var newOffset int64
switch whence {
case io.SeekStart:
case seekStart:
newOffset = offset
case io.SeekCurrent:
case seekCurrent:
newOffset = r.offset + offset
case io.SeekEnd:
case seekEnd:
newOffset = r.size + offset
default:
return 0, os.ErrInvalid
......
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