]> Cypherpunks repositories - gostls13.git/commitdiff
internal/xcoff: change zeroReaderAt to nobitsSectionReader for .bss with all 0s
authorJes Cok <xigua67damn@gmail.com>
Sat, 10 Feb 2024 01:25:05 +0000 (01:25 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 12 Feb 2024 14:42:29 +0000 (14:42 +0000)
Fixes #63337

Change-Id: I239315047e6e4325e2f471108fd764f8dbb7d5b2
GitHub-Last-Rev: cacdf0a279451ab97e6e6ce3fe0d3a025f5ce3aa
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>
src/internal/xcoff/file.go

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