Documentation
¶
Overview ¶
Package native tells native files - ELF and Mach-O binaries - by their content, and reports what they need to run: the platforms they run on and, for an ELF program, the loader and the shared libraries it asks for.
tt package pack labels an archive with the platform its native files pin it to, and tt package build checks that what a component built into .rocks/bin/ is a program of the platform it built for, static when the manifest asks for that. Both read a file the same way, so the detector lives here rather than in either of them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotNative = errors.New("not an ELF or Mach-O file")
ErrNotNative is wrapped by InspectProgram's error for a file that is neither ELF nor Mach-O.
Functions ¶
Types ¶
type File ¶
type File struct {
// Name is the file's path relative to the tree, slash-separated.
Name string
// Platforms lists the platforms the file runs on: one for a thin binary,
// one per slice for a universal Mach-O.
Platforms []Platform
}
File is a native file of a tree: an ELF or Mach-O file, whatever its name.
func Files ¶
Files lists every native file under root, in lexical order, with the platforms each runs on. It does not judge them: the caller compares them with the platform it packs for.
The whole tree is looked at. For an archive that is the [package].include payload, .rocks/ and _runtime/ alike, and the bundled runtime is no exception: the runtime cache has no platform in its layout, so a build of another platform placed there would otherwise travel under the host's label.
type Platform ¶
Platform is an operating system and CPU architecture pair, spelled the way Go spells GOOS and GOARCH. For the four supported pairs its String form is the archive's platform token: linux-amd64, linux-arm64, darwin-amd64, darwin-arm64.
func FilePlatforms ¶
FilePlatforms reports the platforms the file at path runs on, reading only its header. A file that is neither ELF nor Mach-O - Lua, a shebang script, text - is not native and yields nil, and so does one that only starts like a binary and is too short or malformed to be one.
type Program ¶
type Program struct {
// Platforms lists the platforms the program runs on, as FilePlatforms
// reports them.
Platforms []Platform
// Executable reports that a process can be started from the file: an ELF
// executable or position-independent executable, or a Mach-O executable
// in every slice. A shared library, an object file or a core dump is
// native, but not a program.
Executable bool
// Interpreter is the dynamic loader an ELF program names (PT_INTERP);
// empty when it names none.
Interpreter string
// Needed lists the shared libraries the program asks the loader for
// (DT_NEEDED of an ELF program, the dylibs of a Mach-O one).
Needed []string
}
Program describes a native program: the platforms it runs on, whether a process can be started from it, and, for an ELF one, what the system has to supply when it is loaded.
Unlike Files and FilePlatforms, which only read the header, InspectProgram reads the program headers and the dynamic segment too. That is fine for the few files a build declares its output, not for every file of an archive.
func InspectProgram ¶
InspectProgram reads what the native file at path is as a program. A file that is neither ELF nor Mach-O is an error wrapping ErrNotNative.
func (Program) Static ¶
Static reports whether the program needs no loader or shared libraries beyond the base libraries of every platform it runs on.
A static-pie program, which Rust builds for a musl target, has a dynamic segment of its own - it relocates itself - so the dynamic segment is not what tells a dynamic program; the loader and the libraries are.