Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
d00442ab
Commit
d00442ab
authored
Jun 02, 2014
by
Andrew Gerrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[release-branch.go1.3] remove package debug/goobj and copy functionality to cmd/nm
https://golang.org/cl/103760043/
parent
f40040b0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
181 additions
and
204 deletions
+181
-204
src/cmd/nm/debug_goobj.go
src/cmd/nm/debug_goobj.go
+171
-165
src/cmd/nm/goobj.go
src/cmd/nm/goobj.go
+10
-11
src/pkg/debug/goobj/read_test.go
src/pkg/debug/goobj/read_test.go
+0
-28
No files found.
src/
pkg/debug/goobj/read
.go
→
src/
cmd/nm/debug_goobj
.go
View file @
d00442ab
// DO NOT EDIT. Generated by code.google.com/p/rsc/cmd/bundle
// bundle -p main -x goobj_ debug/goobj
/* read.go */
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
...
...
@@ -7,7 +12,8 @@
// TODO(rsc): Decide where this package should live. (golang.org/issue/6932)
// TODO(rsc): Decide the appropriate integer types for various fields.
// TODO(rsc): Write tests. (File format still up in the air a little.)
package
goobj
package
main
import
(
"bufio"
...
...
@@ -20,7 +26,7 @@ import (
)
// A SymKind describes the kind of memory represented by a symbol.
type
SymKind
int
type
goobj_
SymKind
int
// This list is taken from include/link.h.
...
...
@@ -28,108 +34,108 @@ type SymKind int
// TODO(rsc): Give idiomatic Go names.
// TODO(rsc): Reduce the number of symbol types in the object files.
const
(
_
SymKind
=
iota
_
goobj_
SymKind
=
iota
// readonly, executable
STEXT
SELFRXSECT
goobj_
STEXT
goobj_
SELFRXSECT
// readonly, non-executable
STYPE
SSTRING
SGOSTRING
SGOFUNC
SRODATA
SFUNCTAB
STYPELINK
SSYMTAB
// TODO: move to unmapped section
SPCLNTAB
SELFROSECT
goobj_
STYPE
goobj_
SSTRING
goobj_
SGOSTRING
goobj_
SGOFUNC
goobj_
SRODATA
goobj_
SFUNCTAB
goobj_
STYPELINK
goobj_
SSYMTAB
// TODO: move to unmapped section
goobj_
SPCLNTAB
goobj_
SELFROSECT
// writable, non-executable
SMACHOPLT
SELFSECT
SMACHO
// Mach-O __nl_symbol_ptr
SMACHOGOT
SNOPTRDATA
SINITARR
SDATA
SWINDOWS
SBSS
SNOPTRBSS
STLSBSS
goobj_
SMACHOPLT
goobj_
SELFSECT
goobj_
SMACHO
// Mach-O __nl_symbol_ptr
goobj_
SMACHOGOT
goobj_
SNOPTRDATA
goobj_
SINITARR
goobj_
SDATA
goobj_
SWINDOWS
goobj_
SBSS
goobj_
SNOPTRBSS
goobj_
STLSBSS
// not mapped
SXREF
SMACHOSYMSTR
SMACHOSYMTAB
SMACHOINDIRECTPLT
SMACHOINDIRECTGOT
SFILE
SFILEPATH
SCONST
SDYNIMPORT
SHOSTOBJ
goobj_
SXREF
goobj_
SMACHOSYMSTR
goobj_
SMACHOSYMTAB
goobj_
SMACHOINDIRECTPLT
goobj_
SMACHOINDIRECTGOT
goobj_
SFILE
goobj_
SFILEPATH
goobj_
SCONST
goobj_
SDYNIMPORT
goobj_
SHOSTOBJ
)
var
symKindStrings
=
[]
string
{
SBSS
:
"SBSS"
,
SCONST
:
"SCONST"
,
SDATA
:
"SDATA"
,
SDYNIMPORT
:
"SDYNIMPORT"
,
SELFROSECT
:
"SELFROSECT"
,
SELFRXSECT
:
"SELFRXSECT"
,
SELFSECT
:
"SELFSECT"
,
SFILE
:
"SFILE"
,
SFILEPATH
:
"SFILEPATH"
,
SFUNCTAB
:
"SFUNCTAB"
,
SGOFUNC
:
"SGOFUNC"
,
SGOSTRING
:
"SGOSTRING"
,
SHOSTOBJ
:
"SHOSTOBJ"
,
SINITARR
:
"SINITARR"
,
SMACHO
:
"SMACHO"
,
SMACHOGOT
:
"SMACHOGOT"
,
SMACHOINDIRECTGOT
:
"SMACHOINDIRECTGOT"
,
SMACHOINDIRECTPLT
:
"SMACHOINDIRECTPLT"
,
SMACHOPLT
:
"SMACHOPLT"
,
SMACHOSYMSTR
:
"SMACHOSYMSTR"
,
SMACHOSYMTAB
:
"SMACHOSYMTAB"
,
SNOPTRBSS
:
"SNOPTRBSS"
,
SNOPTRDATA
:
"SNOPTRDATA"
,
SPCLNTAB
:
"SPCLNTAB"
,
SRODATA
:
"SRODATA"
,
SSTRING
:
"SSTRING"
,
SSYMTAB
:
"SSYMTAB"
,
STEXT
:
"STEXT"
,
STLSBSS
:
"STLSBSS"
,
STYPE
:
"STYPE"
,
STYPELINK
:
"STYPELINK"
,
SWINDOWS
:
"SWINDOWS"
,
SXREF
:
"SXREF"
,
var
goobj_
symKindStrings
=
[]
string
{
goobj_
SBSS
:
"SBSS"
,
goobj_
SCONST
:
"SCONST"
,
goobj_
SDATA
:
"SDATA"
,
goobj_
SDYNIMPORT
:
"SDYNIMPORT"
,
goobj_
SELFROSECT
:
"SELFROSECT"
,
goobj_
SELFRXSECT
:
"SELFRXSECT"
,
goobj_
SELFSECT
:
"SELFSECT"
,
goobj_
SFILE
:
"SFILE"
,
goobj_
SFILEPATH
:
"SFILEPATH"
,
goobj_
SFUNCTAB
:
"SFUNCTAB"
,
goobj_
SGOFUNC
:
"SGOFUNC"
,
goobj_
SGOSTRING
:
"SGOSTRING"
,
goobj_
SHOSTOBJ
:
"SHOSTOBJ"
,
goobj_
SINITARR
:
"SINITARR"
,
goobj_
SMACHO
:
"SMACHO"
,
goobj_
SMACHOGOT
:
"SMACHOGOT"
,
goobj_
SMACHOINDIRECTGOT
:
"SMACHOINDIRECTGOT"
,
goobj_
SMACHOINDIRECTPLT
:
"SMACHOINDIRECTPLT"
,
goobj_
SMACHOPLT
:
"SMACHOPLT"
,
goobj_
SMACHOSYMSTR
:
"SMACHOSYMSTR"
,
goobj_
SMACHOSYMTAB
:
"SMACHOSYMTAB"
,
goobj_
SNOPTRBSS
:
"SNOPTRBSS"
,
goobj_
SNOPTRDATA
:
"SNOPTRDATA"
,
goobj_
SPCLNTAB
:
"SPCLNTAB"
,
goobj_
SRODATA
:
"SRODATA"
,
goobj_
SSTRING
:
"SSTRING"
,
goobj_
SSYMTAB
:
"SSYMTAB"
,
goobj_
STEXT
:
"STEXT"
,
goobj_
STLSBSS
:
"STLSBSS"
,
goobj_
STYPE
:
"STYPE"
,
goobj_
STYPELINK
:
"STYPELINK"
,
goobj_
SWINDOWS
:
"SWINDOWS"
,
goobj_
SXREF
:
"SXREF"
,
}
func
(
k
SymKind
)
String
()
string
{
if
k
<
0
||
int
(
k
)
>=
len
(
symKindStrings
)
{
func
(
k
goobj_
SymKind
)
String
()
string
{
if
k
<
0
||
int
(
k
)
>=
len
(
goobj_
symKindStrings
)
{
return
fmt
.
Sprintf
(
"SymKind(%d)"
,
k
)
}
return
symKindStrings
[
k
]
return
goobj_
symKindStrings
[
k
]
}
// A Sym is a named symbol in an object file.
type
Sym
struct
{
SymID
// symbol identifier (name and version)
Kind
SymKind
// kind of symbol
DupOK
bool
// are duplicate definitions okay?
Size
int
// size of corresponding data
Type
SymID
// symbol for Go type information
Data
Data
// memory image of symbol
Reloc
[]
Reloc
// relocations to apply to Data
Func
*
Func
// additional data for functions
type
goobj_
Sym
struct
{
goobj_SymID
// symbol identifier (name and version)
Kind
goobj_
SymKind
// kind of symbol
DupOK
bool
// are duplicate definitions okay?
Size
int
// size of corresponding data
Type
goobj_
SymID
// symbol for Go type information
Data
goobj_
Data
// memory image of symbol
Reloc
[]
goobj_
Reloc
// relocations to apply to Data
Func
*
goobj_
Func
// additional data for functions
}
// A SymID - the combination of Name and Version - uniquely identifies
// a symbol within a package.
type
SymID
struct
{
type
goobj_
SymID
struct
{
// Name is the name of a symbol.
Name
string
...
...
@@ -141,7 +147,7 @@ type SymID struct {
Version
int
}
func
(
s
SymID
)
String
()
string
{
func
(
s
goobj_
SymID
)
String
()
string
{
if
s
.
Version
==
0
{
return
s
.
Name
}
...
...
@@ -151,20 +157,20 @@ func (s SymID) String() string {
// A Data is a reference to data stored in an object file.
// It records the offset and size of the data, so that a client can
// read the data only if necessary.
type
Data
struct
{
type
goobj_
Data
struct
{
Offset
int64
Size
int64
}
// A Reloc describes a relocation applied to a memory image to refer
// to an address within a particular symbol.
type
Reloc
struct
{
type
goobj_
Reloc
struct
{
// The bytes at [Offset, Offset+Size) within the memory image
// should be updated to refer to the address Add bytes after the start
// of the symbol Sym.
Offset
int
Size
int
Sym
SymID
Sym
goobj_
SymID
Add
int
// The Type records the form of address expected in the bytes
...
...
@@ -175,7 +181,7 @@ type Reloc struct {
// A Var describes a variable in a function stack frame: a declared
// local variable, an input argument, or an output result.
type
Var
struct
{
type
goobj_
Var
struct
{
// The combination of Name, Kind, and Offset uniquely
// identifies a variable in a function stack frame.
// Using fewer of these - in particular, using only Name - does not.
...
...
@@ -183,57 +189,57 @@ type Var struct {
Kind
int
// TODO(rsc): Define meaning.
Offset
int
// Frame offset. TODO(rsc): Define meaning.
Type
SymID
// Go type for variable.
Type
goobj_
SymID
// Go type for variable.
}
// Func contains additional per-symbol information specific to functions.
type
Func
struct
{
Args
int
// size in bytes of argument frame: inputs and outputs
Frame
int
// size in bytes of local variable frame
Leaf
bool
// function omits save of link register (ARM)
NoSplit
bool
// function omits stack split prologue
Var
[]
Var
// detail about local variables
PCSP
Data
// PC → SP offset map
PCFile
Data
// PC → file number map (index into File)
PCLine
Data
// PC → line number map
PCData
[]
Data
// PC → runtime support data map
FuncData
[]
FuncData
// non-PC-specific runtime support data
File
[]
string
// paths indexed by PCFile
type
goobj_
Func
struct
{
Args
int
// size in bytes of argument frame: inputs and outputs
Frame
int
// size in bytes of local variable frame
Leaf
bool
// function omits save of link register (ARM)
NoSplit
bool
// function omits stack split prologue
Var
[]
goobj_
Var
// detail about local variables
PCSP
goobj_
Data
// PC → SP offset map
PCFile
goobj_
Data
// PC → file number map (index into File)
PCLine
goobj_
Data
// PC → line number map
PCData
[]
goobj_
Data
// PC → runtime support data map
FuncData
[]
goobj_
FuncData
// non-PC-specific runtime support data
File
[]
string
// paths indexed by PCFile
}
// TODO: Add PCData []byte and PCDataIter (similar to liblink).
// A FuncData is a single function-specific data value.
type
FuncData
struct
{
Sym
SymID
// symbol holding data
Offset
int64
// offset into symbol for funcdata pointer
type
goobj_
FuncData
struct
{
Sym
goobj_
SymID
// symbol holding data
Offset
int64
// offset into symbol for funcdata pointer
}
// A Package is a parsed Go object file or archive defining a Go package.
type
Package
struct
{
ImportPath
string
// import path denoting this package
Imports
[]
string
// packages imported by this package
Syms
[]
*
Sym
// symbols defined by this package
MaxVersion
int
// maximum Version in any SymID in Syms
type
goobj_
Package
struct
{
ImportPath
string
// import path denoting this package
Imports
[]
string
// packages imported by this package
Syms
[]
*
goobj_Sym
// symbols defined by this package
MaxVersion
int
// maximum Version in any SymID in Syms
}
var
(
archiveHeader
=
[]
byte
(
"!<arch>
\n
"
)
archiveMagic
=
[]
byte
(
"`
\n
"
)
goobjHeader
=
[]
byte
(
"go objec"
)
// truncated to size of archiveHeader
goobj_
archiveHeader
=
[]
byte
(
"!<arch>
\n
"
)
goobj_
archiveMagic
=
[]
byte
(
"`
\n
"
)
goobj
_goobj
Header
=
[]
byte
(
"go objec"
)
// truncated to size of archiveHeader
errCorruptArchive
=
errors
.
New
(
"corrupt archive"
)
errTruncatedArchive
=
errors
.
New
(
"truncated archive"
)
errNotArchive
=
errors
.
New
(
"unrecognized archive format"
)
goobj_
errCorruptArchive
=
errors
.
New
(
"corrupt archive"
)
goobj_
errTruncatedArchive
=
errors
.
New
(
"truncated archive"
)
goobj_
errNotArchive
=
errors
.
New
(
"unrecognized archive format"
)
errCorruptObject
=
errors
.
New
(
"corrupt object file"
)
errTruncatedObject
=
errors
.
New
(
"truncated object file"
)
errNotObject
=
errors
.
New
(
"unrecognized object file format"
)
goobj_
errCorruptObject
=
errors
.
New
(
"corrupt object file"
)
goobj_
errTruncatedObject
=
errors
.
New
(
"truncated object file"
)
goobj_
errNotObject
=
errors
.
New
(
"unrecognized object file format"
)
)
// An objReader is an object file reader.
type
objReader
struct
{
p
*
Package
type
goobj_
objReader
struct
{
p
*
goobj_
Package
b
*
bufio
.
Reader
f
io
.
ReadSeeker
err
error
...
...
@@ -251,7 +257,7 @@ type objReader struct {
//
// See ../../../cmd/ld/lib.c:/^pathtoprefix and
// ../../../cmd/gc/subr.c:/^pathtoprefix.
func
importPathToPrefix
(
s
string
)
string
{
func
goobj_
importPathToPrefix
(
s
string
)
string
{
// find index of last slash, if any, or else -1.
// used for determining whether an index is after the last slash.
slash
:=
strings
.
LastIndex
(
s
,
"/"
)
...
...
@@ -284,21 +290,21 @@ func importPathToPrefix(s string) string {
}
// init initializes r to read package p from f.
func
(
r
*
objReader
)
init
(
f
io
.
ReadSeeker
,
p
*
Package
)
{
func
(
r
*
goobj_objReader
)
init
(
f
io
.
ReadSeeker
,
p
*
goobj_
Package
)
{
r
.
f
=
f
r
.
p
=
p
r
.
offset
,
_
=
f
.
Seek
(
0
,
1
)
r
.
limit
,
_
=
f
.
Seek
(
0
,
2
)
f
.
Seek
(
r
.
offset
,
0
)
r
.
b
=
bufio
.
NewReader
(
f
)
r
.
pkgprefix
=
importPathToPrefix
(
p
.
ImportPath
)
+
"."
r
.
pkgprefix
=
goobj_
importPathToPrefix
(
p
.
ImportPath
)
+
"."
}
// error records that an error occurred.
// It returns only the first error, so that an error
// caused by an earlier error does not discard information
// about the earlier error.
func
(
r
*
objReader
)
error
(
err
error
)
error
{
func
(
r
*
goobj_
objReader
)
error
(
err
error
)
error
{
if
r
.
err
==
nil
{
if
err
==
io
.
EOF
{
err
=
io
.
ErrUnexpectedEOF
...
...
@@ -314,7 +320,7 @@ func (r *objReader) error(err error) error {
// A sequence of 0 bytes will eventually terminate any
// parsing state in the object file. In particular, it ends the
// reading of a varint.
func
(
r
*
objReader
)
readByte
()
byte
{
func
(
r
*
goobj_
objReader
)
readByte
()
byte
{
if
r
.
err
!=
nil
{
return
0
}
...
...
@@ -339,7 +345,7 @@ func (r *objReader) readByte() byte {
// If an error occurs, read returns the error but also
// records it, so it is safe for callers to ignore the result
// as long as delaying the report is not a problem.
func
(
r
*
objReader
)
readFull
(
b
[]
byte
)
error
{
func
(
r
*
goobj_
objReader
)
readFull
(
b
[]
byte
)
error
{
if
r
.
err
!=
nil
{
return
r
.
err
}
...
...
@@ -355,12 +361,12 @@ func (r *objReader) readFull(b []byte) error {
}
// readInt reads a zigzag varint from the input file.
func
(
r
*
objReader
)
readInt
()
int
{
func
(
r
*
goobj_
objReader
)
readInt
()
int
{
var
u
uint64
for
shift
:=
uint
(
0
);
;
shift
+=
7
{
if
shift
>=
64
{
r
.
error
(
errCorruptObject
)
r
.
error
(
goobj_
errCorruptObject
)
return
0
}
c
:=
r
.
readByte
()
...
...
@@ -372,14 +378,14 @@ func (r *objReader) readInt() int {
v
:=
int64
(
u
>>
1
)
^
(
int64
(
u
)
<<
63
>>
63
)
if
int64
(
int
(
v
))
!=
v
{
r
.
error
(
errCorruptObject
)
// TODO
r
.
error
(
goobj_
errCorruptObject
)
// TODO
return
0
}
return
int
(
v
)
}
// readString reads a length-delimited string from the input file.
func
(
r
*
objReader
)
readString
()
string
{
func
(
r
*
goobj_
objReader
)
readString
()
string
{
n
:=
r
.
readInt
()
buf
:=
make
([]
byte
,
n
)
r
.
readFull
(
buf
)
...
...
@@ -387,7 +393,7 @@ func (r *objReader) readString() string {
}
// readSymID reads a SymID from the input file.
func
(
r
*
objReader
)
readSymID
()
SymID
{
func
(
r
*
goobj_objReader
)
readSymID
()
goobj_
SymID
{
name
,
vers
:=
r
.
readString
(),
r
.
readInt
()
// In a symbol name in an object file, "". denotes the
...
...
@@ -403,19 +409,19 @@ func (r *objReader) readSymID() SymID {
vers
=
r
.
p
.
MaxVersion
}
return
SymID
{
name
,
vers
}
return
goobj_
SymID
{
name
,
vers
}
}
// readData reads a data reference from the input file.
func
(
r
*
objReader
)
readData
()
Data
{
func
(
r
*
goobj_objReader
)
readData
()
goobj_
Data
{
n
:=
r
.
readInt
()
d
:=
Data
{
Offset
:
r
.
offset
,
Size
:
int64
(
n
)}
d
:=
goobj_
Data
{
Offset
:
r
.
offset
,
Size
:
int64
(
n
)}
r
.
skip
(
int64
(
n
))
return
d
}
// skip skips n bytes in the input.
func
(
r
*
objReader
)
skip
(
n
int64
)
{
func
(
r
*
goobj_
objReader
)
skip
(
n
int64
)
{
if
n
<
0
{
r
.
error
(
fmt
.
Errorf
(
"debug/goobj: internal error: misuse of skip"
))
}
...
...
@@ -444,14 +450,14 @@ func (r *objReader) skip(n int64) {
// Parse parses an object file or archive from r,
// assuming that its import path is pkgpath.
func
Parse
(
r
io
.
ReadSeeker
,
pkgpath
string
)
(
*
Package
,
error
)
{
func
goobj_Parse
(
r
io
.
ReadSeeker
,
pkgpath
string
)
(
*
goobj_
Package
,
error
)
{
if
pkgpath
==
""
{
pkgpath
=
`""`
}
p
:=
new
(
Package
)
p
:=
new
(
goobj_
Package
)
p
.
ImportPath
=
pkgpath
var
rd
objReader
var
rd
goobj_
objReader
rd
.
init
(
r
,
p
)
err
:=
rd
.
readFull
(
rd
.
tmp
[
:
8
])
if
err
!=
nil
{
...
...
@@ -463,14 +469,14 @@ func Parse(r io.ReadSeeker, pkgpath string) (*Package, error) {
switch
{
default
:
return
nil
,
errNotObject
return
nil
,
goobj_
errNotObject
case
bytes
.
Equal
(
rd
.
tmp
[
:
8
],
archiveHeader
)
:
case
bytes
.
Equal
(
rd
.
tmp
[
:
8
],
goobj_
archiveHeader
)
:
if
err
:=
rd
.
parseArchive
();
err
!=
nil
{
return
nil
,
err
}
case
bytes
.
Equal
(
rd
.
tmp
[
:
8
],
goobjHeader
)
:
if
err
:=
rd
.
parseObject
(
goobjHeader
);
err
!=
nil
{
case
bytes
.
Equal
(
rd
.
tmp
[
:
8
],
goobj
_goobj
Header
)
:
if
err
:=
rd
.
parseObject
(
goobj
_goobj
Header
);
err
!=
nil
{
return
nil
,
err
}
}
...
...
@@ -480,7 +486,7 @@ func Parse(r io.ReadSeeker, pkgpath string) (*Package, error) {
// trimSpace removes trailing spaces from b and returns the corresponding string.
// This effectively parses the form used in archive headers.
func
trimSpace
(
b
[]
byte
)
string
{
func
goobj_
trimSpace
(
b
[]
byte
)
string
{
return
string
(
bytes
.
TrimRight
(
b
,
" "
))
}
...
...
@@ -488,7 +494,7 @@ func trimSpace(b []byte) string {
// TODO(rsc): Need to skip non-Go object files.
// TODO(rsc): Maybe record table of contents in r.p so that
// linker can avoid having code to parse archives too.
func
(
r
*
objReader
)
parseArchive
()
error
{
func
(
r
*
goobj_
objReader
)
parseArchive
()
error
{
for
r
.
offset
<
r
.
limit
{
if
err
:=
r
.
readFull
(
r
.
tmp
[
:
60
]);
err
!=
nil
{
return
err
...
...
@@ -512,20 +518,20 @@ func (r *objReader) parseArchive() error {
// The file data that follows is padded to an even number of bytes:
// if size is odd, an extra padding byte is inserted betw the next header.
if
len
(
data
)
<
60
{
return
errTruncatedArchive
return
goobj_
errTruncatedArchive
}
if
!
bytes
.
Equal
(
data
[
58
:
60
],
archiveMagic
)
{
return
errCorruptArchive
if
!
bytes
.
Equal
(
data
[
58
:
60
],
goobj_
archiveMagic
)
{
return
goobj_
errCorruptArchive
}
name
:=
trimSpace
(
data
[
0
:
16
])
size
,
err
:=
strconv
.
ParseInt
(
trimSpace
(
data
[
48
:
58
]),
10
,
64
)
name
:=
goobj_
trimSpace
(
data
[
0
:
16
])
size
,
err
:=
strconv
.
ParseInt
(
goobj_
trimSpace
(
data
[
48
:
58
]),
10
,
64
)
if
err
!=
nil
{
return
errCorruptArchive
return
goobj_
errCorruptArchive
}
data
=
data
[
60
:
]
fsize
:=
size
+
size
&
1
if
fsize
<
0
||
fsize
<
size
{
return
errCorruptArchive
return
goobj_
errCorruptArchive
}
switch
name
{
case
"__.SYMDEF"
,
"__.GOSYMDEF"
,
"__.PKGDEF"
:
...
...
@@ -553,7 +559,7 @@ func (r *objReader) parseArchive() error {
// and then the part we want to parse begins.
// The format of that part is defined in a comment at the top
// of src/liblink/objfile.c.
func
(
r
*
objReader
)
parseObject
(
prefix
[]
byte
)
error
{
func
(
r
*
goobj_
objReader
)
parseObject
(
prefix
[]
byte
)
error
{
// TODO(rsc): Maybe use prefix and the initial input to
// record the header line from the file, which would
// give the architecture and other version information.
...
...
@@ -563,7 +569,7 @@ func (r *objReader) parseObject(prefix []byte) error {
for
{
c1
,
c2
,
c3
=
c2
,
c3
,
r
.
readByte
()
if
c3
==
0
{
// NUL or EOF, either is bad
return
errCorruptObject
return
goobj_
errCorruptObject
}
if
c1
==
'\n'
&&
c2
==
'!'
&&
c3
==
'\n'
{
break
...
...
@@ -572,12 +578,12 @@ func (r *objReader) parseObject(prefix []byte) error {
r
.
readFull
(
r
.
tmp
[
:
8
])
if
!
bytes
.
Equal
(
r
.
tmp
[
:
8
],
[]
byte
(
"
\x00\x00
go13ld"
))
{
return
r
.
error
(
errCorruptObject
)
return
r
.
error
(
goobj_
errCorruptObject
)
}
b
:=
r
.
readByte
()
if
b
!=
1
{
return
r
.
error
(
errCorruptObject
)
return
r
.
error
(
goobj_
errCorruptObject
)
}
// Direct package dependencies.
...
...
@@ -593,20 +599,20 @@ func (r *objReader) parseObject(prefix []byte) error {
for
{
if
b
:=
r
.
readByte
();
b
!=
0xfe
{
if
b
!=
0xff
{
return
r
.
error
(
errCorruptObject
)
return
r
.
error
(
goobj_
errCorruptObject
)
}
break
}
typ
:=
r
.
readInt
()
s
:=
&
Sym
{
SymID
:
r
.
readSymID
()}
s
:=
&
goobj_Sym
{
goobj_
SymID
:
r
.
readSymID
()}
r
.
p
.
Syms
=
append
(
r
.
p
.
Syms
,
s
)
s
.
Kind
=
SymKind
(
typ
)
s
.
Kind
=
goobj_
SymKind
(
typ
)
s
.
DupOK
=
r
.
readInt
()
!=
0
s
.
Size
=
r
.
readInt
()
s
.
Type
=
r
.
readSymID
()
s
.
Data
=
r
.
readData
()
s
.
Reloc
=
make
([]
Reloc
,
r
.
readInt
())
s
.
Reloc
=
make
([]
goobj_
Reloc
,
r
.
readInt
())
for
i
:=
range
s
.
Reloc
{
rel
:=
&
s
.
Reloc
[
i
]
rel
.
Offset
=
r
.
readInt
()
...
...
@@ -618,14 +624,14 @@ func (r *objReader) parseObject(prefix []byte) error {
r
.
readSymID
()
// Xsym - ignored
}
if
s
.
Kind
==
STEXT
{
f
:=
new
(
Func
)
if
s
.
Kind
==
goobj_
STEXT
{
f
:=
new
(
goobj_
Func
)
s
.
Func
=
f
f
.
Args
=
r
.
readInt
()
f
.
Frame
=
r
.
readInt
()
f
.
Leaf
=
r
.
readInt
()
!=
0
f
.
NoSplit
=
r
.
readInt
()
!=
0
f
.
Var
=
make
([]
Var
,
r
.
readInt
())
f
.
Var
=
make
([]
goobj_
Var
,
r
.
readInt
())
for
i
:=
range
f
.
Var
{
v
:=
&
f
.
Var
[
i
]
v
.
Name
=
r
.
readSymID
()
.
Name
...
...
@@ -637,11 +643,11 @@ func (r *objReader) parseObject(prefix []byte) error {
f
.
PCSP
=
r
.
readData
()
f
.
PCFile
=
r
.
readData
()
f
.
PCLine
=
r
.
readData
()
f
.
PCData
=
make
([]
Data
,
r
.
readInt
())
f
.
PCData
=
make
([]
goobj_
Data
,
r
.
readInt
())
for
i
:=
range
f
.
PCData
{
f
.
PCData
[
i
]
=
r
.
readData
()
}
f
.
FuncData
=
make
([]
FuncData
,
r
.
readInt
())
f
.
FuncData
=
make
([]
goobj_
FuncData
,
r
.
readInt
())
for
i
:=
range
f
.
FuncData
{
f
.
FuncData
[
i
]
.
Sym
=
r
.
readSymID
()
}
...
...
@@ -657,7 +663,7 @@ func (r *objReader) parseObject(prefix []byte) error {
r
.
readFull
(
r
.
tmp
[
:
7
])
if
!
bytes
.
Equal
(
r
.
tmp
[
:
7
],
[]
byte
(
"
\xff
go13ld"
))
{
return
r
.
error
(
errCorruptObject
)
return
r
.
error
(
goobj_
errCorruptObject
)
}
return
nil
...
...
src/cmd/nm/goobj.go
View file @
d00442ab
...
...
@@ -7,12 +7,11 @@
package
main
import
(
"debug/goobj"
"fmt"
"os"
)
func
goobjName
(
id
goobj
.
SymID
)
string
{
func
goobjName
(
id
goobj
_
SymID
)
string
{
if
id
.
Version
==
0
{
return
id
.
Name
}
...
...
@@ -20,28 +19,28 @@ func goobjName(id goobj.SymID) string {
}
func
goobjSymbols
(
f
*
os
.
File
)
[]
Sym
{
pkg
,
err
:=
goobj
.
Parse
(
f
,
`""`
)
pkg
,
err
:=
goobj
_
Parse
(
f
,
`""`
)
if
err
!=
nil
{
errorf
(
"parsing %s: %v"
,
f
.
Name
(),
err
)
return
nil
}
seen
:=
make
(
map
[
goobj
.
SymID
]
bool
)
seen
:=
make
(
map
[
goobj
_
SymID
]
bool
)
var
syms
[]
Sym
for
_
,
s
:=
range
pkg
.
Syms
{
seen
[
s
.
SymID
]
=
true
sym
:=
Sym
{
Addr
:
uint64
(
s
.
Data
.
Offset
),
Name
:
goobjName
(
s
.
SymID
),
Size
:
int64
(
s
.
Size
),
Type
:
s
.
Type
.
Name
,
Code
:
'?'
}
seen
[
s
.
goobj_
SymID
]
=
true
sym
:=
Sym
{
Addr
:
uint64
(
s
.
Data
.
Offset
),
Name
:
goobjName
(
s
.
goobj_
SymID
),
Size
:
int64
(
s
.
Size
),
Type
:
s
.
Type
.
Name
,
Code
:
'?'
}
switch
s
.
Kind
{
case
goobj
.
STEXT
,
goobj
.
SELFRXSECT
:
case
goobj
_STEXT
,
goobj_
SELFRXSECT
:
sym
.
Code
=
'T'
case
goobj
.
STYPE
,
goobj
.
SSTRING
,
goobj
.
SGOSTRING
,
goobj
.
SGOFUNC
,
goobj
.
SRODATA
,
goobj
.
SFUNCTAB
,
goobj
.
STYPELINK
,
goobj
.
SSYMTAB
,
goobj
.
SPCLNTAB
,
goobj
.
SELFROSECT
:
case
goobj
_STYPE
,
goobj_SSTRING
,
goobj_SGOSTRING
,
goobj_SGOFUNC
,
goobj_SRODATA
,
goobj_SFUNCTAB
,
goobj_STYPELINK
,
goobj_SSYMTAB
,
goobj_SPCLNTAB
,
goobj_
SELFROSECT
:
sym
.
Code
=
'R'
case
goobj
.
SMACHOPLT
,
goobj
.
SELFSECT
,
goobj
.
SMACHO
,
goobj
.
SMACHOGOT
,
goobj
.
SNOPTRDATA
,
goobj
.
SINITARR
,
goobj
.
SDATA
,
goobj
.
SWINDOWS
:
case
goobj
_SMACHOPLT
,
goobj_SELFSECT
,
goobj_SMACHO
,
goobj_SMACHOGOT
,
goobj_SNOPTRDATA
,
goobj_SINITARR
,
goobj_SDATA
,
goobj_
SWINDOWS
:
sym
.
Code
=
'D'
case
goobj
.
SBSS
,
goobj
.
SNOPTRBSS
,
goobj
.
STLSBSS
:
case
goobj
_SBSS
,
goobj_SNOPTRBSS
,
goobj_
STLSBSS
:
sym
.
Code
=
'B'
case
goobj
.
SXREF
,
goobj
.
SMACHOSYMSTR
,
goobj
.
SMACHOSYMTAB
,
goobj
.
SMACHOINDIRECTPLT
,
goobj
.
SMACHOINDIRECTGOT
,
goobj
.
SFILE
,
goobj
.
SFILEPATH
,
goobj
.
SCONST
,
goobj
.
SDYNIMPORT
,
goobj
.
SHOSTOBJ
:
case
goobj
_SXREF
,
goobj_SMACHOSYMSTR
,
goobj_SMACHOSYMTAB
,
goobj_SMACHOINDIRECTPLT
,
goobj_SMACHOINDIRECTGOT
,
goobj_SFILE
,
goobj_SFILEPATH
,
goobj_SCONST
,
goobj_SDYNIMPORT
,
goobj_
SHOSTOBJ
:
sym
.
Code
=
'X'
// should not see
}
if
s
.
Version
!=
0
{
...
...
src/pkg/debug/goobj/read_test.go
deleted
100644 → 0
View file @
f40040b0
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
goobj
import
"testing"
var
importPathToPrefixTests
=
[]
struct
{
in
string
out
string
}{
{
"runtime"
,
"runtime"
},
{
"sync/atomic"
,
"sync/atomic"
},
{
"code.google.com/p/go.tools/godoc"
,
"code.google.com/p/go.tools/godoc"
},
{
"foo.bar/baz.quux"
,
"foo.bar/baz%2equux"
},
{
""
,
""
},
{
"%foo%bar"
,
"%25foo%25bar"
},
{
"
\x01\x00\x7F
☺"
,
"%01%00%7f%e2%98%ba"
},
}
func
TestImportPathToPrefix
(
t
*
testing
.
T
)
{
for
_
,
tt
:=
range
importPathToPrefixTests
{
if
out
:=
importPathToPrefix
(
tt
.
in
);
out
!=
tt
.
out
{
t
.
Errorf
(
"importPathToPrefix(%q) = %q, want %q"
,
tt
.
in
,
out
,
tt
.
out
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment