Skip to content

Commit d24a36c

Browse files
committed
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 <[email protected]> Reviewed-by: David Crawshaw <[email protected]>
1 parent 8ec1889 commit d24a36c

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/debug/elf/file.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ import (
1717
"strings"
1818
)
1919

20+
// seekStart, seekCurrent, seekEnd are copies of
21+
// io.SeekStart, io.SeekCurrent, and io.SeekEnd.
22+
// We can't use the ones from package io because
23+
// we want this code to build with Go 1.4 during
24+
// cmd/dist bootstrap.
25+
const (
26+
seekStart int = 0
27+
seekCurrent int = 1
28+
seekEnd int = 2
29+
)
30+
2031
// TODO: error reporting detail
2132

2233
/*
@@ -269,7 +280,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
269280
switch f.Class {
270281
case ELFCLASS32:
271282
hdr := new(Header32)
272-
sr.Seek(0, io.SeekStart)
283+
sr.Seek(0, seekStart)
273284
if err := binary.Read(sr, f.ByteOrder, hdr); err != nil {
274285
return nil, err
275286
}
@@ -288,7 +299,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
288299
shstrndx = int(hdr.Shstrndx)
289300
case ELFCLASS64:
290301
hdr := new(Header64)
291-
sr.Seek(0, io.SeekStart)
302+
sr.Seek(0, seekStart)
292303
if err := binary.Read(sr, f.ByteOrder, hdr); err != nil {
293304
return nil, err
294305
}
@@ -315,7 +326,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
315326
f.Progs = make([]*Prog, phnum)
316327
for i := 0; i < phnum; i++ {
317328
off := phoff + int64(i)*int64(phentsize)
318-
sr.Seek(off, io.SeekStart)
329+
sr.Seek(off, seekStart)
319330
p := new(Prog)
320331
switch f.Class {
321332
case ELFCLASS32:
@@ -359,7 +370,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
359370
names := make([]uint32, shnum)
360371
for i := 0; i < shnum; i++ {
361372
off := shoff + int64(i)*int64(shentsize)
362-
sr.Seek(off, io.SeekStart)
373+
sr.Seek(off, seekStart)
363374
s := new(Section)
364375
switch f.Class {
365376
case ELFCLASS32:

src/debug/elf/reader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ func (r *readSeekerFromReader) Read(p []byte) (n int, err error) {
6363
func (r *readSeekerFromReader) Seek(offset int64, whence int) (int64, error) {
6464
var newOffset int64
6565
switch whence {
66-
case io.SeekStart:
66+
case seekStart:
6767
newOffset = offset
68-
case io.SeekCurrent:
68+
case seekCurrent:
6969
newOffset = r.offset + offset
70-
case io.SeekEnd:
70+
case seekEnd:
7171
newOffset = r.size + offset
7272
default:
7373
return 0, os.ErrInvalid

0 commit comments

Comments
 (0)