Batamanta.ERTS.LibcDetector (batamanta v1.5.0)

Copy Markdown View Source

Robust libc detection for Linux platforms.

Uses multiple methods in order of reliability to detect whether the system uses glibc or musl libc. This is critical for selecting the correct ERTS build for cross-platform compatibility.

The detector uses these methods in order:

  1. ldd --version - Most reliable for runtime detection

  2. Dynamic loader check - Most reliable for cross-compile

  3. /etc/os-release - Fallback for known distributions

  4. /proc/self/maps - Advanced fallback

    iex> Batamanta.ERTS.LibcDetector.detect() :gnu

    iex> Batamanta.ERTS.LibcDetector.detect() :musl

Summary

Functions

Returns a human-readable description of the detected libc.

Detects the libc type of the current system.

Detects libc by running ldd --version.

Detects libc by checking for dynamic loader files.

Detects libc by reading /etc/os-release.

Detects libc by reading /proc/self/maps.

Validates that the detected libc matches an expected target.

Types

libc_type()

@type libc_type() :: :gnu | :musl | :unknown

Functions

describe(libc_type)

@spec describe(libc_type()) :: String.t()

Returns a human-readable description of the detected libc.

detect()

@spec detect() :: :gnu | :musl

Detects the libc type of the current system.

Returns :gnu for glibc-based systems (Debian, Ubuntu, Arch, Fedora, etc.) or :musl for musl-based systems (Alpine, Void Linux, etc.).

Always returns either :gnu or :musl - never :unknown (uses fallback).

iex> Batamanta.ERTS.LibcDetector.detect()
:gnu

detect_by_ldd()

@spec detect_by_ldd() :: libc_type()

Detects libc by running ldd --version.

This is the most reliable method for runtime detection on the current system.

detect_by_loader()

@spec detect_by_loader() :: libc_type()

Detects libc by checking for dynamic loader files.

This method works even when ldd is not available, making it suitable for cross-compilation scenarios.

detect_by_os_release()

@spec detect_by_os_release() :: libc_type()

Detects libc by reading /etc/os-release.

This method works for known distributions but may fail for custom builds.

detect_by_proc_maps()

@spec detect_by_proc_maps() :: libc_type()

Detects libc by reading /proc/self/maps.

Advanced method that checks which libc is loaded in memory.

validate!(detected_libc, expected_target)

@spec validate!(libc_type(), atom()) :: :ok | no_return()

Validates that the detected libc matches an expected target.

Returns :ok if they match, or an error tuple with details.