elf.5 (4f0689613061cb529e45bdd405b619dbb404b232) elf.5 (757686b11510174fffffec96b816204c8d659fba)
1.\" Copyright (c) 1999 Jeroen Ruigrok van der Werven
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.

--- 74 unchanged lines hidden (view full) ---

83.In sys/elf_generic.h .
84.Pp
85These header files describe the above mentioned headers as C structures
86and also include structures for dynamic sections, relocation sections and
87symbol tables.
88.Pp
89The following types are being used for 32-bit architectures:
90.Bd -literal -offset indent
1.\" Copyright (c) 1999 Jeroen Ruigrok van der Werven
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.

--- 74 unchanged lines hidden (view full) ---

83.In sys/elf_generic.h .
84.Pp
85These header files describe the above mentioned headers as C structures
86and also include structures for dynamic sections, relocation sections and
87symbol tables.
88.Pp
89The following types are being used for 32-bit architectures:
90.Bd -literal -offset indent
91Elf32_Addr Unsigned program address
92Elf32_Half Unsigned halfword field
93Elf32_Off Unsigned file offset
94Elf32_Sword Signed large integer
95Elf32_Word Field or unsigned large integer
96Elf32_Size Unsigned object size
91Elf32_Addr Unsigned 32-bit program address
92Elf32_Half Unsigned 16-bit field
93Elf32_Off Unsigned 32-bit file offset
94Elf32_Sword Signed 32-bit field or integer
95Elf32_Word Unsigned 32-bit field or integer
97.Ed
98.Pp
99For 64-bit architectures we have the following types:
100.Bd -literal -offset indent
96.Ed
97.Pp
98For 64-bit architectures we have the following types:
99.Bd -literal -offset indent
101Elf64_Addr Unsigned program address
102Elf64_Half Unsigned halfword field
103Elf64_Off Unsigned file offset
104Elf64_Sword Signed large integer
105Elf64_Word Field or unsigned large integer
106Elf64_Size Unsigned object size
107Elf64_Quarter Unsigned quarterword field
100Elf64_Addr Unsigned 64-bit program address
101Elf64_Half Unsigned 16-bit field
102Elf64_Off Unsigned 64-bit file offset
103Elf64_Sword Signed 32-bit field
104Elf64_Word Unsigned 32-bit field
105Elf64_Sxword Signed 64-bit field or integer
106Elf64_Xword Unsigned 64-bit field or integer
108.Ed
109.Pp
110All data structures that the file format defines follow the
111.Dq natural
112size and alignment guidelines for the relevant class.
113If necessary,
114data structures contain explicit padding to ensure 4-byte alignment
115for 4-byte objects, to force structure sizes to a multiple of 4, etc.

--- 16 unchanged lines hidden (view full) ---

132 Elf32_Half e_shnum;
133 Elf32_Half e_shstrndx;
134} Elf32_Ehdr;
135.Ed
136.Pp
137.Bd -literal -offset indent
138typedef struct {
139 unsigned char e_ident[EI_NIDENT];
107.Ed
108.Pp
109All data structures that the file format defines follow the
110.Dq natural
111size and alignment guidelines for the relevant class.
112If necessary,
113data structures contain explicit padding to ensure 4-byte alignment
114for 4-byte objects, to force structure sizes to a multiple of 4, etc.

--- 16 unchanged lines hidden (view full) ---

131 Elf32_Half e_shnum;
132 Elf32_Half e_shstrndx;
133} Elf32_Ehdr;
134.Ed
135.Pp
136.Bd -literal -offset indent
137typedef struct {
138 unsigned char e_ident[EI_NIDENT];
140 Elf64_Quarter e_type;
141 Elf64_Quarter e_machine;
142 Elf64_Half e_version;
139 Elf64_Half e_type;
140 Elf64_Half e_machine;
141 Elf64_Word e_version;
143 Elf64_Addr e_entry;
144 Elf64_Off e_phoff;
145 Elf64_Off e_shoff;
142 Elf64_Addr e_entry;
143 Elf64_Off e_phoff;
144 Elf64_Off e_shoff;
146 Elf64_Half e_flags;
147 Elf64_Quarter e_ehsize;
148 Elf64_Quarter e_phentsize;
149 Elf64_Quarter e_phnum;
150 Elf64_Quarter e_shentsize;
151 Elf64_Quarter e_shnum;
152 Elf64_Quarter e_shstrndx;
145 Elf64_Word e_flags;
146 Elf64_Half e_ehsize;
147 Elf64_Half e_phentsize;
148 Elf64_Half e_phnum;
149 Elf64_Half e_shentsize;
150 Elf64_Half e_shnum;
151 Elf64_Half e_shstrndx;
153} Elf64_Ehdr;
154.Ed
155.Pp
156The fields have the following meanings:
157.Pp
158.Bl -tag -width "e_phentsize" -compact -offset indent
159.It Dv e_ident
160This array of bytes specifies to interpret the file,

