package module
Version: v1.3.2 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2023 License: BSD-3-Clause Imports: 8 Imported by: 4



GoDoc License Go Report Card

Go package for figuring out which compiler and compiler version was used for compiling an executable file for Linux (in the ELF format).

Utilities that uses Ainur
Features and limitations
  • Supports detection of compiler name and version if an executable was built with one of these compilers:
    • GCC
    • Clang
    • FPC
    • OCaml
    • Go
    • TCC (compiler name only, TCC does not store the version number in the executables)
    • Rust (for stripped executables, only the compiler name and GCC version used for linking)
    • GHC
  • Works even with stripped executables.
  • Should work for recent versions of all of the above compilers. Executables produced with old versions of the compilers may need more testing.
General info
  • Version: 1.3.2
  • Author: Alexander F. Rødseth <>
  • License: BSD-3



Package ainur provides functions for examining ELF files



This section is empty.


View Source
var (
	GHCVersionRegex   = regexp.MustCompile(`GHC\ (\d{1,4}\.)(\d+\.)?(\d+)`)
	GoVersionRegex    = regexp.MustCompile(`go(\d+\.)(\d+\.)?(\*|\d+)`)
	PasVersionRegex   = regexp.MustCompile(`FPC\ (\d+\.)?(\d+\.)?(\*|\d+)`)
	OcamlVersionRegex = regexp.MustCompile(`(\d+\.)(\d+\.)?(\*|\d+)`)
	GCCVersionRegex0  = regexp.MustCompile(`(\d+\.)(\d+\.)?(\*|\d+)\ `)
	GCCVersionRegex1  = regexp.MustCompile(`\) (\d{1,4}\.)(\d+\.)?(\*|\d+)\ `)
	GCCVersionRegex2  = regexp.MustCompile(` (\d{1,4}\.)(\d+\.)?(\*|\d+)`)
	GCCVersionRegex3  = regexp.MustCompile(`(\d{1,4}\.)(\d+\.)?(\*|\d+)`)
	GCCVersionRegex4  = regexp.MustCompile(`\) (\d{1,4}\.)(\d+\.)?(\*|\d+).(\d+)`)


func Compiler

func Compiler(f *elf.File) string

Compiler takes an *elf.File and tries to find which compiler and version it was compiled with, by probing for known locations, strings and patterns.

func DVer added in v1.0.3

func DVer(f *elf.File) (ver string)

DVer returns "DMD" if it is detected Example output: "DMD"

func Describe added in v1.0.1

func Describe(m elf.Machine) string

Describe returns a descriptive string for a given elf.Machine

func Examine

func Examine(filename string) (string, error)

Examine tries to discover which compiler and compiler version the given file was compiled with.

func ExamineStatic added in v1.2.0

func ExamineStatic(filename string) (bool, error)

ExamineStatic examines a given filename and returns true if is statically linked (does not have PT_DYNAMIC in one of the prog headers)

func FirstIsGreater

func FirstIsGreater(a, b string) bool

FirstIsGreater checks if the first version number is greater than the second one. It uses a relatively simple algorithm, where all non-numbers counts as less than "0".

func GCCVer

func GCCVer(f *elf.File) (ver string)

GCCVer returns the GCC compiler version or an empty string example output: "GCC 6.3.1" Also handles clang.

func GHCVer added in v1.1.0

func GHCVer(f *elf.File) (ver string)

GHCVer returns the GHC compiler version or an empty string example output: "GHC 8.6.2"

func GoVer

func GoVer(f *elf.File) (ver string)

GoVer returns the Go compiler version or an empty string example output: "Go 1.8.3"

func MustExamine

func MustExamine(filename string) string

MustExamine does the same as examine, but panics instead of returning an error

func MustExamineStatic added in v1.2.0

func MustExamineStatic(filename string) bool

MustExamineStatic does the same as ExamineStatic, but panics instead of returning an error

func OCamlVer

func OCamlVer(f *elf.File) (ver string)

OCamlVer returns the OCaml compiler version or an empty string example output: "OCaml 4.05.0"

func PasVer

func PasVer(f *elf.File) (ver string)

PasVer returns the FPC compiler version or an empty string example output: "FPC 3.0.2"

func RustVerStripped

func RustVerStripped(f *elf.File) (ver string)

RustVerStripped returns the Rust compiler version or an empty string, from a stripped Rust executable. Does not contain the Rust version number. Example output: "Rust (GCC 8.1.0)"

func RustVerUnstripped

func RustVerUnstripped(f *elf.File) (ver string)

RustVerUnstripped returns the Rust compiler version or an empty string example output: "Rust 1.27.0"

func Static added in v1.2.0

func Static(f *elf.File) bool

Static checks that PT_DYNAMIC is not in one of the prog headers of the ELF file

func Stripped added in v1.0.2

func Stripped(f *elf.File) bool

Stripped returns true if symbols can not be retrieved from the given ELF file

func TCCVer

func TCCVer(f *elf.File) (ver string)

TCCVer returns "TCC" or an empty string TCC has no version number, but it does have some signature sections.


type StreamReader added in v1.3.2

type StreamReader struct {
	// contains filtered or unexported fields

StreamReader is intended to be used to search in a streaming manner.

func NewStreamReader added in v1.3.2

func NewStreamReader(r io.Reader, bufferSize int) (*StreamReader, error)

NewStreamReader creates a new StreamReader.

func (*StreamReader) Next added in v1.3.2

func (r *StreamReader) Next() ([]byte, error)

Next reads the next half byte buffer from the stream. The reason for reading half is so that we can build something like:

tail my-file | grep "something"

Where "something" may be between two reads.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL