xref: /openbsd-src/gnu/usr.bin/binutils/include/elf/mips.h (revision e93f7393d476ad1c5192174ea92f14ecc97182e7)
1 /* MIPS ELF support for BFD.
2    Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
3 
4    By Ian Lance Taylor, Cygnus Support, <ian@cygnus.com>, from
5    information in the System V Application Binary Interface, MIPS
6    Processor Supplement.
7 
8 This file is part of BFD, the Binary File Descriptor library.
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
23 
24 /* This file holds definitions specific to the MIPS ELF ABI.  Note
25    that most of this is not actually implemented by BFD.  */
26 
27 #ifndef _ELF_MIPS_H
28 #define _ELF_MIPS_H
29 
30 /* Processor specific flags for the ELF header e_flags field.  */
31 
32 /* At least one .noreorder directive appears in the source.  */
33 #define EF_MIPS_NOREORDER	0x00000001
34 
35 /* File contains position independent code.  */
36 #define EF_MIPS_PIC		0x00000002
37 
38 /* Code in file uses the standard calling sequence for calling
39    position independent code.  */
40 #define EF_MIPS_CPIC		0x00000004
41 
42 /* Code in file uses new ABI (-n32 on Irix 6).  */
43 #define EF_MIPS_ABI2		0x00000020
44 
45 /* Four bit MIPS architecture field.  */
46 #define EF_MIPS_ARCH		0xf0000000
47 
48 /* -mips1 code.  */
49 #define E_MIPS_ARCH_1		0x00000000
50 
51 /* -mips2 code.  */
52 #define E_MIPS_ARCH_2		0x10000000
53 
54 /* -mips3 code.  */
55 #define E_MIPS_ARCH_3		0x20000000
56 
57 /* -mips4 code.  */
58 #define E_MIPS_ARCH_4		0x30000000
59 
60 /* Processor specific section indices.  These sections do not actually
61    exist.  Symbols with a st_shndx field corresponding to one of these
62    values have a special meaning.  */
63 
64 /* Defined and allocated common symbol.  Value is virtual address.  If
65    relocated, alignment must be preserved.  */
66 #define SHN_MIPS_ACOMMON	0xff00
67 
68 /* Defined and allocated text symbol.  Value is virtual address.
69    Occur in the dynamic symbol table of Alpha OSF/1 and Irix 5 executables.  */
70 #define SHN_MIPS_TEXT		0xff01
71 
72 /* Defined and allocated data symbol.  Value is virtual address.
73    Occur in the dynamic symbol table of Alpha OSF/1 and Irix 5 executables.  */
74 #define SHN_MIPS_DATA		0xff02
75 
76 /* Small common symbol.  */
77 #define SHN_MIPS_SCOMMON	0xff03
78 
79 /* Small undefined symbol.  */
80 #define SHN_MIPS_SUNDEFINED	0xff04
81 
82 /* Processor specific section types.  */
83 
84 /* Section contains the set of dynamic shared objects used when
85    statically linking.  */
86 #define SHT_MIPS_LIBLIST	0x70000000
87 
88 /* I'm not sure what this is, but it's used on Irix 5.  */
89 #define SHT_MIPS_MSYM		0x70000001
90 
91 /* Section contains list of symbols whose definitions conflict with
92    symbols defined in shared objects.  */
93 #define SHT_MIPS_CONFLICT	0x70000002
94 
95 /* Section contains the global pointer table.  */
96 #define SHT_MIPS_GPTAB		0x70000003
97 
98 /* Section contains microcode information.  The exact format is
99    unspecified.  */
100 #define SHT_MIPS_UCODE		0x70000004
101 
102 /* Section contains some sort of debugging information.  The exact
103    format is unspecified.  It's probably ECOFF symbols.  */
104 #define SHT_MIPS_DEBUG		0x70000005
105 
106 /* Section contains register usage information.  */
107 #define SHT_MIPS_REGINFO	0x70000006
108 
109 /* Section contains interface information.  */
110 #define SHT_MIPS_IFACE		0x7000000b
111 
112 /* Section contains description of contents of another section.  */
113 #define SHT_MIPS_CONTENT	0x7000000c
114 
115 /* Section contains miscellaneous options.  */
116 #define SHT_MIPS_OPTIONS	0x7000000d
117 
118 /* DWARF debugging section.  */
119 #define SHT_MIPS_DWARF		0x7000001e
120 
121 /* I'm not sure what this is, but it appears on Irix 6.  */
122 #define SHT_MIPS_SYMBOL_LIB	0x70000020
123 
124 /* Events section.  */
125 #define SHT_MIPS_EVENTS		0x70000021
126 
127 /* A section of type SHT_MIPS_LIBLIST contains an array of the
128    following structure.  The sh_link field is the section index of the
129    string table.  The sh_info field is the number of entries in the
130    section.  */
131 typedef struct
132 {
133   /* String table index for name of shared object.  */
134   unsigned long l_name;
135   /* Time stamp.  */
136   unsigned long l_time_stamp;
137   /* Checksum of symbol names and common sizes.  */
138   unsigned long l_checksum;
139   /* String table index for version.  */
140   unsigned long l_version;
141   /* Flags.  */
142   unsigned long l_flags;
143 } Elf32_Lib;
144 
145 /* The l_flags field of an Elf32_Lib structure may contain the
146    following flags.  */
147 
148 /* Require an exact match at runtime.  */
149 #define LL_EXACT_MATCH		0x00000001
150 
151 /* Ignore version incompatibilities at runtime.  */
152 #define LL_IGNORE_INT_VER	0x00000002
153 
154 /* A section of type SHT_MIPS_CONFLICT is an array of indices into the
155    .dynsym section.  Each element has the following type.  */
156 typedef unsigned long Elf32_Conflict;
157 
158 /* A section of type SHT_MIPS_GPTAB contains information about how
159    much GP space would be required for different -G arguments.  This
160    information is only used so that the linker can provide informative
161    suggestions as to the best -G value to use.  The sh_info field is
162    the index of the section for which this information applies.  The
163    contents of the section are an array of the following union.  The
164    first element uses the gt_header field.  The remaining elements use
165    the gt_entry field.  */
166 typedef union
167 {
168   struct
169     {
170       /* -G value actually used for this object file.  */
171       unsigned long gt_current_g_value;
172       /* Unused.  */
173       unsigned long gt_unused;
174     } gt_header;
175   struct
176     {
177       /* If this -G argument has been used...  */
178       unsigned long gt_g_value;
179       /* ...this many GP section bytes would be required.  */
180       unsigned long gt_bytes;
181     } gt_entry;
182 } Elf32_gptab;
183 
184 /* The external version of Elf32_gptab.  */
185 
186 typedef union
187 {
188   struct
189     {
190       unsigned char gt_current_g_value[4];
191       unsigned char gt_unused[4];
192     } gt_header;
193   struct
194     {
195       unsigned char gt_g_value[4];
196       unsigned char gt_bytes[4];
197     } gt_entry;
198 } Elf32_External_gptab;
199 
200 /* A section of type SHT_MIPS_REGINFO contains the following
201    structure.  */
202 typedef struct
203 {
204   /* Mask of general purpose registers used.  */
205   unsigned long ri_gprmask;
206   /* Mask of co-processor registers used.  */
207   unsigned long ri_cprmask[4];
208   /* GP register value for this object file.  */
209   long ri_gp_value;
210 } Elf32_RegInfo;
211 
212 /* The external version of the Elf_RegInfo structure.  */
213 typedef struct
214 {
215   unsigned char ri_gprmask[4];
216   unsigned char ri_cprmask[4][4];
217   unsigned char ri_gp_value[4];
218 } Elf32_External_RegInfo;
219 
220 /* MIPS ELF .reginfo swapping routines.  */
221 extern void bfd_mips_elf32_swap_reginfo_in
222   PARAMS ((bfd *, const Elf32_External_RegInfo *, Elf32_RegInfo *));
223 extern void bfd_mips_elf32_swap_reginfo_out
224   PARAMS ((bfd *, const Elf32_RegInfo *, Elf32_External_RegInfo *));
225 
226 /* Processor specific section flags.  */
227 
228 /* This section must be in the global data area.  */
229 #define SHF_MIPS_GPREL		0x10000000
230 
231 /* This section should be merged.  */
232 #define SHF_MIPS_MERGE		0x20000000
233 
234 /* This section contains 32 bit addresses.  */
235 #define SHF_MIPS_ADDR32		0x40000000
236 
237 /* This section contains 64 bit addresses.  */
238 #define SHF_MIPS_ADDR64		0x80000000
239 
240 /* This section may not be stripped.  */
241 #define SHF_MIPS_NOSTRIP	0x08000000
242 
243 /* This section is local to threads.  */
244 #define SHF_MIPS_LOCAL		0x04000000
245 
246 /* Linker should generate implicit weak names for this section.  */
247 #define SHF_MIPS_NAMES		0x02000000
248 
249 /* Processor specific program header types.  */
250 
251 /* Register usage information.  Identifies one .reginfo section.  */
252 #define PT_MIPS_REGINFO		0x70000000
253 
254 /* Runtime procedure table.  */
255 #define PT_MIPS_RTPROC		0x70000001
256 
257 /* Processor specific dynamic array tags.  */
258 
259 /* 32 bit version number for runtime linker interface.  */
260 #define DT_MIPS_RLD_VERSION	0x70000001
261 
262 /* Time stamp.  */
263 #define DT_MIPS_TIME_STAMP	0x70000002
264 
265 /* Checksum of external strings and common sizes.  */
266 #define DT_MIPS_ICHECKSUM	0x70000003
267 
268 /* Index of version string in string table.  */
269 #define DT_MIPS_IVERSION	0x70000004
270 
271 /* 32 bits of flags.  */
272 #define DT_MIPS_FLAGS		0x70000005
273 
274 /* Base address of the segment.  */
275 #define DT_MIPS_BASE_ADDRESS	0x70000006
276 
277 /* Address of .conflict section.  */
278 #define DT_MIPS_CONFLICT	0x70000008
279 
280 /* Address of .liblist section.  */
281 #define DT_MIPS_LIBLIST		0x70000009
282 
283 /* Number of local global offset table entries.  */
284 #define DT_MIPS_LOCAL_GOTNO	0x7000000a
285 
286 /* Number of entries in the .conflict section.  */
287 #define DT_MIPS_CONFLICTNO	0x7000000b
288 
289 /* Number of entries in the .liblist section.  */
290 #define DT_MIPS_LIBLISTNO	0x70000010
291 
292 /* Number of entries in the .dynsym section.  */
293 #define DT_MIPS_SYMTABNO	0x70000011
294 
295 /* Index of first external dynamic symbol not referenced locally.  */
296 #define DT_MIPS_UNREFEXTNO	0x70000012
297 
298 /* Index of first dynamic symbol in global offset table.  */
299 #define DT_MIPS_GOTSYM		0x70000013
300 
301 /* Number of page table entries in global offset table.  */
302 #define DT_MIPS_HIPAGENO	0x70000014
303 
304 /* Address of run time loader map, used for debugging.  */
305 #define DT_MIPS_RLD_MAP		0x70000016
306 
307 /* Flags which may appear in a DT_MIPS_FLAGS entry.  */
308 
309 /* No flags.  */
310 #define RHF_NONE		0x00000000
311 
312 /* Uses shortcut pointers.  */
313 #define RHF_QUICKSTART		0x00000001
314 
315 /* Hash size is not a power of two.  */
316 #define RHF_NOTPOT		0x00000002
317 
318 /* Ignore LD_LIBRARY_PATH.  */
319 #define RHS_NO_LIBRARY_REPLACEMENT \
320 				0x00000004
321 
322 /* Special values for the st_other field in the symbol table.  These
323    are used in an Irix 5 dynamic symbol table.  */
324 
325 #define STO_DEFAULT		0x00
326 #define STO_INTERNAL		0x01
327 #define STO_HIDDEN		0x02
328 #define STO_PROTECTED		0x03
329 
330 /* The 64-bit MIPS ELF ABI uses an usual reloc format.  Each
331    relocation entry specifies up to three actual relocations, all at
332    the same address.  The first relocation which required a symbol
333    uses the symbol in the r_sym field.  The second relocation which
334    requires a symbol uses the symbol in the r_ssym field.  If all
335    three relocations require a symbol, the third one uses a zero
336    value.  */
337 
338 /* An entry in a 64 bit SHT_REL section.  */
339 
340 typedef struct
341 {
342   /* Address of relocation.  */
343   unsigned char r_offset[8];
344   /* Symbol index.  */
345   unsigned char r_sym[4];
346   /* Special symbol.  */
347   unsigned char r_ssym[1];
348   /* Third relocation.  */
349   unsigned char r_type3[1];
350   /* Second relocation.  */
351   unsigned char r_type2[1];
352   /* First relocation.  */
353   unsigned char r_type[1];
354 } Elf64_Mips_External_Rel;
355 
356 typedef struct
357 {
358   /* Address of relocation.  */
359   bfd_vma r_offset;
360   /* Symbol index.  */
361   unsigned long r_sym;
362   /* Special symbol.  */
363   unsigned char r_ssym;
364   /* Third relocation.  */
365   unsigned char r_type3;
366   /* Second relocation.  */
367   unsigned char r_type2;
368   /* First relocation.  */
369   unsigned char r_type;
370 } Elf64_Mips_Internal_Rel;
371 
372 /* An entry in a 64 bit SHT_RELA section.  */
373 
374 typedef struct
375 {
376   /* Address of relocation.  */
377   unsigned char r_offset[8];
378   /* Symbol index.  */
379   unsigned char r_sym[4];
380   /* Special symbol.  */
381   unsigned char r_ssym[1];
382   /* Third relocation.  */
383   unsigned char r_type3[1];
384   /* Second relocation.  */
385   unsigned char r_type2[1];
386   /* First relocation.  */
387   unsigned char r_type[1];
388   /* Addend.  */
389   unsigned char r_addend[8];
390 } Elf64_Mips_External_Rela;
391 
392 typedef struct
393 {
394   /* Address of relocation.  */
395   bfd_vma r_offset;
396   /* Symbol index.  */
397   unsigned long r_sym;
398   /* Special symbol.  */
399   unsigned char r_ssym;
400   /* Third relocation.  */
401   unsigned char r_type3;
402   /* Second relocation.  */
403   unsigned char r_type2;
404   /* First relocation.  */
405   unsigned char r_type;
406   /* Addend.  */
407   bfd_signed_vma r_addend;
408 } Elf64_Mips_Internal_Rela;
409 
410 /* Values found in the r_ssym field of a relocation entry.  */
411 
412 /* No relocation.  */
413 #define RSS_UNDEF	0
414 
415 /* Value of GP.  */
416 #define RSS_GP		1
417 
418 /* Value of GP in object being relocated.  */
419 #define RSS_GP0		2
420 
421 /* Address of location being relocated.  */
422 #define RSS_LOC		3
423 
424 /* A SHT_MIPS_OPTIONS section contains a series of options, each of
425    which starts with this header.  */
426 
427 typedef struct
428 {
429   /* Type of option.  */
430   unsigned char kind[1];
431   /* Size of option descriptor, including header.  */
432   unsigned char size[1];
433   /* Section index of affected section, or 0 for global option.  */
434   unsigned char section[2];
435   /* Information specific to this kind of option.  */
436   unsigned char info[4];
437 } Elf_External_Options;
438 
439 typedef struct
440 {
441   /* Type of option.  */
442   unsigned char kind;
443   /* Size of option descriptor, including header.  */
444   unsigned char size;
445   /* Section index of affected section, or 0 for global option.  */
446   unsigned short section;
447   /* Information specific to this kind of option.  */
448   unsigned long info;
449 } Elf_Internal_Options;
450 
451 /* MIPS ELF option header swapping routines.  */
452 extern void bfd_mips_elf_swap_options_in
453   PARAMS ((bfd *, const Elf_External_Options *, Elf_Internal_Options *));
454 extern void bfd_mips_elf_swap_options_out
455   PARAMS ((bfd *, const Elf_Internal_Options *, Elf_External_Options *));
456 
457 /* Values which may appear in the kind field of an Elf_Options
458    structure.  */
459 
460 /* Undefined.  */
461 #define ODK_NULL	0
462 
463 /* Register usage and GP value.  */
464 #define ODK_REGINFO	1
465 
466 /* Exception processing information.  */
467 #define ODK_EXCEPTIONS	2
468 
469 /* Section padding information.  */
470 #define ODK_PAD		3
471 
472 /* In the 32 bit ABI, an ODK_REGINFO option is just a Elf32_Reginfo
473    structure.  In the 64 bit ABI, it is the following structure.  The
474    info field of the options header is not used.  */
475 
476 typedef struct
477 {
478   /* Mask of general purpose registers used.  */
479   unsigned char ri_gprmask[4];
480   /* Padding.  */
481   unsigned char ri_pad[4];
482   /* Mask of co-processor registers used.  */
483   unsigned char ri_cprmask[4][4];
484   /* GP register value for this object file.  */
485   unsigned char ri_gp_value[8];
486 } Elf64_External_RegInfo;
487 
488 typedef struct
489 {
490   /* Mask of general purpose registers used.  */
491   unsigned long ri_gprmask;
492   /* Padding.  */
493   unsigned long ri_pad;
494   /* Mask of co-processor registers used.  */
495   unsigned long ri_cprmask[4];
496   /* GP register value for this object file.  */
497   bfd_vma ri_gp_value;
498 } Elf64_Internal_RegInfo;
499 
500 /* MIPS ELF reginfo swapping routines.  */
501 extern void bfd_mips_elf64_swap_reginfo_in
502   PARAMS ((bfd *, const Elf64_External_RegInfo *, Elf64_Internal_RegInfo *));
503 extern void bfd_mips_elf64_swap_reginfo_out
504   PARAMS ((bfd *, const Elf64_Internal_RegInfo *, Elf64_External_RegInfo *));
505 
506 #endif /* _ELF_MIPS_H */
507