@@ -11,6 +11,7 @@ import (
11
11
"cmd/oldlink/internal/sym"
12
12
"debug/elf"
13
13
"fmt"
14
+ "log"
14
15
)
15
16
16
17
// Decoding the type.* symbols. This has to be in sync with
@@ -93,7 +94,7 @@ func decodetypeHasUncommon(arch *sys.Arch, p []byte) bool {
93
94
func findShlibSection (ctxt * Link , path string , addr uint64 ) * elf.Section {
94
95
for _ , shlib := range ctxt .Shlibs {
95
96
if shlib .Path == path {
96
- for _ , sect := range shlib .File .Sections {
97
+ for _ , sect := range shlib .File .Sections [ 1 :] { // skip the NULL section
97
98
if sect .Addr <= addr && addr <= sect .Addr + sect .Size {
98
99
return sect
99
100
}
@@ -112,9 +113,15 @@ func decodetypeGcprog(ctxt *Link, s *sym.Symbol) []byte {
112
113
// A gcprog is a 4-byte uint32 indicating length, followed by
113
114
// the actual program.
114
115
progsize := make ([]byte , 4 )
115
- sect .ReadAt (progsize , int64 (addr - sect .Addr ))
116
+ _ , err := sect .ReadAt (progsize , int64 (addr - sect .Addr ))
117
+ if err != nil {
118
+ log .Fatal (err )
119
+ }
116
120
progbytes := make ([]byte , ctxt .Arch .ByteOrder .Uint32 (progsize ))
117
- sect .ReadAt (progbytes , int64 (addr - sect .Addr + 4 ))
121
+ _ , err = sect .ReadAt (progbytes , int64 (addr - sect .Addr + 4 ))
122
+ if err != nil {
123
+ log .Fatal (err )
124
+ }
118
125
return append (progsize , progbytes ... )
119
126
}
120
127
Exitf ("cannot find gcprog for %s" , s .Name )
@@ -124,14 +131,6 @@ func decodetypeGcprog(ctxt *Link, s *sym.Symbol) []byte {
124
131
}
125
132
126
133
func decodetypeGcprogShlib (ctxt * Link , s * sym.Symbol ) uint64 {
127
- if ctxt .Arch .Family == sys .ARM64 {
128
- for _ , shlib := range ctxt .Shlibs {
129
- if shlib .Path == s .File {
130
- return shlib .gcdataAddresses [s ]
131
- }
132
- }
133
- return 0
134
- }
135
134
return decodeInuxi (ctxt .Arch , s .P [2 * int32 (ctxt .Arch .PtrSize )+ 8 + 1 * int32 (ctxt .Arch .PtrSize ):], ctxt .Arch .PtrSize )
136
135
}
137
136
@@ -141,8 +140,15 @@ func decodetypeGcmask(ctxt *Link, s *sym.Symbol) []byte {
141
140
ptrdata := decodetypePtrdata (ctxt .Arch , s .P )
142
141
sect := findShlibSection (ctxt , s .File , addr )
143
142
if sect != nil {
144
- r := make ([]byte , ptrdata / int64 (ctxt .Arch .PtrSize ))
145
- sect .ReadAt (r , int64 (addr - sect .Addr ))
143
+ bits := ptrdata / int64 (ctxt .Arch .PtrSize )
144
+ r := make ([]byte , (bits + 7 )/ 8 )
145
+ // ldshlibsyms avoids closing the ELF file so sect.ReadAt works.
146
+ // If we remove this read (and the ones in decodetypeGcprog), we
147
+ // can close the file.
148
+ _ , err := sect .ReadAt (r , int64 (addr - sect .Addr ))
149
+ if err != nil {
150
+ log .Fatal (err )
151
+ }
146
152
return r
147
153
}
148
154
Exitf ("cannot find gcmask for %s" , s .Name )
0 commit comments