Elf64
ELF (Executable and Linkable Format) is a standard file format for executable files, object code, shared libraries and core dumps. Linux and many UNIX-like operating systems use this format. Let's look at the structure of the ELF-64 Object File Format and some definitions in the Linux kernel source code which related with it.
An ELF object file consists of the following parts:
ELF header - describes the main characteristics of the object file: type, CPU architecture, the virtual address of the entry point, the size and offset of the remaining parts, etc...;
Program header table - lists the available segments and their attributes. Program header table need loaders for placing sections of the file as virtual memory segments;
Section header table - contains the description of the sections.
Now let's have a closer look on these components.
ELF header
The ELF header is located at the beginning of the object file. Its main purpose is to locate all other parts of the object file. The file header contains the following fields:
ELF identification - array of bytes which helps identify the file as an ELF object file and also provides information about general object file characteristic;
Object file type - identifies the object file type. This field can describe that ELF file is a relocatable object file, an executable file, etc...;
Target architecture;
Version of the object file format;
Virtual address of the program entry point;
File offset of the program header table;
File offset of the section header table;
Size of an ELF header;
Size of a program header table entry;
and other fields...
You can find the elf64_hdr
structure which presents ELF64 header in the Linux kernel source code:
This structure defined in the elf.h
Sections
All data stores in a sections in an Elf object file. Sections identified by index in the section header table. Section header contains following fields:
Section name;
Section type;
Section attributes;
Virtual address in memory;
Offset in file;
Size of section;
Link to other section;
Miscellaneous information;
Address alignment boundary;
Size of entries, if section has table;
And presented with the following elf64_shdr
structure in the Linux kernel:
Program header table
All sections are grouped into segments in an executable or shared object file. Program header is an array of structures which describe every segment. It looks like:
in the Linux kernel source code.
elf64_phdr
defined in the same elf.h.
The ELF object file also contains other fields/structures which you can find in the Documentation. Now let's a look at the vmlinux
ELF object.
vmlinux
vmlinux
is also a relocatable ELF object file . We can take a look at it with the readelf
utility. First of all let's look at the header:
Here we can see that vmlinux
is a 64-bit executable file.
We can read from the Documentation/x86/x86_64/mm.txt:
We can then look this address up in the vmlinux
ELF object with:
Note that the address of the startup_64
routine is not ffffffff80000000
, but ffffffff81000000
and now I'll explain why.
We can see following definition in the arch/x86/kernel/vmlinux.lds.S:
Where __START_KERNEL
is:
__START_KERNEL_map
is the value from the documentation - ffffffff80000000
and __PHYSICAL_START
is 0x1000000
. That's why address of the startup_64
is ffffffff81000000
.
And at last we can get program headers from vmlinux
with the following command:
Here we can see five segments with sections list. You can find all of these sections in the generated linker script at - arch/x86/kernel/vmlinux.lds
.
That's all. Of course it's not a full description of ELF (Executable and Linkable Format), but if you want to know more, you can find the documentation - here
Last updated