The GCC Executable Format
Listing 2: Unix Executable File Header (file: exec.h)
/* Excerpted with permission from 4.3BSD include file
* "/usr/include/sys/exec.h"
* Redistribution and use in source and binary forms are freely permitted
* provided that the above copyright notice and attribution and date of work
* and this paragraph are duplicated in all such forms.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* Header prepended to each a.out file.
*/
struct exec {
long a_magic; /* magic number */
unsigned long a_text; /* size of text segment */
unsigned long a_data; /* size of initialized data */
unsigned long a_bss; /* size of uninitialized data */
unsigned long a_syms; /* size of symbol table */
unsigned long a_entry; /* entry point */
unsigned long a_trsize; /* size of text relocation */
unsigned long a_drsize; /* size of data relocation */
};
#define OMAGIC 0407 /* old impure format */
#define NMAGIC 0410 /* read-only text */
#define ZMAGIC 0413 /* demand load format */
This format is the oldest of the many (and, unfortunately still growing) different UNIX executable file formats. The BSD a.out format consists of a header structure (see Listing 2 for exec.h) that details the size of sections following, the instruction segment (or text), the data segment, relocation information, and finally, a symbol-table segment. At this time, we are interested only in the information contained in instruction and data sections, which we then load into a large, dynamically allocated temporary array, before moving it into position. We do not use the relocation information or the symbol-table segment.
|
|