1
0
mirror of https://github.com/golang/go synced 2024-11-23 07:10:05 -07:00

internal/xcoff: change zeroReaderAt to nobitsSectionReader for .bss with all 0s

Fixes #63337

Change-Id: I239315047e6e4325e2f471108fd764f8dbb7d5b2
GitHub-Last-Rev: cacdf0a279
GitHub-Pull-Request: golang/go#64952
Reviewed-on: https://go-review.googlesource.com/c/go/+/553616
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Jes Cok 2024-02-10 01:25:05 +00:00 committed by Gopher Robot
parent 2413629aa8
commit 9cc0f9cba2

View File

@ -8,6 +8,7 @@ package xcoff
import ( import (
"debug/dwarf" "debug/dwarf"
"encoding/binary" "encoding/binary"
"errors"
"fmt" "fmt"
"internal/saferio" "internal/saferio"
"io" "io"
@ -261,7 +262,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
} }
r2 := r r2 := r
if scnptr == 0 { // .bss must have all 0s if scnptr == 0 { // .bss must have all 0s
r2 = zeroReaderAt{} r2 = &nobitsSectionReader{}
} }
s.sr = io.NewSectionReader(r2, int64(scnptr), int64(s.Size)) s.sr = io.NewSectionReader(r2, int64(scnptr), int64(s.Size))
s.ReaderAt = s.sr s.ReaderAt = s.sr
@ -451,15 +452,10 @@ func NewFile(r io.ReaderAt) (*File, error) {
return f, nil return f, nil
} }
// zeroReaderAt is ReaderAt that reads 0s. type nobitsSectionReader struct{}
type zeroReaderAt struct{}
// ReadAt writes len(p) 0s into p. func (*nobitsSectionReader) ReadAt(p []byte, off int64) (n int, err error) {
func (w zeroReaderAt) ReadAt(p []byte, off int64) (n int, err error) { return 0, errors.New("unexpected read from section with uninitialized data")
for i := range p {
p[i] = 0
}
return len(p), nil
} }
// Data reads and returns the contents of the XCOFF section s. // Data reads and returns the contents of the XCOFF section s.