LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

elfedit

Update ELF file headers and x86 feature notes

TLDR

Change the machine type of an ELF file
$ elfedit --output-mach x86-64 [path/to/file]
copy
Change the machine type only when it already matches
$ elfedit --input-mach i386 --output-mach iamcu [path/to/file]
copy
Change the file type to relocatable, executable, or shared object
$ elfedit --output-type [rel|exec|dyn] [path/to/file]
copy
Change the OS ABI
$ elfedit --output-osabi [FreeBSD] [path/to/file]
copy
Set the ABI version (0 through 255)
$ elfedit --output-abiversion [0] [path/to/file]
copy
Enable an x86 feature note
$ elfedit --enable-x86-feature ibt [path/to/file]
copy
Disable an x86 feature note
$ elfedit --disable-x86-feature shstk [path/to/file]
copy
Show help
$ elfedit -h
copy

SYNOPSIS

elfedit [options] elffile...

DESCRIPTION

elfedit updates fields in the ELF header, and on builds that support it, x86 feature bits in the GNU property note. It is part of GNU binutils.Pass at least one output option or one x86-feature option. Input options only narrow which files are changed. 32-bit and 64-bit ELF files are accepted, including ELF members inside archives.The machine name x86-64 is the form to type. The same parser also accepts the underscore spelling.Feature options are compiled in when binutils was built with mmap support. A build without them rejects those flags.

PARAMETERS

--input-mach machine

Match only files whose ELF machine is machine. Without this option, every machine matches. Names are case-insensitive. Accepted names include none, i386, iamcu, l1om, k1om, and x86-64.
--output-mach machine
Write machine into the ELF header. Same names as --input-mach.
--input-type type
Match only files of this ELF type. Without this option, every type matches. Names: none, rel, exec, dyn.
--output-type type
Write type into the ELF header. Same names as --input-type.
--input-osabi osabi
Match only files with this OS ABI. Without this option, every OS ABI matches. Names are case-insensitive. Linux is an alias of GNU. elfedit --help prints the names that build accepts. The binutils manual documents none, HPUX, NetBSD, GNU, Solaris, AIX, Irix, FreeBSD, TRU64, Modesto, OpenBSD, OpenVMS, NSK, AROS, and FenixOS.
--output-osabi osabi
Write osabi into the ELF header. Same names as --input-osabi.
--input-abiversion 0-255
Match only files with this ABI version.
--output-abiversion 0-255
Write this ABI version into the ELF header.
--enable-x86-feature feature
Turn on one x86 feature in the GNU property note. Enabling a feature clears it from the disable mask. Tokens are exact:
$ ibt
copy
$ shstk
copy
$ lam_u48
copy
$ lam_u57
copy
--disable-x86-feature feature
Turn off one x86 feature. Same tokens as --enable-x86-feature. Disabling a feature clears it from the enable mask.
-h, --help
Show help and exit.
-v, --version
Show the version and exit.
@file
Read more options from file. The file may itself contain @file options.

INSTALL

sudo apt install binutils
copy
sudo dnf install binutils
copy
sudo pacman -S binutils
copy
sudo apk add binutils
copy
sudo zypper install binutils
copy
brew install binutils
copy
nix profile install nixpkgs#binutils
copy

CAVEATS

Changing the machine, type, or OS ABI does not rewrite the rest of the file. A header that no longer matches the body will not load.Feature names have no hyphen alias. Type them exactly, inside a context that does not treat underscores as emphasis.

SEE ALSO

readelf(1), objcopy(1), objdump(1), strip(1)

RESOURCES

Copied to clipboard
Kai