ELF: Difference between revisions

1,954 bytes removed ,  6 years ago
m
Reverted edits by Schol-r-lea (talk) to last revision by No92
[unchecked revision][unchecked revision]
No edit summary
m (Reverted edits by Schol-r-lea (talk) to last revision by No92)
Line 280:
|}
The most common architectures are in bold.
 
An example C struct declaration for the file header (from [http://www.iecc.com/linker/linker03.html Levine]) would look like this:
struct ELF_fh {
char magic[4] = "\177ELF"; // magic number
char class; // address size, 1 = 32 bit, 2 = 64 bit
char byteorder; // 1 = little-endian, 2 = big-endian
char hversion; // header version, always 1
char pad[9]; short filetype; // file type: 1 = relocatable, 2 = executable,
// 3 = shared object, 4 = core image
short archtype; // 2 = SPARC, 3 = x86, 4 = 68K, etc.
int fversion; // file version, always 1
int entry; // entry point if executable
int phdrpos; // file position of program header or 0
int shdrpos; // file position of section header or 0
int flags; // architecture specific flags, usually 0
short hdrsize; // size of this ELF header
short phdrent; // size of an entry in program header
short phdrcnt; // number of entries in program header or 0
short shdrent; // size of an entry in section header
short phdrcnt; // number of entries in section header or 0
short strsec; // section number that contains section name strings
};
 
=== Program header ===
Line 372 ⟶ 349:
 
Flags: 1 = executable, 2 = writable, 4 = readable.
 
An example C struct for the 32-bit (also from Levine) might be:
 
 
struct ELF_progh {
int type; // loadable code or data, dynamic linking info, etc.
int offset; // file offset of segment
int virtaddr; // virtual address to map segment
int physaddr; // physical address, not used
int filesize; // size of segment in file
int memsize; // size of segment in memory (bigger if contains BSS)
int flags; // Read, Write, Execute bits
int align; // required alignment, invariably hardware page size
};
 
 
 
 
=== Using the PIC with programs ===
Line 431 ⟶ 391:
* [http://www.x86-64.org/documentation/abi.pdf x86-64 ABI] Documented x86-64 specific extensions with ELF64.
* [http://www.robinhoksbergen.com/papers/howto_elf.html Manually Creating an ELF Executable](dead) Detailed guide on how to create ELF binaries from scratch.
* ''[http://www.iecc.com/linker/ Linkers and Loader], John Levine 1999, online beta edition.
 
[[Category:ABI]]
[[Category:Executable Formats]]
Anonymous user