1 /* This file is derived from the GAS 2.1.4 assembler control file.
2 The GAS product is under the GNU General Public License, version 2 or later.
3 As such, this file is also under that license.
5 If the file format changes in the COFF object, this file should be
6 subsequently updated to reflect the changes.
8 The actual loader module only uses a few of these structures. The full
9 set is documented here because I received the full set. If you wish
10 more information about COFF, then O'Reilly has a very excellent book.
13 #define E_SYMNMLEN 8 /* Number of characters in a symbol name */
14 #define E_FILNMLEN 14 /* Number of characters in a file name */
15 #define E_DIMNUM 4 /* Number of array dimensions in auxiliary entry */
18 * These defines are byte order independent. There is no alignment of fields
19 * permitted in the structures. Therefore they are declared as characters
20 * and the values loaded from the character positions. It also makes it
21 * nice to have it "endian" independent.
24 /* Load a short int from the following tables with little-endian formats */
25 #define COFF_SHORT_L(ps) ((short)(((unsigned short)((unsigned char)ps[1])<<8)|\
26 ((unsigned short)((unsigned char)ps[0]))))
28 /* Load a long int from the following tables with little-endian formats */
29 #define COFF_LONG_L(ps) (((long)(((unsigned long)((unsigned char)ps[3])<<24) |\
30 ((unsigned long)((unsigned char)ps[2])<<16) |\
31 ((unsigned long)((unsigned char)ps[1])<<8) |\
32 ((unsigned long)((unsigned char)ps[0])))))
34 /* Load a short int from the following tables with big-endian formats */
35 #define COFF_SHORT_H(ps) ((short)(((unsigned short)((unsigned char)ps[0])<<8)|\
36 ((unsigned short)((unsigned char)ps[1]))))
38 /* Load a long int from the following tables with big-endian formats */
39 #define COFF_LONG_H(ps) (((long)(((unsigned long)((unsigned char)ps[0])<<24) |\
40 ((unsigned long)((unsigned char)ps[1])<<16) |\
41 ((unsigned long)((unsigned char)ps[2])<<8) |\
42 ((unsigned long)((unsigned char)ps[3])))))
44 /* These may be overridden later by brain dead implementations which generate
45 a big-endian header with little-endian data. In that case, generate a
46 replacement macro which tests a flag and uses either of the two above
49 #define COFF_LONG(v) COFF_LONG_L(v)
50 #define COFF_SHORT(v) COFF_SHORT_L(v)
52 /*** coff information for Intel 386/486. */
54 /********************** FILE HEADER **********************/
57 char f_magic
[2]; /* magic number */
58 char f_nscns
[2]; /* number of sections */
59 char f_timdat
[4]; /* time & date stamp */
60 char f_symptr
[4]; /* file pointer to symtab */
61 char f_nsyms
[4]; /* number of symtab entries */
62 char f_opthdr
[2]; /* sizeof(optional hdr) */
63 char f_flags
[2]; /* flags */
69 * F_RELFLG relocation info stripped from file
70 * F_EXEC file is executable (i.e. no unresolved external
72 * F_LNNO line numbers stripped from file
73 * F_LSYMS local symbols stripped from file
74 * F_MINMAL this is a minimal object file (".m") output of fextract
75 * F_UPDATE this is a fully bound update file, output of ogen
76 * F_SWABD this file has had its bytes swabbed (in names)
77 * F_AR16WR this file has the byte ordering of an AR16WR
78 * (e.g. 11/70) machine
79 * F_AR32WR this file has the byte ordering of an AR32WR machine
80 * (e.g. vax and iNTEL 386)
81 * F_AR32W this file has the byte ordering of an AR32W machine
83 * F_PATCH file contains "patch" list in optional header
84 * F_NODF (minimal file only) no decision functions for
88 #define COFF_F_RELFLG 0000001
89 #define COFF_F_EXEC 0000002
90 #define COFF_F_LNNO 0000004
91 #define COFF_F_LSYMS 0000010
92 #define COFF_F_MINMAL 0000020
93 #define COFF_F_UPDATE 0000040
94 #define COFF_F_SWABD 0000100
95 #define COFF_F_AR16WR 0000200
96 #define COFF_F_AR32WR 0000400
97 #define COFF_F_AR32W 0001000
98 #define COFF_F_PATCH 0002000
99 #define COFF_F_NODF 0002000
101 #define COFF_I386MAGIC 0x14c /* Linux's system */
103 #if 0 /* Perhaps, someday, these formats may be used. */
104 #define COFF_I386PTXMAGIC 0x154
105 #define COFF_I386AIXMAGIC 0x175 /* IBM's AIX system */
106 #define COFF_I386BADMAG(x) ((COFF_SHORT((x).f_magic) != COFF_I386MAGIC) \
107 && COFF_SHORT((x).f_magic) != COFF_I386PTXMAGIC \
108 && COFF_SHORT((x).f_magic) != COFF_I386AIXMAGIC)
110 #define COFF_I386BADMAG(x) (COFF_SHORT((x).f_magic) != COFF_I386MAGIC)
113 #define COFF_FILHDR struct COFF_filehdr
114 #define COFF_FILHSZ sizeof(COFF_FILHDR)
116 /********************** AOUT "OPTIONAL HEADER" **********************/
118 /* Linux COFF must have this "optional" header. Standard COFF has no entry
119 location for the "entry" point. They normally would start with the first
120 location of the .text section. This is not a good idea for linux. So,
121 the use of this "optional" header is not optional. It is required.
123 Do not be tempted to assume that the size of the optional header is
124 a constant and simply index the next byte by the size of this structure.
125 Use the 'f_opthdr' field in the main coff header for the size of the
126 structure actually written to the file!!
131 char magic
[2]; /* type of file */
132 char vstamp
[2]; /* version stamp */
133 char tsize
[4]; /* text size in bytes, padded to FW bdry */
134 char dsize
[4]; /* initialized data " " */
135 char bsize
[4]; /* uninitialized data " " */
136 char entry
[4]; /* entry pt. */
137 char text_start
[4]; /* base of text used for this file */
138 char data_start
[4]; /* base of data used for this file */
142 #define COFF_AOUTSZ (sizeof(COFF_AOUTHDR))
144 #define COFF_STMAGIC 0401
145 #define COFF_OMAGIC 0404
146 #define COFF_JMAGIC 0407 /* dirty text and data image, can't share */
147 #define COFF_DMAGIC 0410 /* dirty text segment, data aligned */
148 #define COFF_ZMAGIC 0413 /* The proper magic number for executables */
149 #define COFF_SHMAGIC 0443 /* shared library header */
151 /********************** SECTION HEADER **********************/
154 char s_name
[8]; /* section name */
155 char s_paddr
[4]; /* physical address, aliased s_nlib */
156 char s_vaddr
[4]; /* virtual address */
157 char s_size
[4]; /* section size */
158 char s_scnptr
[4]; /* file ptr to raw data for section */
159 char s_relptr
[4]; /* file ptr to relocation */
160 char s_lnnoptr
[4]; /* file ptr to line numbers */
161 char s_nreloc
[2]; /* number of relocation entries */
162 char s_nlnno
[2]; /* number of line number entries */
163 char s_flags
[4]; /* flags */
166 #define COFF_SCNHDR struct COFF_scnhdr
167 #define COFF_SCNHSZ sizeof(COFF_SCNHDR)
170 * names of "special" sections
173 #define COFF_TEXT ".text"
174 #define COFF_DATA ".data"
175 #define COFF_BSS ".bss"
176 #define COFF_COMMENT ".comment"
177 #define COFF_LIB ".lib"
179 #define COFF_SECT_TEXT 0 /* Section for instruction code */
180 #define COFF_SECT_DATA 1 /* Section for initialized globals */
181 #define COFF_SECT_BSS 2 /* Section for un-initialized globals */
182 #define COFF_SECT_REQD 3 /* Minimum number of sections for good file */
184 #define COFF_STYP_REG 0x00 /* regular segment */
185 #define COFF_STYP_DSECT 0x01 /* dummy segment */
186 #define COFF_STYP_NOLOAD 0x02 /* no-load segment */
187 #define COFF_STYP_GROUP 0x04 /* group segment */
188 #define COFF_STYP_PAD 0x08 /* .pad segment */
189 #define COFF_STYP_COPY 0x10 /* copy section */
190 #define COFF_STYP_TEXT 0x20 /* .text segment */
191 #define COFF_STYP_DATA 0x40 /* .data segment */
192 #define COFF_STYP_BSS 0x80 /* .bss segment */
193 #define COFF_STYP_INFO 0x200 /* .comment section */
194 #define COFF_STYP_OVER 0x400 /* overlay section */
195 #define COFF_STYP_LIB 0x800 /* library section */
198 * Shared libraries have the following section header in the data field for
203 char sl_entsz
[4]; /* Size of this entry */
204 char sl_pathndx
[4]; /* size of the header field */
207 #define COFF_SLIBHD struct COFF_slib
208 #define COFF_SLIBSZ sizeof(COFF_SLIBHD)
210 /********************** LINE NUMBERS **********************/
212 /* 1 line number entry for every "breakpointable" source line in a section.
213 * Line numbers are grouped on a per function basis; first entry in a function
214 * grouping will have l_lnno = 0 and in place of physical address will be the
215 * symbol table index of the function name.
220 char l_symndx
[4]; /* function name symbol index, iff l_lnno == 0*/
221 char l_paddr
[4]; /* (physical) address of line number */
223 char l_lnno
[2]; /* line number */
226 #define COFF_LINENO struct COFF_lineno
227 #define COFF_LINESZ 6
229 /********************** SYMBOLS **********************/
231 #define COFF_E_SYMNMLEN 8 /* # characters in a short symbol name */
232 #define COFF_E_FILNMLEN 14 /* # characters in a file name */
233 #define COFF_E_DIMNUM 4 /* # array dimensions in auxiliary entry */
236 * All symbols and sections have the following definition
242 char e_name
[E_SYMNMLEN
]; /* Symbol name (first 8 characters) */
244 char e_zeroes
[4]; /* Leading zeros */
245 char e_offset
[4]; /* Offset if this is a header section */
249 char e_value
[4]; /* Value (address) of the segment */
250 char e_scnum
[2]; /* Section number */
251 char e_type
[2]; /* Type of section */
252 char e_sclass
[1]; /* Loader class */
253 char e_numaux
[1]; /* Number of auxiliary entries which follow */
256 #define COFF_N_BTMASK (0xf) /* Mask for important class bits */
257 #define COFF_N_TMASK (0x30) /* Mask for important type bits */
258 #define COFF_N_BTSHFT (4) /* # bits to shift class field */
259 #define COFF_N_TSHIFT (2) /* # bits to shift type field */
262 * Auxiliary entries because the main table is too limiting.
268 * Debugger information
272 char x_tagndx
[4]; /* str, un, or enum tag indx */
275 char x_lnno
[2]; /* declaration line number */
276 char x_size
[2]; /* str/union/array size */
278 char x_fsize
[4]; /* size of function */
282 struct { /* if ISFCN, tag, or .bb */
283 char x_lnnoptr
[4]; /* ptr to fcn line # */
284 char x_endndx
[4]; /* entry ndx past block end */
287 struct { /* if ISARY, up to 4 dimen. */
288 char x_dimen
[E_DIMNUM
][2];
292 char x_tvndx
[2]; /* tv index */
296 * Source file names (debugger information)
300 char x_fname
[E_FILNMLEN
];
308 * Section information
312 char x_scnlen
[4]; /* section length */
313 char x_nreloc
[2]; /* # relocation entries */
314 char x_nlinno
[2]; /* # line numbers */
318 * Transfer vector (branch table)
322 char x_tvfill
[4]; /* tv fill value */
323 char x_tvlen
[2]; /* length of .tv */
324 char x_tvran
[2][2]; /* tv range */
325 } x_tv
; /* info about .tv section (in auxent of symbol .tv)) */
328 #define COFF_SYMENT struct COFF_syment
329 #define COFF_SYMESZ 18
330 #define COFF_AUXENT union COFF_auxent
331 #define COFF_AUXESZ 18
333 #define COFF_ETEXT "etext"
335 /********************** RELOCATION DIRECTIVES **********************/
338 char r_vaddr
[4]; /* Virtual address of item */
339 char r_symndx
[4]; /* Symbol index in the symtab */
340 char r_type
[2]; /* Relocation type */
343 #define COFF_RELOC struct COFF_reloc
344 #define COFF_RELSZ 10
346 #define COFF_DEF_DATA_SECTION_ALIGNMENT 4
347 #define COFF_DEF_BSS_SECTION_ALIGNMENT 4
348 #define COFF_DEF_TEXT_SECTION_ALIGNMENT 4
350 /* For new sections we haven't heard of before */
351 #define COFF_DEF_SECTION_ALIGNMENT 4
This page took 0.037838 seconds and 5 git commands to generate.