Documentation ¶
Overview ¶
package pfelf implements functions for processing of ELF files and extracting data from them. This file provides a cacheable file offset to virtual address mapping.
package pfelf implements functions for processing of ELF files and extracting data from them. This file provides convenience functions for golang debug/elf standard library.
Index ¶
- Variables
- func GetBuildID(elfFile *elf.File) (string, error)
- func GetBuildIDFromNotesFile(filePath string) (string, error)
- func GetDebugLink(elfFile *elf.File) (linkName string, crc32 int32, err error)
- func GetDynamicSymbols(elfFile *elf.File) (*libpf.SymbolMap, error)
- func GetKernelVersionBytes(elfFile *elf.File) ([]byte, error)
- func GetSectionAddress(e *elf.File, sectionName string) (addr uint64, found bool, err error)
- func HasCodeSection(elfFile *elf.File) bool
- func HasDWARFData(elfFile *elf.File) bool
- func HasSection(file *elf.File, section string) (bool, error)
- func IsGoBinary(file *elf.File) (bool, error)
- func ParseDebugLink(data []byte) (linkName string, crc32 int32, err error)
- type AddressMapper
- type ELFOpener
- type File
- func (f *File) CRC32() (int32, error)
- func (f *File) Close() (err error)
- func (f *File) DebuglinkFileName(elfFilePath string, elfOpener ELFOpener) string
- func (f *File) DynString(tag elf.DynTag) ([]string, error)
- func (f *File) EHFrame() (*Prog, error)
- func (f *File) GetAddressMapper() AddressMapper
- func (f *File) GetBuildID() (string, error)
- func (f *File) GetDebugLink() (linkName string, crc int32, err error)
- func (f *File) GetRemoteMemory() remotememory.RemoteMemory
- func (f *File) IsGolang() bool
- func (f *File) LoadSections() error
- func (f *File) LookupSymbol(symbol libpf.SymbolName) (*libpf.Symbol, error)
- func (f *File) LookupSymbolAddress(symbol libpf.SymbolName) (libpf.SymbolValue, error)
- func (f *File) OpenDebugLink(elfFilePath string, elfOpener ELFOpener) (debugELF *File, debugFile string)
- func (f *File) ReadAt(p []byte, addr int64) (int, error)
- func (f *File) ReadDynamicSymbols() (*libpf.SymbolMap, error)
- func (f *File) ReadSymbols() (*libpf.SymbolMap, error)
- func (f *File) ReadVirtualMemory(p []byte, addr int64) (int, error)
- func (f *File) Section(name string) *Section
- func (f *File) TLSDescriptors() (map[string]libpf.Address, error)
- type Prog
- type Reference
- type Section
Constants ¶
This section is empty.
Variables ¶
var ErrNoBuildID = errors.New("no build ID")
var ErrNoDebugLink = errors.New("no debug link")
var ErrNotELF = errors.New("not an ELF file")
ErrNotELF is returned when the file is not an ELF
var ErrSymbolNotFound = errors.New("symbol not found")
ErrSymbolNotFound is returned when requested symbol was not found
var SystemOpener systemOpener
Functions ¶
func GetBuildID ¶
GetBuildID extracts the build ID from the provided ELF file. This is read from the .note.gnu.build-id or .notes section of the ELF, and may not exist. If no build ID is present an ErrNoBuildID is returned.
func GetBuildIDFromNotesFile ¶
GetBuildIDFromNotesFile returns the build ID contained in a file with the format of an ELF notes section.
func GetDebugLink ¶
GetDebugLink reads and parses the .gnu_debuglink section of given ELF file. Error is returned if the data is malformed. If the link does not exist then ErrNoDebugLink is returned.
func GetDynamicSymbols ¶
GetDynamicSymbols gets the dynamic symbols of elf.File and returns them as libpf.SymbolMap for fast lookup by address and name.
func GetKernelVersionBytes ¶
GetKernelVersionBytes returns the kernel version from a kernel image, as it appears in /proc/version
This makes the assumption that the string is the first one in ".rodata" that starts with "Linux version ".
func GetSectionAddress ¶
GetSectionAddress returns the address of an ELF section. `found` is set to false if such a section does not exist.
func HasCodeSection ¶
HasCodeSection returns true if the file contains at least one non-empty executable code section.
func HasDWARFData ¶
HasDWARFData returns true if the provided ELF file contains actionable DWARF debugging information. This function does not call `elfFile.DWARF()` on purpose, as it can be extremely expensive in terms of CPU/memory, possibly uncompressing all data in `.zdebug_` sections. This function being used extensively by the indexing service, it is preferable to keep it lightweight.
func HasSection ¶
HasSection returns true if the provided file contains a specific section.
func IsGoBinary ¶
IsGoBinary returns true if the provided file is a Go binary (= an ELF file with a known Golang section).
Types ¶
type AddressMapper ¶
type AddressMapper struct {
// contains filtered or unexported fields
}
AddressMapper contains minimal information about PHDRs needed for address mapping
func (*AddressMapper) FileOffsetToVirtualAddress ¶
func (am *AddressMapper) FileOffsetToVirtualAddress(fileOffset uint64) (uint64, bool)
FileOffsetToVirtualAddress attempts to convert an on-disk file offset to the ELF virtual address where it would be mapped by default.
type ELFOpener ¶
ELFOpener is the interface to open ELF files from arbitrary location with given filename.
Implementations must be safe to be called from different threads simultaneously.
type File ¶
type File struct { // ROData is a slice of pointers to the read-only data segments of the ELF // These are sorted so that segments marked as "read" appear before those // marked as "read-execute" ROData []*Prog // Progs contains the program header Progs []Prog // Sections contains the program sections if loaded Sections []Section // InsideCore indicates that this ELF is mapped from a coredump ELF InsideCore bool // Fields to mimic elf.debug Type elf.Type Machine elf.Machine Entry uint64 // contains filtered or unexported fields }
File represents an open ELF file
func (*File) DebuglinkFileName ¶
DebuglinkFileName returns the debug file linked by .gnu_debuglink if any
func (*File) DynString ¶
DynString returns the strings listed for the given tag in the file's dynamic program header.
func (*File) GetAddressMapper ¶
func (f *File) GetAddressMapper() AddressMapper
NewAddressMapper returns an address mapper for given ELF File
func (*File) GetBuildID ¶
GetBuildID returns the ELF BuildID if present
func (*File) GetDebugLink ¶
GetDebugLink reads and parses the .gnu_debuglink section. If the link does not exist then ErrNoDebugLink is returned.
func (*File) GetRemoteMemory ¶
func (f *File) GetRemoteMemory() remotememory.RemoteMemory
GetRemoteMemory returns RemoteMemory interface for the core dump
func (*File) LoadSections ¶
LoadSections loads the ELF file sections
func (*File) LookupSymbol ¶
LookupSymbol searches for a given symbol in the ELF
func (*File) LookupSymbolAddress ¶
func (f *File) LookupSymbolAddress(symbol libpf.SymbolName) (libpf.SymbolValue, error)
LookupSymbol searches for a given symbol in the ELF
func (*File) OpenDebugLink ¶
func (f *File) OpenDebugLink(elfFilePath string, elfOpener ELFOpener) ( debugELF *File, debugFile string)
OpenDebugLink tries to locate and open the corresponding debug ELF for this DSO.
func (*File) ReadDynamicSymbols ¶
ReadDynamicSymbols reads the full dynamic symbol table from the ELF
func (*File) ReadSymbols ¶
ReadSymbols reads the full dynamic symbol table from the ELF
func (*File) ReadVirtualMemory ¶
ReadVirtualMemory reads bytes from given virtual address
type Prog ¶
type Prog struct { elf.ProgHeader // contains filtered or unexported fields }
Prog represents a program header, and data associated with it
func (*Prog) DataReader ¶
DataReader loads the whole program header referenced data, and returns reader to it.
func (*Prog) Open ¶
func (ph *Prog) Open() io.ReadSeeker
Open returns a new ReadSeeker reading the ELF program body.
type Reference ¶
type Reference struct { // Interface to open ELF files as needed ELFOpener // contains filtered or unexported fields }
Reference is a reference to an ELF file which is loaded and cached on demand.
func NewReference ¶
NewReference returns a new Reference
func (*Reference) Close ¶
func (ref *Reference) Close()
Close closes the File if it has been opened earlier.