--- 250 unchanged lines hidden (view full) ---

411also has different versions depending on the architecture:
412.Pp
413.Bd -literal -offset indent
414typedef struct {
415 Elf32_Word p_type;
416 Elf32_Off p_offset;
417 Elf32_Addr p_vaddr;
418 Elf32_Addr p_paddr;
152} Elf64_Ehdr;
153.Ed
154.Pp
155The fields have the following meanings:
156.Pp
157.Bl -tag -width "e_phentsize" -compact -offset indent
158.It Dv e_ident
159This array of bytes specifies to interpret the file,

--- 250 unchanged lines hidden (view full) ---

410also has different versions depending on the architecture:
411.Pp
412.Bd -literal -offset indent
413typedef struct {
414 Elf32_Word p_type;
415 Elf32_Off p_offset;
416 Elf32_Addr p_vaddr;
417 Elf32_Addr p_paddr;
419 Elf32_Size p_filesz;
420 Elf32_Size p_memsz;
418 Elf32_Word p_filesz;
419 Elf32_Word p_memsz;
421 Elf32_Word p_flags;
420 Elf32_Word p_flags;
422 Elf32_Size p_align;
421 Elf32_Word p_align;
423} Elf32_Phdr;
424.Ed
425.Pp
426.Bd -literal -offset indent
427typedef struct {
422} Elf32_Phdr;
423.Ed
424.Pp
425.Bd -literal -offset indent
426typedef struct {
428 Elf64_Half p_type;
429 Elf64_Half p_flags;
427 Elf64_Word p_type;
428 Elf64_Word p_flags;
430 Elf64_Off p_offset;
431 Elf64_Addr p_vaddr;
432 Elf64_Addr p_paddr;
429 Elf64_Off p_offset;
430 Elf64_Addr p_vaddr;
431 Elf64_Addr p_paddr;
433 Elf64_Size p_filesz;
434 Elf64_Size p_memsz;
435 Elf64_Size p_align;
432 Elf64_Xword p_filesz;
433 Elf64_Xword p_memsz;
434 Elf64_Xword p_align;
436} Elf64_Phdr;
437.Ed
438.Pp
439The main difference between the 32-bit and the 64-bit program header lies
440only in the location of a
441.Sy p_flags
442member in the total struct.
443.Pp

--- 182 unchanged lines hidden (view full) ---

626The section header has the following structure:
627.Bd -literal -offset indent
628typedef struct {
629 Elf32_Word sh_name;
630 Elf32_Word sh_type;
631 Elf32_Word sh_flags;
632 Elf32_Addr sh_addr;
633 Elf32_Off sh_offset;
435} Elf64_Phdr;
436.Ed
437.Pp
438The main difference between the 32-bit and the 64-bit program header lies
439only in the location of a
440.Sy p_flags
441member in the total struct.
442.Pp

--- 182 unchanged lines hidden (view full) ---

625The section header has the following structure:
626.Bd -literal -offset indent
627typedef struct {
628 Elf32_Word sh_name;
629 Elf32_Word sh_type;
630 Elf32_Word sh_flags;
631 Elf32_Addr sh_addr;
632 Elf32_Off sh_offset;
634 Elf32_Size sh_size;
633 Elf32_Word sh_size;
635 Elf32_Word sh_link;
636 Elf32_Word sh_info;
634 Elf32_Word sh_link;
635 Elf32_Word sh_info;
637 Elf32_Size sh_addralign;
638 Elf32_Size sh_entsize;
636 Elf32_Word sh_addralign;
637 Elf32_Word sh_entsize;
639} Elf32_Shdr;
640.Ed
641.Pp
642.Bd -literal -offset indent
643typedef struct {
638} Elf32_Shdr;
639.Ed
640.Pp
641.Bd -literal -offset indent
642typedef struct {
644 Elf64_Half sh_name;
645 Elf64_Half sh_type;
646 Elf64_Size sh_flags;
643 Elf64_Word sh_name;
644 Elf64_Word sh_type;
645 Elf64_Xword sh_flags;
647 Elf64_Addr sh_addr;
648 Elf64_Off sh_offset;
646 Elf64_Addr sh_addr;
647 Elf64_Off sh_offset;
649 Elf64_Size sh_size;
650 Elf64_Half sh_link;
651 Elf64_Half sh_info;
652 Elf64_Size sh_addralign;
653 Elf64_Size sh_entsize;
648 Elf64_Xword sh_size;
649 Elf64_Word sh_link;
650 Elf64_Word sh_info;
651 Elf64_Xword sh_addralign;
652 Elf64_Xword sh_entsize;
654} Elf64_Shdr;
655.Ed
656.Pp
657.Bl -tag -width "sh_addralign" -compact
658.It Dv sh_name
659This member specifies the name of the section.
660Its value is an index
661into the section header string table section, giving the location of

