mirror of
https://github.com/golang/go
synced 2024-11-12 03:00:22 -07:00
debug/pe: unexport newly introduced identifiers
CLs 22181, 22332 and 22336 intorduced new functionality to be used in cmd/link (see issue #15345 for details). But we didn't have chance to use new functionality yet. Unexport newly introduced identifiers, so we don't have to commit to the API until we actually tried it. Rename File.COFFSymbols into File._COFFSymbols, COFFSymbol.FullName into COFFSymbol._FullName, Section.Relocs into Section._Relocs, Reloc into _Relocs, File.StringTable into File._StringTable and StringTable into _StringTable. Updates #15345 Change-Id: I770eeb61f855de85e0c175225d5d1c006869b9ec Reviewed-on: https://go-review.googlesource.com/22720 Reviewed-by: David Crawshaw <crawshaw@golang.org> Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
27d0d849fe
commit
57be1607d9
@ -19,8 +19,8 @@ type File struct {
|
|||||||
OptionalHeader interface{} // of type *OptionalHeader32 or *OptionalHeader64
|
OptionalHeader interface{} // of type *OptionalHeader32 or *OptionalHeader64
|
||||||
Sections []*Section
|
Sections []*Section
|
||||||
Symbols []*Symbol // COFF symbols with auxiliary symbol records removed
|
Symbols []*Symbol // COFF symbols with auxiliary symbol records removed
|
||||||
COFFSymbols []COFFSymbol // all COFF symbols (including auxiliary symbol records)
|
_COFFSymbols []COFFSymbol // all COFF symbols (including auxiliary symbol records)
|
||||||
StringTable StringTable
|
_StringTable _StringTable
|
||||||
|
|
||||||
closer io.Closer
|
closer io.Closer
|
||||||
}
|
}
|
||||||
@ -93,17 +93,17 @@ func NewFile(r io.ReaderAt) (*File, error) {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Read string table.
|
// Read string table.
|
||||||
f.StringTable, err = readStringTable(&f.FileHeader, sr)
|
f._StringTable, err = readStringTable(&f.FileHeader, sr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read symbol table.
|
// Read symbol table.
|
||||||
f.COFFSymbols, err = readCOFFSymbols(&f.FileHeader, sr)
|
f._COFFSymbols, err = readCOFFSymbols(&f.FileHeader, sr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
f.Symbols, err = removeAuxSymbols(f.COFFSymbols, f.StringTable)
|
f.Symbols, err = removeAuxSymbols(f._COFFSymbols, f._StringTable)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -141,7 +141,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
|
|||||||
if err := binary.Read(sr, binary.LittleEndian, sh); err != nil {
|
if err := binary.Read(sr, binary.LittleEndian, sh); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
name, err := sh.fullName(f.StringTable)
|
name, err := sh.fullName(f._StringTable)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ func NewFile(r io.ReaderAt) (*File, error) {
|
|||||||
}
|
}
|
||||||
for i := range f.Sections {
|
for i := range f.Sections {
|
||||||
var err error
|
var err error
|
||||||
f.Sections[i].Relocs, err = readRelocs(&f.Sections[i].SectionHeader, sr)
|
f.Sections[i]._Relocs, err = readRelocs(&f.Sections[i].SectionHeader, sr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ type SectionHeader32 struct {
|
|||||||
// fullName finds real name of section sh. Normally name is stored
|
// fullName finds real name of section sh. Normally name is stored
|
||||||
// in sh.Name, but if it is longer then 8 characters, it is stored
|
// in sh.Name, but if it is longer then 8 characters, it is stored
|
||||||
// in COFF string table st instead.
|
// in COFF string table st instead.
|
||||||
func (sh *SectionHeader32) fullName(st StringTable) (string, error) {
|
func (sh *SectionHeader32) fullName(st _StringTable) (string, error) {
|
||||||
if sh.Name[0] != '/' {
|
if sh.Name[0] != '/' {
|
||||||
return cstring(sh.Name[:]), nil
|
return cstring(sh.Name[:]), nil
|
||||||
}
|
}
|
||||||
@ -41,15 +41,15 @@ func (sh *SectionHeader32) fullName(st StringTable) (string, error) {
|
|||||||
|
|
||||||
// TODO(brainman): copy all IMAGE_REL_* consts from ldpe.go here
|
// TODO(brainman): copy all IMAGE_REL_* consts from ldpe.go here
|
||||||
|
|
||||||
// Reloc represents a PE COFF relocation.
|
// _Reloc represents a PE COFF relocation.
|
||||||
// Each section contains its own relocation list.
|
// Each section contains its own relocation list.
|
||||||
type Reloc struct {
|
type _Reloc struct {
|
||||||
VirtualAddress uint32
|
VirtualAddress uint32
|
||||||
SymbolTableIndex uint32
|
SymbolTableIndex uint32
|
||||||
Type uint16
|
Type uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
func readRelocs(sh *SectionHeader, r io.ReadSeeker) ([]Reloc, error) {
|
func readRelocs(sh *SectionHeader, r io.ReadSeeker) ([]_Reloc, error) {
|
||||||
if sh.NumberOfRelocations <= 0 {
|
if sh.NumberOfRelocations <= 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ func readRelocs(sh *SectionHeader, r io.ReadSeeker) ([]Reloc, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("fail to seek to %q section relocations: %v", sh.Name, err)
|
return nil, fmt.Errorf("fail to seek to %q section relocations: %v", sh.Name, err)
|
||||||
}
|
}
|
||||||
relocs := make([]Reloc, sh.NumberOfRelocations)
|
relocs := make([]_Reloc, sh.NumberOfRelocations)
|
||||||
err = binary.Read(r, binary.LittleEndian, relocs)
|
err = binary.Read(r, binary.LittleEndian, relocs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("fail to read section relocations: %v", err)
|
return nil, fmt.Errorf("fail to read section relocations: %v", err)
|
||||||
@ -83,7 +83,7 @@ type SectionHeader struct {
|
|||||||
// Section provides access to PE COFF section.
|
// Section provides access to PE COFF section.
|
||||||
type Section struct {
|
type Section struct {
|
||||||
SectionHeader
|
SectionHeader
|
||||||
Relocs []Reloc
|
_Relocs []_Reloc
|
||||||
|
|
||||||
// Embed ReaderAt for ReadAt method.
|
// Embed ReaderAt for ReadAt method.
|
||||||
// Do not embed SectionReader directly
|
// Do not embed SectionReader directly
|
||||||
|
@ -19,10 +19,10 @@ func cstring(b []byte) string {
|
|||||||
return string(b[:i])
|
return string(b[:i])
|
||||||
}
|
}
|
||||||
|
|
||||||
// StringTable is a COFF string table.
|
// _StringTable is a COFF string table.
|
||||||
type StringTable []byte
|
type _StringTable []byte
|
||||||
|
|
||||||
func readStringTable(fh *FileHeader, r io.ReadSeeker) (StringTable, error) {
|
func readStringTable(fh *FileHeader, r io.ReadSeeker) (_StringTable, error) {
|
||||||
// COFF string table is located right after COFF symbol table.
|
// COFF string table is located right after COFF symbol table.
|
||||||
offset := fh.PointerToSymbolTable + COFFSymbolSize*fh.NumberOfSymbols
|
offset := fh.PointerToSymbolTable + COFFSymbolSize*fh.NumberOfSymbols
|
||||||
_, err := r.Seek(int64(offset), io.SeekStart)
|
_, err := r.Seek(int64(offset), io.SeekStart)
|
||||||
@ -44,13 +44,13 @@ func readStringTable(fh *FileHeader, r io.ReadSeeker) (StringTable, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("fail to read string table: %v", err)
|
return nil, fmt.Errorf("fail to read string table: %v", err)
|
||||||
}
|
}
|
||||||
return StringTable(buf), nil
|
return _StringTable(buf), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(brainman): decide if start parameter should be int instead of uint32
|
// TODO(brainman): decide if start parameter should be int instead of uint32
|
||||||
|
|
||||||
// String extracts string from COFF string table st at offset start.
|
// String extracts string from COFF string table st at offset start.
|
||||||
func (st StringTable) String(start uint32) (string, error) {
|
func (st _StringTable) String(start uint32) (string, error) {
|
||||||
// start includes 4 bytes of string table length
|
// start includes 4 bytes of string table length
|
||||||
if start < 4 {
|
if start < 4 {
|
||||||
return "", fmt.Errorf("offset %d is before the start of string table", start)
|
return "", fmt.Errorf("offset %d is before the start of string table", start)
|
||||||
|
@ -46,17 +46,17 @@ func isSymNameOffset(name [8]byte) (bool, uint32) {
|
|||||||
return false, 0
|
return false, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// FullName finds real name of symbol sym. Normally name is stored
|
// _FullName finds real name of symbol sym. Normally name is stored
|
||||||
// in sym.Name, but if it is longer then 8 characters, it is stored
|
// in sym.Name, but if it is longer then 8 characters, it is stored
|
||||||
// in COFF string table st instead.
|
// in COFF string table st instead.
|
||||||
func (sym *COFFSymbol) FullName(st StringTable) (string, error) {
|
func (sym *COFFSymbol) _FullName(st _StringTable) (string, error) {
|
||||||
if ok, offset := isSymNameOffset(sym.Name); ok {
|
if ok, offset := isSymNameOffset(sym.Name); ok {
|
||||||
return st.String(offset)
|
return st.String(offset)
|
||||||
}
|
}
|
||||||
return cstring(sym.Name[:]), nil
|
return cstring(sym.Name[:]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeAuxSymbols(allsyms []COFFSymbol, st StringTable) ([]*Symbol, error) {
|
func removeAuxSymbols(allsyms []COFFSymbol, st _StringTable) ([]*Symbol, error) {
|
||||||
if len(allsyms) == 0 {
|
if len(allsyms) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ func removeAuxSymbols(allsyms []COFFSymbol, st StringTable) ([]*Symbol, error) {
|
|||||||
aux--
|
aux--
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
name, err := sym.FullName(st)
|
name, err := sym._FullName(st)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user