OLD | NEW |
1 // Copyright 2013 The Go Authors. All rights reserved. | 1 // Copyright 2013 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package goobj implements reading of Go object files and archives. | 5 // Package goobj implements reading of Go object files and archives. |
6 // | 6 // |
7 // TODO(rsc): Decide where this package should live. (golang.org/issue/6932) | 7 // TODO(rsc): Decide where this package should live. (golang.org/issue/6932) |
8 // TODO(rsc): Decide the appropriate integer types for various fields. | 8 // TODO(rsc): Decide the appropriate integer types for various fields. |
9 // TODO(rsc): Write tests. (File format still up in the air a little.) | 9 // TODO(rsc): Write tests. (File format still up in the air a little.) |
10 package goobj | 10 package goobj |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 128 } |
129 | 129 |
130 // A SymID - the combination of Name and Version - uniquely identifies | 130 // A SymID - the combination of Name and Version - uniquely identifies |
131 // a symbol within a package. | 131 // a symbol within a package. |
132 type SymID struct { | 132 type SymID struct { |
133 // Name is the name of a symbol. | 133 // Name is the name of a symbol. |
134 Name string | 134 Name string |
135 | 135 |
136 // Version is zero for symbols with global visibility. | 136 // Version is zero for symbols with global visibility. |
137 // Symbols with only file visibility (such as file-level static | 137 // Symbols with only file visibility (such as file-level static |
138 » // declarations in C) have a non-zero version distinguising | 138 » // declarations in C) have a non-zero version distinguishing |
139 // a symbol in one file from a symbol of the same name | 139 // a symbol in one file from a symbol of the same name |
140 // in another file | 140 // in another file |
141 Version int | 141 Version int |
142 } | 142 } |
143 | 143 |
144 func (s SymID) String() string { | 144 func (s SymID) String() string { |
145 if s.Version == 0 { | 145 if s.Version == 0 { |
146 return s.Name | 146 return s.Name |
147 } | 147 } |
148 return fmt.Sprintf("%s<%d>", s.Name, s.Version) | 148 return fmt.Sprintf("%s<%d>", s.Name, s.Version) |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 // 40:48 mode | 503 // 40:48 mode |
504 // 48:58 size | 504 // 48:58 size |
505 // 58:60 magic - `\n | 505 // 58:60 magic - `\n |
506 // We only care about name, size, and magic. | 506 // We only care about name, size, and magic. |
507 // The fields are space-padded on the right. | 507 // The fields are space-padded on the right. |
508 // The size is in decimal. | 508 // The size is in decimal. |
509 // The file data - size bytes - follows the header. | 509 // The file data - size bytes - follows the header. |
510 // Headers are 2-byte aligned, so if size is odd, an extra paddi
ng | 510 // Headers are 2-byte aligned, so if size is odd, an extra paddi
ng |
511 // byte sits between the file data and the next header. | 511 // byte sits between the file data and the next header. |
512 // The file data that follows is padded to an even number of byt
es: | 512 // The file data that follows is padded to an even number of byt
es: |
513 » » // if size is odd, an extra padding byte is inserted betw the ne
xt header. | 513 » » // if size is odd, an extra padding byte is inserted after the d
ata. |
514 if len(data) < 60 { | 514 if len(data) < 60 { |
515 return errTruncatedArchive | 515 return errTruncatedArchive |
516 } | 516 } |
517 if !bytes.Equal(data[58:60], archiveMagic) { | 517 if !bytes.Equal(data[58:60], archiveMagic) { |
518 return errCorruptArchive | 518 return errCorruptArchive |
519 } | 519 } |
520 name := trimSpace(data[0:16]) | 520 name := trimSpace(data[0:16]) |
521 size, err := strconv.ParseInt(trimSpace(data[48:58]), 10, 64) | 521 size, err := strconv.ParseInt(trimSpace(data[48:58]), 10, 64) |
522 if err != nil { | 522 if err != nil { |
523 return errCorruptArchive | 523 return errCorruptArchive |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 } | 655 } |
656 } | 656 } |
657 | 657 |
658 r.readFull(r.tmp[:7]) | 658 r.readFull(r.tmp[:7]) |
659 if !bytes.Equal(r.tmp[:7], []byte("\xffgo13ld")) { | 659 if !bytes.Equal(r.tmp[:7], []byte("\xffgo13ld")) { |
660 return r.error(errCorruptObject) | 660 return r.error(errCorruptObject) |
661 } | 661 } |
662 | 662 |
663 return nil | 663 return nil |
664 } | 664 } |
OLD | NEW |