SUBMIT A FILE TYPE CONTACT US SUPPORT ABOUT US

What Is an ELF File? The Linux Program Format, and How to Open and Check One

ELF files are the programs of Linux, and a program that starts is not always a program that is right. Jump to your question below, or work through it in order.

42 min read Updated October 2026 Checked against sources and tests

What Is an ELF File? A program format, and not a document

Short answer

An ELF file is a program, a shared library, an object file or a core dump in the Executable and Linkable Format. Linux and most Unix systems start their programs from ELF files. One header names the chip, and the ELF file needs no ending.

We built 8 ELF files, made 32 damaged copies of one program and tested five readers, Linux and a 75 line script. Linux refused 17 copies, and for 6 of them no reader said a word.

To open ELF files, read how to open ELF files. To check one, read the header check. If yours will not start, begin with the ten causes.

An ELF file is a program, a shared library, an object file or a core dump in the Executable and Linkable Format. Linux and most Unix systems use it for the programs they start. The name belongs to the format and not to one program, and most ELF files have no ending at all.

Picture a developer with a build folder. It has firmware.elf, the library libtriple.so and the program hello, which has no ending. All three are ELF files. Double click any of them on Windows and nothing happens. An ELF file is not a document. It is a set of instructions for one chip and one system.

Wikipedia says Unix System Laboratories designed the format, and that it first appeared in the System V Release 4 specification. In 1999 the 86open project chose it as the common binary format for Unix systems on x86 chips. It replaced the older a.out and COFF formats on Unix like systems.

Linux is the best known user. On our Ubuntu 24.04 test machine, 869 of the 1,233 files in /usr/bin start with the ELF signature, and 364 start with #! because they are scripts. Of those 869 ELF files, 850 are type DYN and only 19 are type EXEC. The four kinds explain why.

Other systems use ELF files too. FileInfo lists three kinds of .elf file, the Linux format, Nintendo Wii games and Sony PlayStation executables. Wikipedia adds Android libraries, firmware for Atmel AVR chips and the PlayStation Portable. Windows starts ELF files only through its Linux subsystem.

Two claims that circulate online need a fix. An ELF file is not tied to one chip. The header names the chip, and the 12 test headers we made named 12 different chips. And an ELF file is not always a program, because object files and core dumps use the same format.

Who sends you ELF files

ELF files come from build servers, package archives, embedded boards, game modders and crash reports. Malware analysts and forensic examiners get them too. If an ELF file reaches you from a source you do not know, treat it as a program that can do anything its user can do. Read the safety section first.

Three questions start most readers off. Will the ELF file start on your computer? It must match your chip and your system. Is the ELF file complete? Only a header check says so, and our damage tests show how often readers miss a problem. Is it a program at all? The four types decide.

ELF file facts at a glance

Quick facts about ELF files
Property Value
Meaning A file in the Executable and Linkable Format. It stores a program, a library, an object file or a core dump.
Ending .elf, .so, .o, .ko, .axf and more, or no ending at all.
Made by Compilers and linkers like gcc and ld. Unix System Laboratories designed the format.
Starts with 7f 45 4c 46, which is the byte 7f and the letters ELF.
Stores Code, data, symbols and two header tables that describe them.
Kinds Four: object (REL), program (EXEC), shared object (DYN) and core dump (CORE).
MIME type None for .elf in the four databases we checked.
Opens in Linux starts programs. readelf, objdump, file, pyelftools and LIEF read all kinds.
Safe to open Reading an ELF file with a tool is safe. Starting a program from an unknown ELF file is not.

Wrong page? A Windows program ends in .exe and has its own EXE file guide. Debian packages that contain ELF files are DEB files, and Mac disk images are DMG files.

What Is Inside an ELF File? A header and two tables that Linux and tools read

An ELF file is a header, a table of program headers, a body and a table of section headers. Linux starts programs from the first two and the body. Tools like readelf list the sections. Our 16,000 byte test program has 13 program headers and 31 section headers.

The first 64 bytes are the ELF header. In our test program they begin 7f 45 4c 46 02 01 01 00. That says ELF, 64 bit, little endian and version 1. The next listing shows the first 64 bytes of the ELF file.

