github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/internal/objfile/objfile.go (about)

     1  // Copyright 2014 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package objfile implements portable access to OS-specific executable files.
     6  package objfile
     7  
     8  import (
     9  	"github.com/shogo82148/std/debug/dwarf"
    10  	"github.com/shogo82148/std/os"
    11  )
    12  
    13  // A File is an opened executable file.
    14  type File struct {
    15  	r       *os.File
    16  	entries []*Entry
    17  }
    18  
    19  type Entry struct {
    20  	name string
    21  	raw  rawFile
    22  }
    23  
    24  // A Sym is a symbol defined in an executable file.
    25  type Sym struct {
    26  	Name   string
    27  	Addr   uint64
    28  	Size   int64
    29  	Code   rune
    30  	Type   string
    31  	Relocs []Reloc
    32  }
    33  
    34  type Reloc struct {
    35  	Addr     uint64
    36  	Size     uint64
    37  	Stringer RelocStringer
    38  }
    39  
    40  type RelocStringer interface {
    41  	String(insnOffset uint64) string
    42  }
    43  
    44  // Open opens the named file.
    45  // The caller must call f.Close when the file is no longer needed.
    46  func Open(name string) (*File, error)
    47  
    48  func (f *File) Close() error
    49  
    50  func (f *File) Entries() []*Entry
    51  
    52  func (f *File) Symbols() ([]Sym, error)
    53  
    54  func (f *File) PCLineTable() (Liner, error)
    55  
    56  func (f *File) Text() (uint64, []byte, error)
    57  
    58  func (f *File) GOARCH() string
    59  
    60  func (f *File) LoadAddress() (uint64, error)
    61  
    62  func (f *File) DWARF() (*dwarf.Data, error)
    63  
    64  func (f *File) Disasm() (*Disasm, error)
    65  
    66  func (e *Entry) Name() string
    67  
    68  func (e *Entry) Symbols() ([]Sym, error)
    69  
    70  func (e *Entry) PCLineTable() (Liner, error)
    71  
    72  func (e *Entry) Text() (uint64, []byte, error)
    73  
    74  func (e *Entry) GOARCH() string
    75  
    76  // LoadAddress returns the expected load address of the file.
    77  // This differs from the actual load address for a position-independent
    78  // executable.
    79  func (e *Entry) LoadAddress() (uint64, error)
    80  
    81  // DWARF returns DWARF debug data for the file, if any.
    82  // This is for cmd/pprof to locate cgo functions.
    83  func (e *Entry) DWARF() (*dwarf.Data, error)