LinuxCommandLibrary

elfedit

Modify ELF file metadata

SYNOPSIS

elfedit [OPTION...] INPUT [OUTPUT]

PARAMETERS

-h, --help
    Display short help text and exit

-V, --version
    Print version information and exit

--input-section=NAME
    Input section name. Multiple uses allowed for several sections

--output-section=NAME[::TYPE[::FLAGS[::ENT_SIZE]]]
    Output section spec; empty NAME removes. TYPE/FLAGS/ENT_SIZE optional numerics or 'note'/'null'

--keep-section[=NAME]
    Keep unmatched sections; no NAME keeps all except input/output

--force-output-section
    Create output section even without matching input

DESCRIPTION

elfedit is a command-line tool from the elfutils package designed for straightforward modifications to ELF (Executable and Linkable Format) files, common in Linux for executables, shared libraries, object files, and core dumps. It copies specified input sections to output sections, allowing renaming, type changes, flag adjustments, or removal via empty output names. Ideal for tasks like stripping build-ID notes for reproducible builds, removing debug sections, or tweaking ABI tags.

By default, elfedit discards unspecified sections, preserving only edited ones. Use --keep-section to retain others. It's efficient for build automation, faster than binutils tools like objcopy for simple edits, but limited to section-level changes—no symbol table or relocation edits. Requires specifying sections precisely; errors can corrupt files. Install via elfutils package on most distros.

CAVEATS

Destructive if OUTPUT omitted (overwrites INPUT); backups essential. Limited to section copies/modifications—no relocation/symbol edits. Corrupts files on invalid specs. Not for dynamic changes.

EXAMPLE: REMOVE BUILD-ID

elfedit --input-section=.note.gnu.build-id --output-section='' input.o output.o
Removes note, discards other sections.

EXAMPLE: RENAME SECTION

elfedit --input-section=.debug_info --output-section=.debug_info.new input.o output.o
Renames while keeping only this edit (use --keep-section=* to preserve others).

HISTORY

Developed in elfutils project by Joseph Jahner (2008, v0.142); maintained by Red Hat. Evolved for build toolchains, focusing on reproducible binaries.

SEE ALSO

eu-readelf(1), readelf(1), objcopy(1), strip(1), eu-strip(1)

Copied to clipboard