The first 64 bytes of our test program
00000000: 7f45 4c46 0201 0100 0000 0000 0000 0000  .ELF............
00000010: 0300 3e00 0100 0000 6010 0000 0000 0000  ..>.....`.......
00000020: 4000 0000 0000 0000 c036 0000 0000 0000  @........6......
00000030: 0000 0000 4000 3800 0d00 4000 1f00 1e00  ....@.8...@.....

The same bytes make more sense when readelf lists them. Debian's elf(5) page describes the same fields. The listing shows a 64 bit program for an x86 64 chip. It starts at address 0x1060.

Output of readelf on the header
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              DYN (Position-Independent Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x1060
  Start of program headers:          64 (bytes into file)
  Start of section headers:          14016 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         13
  Size of section headers:           64 (bytes)
  Number of section headers:         31
  Section header string table index: 30
A stack of four blocks for one 16,000 byte ELF file. The ELF header takes bytes 0 to 63. The program header table follows with 13 entries of 56 bytes. The body contains the code and data. The section header table begins at byte 14,016 with 31 entries of 64 bytes. A bracket marks the program headers and the body as what Linux needs to start the program, and a second bracket marks the section headers as what tools use to read it.
One ELF program from our tests. Linux starts it from the program headers, and tools read it from the section headers.
Fields in the header of an ELF file
Offset Meaning and what we saw
0 The signature 7f 45 4c 46. It is the byte 7f and the letters ELF. All 8 good files we built start with it.
4 The class. 2 means 64 bit and 1 means 32 bit. Our program reads 2.
5 The byte order. 1 means little endian and 2 means big endian. Our program reads 1.
16 The type. 1 is an object file, 2 a fixed address program, 3 a shared object or modern program and 4 a core dump. Ours reads 3.
18 The chip. Our value 0x3e means x86 64. We made headers for 12 chips, from AVR to IBM S/390.
24 The entry point, the first address that Linux jumps to. Ours is 0x1060.
32 Where the program header table starts. Ours is at byte 64, right after the header.
40 Where the section header table starts. Ours is at byte 14,016, near the end.
52 The sizes. The header takes 64 bytes. Program header entries take 56 bytes and we have 13. Section header entries take 64 bytes and we have 31.

The System V ABI draft is the formal source. Its chapters cover the header, the program headers, the sections and loading with dynamic linking.

What the two tables do

The program header table describes segments. A segment is a block of the ELF file that Linux maps into memory. Our program has 4 load segments. One is code, two are read only data and one is data that can change. A segment named INTERP names the loader, which here is /lib64/ld-linux-x86-64.so.2.

The section header table describes sections. A section is a named part of the ELF file, like .text for code, .data for data and .symtab for symbols. Linkers and debuggers use sections. elf(5) says program headers matter for programs and shared objects, and that the section table lets you find every section.

Our tests show the split. All six copies with damaged section headers started, and all five copies with damaged program headers failed. The start test lists them.

What the header does not show

The header does not store the ELF file size or a checksum. An ELF file cut after its last segment still starts with a good header. Our copy cut by 2,000 bytes lost its section table and still printed its text. Headers are maps and not seals.

Bytes are not sections. Every byte of an ELF file can belong to a segment, a section, both or neither. Our 16,000 byte program has 31 sections, and 4 load segments cover most of the same bytes from the other side.

Which Kind of ELF File Do You Have? Object, program, library or crash dump

ELF files come in four kinds. REL is an object file, EXEC is a program with a fixed address, DYN is a shared library or modern program, and CORE is a crash dump. The type is one number at byte 16, and Linux starts only EXEC and DYN files.

The type matters more than the ending. libtriple.so and hello_pie are both DYN, and only hello_pie has a loader and an entry point that Linux can use. The table lists the four types with the ELF file we built for every type.

The four kinds of ELF file
Type What it is and what we built
REL An object file. A compiler makes it from one source file, and a linker joins it with others. It has no program headers. Our ELF file: hello.o, 1,608 bytes, 14 sections, and Linux says Exec format error.
EXEC A program with a fixed load address. Older programs and static ones use it. Our ELF files: hello_exec at 15,904 bytes with 13 program headers, and hello_static at 785,352 bytes with 10 program headers and no loader.
DYN A shared object, which is a .so library, or a position independent program. Our ELF files: libtriple.so at 15,112 bytes and hello_pie at 16,000 bytes. Both are DYN, and file calls them a shared object and a pie executable.
CORE A core dump, which copies a crashed process. It has program headers and no sections. Our ELF file: core_dump from a program that wrote to address 0, 348,160 bytes, 24 program headers and 0 sections.
Six ELF files from our tests with two bars apiece. Bars show the count of program headers and section headers. The object file hello.o has 0 program headers and 14 section headers. The shared library has 11 and 25, the fixed address program has 13 and 31, the position independent program has 13 and 31, the static program has 10 and 28 and the core dump has 24 and 0.
Program headers and section headers in six files we built. A file needs program headers to start and section headers only to be linked or studied.

The figure draws what the table cannot. The bars count the program headers and the section headers. The object file has no program headers, and the core dump has no section headers. Both show that the two tables serve different jobs.

Is it a program or a library

Modern Linux makes most programs type DYN, so they can load at a random address. That is why 850 of the 869 ELF files in our /usr/bin are DYN. A shared library is also DYN. The type alone does not separate them. A loader path in the INTERP segment points to a program, and our library has none.

We tried to start libtriple.so with the execute permission set. It ended with signal 11, which is a crash, because it is a library and not a program. We tried hello.o and the core dump the same way, and both got Exec format error.

What a static program changes

hello_static is the same program linked with its libraries inside. It is 785,352 bytes, against 16,000 for hello_pie. It has no INTERP segment, so no loader is needed, and ldd says not a dynamic executable. It started without any library on the system.

What stripping removes

Stripping removes the symbols. Our stripped copy of hello_pie is 14,472 bytes, which is 1,528 less. It has 29 sections instead of 31, and nm finds no symbols in it. It started and printed the same text. Stripping changes what a debugger can see and not what Linux starts.

Where Do You Meet ELF Files? Linux, firmware, Android and game consoles

You meet ELF files as Linux programs and libraries, as object files, as kernel modules, as crash dumps, as firmware builds and as console games. The ending alone does not say which one you have. The first four bytes and the type decide.

The ending says little. Programs have none, libraries end in .so and the same extension can hide Wii games, PlayStation programs or firmware images. The table lists the ELF files we met and the facts we could check.

Where ELF files come from
Kind What it is
Linux programs Most programs on Linux are ELF files with no ending. 869 of the 1,233 files in our /usr/bin are, and 130 of the 186 in /usr/sbin. Source: Our test machine.
Shared libraries Files ending in .so. In our /usr/lib/x86_64-linux-gnu folder, 822 of the 826 files with .so in the name start with the ELF signature. Source: Our test machine.
Object files Files ending in .o, the output of a compiler before linking. Source: Our tests.
Kernel modules Files ending in .ko. Wikipedia lists the ending among ELF files. We had none to test. Source: Wikipedia.
Core dumps Crash copies of a process, often called core. Our core dump is type CORE. Source: Our tests.
Firmware builds Embedded tool chains write .elf files, and Arm tools use .axf. Wikipedia lists AVR and MSP430 among the chips. Source: Wikipedia.
Game consoles .elf files store programs for the Wii and PlayStation, per FileInfo. Wikipedia lists more consoles. Source: FileInfo and Wikipedia.
Android Native libraries in Android apps are .so ELF files. Since Android 5.0, apps compile to native ELF code at install, per Wikipedia. Source: Wikipedia.

Same ending, different file

the FileInfo entry lists three kinds under .elf. One is the Linux format, one is a Nintendo Wii game file and one is a PlayStation executable. Filext adds Samsung camera firmware that arrives as an ELF file. We had no sample of any console or camera file, so these are the sites' claims.

Open the first bytes before you trust a story about the ending. Any file with 7f 45 4c 46 at byte 0 is in the format, whatever the ending says. Files that start with other bytes are not, and our check script tests that in its first line.

What the databases say about the ending

We looked up .elf and its neighbours in four file type lists. They are Debian media-types 10.1.0, shared-mime-info 2.4, Python mimetypes and mime-db 1.54.0. A media type names the file for browsers and servers, and a missing one means a download with no label.

What four databases list
Ending Result
.elf None of the four lists it. shared-mime-info names ELF files by their first bytes instead.
.so shared-mime-info lists application/x-sharedlib. Python and mime-db list octet-stream.
.o Debian, shared-mime-info and Python list application/x-object. mime-db lists none.
.ko, .axf and .out None of the four lists them.

A download is not a program. No list gives .elf a type, so browsers save the ELF file and show nothing. That is also good news, because servers that offer ELF files for download do not start them.

What Did We Find in 32 Damaged ELF Files? Five readers stayed silent on 6 of the 17 that Linux refused

We built 8 good ELF files and made 32 damaged copies of one program. Linux refused 17 copies. Five readers flagged from 1 to 19 copies apiece, and no reader flagged 6 of the 17 that Linux refused. A 75 line script found 14 of the 17.

We wanted facts and not guesses, so we built the files ourselves. We compiled a 3 line C program with gcc 13.3.0 on Ubuntu 24.04. It adds two numbers and prints hello 5.

We made 8 good ELF files from it and from two other tiny programs. They are one object file, one shared library, the fixed address, position independent, static and stripped programs, the crash program and its core dump.

Then we damaged one 16,000 byte program in 32 ways, in six groups. We changed identity bytes, header fields, program headers, section headers, the end of the ELF file and bytes in the body. We started every copy as an ordinary user on Linux 6.18, and we checked the exit code and the output.

8 good ELF files we built
32 damaged copies of one program
17 of 32 copies that Linux refused to start
6 of 17 refused copies that no reader flagged
What the tools did with 32 damaged ELF files
Test Result
The file command Named all 8 good files and all 12 test headers by their first bytes. It flagged 7 of 32 damaged copies and printed only data for the zeroed signature.
readelf 2.42 Flagged 19 of 32 copies with a warning or an error. It flagged more than any other reader, and 11 of its 19 were copies that Linux refused.
objdump 2.42 Flagged 14 of 32 copies. It said file format not recognized for 12 of them and never says why. Two got a warning about a corrupt string table index.
pyelftools 0.33 Failed on 13 of 32 copies with an exception. Its messages name the field or the offset that failed, like a too small e_phentsize or a read past the end of the ELF file.
LIEF 1.0.0 Failed on 1 copy, the zeroed signature. It returned an object for the other 31, even a file cut to 63 bytes. We turned its own warnings off, so this counts failures only.
Our script Flagged 23 of 32 copies, skipped 2 and passed 7. It flagged 14 of the 17 copies that Linux refused.
Linux 6.18 Started 15 of 32 copies, one of them with changed text. It refused 17, with 9 Exec format errors, 5 crashes, 2 illegal instructions and 1 missing loader.
A grid of thirty two kinds of damage made in one ELF program, in six groups, against seven checks. Five readers and our script either flag the damage or stay silent, and Linux either starts the program, fails to start it or starts it with changed output. Linux failed to start 17 copies. Six of those showed no problem in any of five readers. Linux started 14 copies, and ten of those were flagged by at least one reader. One copy started and printed changed text with no reader and no script noticing.
Thirty two kinds of damage in one ELF program, against five readers, our script and Linux itself. Green means a check noticed the damage.

Read the grid by column. A reader that is silent about a copy is not wrong about the bytes it parsed. It describes the ELF file as written, and it does not start the program. Only the Linux column says if the ELF file works, and only the readers and the script say why.

Where the readers disagree

Three readers flagged 20 copies in all, and only 12 of them drew a flag from all three. Six copies were flagged by one reader alone. One reader is not a verdict, so use readelf and one library when a result matters.

Eleven copies drew no flag from any of the five readers. Six of them were refused by Linux, and five started. The five were the changed OS ABI byte, the header size field of 16, the section table offset of 0, the 4,096 junk bytes and the changed word of text.

Why a valid header can still fail

Two refused copies look fine to every reader. One has its type set to EXEC, which is valid for programs built for fixed addresses. This one was built to move, so it crashed. The other has its chip set to AArch64. That is valid for AArch64 programs, and it cannot start on x86 64 chips.

Both readers and Linux are right. The problem lies between the ELF file and your computer. That is why the start test begins with your chip and not with the bytes.

What the headers of 12 chips showed

We made one small header per chip, 12 in all. The chips were x86, x86 64, Arm 32 bit, AArch64 and RISC V 64 bit. The rest were MIPS, SuperH, PowerPC 32 and 64 bit, IBM S/390, SPARC V9 and AVR.

The file command named all 12 and gave the word size and the byte order. readelf named all 12 machines. The format is not tied to one chip.

Program headers decide the start All 5 copies with damaged program headers failed to start, as 3 Exec format errors and 2 crashes. A reader may stay silent, but Linux does not.
Section headers are optional for a start All 6 copies with damaged or missing section headers started and printed their text. Debuggers need the table and Linux does not.
Readers can pass a broken program No reader flagged 6 of the 17 copies that Linux refused. Our script flagged 14 of the 17.
A start is not proof One copy printed jello 5, and no reader or script noticed. A copy with 4,096 junk bytes added also passed every check. Both are still valid ELF files.

Read the study with care. It shows what five readers and one kernel do with our copies. All 32 come from one small x86 64 program, so they show what can happen and not how common it is. We started no 32 bit file, no Arm file and no console file, and we used no Windows tool.

What Does Our Expert Say About ELF Files? A note from Neeraj Singh on reading the headers first

Read the headers before you start an ELF file. It takes a second, and it shows if the ELF file matches your chip, has its program headers and names a loader that exists. Starting the ELF file is the last step and not the first.

Neeraj Singh

Expert insight

“An ELF file is a program, so the first question is who made it. In our tests, six damaged copies stopped Linux while five readers said nothing, and one copy started and printed the wrong text. Read the headers first, and start an ELF file you do not trust only inside a sandbox.”

Neeraj Singh Manager, Tech Support & Operations 19+ years fixing Windows and system errors

Why the headers come first

Most readers describe a broken ELF file without a warning. All five of ours stayed silent about the copy whose entry point moved by 2 bytes, and Linux stopped it with an illegal instruction. A header check is the one step that names bad loader paths and entry points outside the code, and the check script does both.

The headers matter for a second reason. Programs that start are not programs you can trust. An ELF file can do everything its user can do, and the headers do not say what the code will do. Without a sandbox, an unknown ELF file is a risk.

The check has a limit, and the damage tests show it. A pass proves that the headers agree with one another and with your computer. It does not prove that the code is what its maker wrote. One copy with a changed word of text passed everything.

Save the original. Keep the first copy of every ELF file you receive in a place nobody edits, and write down its SHA256 hash. Work on a second copy. Only the hash proves that the file you checked is the file you got.

How Do You Open ELF Files? Linux, readers and Python

Open ELF files with Linux if you need the program, and with a reader if you need to see inside. Tools like file, readelf, objdump and the Python module pyelftools read any ELF file without starting it. Windows and Mac do not start Linux programs.

the FileInfo listing lists elfutils, ELFDump and readelf for the Linux kind of file, and emulators for the console kinds. We tested on Linux, so the table marks what we tested and what we did not. Reading an ELF file and starting one are different jobs, and the next sections cover both.

Programs that open ELF files
Program What it does
Linux Starts EXEC and DYN files built for its chip, once the ELF file has the execute permission. It started all 4 good programs we built.
file Names the kind, the chip, the word size and the loader from the first bytes. It named all 8 good files and 12 of 12 test headers.
readelf Lists the header, the segments, the sections and the symbols of any ELF file without starting it. Part of GNU Binutils 2.42.
objdump Lists headers and the libraries a file needs with -p, and shows code with -d. Part of GNU Binutils 2.42.
nm Lists the symbols in a file. It found none in our stripped program.
pyelftools A Python module that reads the headers, sections and segments. It works on Windows, Mac and Linux, because it only reads.
LIEF A library for Python and C++ that parses ELF files and can write changes. It returned an object for 31 of our 32 damaged copies.
Windows Does not start ELF files. Windows uses ELF only through its Linux subsystem, as Wikipedia says. Readers like pyelftools still work there.
Dolphin, PCSX2 and RPCS3 Emulators that FileInfo lists for Wii and PlayStation .elf files. We did not test them.

Open ELF files on Linux

Give the ELF file the execute permission with chmod +x and start it by its path. Without the permission, bash says Permission denied. Start with the commands below, because they read the ELF file and do not start it.

Read an ELF file before you start it
file hello_pie
readelf -h hello_pie
readelf -lW hello_pie
readelf -SW hello_pie
objdump -p hello_pie
sha256sum hello_pie

The file command names the kind in one line. Use readelf -h for the header, -l for the segments and -S for the sections. Use objdump -p to list the libraries a program needs.

The next listing is the line file prints for our test program. A fourth option is ldd, and the safety advice explains why we avoid it on files we did not build.

Libraries our test program needs
Dynamic Section:
  NEEDED               libc.so.6

Open ELF files with Python

Install pyelftools with pip install pyelftools. The next script prints the type, the chip and the number of sections and segments, and then the size of five sections. It reads the ELF file and does not start it, so it works on Windows and Mac too.

Read an ELF file with pyelftools
from elftools.elf.elffile import ELFFile
with open('hello_pie', 'rb') as f:
    elf = ELFFile(f)
    print(elf.header['e_type'], elf.header['e_machine'], elf.num_sections(), elf.num_segments())
    for section in elf.iter_sections():
        if section.name in ('.interp', '.text', '.data', '.symtab', '.dynamic'):
            print(section.name, section['sh_size'])

The listing is what it printed for our position independent program. The first line says type DYN and chip x86 64, with 31 sections and 13 segments. The symbol table is the largest named part.

Output of the script
ET_DYN EM_X86_64 31 13
.interp 28
.text 286
.dynamic 496
.data 16
.symtab 888

Open console ELF files

FileInfo says Wii .elf files open in the Dolphin emulator, and that PlayStation ones open in RPCS3 and PCSX2. It also lists an ELF to DOL converter for Wii files. We had no console file and did not test any emulator. Check the emulator's own page for the system you use.

Readers describe, Linux decides. A reader lists what the headers say. Only starting the program shows if it works. Our copy with a changed chip passed all five readers and still failed on Linux, so the cause list starts with your chip.

How Do You Check an ELF File? Read the headers, the loader and the entry point

Check an ELF file with file, readelf or our 75 line script. All three read the headers. They show the type, the chip and the table sizes, and our script also checks that the segments, the loader and the entry point agree.

Start with the signature. Good ELF files begin 7f 45 4c 46, and every good file we built did. Then read the type, the chip and the word size. The next listing is our script on the good program, and every line ends in OK.

The script on a good ELF file
file         good/hello_pie (16000 bytes)
signature    7f 45 4c 46 OK
class        2 64-bit
byte order   1 little endian
ident ver    1 OK
type         3 DYN
version      1 OK
header size  64 OK
prog headers 13 at 64 OK
segments     4 load segments OK
entry point  0x1060 OK
loader       /lib64/ld-linux-x86-64.so.2 OK
sections     31 at 14016 OK
hash         89d9d62546ba841d0d761fb05175a629abfef8ab75e02fecf9e408c1bff93e7a

The script checks what Linux checks, in the same order. The damage test lists the six steps and what broke at every one. Section headers are not a step, so broken section tables only draw warnings.

Check ELF files with Python

The script reads the header and checks the signature, the class, the byte order and the type. Then it checks the program header table, the load segments, the entry point and the loader path. Last it checks the section header table and prints the SHA256 hash. It reads 64 bit little endian files only.

Check ELF files with Python
import os, struct, sys

CLASS = {1: '32-bit', 2: '64-bit'}
DATA = {1: 'little endian', 2: 'big endian'}
TYPE = {1: 'REL', 2: 'EXEC', 3: 'DYN', 4: 'CORE'}


def check(path):
    size = os.path.getsize(path)
    d = open(path, 'rb').read()
    print('file        ', path, '(%d bytes)' % size)
    if len(d) < 64:
        print('size         WRONG, the header needs 64 bytes and the file has', len(d))
        return
    if d[:4] != b'\x7fELF':
        print('signature   ', d[:4].hex(' '), 'WRONG, expected 7f 45 4c 46')
        return
    print('signature   ', d[:4].hex(' '), 'OK')
    cl, da, ver = d[4], d[5], d[6]
    print('class       ', cl, CLASS.get(cl, 'WRONG, expected 1 or 2'))
    print('byte order  ', da, DATA.get(da, 'WRONG, expected 1 or 2'))
    print('ident ver   ', ver, 'OK' if ver == 1 else 'WRONG, expected 1')
    if cl != 2 or da != 1:
        print('rest         skipped, this script checks 64-bit little endian files only')
        return
    (typ, mach, ver2, entry, phoff, shoff, flags, ehsize, phentsize, phnum, shentsize, shnum, shstrndx) = struct.unpack_from('<HHIQQQIHHHHHH', d, 16)
    print('type        ', typ, TYPE.get(typ, 'WRONG, expected 1 to 4'))
    print('version     ', ver2, 'OK' if ver2 == 1 else 'WRONG, expected 1')
    print('header size ', ehsize, 'OK' if ehsize == 64 else 'WRONG, expected 64')
    pbad = 0
    segs = []
    if typ in (2, 3, 4):
        ok = phentsize == 56 and phnum > 0 and phoff + phnum * phentsize <= size
        print('prog headers', '%d at %d' % (phnum, phoff), 'OK' if ok else 'WRONG, the table is missing, the wrong size or past the end')
        if ok:
            for i in range(phnum):
                t, fl, off, va, pa, fs, ms, al = struct.unpack_from('<IIQQQQQQ', d, phoff + i * 56)
                segs.append((t, fl, off, va, fs, ms))
                if t == 1 and (off + fs > size or fs > ms):
                    pbad += 1
            loads = sum(1 for s in segs if s[0] == 1)
            print('segments    ', '%d load segments' % loads, 'OK' if loads and not pbad else 'WRONG, %d reach past the end or have a file size over the memory size' % pbad if pbad else 'WRONG, no load segment')
            interp = [s for s in segs if s[0] == 3]
            ent = any(s[0] == 1 and s[1] & 1 and s[3] <= entry < s[3] + s[5] for s in segs)
            if typ == 2 or (typ == 3 and (entry or interp)):
                print('entry point ', hex(entry), 'OK' if ent else 'WRONG, not inside a segment that can execute')
            if interp:
                s = interp[0]
                p = d[s[2]:s[2] + s[4]].split(b'\0')[0].decode('latin-1')
                print('loader      ', p, 'OK' if os.path.exists(p) else 'MISSING on this computer')
            if typ == 3 and segs and any(s[0] == 1 for s in segs) and [s for s in segs if s[0] == 1][0][3] != 0:
                print('base address', 'first load segment starts at', hex([s for s in segs if s[0] == 1][0][3]), 'unusual for a DYN file')
            if typ == 2 and segs and [s for s in segs if s[0] == 1][0][3] == 0:
                print('base address', 'EXEC file loads at address 0', 'WRONG, EXEC files have a fixed address')
    else:
        print('prog headers', '%d' % phnum, 'WRONG, only EXEC, DYN and CORE files need them' if phnum else 'OK, none in a REL file')
    if shoff == 0 and shnum == 0:
        print('sections    ', 'none (section header table removed or never written)')
    else:
        ok = shentsize == 64 and shoff + shnum * shentsize <= size and shstrndx < shnum
        print('sections    ', '%d at %d' % (shnum, shoff), 'OK' if ok else 'WRONG, the table is past the end or the name index is out of range')
        if ok:
            zero = d[shoff:shoff + shnum * shentsize].count(0) == shnum * shentsize
            if zero:
                print('section data ', 'WRONG, every section header is zero')
    if shoff and shoff < size:
        tail = size - (shoff + shnum * shentsize)
        if tail > 0:
            print('trailing    ', tail, 'bytes after the last header table')
    print('hash        ', __import__('hashlib').sha256(d).hexdigest())


for p in sys.argv[1:]:
    check(p)
    print()

Here is what it printed for three damaged copies. The first has its last 2,000 bytes cut. The second has its program header table zeroed. The third has one letter changed in the loader path.

A copy cut by 2,000 bytes
file         dmg/c24 (14000 bytes)
signature    7f 45 4c 46 OK
class        2 64-bit
byte order   1 little endian
ident ver    1 OK
type         3 DYN
version      1 OK
header size  64 OK
prog headers 13 at 64 OK
segments     4 load segments OK
entry point  0x1060 OK
loader       /lib64/ld-linux-x86-64.so.2 OK
sections     31 at 14016 WRONG, the table is past the end or the name index is out of range
hash         d790bdff670429bef94045a7292e7f8063e039a468facc317f47c36d01868d10
A copy with a zeroed program header table
file         dmg/c29 (16000 bytes)
signature    7f 45 4c 46 OK
class        2 64-bit
byte order   1 little endian
ident ver    1 OK
type         3 DYN
version      1 OK
header size  64 OK
prog headers 13 at 64 OK
segments     0 load segments WRONG, no load segment
entry point  0x1060 WRONG, not inside a segment that can execute
sections     31 at 14016 OK
hash         dfb3f42be784cdf13f75e8df9c37f1a4d3f2019f6d8bfe71012b1a711229ae4b
A copy with a changed loader path
file         dmg/c27 (16000 bytes)
signature    7f 45 4c 46 OK
class        2 64-bit
byte order   1 little endian
ident ver    1 OK
type         3 DYN
version      1 OK
header size  64 OK
prog headers 13 at 64 OK
segments     4 load segments OK
entry point  0x1060 OK
loader       /lib64/ld-linux-x86-64.sX.2 MISSING on this computer
sections     31 at 14016 OK
hash         7c522b333a54ce82fcc0f693841c02583530850b71cc54ee91ed9e4ef8dcd67e

The first listing names the section table as past the end. That copy still started and printed its text, so the warning is true and the program is fine. The second shows no load segment and an entry point outside any code. Linux crashed that copy. The third names a loader that does not exist on this computer.

What the script found in 32 damaged copies

Our script on 32 damaged copies
Result Cases
Flagged, refused (14) The zeroed signature, type EXEC on a position independent file, type REL, type 0xFFFF, entry point 0, five program header changes, three cut files and the changed loader path. Linux refused every one.
Flagged, started (9) Class 0, ident version 0, header version 0, header size 16, four section header changes and the last 2,000 bytes cut. Linux started all nine.
Passed, refused (3) The chip set to AArch64, the entry point moved 2 bytes and the first byte of the entry code flipped. The script cannot know your chip or read the code.
Passed, started (4) OS ABI 255, a section table offset of 0, 4,096 junk bytes and one word of text changed to jello. The first three are harmless, and the last one is a changed program.
Skipped (2) The 32 bit class and the big endian byte order. The script checks 64 bit little endian files only, so it says so and stops. Linux started both.

The script teaches and does not scan for malware. It cannot know your chip, and it cannot read the code. Use it to catch broken headers, a missing loader and an entry point outside the code. Use a sandbox when the question is what programs do.

Check ELF files with readelf and file

file is the fastest check. It flagged 7 damaged copies, like invalid class, unknown arch and invalid version. readelf is the strongest reader, with warnings for 19 copies. Its errors name the header or the offset, so read the first line it prints.

Debian's elf(5) page lists every field readelf prints. Compare the header with the ELF file size too. Our 63 byte copy made readelf say it failed to read the ELF file header. Our 64 byte copy made it say the ELF file is not big enough for its 13 program headers.

A pass is not a promise. A good header means the headers agree with one another and with your computer. It does not mean the code is safe or that the ELF file is the one its maker built. Our changed word of text passed every reader and our script.

Are ELF Files Safe to Open? Reading is safe, and starting a program is not

Reading an ELF file is safe and starting one is not. A reader lists bytes and never starts the code. A program does everything its user can do, so start only ELF files you trust, and use a sandbox for the rest. Never use ldd on an unknown file.

The ending says nothing about safety. An ELF file is a program, and its safety depends on who wrote it. The table lists what to check, and every row ends with its source.

What to check before you open ELF files
Check What to do
The sender Start ELF files only from sources you trust. A program can do everything its user can do. Source: Our advice.
Reading file, readelf, objdump and pyelftools only read bytes. We used all four on 53 files, and every SHA256 hash was the same afterward. Source: Our tests.
Starting Linux starts the code in the ELF file. Files you did not build need a sandbox like a virtual machine with no network. Source: Our advice.
The ldd command ldd can start the program to find its libraries, and Debian's page says never to use it on an untrusted file. Use objdump -p instead. Source: ldd(1).
Library paths LD_LIBRARY_PATH is searched before the system library folders. A library placed there loads first, and our test used it to load libtriple.so from the current folder. Source: ld.so(8).
The execute permission Linux will not start a file without it, and the shell says Permission denied. Adding the permission is the step that makes downloads into programs. Source: Our tests and execve(2).

Why a reader is safer than a start

A reader opens an ELF file and prints what it finds. Linux maps the segments into memory and jumps to the entry point. We checked 53 files before and after file, readelf, objdump and pyelftools. The SHA256 hash of every file was the same.

Use a reader first when you are not sure what an ELF file is. Check the chip, the loader and the libraries before you start anything. Files that need libraries you do not have stop with an error, and the error shows that nothing has started yet.

Why you should check the first bytes

Files that end in .elf can be Wii games or firmware, and files with no ending can be scripts. An ELF file has 7f 45 4c 46 at byte 0, and our 75 line script tests that. Files with other bytes are not ELF files, and file says what they are.

Of the 1,233 files in our /usr/bin, 364 start with #! and are scripts, even though they live beside 869 ELF files. The folder says little, and the first bytes name the kind.

A name is not a promise. Files called update or driver can be any program. Check where one came from, hash it and read its headers before you give it the execute permission. For a Windows installer, read the guide to EXE files first.

Why Will Your ELF File Not Start? Ten causes, and what to do about every one

Most ELF files that will not start fail for one of ten reasons. Check your system and your chip first, then the permission, the library and the loader. A damaged header or a cut copy stops Linux with an Exec format error, and a bad entry point opens fine in every reader.

We damaged one ELF program in 32 ways and started every copy. Linux refused 17. Nine gave Exec format error, five crashed, two hit an illegal instruction and one lost its loader. The other 15 started, and 10 of them drew a flag from a reader.

A flow of six steps that Linux takes to start an ELF program, with the damaged copies that broke every step. Step 1 checks the first four bytes. Step 2 checks the type and the chip. Step 3 reads the program headers. Step 4 maps the load segments. Step 5 finds the loader. Step 6 jumps to the entry point. The section headers are not read at any step, and all six copies with damaged section headers still started.
Six steps that Linux takes to start an ELF file, and what broke at every step in our tests. Section headers are not one of the steps.

Read the red boxes slowly. Section headers are not a step at all. All six copies with damaged section headers started. The damage that stops Linux lies in the first bytes, the program headers and the entry point. A reader that says nothing about those parts is not looking at what Linux reads.

Ten causes of ELF files that will not start
Cause Result and fix
The wrong system (1) Windows starts ELF files only through its Linux subsystem, and macOS uses Mach-O files, per Wikipedia. A double click does nothing. Fix: Start the ELF file on Linux, in a virtual machine or in the Windows subsystem for Linux.
The wrong chip (2) Our copy with the chip set to AArch64 passed all five readers, and Linux said Exec format error. It was a valid file for another chip. Fix: Compare uname -m with the Machine line of readelf -h, and get a build for your chip.
No execute permission (3) The shell says Permission denied, as it did for our copy without the permission. execve(2) lists a missing execute permission and a noexec mount. Fix: Add the permission on a copy with chmod +x.
A missing library (4) The error says error while loading shared libraries, and then names the ELF file. Our test program needed libtriple.so, and stopped with exit code 127. Fix: Install the library or point LD_LIBRARY_PATH at its folder. Our program then printed 21.
A missing loader (5) The shell says No such file or directory although the ELF file is there. Our copy with one letter changed in the loader path did that. The execve(2) page says the same error covers a missing ELF interpreter. Fix: Read the path with readelf -l and install that loader.
Not a program (6) Object files and core dumps gave Exec format error. A shared library crashed with signal 11. Our copy with type EXEC on a position independent program crashed too. Fix: Check the type at byte 16 and use the right tool, like a linker for object files.
A damaged header (7) A zeroed first byte, type REL and type 0xFFFF all gave Exec format error, and the file command printed only data for the first. Fix: Get a new copy and compare the size and the SHA256 hash with the sender.
Program header trouble (8) An offset past the end, a count of 0 and an entry size of 32 gave Exec format error. A zeroed table and an oversized first load segment crashed. Fix: Get a new copy. Our script flagged all five.
A cut copy (9) Cut to 63 or 64 bytes, our program gave Exec format error. Cut in half, it crashed. Cut by 2,000 bytes it still started, because only the section table was gone. Fix: Copy the ELF file again and compare its size with the source.
A bad entry point or code (10) An entry point of 0 crashed. An entry moved by 2 bytes and a flipped first byte gave an illegal instruction. No reader flagged any of the three. Fix: Get a new copy and check its hash.

Fix a missing library

A missing library is the cause you meet most when you move a program between machines. We built a program that needs libtriple.so and left the library in the current folder only. The listing shows the error, what ldd printed and the fix. The ld.so(8) page lists where Linux looks and in which order.

Four ways an ELF file fails and one fix
$ ./noexec
bash: line 1: ./noexec: Permission denied
$ ./hello.o
bash: line 1: ./hello.o: cannot execute binary file: Exec format error
$ ./core_dump
bash: line 1: ./core_dump: cannot execute binary file: Exec format error
$ ./withlib
./withlib: error while loading shared libraries: libtriple.so: cannot open shared object file: No such file or directory
$ ldd ./withlib
	linux-vdso.so.1 (0x00007f2ee329a000)
	libtriple.so => not found
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2ee3000000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f2ee329c000)
$ LD_LIBRARY_PATH=. ./withlib
21

The first three failures came from files with no permission, an object file and a core dump. The fourth is the missing library. The last line is the fix, with LD_LIBRARY_PATH pointing at the current folder. Use that only for a file you trust, because a library placed there loads first.

Repair steps in the order we would try them

We tested the commands below on Linux 6.18. We did not test any other kernel, any 32 bit program or any file from a game console.

  1. Copy the ELF file, write its SHA256 hash and work on the copy.
  2. Read the kind with file and the header with readelf -h. Compare the Machine line with the output of uname -m.
  3. Check the permission with ls -l. Add it on the copy with chmod +x if it is missing.
  4. Read the loader with readelf -l, in the line that says Requesting program interpreter. Check that the path exists.
  5. List the libraries with objdump -p and look for the NEEDED lines. Install the missing ones.
  6. Test the headers with our script. If it flags the header or the program headers, get a new copy.
  7. Start the ELF file only when the checks pass, and use a sandbox if you do not trust where it came from.

What to send the sender or a helper

Short messages get faster answers. Include the details below. Send the output of readelf too, because the first lines name the type, the chip and the sizes.

A message that gets an answer
Subject: ELF file will not start
File: the name, the size in bytes and the SHA256 hash
Kind: the output of the file command
Header: the first 20 lines of readelf -h
System: the output of uname -m and the name of your Linux version
What happens: the exact words of the error
Source: where the ELF file came from and when it was copied

What no repair can fix

Code that is gone A cut copy or a flipped byte in the code takes the program with it. Only the original file or the source brings it back.
A bad entry point No tool knows the right address. Get a new copy of the ELF file.
A damaged header A hex editor can restore a few bytes if you know the right values, but a new copy is faster and safer.
The execute permission Add it with chmod on a copy.
A missing library Install it or set the library path for a file you trust.
The wrong chip or system Get a build for your chip, or use a virtual machine.

Do not try random repair sites. A site that offers to fix any ELF file for free can keep the upload, and the file can contain your code. Try the steps above first, and ask the sender for a new copy.

How Do You Convert an ELF File? Binary, hex and text listings

Convert ELF files to a flat binary, to Intel hex or to S-records with objcopy, and to a text listing with readelf or objdump. None of the results starts as a program. No tool converts an ELF file to an EXE file, because the two are for different systems.

Two kinds of conversion exist. One copies the loadable bytes into a flat file for a programmer or a debugger. The other prints the headers and code as text. Choose by what you need next. The table lists what we found.

Conversions and what we found
Type Finding and source
ELF to binary objcopy writes the loadable sections as one flat file. Our hello_exec became 15,616 bytes, and file calls it data. It starts with the loader path and has no headers. Source: Our tests.
ELF to Intel hex objcopy writes text lines with addresses. Our ELF file became 4,724 bytes in 110 lines, and the first line sets the high address. Source: Our tests.
ELF to S-record objcopy writes Motorola S-record lines. Our ELF file became 4,818 bytes in 109 lines, and file names the format. Source: Our tests.
ELF to a text listing readelf and objdump print headers, sections and code as text. You can save that output, and it is not a program. Source: Our tests.
ELF to DOL FileInfo lists an ELF to DOL converter for Wii files, and says DOL is like ELF without the debugging data. We did not test it. Source: FileInfo.
ELF to EXE No conversion exists, because the two formats are for different systems. Compile the source for Windows, or start the ELF file in the Windows subsystem for Linux. Source: Wikipedia.

Convert ELF files to binary and hex

objcopy comes with GNU Binutils. The next commands convert our fixed address program to the three flat formats, and strip one copy. The binary file drops the headers, so it cannot start, and its addresses are lost unless you write them down.

Convert and strip with Binutils
objcopy -O binary hello_exec hello.bin
objcopy -O ihex hello_exec hello.ihex
objcopy -O srec hello_exec hello.srec
strip -o hello_stripped hello_pie

The listing shows the first lines of the Intel hex file and the S-record file. Both are text. The hex file has a line for the high address and then lines of data. The data in the second line is the loader path, which is why the binary file starts with it.

The first lines of the hex file
:020000040040BA
:100318002F6C696236342F6C642D6C696E75782D7C
:0C0328007838362D36342E736F2E3200DC
The first lines of the S-record file
S0090000682E73726563B3
S2144003182F6C696236342F6C642D6C696E75782D37

Convert ELF files to EXE files

Wikipedia says Windows uses ELF files only for its Linux subsystem. Linux programs do not become Windows programs when you rename them. If you have the source, build it for Windows. If you only need the program, start it inside the Windows subsystem for Linux or a virtual machine. Our EXE guide covers the Windows side.

Make an ELF file smaller with strip

Stripping removes the symbols and keeps the program. Our position independent program went from 16,000 bytes to 14,472, and from 31 sections to 29. It started and printed the same text. A stripped file is harder to debug, so keep an unstripped copy.

Keep the ELF file. A flat binary does not keep the headers, the symbols or the loader path. Hash the ELF file, write the hash in your log and keep the ELF file as the original.

ELF or EXE: What Is the Difference? Also Mach-O, a.out, SO, DLL and DEB

An ELF file is the Linux and Unix format for programs and libraries. An EXE file is the Windows format, called PE, and a Mach-O file is the macOS format. They serve the same purpose on different systems, so none of them starts on another system.

The names are easy to mix up, and the files do different jobs. The table lists the near neighbours. Every row ends with its source.

ELF compared with PE, Mach-O, a.out, SO, DLL, DEB and LA
Format What it is
ELF Programs, libraries, object files and core dumps on Linux, Unix, Android and many consoles. It starts with 7f 45 4c 46. Source: Wikipedia.
EXE and PE The Windows format, called Portable Executable. A file starts with the letters MZ and has a PE signature after the DOS header. .dll and .sys files use it too. Source: Wikipedia.
Mach-O The format of macOS and iOS programs. A 32 bit file starts with 0xfeedface and a 64 bit file with 0xfeedfacf. Source: Wikipedia.
a.out and COFF The older Unix formats that ELF replaced on Unix like systems. PE extends COFF. Source: Wikipedia.
SO and DLL Shared libraries. Linux uses .so files in the ELF format, and Windows uses .dll files in the PE format. Source: Wikipedia.
DEB A Debian package that contains ELF files. It is an archive and not a program. Source: Our DEB guide.
LA A libtool archive, which is small text about a library. It is not an ELF file. Source: Our LA guide.

Which one do you need

You need a Linux program Use an ELF file on Linux, and check the chip first, as the table of causes show.
You need a Windows program Use an EXE file. Our Windows EXE guide covers it.
You need to see inside Use a reader like readelf, as the open section shows.
You need a flat image Use objcopy, as the convert section shows.

The three formats share a plan. All three start with a header and then say where the code and data go. They differ in details like the first bytes and the names of the parts. Wikipedia says Mach-O was designed to replace the older a.out format, which ELF also replaced elsewhere.

Other things named ELF

FileInfo's ELF page says the .elf ending also belongs to Nintendo Wii game files and to PlayStation executables. Filext's list adds Samsung camera firmware. We had no sample of any of them.

The first bytes settle it. An ELF file has 7f 45 4c 46 at byte 0, and the file command named all 8 of our good files by it. If your ELF file starts with something else, it is not in this format, whatever the ending says.

Why Windows says no

A Windows program needs the PE format and the MZ signature. An ELF file has neither, so Windows has nothing to start. Wikipedia says Windows uses ELF files only through its Linux subsystem. Readers like pyelftools still open any ELF file there, because reading needs no start.

What Is the ELF File Format Made Of? The facts we could check, and where they came from

ELF files follow the System V ABI, which the Linux Foundation hosts, and Debian's elf(5) page lists the fields. Public facts come from those two, Wikipedia, FileInfo, Filext and our own checks of 8 good files and 32 damaged copies. The rest of this section lists them.

Facts about the ELF file format
Part What we could check
Maker Unix System Laboratories designed it, and it appeared in the System V Release 4 specification, per Wikipedia.
Kind Binary. A header, program headers, a body and section headers, in that order in our ELF files.
Signature 7f 45 4c 46 at byte 0.
Specification The System V ABI, with a draft of 24 April 2001 at the Linux Foundation. Debian's elf(5) page lists the fields.
Classes 32 bit with a 52 byte header and 64 bit with a 64 byte header, per Wikipedia. Byte 4 says which.
Byte order Little or big endian, at byte 5.
Types REL, EXEC, DYN and CORE, in the type field at byte 16. NONE is a fifth value.
Chips The header names the chip. Our 12 test headers named x86, x86 64, Arm, AArch64, RISC V, MIPS, SuperH, PowerPC, S/390, SPARC and AVR.
Endings None, .elf, .so, .o, .ko, .axf, .out, .bin, .prx, .puff, .mod and .AppImage, per Wikipedia.
Media type None for .elf in the four lists that we checked.
Detection file 5.45 named all 8 good files and flagged 7 damaged copies.
Other claimants FileInfo lists Wii and PlayStation files. Filext lists Samsung camera firmware.

About the values we list

Facts about the format come from the System V ABI draft, Debian's manual pages for elf(5), execve(2), ld.so(8) and ldd(1), and Wikipedia. FileInfo and Filext add the other uses of the ending. Our own checks fill the gaps, and we say so where they do.

Where sources differ, we say so. FileInfo calls .elf a Wii game file in one entry and a PlayStation program in another, and Filext lists camera firmware. These are different programs that share an ending, so the page lists all of them.

What we left out

We tested only 64 bit little endian x86 files on Linux 6.18. We did not start a 32 bit program, an Arm program or a console file. We made no kernel module and no Android library, and we started none of the emulators.

Our 32 damaged copies come from one small program, so they show what can happen and not how common it is. We turned LIEF's own warnings off, so its result counts failures only. We name no vendor tool and no price.

Sources checked

For the format, see Wikipedia on ELF, the ABI draft and the elf(5) manual page. For starting and loading, see execve(2) manual page, ld.so(8) and ldd(1).

For other formats, see Wikipedia on Portable Executable and Mach-O. For the ending, see FileInfo for ELF and the Filext entry. Every count and label came from the files and scripts in our research folder.

Frequently Asked Questions About ELF Files

What is an ELF file?

An ELF file is a program, a shared library, an object file or a core dump in the Executable and Linkable Format. Linux and most Unix systems use it for the programs they start. One header names the chip and the type. Most ELF files have no ending.

How do I open an ELF file?

Linux starts ELF programs for its own chip once the ELF file has the execute permission. To look inside without starting anything, use file, readelf, objdump or the Python module pyelftools. Windows and Mac do not start Linux programs.

Can you start an ELF file on Windows?

Not directly. Windows uses ELF files only through its Linux subsystem, as Wikipedia explains. Use that subsystem or a virtual machine to start a Linux program. Readers like pyelftools open any ELF file on Windows, because reading needs no start.

What does ELF stand for?

ELF stands for Executable and Linkable Format. Wikipedia says the name first meant Extensible Linking Format. Unix System Laboratories designed it, and the 86open project chose it in 1999 as the common format for Unix systems on x86 chips.

What is the difference between an ELF file and an EXE file?

An ELF file is the Linux and Unix format, and it starts with 7f 45 4c 46. An EXE file is the Windows format called PE, and it starts with the letters MZ. Both store programs, and neither starts on the other system.

Why does an ELF file say Exec format error?

Linux does not recognize the ELF file for your computer. The chip can be wrong, the header can be damaged or the ELF file can be an object file or a core dump. We saw it on 9 of our 32 damaged copies. Compare your chip with the Machine line of readelf.

Why does my ELF file say No such file or directory when it exists?

The file is there, but its loader is not. Linux names a loader in the ELF file, and the error covers a missing loader too, as Debian's execve page explains. Our copy with one letter changed in the loader path gave exactly that. Read the path with readelf and install that loader.

How do I check an ELF file?

Read the first bytes and the headers. Good ELF files start with 7f 45 4c 46. Use file for a quick answer and readelf for the header, the segments and the sections. Our 75 line script also checks the loader and the entry point. Always check a copy.

Is an ELF file safe to open?

Reading one with a tool is safe, and our readers changed none of 53 files. Starting programs is different, because they can do everything their user can do. Start only ELF files you trust, use a sandbox for the rest and never use ldd on an unknown file.

Can a damaged ELF file be repaired?

Rarely. A new copy is faster and safer. Lost code and bad entry points cannot come back without the original. A damaged header can sometimes be fixed by hand if you know the right values, but readers that say nothing can hide the problem.

How do I convert an ELF file to binary or hex?

Use objcopy from GNU Binutils with the output format binary, ihex or srec. The result is a flat file with no headers, so it cannot start. Our test file became 15,616 bytes as a binary and about 4,700 bytes as hex text. Keep the ELF file as the original.

Does an ELF file need section headers to start?

No. All six of our copies with damaged or missing section headers started and printed their text. Linux uses the program headers. Debuggers and linkers use the section headers, so a stripped or damaged section table still limits what tools can show.

Still Stuck With an ELF File? Seven routes out, depending on what went wrong

Your ELF file will not start

Check your system, your chip and the permission first. The ten causes list what to try in order.

Your reader shows an error

Compare the size and the hash with the source. The repair steps show the order.

Is it a Windows program? The page on EXE files explains the Windows format and its installers.

Did it come in a Debian package? The page on DEB files shows how to open the package and its contents.

Is it a Mac disk image? The page on DMG files covers Mac disk images and the programs inside them.

Is it a libtool file? The page on LA files covers the small text files that describe Linux libraries.

Is it a file type you do not know? Browse the file extension resource library, or send it to us on the submit a file type page.