Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoInterpreter is returned if no interpreter is found in an ELF file. ErrNoInterpreter = errors.New("no interpreter in ELF file") // ErrNotELFFile is returned if the file does not have an ELF magic number. ErrNotELFFile = errors.New("is not an ELF file") // ErrOSABINotSupported is returned if the OS ABI of an ELF file is not // supported. ErrOSABINotSupported = errors.New("OSABI not supported") // ErrMachineNotSupported is returned if the machine type of an ELF file // is not supported. ErrMachineNotSupported = errors.New("machine type not supported") )
var ErrArchNotSupported = errors.New("architecture not supported")
Functions ¶
func AssertContainsPaths ¶ added in v0.12.0
func Ldd ¶ added in v0.12.0
Ldd gathers the required shared objects of the ELF file with the given path. The path must point to an ELF file. ErrNotELFFile is returned if it is not an ELF file. ErrNoInterpreter is returned if no interpreter path is found in the ELF file. This is the case if the binary was statically linked.
The objects are searched for in the usual search paths of the file's interpreter. Note that the dynamic linker consumes the environment variable LD_LIBRARY_PATH, so it can be used to add additional search paths.
Since this implementation executes the ELF interpreter of the given file, it should be run only for trusted binaries!
Until version 2.27 the glibc provided ldd worked like this implementation and executed the binaries ELF interpreter directly. Since this has some security implications and may lead to unintended execution of arbitrary code it was changed with version 2.27. With newer versions, ldd tries a set of fixed known ELF interpreters. Since they are specific to the glibc build, thus Linux distribution specific, it is not feasible for this implementation. Because of this the former procedure is used, so use with great care!
Types ¶
type Arch ¶
type Arch string
func ReadELFArch ¶ added in v0.12.0
ReadELFArch returns the sys.Arch of the given ELF file.
It returns an error if the ELF file is not for Linux or is for an unsupported architecture.
func (*Arch) KVMAvailable ¶
KVMAvailable checks if KVM support is available for the given architecture.
type LibCollection ¶ added in v0.12.0
type LibCollection struct {
// contains filtered or unexported fields
}
LibCollection is a deduplicated collection of dynamically linked libraries and paths they are found at.
func CollectLibsFor ¶ added in v0.12.0
func CollectLibsFor( ctx context.Context, files ...string, ) (LibCollection, error)
CollectLibsFor recursively resolves the dynamically linked shared objects of all given ELF files.
The dynamic linker consumed LD_LIBRARY_PATH from the environment.
func (*LibCollection) SearchPaths ¶ added in v0.12.0
func (c *LibCollection) SearchPaths() iter.Seq[string]