--- 406 unchanged lines hidden (view full) ---

1068relocate a program's symbolic definitions and references.
1069A symbol table
1070index is a subscript into this array.
1071.Pp
1072.Bd -literal -offset indent
1073typedef struct {
1074 Elf32_Word st_name;
1075 Elf32_Addr st_value;
653} Elf64_Shdr;
654.Ed
655.Pp
656.Bl -tag -width "sh_addralign" -compact
657.It Dv sh_name
658This member specifies the name of the section.
659Its value is an index
660into the section header string table section, giving the location of

--- 406 unchanged lines hidden (view full) ---

1067relocate a program's symbolic definitions and references.
1068A symbol table
1069index is a subscript into this array.
1070.Pp
1071.Bd -literal -offset indent
1072typedef struct {
1073 Elf32_Word st_name;
1074 Elf32_Addr st_value;
1076 Elf32_Size st_size;
1075 Elf32_Word st_size;
1077 unsigned char st_info;
1078 unsigned char st_other;
1079 Elf32_Half st_shndx;
1080} Elf32_Sym;
1081.Ed
1082.Pp
1083.Bd -literal -offset indent
1084typedef struct {
1076 unsigned char st_info;
1077 unsigned char st_other;
1078 Elf32_Half st_shndx;
1079} Elf32_Sym;
1080.Ed
1081.Pp
1082.Bd -literal -offset indent
1083typedef struct {
1085 Elf64_Half st_name;
1084 Elf64_Word st_name;
1086 unsigned char st_info;
1087 unsigned char st_other;
1085 unsigned char st_info;
1086 unsigned char st_other;
1088 Elf64_Quarter st_shndx;
1087 Elf64_Half st_shndx;
1089 Elf64_Addr st_value;
1088 Elf64_Addr st_value;
1090 Elf64_Size st_size;
1089 Elf64_Xword st_size;
1091} Elf64_Sym;
1092.Ed
1093.Pp
1094.Bl -tag -width "st_value" -compact
1095.It Dv st_name
1096This member holds an index into the object file's symbol string table,
1097which holds character representations of the symbol names.
1098If the value

--- 113 unchanged lines hidden (view full) ---

1212typedef struct {
1213 Elf32_Addr r_offset;
1214 Elf32_Word r_info;
1215} Elf32_Rel;
1216.Ed
1217.Bd -literal -offset indent
1218typedef struct {
1219 Elf64_Addr r_offset;
1090} Elf64_Sym;
1091.Ed
1092.Pp
1093.Bl -tag -width "st_value" -compact
1094.It Dv st_name
1095This member holds an index into the object file's symbol string table,
1096which holds character representations of the symbol names.
1097If the value

--- 113 unchanged lines hidden (view full) ---

1211typedef struct {
1212 Elf32_Addr r_offset;
1213 Elf32_Word r_info;
1214} Elf32_Rel;
1215.Ed
1216.Bd -literal -offset indent
1217typedef struct {
1218 Elf64_Addr r_offset;
1220 Elf64_Size r_info;
1219 Elf64_Xword r_info;
1221} Elf64_Rel;
1222.Ed
1223.Pp
1224Relocation structures that need an addend:
1225.Pp
1226.Bd -literal -offset indent
1227typedef struct {
1228 Elf32_Addr r_offset;
1229 Elf32_Word r_info;
1230 Elf32_Sword r_addend;
1231} Elf32_Rela;
1232.Ed
1233.Bd -literal -offset indent
1234typedef struct {
1235 Elf64_Addr r_offset;
1220} Elf64_Rel;
1221.Ed
1222.Pp
1223Relocation structures that need an addend:
1224.Pp
1225.Bd -literal -offset indent
1226typedef struct {
1227 Elf32_Addr r_offset;
1228 Elf32_Word r_info;
1229 Elf32_Sword r_addend;
1230} Elf32_Rela;
1231.Ed
1232.Bd -literal -offset indent
1233typedef struct {
1234 Elf64_Addr r_offset;
1236 Elf64_Size r_info;
1237 Elf64_Off r_addend;
1235 Elf64_Xword r_info;
1236 Elf64_Sxword r_addend;
1238} Elf64_Rela;
1239.Ed
1240.Pp
1241.Bl -tag -width "r_offset" -compact
1242.It Dv r_offset
1243This member gives the location at which to apply the relocation action.
1244For a relocatable file, the value is the byte offset from the beginning
1245of the section to the storage unit affected by the relocation.

--- 55 unchanged lines hidden ---
1237} Elf64_Rela;
1238.Ed
1239.Pp
1240.Bl -tag -width "r_offset" -compact
1241.It Dv r_offset
1242This member gives the location at which to apply the relocation action.
1243For a relocatable file, the value is the byte offset from the beginning
1244of the section to the storage unit affected by the relocation.

--- 55 unchanged lines hidden ---