Commit | Line | Data |
---|---|---|
b3c0fc57 | 1 | /* MIPS-specific support for 32-bit ELF |
5b3b9ff6 | 2 | Copyright 1993, 1994, 1995, 1996 Free Software Foundation, Inc. |
6b4b4d17 | 3 | |
b3c0fc57 ILT |
4 | Most of the information added by Ian Lance Taylor, Cygnus Support, |
5 | <ian@cygnus.com>. | |
6 | ||
6b4b4d17 JK |
7 | This file is part of BFD, the Binary File Descriptor library. |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with this program; if not, write to the Free Software | |
3fe22b98 | 21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
6b4b4d17 | 22 | |
5b3b9ff6 ILT |
23 | /* This file handles MIPS ELF targets. SGI Irix 5 uses a slightly |
24 | different MIPS ELF from other targets. This matters when linking. | |
25 | This file supports both, switching at runtime. */ | |
26 | ||
6b4b4d17 JK |
27 | #include "bfd.h" |
28 | #include "sysdep.h" | |
29 | #include "libbfd.h" | |
6e07e54f ILT |
30 | #include "bfdlink.h" |
31 | #include "genlink.h" | |
6ab826bd | 32 | #include "elf-bfd.h" |
b3c0fc57 ILT |
33 | #include "elf/mips.h" |
34 | ||
6e07e54f ILT |
35 | /* Get the ECOFF swapping routines. */ |
36 | #include "coff/sym.h" | |
37 | #include "coff/symconst.h" | |
38 | #include "coff/internal.h" | |
39 | #include "coff/ecoff.h" | |
40 | #include "coff/mips.h" | |
41 | #define ECOFF_32 | |
42 | #include "ecoffswap.h" | |
43 | ||
b3c0fc57 ILT |
44 | static bfd_reloc_status_type mips_elf_hi16_reloc PARAMS ((bfd *abfd, |
45 | arelent *reloc, | |
46 | asymbol *symbol, | |
47 | PTR data, | |
48 | asection *section, | |
6e07e54f ILT |
49 | bfd *output_bfd, |
50 | char **error)); | |
51 | static bfd_reloc_status_type mips_elf_got16_reloc PARAMS ((bfd *abfd, | |
52 | arelent *reloc, | |
53 | asymbol *symbol, | |
54 | PTR data, | |
55 | asection *section, | |
56 | bfd *output_bfd, | |
57 | char **error)); | |
b3c0fc57 ILT |
58 | static bfd_reloc_status_type mips_elf_lo16_reloc PARAMS ((bfd *abfd, |
59 | arelent *reloc, | |
60 | asymbol *symbol, | |
61 | PTR data, | |
62 | asection *section, | |
6e07e54f ILT |
63 | bfd *output_bfd, |
64 | char **error)); | |
b3c0fc57 ILT |
65 | static bfd_reloc_status_type mips_elf_gprel16_reloc PARAMS ((bfd *abfd, |
66 | arelent *reloc, | |
67 | asymbol *symbol, | |
68 | PTR data, | |
69 | asection *section, | |
6e07e54f ILT |
70 | bfd *output_bfd, |
71 | char **error)); | |
5b3b9ff6 ILT |
72 | static bfd_reloc_status_type mips_elf_gprel32_reloc PARAMS ((bfd *abfd, |
73 | arelent *reloc, | |
74 | asymbol *symbol, | |
75 | PTR data, | |
76 | asection *section, | |
77 | bfd *output_bfd, | |
78 | char **error)); | |
16fe8950 | 79 | static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup |
aac6b32f ILT |
80 | PARAMS ((bfd *, bfd_reloc_code_real_type)); |
81 | static void mips_info_to_howto_rel | |
82 | PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *)); | |
53787b23 ILT |
83 | static void bfd_mips_elf32_swap_gptab_in |
84 | PARAMS ((bfd *, const Elf32_External_gptab *, Elf32_gptab *)); | |
85 | static void bfd_mips_elf32_swap_gptab_out | |
86 | PARAMS ((bfd *, const Elf32_gptab *, Elf32_External_gptab *)); | |
aac6b32f | 87 | static boolean mips_elf_sym_is_global PARAMS ((bfd *, asymbol *)); |
00176555 | 88 | static boolean mips_elf32_object_p PARAMS ((bfd *)); |
5b3b9ff6 ILT |
89 | static boolean mips_elf_create_procedure_table |
90 | PARAMS ((PTR, bfd *, struct bfd_link_info *, asection *, | |
91 | struct ecoff_debug_info *)); | |
92 | static int mips_elf_additional_program_headers PARAMS ((bfd *)); | |
93 | static boolean mips_elf_modify_segment_map PARAMS ((bfd *)); | |
53787b23 ILT |
94 | static boolean mips_elf_set_private_flags PARAMS ((bfd *, flagword)); |
95 | static boolean mips_elf_copy_private_bfd_data PARAMS ((bfd *, bfd *)); | |
96 | static boolean mips_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *)); | |
d1bf45aa | 97 | static boolean mips_elf32_section_from_shdr |
aac6b32f | 98 | PARAMS ((bfd *, Elf32_Internal_Shdr *, char *)); |
00176555 | 99 | static boolean mips_elf32_section_processing |
aac6b32f | 100 | PARAMS ((bfd *, Elf32_Internal_Shdr *)); |
a2546fce ILT |
101 | static boolean mips_elf_is_local_label |
102 | PARAMS ((bfd *, asymbol *)); | |
a16fcab3 KR |
103 | static boolean mips_elf_find_nearest_line |
104 | PARAMS ((bfd *, asection *, asymbol **, bfd_vma, const char **, | |
105 | const char **, unsigned int *)); | |
aac6b32f ILT |
106 | static struct bfd_hash_entry *mips_elf_link_hash_newfunc |
107 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); | |
108 | static struct bfd_link_hash_table *mips_elf_link_hash_table_create | |
109 | PARAMS ((bfd *)); | |
110 | static int gptab_compare PARAMS ((const void *, const void *)); | |
111 | static boolean mips_elf_final_link | |
112 | PARAMS ((bfd *, struct bfd_link_info *)); | |
113 | static void mips_elf_relocate_hi16 | |
114 | PARAMS ((bfd *, Elf_Internal_Rela *, Elf_Internal_Rela *, bfd_byte *, | |
115 | bfd_vma)); | |
5b3b9ff6 ILT |
116 | static void mips_elf_relocate_got_local |
117 | PARAMS ((bfd *, bfd *, asection *, Elf_Internal_Rela *, | |
118 | Elf_Internal_Rela *, bfd_byte *, bfd_vma)); | |
119 | static void mips_elf_relocate_global_got | |
120 | PARAMS ((bfd *, Elf_Internal_Rela *, bfd_byte *, bfd_vma)); | |
121 | static boolean mips_elf_adjust_dynindx | |
122 | PARAMS ((struct elf_link_hash_entry *, PTR)); | |
aac6b32f ILT |
123 | static boolean mips_elf_relocate_section |
124 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
82b1edf7 | 125 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); |
53787b23 ILT |
126 | static boolean mips_elf_create_dynamic_sections |
127 | PARAMS ((bfd *, struct bfd_link_info *)); | |
128 | static boolean mips_elf_create_compact_rel_section | |
129 | PARAMS ((bfd *, struct bfd_link_info *)); | |
130 | static boolean mips_elf_create_got_section | |
131 | PARAMS ((bfd *, struct bfd_link_info *)); | |
132 | static boolean mips_elf_check_relocs | |
133 | PARAMS ((bfd *, struct bfd_link_info *, asection *, | |
134 | const Elf_Internal_Rela *)); | |
135 | static boolean mips_elf_adjust_dynamic_symbol | |
136 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); | |
137 | static boolean mips_elf_size_dynamic_sections | |
138 | PARAMS ((bfd *, struct bfd_link_info *)); | |
139 | static boolean mips_elf_finish_dynamic_symbol | |
140 | PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, | |
141 | Elf_Internal_Sym *)); | |
142 | static boolean mips_elf_finish_dynamic_sections | |
143 | PARAMS ((bfd *, struct bfd_link_info *)); | |
aac6b32f ILT |
144 | static boolean mips_elf_add_symbol_hook |
145 | PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *, | |
146 | const char **, flagword *, asection **, bfd_vma *)); | |
5b3b9ff6 | 147 | static bfd_reloc_status_type mips_elf_final_gp |
abec70b9 | 148 | PARAMS ((bfd *, asymbol *, boolean, char **, bfd_vma *)); |
53787b23 ILT |
149 | static bfd_byte *elf32_mips_get_relocated_section_contents |
150 | PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, | |
151 | bfd_byte *, boolean, asymbol **)); | |
5b3b9ff6 ILT |
152 | |
153 | /* This is true for Irix 5 executables, false for normal MIPS ELF ABI | |
154 | executables. FIXME: At the moment, we default to always generating | |
155 | Irix 5 executables. */ | |
156 | ||
157 | #define SGI_COMPAT(abfd) (1) | |
158 | ||
159 | /* This structure is used to hold .got information when linking. It | |
160 | is stored in the tdata field of the bfd_elf_section_data structure. */ | |
161 | ||
162 | struct mips_got_info | |
163 | { | |
164 | /* The symbol index of the first global .got symbol. */ | |
165 | unsigned long global_gotsym; | |
166 | /* The number of local .got entries. */ | |
167 | unsigned int local_gotno; | |
168 | }; | |
169 | ||
170 | /* The number of local .got entries we reserve. */ | |
171 | #define MIPS_RESERVED_GOTNO (2) | |
172 | ||
173 | /* Instructions which appear in a stub. For some reason the stub is | |
174 | slightly different on an SGI system. */ | |
175 | #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000) | |
176 | #define STUB_LW(abfd) \ | |
177 | (SGI_COMPAT (abfd) \ | |
178 | ? 0x8f998010 /* lw t9,0x8010(gp) */ \ | |
179 | : 0x8f998000) /* lw t9,0x8000(gp) */ | |
180 | #define STUB_MOVE 0x03e07825 /* move t7,ra */ | |
181 | #define STUB_JALR 0x0320f809 /* jal t9 */ | |
182 | #define STUB_LI16 0x34180000 /* ori t8,zero,0 */ | |
183 | #define MIPS_FUNCTION_STUB_SIZE (16) | |
184 | ||
185 | /* Names of sections which appear in the .dynsym section in an Irix 5 | |
186 | executable. */ | |
187 | ||
188 | static const char * const mips_elf_dynsym_sec_names[] = | |
189 | { | |
190 | ".text", | |
191 | ".init", | |
192 | ".fini", | |
193 | ".data", | |
194 | ".rodata", | |
195 | ".sdata", | |
196 | ".sbss", | |
197 | ".bss", | |
198 | NULL | |
199 | }; | |
200 | ||
201 | #define SIZEOF_MIPS_DYNSYM_SECNAMES \ | |
202 | (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0]) | |
203 | ||
204 | /* The number of entries in mips_elf_dynsym_sec_names which go in the | |
205 | text segment. */ | |
206 | ||
207 | #define MIPS_TEXT_DYNSYM_SECNO (3) | |
208 | ||
209 | /* The names of the runtime procedure table symbols used on Irix 5. */ | |
210 | ||
211 | static const char * const mips_elf_dynsym_rtproc_names[] = | |
212 | { | |
213 | "_procedure_table", | |
214 | "_procedure_string_table", | |
215 | "_procedure_table_size", | |
216 | NULL | |
217 | }; | |
218 | ||
219 | /* These structures are used to generate the .compact_rel section on | |
220 | Irix 5. */ | |
221 | ||
222 | typedef struct | |
223 | { | |
224 | unsigned long id1; /* Always one? */ | |
225 | unsigned long num; /* Number of compact relocation entries. */ | |
226 | unsigned long id2; /* Always two? */ | |
227 | unsigned long offset; /* The file offset of the first relocation. */ | |
228 | unsigned long reserved0; /* Zero? */ | |
229 | unsigned long reserved1; /* Zero? */ | |
230 | } Elf32_compact_rel; | |
231 | ||
232 | typedef struct | |
233 | { | |
234 | bfd_byte id1[4]; | |
235 | bfd_byte num[4]; | |
236 | bfd_byte id2[4]; | |
237 | bfd_byte offset[4]; | |
238 | bfd_byte reserved0[4]; | |
239 | bfd_byte reserved1[4]; | |
240 | } Elf32_External_compact_rel; | |
241 | ||
242 | typedef struct | |
243 | { | |
053baeb1 ILT |
244 | unsigned int ctype : 1; /* 1: long 0: short format. See below. */ |
245 | unsigned int rtype : 4; /* Relocation types. See below. */ | |
246 | unsigned int dist2to : 8; | |
247 | unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */ | |
5b3b9ff6 ILT |
248 | unsigned long konst; /* KONST field. See below. */ |
249 | unsigned long vaddr; /* VADDR to be relocated. */ | |
250 | } Elf32_crinfo; | |
251 | ||
252 | typedef struct | |
253 | { | |
053baeb1 ILT |
254 | unsigned int ctype : 1; /* 1: long 0: short format. See below. */ |
255 | unsigned int rtype : 4; /* Relocation types. See below. */ | |
256 | unsigned int dist2to : 8; | |
257 | unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */ | |
5b3b9ff6 ILT |
258 | unsigned long konst; /* KONST field. See below. */ |
259 | } Elf32_crinfo2; | |
260 | ||
261 | typedef struct | |
262 | { | |
263 | bfd_byte info[4]; | |
264 | bfd_byte konst[4]; | |
265 | bfd_byte vaddr[4]; | |
266 | } Elf32_External_crinfo; | |
267 | ||
268 | typedef struct | |
269 | { | |
270 | bfd_byte info[4]; | |
271 | bfd_byte konst[4]; | |
272 | } Elf32_External_crinfo2; | |
273 | ||
053baeb1 ILT |
274 | /* These are the constants used to swap the bitfields in a crinfo. */ |
275 | ||
276 | #define CRINFO_CTYPE (0x1) | |
277 | #define CRINFO_CTYPE_SH (31) | |
278 | #define CRINFO_RTYPE (0xf) | |
279 | #define CRINFO_RTYPE_SH (27) | |
280 | #define CRINFO_DIST2TO (0xff) | |
281 | #define CRINFO_DIST2TO_SH (19) | |
282 | #define CRINFO_RELVADDR (0x7ffff) | |
283 | #define CRINFO_RELVADDR_SH (0) | |
284 | ||
5b3b9ff6 ILT |
285 | /* A compact relocation info has long (3 words) or short (2 words) |
286 | formats. A short format doesn't have VADDR field and relvaddr | |
287 | fields contains ((VADDR - vaddr of the previous entry) >> 2). */ | |
288 | #define CRF_MIPS_LONG 1 | |
289 | #define CRF_MIPS_SHORT 0 | |
290 | ||
291 | /* There are 4 types of compact relocation at least. The value KONST | |
292 | has different meaning for each type: | |
293 | ||
294 | (type) (konst) | |
295 | CT_MIPS_REL32 Address in data | |
296 | CT_MIPS_WORD Address in word (XXX) | |
297 | CT_MIPS_GPHI_LO GP - vaddr | |
298 | CT_MIPS_JMPAD Address to jump | |
299 | */ | |
300 | ||
301 | #define CRT_MIPS_REL32 0xa | |
302 | #define CRT_MIPS_WORD 0xb | |
303 | #define CRT_MIPS_GPHI_LO 0xc | |
304 | #define CRT_MIPS_JMPAD 0xd | |
305 | ||
053baeb1 ILT |
306 | #define mips_elf_set_cr_format(x,format) ((x).ctype = (format)) |
307 | #define mips_elf_set_cr_type(x,type) ((x).rtype = (type)) | |
308 | #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v)) | |
309 | #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2) | |
b3c0fc57 | 310 | |
53787b23 ILT |
311 | static void bfd_elf32_swap_compact_rel_out |
312 | PARAMS ((bfd *, const Elf32_compact_rel *, Elf32_External_compact_rel *)); | |
313 | static void bfd_elf32_swap_crinfo_out | |
314 | PARAMS ((bfd *, const Elf32_crinfo *, Elf32_External_crinfo *)); | |
315 | ||
b3c0fc57 ILT |
316 | #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */ |
317 | ||
318 | enum reloc_type | |
319 | { | |
320 | R_MIPS_NONE = 0, | |
321 | R_MIPS_16, R_MIPS_32, | |
322 | R_MIPS_REL32, R_MIPS_26, | |
323 | R_MIPS_HI16, R_MIPS_LO16, | |
324 | R_MIPS_GPREL16, R_MIPS_LITERAL, | |
325 | R_MIPS_GOT16, R_MIPS_PC16, | |
326 | R_MIPS_CALL16, R_MIPS_GPREL32, | |
6a5848cd ILT |
327 | /* The remaining relocs are defined on Irix, although they are not |
328 | in the MIPS ELF ABI. */ | |
329 | R_MIPS_UNUSED1, R_MIPS_UNUSED2, | |
330 | R_MIPS_UNUSED3, | |
331 | R_MIPS_SHIFT5, R_MIPS_SHIFT6, | |
332 | R_MIPS_64, R_MIPS_GOT_DISP, | |
333 | R_MIPS_GOT_PAGE, R_MIPS_GOT_OFST, | |
334 | R_MIPS_GOT_HI16, R_MIPS_GOT_LO16, | |
335 | R_MIPS_SUB, R_MIPS_INSERT_A, | |
336 | R_MIPS_INSERT_B, R_MIPS_DELETE, | |
337 | R_MIPS_HIGHER, R_MIPS_HIGHEST, | |
338 | R_MIPS_CALL_HI16, R_MIPS_CALL_LO16, | |
b3c0fc57 ILT |
339 | R_MIPS_max |
340 | }; | |
341 | ||
342 | static reloc_howto_type elf_mips_howto_table[] = | |
343 | { | |
344 | /* No relocation. */ | |
345 | HOWTO (R_MIPS_NONE, /* type */ | |
346 | 0, /* rightshift */ | |
347 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
348 | 0, /* bitsize */ | |
349 | false, /* pc_relative */ | |
350 | 0, /* bitpos */ | |
351 | complain_overflow_dont, /* complain_on_overflow */ | |
352 | bfd_elf_generic_reloc, /* special_function */ | |
353 | "R_MIPS_NONE", /* name */ | |
354 | false, /* partial_inplace */ | |
355 | 0, /* src_mask */ | |
356 | 0, /* dst_mask */ | |
357 | false), /* pcrel_offset */ | |
358 | ||
359 | /* 16 bit relocation. */ | |
360 | HOWTO (R_MIPS_16, /* type */ | |
361 | 0, /* rightshift */ | |
362 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
363 | 16, /* bitsize */ | |
364 | false, /* pc_relative */ | |
365 | 0, /* bitpos */ | |
366 | complain_overflow_bitfield, /* complain_on_overflow */ | |
367 | bfd_elf_generic_reloc, /* special_function */ | |
368 | "R_MIPS_16", /* name */ | |
369 | true, /* partial_inplace */ | |
370 | 0xffff, /* src_mask */ | |
371 | 0xffff, /* dst_mask */ | |
372 | false), /* pcrel_offset */ | |
373 | ||
374 | /* 32 bit relocation. */ | |
375 | HOWTO (R_MIPS_32, /* type */ | |
376 | 0, /* rightshift */ | |
377 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
378 | 32, /* bitsize */ | |
379 | false, /* pc_relative */ | |
380 | 0, /* bitpos */ | |
381 | complain_overflow_bitfield, /* complain_on_overflow */ | |
382 | bfd_elf_generic_reloc, /* special_function */ | |
383 | "R_MIPS_32", /* name */ | |
384 | true, /* partial_inplace */ | |
385 | 0xffffffff, /* src_mask */ | |
386 | 0xffffffff, /* dst_mask */ | |
387 | false), /* pcrel_offset */ | |
388 | ||
389 | /* 32 bit symbol relative relocation. */ | |
390 | HOWTO (R_MIPS_REL32, /* type */ | |
391 | 0, /* rightshift */ | |
392 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
393 | 32, /* bitsize */ | |
394 | false, /* pc_relative */ | |
395 | 0, /* bitpos */ | |
396 | complain_overflow_bitfield, /* complain_on_overflow */ | |
397 | bfd_elf_generic_reloc, /* special_function */ | |
398 | "R_MIPS_REL32", /* name */ | |
399 | true, /* partial_inplace */ | |
400 | 0xffffffff, /* src_mask */ | |
401 | 0xffffffff, /* dst_mask */ | |
402 | false), /* pcrel_offset */ | |
403 | ||
404 | /* 26 bit branch address. */ | |
405 | HOWTO (R_MIPS_26, /* type */ | |
406 | 2, /* rightshift */ | |
407 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
408 | 26, /* bitsize */ | |
409 | false, /* pc_relative */ | |
410 | 0, /* bitpos */ | |
6e07e54f ILT |
411 | complain_overflow_dont, /* complain_on_overflow */ |
412 | /* This needs complex overflow | |
413 | detection, because the upper four | |
414 | bits must match the PC. */ | |
b3c0fc57 ILT |
415 | bfd_elf_generic_reloc, /* special_function */ |
416 | "R_MIPS_26", /* name */ | |
417 | true, /* partial_inplace */ | |
418 | 0x3ffffff, /* src_mask */ | |
419 | 0x3ffffff, /* dst_mask */ | |
420 | false), /* pcrel_offset */ | |
421 | ||
422 | /* High 16 bits of symbol value. */ | |
423 | HOWTO (R_MIPS_HI16, /* type */ | |
424 | 0, /* rightshift */ | |
425 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
426 | 16, /* bitsize */ | |
427 | false, /* pc_relative */ | |
428 | 0, /* bitpos */ | |
429 | complain_overflow_dont, /* complain_on_overflow */ | |
430 | mips_elf_hi16_reloc, /* special_function */ | |
431 | "R_MIPS_HI16", /* name */ | |
432 | true, /* partial_inplace */ | |
433 | 0xffff, /* src_mask */ | |
434 | 0xffff, /* dst_mask */ | |
435 | false), /* pcrel_offset */ | |
436 | ||
437 | /* Low 16 bits of symbol value. */ | |
438 | HOWTO (R_MIPS_LO16, /* type */ | |
439 | 0, /* rightshift */ | |
440 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
441 | 16, /* bitsize */ | |
442 | false, /* pc_relative */ | |
443 | 0, /* bitpos */ | |
444 | complain_overflow_dont, /* complain_on_overflow */ | |
445 | mips_elf_lo16_reloc, /* special_function */ | |
446 | "R_MIPS_LO16", /* name */ | |
447 | true, /* partial_inplace */ | |
448 | 0xffff, /* src_mask */ | |
449 | 0xffff, /* dst_mask */ | |
450 | false), /* pcrel_offset */ | |
451 | ||
452 | /* GP relative reference. */ | |
453 | HOWTO (R_MIPS_GPREL16, /* type */ | |
454 | 0, /* rightshift */ | |
455 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
456 | 16, /* bitsize */ | |
457 | false, /* pc_relative */ | |
458 | 0, /* bitpos */ | |
459 | complain_overflow_signed, /* complain_on_overflow */ | |
460 | mips_elf_gprel16_reloc, /* special_function */ | |
461 | "R_MIPS_GPREL16", /* name */ | |
462 | true, /* partial_inplace */ | |
463 | 0xffff, /* src_mask */ | |
464 | 0xffff, /* dst_mask */ | |
465 | false), /* pcrel_offset */ | |
466 | ||
467 | /* Reference to literal section. */ | |
468 | HOWTO (R_MIPS_LITERAL, /* type */ | |
469 | 0, /* rightshift */ | |
470 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
471 | 16, /* bitsize */ | |
472 | false, /* pc_relative */ | |
473 | 0, /* bitpos */ | |
474 | complain_overflow_signed, /* complain_on_overflow */ | |
475 | mips_elf_gprel16_reloc, /* special_function */ | |
476 | "R_MIPS_LITERAL", /* name */ | |
477 | true, /* partial_inplace */ | |
478 | 0xffff, /* src_mask */ | |
479 | 0xffff, /* dst_mask */ | |
480 | false), /* pcrel_offset */ | |
481 | ||
482 | /* Reference to global offset table. */ | |
b3c0fc57 ILT |
483 | HOWTO (R_MIPS_GOT16, /* type */ |
484 | 0, /* rightshift */ | |
485 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
486 | 16, /* bitsize */ | |
487 | false, /* pc_relative */ | |
488 | 0, /* bitpos */ | |
489 | complain_overflow_signed, /* complain_on_overflow */ | |
6e07e54f | 490 | mips_elf_got16_reloc, /* special_function */ |
b3c0fc57 ILT |
491 | "R_MIPS_GOT16", /* name */ |
492 | false, /* partial_inplace */ | |
493 | 0, /* src_mask */ | |
494 | 0xffff, /* dst_mask */ | |
495 | false), /* pcrel_offset */ | |
496 | ||
497 | /* 16 bit PC relative reference. */ | |
498 | HOWTO (R_MIPS_PC16, /* type */ | |
499 | 0, /* rightshift */ | |
500 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
501 | 16, /* bitsize */ | |
502 | true, /* pc_relative */ | |
503 | 0, /* bitpos */ | |
504 | complain_overflow_signed, /* complain_on_overflow */ | |
505 | bfd_elf_generic_reloc, /* special_function */ | |
506 | "R_MIPS_PC16", /* name */ | |
507 | true, /* partial_inplace */ | |
508 | 0xffff, /* src_mask */ | |
509 | 0xffff, /* dst_mask */ | |
510 | false), /* pcrel_offset */ | |
511 | ||
512 | /* 16 bit call through global offset table. */ | |
513 | /* FIXME: This is not handled correctly. */ | |
514 | HOWTO (R_MIPS_CALL16, /* type */ | |
515 | 0, /* rightshift */ | |
516 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
517 | 16, /* bitsize */ | |
518 | false, /* pc_relative */ | |
519 | 0, /* bitpos */ | |
520 | complain_overflow_signed, /* complain_on_overflow */ | |
521 | bfd_elf_generic_reloc, /* special_function */ | |
522 | "R_MIPS_CALL16", /* name */ | |
523 | false, /* partial_inplace */ | |
524 | 0, /* src_mask */ | |
525 | 0xffff, /* dst_mask */ | |
526 | false), /* pcrel_offset */ | |
527 | ||
528 | /* 32 bit GP relative reference. */ | |
b3c0fc57 ILT |
529 | HOWTO (R_MIPS_GPREL32, /* type */ |
530 | 0, /* rightshift */ | |
531 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
532 | 32, /* bitsize */ | |
533 | false, /* pc_relative */ | |
534 | 0, /* bitpos */ | |
535 | complain_overflow_bitfield, /* complain_on_overflow */ | |
5b3b9ff6 | 536 | mips_elf_gprel32_reloc, /* special_function */ |
b3c0fc57 ILT |
537 | "R_MIPS_GPREL32", /* name */ |
538 | true, /* partial_inplace */ | |
539 | 0xffffffff, /* src_mask */ | |
540 | 0xffffffff, /* dst_mask */ | |
6a5848cd ILT |
541 | false), /* pcrel_offset */ |
542 | ||
543 | /* The remaining relocs are defined on Irix 5, although they are | |
544 | not defined by the ABI. */ | |
545 | { 13 }, | |
546 | { 14 }, | |
547 | { 15 }, | |
548 | ||
549 | /* A 5 bit shift field. */ | |
550 | HOWTO (R_MIPS_SHIFT5, /* type */ | |
551 | 0, /* rightshift */ | |
552 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
553 | 5, /* bitsize */ | |
554 | false, /* pc_relative */ | |
555 | 6, /* bitpos */ | |
556 | complain_overflow_bitfield, /* complain_on_overflow */ | |
557 | bfd_elf_generic_reloc, /* special_function */ | |
558 | "R_MIPS_SHIFT5", /* name */ | |
559 | true, /* partial_inplace */ | |
560 | 0x000007c0, /* src_mask */ | |
561 | 0x000007c0, /* dst_mask */ | |
562 | false), /* pcrel_offset */ | |
563 | ||
564 | /* A 6 bit shift field. */ | |
565 | /* FIXME: This is not handled correctly; a special function is | |
566 | needed to put the most significant bit in the right place. */ | |
567 | HOWTO (R_MIPS_SHIFT6, /* type */ | |
568 | 0, /* rightshift */ | |
569 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
570 | 6, /* bitsize */ | |
571 | false, /* pc_relative */ | |
572 | 6, /* bitpos */ | |
573 | complain_overflow_bitfield, /* complain_on_overflow */ | |
574 | bfd_elf_generic_reloc, /* special_function */ | |
575 | "R_MIPS_SHIFT6", /* name */ | |
576 | true, /* partial_inplace */ | |
577 | 0x000007c4, /* src_mask */ | |
578 | 0x000007c4, /* dst_mask */ | |
579 | false), /* pcrel_offset */ | |
580 | ||
581 | /* A 64 bit relocation. Presumably not used in 32 bit ELF. */ | |
582 | { R_MIPS_64 }, | |
583 | ||
584 | /* Displacement in the global offset table. */ | |
585 | /* FIXME: Not handled correctly. */ | |
586 | HOWTO (R_MIPS_GOT_DISP, /* type */ | |
587 | 0, /* rightshift */ | |
588 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
589 | 16, /* bitsize */ | |
590 | false, /* pc_relative */ | |
591 | 0, /* bitpos */ | |
592 | complain_overflow_bitfield, /* complain_on_overflow */ | |
593 | bfd_elf_generic_reloc, /* special_function */ | |
594 | "R_MIPS_GOT_DISP", /* name */ | |
595 | true, /* partial_inplace */ | |
596 | 0x0000ffff, /* src_mask */ | |
597 | 0x0000ffff, /* dst_mask */ | |
598 | false), /* pcrel_offset */ | |
599 | ||
600 | /* Displacement to page pointer in the global offset table. */ | |
601 | /* FIXME: Not handled correctly. */ | |
602 | HOWTO (R_MIPS_GOT_PAGE, /* type */ | |
603 | 0, /* rightshift */ | |
604 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
605 | 16, /* bitsize */ | |
606 | false, /* pc_relative */ | |
607 | 0, /* bitpos */ | |
608 | complain_overflow_bitfield, /* complain_on_overflow */ | |
609 | bfd_elf_generic_reloc, /* special_function */ | |
610 | "R_MIPS_GOT_PAGE", /* name */ | |
611 | true, /* partial_inplace */ | |
612 | 0x0000ffff, /* src_mask */ | |
613 | 0x0000ffff, /* dst_mask */ | |
614 | false), /* pcrel_offset */ | |
615 | ||
616 | /* Offset from page pointer in the global offset table. */ | |
617 | /* FIXME: Not handled correctly. */ | |
618 | HOWTO (R_MIPS_GOT_OFST, /* type */ | |
619 | 0, /* rightshift */ | |
620 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
621 | 16, /* bitsize */ | |
622 | false, /* pc_relative */ | |
623 | 0, /* bitpos */ | |
624 | complain_overflow_bitfield, /* complain_on_overflow */ | |
625 | bfd_elf_generic_reloc, /* special_function */ | |
626 | "R_MIPS_GOT_OFST", /* name */ | |
627 | true, /* partial_inplace */ | |
628 | 0x0000ffff, /* src_mask */ | |
629 | 0x0000ffff, /* dst_mask */ | |
630 | false), /* pcrel_offset */ | |
631 | ||
632 | /* High 16 bits of displacement in global offset table. */ | |
633 | /* FIXME: Not handled correctly. */ | |
634 | HOWTO (R_MIPS_GOT_HI16, /* type */ | |
635 | 0, /* rightshift */ | |
636 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
637 | 16, /* bitsize */ | |
638 | false, /* pc_relative */ | |
639 | 0, /* bitpos */ | |
640 | complain_overflow_dont, /* complain_on_overflow */ | |
641 | bfd_elf_generic_reloc, /* special_function */ | |
642 | "R_MIPS_GOT_HI16", /* name */ | |
643 | true, /* partial_inplace */ | |
644 | 0x0000ffff, /* src_mask */ | |
645 | 0x0000ffff, /* dst_mask */ | |
646 | false), /* pcrel_offset */ | |
647 | ||
648 | /* Low 16 bits of displacement in global offset table. */ | |
649 | /* FIXME: Not handled correctly. */ | |
650 | HOWTO (R_MIPS_GOT_LO16, /* type */ | |
651 | 0, /* rightshift */ | |
652 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
653 | 16, /* bitsize */ | |
654 | false, /* pc_relative */ | |
655 | 0, /* bitpos */ | |
656 | complain_overflow_dont, /* complain_on_overflow */ | |
657 | bfd_elf_generic_reloc, /* special_function */ | |
658 | "R_MIPS_GOT_LO16", /* name */ | |
659 | true, /* partial_inplace */ | |
660 | 0x0000ffff, /* src_mask */ | |
661 | 0x0000ffff, /* dst_mask */ | |
662 | false), /* pcrel_offset */ | |
663 | ||
664 | /* 64 bit subtraction. Presumably not used in 32 bit ELF. */ | |
665 | { R_MIPS_SUB }, | |
666 | ||
667 | /* Used to cause the linker to insert and delete instructions? */ | |
668 | { R_MIPS_INSERT_A }, | |
669 | { R_MIPS_INSERT_B }, | |
670 | { R_MIPS_DELETE }, | |
671 | ||
672 | /* Get the higher values of a 64 bit addend. Presumably not used in | |
673 | 32 bit ELF. */ | |
674 | { R_MIPS_HIGHER }, | |
675 | { R_MIPS_HIGHEST }, | |
676 | ||
677 | /* High 16 bits of displacement in global offset table. */ | |
678 | /* FIXME: Not handled correctly. */ | |
679 | HOWTO (R_MIPS_CALL_HI16, /* type */ | |
680 | 0, /* rightshift */ | |
681 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
682 | 16, /* bitsize */ | |
683 | false, /* pc_relative */ | |
684 | 0, /* bitpos */ | |
685 | complain_overflow_dont, /* complain_on_overflow */ | |
686 | bfd_elf_generic_reloc, /* special_function */ | |
687 | "R_MIPS_CALL_HI16", /* name */ | |
688 | true, /* partial_inplace */ | |
689 | 0x0000ffff, /* src_mask */ | |
690 | 0x0000ffff, /* dst_mask */ | |
691 | false), /* pcrel_offset */ | |
692 | ||
693 | /* Low 16 bits of displacement in global offset table. */ | |
694 | /* FIXME: Not handled correctly. */ | |
695 | HOWTO (R_MIPS_CALL_LO16, /* type */ | |
696 | 0, /* rightshift */ | |
697 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
698 | 16, /* bitsize */ | |
699 | false, /* pc_relative */ | |
700 | 0, /* bitpos */ | |
701 | complain_overflow_dont, /* complain_on_overflow */ | |
702 | bfd_elf_generic_reloc, /* special_function */ | |
703 | "R_MIPS_CALL_LO16", /* name */ | |
704 | true, /* partial_inplace */ | |
705 | 0x0000ffff, /* src_mask */ | |
706 | 0x0000ffff, /* dst_mask */ | |
b3c0fc57 ILT |
707 | false) /* pcrel_offset */ |
708 | }; | |
709 | ||
710 | /* Do a R_MIPS_HI16 relocation. This has to be done in combination | |
711 | with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to | |
712 | the HI16. Here we just save the information we need; we do the | |
713 | actual relocation when we see the LO16. MIPS ELF requires that the | |
abec70b9 ILT |
714 | LO16 immediately follow the HI16. As a GNU extension, we permit an |
715 | arbitrary number of HI16 relocs to be associated with a single LO16 | |
716 | reloc. This extension permits gcc to output the HI and LO relocs | |
717 | itself. */ | |
b3c0fc57 | 718 | |
abec70b9 ILT |
719 | struct mips_hi16 |
720 | { | |
721 | struct mips_hi16 *next; | |
722 | bfd_byte *addr; | |
723 | bfd_vma addend; | |
724 | }; | |
725 | ||
726 | /* FIXME: This should not be a static variable. */ | |
727 | ||
728 | static struct mips_hi16 *mips_hi16_list; | |
b3c0fc57 ILT |
729 | |
730 | static bfd_reloc_status_type | |
731 | mips_elf_hi16_reloc (abfd, | |
732 | reloc_entry, | |
733 | symbol, | |
734 | data, | |
735 | input_section, | |
6e07e54f ILT |
736 | output_bfd, |
737 | error_message) | |
b3c0fc57 ILT |
738 | bfd *abfd; |
739 | arelent *reloc_entry; | |
740 | asymbol *symbol; | |
741 | PTR data; | |
742 | asection *input_section; | |
743 | bfd *output_bfd; | |
6e07e54f | 744 | char **error_message; |
b3c0fc57 ILT |
745 | { |
746 | bfd_reloc_status_type ret; | |
747 | bfd_vma relocation; | |
abec70b9 | 748 | struct mips_hi16 *n; |
b3c0fc57 | 749 | |
b3c0fc57 ILT |
750 | /* If we're relocating, and this an external symbol, we don't want |
751 | to change anything. */ | |
752 | if (output_bfd != (bfd *) NULL | |
753 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
754 | && reloc_entry->addend == 0) | |
755 | { | |
756 | reloc_entry->address += input_section->output_offset; | |
757 | return bfd_reloc_ok; | |
758 | } | |
759 | ||
5b3b9ff6 ILT |
760 | ret = bfd_reloc_ok; |
761 | ||
6e07e54f | 762 | if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0) |
5b3b9ff6 ILT |
763 | { |
764 | boolean relocateable; | |
abec70b9 | 765 | bfd_vma gp; |
6e07e54f | 766 | |
5b3b9ff6 ILT |
767 | if (ret == bfd_reloc_undefined) |
768 | abort (); | |
b3c0fc57 | 769 | |
5b3b9ff6 ILT |
770 | if (output_bfd != NULL) |
771 | relocateable = true; | |
772 | else | |
773 | { | |
774 | relocateable = false; | |
775 | output_bfd = symbol->section->output_section->owner; | |
776 | } | |
777 | ||
778 | ret = mips_elf_final_gp (output_bfd, symbol, relocateable, | |
abec70b9 | 779 | error_message, &gp); |
5b3b9ff6 ILT |
780 | if (ret != bfd_reloc_ok) |
781 | return ret; | |
782 | ||
abec70b9 | 783 | relocation = gp - reloc_entry->address; |
5b3b9ff6 | 784 | } |
b3c0fc57 | 785 | else |
5b3b9ff6 ILT |
786 | { |
787 | if (bfd_is_und_section (symbol->section) | |
788 | && output_bfd == (bfd *) NULL) | |
789 | ret = bfd_reloc_undefined; | |
790 | ||
791 | if (bfd_is_com_section (symbol->section)) | |
792 | relocation = 0; | |
793 | else | |
794 | relocation = symbol->value; | |
795 | } | |
b3c0fc57 ILT |
796 | |
797 | relocation += symbol->section->output_section->vma; | |
798 | relocation += symbol->section->output_offset; | |
799 | relocation += reloc_entry->addend; | |
800 | ||
801 | if (reloc_entry->address > input_section->_cooked_size) | |
802 | return bfd_reloc_outofrange; | |
803 | ||
804 | /* Save the information, and let LO16 do the actual relocation. */ | |
abec70b9 ILT |
805 | n = (struct mips_hi16 *) bfd_malloc (sizeof *n); |
806 | if (n == NULL) | |
807 | return bfd_reloc_outofrange; | |
808 | n->addr = (bfd_byte *) data + reloc_entry->address; | |
809 | n->addend = relocation; | |
810 | n->next = mips_hi16_list; | |
811 | mips_hi16_list = n; | |
b3c0fc57 ILT |
812 | |
813 | if (output_bfd != (bfd *) NULL) | |
814 | reloc_entry->address += input_section->output_offset; | |
815 | ||
816 | return ret; | |
817 | } | |
818 | ||
819 | /* Do a R_MIPS_LO16 relocation. This is a straightforward 16 bit | |
820 | inplace relocation; this function exists in order to do the | |
821 | R_MIPS_HI16 relocation described above. */ | |
822 | ||
823 | static bfd_reloc_status_type | |
824 | mips_elf_lo16_reloc (abfd, | |
825 | reloc_entry, | |
826 | symbol, | |
827 | data, | |
828 | input_section, | |
6e07e54f ILT |
829 | output_bfd, |
830 | error_message) | |
b3c0fc57 ILT |
831 | bfd *abfd; |
832 | arelent *reloc_entry; | |
833 | asymbol *symbol; | |
834 | PTR data; | |
835 | asection *input_section; | |
836 | bfd *output_bfd; | |
6e07e54f | 837 | char **error_message; |
b3c0fc57 | 838 | { |
5b3b9ff6 | 839 | arelent gp_disp_relent; |
b3c0fc57 | 840 | |
abec70b9 | 841 | if (mips_hi16_list != NULL) |
b3c0fc57 | 842 | { |
abec70b9 ILT |
843 | struct mips_hi16 *l; |
844 | ||
845 | l = mips_hi16_list; | |
846 | while (l != NULL) | |
5b3b9ff6 | 847 | { |
abec70b9 ILT |
848 | unsigned long insn; |
849 | unsigned long val; | |
850 | unsigned long vallo; | |
851 | struct mips_hi16 *next; | |
852 | ||
853 | /* Do the HI16 relocation. Note that we actually don't need | |
854 | to know anything about the LO16 itself, except where to | |
855 | find the low 16 bits of the addend needed by the LO16. */ | |
856 | insn = bfd_get_32 (abfd, l->addr); | |
857 | vallo = (bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address) | |
858 | & 0xffff); | |
859 | val = ((insn & 0xffff) << 16) + vallo; | |
860 | val += l->addend; | |
861 | ||
862 | /* The low order 16 bits are always treated as a signed | |
863 | value. Therefore, a negative value in the low order bits | |
864 | requires an adjustment in the high order bits. We need | |
865 | to make this adjustment in two ways: once for the bits we | |
866 | took from the data, and once for the bits we are putting | |
867 | back in to the data. */ | |
868 | if ((vallo & 0x8000) != 0) | |
869 | val -= 0x10000; | |
870 | if ((val & 0x8000) != 0) | |
871 | val += 0x10000; | |
872 | ||
873 | insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff); | |
874 | bfd_put_32 (abfd, insn, l->addr); | |
875 | ||
876 | if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0) | |
877 | { | |
878 | gp_disp_relent = *reloc_entry; | |
879 | reloc_entry = &gp_disp_relent; | |
880 | reloc_entry->addend = l->addend; | |
881 | } | |
882 | ||
883 | next = l->next; | |
884 | free (l); | |
885 | l = next; | |
5b3b9ff6 | 886 | } |
abec70b9 ILT |
887 | |
888 | mips_hi16_list = NULL; | |
5b3b9ff6 ILT |
889 | } |
890 | else if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0) | |
891 | { | |
892 | bfd_reloc_status_type ret; | |
abec70b9 | 893 | bfd_vma gp, relocation; |
5b3b9ff6 ILT |
894 | |
895 | /* FIXME: Does this case ever occur? */ | |
896 | ||
abec70b9 | 897 | ret = mips_elf_final_gp (output_bfd, symbol, true, error_message, &gp); |
5b3b9ff6 ILT |
898 | if (ret != bfd_reloc_ok) |
899 | return ret; | |
900 | ||
abec70b9 | 901 | relocation = gp - reloc_entry->address; |
5b3b9ff6 ILT |
902 | relocation += symbol->section->output_section->vma; |
903 | relocation += symbol->section->output_offset; | |
904 | relocation += reloc_entry->addend; | |
905 | ||
906 | if (reloc_entry->address > input_section->_cooked_size) | |
907 | return bfd_reloc_outofrange; | |
908 | ||
909 | gp_disp_relent = *reloc_entry; | |
910 | reloc_entry = &gp_disp_relent; | |
911 | reloc_entry->addend = relocation - 4; | |
b3c0fc57 ILT |
912 | } |
913 | ||
914 | /* Now do the LO16 reloc in the usual way. */ | |
915 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, | |
6e07e54f ILT |
916 | input_section, output_bfd, error_message); |
917 | } | |
918 | ||
919 | /* Do a R_MIPS_GOT16 reloc. This is a reloc against the global offset | |
920 | table used for PIC code. If the symbol is an external symbol, the | |
921 | instruction is modified to contain the offset of the appropriate | |
922 | entry in the global offset table. If the symbol is a section | |
923 | symbol, the next reloc is a R_MIPS_LO16 reloc. The two 16 bit | |
924 | addends are combined to form the real addend against the section | |
925 | symbol; the GOT16 is modified to contain the offset of an entry in | |
926 | the global offset table, and the LO16 is modified to offset it | |
927 | appropriately. Thus an offset larger than 16 bits requires a | |
928 | modified value in the global offset table. | |
929 | ||
930 | This implementation suffices for the assembler, but the linker does | |
931 | not yet know how to create global offset tables. */ | |
932 | ||
933 | static bfd_reloc_status_type | |
934 | mips_elf_got16_reloc (abfd, | |
935 | reloc_entry, | |
936 | symbol, | |
937 | data, | |
938 | input_section, | |
939 | output_bfd, | |
940 | error_message) | |
941 | bfd *abfd; | |
942 | arelent *reloc_entry; | |
943 | asymbol *symbol; | |
944 | PTR data; | |
945 | asection *input_section; | |
946 | bfd *output_bfd; | |
947 | char **error_message; | |
948 | { | |
949 | /* If we're relocating, and this an external symbol, we don't want | |
950 | to change anything. */ | |
951 | if (output_bfd != (bfd *) NULL | |
952 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
953 | && reloc_entry->addend == 0) | |
954 | { | |
955 | reloc_entry->address += input_section->output_offset; | |
956 | return bfd_reloc_ok; | |
957 | } | |
958 | ||
959 | /* If we're relocating, and this is a local symbol, we can handle it | |
960 | just like HI16. */ | |
961 | if (output_bfd != (bfd *) NULL | |
962 | && (symbol->flags & BSF_SECTION_SYM) != 0) | |
963 | return mips_elf_hi16_reloc (abfd, reloc_entry, symbol, data, | |
964 | input_section, output_bfd, error_message); | |
965 | ||
966 | abort (); | |
b3c0fc57 ILT |
967 | } |
968 | ||
5b3b9ff6 ILT |
969 | /* We have to figure out the gp value, so that we can adjust the |
970 | symbol value correctly. We look up the symbol _gp in the output | |
971 | BFD. If we can't find it, we're stuck. We cache it in the ELF | |
972 | target data. We don't need to adjust the symbol value for an | |
973 | external symbol if we are producing relocateable output. */ | |
a16fcab3 | 974 | |
b3c0fc57 | 975 | static bfd_reloc_status_type |
abec70b9 | 976 | mips_elf_final_gp (output_bfd, symbol, relocateable, error_message, pgp) |
b3c0fc57 | 977 | bfd *output_bfd; |
5b3b9ff6 ILT |
978 | asymbol *symbol; |
979 | boolean relocateable; | |
6e07e54f | 980 | char **error_message; |
abec70b9 | 981 | bfd_vma *pgp; |
b3c0fc57 | 982 | { |
24f13b03 | 983 | if (bfd_is_und_section (symbol->section) |
5b3b9ff6 | 984 | && ! relocateable) |
abec70b9 ILT |
985 | { |
986 | *pgp = 0; | |
987 | return bfd_reloc_undefined; | |
988 | } | |
a16fcab3 | 989 | |
abec70b9 ILT |
990 | *pgp = _bfd_get_gp_value (output_bfd); |
991 | if (*pgp == 0 | |
5b3b9ff6 | 992 | && (! relocateable |
b3c0fc57 ILT |
993 | || (symbol->flags & BSF_SECTION_SYM) != 0)) |
994 | { | |
5b3b9ff6 | 995 | if (relocateable) |
b3c0fc57 ILT |
996 | { |
997 | /* Make up a value. */ | |
abec70b9 ILT |
998 | *pgp = symbol->section->output_section->vma + 0x4000; |
999 | _bfd_set_gp_value (output_bfd, *pgp); | |
b3c0fc57 ILT |
1000 | } |
1001 | else | |
1002 | { | |
1003 | unsigned int count; | |
1004 | asymbol **sym; | |
1005 | unsigned int i; | |
1006 | ||
1007 | count = bfd_get_symcount (output_bfd); | |
1008 | sym = bfd_get_outsymbols (output_bfd); | |
1009 | ||
1010 | if (sym == (asymbol **) NULL) | |
1011 | i = count; | |
1012 | else | |
1013 | { | |
1014 | for (i = 0; i < count; i++, sym++) | |
1015 | { | |
1016 | register CONST char *name; | |
1017 | ||
1018 | name = bfd_asymbol_name (*sym); | |
1019 | if (*name == '_' && strcmp (name, "_gp") == 0) | |
1020 | { | |
abec70b9 ILT |
1021 | *pgp = bfd_asymbol_value (*sym); |
1022 | _bfd_set_gp_value (output_bfd, *pgp); | |
b3c0fc57 ILT |
1023 | break; |
1024 | } | |
1025 | } | |
1026 | } | |
1027 | ||
1028 | if (i >= count) | |
1029 | { | |
1030 | /* Only get the error once. */ | |
abec70b9 ILT |
1031 | *pgp = 4; |
1032 | _bfd_set_gp_value (output_bfd, *pgp); | |
6e07e54f ILT |
1033 | *error_message = |
1034 | (char *) "GP relative relocation when _gp not defined"; | |
b3c0fc57 ILT |
1035 | return bfd_reloc_dangerous; |
1036 | } | |
1037 | } | |
1038 | } | |
1039 | ||
5b3b9ff6 ILT |
1040 | return bfd_reloc_ok; |
1041 | } | |
1042 | ||
1043 | /* Do a R_MIPS_GPREL16 relocation. This is a 16 bit value which must | |
1044 | become the offset from the gp register. This function also handles | |
1045 | R_MIPS_LITERAL relocations, although those can be handled more | |
1046 | cleverly because the entries in the .lit8 and .lit4 sections can be | |
1047 | merged. */ | |
1048 | ||
1049 | static bfd_reloc_status_type gprel16_with_gp PARAMS ((bfd *, asymbol *, | |
1050 | arelent *, asection *, | |
1051 | boolean, PTR, bfd_vma)); | |
1052 | ||
1053 | static bfd_reloc_status_type | |
1054 | mips_elf_gprel16_reloc (abfd, | |
1055 | reloc_entry, | |
1056 | symbol, | |
1057 | data, | |
1058 | input_section, | |
1059 | output_bfd, | |
1060 | error_message) | |
1061 | bfd *abfd; | |
1062 | arelent *reloc_entry; | |
1063 | asymbol *symbol; | |
1064 | PTR data; | |
1065 | asection *input_section; | |
1066 | bfd *output_bfd; | |
1067 | char **error_message; | |
1068 | { | |
1069 | boolean relocateable; | |
1070 | bfd_reloc_status_type ret; | |
abec70b9 | 1071 | bfd_vma gp; |
5b3b9ff6 ILT |
1072 | |
1073 | /* If we're relocating, and this is an external symbol with no | |
1074 | addend, we don't want to change anything. We will only have an | |
1075 | addend if this is a newly created reloc, not read from an ELF | |
1076 | file. */ | |
1077 | if (output_bfd != (bfd *) NULL | |
1078 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
1079 | && reloc_entry->addend == 0) | |
1080 | { | |
1081 | reloc_entry->address += input_section->output_offset; | |
1082 | return bfd_reloc_ok; | |
1083 | } | |
1084 | ||
1085 | if (output_bfd != (bfd *) NULL) | |
1086 | relocateable = true; | |
1087 | else | |
1088 | { | |
1089 | relocateable = false; | |
1090 | output_bfd = symbol->section->output_section->owner; | |
1091 | } | |
1092 | ||
abec70b9 ILT |
1093 | ret = mips_elf_final_gp (output_bfd, symbol, relocateable, error_message, |
1094 | &gp); | |
5b3b9ff6 ILT |
1095 | if (ret != bfd_reloc_ok) |
1096 | return ret; | |
1097 | ||
a2546fce | 1098 | return gprel16_with_gp (abfd, symbol, reloc_entry, input_section, |
abec70b9 | 1099 | relocateable, data, gp); |
a16fcab3 KR |
1100 | } |
1101 | ||
1102 | static bfd_reloc_status_type | |
1103 | gprel16_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data, | |
1104 | gp) | |
1105 | bfd *abfd; | |
1106 | asymbol *symbol; | |
1107 | arelent *reloc_entry; | |
1108 | asection *input_section; | |
1109 | boolean relocateable; | |
1110 | PTR data; | |
1111 | bfd_vma gp; | |
1112 | { | |
1113 | bfd_vma relocation; | |
1114 | unsigned long insn; | |
1115 | unsigned long val; | |
1116 | ||
b3c0fc57 ILT |
1117 | if (bfd_is_com_section (symbol->section)) |
1118 | relocation = 0; | |
1119 | else | |
1120 | relocation = symbol->value; | |
1121 | ||
1122 | relocation += symbol->section->output_section->vma; | |
1123 | relocation += symbol->section->output_offset; | |
1124 | ||
1125 | if (reloc_entry->address > input_section->_cooked_size) | |
1126 | return bfd_reloc_outofrange; | |
1127 | ||
1128 | insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address); | |
1129 | ||
1130 | /* Set val to the offset into the section or symbol. */ | |
1131 | val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff; | |
1132 | if (val & 0x8000) | |
1133 | val -= 0x10000; | |
1134 | ||
1135 | /* Adjust val for the final section location and GP value. If we | |
1136 | are producing relocateable output, we don't want to do this for | |
1137 | an external symbol. */ | |
5b3b9ff6 | 1138 | if (! relocateable |
b3c0fc57 | 1139 | || (symbol->flags & BSF_SECTION_SYM) != 0) |
a16fcab3 | 1140 | val += relocation - gp; |
b3c0fc57 ILT |
1141 | |
1142 | insn = (insn &~ 0xffff) | (val & 0xffff); | |
1143 | bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address); | |
1144 | ||
5b3b9ff6 | 1145 | if (relocateable) |
b3c0fc57 ILT |
1146 | reloc_entry->address += input_section->output_offset; |
1147 | ||
1148 | /* Make sure it fit in 16 bits. */ | |
1149 | if (val >= 0x8000 && val < 0xffff8000) | |
6e07e54f | 1150 | return bfd_reloc_overflow; |
b3c0fc57 ILT |
1151 | |
1152 | return bfd_reloc_ok; | |
1153 | } | |
6b4b4d17 | 1154 | |
5b3b9ff6 ILT |
1155 | /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset |
1156 | from the gp register? XXX */ | |
1157 | ||
1158 | static bfd_reloc_status_type gprel32_with_gp PARAMS ((bfd *, asymbol *, | |
1159 | arelent *, asection *, | |
1160 | boolean, PTR, bfd_vma)); | |
1161 | ||
1162 | static bfd_reloc_status_type | |
1163 | mips_elf_gprel32_reloc (abfd, | |
1164 | reloc_entry, | |
1165 | symbol, | |
1166 | data, | |
1167 | input_section, | |
1168 | output_bfd, | |
1169 | error_message) | |
1170 | bfd *abfd; | |
1171 | arelent *reloc_entry; | |
1172 | asymbol *symbol; | |
1173 | PTR data; | |
1174 | asection *input_section; | |
1175 | bfd *output_bfd; | |
1176 | char **error_message; | |
1177 | { | |
1178 | boolean relocateable; | |
1179 | bfd_reloc_status_type ret; | |
abec70b9 | 1180 | bfd_vma gp; |
5b3b9ff6 ILT |
1181 | |
1182 | /* If we're relocating, and this is an external symbol with no | |
1183 | addend, we don't want to change anything. We will only have an | |
1184 | addend if this is a newly created reloc, not read from an ELF | |
1185 | file. */ | |
1186 | if (output_bfd != (bfd *) NULL | |
1187 | && (symbol->flags & BSF_SECTION_SYM) == 0 | |
1188 | && reloc_entry->addend == 0) | |
1189 | { | |
1190 | *error_message = (char *) | |
1191 | "32bits gp relative relocation occurs for an external symbol"; | |
1192 | return bfd_reloc_outofrange; | |
1193 | } | |
1194 | ||
1195 | if (output_bfd != (bfd *) NULL) | |
abec70b9 ILT |
1196 | { |
1197 | relocateable = true; | |
1198 | gp = _bfd_get_gp_value (output_bfd); | |
1199 | } | |
5b3b9ff6 ILT |
1200 | else |
1201 | { | |
1202 | relocateable = false; | |
1203 | output_bfd = symbol->section->output_section->owner; | |
1204 | ||
1205 | ret = mips_elf_final_gp (output_bfd, symbol, relocateable, | |
abec70b9 | 1206 | error_message, &gp); |
5b3b9ff6 ILT |
1207 | if (ret != bfd_reloc_ok) |
1208 | return ret; | |
1209 | } | |
1210 | ||
1211 | return gprel32_with_gp (abfd, symbol, reloc_entry, input_section, | |
abec70b9 | 1212 | relocateable, data, gp); |
5b3b9ff6 ILT |
1213 | } |
1214 | ||
1215 | static bfd_reloc_status_type | |
1216 | gprel32_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data, | |
1217 | gp) | |
1218 | bfd *abfd; | |
1219 | asymbol *symbol; | |
1220 | arelent *reloc_entry; | |
1221 | asection *input_section; | |
1222 | boolean relocateable; | |
1223 | PTR data; | |
1224 | bfd_vma gp; | |
1225 | { | |
1226 | bfd_vma relocation; | |
1227 | unsigned long val; | |
1228 | ||
1229 | if (bfd_is_com_section (symbol->section)) | |
1230 | relocation = 0; | |
1231 | else | |
1232 | relocation = symbol->value; | |
1233 | ||
1234 | relocation += symbol->section->output_section->vma; | |
1235 | relocation += symbol->section->output_offset; | |
1236 | ||
1237 | if (reloc_entry->address > input_section->_cooked_size) | |
1238 | return bfd_reloc_outofrange; | |
1239 | ||
1240 | val = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address); | |
1241 | ||
1242 | /* Set val to the offset into the section or symbol. */ | |
1243 | val += reloc_entry->addend; | |
1244 | ||
1245 | /* Adjust val for the final section location and GP value. If we | |
1246 | are producing relocateable output, we don't want to do this for | |
1247 | an external symbol. */ | |
1248 | if (! relocateable | |
1249 | || (symbol->flags & BSF_SECTION_SYM) != 0) | |
1250 | val += relocation - gp; | |
1251 | ||
1252 | bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address); | |
1253 | ||
1254 | if (relocateable) | |
1255 | reloc_entry->address += input_section->output_offset; | |
1256 | ||
1257 | return bfd_reloc_ok; | |
1258 | } | |
1259 | ||
b3c0fc57 | 1260 | /* A mapping from BFD reloc types to MIPS ELF reloc types. */ |
6b4b4d17 | 1261 | |
b3c0fc57 ILT |
1262 | struct elf_reloc_map { |
1263 | bfd_reloc_code_real_type bfd_reloc_val; | |
1264 | enum reloc_type elf_reloc_val; | |
1265 | }; | |
1266 | ||
1267 | static CONST struct elf_reloc_map mips_reloc_map[] = | |
1268 | { | |
1269 | { BFD_RELOC_NONE, R_MIPS_NONE, }, | |
1270 | { BFD_RELOC_16, R_MIPS_16 }, | |
1271 | { BFD_RELOC_32, R_MIPS_32 }, | |
1272 | { BFD_RELOC_CTOR, R_MIPS_32 }, | |
1273 | { BFD_RELOC_32_PCREL, R_MIPS_REL32 }, | |
1274 | { BFD_RELOC_MIPS_JMP, R_MIPS_26 }, | |
1275 | { BFD_RELOC_HI16_S, R_MIPS_HI16 }, | |
1276 | { BFD_RELOC_LO16, R_MIPS_LO16 }, | |
1277 | { BFD_RELOC_MIPS_GPREL, R_MIPS_GPREL16 }, | |
1278 | { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL }, | |
1279 | { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 }, | |
1280 | { BFD_RELOC_16_PCREL, R_MIPS_PC16 }, | |
1281 | { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 }, | |
e9f03cd4 ILT |
1282 | { BFD_RELOC_MIPS_GPREL32, R_MIPS_GPREL32 }, |
1283 | { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 }, | |
b7384d22 ILT |
1284 | { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 }, |
1285 | { BFD_RELOC_MIPS_CALL_HI16, R_MIPS_CALL_HI16 }, | |
1286 | { BFD_RELOC_MIPS_CALL_LO16, R_MIPS_CALL_LO16 } | |
b3c0fc57 ILT |
1287 | }; |
1288 | ||
1289 | /* Given a BFD reloc type, return a howto structure. */ | |
1290 | ||
16fe8950 | 1291 | static reloc_howto_type * |
b3c0fc57 ILT |
1292 | bfd_elf32_bfd_reloc_type_lookup (abfd, code) |
1293 | bfd *abfd; | |
1294 | bfd_reloc_code_real_type code; | |
1295 | { | |
6ab826bd | 1296 | unsigned int i; |
b3c0fc57 ILT |
1297 | |
1298 | for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map); i++) | |
1299 | { | |
1300 | if (mips_reloc_map[i].bfd_reloc_val == code) | |
1301 | return &elf_mips_howto_table[(int) mips_reloc_map[i].elf_reloc_val]; | |
1302 | } | |
1303 | return NULL; | |
1304 | } | |
1305 | ||
1306 | /* Given a MIPS reloc type, fill in an arelent structure. */ | |
1307 | ||
1308 | static void | |
1309 | mips_info_to_howto_rel (abfd, cache_ptr, dst) | |
1310 | bfd *abfd; | |
1311 | arelent *cache_ptr; | |
1312 | Elf32_Internal_Rel *dst; | |
1313 | { | |
1314 | unsigned int r_type; | |
1315 | ||
1316 | r_type = ELF32_R_TYPE (dst->r_info); | |
1317 | BFD_ASSERT (r_type < (unsigned int) R_MIPS_max); | |
1318 | cache_ptr->howto = &elf_mips_howto_table[r_type]; | |
1319 | ||
1320 | /* The addend for a GPREL16 or LITERAL relocation comes from the GP | |
1321 | value for the object file. We get the addend now, rather than | |
1322 | when we do the relocation, because the symbol manipulations done | |
1323 | by the linker may cause us to lose track of the input BFD. */ | |
1324 | if (((*cache_ptr->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0 | |
1325 | && (r_type == (unsigned int) R_MIPS_GPREL16 | |
1326 | || r_type == (unsigned int) R_MIPS_LITERAL)) | |
1327 | cache_ptr->addend = elf_gp (abfd); | |
1328 | } | |
1329 | \f | |
1330 | /* A .reginfo section holds a single Elf32_RegInfo structure. These | |
1331 | routines swap this structure in and out. They are used outside of | |
1332 | BFD, so they are globally visible. */ | |
1333 | ||
1334 | void | |
1335 | bfd_mips_elf32_swap_reginfo_in (abfd, ex, in) | |
1336 | bfd *abfd; | |
1337 | const Elf32_External_RegInfo *ex; | |
1338 | Elf32_RegInfo *in; | |
1339 | { | |
1340 | in->ri_gprmask = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gprmask); | |
1341 | in->ri_cprmask[0] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[0]); | |
1342 | in->ri_cprmask[1] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[1]); | |
1343 | in->ri_cprmask[2] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[2]); | |
1344 | in->ri_cprmask[3] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[3]); | |
1345 | in->ri_gp_value = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gp_value); | |
1346 | } | |
1347 | ||
1348 | void | |
1349 | bfd_mips_elf32_swap_reginfo_out (abfd, in, ex) | |
1350 | bfd *abfd; | |
1351 | const Elf32_RegInfo *in; | |
1352 | Elf32_External_RegInfo *ex; | |
1353 | { | |
1354 | bfd_h_put_32 (abfd, (bfd_vma) in->ri_gprmask, | |
1355 | (bfd_byte *) ex->ri_gprmask); | |
1356 | bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[0], | |
1357 | (bfd_byte *) ex->ri_cprmask[0]); | |
1358 | bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[1], | |
1359 | (bfd_byte *) ex->ri_cprmask[1]); | |
1360 | bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[2], | |
1361 | (bfd_byte *) ex->ri_cprmask[2]); | |
1362 | bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[3], | |
1363 | (bfd_byte *) ex->ri_cprmask[3]); | |
1364 | bfd_h_put_32 (abfd, (bfd_vma) in->ri_gp_value, | |
1365 | (bfd_byte *) ex->ri_gp_value); | |
1366 | } | |
aac6b32f ILT |
1367 | |
1368 | /* Swap an entry in a .gptab section. Note that these routines rely | |
1369 | on the equivalence of the two elements of the union. */ | |
1370 | ||
1371 | static void | |
1372 | bfd_mips_elf32_swap_gptab_in (abfd, ex, in) | |
1373 | bfd *abfd; | |
1374 | const Elf32_External_gptab *ex; | |
1375 | Elf32_gptab *in; | |
1376 | { | |
1377 | in->gt_entry.gt_g_value = bfd_h_get_32 (abfd, ex->gt_entry.gt_g_value); | |
1378 | in->gt_entry.gt_bytes = bfd_h_get_32 (abfd, ex->gt_entry.gt_bytes); | |
1379 | } | |
1380 | ||
1381 | static void | |
1382 | bfd_mips_elf32_swap_gptab_out (abfd, in, ex) | |
1383 | bfd *abfd; | |
1384 | const Elf32_gptab *in; | |
1385 | Elf32_External_gptab *ex; | |
1386 | { | |
1387 | bfd_h_put_32 (abfd, (bfd_vma) in->gt_entry.gt_g_value, | |
1388 | ex->gt_entry.gt_g_value); | |
1389 | bfd_h_put_32 (abfd, (bfd_vma) in->gt_entry.gt_bytes, | |
1390 | ex->gt_entry.gt_bytes); | |
1391 | } | |
5b3b9ff6 ILT |
1392 | |
1393 | static void | |
1394 | bfd_elf32_swap_compact_rel_out (abfd, in, ex) | |
1395 | bfd *abfd; | |
53787b23 | 1396 | const Elf32_compact_rel *in; |
5b3b9ff6 ILT |
1397 | Elf32_External_compact_rel *ex; |
1398 | { | |
1399 | bfd_h_put_32 (abfd, (bfd_vma) in->id1, ex->id1); | |
1400 | bfd_h_put_32 (abfd, (bfd_vma) in->num, ex->num); | |
1401 | bfd_h_put_32 (abfd, (bfd_vma) in->id2, ex->id2); | |
1402 | bfd_h_put_32 (abfd, (bfd_vma) in->offset, ex->offset); | |
1403 | bfd_h_put_32 (abfd, (bfd_vma) in->reserved0, ex->reserved0); | |
1404 | bfd_h_put_32 (abfd, (bfd_vma) in->reserved1, ex->reserved1); | |
1405 | } | |
1406 | ||
1407 | static void | |
1408 | bfd_elf32_swap_crinfo_out (abfd, in, ex) | |
1409 | bfd *abfd; | |
53787b23 | 1410 | const Elf32_crinfo *in; |
5b3b9ff6 ILT |
1411 | Elf32_External_crinfo *ex; |
1412 | { | |
053baeb1 ILT |
1413 | unsigned long l; |
1414 | ||
1415 | l = (((in->ctype & CRINFO_CTYPE) << CRINFO_CTYPE_SH) | |
1416 | | ((in->rtype & CRINFO_RTYPE) << CRINFO_RTYPE_SH) | |
1417 | | ((in->dist2to & CRINFO_DIST2TO) << CRINFO_DIST2TO_SH) | |
1418 | | ((in->relvaddr & CRINFO_RELVADDR) << CRINFO_RELVADDR_SH)); | |
1419 | bfd_h_put_32 (abfd, (bfd_vma) l, ex->info); | |
5b3b9ff6 ILT |
1420 | bfd_h_put_32 (abfd, (bfd_vma) in->konst, ex->konst); |
1421 | bfd_h_put_32 (abfd, (bfd_vma) in->vaddr, ex->vaddr); | |
1422 | } | |
1423 | \f | |
1424 | /* Determine whether a symbol is global for the purposes of splitting | |
1425 | the symbol table into global symbols and local symbols. At least | |
6e07e54f ILT |
1426 | on Irix 5, this split must be between section symbols and all other |
1427 | symbols. On most ELF targets the split is between static symbols | |
1428 | and externally visible symbols. */ | |
1429 | ||
1430 | /*ARGSUSED*/ | |
1431 | static boolean | |
1432 | mips_elf_sym_is_global (abfd, sym) | |
1433 | bfd *abfd; | |
1434 | asymbol *sym; | |
1435 | { | |
1436 | return (sym->flags & BSF_SECTION_SYM) == 0 ? true : false; | |
1437 | } | |
1438 | \f | |
00176555 ILT |
1439 | /* Set the right machine number for a MIPS ELF file. This is used for |
1440 | both the 32-bit and the 64-bit ABI. */ | |
6e07e54f | 1441 | |
00176555 ILT |
1442 | boolean |
1443 | _bfd_mips_elf_object_p (abfd) | |
6e07e54f ILT |
1444 | bfd *abfd; |
1445 | { | |
1446 | switch (elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) | |
1447 | { | |
1448 | default: | |
1449 | case E_MIPS_ARCH_1: | |
1450 | /* Just use the default, which was set in elfcode.h. */ | |
1451 | break; | |
1452 | ||
1453 | case E_MIPS_ARCH_2: | |
1454 | (void) bfd_default_set_arch_mach (abfd, bfd_arch_mips, 6000); | |
1455 | break; | |
1456 | ||
1457 | case E_MIPS_ARCH_3: | |
1458 | (void) bfd_default_set_arch_mach (abfd, bfd_arch_mips, 4000); | |
1459 | break; | |
cabd8fa0 ILT |
1460 | |
1461 | case E_MIPS_ARCH_4: | |
1462 | (void) bfd_default_set_arch_mach (abfd, bfd_arch_mips, 8000); | |
1463 | break; | |
6e07e54f ILT |
1464 | } |
1465 | ||
00176555 ILT |
1466 | return true; |
1467 | } | |
1468 | ||
1469 | /* Set the right machine number for a 32-bit MIPS ELF file. */ | |
1470 | ||
1471 | static boolean | |
1472 | mips_elf32_object_p (abfd) | |
1473 | bfd *abfd; | |
1474 | { | |
aac6b32f ILT |
1475 | /* Irix 5 is broken. Object file symbol tables are not always |
1476 | sorted correctly such that local symbols precede global symbols, | |
6c495350 ILT |
1477 | and the sh_info field in the symbol table is not always right. */ |
1478 | elf_bad_symtab (abfd) = true; | |
aac6b32f | 1479 | |
00176555 | 1480 | return _bfd_mips_elf_object_p (abfd); |
6e07e54f ILT |
1481 | } |
1482 | ||
1483 | /* The final processing done just before writing out a MIPS ELF object | |
1484 | file. This gets the MIPS architecture right based on the machine | |
00176555 | 1485 | number. This is used by both the 32-bit and the 64-bit ABI. */ |
6e07e54f | 1486 | |
24f13b03 | 1487 | /*ARGSUSED*/ |
00176555 ILT |
1488 | void |
1489 | _bfd_mips_elf_final_write_processing (abfd, linker) | |
6e07e54f | 1490 | bfd *abfd; |
24f13b03 | 1491 | boolean linker; |
6e07e54f ILT |
1492 | { |
1493 | unsigned long val; | |
aac6b32f ILT |
1494 | unsigned int i; |
1495 | Elf_Internal_Shdr **hdrpp; | |
6e07e54f ILT |
1496 | |
1497 | switch (bfd_get_mach (abfd)) | |
1498 | { | |
1499 | case 3000: | |
1500 | val = E_MIPS_ARCH_1; | |
1501 | break; | |
1502 | ||
1503 | case 6000: | |
1504 | val = E_MIPS_ARCH_2; | |
1505 | break; | |
1506 | ||
1507 | case 4000: | |
1508 | val = E_MIPS_ARCH_3; | |
1509 | break; | |
1510 | ||
cabd8fa0 ILT |
1511 | case 8000: |
1512 | val = E_MIPS_ARCH_4; | |
1513 | break; | |
1514 | ||
6e07e54f | 1515 | default: |
5b3b9ff6 ILT |
1516 | val = 0; |
1517 | break; | |
6e07e54f ILT |
1518 | } |
1519 | ||
1520 | elf_elfheader (abfd)->e_flags &=~ EF_MIPS_ARCH; | |
1521 | elf_elfheader (abfd)->e_flags |= val; | |
aac6b32f ILT |
1522 | |
1523 | /* Set the sh_info field for .gptab sections. */ | |
1524 | for (i = 1, hdrpp = elf_elfsections (abfd) + 1; | |
1525 | i < elf_elfheader (abfd)->e_shnum; | |
1526 | i++, hdrpp++) | |
1527 | { | |
1528 | if ((*hdrpp)->sh_type == SHT_MIPS_GPTAB) | |
1529 | { | |
1530 | const char *name; | |
1531 | asection *sec; | |
1532 | ||
24f13b03 ILT |
1533 | BFD_ASSERT ((*hdrpp)->bfd_section != NULL); |
1534 | name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section); | |
aac6b32f ILT |
1535 | BFD_ASSERT (name != NULL |
1536 | && strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0); | |
1537 | sec = bfd_get_section_by_name (abfd, name + sizeof ".gptab" - 1); | |
1538 | BFD_ASSERT (sec != NULL); | |
1539 | (*hdrpp)->sh_info = elf_section_data (sec)->this_idx; | |
1540 | } | |
1541 | } | |
6e07e54f ILT |
1542 | } |
1543 | \f | |
5b3b9ff6 ILT |
1544 | /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */ |
1545 | ||
1546 | static boolean | |
1547 | mips_elf_set_private_flags (abfd, flags) | |
1548 | bfd *abfd; | |
1549 | flagword flags; | |
1550 | { | |
1551 | BFD_ASSERT (!elf_flags_init (abfd) | |
1552 | || elf_elfheader (abfd)->e_flags == flags); | |
1553 | ||
1554 | elf_elfheader (abfd)->e_flags = flags; | |
1555 | elf_flags_init (abfd) = true; | |
1556 | return true; | |
1557 | } | |
1558 | ||
1559 | /* Copy backend specific data from one object module to another */ | |
1560 | ||
1561 | static boolean | |
1562 | mips_elf_copy_private_bfd_data (ibfd, obfd) | |
1563 | bfd *ibfd; | |
1564 | bfd *obfd; | |
1565 | { | |
1566 | /* This function is selected based on the input vector. We only | |
1567 | want to copy information over if the output BFD also uses Elf | |
1568 | format. */ | |
1569 | if (bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
1570 | return true; | |
1571 | ||
1572 | BFD_ASSERT (!elf_flags_init (obfd) | |
1573 | || (elf_elfheader (obfd)->e_flags | |
1574 | == elf_elfheader (ibfd)->e_flags)); | |
1575 | ||
d1bf45aa | 1576 | elf_gp (obfd) = elf_gp (ibfd); |
5b3b9ff6 ILT |
1577 | elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags; |
1578 | elf_flags_init (obfd) = true; | |
1579 | return true; | |
1580 | } | |
1581 | ||
1582 | /* Merge backend specific data from an object file to the output | |
1583 | object file when linking. */ | |
1584 | ||
1585 | static boolean | |
1586 | mips_elf_merge_private_bfd_data (ibfd, obfd) | |
1587 | bfd *ibfd; | |
1588 | bfd *obfd; | |
1589 | { | |
1590 | flagword old_flags; | |
1591 | flagword new_flags; | |
1592 | ||
1593 | /* Check if we have the same endianess */ | |
1594 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder | |
1595 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) | |
1596 | { | |
1597 | (*_bfd_error_handler) | |
1598 | ("%s: compiled for a %s endian system and target is %s endian", | |
1599 | bfd_get_filename (ibfd), | |
1600 | bfd_big_endian (ibfd) ? "big" : "little", | |
1601 | bfd_big_endian (obfd) ? "big" : "little"); | |
1602 | ||
1603 | bfd_set_error (bfd_error_wrong_format); | |
1604 | return false; | |
1605 | } | |
1606 | ||
1607 | /* This function is selected based on the input vector. We only | |
1608 | want to copy information over if the output BFD also uses Elf | |
1609 | format. */ | |
1610 | if (bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
1611 | return true; | |
1612 | ||
1613 | new_flags = elf_elfheader (ibfd)->e_flags; | |
1614 | elf_elfheader (obfd)->e_flags |= new_flags & EF_MIPS_NOREORDER; | |
1615 | old_flags = elf_elfheader (obfd)->e_flags; | |
1616 | ||
1617 | if (!elf_flags_init (obfd)) /* First call, no flags set */ | |
1618 | { | |
1619 | elf_flags_init (obfd) = true; | |
1620 | elf_elfheader (obfd)->e_flags = new_flags; | |
1621 | } | |
1622 | else if (((new_flags ^ old_flags) & ~EF_MIPS_NOREORDER) | |
1623 | == 0) /* Compatible flags are ok */ | |
1624 | ; | |
1625 | else /* Incompatible flags */ | |
1626 | { | |
1627 | /* Warn about -fPIC mismatch */ | |
1628 | if ((new_flags & EF_MIPS_PIC) != (old_flags & EF_MIPS_PIC)) | |
1629 | { | |
1630 | new_flags &= ~EF_MIPS_PIC; | |
1631 | (*_bfd_error_handler) | |
1632 | ("%s: needs all files compiled with -fPIC", | |
1633 | bfd_get_filename (ibfd)); | |
1634 | } | |
1635 | ||
1636 | if ((new_flags & EF_MIPS_CPIC) != (old_flags & EF_MIPS_CPIC)) | |
1637 | { | |
1638 | new_flags &= ~EF_MIPS_CPIC; | |
1639 | (*_bfd_error_handler) | |
1640 | ("%s: needs all files compiled with -mabicalls", | |
1641 | bfd_get_filename (ibfd)); | |
1642 | } | |
1643 | ||
1644 | /* Warn about any other mismatches */ | |
1645 | if (new_flags != old_flags) | |
1646 | (*_bfd_error_handler) | |
1647 | ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)", | |
1648 | bfd_get_filename (ibfd), (unsigned long) new_flags, | |
1649 | (unsigned long) old_flags); | |
1650 | ||
1651 | bfd_set_error (bfd_error_bad_value); | |
1652 | return false; | |
1653 | } | |
1654 | ||
1655 | return true; | |
1656 | } | |
1657 | \f | |
b3c0fc57 ILT |
1658 | /* Handle a MIPS specific section when reading an object file. This |
1659 | is called when elfcode.h finds a section with an unknown type. | |
d1bf45aa ILT |
1660 | This routine supports both the 32-bit and 64-bit ELF ABI. |
1661 | ||
b3c0fc57 ILT |
1662 | FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure |
1663 | how to. */ | |
1664 | ||
d1bf45aa ILT |
1665 | boolean |
1666 | _bfd_mips_elf_section_from_shdr (abfd, hdr, name) | |
b3c0fc57 | 1667 | bfd *abfd; |
d1bf45aa ILT |
1668 | Elf_Internal_Shdr *hdr; |
1669 | const char *name; | |
b3c0fc57 ILT |
1670 | { |
1671 | /* There ought to be a place to keep ELF backend specific flags, but | |
1672 | at the moment there isn't one. We just keep track of the | |
1673 | sections by their name, instead. Fortunately, the ABI gives | |
1674 | suggested names for all the MIPS specific sections, so we will | |
1675 | probably get away with this. */ | |
1676 | switch (hdr->sh_type) | |
1677 | { | |
1678 | case SHT_MIPS_LIBLIST: | |
1679 | if (strcmp (name, ".liblist") != 0) | |
1680 | return false; | |
1681 | break; | |
6a5848cd ILT |
1682 | case SHT_MIPS_MSYM: |
1683 | if (strcmp (name, ".msym") != 0) | |
1684 | return false; | |
1685 | break; | |
b3c0fc57 ILT |
1686 | case SHT_MIPS_CONFLICT: |
1687 | if (strcmp (name, ".conflict") != 0) | |
1688 | return false; | |
1689 | break; | |
1690 | case SHT_MIPS_GPTAB: | |
1691 | if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) != 0) | |
1692 | return false; | |
1693 | break; | |
1694 | case SHT_MIPS_UCODE: | |
1695 | if (strcmp (name, ".ucode") != 0) | |
1696 | return false; | |
1697 | break; | |
1698 | case SHT_MIPS_DEBUG: | |
1699 | if (strcmp (name, ".mdebug") != 0) | |
1700 | return false; | |
1701 | break; | |
1702 | case SHT_MIPS_REGINFO: | |
1703 | if (strcmp (name, ".reginfo") != 0 | |
1704 | || hdr->sh_size != sizeof (Elf32_External_RegInfo)) | |
1705 | return false; | |
1706 | break; | |
6e07e54f ILT |
1707 | case SHT_MIPS_OPTIONS: |
1708 | if (strcmp (name, ".options") != 0) | |
1709 | return false; | |
1710 | break; | |
6a5848cd ILT |
1711 | case SHT_MIPS_DWARF: |
1712 | if (strncmp (name, ".debug_", sizeof ".debug_" - 1) != 0) | |
1713 | return false; | |
1714 | break; | |
1715 | case SHT_MIPS_EVENTS: | |
1716 | if (strncmp (name, ".MIPS.events.", sizeof ".MIPS.events." - 1) != 0) | |
1717 | return false; | |
1718 | break; | |
b3c0fc57 ILT |
1719 | default: |
1720 | return false; | |
1721 | } | |
1722 | ||
497c5434 ILT |
1723 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) |
1724 | return false; | |
b3c0fc57 | 1725 | |
497c5434 ILT |
1726 | if (hdr->sh_type == SHT_MIPS_DEBUG) |
1727 | { | |
d1bf45aa ILT |
1728 | if (! bfd_set_section_flags (abfd, hdr->bfd_section, |
1729 | (bfd_get_section_flags (abfd, | |
1730 | hdr->bfd_section) | |
497c5434 ILT |
1731 | | SEC_DEBUGGING))) |
1732 | return false; | |
1733 | } | |
b3c0fc57 | 1734 | |
d1bf45aa ILT |
1735 | return true; |
1736 | } | |
1737 | ||
1738 | /* Handle a 32-bit MIPS ELF specific section. */ | |
1739 | ||
1740 | static boolean | |
1741 | mips_elf32_section_from_shdr (abfd, hdr, name) | |
1742 | bfd *abfd; | |
1743 | Elf_Internal_Shdr *hdr; | |
1744 | char *name; | |
1745 | { | |
1746 | if (! _bfd_mips_elf_section_from_shdr (abfd, hdr, name)) | |
1747 | return false; | |
1748 | ||
497c5434 | 1749 | /* FIXME: We should record sh_info for a .gptab section. */ |
b3c0fc57 | 1750 | |
497c5434 ILT |
1751 | /* For a .reginfo section, set the gp value in the tdata information |
1752 | from the contents of this section. We need the gp value while | |
d1bf45aa ILT |
1753 | processing relocs, so we just get it now. The .reginfo section |
1754 | is not used in the 64-bit MIPS ELF ABI. */ | |
497c5434 ILT |
1755 | if (hdr->sh_type == SHT_MIPS_REGINFO) |
1756 | { | |
1757 | Elf32_External_RegInfo ext; | |
1758 | Elf32_RegInfo s; | |
b3c0fc57 | 1759 | |
d1bf45aa | 1760 | if (! bfd_get_section_contents (abfd, hdr->bfd_section, (PTR) &ext, |
497c5434 ILT |
1761 | (file_ptr) 0, sizeof ext)) |
1762 | return false; | |
1763 | bfd_mips_elf32_swap_reginfo_in (abfd, &ext, &s); | |
1764 | elf_gp (abfd) = s.ri_gp_value; | |
b3c0fc57 ILT |
1765 | } |
1766 | ||
1767 | return true; | |
1768 | } | |
1769 | ||
1770 | /* Set the correct type for a MIPS ELF section. We do this by the | |
00176555 ILT |
1771 | section name, which is a hack, but ought to work. This routine is |
1772 | used by both the 32-bit and the 64-bit ABI. */ | |
b3c0fc57 | 1773 | |
00176555 ILT |
1774 | boolean |
1775 | _bfd_mips_elf_fake_sections (abfd, hdr, sec) | |
b3c0fc57 ILT |
1776 | bfd *abfd; |
1777 | Elf32_Internal_Shdr *hdr; | |
1778 | asection *sec; | |
1779 | { | |
1780 | register const char *name; | |
1781 | ||
1782 | name = bfd_get_section_name (abfd, sec); | |
1783 | ||
1784 | if (strcmp (name, ".liblist") == 0) | |
1785 | { | |
1786 | hdr->sh_type = SHT_MIPS_LIBLIST; | |
1787 | hdr->sh_info = sec->_raw_size / sizeof (Elf32_Lib); | |
1788 | /* FIXME: Set the sh_link field. */ | |
1789 | } | |
6a5848cd ILT |
1790 | else if (strcmp (name, ".msym") == 0) |
1791 | { | |
1792 | hdr->sh_type = SHT_MIPS_MSYM; | |
1793 | hdr->sh_entsize = 8; | |
1794 | /* FIXME: Set the sh_info field. */ | |
1795 | } | |
b3c0fc57 ILT |
1796 | else if (strcmp (name, ".conflict") == 0) |
1797 | hdr->sh_type = SHT_MIPS_CONFLICT; | |
1798 | else if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0) | |
1799 | { | |
1800 | hdr->sh_type = SHT_MIPS_GPTAB; | |
aac6b32f | 1801 | hdr->sh_entsize = sizeof (Elf32_External_gptab); |
00176555 | 1802 | /* The sh_info field is set in final_write_processing. */ |
b3c0fc57 ILT |
1803 | } |
1804 | else if (strcmp (name, ".ucode") == 0) | |
1805 | hdr->sh_type = SHT_MIPS_UCODE; | |
1806 | else if (strcmp (name, ".mdebug") == 0) | |
6e07e54f ILT |
1807 | { |
1808 | hdr->sh_type = SHT_MIPS_DEBUG; | |
5b3b9ff6 ILT |
1809 | /* In a shared object on Irix 5.3, the .mdebug section has an |
1810 | entsize of 0. FIXME: Does this matter? */ | |
1811 | if (SGI_COMPAT (abfd) && (abfd->flags & DYNAMIC) != 0) | |
1812 | hdr->sh_entsize = 0; | |
1813 | else | |
1814 | hdr->sh_entsize = 1; | |
6e07e54f | 1815 | } |
b3c0fc57 ILT |
1816 | else if (strcmp (name, ".reginfo") == 0) |
1817 | { | |
1818 | hdr->sh_type = SHT_MIPS_REGINFO; | |
5b3b9ff6 ILT |
1819 | /* In a shared object on Irix 5.3, the .reginfo section has an |
1820 | entsize of 0x18. FIXME: Does this matter? */ | |
1821 | if (SGI_COMPAT (abfd) && (abfd->flags & DYNAMIC) != 0) | |
1822 | hdr->sh_entsize = sizeof (Elf32_External_RegInfo); | |
1823 | else | |
1824 | hdr->sh_entsize = 1; | |
b3c0fc57 ILT |
1825 | |
1826 | /* Force the section size to the correct value, even if the | |
1827 | linker thinks it is larger. The link routine below will only | |
1828 | write out this much data for .reginfo. */ | |
1829 | hdr->sh_size = sec->_raw_size = sizeof (Elf32_External_RegInfo); | |
1830 | } | |
5b3b9ff6 ILT |
1831 | else if (SGI_COMPAT (abfd) |
1832 | && (strcmp (name, ".hash") == 0 | |
1833 | || strcmp (name, ".dynamic") == 0 | |
1834 | || strcmp (name, ".dynstr") == 0)) | |
1835 | { | |
1836 | hdr->sh_entsize = 0; | |
1837 | hdr->sh_info = SIZEOF_MIPS_DYNSYM_SECNAMES; | |
1838 | } | |
1839 | else if (strcmp (name, ".got") == 0 | |
1840 | || strcmp (name, ".sdata") == 0 | |
1841 | || strcmp (name, ".sbss") == 0 | |
1842 | || strcmp (name, ".lit4") == 0 | |
1843 | || strcmp (name, ".lit8") == 0) | |
1844 | hdr->sh_flags |= SHF_MIPS_GPREL; | |
6e07e54f ILT |
1845 | else if (strcmp (name, ".options") == 0) |
1846 | { | |
1847 | hdr->sh_type = SHT_MIPS_OPTIONS; | |
1848 | hdr->sh_entsize = 1; | |
1849 | } | |
6a5848cd ILT |
1850 | else if (strncmp (name, ".debug_", sizeof ".debug_" - 1) == 0) |
1851 | hdr->sh_type = SHT_MIPS_DWARF; | |
1852 | else if (strncmp (name, ".MIPS.events.", sizeof ".MIPS.events." - 1) == 0) | |
1853 | hdr->sh_type = SHT_MIPS_EVENTS; | |
b3c0fc57 ILT |
1854 | |
1855 | return true; | |
1856 | } | |
1857 | ||
1858 | /* Given a BFD section, try to locate the corresponding ELF section | |
00176555 ILT |
1859 | index. This is used by both the 32-bit and the 64-bit ABI. |
1860 | Actually, it's not clear to me that the 64-bit ABI supports these, | |
1861 | but for non-PIC objects we will certainly want support for at least | |
1862 | the .scommon section. */ | |
b3c0fc57 | 1863 | |
00176555 ILT |
1864 | boolean |
1865 | _bfd_mips_elf_section_from_bfd_section (abfd, hdr, sec, retval) | |
b3c0fc57 ILT |
1866 | bfd *abfd; |
1867 | Elf32_Internal_Shdr *hdr; | |
1868 | asection *sec; | |
1869 | int *retval; | |
1870 | { | |
1871 | if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0) | |
1872 | { | |
1873 | *retval = SHN_MIPS_SCOMMON; | |
1874 | return true; | |
1875 | } | |
82b1edf7 KR |
1876 | if (strcmp (bfd_get_section_name (abfd, sec), ".acommon") == 0) |
1877 | { | |
1878 | *retval = SHN_MIPS_ACOMMON; | |
1879 | return true; | |
1880 | } | |
b3c0fc57 ILT |
1881 | return false; |
1882 | } | |
1883 | ||
1884 | /* Work over a section just before writing it out. We update the GP | |
1885 | value in the .reginfo section based on the value we are using. | |
00176555 ILT |
1886 | This routine is used by both the 32-bit and the 64-bit ABI. FIXME: |
1887 | We recognize sections that need the SHF_MIPS_GPREL flag by name; | |
1888 | there has to be a better way. */ | |
b3c0fc57 | 1889 | |
00176555 ILT |
1890 | boolean |
1891 | _bfd_mips_elf_section_processing (abfd, hdr) | |
b3c0fc57 | 1892 | bfd *abfd; |
00176555 | 1893 | Elf_Internal_Shdr *hdr; |
b3c0fc57 | 1894 | { |
24f13b03 | 1895 | if (hdr->bfd_section != NULL) |
b3c0fc57 | 1896 | { |
24f13b03 | 1897 | const char *name = bfd_get_section_name (abfd, hdr->bfd_section); |
b3c0fc57 ILT |
1898 | |
1899 | if (strcmp (name, ".sdata") == 0) | |
1900 | { | |
1901 | hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL; | |
1902 | hdr->sh_type = SHT_PROGBITS; | |
1903 | } | |
1904 | else if (strcmp (name, ".sbss") == 0) | |
1905 | { | |
1906 | hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL; | |
1907 | hdr->sh_type = SHT_NOBITS; | |
1908 | } | |
1909 | else if (strcmp (name, ".lit8") == 0 | |
1910 | || strcmp (name, ".lit4") == 0) | |
1911 | { | |
1912 | hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL; | |
1913 | hdr->sh_type = SHT_PROGBITS; | |
1914 | } | |
5b3b9ff6 ILT |
1915 | else if (strcmp (name, ".compact_rel") == 0) |
1916 | { | |
1917 | hdr->sh_flags = 0; | |
1918 | hdr->sh_type = SHT_PROGBITS; | |
1919 | } | |
1920 | else if (strcmp (name, ".rtproc") == 0) | |
1921 | { | |
1922 | if (hdr->sh_addralign != 0 && hdr->sh_entsize == 0) | |
1923 | { | |
1924 | unsigned int adjust; | |
1925 | ||
1926 | adjust = hdr->sh_size % hdr->sh_addralign; | |
1927 | if (adjust != 0) | |
1928 | hdr->sh_size += hdr->sh_addralign - adjust; | |
1929 | } | |
1930 | } | |
b3c0fc57 ILT |
1931 | } |
1932 | ||
1933 | return true; | |
1934 | } | |
00176555 ILT |
1935 | |
1936 | /* Work over a section just before writing it out. We update the GP | |
1937 | value in the .reginfo section based on the value we are using. The | |
1938 | 64 bit ABI does not use the .reginfo section. */ | |
1939 | ||
1940 | static boolean | |
1941 | mips_elf32_section_processing (abfd, hdr) | |
1942 | bfd *abfd; | |
1943 | Elf32_Internal_Shdr *hdr; | |
1944 | { | |
1945 | if (hdr->sh_type == SHT_MIPS_REGINFO) | |
1946 | { | |
1947 | bfd_byte buf[4]; | |
1948 | ||
1949 | BFD_ASSERT (hdr->sh_size == sizeof (Elf32_External_RegInfo)); | |
1950 | BFD_ASSERT (hdr->contents == NULL); | |
1951 | ||
1952 | if (bfd_seek (abfd, | |
1953 | hdr->sh_offset + sizeof (Elf32_External_RegInfo) - 4, | |
1954 | SEEK_SET) == -1) | |
1955 | return false; | |
1956 | bfd_h_put_32 (abfd, (bfd_vma) elf_gp (abfd), buf); | |
1957 | if (bfd_write (buf, (bfd_size_type) 1, (bfd_size_type) 4, abfd) != 4) | |
1958 | return false; | |
1959 | } | |
1960 | ||
1961 | return _bfd_mips_elf_section_processing (abfd, hdr); | |
1962 | } | |
b3c0fc57 | 1963 | \f |
aac6b32f ILT |
1964 | /* MIPS ELF uses two common sections. One is the usual one, and the |
1965 | other is for small objects. All the small objects are kept | |
1966 | together, and then referenced via the gp pointer, which yields | |
1967 | faster assembler code. This is what we use for the small common | |
1968 | section. This approach is copied from ecoff.c. */ | |
1969 | static asection mips_elf_scom_section; | |
1970 | static asymbol mips_elf_scom_symbol; | |
1971 | static asymbol *mips_elf_scom_symbol_ptr; | |
1972 | ||
1973 | /* MIPS ELF also uses an acommon section, which represents an | |
1974 | allocated common symbol which may be overridden by a | |
1975 | definition in a shared library. */ | |
1976 | static asection mips_elf_acom_section; | |
1977 | static asymbol mips_elf_acom_symbol; | |
1978 | static asymbol *mips_elf_acom_symbol_ptr; | |
1979 | ||
5b3b9ff6 ILT |
1980 | /* The Irix 5 support uses two virtual sections, which represent |
1981 | text/data symbols defined in dynamic objects. */ | |
1982 | static asection mips_elf_text_section; | |
1983 | static asection *mips_elf_text_section_ptr; | |
1984 | static asymbol mips_elf_text_symbol; | |
1985 | static asymbol *mips_elf_text_symbol_ptr; | |
1986 | ||
1987 | static asection mips_elf_data_section; | |
1988 | static asection *mips_elf_data_section_ptr; | |
1989 | static asymbol mips_elf_data_symbol; | |
1990 | static asymbol *mips_elf_data_symbol_ptr; | |
1991 | ||
00176555 ILT |
1992 | /* Handle the special MIPS section numbers that a symbol may use. |
1993 | This is used for both the 32-bit and the 64-bit ABI. */ | |
aac6b32f | 1994 | |
00176555 ILT |
1995 | void |
1996 | _bfd_mips_elf_symbol_processing (abfd, asym) | |
aac6b32f ILT |
1997 | bfd *abfd; |
1998 | asymbol *asym; | |
1999 | { | |
2000 | elf_symbol_type *elfsym; | |
2001 | ||
2002 | elfsym = (elf_symbol_type *) asym; | |
2003 | switch (elfsym->internal_elf_sym.st_shndx) | |
2004 | { | |
2005 | case SHN_MIPS_ACOMMON: | |
2006 | /* This section is used in a dynamically linked executable file. | |
2007 | It is an allocated common section. The dynamic linker can | |
2008 | either resolve these symbols to something in a shared | |
2009 | library, or it can just leave them here. For our purposes, | |
2010 | we can consider these symbols to be in a new section. */ | |
2011 | if (mips_elf_acom_section.name == NULL) | |
2012 | { | |
2013 | /* Initialize the acommon section. */ | |
2014 | mips_elf_acom_section.name = ".acommon"; | |
6ab826bd | 2015 | mips_elf_acom_section.flags = SEC_ALLOC; |
aac6b32f ILT |
2016 | mips_elf_acom_section.output_section = &mips_elf_acom_section; |
2017 | mips_elf_acom_section.symbol = &mips_elf_acom_symbol; | |
2018 | mips_elf_acom_section.symbol_ptr_ptr = &mips_elf_acom_symbol_ptr; | |
2019 | mips_elf_acom_symbol.name = ".acommon"; | |
2020 | mips_elf_acom_symbol.flags = BSF_SECTION_SYM; | |
2021 | mips_elf_acom_symbol.section = &mips_elf_acom_section; | |
2022 | mips_elf_acom_symbol_ptr = &mips_elf_acom_symbol; | |
2023 | } | |
2024 | asym->section = &mips_elf_acom_section; | |
2025 | break; | |
2026 | ||
2027 | case SHN_COMMON: | |
2028 | /* Common symbols less than the GP size are automatically | |
2029 | treated as SHN_MIPS_SCOMMON symbols. */ | |
2030 | if (asym->value > elf_gp_size (abfd)) | |
2031 | break; | |
2032 | /* Fall through. */ | |
2033 | case SHN_MIPS_SCOMMON: | |
2034 | if (mips_elf_scom_section.name == NULL) | |
2035 | { | |
2036 | /* Initialize the small common section. */ | |
2037 | mips_elf_scom_section.name = ".scommon"; | |
2038 | mips_elf_scom_section.flags = SEC_IS_COMMON; | |
2039 | mips_elf_scom_section.output_section = &mips_elf_scom_section; | |
2040 | mips_elf_scom_section.symbol = &mips_elf_scom_symbol; | |
2041 | mips_elf_scom_section.symbol_ptr_ptr = &mips_elf_scom_symbol_ptr; | |
2042 | mips_elf_scom_symbol.name = ".scommon"; | |
2043 | mips_elf_scom_symbol.flags = BSF_SECTION_SYM; | |
2044 | mips_elf_scom_symbol.section = &mips_elf_scom_section; | |
2045 | mips_elf_scom_symbol_ptr = &mips_elf_scom_symbol; | |
2046 | } | |
2047 | asym->section = &mips_elf_scom_section; | |
2048 | asym->value = elfsym->internal_elf_sym.st_size; | |
2049 | break; | |
2050 | ||
2051 | case SHN_MIPS_SUNDEFINED: | |
24f13b03 | 2052 | asym->section = bfd_und_section_ptr; |
aac6b32f | 2053 | break; |
5b3b9ff6 ILT |
2054 | |
2055 | #if 0 /* for SGI_COMPAT */ | |
2056 | case SHN_MIPS_TEXT: | |
2057 | asym->section = mips_elf_text_section_ptr; | |
2058 | break; | |
2059 | ||
2060 | case SHN_MIPS_DATA: | |
2061 | asym->section = mips_elf_data_section_ptr; | |
2062 | break; | |
2063 | #endif | |
2064 | } | |
2065 | } | |
2066 | \f | |
2067 | /* When creating an Irix 5 executable, we need REGINFO and RTPROC | |
2068 | segments. */ | |
2069 | ||
2070 | static int | |
2071 | mips_elf_additional_program_headers (abfd) | |
2072 | bfd *abfd; | |
2073 | { | |
2074 | asection *s; | |
2075 | int ret; | |
2076 | ||
2077 | ret = 0; | |
2078 | ||
2079 | if (! SGI_COMPAT (abfd)) | |
2080 | return ret; | |
2081 | ||
2082 | s = bfd_get_section_by_name (abfd, ".reginfo"); | |
2083 | if (s != NULL && (s->flags & SEC_LOAD) != 0) | |
2084 | { | |
2085 | /* We need a PT_MIPS_REGINFO segment. */ | |
2086 | ++ret; | |
2087 | } | |
2088 | ||
53787b23 | 2089 | if (bfd_get_section_by_name (abfd, ".dynamic") != NULL |
5b3b9ff6 ILT |
2090 | && bfd_get_section_by_name (abfd, ".mdebug") != NULL) |
2091 | { | |
2092 | /* We need a PT_MIPS_RTPROC segment. */ | |
2093 | ++ret; | |
2094 | } | |
2095 | ||
2096 | return ret; | |
2097 | } | |
2098 | ||
2099 | /* Modify the segment map for an Irix 5 executable. */ | |
2100 | ||
2101 | static boolean | |
2102 | mips_elf_modify_segment_map (abfd) | |
2103 | bfd *abfd; | |
2104 | { | |
2105 | asection *s; | |
2106 | struct elf_segment_map *m, **pm; | |
2107 | ||
2108 | if (! SGI_COMPAT (abfd)) | |
2109 | return true; | |
2110 | ||
2111 | /* If there is a .reginfo section, we need a PT_MIPS_REGINFO | |
2112 | segment. */ | |
2113 | s = bfd_get_section_by_name (abfd, ".reginfo"); | |
2114 | if (s != NULL && (s->flags & SEC_LOAD) != 0) | |
2115 | { | |
2116 | for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) | |
2117 | if (m->p_type == PT_MIPS_REGINFO) | |
2118 | break; | |
2119 | if (m == NULL) | |
2120 | { | |
2121 | m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m); | |
2122 | if (m == NULL) | |
2123 | return false; | |
2124 | ||
2125 | m->p_type = PT_MIPS_REGINFO; | |
2126 | m->count = 1; | |
2127 | m->sections[0] = s; | |
2128 | ||
2129 | /* We want to put it after the PHDR and INTERP segments. */ | |
2130 | pm = &elf_tdata (abfd)->segment_map; | |
2131 | while (*pm != NULL | |
2132 | && ((*pm)->p_type == PT_PHDR | |
2133 | || (*pm)->p_type == PT_INTERP)) | |
2134 | pm = &(*pm)->next; | |
2135 | ||
2136 | m->next = *pm; | |
2137 | *pm = m; | |
2138 | } | |
2139 | } | |
2140 | ||
2141 | /* If there are .dynamic and .mdebug sections, we make a room for | |
2142 | the RTPROC header. FIXME: Rewrite without section names. */ | |
2143 | if (bfd_get_section_by_name (abfd, ".interp") == NULL | |
2144 | && bfd_get_section_by_name (abfd, ".dynamic") != NULL | |
2145 | && bfd_get_section_by_name (abfd, ".mdebug") != NULL) | |
2146 | { | |
2147 | for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) | |
2148 | if (m->p_type == PT_MIPS_RTPROC) | |
2149 | break; | |
2150 | if (m == NULL) | |
2151 | { | |
2152 | m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m); | |
2153 | if (m == NULL) | |
2154 | return false; | |
2155 | ||
2156 | m->p_type = PT_MIPS_RTPROC; | |
2157 | ||
2158 | s = bfd_get_section_by_name (abfd, ".rtproc"); | |
2159 | if (s == NULL) | |
2160 | { | |
2161 | m->count = 0; | |
2162 | m->p_flags = 0; | |
2163 | m->p_flags_valid = 1; | |
2164 | } | |
2165 | else | |
2166 | { | |
2167 | m->count = 1; | |
2168 | m->sections[0] = s; | |
2169 | } | |
2170 | ||
2171 | /* We want to put it after the DYNAMIC segment. */ | |
2172 | pm = &elf_tdata (abfd)->segment_map; | |
2173 | while (*pm != NULL && (*pm)->p_type != PT_DYNAMIC) | |
2174 | pm = &(*pm)->next; | |
2175 | if (*pm != NULL) | |
2176 | pm = &(*pm)->next; | |
2177 | ||
2178 | m->next = *pm; | |
2179 | *pm = m; | |
2180 | } | |
2181 | } | |
2182 | ||
2183 | /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, .dynstr, | |
2184 | .dynsym, and .hash sections, and everything in between. */ | |
2185 | for (pm = &elf_tdata (abfd)->segment_map; *pm != NULL; pm = &(*pm)->next) | |
2186 | if ((*pm)->p_type == PT_DYNAMIC) | |
2187 | break; | |
2188 | m = *pm; | |
2189 | if (m != NULL | |
2190 | && m->count == 1 | |
2191 | && strcmp (m->sections[0]->name, ".dynamic") == 0) | |
2192 | { | |
2193 | static const char *sec_names[] = | |
2194 | { ".dynamic", ".dynstr", ".dynsym", ".hash" }; | |
2195 | bfd_vma low, high; | |
2196 | unsigned int i, c; | |
2197 | struct elf_segment_map *n; | |
2198 | ||
2199 | low = 0xffffffff; | |
2200 | high = 0; | |
2201 | for (i = 0; i < sizeof sec_names / sizeof sec_names[0]; i++) | |
2202 | { | |
2203 | s = bfd_get_section_by_name (abfd, sec_names[i]); | |
2204 | if (s != NULL && (s->flags & SEC_LOAD) != 0) | |
2205 | { | |
2206 | bfd_size_type sz; | |
2207 | ||
2208 | if (low > s->vma) | |
2209 | low = s->vma; | |
2210 | sz = s->_cooked_size; | |
2211 | if (sz == 0) | |
2212 | sz = s->_raw_size; | |
2213 | if (high < s->vma + sz) | |
2214 | high = s->vma + sz; | |
2215 | } | |
2216 | } | |
2217 | ||
2218 | c = 0; | |
2219 | for (s = abfd->sections; s != NULL; s = s->next) | |
2220 | if ((s->flags & SEC_LOAD) != 0 | |
2221 | && s->vma >= low | |
2222 | && ((s->vma | |
2223 | + (s->_cooked_size != 0 ? s->_cooked_size : s->_raw_size)) | |
2224 | <= high)) | |
2225 | ++c; | |
2226 | ||
2227 | n = ((struct elf_segment_map *) | |
2228 | bfd_zalloc (abfd, sizeof *n + (c - 1) * sizeof (asection *))); | |
2229 | if (n == NULL) | |
2230 | return false; | |
2231 | *n = *m; | |
2232 | n->count = c; | |
2233 | ||
2234 | i = 0; | |
2235 | for (s = abfd->sections; s != NULL; s = s->next) | |
2236 | { | |
2237 | if ((s->flags & SEC_LOAD) != 0 | |
2238 | && s->vma >= low | |
2239 | && ((s->vma | |
2240 | + (s->_cooked_size != 0 ? s->_cooked_size : s->_raw_size)) | |
2241 | <= high)) | |
2242 | { | |
2243 | n->sections[i] = s; | |
2244 | ++i; | |
2245 | } | |
2246 | } | |
2247 | ||
2248 | *pm = n; | |
aac6b32f | 2249 | } |
5b3b9ff6 ILT |
2250 | |
2251 | return true; | |
2252 | } | |
2253 | \f | |
2254 | /* The structure of the runtime procedure descriptor created by the | |
2255 | loader for use by the static exception system. */ | |
2256 | ||
2257 | typedef struct runtime_pdr { | |
2258 | bfd_vma adr; /* memory address of start of procedure */ | |
2259 | long regmask; /* save register mask */ | |
2260 | long regoffset; /* save register offset */ | |
2261 | long fregmask; /* save floating point register mask */ | |
2262 | long fregoffset; /* save floating point register offset */ | |
2263 | long frameoffset; /* frame size */ | |
2264 | short framereg; /* frame pointer register */ | |
2265 | short pcreg; /* offset or reg of return pc */ | |
2266 | long irpss; /* index into the runtime string table */ | |
2267 | long reserved; | |
2268 | struct exception_info *exception_info;/* pointer to exception array */ | |
2269 | } RPDR, *pRPDR; | |
2270 | #define cbRPDR sizeof(RPDR) | |
2271 | #define rpdNil ((pRPDR) 0) | |
2272 | ||
2273 | /* Swap RPDR (runtime procedure table entry) for output. */ | |
2274 | ||
2275 | static void ecoff_swap_rpdr_out | |
2276 | PARAMS ((bfd *, const RPDR *, struct rpdr_ext *)); | |
2277 | ||
2278 | static void | |
2279 | ecoff_swap_rpdr_out (abfd, in, ex) | |
2280 | bfd *abfd; | |
2281 | const RPDR *in; | |
2282 | struct rpdr_ext *ex; | |
2283 | { | |
2284 | /* ecoff_put_off was defined in ecoffswap.h. */ | |
2285 | ecoff_put_off (abfd, in->adr, (bfd_byte *) ex->p_adr); | |
2286 | bfd_h_put_32 (abfd, in->regmask, (bfd_byte *) ex->p_regmask); | |
2287 | bfd_h_put_32 (abfd, in->regoffset, (bfd_byte *) ex->p_regoffset); | |
2288 | bfd_h_put_32 (abfd, in->fregmask, (bfd_byte *) ex->p_fregmask); | |
2289 | bfd_h_put_32 (abfd, in->fregoffset, (bfd_byte *) ex->p_fregoffset); | |
2290 | bfd_h_put_32 (abfd, in->frameoffset, (bfd_byte *) ex->p_frameoffset); | |
2291 | ||
2292 | bfd_h_put_16 (abfd, in->framereg, (bfd_byte *) ex->p_framereg); | |
2293 | bfd_h_put_16 (abfd, in->pcreg, (bfd_byte *) ex->p_pcreg); | |
2294 | ||
2295 | bfd_h_put_32 (abfd, in->irpss, (bfd_byte *) ex->p_irpss); | |
2296 | #if 0 /* FIXME */ | |
2297 | ecoff_put_off (abfd, in->exception_info, (bfd_byte *) ex->p_exception_info); | |
2298 | #endif | |
aac6b32f ILT |
2299 | } |
2300 | \f | |
6e07e54f ILT |
2301 | /* Read ECOFF debugging information from a .mdebug section into a |
2302 | ecoff_debug_info structure. */ | |
b3c0fc57 | 2303 | |
00176555 ILT |
2304 | boolean |
2305 | _bfd_mips_elf_read_ecoff_info (abfd, section, debug) | |
b3c0fc57 | 2306 | bfd *abfd; |
6e07e54f ILT |
2307 | asection *section; |
2308 | struct ecoff_debug_info *debug; | |
b3c0fc57 | 2309 | { |
6e07e54f ILT |
2310 | HDRR *symhdr; |
2311 | const struct ecoff_debug_swap *swap; | |
a3a33af3 | 2312 | char *ext_hdr = NULL; |
6e07e54f ILT |
2313 | |
2314 | swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap; | |
2315 | ||
5b3b9ff6 | 2316 | ext_hdr = (char *) bfd_malloc ((size_t) swap->external_hdr_size); |
a3a33af3 | 2317 | if (ext_hdr == NULL && swap->external_hdr_size != 0) |
5b3b9ff6 | 2318 | goto error_return; |
6e07e54f ILT |
2319 | |
2320 | if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0, | |
2321 | swap->external_hdr_size) | |
2322 | == false) | |
a3a33af3 | 2323 | goto error_return; |
6e07e54f ILT |
2324 | |
2325 | symhdr = &debug->symbolic_header; | |
2326 | (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr); | |
2327 | ||
2328 | /* The symbolic header contains absolute file offsets and sizes to | |
2329 | read. */ | |
2330 | #define READ(ptr, offset, count, size, type) \ | |
2331 | if (symhdr->count == 0) \ | |
2332 | debug->ptr = NULL; \ | |
2333 | else \ | |
2334 | { \ | |
5b3b9ff6 | 2335 | debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \ |
6e07e54f | 2336 | if (debug->ptr == NULL) \ |
5b3b9ff6 | 2337 | goto error_return; \ |
6e07e54f ILT |
2338 | if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \ |
2339 | || (bfd_read (debug->ptr, size, symhdr->count, \ | |
2340 | abfd) != size * symhdr->count)) \ | |
a3a33af3 | 2341 | goto error_return; \ |
6e07e54f ILT |
2342 | } |
2343 | ||
2344 | READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *); | |
2345 | READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR); | |
2346 | READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR); | |
2347 | READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR); | |
2348 | READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR); | |
2349 | READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext), | |
2350 | union aux_ext *); | |
2351 | READ (ss, cbSsOffset, issMax, sizeof (char), char *); | |
2352 | READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *); | |
2353 | READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR); | |
2354 | READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR); | |
aac6b32f ILT |
2355 | READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR); |
2356 | #undef READ | |
9783e04a DM |
2357 | |
2358 | debug->fdr = NULL; | |
a3a33af3 | 2359 | debug->adjust = NULL; |
6e07e54f ILT |
2360 | |
2361 | return true; | |
a3a33af3 ILT |
2362 | |
2363 | error_return: | |
2364 | if (ext_hdr != NULL) | |
2365 | free (ext_hdr); | |
a3a33af3 ILT |
2366 | if (debug->line != NULL) |
2367 | free (debug->line); | |
2368 | if (debug->external_dnr != NULL) | |
2369 | free (debug->external_dnr); | |
2370 | if (debug->external_pdr != NULL) | |
2371 | free (debug->external_pdr); | |
2372 | if (debug->external_sym != NULL) | |
2373 | free (debug->external_sym); | |
2374 | if (debug->external_opt != NULL) | |
2375 | free (debug->external_opt); | |
2376 | if (debug->external_aux != NULL) | |
2377 | free (debug->external_aux); | |
2378 | if (debug->ss != NULL) | |
2379 | free (debug->ss); | |
2380 | if (debug->ssext != NULL) | |
2381 | free (debug->ssext); | |
2382 | if (debug->external_fdr != NULL) | |
2383 | free (debug->external_fdr); | |
2384 | if (debug->external_rfd != NULL) | |
2385 | free (debug->external_rfd); | |
aac6b32f ILT |
2386 | if (debug->external_ext != NULL) |
2387 | free (debug->external_ext); | |
a3a33af3 | 2388 | return false; |
6e07e54f | 2389 | } |
a16fcab3 | 2390 | \f |
a2546fce ILT |
2391 | /* MIPS ELF local labels start with '$', not 'L'. */ |
2392 | ||
2393 | /*ARGSUSED*/ | |
2394 | static boolean | |
2395 | mips_elf_is_local_label (abfd, symbol) | |
2396 | bfd *abfd; | |
2397 | asymbol *symbol; | |
2398 | { | |
2399 | return symbol->name[0] == '$'; | |
2400 | } | |
2401 | ||
a16fcab3 KR |
2402 | /* MIPS ELF uses a special find_nearest_line routine in order the |
2403 | handle the ECOFF debugging information. */ | |
2404 | ||
2405 | struct mips_elf_find_line | |
2406 | { | |
2407 | struct ecoff_debug_info d; | |
2408 | struct ecoff_find_line i; | |
2409 | }; | |
6e07e54f | 2410 | |
a16fcab3 KR |
2411 | static boolean |
2412 | mips_elf_find_nearest_line (abfd, section, symbols, offset, filename_ptr, | |
2413 | functionname_ptr, line_ptr) | |
2414 | bfd *abfd; | |
2415 | asection *section; | |
2416 | asymbol **symbols; | |
2417 | bfd_vma offset; | |
2418 | const char **filename_ptr; | |
2419 | const char **functionname_ptr; | |
2420 | unsigned int *line_ptr; | |
2421 | { | |
2422 | asection *msec; | |
2423 | ||
2424 | msec = bfd_get_section_by_name (abfd, ".mdebug"); | |
2425 | if (msec != NULL) | |
2426 | { | |
6ab826bd | 2427 | flagword origflags; |
a16fcab3 KR |
2428 | struct mips_elf_find_line *fi; |
2429 | const struct ecoff_debug_swap * const swap = | |
2430 | get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap; | |
2431 | ||
6ab826bd FF |
2432 | /* If we are called during a link, mips_elf_final_link may have |
2433 | cleared the SEC_HAS_CONTENTS field. We force it back on here | |
2434 | if appropriate (which it normally will be). */ | |
2435 | origflags = msec->flags; | |
2436 | if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS) | |
2437 | msec->flags |= SEC_HAS_CONTENTS; | |
2438 | ||
a16fcab3 KR |
2439 | fi = elf_tdata (abfd)->find_line_info; |
2440 | if (fi == NULL) | |
2441 | { | |
2442 | bfd_size_type external_fdr_size; | |
2443 | char *fraw_src; | |
2444 | char *fraw_end; | |
2445 | struct fdr *fdr_ptr; | |
2446 | ||
2447 | fi = ((struct mips_elf_find_line *) | |
abec70b9 | 2448 | bfd_zalloc (abfd, sizeof (struct mips_elf_find_line))); |
a16fcab3 KR |
2449 | if (fi == NULL) |
2450 | { | |
6ab826bd | 2451 | msec->flags = origflags; |
a16fcab3 KR |
2452 | return false; |
2453 | } | |
2454 | ||
00176555 | 2455 | if (! _bfd_mips_elf_read_ecoff_info (abfd, msec, &fi->d)) |
6ab826bd FF |
2456 | { |
2457 | msec->flags = origflags; | |
2458 | return false; | |
2459 | } | |
a16fcab3 KR |
2460 | |
2461 | /* Swap in the FDR information. */ | |
2462 | fi->d.fdr = ((struct fdr *) | |
2463 | bfd_alloc (abfd, | |
2464 | (fi->d.symbolic_header.ifdMax * | |
2465 | sizeof (struct fdr)))); | |
2466 | if (fi->d.fdr == NULL) | |
2467 | { | |
6ab826bd | 2468 | msec->flags = origflags; |
a16fcab3 KR |
2469 | return false; |
2470 | } | |
2471 | external_fdr_size = swap->external_fdr_size; | |
2472 | fdr_ptr = fi->d.fdr; | |
2473 | fraw_src = (char *) fi->d.external_fdr; | |
2474 | fraw_end = (fraw_src | |
2475 | + fi->d.symbolic_header.ifdMax * external_fdr_size); | |
2476 | for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++) | |
2477 | (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr); | |
2478 | ||
2479 | elf_tdata (abfd)->find_line_info = fi; | |
2480 | ||
2481 | /* Note that we don't bother to ever free this information. | |
2482 | find_nearest_line is either called all the time, as in | |
2483 | objdump -l, so the information should be saved, or it is | |
2484 | rarely called, as in ld error messages, so the memory | |
2485 | wasted is unimportant. Still, it would probably be a | |
2486 | good idea for free_cached_info to throw it away. */ | |
2487 | } | |
2488 | ||
2489 | if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap, | |
2490 | &fi->i, filename_ptr, functionname_ptr, | |
2491 | line_ptr)) | |
6ab826bd FF |
2492 | { |
2493 | msec->flags = origflags; | |
2494 | return true; | |
2495 | } | |
2496 | ||
2497 | msec->flags = origflags; | |
a16fcab3 KR |
2498 | } |
2499 | ||
2500 | /* Fall back on the generic ELF find_nearest_line routine. */ | |
2501 | ||
ede4eed4 KR |
2502 | return _bfd_elf_find_nearest_line (abfd, section, symbols, offset, |
2503 | filename_ptr, functionname_ptr, | |
2504 | line_ptr); | |
a16fcab3 KR |
2505 | } |
2506 | \f | |
aac6b32f ILT |
2507 | /* The MIPS ELF linker needs additional information for each symbol in |
2508 | the global hash table. */ | |
2509 | ||
2510 | struct mips_elf_link_hash_entry | |
2511 | { | |
2512 | struct elf_link_hash_entry root; | |
6e07e54f | 2513 | |
aac6b32f ILT |
2514 | /* External symbol information. */ |
2515 | EXTR esym; | |
abec70b9 ILT |
2516 | |
2517 | /* Number of MIPS_32 or MIPS_REL32 relocs against this symbol. */ | |
2518 | unsigned int mips_32_relocs; | |
aac6b32f ILT |
2519 | }; |
2520 | ||
2521 | /* MIPS ELF linker hash table. */ | |
2522 | ||
2523 | struct mips_elf_link_hash_table | |
2524 | { | |
2525 | struct elf_link_hash_table root; | |
5b3b9ff6 ILT |
2526 | /* String section indices for the dynamic section symbols. */ |
2527 | bfd_size_type dynsym_sec_strindex[SIZEOF_MIPS_DYNSYM_SECNAMES]; | |
2528 | /* The number of .rtproc entries. */ | |
2529 | bfd_size_type procedure_count; | |
53787b23 ILT |
2530 | /* The size of the .compact_rel section (if SGI_COMPAT). */ |
2531 | bfd_size_type compact_rel_size; | |
aac6b32f ILT |
2532 | }; |
2533 | ||
2534 | /* Look up an entry in a MIPS ELF linker hash table. */ | |
2535 | ||
2536 | #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \ | |
2537 | ((struct mips_elf_link_hash_entry *) \ | |
2538 | elf_link_hash_lookup (&(table)->root, (string), (create), \ | |
2539 | (copy), (follow))) | |
2540 | ||
2541 | /* Traverse a MIPS ELF linker hash table. */ | |
2542 | ||
2543 | #define mips_elf_link_hash_traverse(table, func, info) \ | |
2544 | (elf_link_hash_traverse \ | |
2545 | (&(table)->root, \ | |
2546 | (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \ | |
2547 | (info))) | |
2548 | ||
2549 | /* Get the MIPS ELF linker hash table from a link_info structure. */ | |
2550 | ||
2551 | #define mips_elf_hash_table(p) \ | |
2552 | ((struct mips_elf_link_hash_table *) ((p)->hash)) | |
2553 | ||
2554 | static boolean mips_elf_output_extsym | |
2555 | PARAMS ((struct mips_elf_link_hash_entry *, PTR)); | |
2556 | ||
2557 | /* Create an entry in a MIPS ELF linker hash table. */ | |
2558 | ||
2559 | static struct bfd_hash_entry * | |
2560 | mips_elf_link_hash_newfunc (entry, table, string) | |
2561 | struct bfd_hash_entry *entry; | |
2562 | struct bfd_hash_table *table; | |
2563 | const char *string; | |
2564 | { | |
2565 | struct mips_elf_link_hash_entry *ret = | |
2566 | (struct mips_elf_link_hash_entry *) entry; | |
2567 | ||
2568 | /* Allocate the structure if it has not already been allocated by a | |
2569 | subclass. */ | |
2570 | if (ret == (struct mips_elf_link_hash_entry *) NULL) | |
2571 | ret = ((struct mips_elf_link_hash_entry *) | |
2572 | bfd_hash_allocate (table, | |
2573 | sizeof (struct mips_elf_link_hash_entry))); | |
2574 | if (ret == (struct mips_elf_link_hash_entry *) NULL) | |
a9713b91 | 2575 | return (struct bfd_hash_entry *) ret; |
aac6b32f ILT |
2576 | |
2577 | /* Call the allocation method of the superclass. */ | |
2578 | ret = ((struct mips_elf_link_hash_entry *) | |
2579 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, | |
2580 | table, string)); | |
2581 | if (ret != (struct mips_elf_link_hash_entry *) NULL) | |
2582 | { | |
2583 | /* Set local fields. */ | |
2584 | memset (&ret->esym, 0, sizeof (EXTR)); | |
2585 | /* We use -2 as a marker to indicate that the information has | |
2586 | not been set. -1 means there is no associated ifd. */ | |
2587 | ret->esym.ifd = -2; | |
abec70b9 | 2588 | ret->mips_32_relocs = 0; |
aac6b32f ILT |
2589 | } |
2590 | ||
2591 | return (struct bfd_hash_entry *) ret; | |
2592 | } | |
2593 | ||
2594 | /* Create a MIPS ELF linker hash table. */ | |
2595 | ||
2596 | static struct bfd_link_hash_table * | |
2597 | mips_elf_link_hash_table_create (abfd) | |
2598 | bfd *abfd; | |
2599 | { | |
2600 | struct mips_elf_link_hash_table *ret; | |
5b3b9ff6 | 2601 | unsigned int i; |
aac6b32f ILT |
2602 | |
2603 | ret = ((struct mips_elf_link_hash_table *) | |
2604 | bfd_alloc (abfd, sizeof (struct mips_elf_link_hash_table))); | |
2605 | if (ret == (struct mips_elf_link_hash_table *) NULL) | |
a9713b91 | 2606 | return NULL; |
aac6b32f ILT |
2607 | |
2608 | if (! _bfd_elf_link_hash_table_init (&ret->root, abfd, | |
2609 | mips_elf_link_hash_newfunc)) | |
2610 | { | |
2611 | bfd_release (abfd, ret); | |
2612 | return NULL; | |
2613 | } | |
2614 | ||
5b3b9ff6 ILT |
2615 | for (i = 0; i < SIZEOF_MIPS_DYNSYM_SECNAMES; i++) |
2616 | ret->dynsym_sec_strindex[i] = (bfd_size_type) -1; | |
2617 | ret->procedure_count = 0; | |
53787b23 | 2618 | ret->compact_rel_size = 0; |
5b3b9ff6 | 2619 | |
aac6b32f ILT |
2620 | return &ret->root.root; |
2621 | } | |
2622 | ||
2623 | /* Hook called by the linker routine which adds symbols from an object | |
2624 | file. We must handle the special MIPS section numbers here. */ | |
2625 | ||
2626 | /*ARGSUSED*/ | |
6e07e54f | 2627 | static boolean |
aac6b32f ILT |
2628 | mips_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) |
2629 | bfd *abfd; | |
2630 | struct bfd_link_info *info; | |
2631 | const Elf_Internal_Sym *sym; | |
2632 | const char **namep; | |
2633 | flagword *flagsp; | |
2634 | asection **secp; | |
2635 | bfd_vma *valp; | |
2636 | { | |
53787b23 ILT |
2637 | if (SGI_COMPAT (abfd) |
2638 | && (abfd->flags & DYNAMIC) != 0 | |
2639 | && strcmp (*namep, "_rld_new_interface") == 0) | |
2640 | { | |
2641 | /* Skip Irix 5 rld entry name. */ | |
2642 | *namep = NULL; | |
2643 | return true; | |
2644 | } | |
2645 | ||
aac6b32f ILT |
2646 | switch (sym->st_shndx) |
2647 | { | |
2648 | case SHN_COMMON: | |
2649 | /* Common symbols less than the GP size are automatically | |
2650 | treated as SHN_MIPS_SCOMMON symbols. */ | |
2651 | if (sym->st_size > elf_gp_size (abfd)) | |
2652 | break; | |
2653 | /* Fall through. */ | |
2654 | case SHN_MIPS_SCOMMON: | |
2655 | *secp = bfd_make_section_old_way (abfd, ".scommon"); | |
2656 | (*secp)->flags |= SEC_IS_COMMON; | |
2657 | *valp = sym->st_size; | |
2658 | break; | |
2659 | ||
5b3b9ff6 ILT |
2660 | case SHN_MIPS_TEXT: |
2661 | /* This section is used in a shared object. */ | |
2662 | if (mips_elf_text_section_ptr == NULL) | |
2663 | { | |
2664 | /* Initialize the section. */ | |
2665 | mips_elf_text_section.name = ".text"; | |
2666 | mips_elf_text_section.flags = SEC_NO_FLAGS; | |
2667 | mips_elf_text_section.output_section = NULL; | |
2668 | mips_elf_text_section.owner = abfd; | |
2669 | mips_elf_text_section.symbol = &mips_elf_text_symbol; | |
2670 | mips_elf_text_section.symbol_ptr_ptr = &mips_elf_text_symbol_ptr; | |
2671 | mips_elf_text_symbol.name = ".text"; | |
2672 | mips_elf_text_symbol.flags = BSF_SECTION_SYM; | |
2673 | mips_elf_text_symbol.section = &mips_elf_text_section; | |
2674 | mips_elf_text_symbol_ptr = &mips_elf_text_symbol; | |
2675 | mips_elf_text_section_ptr = &mips_elf_text_section; | |
2676 | } | |
2677 | if (info->shared) | |
2678 | *secp = bfd_und_section_ptr; | |
2679 | else | |
2680 | *secp = mips_elf_text_section_ptr; | |
2681 | break; | |
2682 | ||
53787b23 ILT |
2683 | case SHN_MIPS_ACOMMON: |
2684 | /* Fall through. XXX Can we treat this as allocated data? */ | |
5b3b9ff6 ILT |
2685 | case SHN_MIPS_DATA: |
2686 | /* This section is used in a shared object. */ | |
2687 | if (mips_elf_data_section_ptr == NULL) | |
2688 | { | |
2689 | /* Initialize the section. */ | |
2690 | mips_elf_data_section.name = ".data"; | |
2691 | mips_elf_data_section.flags = SEC_NO_FLAGS; | |
2692 | mips_elf_data_section.output_section = NULL; | |
2693 | mips_elf_data_section.owner = abfd; | |
2694 | mips_elf_data_section.symbol = &mips_elf_data_symbol; | |
2695 | mips_elf_data_section.symbol_ptr_ptr = &mips_elf_data_symbol_ptr; | |
2696 | mips_elf_data_symbol.name = ".data"; | |
2697 | mips_elf_data_symbol.flags = BSF_SECTION_SYM; | |
2698 | mips_elf_data_symbol.section = &mips_elf_data_section; | |
2699 | mips_elf_data_symbol_ptr = &mips_elf_data_symbol; | |
2700 | mips_elf_data_section_ptr = &mips_elf_data_section; | |
2701 | } | |
2702 | if (info->shared) | |
2703 | *secp = bfd_und_section_ptr; | |
2704 | else | |
2705 | *secp = mips_elf_data_section_ptr; | |
2706 | break; | |
2707 | ||
aac6b32f | 2708 | case SHN_MIPS_SUNDEFINED: |
24f13b03 | 2709 | *secp = bfd_und_section_ptr; |
aac6b32f ILT |
2710 | break; |
2711 | } | |
2712 | ||
2713 | return true; | |
2714 | } | |
2715 | ||
2716 | /* Structure used to pass information to mips_elf_output_extsym. */ | |
2717 | ||
2718 | struct extsym_info | |
6e07e54f | 2719 | { |
aac6b32f ILT |
2720 | bfd *abfd; |
2721 | struct bfd_link_info *info; | |
2722 | struct ecoff_debug_info *debug; | |
9783e04a | 2723 | const struct ecoff_debug_swap *swap; |
aac6b32f ILT |
2724 | boolean failed; |
2725 | }; | |
9783e04a | 2726 | |
aac6b32f ILT |
2727 | /* This routine is used to write out ECOFF debugging external symbol |
2728 | information. It is called via mips_elf_link_hash_traverse. The | |
2729 | ECOFF external symbol information must match the ELF external | |
2730 | symbol information. Unfortunately, at this point we don't know | |
2731 | whether a symbol is required by reloc information, so the two | |
2732 | tables may wind up being different. We must sort out the external | |
2733 | symbol information before we can set the final size of the .mdebug | |
2734 | section, and we must set the size of the .mdebug section before we | |
2735 | can relocate any sections, and we can't know which symbols are | |
2736 | required by relocation until we relocate the sections. | |
2737 | Fortunately, it is relatively unlikely that any symbol will be | |
2738 | stripped but required by a reloc. In particular, it can not happen | |
2739 | when generating a final executable. */ | |
2740 | ||
2741 | static boolean | |
2742 | mips_elf_output_extsym (h, data) | |
2743 | struct mips_elf_link_hash_entry *h; | |
2744 | PTR data; | |
2745 | { | |
2746 | struct extsym_info *einfo = (struct extsym_info *) data; | |
2747 | boolean strip; | |
5b3b9ff6 | 2748 | asection *sec, *output_section; |
aac6b32f ILT |
2749 | |
2750 | if (h->root.indx == -2) | |
2751 | strip = false; | |
2752 | else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
2753 | || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0) | |
2754 | && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 | |
2755 | && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0) | |
2756 | strip = true; | |
2757 | else if (einfo->info->strip == strip_all | |
2758 | || (einfo->info->strip == strip_some | |
2759 | && bfd_hash_lookup (einfo->info->keep_hash, | |
2760 | h->root.root.root.string, | |
2761 | false, false) == NULL)) | |
2762 | strip = true; | |
2763 | else | |
2764 | strip = false; | |
2765 | ||
2766 | if (strip) | |
2767 | return true; | |
6e07e54f | 2768 | |
aac6b32f | 2769 | if (h->esym.ifd == -2) |
6e07e54f | 2770 | { |
aac6b32f ILT |
2771 | h->esym.jmptbl = 0; |
2772 | h->esym.cobol_main = 0; | |
2773 | h->esym.weakext = 0; | |
2774 | h->esym.reserved = 0; | |
2775 | h->esym.ifd = ifdNil; | |
2776 | h->esym.asym.value = 0; | |
2777 | h->esym.asym.st = stGlobal; | |
2778 | ||
5b3b9ff6 ILT |
2779 | if (SGI_COMPAT (einfo->abfd) |
2780 | && (h->root.root.type == bfd_link_hash_undefined | |
2781 | || h->root.root.type == bfd_link_hash_undefweak)) | |
2782 | { | |
2783 | const char *name; | |
2784 | ||
2785 | /* Use undefined class. Also, set class and type for some | |
2786 | special symbols. */ | |
2787 | name = h->root.root.root.string; | |
2788 | if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0 | |
2789 | || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0) | |
2790 | { | |
2791 | h->esym.asym.sc = scData; | |
2792 | h->esym.asym.st = stLabel; | |
2793 | h->esym.asym.value = 0; | |
2794 | } | |
2795 | else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0) | |
2796 | { | |
2797 | h->esym.asym.sc = scAbs; | |
2798 | h->esym.asym.st = stLabel; | |
2799 | h->esym.asym.value = | |
2800 | mips_elf_hash_table (einfo->info)->procedure_count; | |
2801 | } | |
2802 | else if (strcmp (name, "_gp_disp") == 0) | |
2803 | { | |
2804 | h->esym.asym.sc = scAbs; | |
2805 | h->esym.asym.st = stLabel; | |
2806 | h->esym.asym.value = elf_gp (einfo->abfd); | |
2807 | } | |
2808 | else | |
2809 | h->esym.asym.sc = scUndefined; | |
2810 | } | |
2811 | else if (h->root.root.type != bfd_link_hash_defined | |
a16fcab3 | 2812 | && h->root.root.type != bfd_link_hash_defweak) |
aac6b32f ILT |
2813 | h->esym.asym.sc = scAbs; |
2814 | else | |
2815 | { | |
aac6b32f ILT |
2816 | const char *name; |
2817 | ||
5b3b9ff6 ILT |
2818 | sec = h->root.root.u.def.section; |
2819 | output_section = sec->output_section; | |
2820 | ||
2821 | /* When making a shared library and symbol h is the one from | |
2822 | the another shared library, OUTPUT_SECTION may be null. */ | |
2823 | if (output_section == NULL) | |
2824 | h->esym.asym.sc = scUndefined; | |
aac6b32f | 2825 | else |
5b3b9ff6 ILT |
2826 | { |
2827 | name = bfd_section_name (output_section->owner, output_section); | |
2828 | ||
2829 | if (strcmp (name, ".text") == 0) | |
2830 | h->esym.asym.sc = scText; | |
2831 | else if (strcmp (name, ".data") == 0) | |
2832 | h->esym.asym.sc = scData; | |
2833 | else if (strcmp (name, ".sdata") == 0) | |
2834 | h->esym.asym.sc = scSData; | |
2835 | else if (strcmp (name, ".rodata") == 0 | |
2836 | || strcmp (name, ".rdata") == 0) | |
2837 | h->esym.asym.sc = scRData; | |
2838 | else if (strcmp (name, ".bss") == 0) | |
2839 | h->esym.asym.sc = scBss; | |
2840 | else if (strcmp (name, ".sbss") == 0) | |
2841 | h->esym.asym.sc = scSBss; | |
2842 | else if (strcmp (name, ".init") == 0) | |
2843 | h->esym.asym.sc = scInit; | |
2844 | else if (strcmp (name, ".fini") == 0) | |
2845 | h->esym.asym.sc = scFini; | |
2846 | else | |
2847 | h->esym.asym.sc = scAbs; | |
2848 | } | |
aac6b32f ILT |
2849 | } |
2850 | ||
2851 | h->esym.asym.reserved = 0; | |
2852 | h->esym.asym.index = indexNil; | |
6e07e54f ILT |
2853 | } |
2854 | ||
16fe8950 ILT |
2855 | if (h->root.root.type == bfd_link_hash_common) |
2856 | h->esym.asym.value = h->root.root.u.c.size; | |
a16fcab3 KR |
2857 | else if (h->root.root.type == bfd_link_hash_defined |
2858 | || h->root.root.type == bfd_link_hash_defweak) | |
16fe8950 | 2859 | { |
16fe8950 ILT |
2860 | if (h->esym.asym.sc == scCommon) |
2861 | h->esym.asym.sc = scBss; | |
2862 | else if (h->esym.asym.sc == scSCommon) | |
2863 | h->esym.asym.sc = scSBss; | |
2864 | ||
2865 | sec = h->root.root.u.def.section; | |
5b3b9ff6 ILT |
2866 | output_section = sec->output_section; |
2867 | if (output_section != NULL) | |
2868 | h->esym.asym.value = (h->root.root.u.def.value | |
2869 | + sec->output_offset | |
2870 | + output_section->vma); | |
2871 | else | |
2872 | h->esym.asym.value = 0; | |
16fe8950 | 2873 | } |
5b3b9ff6 ILT |
2874 | else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) |
2875 | { | |
2876 | /* Set type and value for a symbol with a function stub. */ | |
2877 | h->esym.asym.st = stProc; | |
2878 | sec = h->root.root.u.def.section; | |
2879 | if (sec == NULL) | |
2880 | h->esym.asym.value = 0; | |
2881 | else | |
2882 | { | |
2883 | output_section = sec->output_section; | |
2884 | if (output_section != NULL) | |
2885 | h->esym.asym.value = (h->root.plt_offset | |
2886 | + sec->output_offset | |
2887 | + output_section->vma); | |
2888 | else | |
2889 | h->esym.asym.value = 0; | |
2890 | } | |
2891 | #if 0 /* FIXME? */ | |
2892 | h->esym.ifd = 0; | |
2893 | #endif | |
2894 | } | |
aac6b32f ILT |
2895 | |
2896 | if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap, | |
2897 | h->root.root.root.string, | |
2898 | &h->esym)) | |
2899 | { | |
2900 | einfo->failed = true; | |
2901 | return false; | |
2902 | } | |
6e07e54f ILT |
2903 | |
2904 | return true; | |
2905 | } | |
2906 | ||
5b3b9ff6 ILT |
2907 | /* Create a runtime procedure table from the .mdebug section. */ |
2908 | ||
2909 | static boolean | |
2910 | mips_elf_create_procedure_table (handle, abfd, info, s, debug) | |
2911 | PTR handle; | |
2912 | bfd *abfd; | |
2913 | struct bfd_link_info *info; | |
2914 | asection *s; | |
2915 | struct ecoff_debug_info *debug; | |
2916 | { | |
2917 | const struct ecoff_debug_swap *swap; | |
2918 | HDRR *hdr = &debug->symbolic_header; | |
2919 | RPDR *rpdr, *rp; | |
2920 | struct rpdr_ext *erp; | |
2921 | PTR rtproc; | |
2922 | struct pdr_ext *epdr; | |
2923 | struct sym_ext *esym; | |
2924 | char *ss, **sv; | |
2925 | char *str; | |
2926 | unsigned long size, count; | |
2927 | unsigned long sindex; | |
2928 | unsigned long i; | |
2929 | PDR pdr; | |
2930 | SYMR sym; | |
2931 | const char *no_name_func = "static procedure (no name)"; | |
2932 | ||
2933 | epdr = NULL; | |
2934 | rpdr = NULL; | |
2935 | esym = NULL; | |
2936 | ss = NULL; | |
abec70b9 | 2937 | sv = NULL; |
5b3b9ff6 ILT |
2938 | |
2939 | swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap; | |
2940 | ||
2941 | sindex = strlen (no_name_func) + 1; | |
2942 | count = hdr->ipdMax; | |
2943 | if (count > 0) | |
2944 | { | |
2945 | size = swap->external_pdr_size; | |
2946 | ||
2947 | epdr = (struct pdr_ext *) bfd_malloc (size * count); | |
2948 | if (epdr == NULL) | |
2949 | goto error_return; | |
2950 | ||
2951 | if (! _bfd_ecoff_get_accumulated_pdr (handle, (PTR) epdr)) | |
2952 | goto error_return; | |
2953 | ||
2954 | size = sizeof (RPDR); | |
2955 | rp = rpdr = (RPDR *) bfd_malloc (size * count); | |
2956 | if (rpdr == NULL) | |
2957 | goto error_return; | |
2958 | ||
2959 | sv = (char **) bfd_malloc (sizeof (char *) * count); | |
2960 | if (sv == NULL) | |
2961 | goto error_return; | |
2962 | ||
2963 | count = hdr->isymMax; | |
2964 | size = swap->external_sym_size; | |
2965 | esym = (struct sym_ext *) bfd_malloc (size * count); | |
2966 | if (esym == NULL) | |
2967 | goto error_return; | |
2968 | ||
2969 | if (! _bfd_ecoff_get_accumulated_sym (handle, (PTR) esym)) | |
2970 | goto error_return; | |
2971 | ||
2972 | count = hdr->issMax; | |
2973 | ss = (char *) bfd_malloc (count); | |
2974 | if (ss == NULL) | |
2975 | goto error_return; | |
2976 | if (! _bfd_ecoff_get_accumulated_ss (handle, (PTR) ss)) | |
2977 | goto error_return; | |
2978 | ||
2979 | count = hdr->ipdMax; | |
abec70b9 | 2980 | for (i = 0; i < count; i++, rp++) |
5b3b9ff6 | 2981 | { |
abec70b9 | 2982 | (*swap->swap_pdr_in) (abfd, (PTR) (epdr + i), &pdr); |
5b3b9ff6 ILT |
2983 | (*swap->swap_sym_in) (abfd, (PTR) &esym[pdr.isym], &sym); |
2984 | rp->adr = sym.value; | |
2985 | rp->regmask = pdr.regmask; | |
2986 | rp->regoffset = pdr.regoffset; | |
2987 | rp->fregmask = pdr.fregmask; | |
2988 | rp->fregoffset = pdr.fregoffset; | |
2989 | rp->frameoffset = pdr.frameoffset; | |
2990 | rp->framereg = pdr.framereg; | |
2991 | rp->pcreg = pdr.pcreg; | |
2992 | rp->irpss = sindex; | |
2993 | sv[i] = ss + sym.iss; | |
2994 | sindex += strlen (sv[i]) + 1; | |
2995 | } | |
2996 | } | |
2997 | ||
2998 | size = sizeof (struct rpdr_ext) * (count + 2) + sindex; | |
2999 | size = BFD_ALIGN (size, 16); | |
3000 | rtproc = (PTR) bfd_alloc (abfd, size); | |
3001 | if (rtproc == NULL) | |
3002 | { | |
3003 | mips_elf_hash_table (info)->procedure_count = 0; | |
3004 | goto error_return; | |
3005 | } | |
3006 | ||
3007 | mips_elf_hash_table (info)->procedure_count = count + 2; | |
3008 | ||
3009 | erp = (struct rpdr_ext *) rtproc; | |
abec70b9 | 3010 | memset (erp, 0, sizeof (struct rpdr_ext)); |
5b3b9ff6 ILT |
3011 | erp++; |
3012 | str = (char *) rtproc + sizeof (struct rpdr_ext) * (count + 2); | |
3013 | strcpy (str, no_name_func); | |
3014 | str += strlen (no_name_func) + 1; | |
3015 | for (i = 0; i < count; i++) | |
3016 | { | |
3017 | ecoff_swap_rpdr_out (abfd, rpdr + i, erp + i); | |
3018 | strcpy (str, sv[i]); | |
3019 | str += strlen (sv[i]) + 1; | |
3020 | } | |
3021 | ecoff_put_off (abfd, (bfd_vma) -1, (bfd_byte *) (erp + count)->p_adr); | |
3022 | ||
3023 | /* Set the size and contents of .rtproc section. */ | |
3024 | s->_raw_size = size; | |
3025 | s->contents = rtproc; | |
3026 | ||
3027 | /* Skip this section later on (I don't think this currently | |
3028 | matters, but someday it might). */ | |
3029 | s->link_order_head = (struct bfd_link_order *) NULL; | |
3030 | ||
abec70b9 ILT |
3031 | if (epdr != NULL) |
3032 | free (epdr); | |
3033 | if (rpdr != NULL) | |
3034 | free (rpdr); | |
3035 | if (esym != NULL) | |
3036 | free (esym); | |
3037 | if (ss != NULL) | |
3038 | free (ss); | |
3039 | if (sv != NULL) | |
3040 | free (sv); | |
5b3b9ff6 ILT |
3041 | |
3042 | return true; | |
3043 | ||
3044 | error_return: | |
3045 | if (epdr != NULL) | |
3046 | free (epdr); | |
3047 | if (rpdr != NULL) | |
3048 | free (rpdr); | |
3049 | if (esym != NULL) | |
3050 | free (esym); | |
3051 | if (ss != NULL) | |
3052 | free (ss); | |
3053 | if (sv != NULL) | |
3054 | free (sv); | |
3055 | return false; | |
3056 | } | |
3057 | ||
aac6b32f | 3058 | /* A comparison routine used to sort .gptab entries. */ |
6e07e54f | 3059 | |
aac6b32f ILT |
3060 | static int |
3061 | gptab_compare (p1, p2) | |
3062 | const PTR p1; | |
3063 | const PTR p2; | |
6e07e54f | 3064 | { |
aac6b32f ILT |
3065 | const Elf32_gptab *a1 = (const Elf32_gptab *) p1; |
3066 | const Elf32_gptab *a2 = (const Elf32_gptab *) p2; | |
3067 | ||
3068 | return a1->gt_entry.gt_g_value - a2->gt_entry.gt_g_value; | |
6e07e54f ILT |
3069 | } |
3070 | ||
3071 | /* We need to use a special link routine to handle the .reginfo and | |
3072 | the .mdebug sections. We need to merge all instances of these | |
3073 | sections together, not write them all out sequentially. */ | |
3074 | ||
3075 | static boolean | |
3076 | mips_elf_final_link (abfd, info) | |
3077 | bfd *abfd; | |
3078 | struct bfd_link_info *info; | |
3079 | { | |
6e07e54f ILT |
3080 | asection **secpp; |
3081 | asection *o; | |
3082 | struct bfd_link_order *p; | |
aac6b32f | 3083 | asection *reginfo_sec, *mdebug_sec, *gptab_data_sec, *gptab_bss_sec; |
5b3b9ff6 | 3084 | asection *rtproc_sec; |
b3c0fc57 | 3085 | Elf32_RegInfo reginfo; |
6e07e54f ILT |
3086 | struct ecoff_debug_info debug; |
3087 | const struct ecoff_debug_swap *swap | |
3088 | = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap; | |
3089 | HDRR *symhdr = &debug.symbolic_header; | |
9783e04a | 3090 | PTR mdebug_handle = NULL; |
6e07e54f | 3091 | |
497c5434 | 3092 | /* Drop the .options section, since it has special semantics which I |
aac6b32f ILT |
3093 | haven't bothered to figure out. */ |
3094 | for (secpp = &abfd->sections; *secpp != NULL; secpp = &(*secpp)->next) | |
6e07e54f | 3095 | { |
aac6b32f | 3096 | if (strcmp ((*secpp)->name, ".options") == 0) |
6e07e54f | 3097 | { |
aac6b32f ILT |
3098 | for (p = (*secpp)->link_order_head; p != NULL; p = p->next) |
3099 | if (p->type == bfd_indirect_link_order) | |
3100 | p->u.indirect.section->flags &=~ SEC_HAS_CONTENTS; | |
3101 | (*secpp)->link_order_head = NULL; | |
6e07e54f ILT |
3102 | *secpp = (*secpp)->next; |
3103 | --abfd->section_count; | |
aac6b32f | 3104 | break; |
6e07e54f | 3105 | } |
6e07e54f | 3106 | } |
b3c0fc57 | 3107 | |
5b3b9ff6 ILT |
3108 | /* Get a value for the GP register. */ |
3109 | if (elf_gp (abfd) == 0) | |
b3c0fc57 | 3110 | { |
5b3b9ff6 ILT |
3111 | struct bfd_link_hash_entry *h; |
3112 | ||
3113 | h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true); | |
3114 | if (h != (struct bfd_link_hash_entry *) NULL | |
3115 | && h->type == bfd_link_hash_defined) | |
3116 | elf_gp (abfd) = (h->u.def.value | |
3117 | + h->u.def.section->output_section->vma | |
3118 | + h->u.def.section->output_offset); | |
3119 | else if (info->relocateable) | |
b3c0fc57 | 3120 | { |
5b3b9ff6 | 3121 | bfd_vma lo; |
b3c0fc57 | 3122 | |
5b3b9ff6 ILT |
3123 | /* Make up a value. */ |
3124 | lo = (bfd_vma) -1; | |
3125 | for (o = abfd->sections; o != (asection *) NULL; o = o->next) | |
3126 | { | |
3127 | if (o->vma < lo | |
3128 | && (strcmp (o->name, ".sbss") == 0 | |
3129 | || strcmp (o->name, ".sdata") == 0 | |
3130 | || strcmp (o->name, ".lit4") == 0 | |
3131 | || strcmp (o->name, ".lit8") == 0)) | |
3132 | lo = o->vma; | |
3133 | } | |
3134 | elf_gp (abfd) = lo + ELF_MIPS_GP_OFFSET (abfd); | |
3135 | } | |
3136 | else | |
3137 | { | |
3138 | /* If the relocate_section function needs to do a reloc | |
3139 | involving the GP value, it should make a reloc_dangerous | |
3140 | callback to warn that GP is not defined. */ | |
3141 | } | |
3142 | } | |
3143 | ||
3144 | /* Go through the sections and collect the .reginfo and .mdebug | |
3145 | information. */ | |
3146 | reginfo_sec = NULL; | |
3147 | mdebug_sec = NULL; | |
3148 | gptab_data_sec = NULL; | |
3149 | gptab_bss_sec = NULL; | |
3150 | for (o = abfd->sections; o != (asection *) NULL; o = o->next) | |
3151 | { | |
3152 | if (strcmp (o->name, ".reginfo") == 0) | |
3153 | { | |
3154 | memset (®info, 0, sizeof reginfo); | |
3155 | ||
3156 | /* We have found the .reginfo section in the output file. | |
3157 | Look through all the link_orders comprising it and merge | |
3158 | the information together. */ | |
3159 | for (p = o->link_order_head; | |
3160 | p != (struct bfd_link_order *) NULL; | |
3161 | p = p->next) | |
3162 | { | |
3163 | asection *input_section; | |
6e07e54f ILT |
3164 | bfd *input_bfd; |
3165 | Elf32_External_RegInfo ext; | |
3166 | Elf32_RegInfo sub; | |
3167 | ||
3168 | if (p->type != bfd_indirect_link_order) | |
aac6b32f ILT |
3169 | { |
3170 | if (p->type == bfd_fill_link_order) | |
3171 | continue; | |
3172 | abort (); | |
3173 | } | |
6e07e54f ILT |
3174 | |
3175 | input_section = p->u.indirect.section; | |
3176 | input_bfd = input_section->owner; | |
a16fcab3 KR |
3177 | |
3178 | /* The linker emulation code has probably clobbered the | |
3179 | size to be zero bytes. */ | |
3180 | if (input_section->_raw_size == 0) | |
3181 | input_section->_raw_size = sizeof (Elf32_External_RegInfo); | |
3182 | ||
6e07e54f ILT |
3183 | if (! bfd_get_section_contents (input_bfd, input_section, |
3184 | (PTR) &ext, | |
3185 | (file_ptr) 0, | |
3186 | sizeof ext)) | |
3187 | return false; | |
3188 | ||
3189 | bfd_mips_elf32_swap_reginfo_in (input_bfd, &ext, &sub); | |
3190 | ||
3191 | reginfo.ri_gprmask |= sub.ri_gprmask; | |
3192 | reginfo.ri_cprmask[0] |= sub.ri_cprmask[0]; | |
3193 | reginfo.ri_cprmask[1] |= sub.ri_cprmask[1]; | |
3194 | reginfo.ri_cprmask[2] |= sub.ri_cprmask[2]; | |
3195 | reginfo.ri_cprmask[3] |= sub.ri_cprmask[3]; | |
3196 | ||
3197 | /* ri_gp_value is set by the function | |
00176555 | 3198 | mips_elf32_section_processing when the section is |
6e07e54f | 3199 | finally written out. */ |
aac6b32f ILT |
3200 | |
3201 | /* Hack: reset the SEC_HAS_CONTENTS flag so that | |
3202 | elf_link_input_bfd ignores this section. */ | |
3203 | input_section->flags &=~ SEC_HAS_CONTENTS; | |
6e07e54f ILT |
3204 | } |
3205 | ||
3206 | /* Force the section size to the value we want. */ | |
3207 | o->_raw_size = sizeof (Elf32_External_RegInfo); | |
3208 | ||
aac6b32f ILT |
3209 | /* Skip this section later on (I don't think this currently |
3210 | matters, but someday it might). */ | |
6e07e54f ILT |
3211 | o->link_order_head = (struct bfd_link_order *) NULL; |
3212 | ||
3213 | reginfo_sec = o; | |
3214 | } | |
3215 | ||
3216 | if (strcmp (o->name, ".mdebug") == 0) | |
3217 | { | |
aac6b32f ILT |
3218 | struct extsym_info einfo; |
3219 | ||
6e07e54f ILT |
3220 | /* We have found the .mdebug section in the output file. |
3221 | Look through all the link_orders comprising it and merge | |
3222 | the information together. */ | |
3223 | symhdr->magic = swap->sym_magic; | |
3224 | /* FIXME: What should the version stamp be? */ | |
3225 | symhdr->vstamp = 0; | |
3226 | symhdr->ilineMax = 0; | |
3227 | symhdr->cbLine = 0; | |
3228 | symhdr->idnMax = 0; | |
3229 | symhdr->ipdMax = 0; | |
3230 | symhdr->isymMax = 0; | |
3231 | symhdr->ioptMax = 0; | |
3232 | symhdr->iauxMax = 0; | |
3233 | symhdr->issMax = 0; | |
3234 | symhdr->issExtMax = 0; | |
3235 | symhdr->ifdMax = 0; | |
3236 | symhdr->crfd = 0; | |
3237 | symhdr->iextMax = 0; | |
3238 | ||
3239 | /* We accumulate the debugging information itself in the | |
3240 | debug_info structure. */ | |
9783e04a DM |
3241 | debug.line = NULL; |
3242 | debug.external_dnr = NULL; | |
3243 | debug.external_pdr = NULL; | |
3244 | debug.external_sym = NULL; | |
3245 | debug.external_opt = NULL; | |
3246 | debug.external_aux = NULL; | |
3247 | debug.ss = NULL; | |
6e07e54f | 3248 | debug.ssext = debug.ssext_end = NULL; |
9783e04a DM |
3249 | debug.external_fdr = NULL; |
3250 | debug.external_rfd = NULL; | |
6e07e54f ILT |
3251 | debug.external_ext = debug.external_ext_end = NULL; |
3252 | ||
9783e04a DM |
3253 | mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info); |
3254 | if (mdebug_handle == (PTR) NULL) | |
3255 | return false; | |
3256 | ||
5b3b9ff6 ILT |
3257 | if (SGI_COMPAT (abfd)) |
3258 | { | |
3259 | asection *s; | |
3260 | EXTR esym; | |
3261 | bfd_vma last; | |
3262 | unsigned int i; | |
3263 | static const char * const name[] = | |
3264 | { ".text", ".init", ".fini", ".data", | |
3265 | ".rodata", ".sdata", ".sbss", ".bss" }; | |
3266 | static const int sc[] = { scText, scInit, scFini, scData, | |
3267 | scRData, scSData, scSBss, scBss }; | |
3268 | ||
3269 | esym.jmptbl = 0; | |
3270 | esym.cobol_main = 0; | |
3271 | esym.weakext = 0; | |
3272 | esym.reserved = 0; | |
3273 | esym.ifd = ifdNil; | |
3274 | esym.asym.iss = issNil; | |
3275 | esym.asym.st = stLocal; | |
3276 | esym.asym.reserved = 0; | |
3277 | esym.asym.index = indexNil; | |
3278 | for (i = 0; i < 8; i++) | |
3279 | { | |
3280 | esym.asym.sc = sc[i]; | |
3281 | s = bfd_get_section_by_name (abfd, name[i]); | |
3282 | if (s != NULL) | |
3283 | { | |
3284 | esym.asym.value = s->vma; | |
3285 | last = s->vma + s->_raw_size; | |
3286 | } | |
3287 | else | |
3288 | esym.asym.value = last; | |
3289 | ||
3290 | if (! bfd_ecoff_debug_one_external (abfd, &debug, swap, | |
3291 | name[i], &esym)) | |
3292 | return false; | |
3293 | } | |
3294 | } | |
3295 | ||
6e07e54f ILT |
3296 | for (p = o->link_order_head; |
3297 | p != (struct bfd_link_order *) NULL; | |
3298 | p = p->next) | |
3299 | { | |
3300 | asection *input_section; | |
3301 | bfd *input_bfd; | |
3302 | const struct ecoff_debug_swap *input_swap; | |
3303 | struct ecoff_debug_info input_debug; | |
aac6b32f ILT |
3304 | char *eraw_src; |
3305 | char *eraw_end; | |
6e07e54f ILT |
3306 | |
3307 | if (p->type != bfd_indirect_link_order) | |
aac6b32f ILT |
3308 | { |
3309 | if (p->type == bfd_fill_link_order) | |
3310 | continue; | |
3311 | abort (); | |
3312 | } | |
6e07e54f ILT |
3313 | |
3314 | input_section = p->u.indirect.section; | |
3315 | input_bfd = input_section->owner; | |
3316 | ||
3317 | if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour | |
3318 | || (get_elf_backend_data (input_bfd) | |
3319 | ->elf_backend_ecoff_debug_swap) == NULL) | |
b3c0fc57 | 3320 | { |
6e07e54f ILT |
3321 | /* I don't know what a non MIPS ELF bfd would be |
3322 | doing with a .mdebug section, but I don't really | |
3323 | want to deal with it. */ | |
3324 | continue; | |
b3c0fc57 | 3325 | } |
6e07e54f ILT |
3326 | |
3327 | input_swap = (get_elf_backend_data (input_bfd) | |
3328 | ->elf_backend_ecoff_debug_swap); | |
3329 | ||
3330 | BFD_ASSERT (p->size == input_section->_raw_size); | |
3331 | ||
3332 | /* The ECOFF linking code expects that we have already | |
3333 | read in the debugging information and set up an | |
3334 | ecoff_debug_info structure, so we do that now. */ | |
00176555 ILT |
3335 | if (! _bfd_mips_elf_read_ecoff_info (input_bfd, input_section, |
3336 | &input_debug)) | |
6e07e54f ILT |
3337 | return false; |
3338 | ||
3339 | if (! (bfd_ecoff_debug_accumulate | |
9783e04a DM |
3340 | (mdebug_handle, abfd, &debug, swap, input_bfd, |
3341 | &input_debug, input_swap, info))) | |
6e07e54f ILT |
3342 | return false; |
3343 | ||
3344 | /* Loop through the external symbols. For each one with | |
aac6b32f ILT |
3345 | interesting information, try to find the symbol in |
3346 | the linker global hash table and save the information | |
3347 | for the output external symbols. */ | |
3348 | eraw_src = input_debug.external_ext; | |
3349 | eraw_end = (eraw_src | |
3350 | + (input_debug.symbolic_header.iextMax | |
3351 | * input_swap->external_ext_size)); | |
3352 | for (; | |
3353 | eraw_src < eraw_end; | |
3354 | eraw_src += input_swap->external_ext_size) | |
6e07e54f | 3355 | { |
aac6b32f ILT |
3356 | EXTR ext; |
3357 | const char *name; | |
3358 | struct mips_elf_link_hash_entry *h; | |
3359 | ||
3360 | (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext); | |
3361 | if (ext.asym.sc == scNil | |
3362 | || ext.asym.sc == scUndefined | |
3363 | || ext.asym.sc == scSUndefined) | |
3364 | continue; | |
3365 | ||
3366 | name = input_debug.ssext + ext.asym.iss; | |
3367 | h = mips_elf_link_hash_lookup (mips_elf_hash_table (info), | |
3368 | name, false, false, true); | |
3369 | if (h == NULL || h->esym.ifd != -2) | |
3370 | continue; | |
3371 | ||
3372 | if (ext.ifd != -1) | |
6e07e54f | 3373 | { |
aac6b32f ILT |
3374 | BFD_ASSERT (ext.ifd |
3375 | < input_debug.symbolic_header.ifdMax); | |
3376 | ext.ifd = input_debug.ifdmap[ext.ifd]; | |
6e07e54f | 3377 | } |
aac6b32f ILT |
3378 | |
3379 | h->esym = ext; | |
6e07e54f ILT |
3380 | } |
3381 | ||
aac6b32f | 3382 | /* Free up the information we just read. */ |
6e07e54f ILT |
3383 | free (input_debug.line); |
3384 | free (input_debug.external_dnr); | |
3385 | free (input_debug.external_pdr); | |
3386 | free (input_debug.external_sym); | |
3387 | free (input_debug.external_opt); | |
3388 | free (input_debug.external_aux); | |
3389 | free (input_debug.ss); | |
3390 | free (input_debug.ssext); | |
3391 | free (input_debug.external_fdr); | |
3392 | free (input_debug.external_rfd); | |
aac6b32f ILT |
3393 | free (input_debug.external_ext); |
3394 | ||
3395 | /* Hack: reset the SEC_HAS_CONTENTS flag so that | |
3396 | elf_link_input_bfd ignores this section. */ | |
3397 | input_section->flags &=~ SEC_HAS_CONTENTS; | |
b3c0fc57 ILT |
3398 | } |
3399 | ||
5b3b9ff6 ILT |
3400 | if (SGI_COMPAT (abfd) && info->shared) |
3401 | { | |
3402 | /* Create .rtproc section. */ | |
3403 | rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc"); | |
3404 | if (rtproc_sec == NULL) | |
3405 | { | |
3406 | flagword flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
3407 | | SEC_READONLY); | |
3408 | ||
3409 | rtproc_sec = bfd_make_section (abfd, ".rtproc"); | |
3410 | if (rtproc_sec == NULL | |
3411 | || ! bfd_set_section_flags (abfd, rtproc_sec, flags) | |
3412 | || ! bfd_set_section_alignment (abfd, rtproc_sec, 12)) | |
3413 | return false; | |
3414 | } | |
3415 | ||
3416 | if (! mips_elf_create_procedure_table (mdebug_handle, abfd, | |
3417 | info, rtproc_sec, &debug)) | |
3418 | return false; | |
3419 | } | |
3420 | ||
6e07e54f | 3421 | /* Build the external symbol information. */ |
aac6b32f ILT |
3422 | einfo.abfd = abfd; |
3423 | einfo.info = info; | |
3424 | einfo.debug = &debug; | |
3425 | einfo.swap = swap; | |
3426 | einfo.failed = false; | |
3427 | mips_elf_link_hash_traverse (mips_elf_hash_table (info), | |
3428 | mips_elf_output_extsym, | |
3429 | (PTR) &einfo); | |
3430 | if (einfo.failed) | |
b3c0fc57 ILT |
3431 | return false; |
3432 | ||
aac6b32f | 3433 | /* Set the size of the .mdebug section. */ |
6e07e54f ILT |
3434 | o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap); |
3435 | ||
aac6b32f ILT |
3436 | /* Skip this section later on (I don't think this currently |
3437 | matters, but someday it might). */ | |
6e07e54f ILT |
3438 | o->link_order_head = (struct bfd_link_order *) NULL; |
3439 | ||
3440 | mdebug_sec = o; | |
3441 | } | |
6e07e54f | 3442 | |
aac6b32f | 3443 | if (strncmp (o->name, ".gptab.", sizeof ".gptab." - 1) == 0) |
6e07e54f | 3444 | { |
aac6b32f ILT |
3445 | const char *subname; |
3446 | unsigned int c; | |
3447 | Elf32_gptab *tab; | |
3448 | Elf32_External_gptab *ext_tab; | |
3449 | unsigned int i; | |
3450 | ||
3451 | /* The .gptab.sdata and .gptab.sbss sections hold | |
3452 | information describing how the small data area would | |
3453 | change depending upon the -G switch. These sections | |
3454 | not used in executables files. */ | |
3455 | if (! info->relocateable) | |
3456 | { | |
3457 | asection **secpp; | |
3458 | ||
3459 | for (p = o->link_order_head; | |
3460 | p != (struct bfd_link_order *) NULL; | |
3461 | p = p->next) | |
3462 | { | |
3463 | asection *input_section; | |
3464 | ||
3465 | if (p->type != bfd_indirect_link_order) | |
3466 | { | |
3467 | if (p->type == bfd_fill_link_order) | |
3468 | continue; | |
3469 | abort (); | |
3470 | } | |
3471 | ||
3472 | input_section = p->u.indirect.section; | |
3473 | ||
3474 | /* Hack: reset the SEC_HAS_CONTENTS flag so that | |
3475 | elf_link_input_bfd ignores this section. */ | |
3476 | input_section->flags &=~ SEC_HAS_CONTENTS; | |
3477 | } | |
3478 | ||
3479 | /* Skip this section later on (I don't think this | |
3480 | currently matters, but someday it might). */ | |
3481 | o->link_order_head = (struct bfd_link_order *) NULL; | |
3482 | ||
3483 | /* Really remove the section. */ | |
3484 | for (secpp = &abfd->sections; | |
3485 | *secpp != o; | |
3486 | secpp = &(*secpp)->next) | |
3487 | ; | |
3488 | *secpp = (*secpp)->next; | |
3489 | --abfd->section_count; | |
3490 | ||
3491 | continue; | |
3492 | } | |
3493 | ||
3494 | /* There is one gptab for initialized data, and one for | |
3495 | uninitialized data. */ | |
3496 | if (strcmp (o->name, ".gptab.sdata") == 0) | |
3497 | gptab_data_sec = o; | |
3498 | else if (strcmp (o->name, ".gptab.sbss") == 0) | |
3499 | gptab_bss_sec = o; | |
3500 | else | |
3501 | { | |
a9713b91 ILT |
3502 | (*_bfd_error_handler) |
3503 | ("%s: illegal section name `%s'", | |
3504 | bfd_get_filename (abfd), o->name); | |
aac6b32f ILT |
3505 | bfd_set_error (bfd_error_nonrepresentable_section); |
3506 | return false; | |
3507 | } | |
3508 | ||
3509 | /* The linker script always combines .gptab.data and | |
3510 | .gptab.sdata into .gptab.sdata, and likewise for | |
3511 | .gptab.bss and .gptab.sbss. It is possible that there is | |
3512 | no .sdata or .sbss section in the output file, in which | |
3513 | case we must change the name of the output section. */ | |
3514 | subname = o->name + sizeof ".gptab" - 1; | |
3515 | if (bfd_get_section_by_name (abfd, subname) == NULL) | |
3516 | { | |
3517 | if (o == gptab_data_sec) | |
3518 | o->name = ".gptab.data"; | |
3519 | else | |
3520 | o->name = ".gptab.bss"; | |
3521 | subname = o->name + sizeof ".gptab" - 1; | |
3522 | BFD_ASSERT (bfd_get_section_by_name (abfd, subname) != NULL); | |
3523 | } | |
3524 | ||
3525 | /* Set up the first entry. */ | |
3526 | c = 1; | |
5b3b9ff6 | 3527 | tab = (Elf32_gptab *) bfd_malloc (c * sizeof (Elf32_gptab)); |
aac6b32f | 3528 | if (tab == NULL) |
5b3b9ff6 | 3529 | return false; |
aac6b32f ILT |
3530 | tab[0].gt_header.gt_current_g_value = elf_gp_size (abfd); |
3531 | tab[0].gt_header.gt_unused = 0; | |
3532 | ||
3533 | /* Combine the input sections. */ | |
6e07e54f ILT |
3534 | for (p = o->link_order_head; |
3535 | p != (struct bfd_link_order *) NULL; | |
3536 | p = p->next) | |
3537 | { | |
aac6b32f ILT |
3538 | asection *input_section; |
3539 | bfd *input_bfd; | |
3540 | bfd_size_type size; | |
3541 | unsigned long last; | |
3542 | bfd_size_type gpentry; | |
3543 | ||
3544 | if (p->type != bfd_indirect_link_order) | |
6e07e54f | 3545 | { |
aac6b32f ILT |
3546 | if (p->type == bfd_fill_link_order) |
3547 | continue; | |
3548 | abort (); | |
3549 | } | |
6e07e54f | 3550 | |
aac6b32f ILT |
3551 | input_section = p->u.indirect.section; |
3552 | input_bfd = input_section->owner; | |
3553 | ||
3554 | /* Combine the gptab entries for this input section one | |
3555 | by one. We know that the input gptab entries are | |
3556 | sorted by ascending -G value. */ | |
3557 | size = bfd_section_size (input_bfd, input_section); | |
3558 | last = 0; | |
3559 | for (gpentry = sizeof (Elf32_External_gptab); | |
3560 | gpentry < size; | |
3561 | gpentry += sizeof (Elf32_External_gptab)) | |
3562 | { | |
3563 | Elf32_External_gptab ext_gptab; | |
3564 | Elf32_gptab int_gptab; | |
3565 | unsigned long val; | |
3566 | unsigned long add; | |
3567 | boolean exact; | |
3568 | unsigned int look; | |
3569 | ||
3570 | if (! (bfd_get_section_contents | |
3571 | (input_bfd, input_section, (PTR) &ext_gptab, | |
3572 | gpentry, sizeof (Elf32_External_gptab)))) | |
9783e04a | 3573 | { |
aac6b32f | 3574 | free (tab); |
9783e04a DM |
3575 | return false; |
3576 | } | |
aac6b32f ILT |
3577 | |
3578 | bfd_mips_elf32_swap_gptab_in (input_bfd, &ext_gptab, | |
3579 | &int_gptab); | |
3580 | val = int_gptab.gt_entry.gt_g_value; | |
3581 | add = int_gptab.gt_entry.gt_bytes - last; | |
3582 | ||
3583 | exact = false; | |
3584 | for (look = 1; look < c; look++) | |
3585 | { | |
3586 | if (tab[look].gt_entry.gt_g_value >= val) | |
3587 | tab[look].gt_entry.gt_bytes += add; | |
3588 | ||
3589 | if (tab[look].gt_entry.gt_g_value == val) | |
3590 | exact = true; | |
3591 | } | |
3592 | ||
3593 | if (! exact) | |
3594 | { | |
3595 | Elf32_gptab *new_tab; | |
3596 | unsigned int max; | |
3597 | ||
3598 | /* We need a new table entry. */ | |
3599 | new_tab = ((Elf32_gptab *) | |
5b3b9ff6 ILT |
3600 | bfd_realloc ((PTR) tab, |
3601 | (c + 1) * sizeof (Elf32_gptab))); | |
aac6b32f ILT |
3602 | if (new_tab == NULL) |
3603 | { | |
aac6b32f ILT |
3604 | free (tab); |
3605 | return false; | |
3606 | } | |
3607 | tab = new_tab; | |
3608 | tab[c].gt_entry.gt_g_value = val; | |
3609 | tab[c].gt_entry.gt_bytes = add; | |
3610 | ||
3611 | /* Merge in the size for the next smallest -G | |
3612 | value, since that will be implied by this new | |
3613 | value. */ | |
3614 | max = 0; | |
3615 | for (look = 1; look < c; look++) | |
3616 | { | |
3617 | if (tab[look].gt_entry.gt_g_value < val | |
3618 | && (max == 0 | |
3619 | || (tab[look].gt_entry.gt_g_value | |
3620 | > tab[max].gt_entry.gt_g_value))) | |
3621 | max = look; | |
3622 | } | |
3623 | if (max != 0) | |
3624 | tab[c].gt_entry.gt_bytes += | |
3625 | tab[max].gt_entry.gt_bytes; | |
3626 | ||
3627 | ++c; | |
3628 | } | |
3629 | ||
3630 | last = int_gptab.gt_entry.gt_bytes; | |
6e07e54f | 3631 | } |
aac6b32f ILT |
3632 | |
3633 | /* Hack: reset the SEC_HAS_CONTENTS flag so that | |
3634 | elf_link_input_bfd ignores this section. */ | |
3635 | input_section->flags &=~ SEC_HAS_CONTENTS; | |
6e07e54f | 3636 | } |
aac6b32f ILT |
3637 | |
3638 | /* The table must be sorted by -G value. */ | |
3639 | if (c > 2) | |
3640 | qsort (tab + 1, c - 1, sizeof (tab[0]), gptab_compare); | |
3641 | ||
3642 | /* Swap out the table. */ | |
3643 | ext_tab = ((Elf32_External_gptab *) | |
3644 | bfd_alloc (abfd, c * sizeof (Elf32_External_gptab))); | |
3645 | if (ext_tab == NULL) | |
6e07e54f | 3646 | { |
aac6b32f ILT |
3647 | free (tab); |
3648 | return false; | |
3649 | } | |
3650 | ||
3651 | for (i = 0; i < c; i++) | |
3652 | bfd_mips_elf32_swap_gptab_out (abfd, tab + i, ext_tab + i); | |
3653 | free (tab); | |
3654 | ||
3655 | o->_raw_size = c * sizeof (Elf32_External_gptab); | |
3656 | o->contents = (bfd_byte *) ext_tab; | |
3657 | ||
3658 | /* Skip this section later on (I don't think this currently | |
3659 | matters, but someday it might). */ | |
3660 | o->link_order_head = (struct bfd_link_order *) NULL; | |
3661 | } | |
3662 | } | |
3663 | ||
aac6b32f ILT |
3664 | /* Invoke the regular ELF backend linker to do all the work. */ |
3665 | if (! bfd_elf32_bfd_final_link (abfd, info)) | |
3666 | return false; | |
3667 | ||
3668 | /* Now write out the computed sections. */ | |
3669 | ||
6e07e54f ILT |
3670 | if (reginfo_sec != (asection *) NULL) |
3671 | { | |
3672 | Elf32_External_RegInfo ext; | |
3673 | ||
3674 | bfd_mips_elf32_swap_reginfo_out (abfd, ®info, &ext); | |
3675 | if (! bfd_set_section_contents (abfd, reginfo_sec, (PTR) &ext, | |
3676 | (file_ptr) 0, sizeof ext)) | |
3677 | return false; | |
3678 | } | |
b3c0fc57 | 3679 | |
6e07e54f ILT |
3680 | if (mdebug_sec != (asection *) NULL) |
3681 | { | |
aac6b32f | 3682 | BFD_ASSERT (abfd->output_has_begun); |
9783e04a DM |
3683 | if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug, |
3684 | swap, info, | |
3685 | mdebug_sec->filepos)) | |
6e07e54f | 3686 | return false; |
9783e04a DM |
3687 | |
3688 | bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info); | |
b3c0fc57 ILT |
3689 | } |
3690 | ||
aac6b32f | 3691 | if (gptab_data_sec != (asection *) NULL) |
6e07e54f | 3692 | { |
aac6b32f ILT |
3693 | if (! bfd_set_section_contents (abfd, gptab_data_sec, |
3694 | gptab_data_sec->contents, | |
3695 | (file_ptr) 0, | |
3696 | gptab_data_sec->_raw_size)) | |
3697 | return false; | |
3698 | } | |
3699 | ||
3700 | if (gptab_bss_sec != (asection *) NULL) | |
3701 | { | |
3702 | if (! bfd_set_section_contents (abfd, gptab_bss_sec, | |
3703 | gptab_bss_sec->contents, | |
3704 | (file_ptr) 0, | |
3705 | gptab_bss_sec->_raw_size)) | |
3706 | return false; | |
6e07e54f ILT |
3707 | } |
3708 | ||
5b3b9ff6 ILT |
3709 | if (SGI_COMPAT (abfd)) |
3710 | { | |
3711 | rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc"); | |
3712 | if (rtproc_sec != NULL) | |
3713 | { | |
3714 | if (! bfd_set_section_contents (abfd, rtproc_sec, | |
3715 | rtproc_sec->contents, | |
3716 | (file_ptr) 0, | |
3717 | rtproc_sec->_raw_size)) | |
3718 | return false; | |
3719 | } | |
3720 | } | |
3721 | ||
6e07e54f | 3722 | return true; |
b3c0fc57 | 3723 | } |
6e07e54f | 3724 | |
aac6b32f | 3725 | /* Handle a MIPS ELF HI16 reloc. */ |
b3c0fc57 ILT |
3726 | |
3727 | static void | |
aac6b32f ILT |
3728 | mips_elf_relocate_hi16 (input_bfd, relhi, rello, contents, addend) |
3729 | bfd *input_bfd; | |
3730 | Elf_Internal_Rela *relhi; | |
3731 | Elf_Internal_Rela *rello; | |
3732 | bfd_byte *contents; | |
3733 | bfd_vma addend; | |
b3c0fc57 | 3734 | { |
aac6b32f ILT |
3735 | bfd_vma insn; |
3736 | bfd_vma addlo; | |
b3c0fc57 | 3737 | |
aac6b32f ILT |
3738 | insn = bfd_get_32 (input_bfd, contents + relhi->r_offset); |
3739 | ||
3740 | addlo = bfd_get_32 (input_bfd, contents + rello->r_offset); | |
3741 | addlo &= 0xffff; | |
3742 | ||
3743 | addend += ((insn & 0xffff) << 16) + addlo; | |
3744 | ||
3745 | if ((addlo & 0x8000) != 0) | |
3746 | addend -= 0x10000; | |
3747 | if ((addend & 0x8000) != 0) | |
3748 | addend += 0x10000; | |
3749 | ||
3750 | bfd_put_32 (input_bfd, | |
3751 | (insn & 0xffff0000) | ((addend >> 16) & 0xffff), | |
3752 | contents + relhi->r_offset); | |
3753 | } | |
3754 | ||
5b3b9ff6 ILT |
3755 | /* Handle a MIPS ELF local GOT16 reloc. */ |
3756 | ||
3757 | static void | |
3758 | mips_elf_relocate_got_local (output_bfd, input_bfd, sgot, relhi, rello, | |
3759 | contents, addend) | |
3760 | bfd *output_bfd; | |
3761 | bfd *input_bfd; | |
3762 | asection *sgot; | |
3763 | Elf_Internal_Rela *relhi; | |
3764 | Elf_Internal_Rela *rello; | |
3765 | bfd_byte *contents; | |
3766 | bfd_vma addend; | |
3767 | { | |
3768 | int local_gotno; | |
3769 | int i; | |
3770 | bfd_vma insn; | |
3771 | bfd_vma addlo; | |
3772 | bfd_vma address; | |
3773 | bfd_vma hipage; | |
3774 | bfd_byte *got_contents; | |
3775 | struct mips_got_info *g; | |
3776 | ||
3777 | insn = bfd_get_32 (input_bfd, contents + relhi->r_offset); | |
3778 | ||
3779 | addlo = bfd_get_32 (input_bfd, contents + rello->r_offset); | |
3780 | addlo &= 0xffff; | |
3781 | ||
3782 | addend += ((insn & 0xffff) << 16) + addlo; | |
3783 | ||
3784 | if ((addlo & 0x8000) != 0) | |
3785 | addend -= 0x10000; | |
3786 | if ((addend & 0x8000) != 0) | |
3787 | addend += 0x10000; | |
3788 | ||
3789 | /* Get a got entry representing requested hipage. */ | |
3790 | BFD_ASSERT (elf_section_data (sgot) != NULL); | |
3791 | g = (struct mips_got_info *) elf_section_data (sgot)->tdata; | |
3792 | BFD_ASSERT (g != NULL); | |
3793 | ||
3794 | local_gotno = g->local_gotno; | |
3795 | got_contents = sgot->contents; | |
3796 | hipage = addend & 0xffff0000; | |
3797 | ||
3798 | for (i = MIPS_RESERVED_GOTNO; i < local_gotno; i++) | |
3799 | { | |
3800 | address = bfd_get_32 (input_bfd, got_contents + i * 4); | |
3801 | if (hipage == (address & 0xffff0000)) | |
3802 | break; | |
3803 | if (address == (bfd_vma) 0) | |
3804 | { | |
3805 | bfd_put_32 (input_bfd, hipage, got_contents + i * 4); | |
3806 | break; | |
3807 | } | |
3808 | } | |
3809 | ||
3810 | BFD_ASSERT (i < local_gotno); | |
3811 | #if 1 | |
3812 | if (i == local_gotno) | |
3813 | (*_bfd_error_handler) | |
3814 | ("ELF MIPS linker: more got entries are needed for hipage: %x", | |
3815 | hipage); | |
3816 | #endif | |
3817 | ||
3818 | i = - ELF_MIPS_GP_OFFSET (output_bfd) + i * 4; | |
3819 | bfd_put_32 (input_bfd, (insn & 0xffff0000) | (i & 0xffff), | |
3820 | contents + relhi->r_offset); | |
3821 | } | |
3822 | ||
3823 | /* Handle MIPS ELF CALL16 reloc and global GOT16 reloc. */ | |
3824 | ||
3825 | static void | |
3826 | mips_elf_relocate_global_got (input_bfd, rel, contents, offset) | |
3827 | bfd *input_bfd; | |
3828 | Elf_Internal_Rela *rel; | |
3829 | bfd_byte *contents; | |
3830 | bfd_vma offset; | |
3831 | { | |
3832 | bfd_vma insn; | |
3833 | ||
3834 | insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
3835 | bfd_put_32 (input_bfd, | |
3836 | (insn & 0xffff0000) | (offset & 0xffff), | |
3837 | contents + rel->r_offset); | |
3838 | } | |
3839 | ||
aac6b32f ILT |
3840 | /* Relocate a MIPS ELF section. */ |
3841 | ||
3842 | static boolean | |
3843 | mips_elf_relocate_section (output_bfd, info, input_bfd, input_section, | |
82b1edf7 | 3844 | contents, relocs, local_syms, local_sections) |
aac6b32f ILT |
3845 | bfd *output_bfd; |
3846 | struct bfd_link_info *info; | |
3847 | bfd *input_bfd; | |
3848 | asection *input_section; | |
3849 | bfd_byte *contents; | |
3850 | Elf_Internal_Rela *relocs; | |
3851 | Elf_Internal_Sym *local_syms; | |
3852 | asection **local_sections; | |
3853 | { | |
3854 | Elf_Internal_Shdr *symtab_hdr; | |
3855 | size_t locsymcount; | |
3856 | size_t extsymoff; | |
5b3b9ff6 ILT |
3857 | asection *sgot, *sreloc, *scpt; |
3858 | bfd *dynobj; | |
abec70b9 | 3859 | bfd_vma gp; |
aac6b32f ILT |
3860 | Elf_Internal_Rela *rel; |
3861 | Elf_Internal_Rela *relend; | |
5b3b9ff6 | 3862 | struct mips_got_info *g; |
aac6b32f | 3863 | |
5b3b9ff6 | 3864 | dynobj = elf_hash_table (info)->dynobj; |
aac6b32f ILT |
3865 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
3866 | ||
5b3b9ff6 ILT |
3867 | sgot = NULL; |
3868 | sreloc = NULL; | |
3869 | if (dynobj == NULL || ! SGI_COMPAT (output_bfd)) | |
3870 | scpt = NULL; | |
3871 | else | |
3872 | scpt = bfd_get_section_by_name (dynobj, ".compact_rel"); | |
3873 | g = NULL; | |
3874 | ||
aac6b32f | 3875 | if (elf_bad_symtab (input_bfd)) |
b3c0fc57 | 3876 | { |
aac6b32f ILT |
3877 | locsymcount = symtab_hdr->sh_size / sizeof (Elf32_External_Sym); |
3878 | extsymoff = 0; | |
3879 | } | |
3880 | else | |
3881 | { | |
3882 | locsymcount = symtab_hdr->sh_info; | |
3883 | extsymoff = symtab_hdr->sh_info; | |
3884 | } | |
3885 | ||
abec70b9 ILT |
3886 | gp = _bfd_get_gp_value (output_bfd); |
3887 | ||
aac6b32f ILT |
3888 | rel = relocs; |
3889 | relend = relocs + input_section->reloc_count; | |
3890 | for (; rel < relend; rel++) | |
3891 | { | |
3892 | int r_type; | |
82b1edf7 | 3893 | reloc_howto_type *howto; |
6ab826bd | 3894 | unsigned long r_symndx; |
aac6b32f ILT |
3895 | bfd_vma addend; |
3896 | struct elf_link_hash_entry *h; | |
3897 | asection *sec; | |
3898 | Elf_Internal_Sym *sym; | |
3899 | bfd_reloc_status_type r; | |
3900 | ||
3901 | r_type = ELF32_R_TYPE (rel->r_info); | |
3902 | if (r_type < 0 || r_type >= (int) R_MIPS_max) | |
6e07e54f | 3903 | { |
aac6b32f ILT |
3904 | bfd_set_error (bfd_error_bad_value); |
3905 | return false; | |
6e07e54f | 3906 | } |
aac6b32f | 3907 | howto = elf_mips_howto_table + r_type; |
b3c0fc57 | 3908 | |
5b3b9ff6 ILT |
3909 | if (dynobj != NULL |
3910 | && (r_type == R_MIPS_CALL16 | |
3911 | || r_type == R_MIPS_GOT16 | |
3912 | || r_type == R_MIPS_CALL_HI16 | |
3913 | || r_type == R_MIPS_CALL_LO16 | |
3914 | || r_type == R_MIPS_GOT_HI16 | |
3915 | || r_type == R_MIPS_GOT_LO16)) | |
3916 | { | |
3917 | /* We need the .got section. */ | |
3918 | if (sgot == NULL) | |
3919 | { | |
3920 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
3921 | BFD_ASSERT (sgot != NULL); | |
3922 | BFD_ASSERT (elf_section_data (sgot) != NULL); | |
3923 | g = (struct mips_got_info *) elf_section_data (sgot)->tdata; | |
3924 | BFD_ASSERT (g != NULL); | |
3925 | } | |
3926 | } | |
3927 | ||
aac6b32f ILT |
3928 | r_symndx = ELF32_R_SYM (rel->r_info); |
3929 | ||
3930 | /* Mix in the change in GP address for a GP relative reloc. */ | |
3931 | if (r_type != R_MIPS_GPREL16 | |
3932 | && r_type != R_MIPS_LITERAL | |
3933 | && r_type != R_MIPS_GPREL32) | |
3934 | addend = 0; | |
3935 | else | |
b3c0fc57 | 3936 | { |
cba3f8a9 | 3937 | if (gp == 0) |
aac6b32f ILT |
3938 | { |
3939 | if (! ((*info->callbacks->reloc_dangerous) | |
3940 | (info, | |
3941 | "GP relative relocation when GP not defined", | |
3942 | input_bfd, input_section, | |
3943 | rel->r_offset))) | |
3944 | return false; | |
3945 | /* Only give the error once per link. */ | |
cba3f8a9 ILT |
3946 | gp = 4; |
3947 | _bfd_set_gp_value (output_bfd, gp); | |
aac6b32f ILT |
3948 | } |
3949 | ||
3950 | if (r_symndx < extsymoff | |
3951 | || (elf_bad_symtab (input_bfd) | |
3952 | && local_sections[r_symndx] != NULL)) | |
3953 | { | |
3954 | /* This is a relocation against a section. The current | |
3955 | addend in the instruction is the difference between | |
3956 | INPUT_SECTION->vma and the GP value of INPUT_BFD. We | |
3957 | must change this to be the difference between the | |
3958 | final definition (which will end up in RELOCATION) | |
3959 | and the GP value of OUTPUT_BFD (which is in GP). */ | |
cba3f8a9 | 3960 | addend = elf_gp (input_bfd) - gp; |
aac6b32f ILT |
3961 | } |
3962 | else if (! info->relocateable) | |
3963 | { | |
3964 | /* We are doing a final link. The current addend in the | |
3965 | instruction is simply the desired offset into the | |
3966 | symbol (normally zero). We want the instruction to | |
3967 | hold the difference between the final definition of | |
3968 | the symbol (which will end up in RELOCATION) and the | |
3969 | GP value of OUTPUT_BFD (which is in GP). */ | |
cba3f8a9 | 3970 | addend = - gp; |
aac6b32f ILT |
3971 | } |
3972 | else | |
3973 | { | |
3974 | /* We are generating relocateable output, and we aren't | |
3975 | going to define this symbol, so we just leave the | |
3976 | instruction alone. */ | |
3977 | addend = 0; | |
3978 | } | |
b3c0fc57 | 3979 | } |
b3c0fc57 | 3980 | |
aac6b32f ILT |
3981 | h = NULL; |
3982 | sym = NULL; | |
3983 | sec = NULL; | |
3984 | if (info->relocateable) | |
3985 | { | |
3986 | /* This is a relocateable link. We don't have to change | |
3987 | anything, unless the reloc is against a section symbol, | |
3988 | in which case we have to adjust according to where the | |
3989 | section symbol winds up in the output section. */ | |
3990 | if (r_symndx >= locsymcount | |
3991 | || (elf_bad_symtab (input_bfd) | |
3992 | && local_sections[r_symndx] == NULL)) | |
3993 | r = bfd_reloc_ok; | |
3994 | else | |
3995 | { | |
3996 | sym = local_syms + r_symndx; | |
3997 | if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) | |
3998 | r = bfd_reloc_ok; | |
3999 | else | |
4000 | { | |
4001 | sec = local_sections[r_symndx]; | |
4002 | ||
4003 | /* It would be logical to add sym->st_value here, | |
4004 | but Irix 5 sometimes generates a garbage symbol | |
4005 | value. */ | |
4006 | addend += sec->output_offset; | |
4007 | ||
5b3b9ff6 ILT |
4008 | /* If this is HI16 or GOT16 with an associated LO16, |
4009 | adjust the addend accordingly. Otherwise, just | |
aac6b32f | 4010 | relocate. */ |
abec70b9 | 4011 | if (r_type != R_MIPS_HI16 && r_type != R_MIPS_GOT16) |
aac6b32f ILT |
4012 | r = _bfd_relocate_contents (howto, input_bfd, |
4013 | addend, | |
4014 | contents + rel->r_offset); | |
4015 | else | |
4016 | { | |
abec70b9 ILT |
4017 | Elf_Internal_Rela *lorel; |
4018 | ||
4019 | /* As a GNU extension, permit an arbitrary | |
4020 | number of R_MIPS_HI16 relocs before the | |
4021 | R_MIPS_LO16 reloc. This permits gcc to emit | |
4022 | the HI and LO relocs itself. */ | |
4023 | if (r_type == R_MIPS_GOT16) | |
4024 | lorel = rel + 1; | |
4025 | else | |
4026 | { | |
4027 | for (lorel = rel + 1; | |
4028 | (lorel < relend | |
4029 | && (ELF32_R_TYPE (lorel->r_info) | |
4030 | == R_MIPS_HI16)); | |
4031 | lorel++) | |
4032 | ; | |
4033 | } | |
4034 | if (lorel < relend | |
4035 | && ELF32_R_TYPE (lorel->r_info) == R_MIPS_LO16) | |
4036 | { | |
4037 | mips_elf_relocate_hi16 (input_bfd, rel, lorel, | |
4038 | contents, addend); | |
4039 | r = bfd_reloc_ok; | |
4040 | } | |
4041 | else | |
4042 | r = _bfd_relocate_contents (howto, input_bfd, | |
4043 | addend, | |
4044 | contents + rel->r_offset); | |
aac6b32f ILT |
4045 | } |
4046 | } | |
4047 | } | |
4048 | } | |
4049 | else | |
4050 | { | |
4051 | bfd_vma relocation; | |
5b3b9ff6 | 4052 | boolean local; |
aac6b32f ILT |
4053 | |
4054 | /* This is a final link. */ | |
4055 | sym = NULL; | |
4056 | if (r_symndx < extsymoff | |
4057 | || (elf_bad_symtab (input_bfd) | |
4058 | && local_sections[r_symndx] != NULL)) | |
4059 | { | |
5b3b9ff6 | 4060 | local = true; |
aac6b32f ILT |
4061 | sym = local_syms + r_symndx; |
4062 | sec = local_sections[r_symndx]; | |
4063 | relocation = (sec->output_section->vma | |
4064 | + sec->output_offset); | |
4065 | ||
4066 | /* It would be logical to always add sym->st_value here, | |
4067 | but Irix 5 sometimes generates a garbage symbol | |
4068 | value. */ | |
4069 | if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) | |
4070 | relocation += sym->st_value; | |
4071 | } | |
4072 | else | |
4073 | { | |
4074 | long indx; | |
4075 | ||
5b3b9ff6 | 4076 | local = false; |
aac6b32f ILT |
4077 | indx = r_symndx - extsymoff; |
4078 | h = elf_sym_hashes (input_bfd)[indx]; | |
e9f03cd4 ILT |
4079 | while (h->root.type == bfd_link_hash_indirect |
4080 | || h->root.type == bfd_link_hash_warning) | |
4081 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5b3b9ff6 ILT |
4082 | if (strcmp (h->root.root.string, "_gp_disp") == 0) |
4083 | { | |
cba3f8a9 | 4084 | if (gp == 0) |
5b3b9ff6 ILT |
4085 | { |
4086 | if (! ((*info->callbacks->reloc_dangerous) | |
4087 | (info, | |
4088 | "_gp_disp used when GP not defined", | |
4089 | input_bfd, input_section, | |
4090 | rel->r_offset))) | |
4091 | return false; | |
4092 | /* Only give the error once per link. */ | |
cba3f8a9 ILT |
4093 | gp = 4; |
4094 | _bfd_set_gp_value (output_bfd, gp); | |
5b3b9ff6 ILT |
4095 | relocation = 0; |
4096 | } | |
4097 | else | |
4098 | { | |
4099 | sec = input_section; | |
4100 | if (sec->output_section != NULL) | |
cba3f8a9 | 4101 | relocation = (gp |
5b3b9ff6 ILT |
4102 | - (rel->r_offset |
4103 | + sec->output_section->vma | |
4104 | + sec->output_offset)); | |
4105 | else | |
cba3f8a9 | 4106 | relocation = gp - rel->r_offset; |
5b3b9ff6 ILT |
4107 | if (r_type == R_MIPS_LO16) |
4108 | relocation += 4; | |
4109 | } | |
4110 | } | |
4111 | else if (h->root.type == bfd_link_hash_defined | |
a16fcab3 | 4112 | || h->root.type == bfd_link_hash_defweak) |
aac6b32f ILT |
4113 | { |
4114 | sec = h->root.u.def.section; | |
5b3b9ff6 ILT |
4115 | if (sec->output_section == NULL) |
4116 | relocation = 0; | |
4117 | else | |
4118 | relocation = (h->root.u.def.value | |
4119 | + sec->output_section->vma | |
4120 | + sec->output_offset); | |
aac6b32f | 4121 | } |
a16fcab3 | 4122 | else if (h->root.type == bfd_link_hash_undefweak) |
aac6b32f | 4123 | relocation = 0; |
5b3b9ff6 ILT |
4124 | else if (info->shared && ! info->symbolic) |
4125 | relocation = 0; | |
53787b23 ILT |
4126 | else if (strcmp (h->root.root.string, "_DYNAMIC_LINK") == 0) |
4127 | { | |
4128 | /* If this is a dynamic link, we should have created | |
4129 | a _DYNAMIC_LINK symbol in | |
4130 | mips_elf_create_dynamic_sections. Otherwise, we | |
4131 | should define the symbol with a value of 0. | |
4132 | FIXME: It should probably get into the symbol | |
4133 | table somehow as well. */ | |
4134 | BFD_ASSERT (! info->shared); | |
4135 | BFD_ASSERT (bfd_get_section_by_name (output_bfd, | |
4136 | ".dynamic") == NULL); | |
4137 | relocation = 0; | |
4138 | } | |
aac6b32f ILT |
4139 | else |
4140 | { | |
4141 | if (! ((*info->callbacks->undefined_symbol) | |
4142 | (info, h->root.root.string, input_bfd, | |
4143 | input_section, rel->r_offset))) | |
4144 | return false; | |
4145 | relocation = 0; | |
4146 | } | |
4147 | } | |
4148 | ||
abec70b9 | 4149 | if (r_type == R_MIPS_HI16) |
aac6b32f | 4150 | { |
abec70b9 ILT |
4151 | Elf_Internal_Rela *lorel; |
4152 | ||
4153 | /* As a GNU extension, permit an arbitrary number of | |
4154 | R_MIPS_HI16 relocs before the R_MIPS_LO16 reloc. | |
4155 | This permits gcc to emit the HI and LO relocs itself. */ | |
4156 | for (lorel = rel + 1; | |
4157 | (lorel < relend | |
4158 | && ELF32_R_TYPE (lorel->r_info) == R_MIPS_HI16); | |
4159 | lorel++) | |
4160 | ; | |
4161 | if (lorel < relend | |
4162 | && ELF32_R_TYPE (lorel->r_info) == R_MIPS_LO16) | |
4163 | { | |
4164 | mips_elf_relocate_hi16 (input_bfd, rel, lorel, | |
4165 | contents, relocation + addend); | |
4166 | r = bfd_reloc_ok; | |
4167 | } | |
4168 | else | |
4169 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
4170 | contents, rel->r_offset, | |
4171 | relocation, addend); | |
aac6b32f | 4172 | } |
5b3b9ff6 ILT |
4173 | else if (r_type == R_MIPS_GOT16 && local) |
4174 | { | |
abec70b9 | 4175 | /* GOT16 must also have an associated LO16 in the local |
5b3b9ff6 ILT |
4176 | case. In this case, the addend is extracted and the |
4177 | section in which the referenced object is determined. | |
4178 | Then the final address of the object is computed and | |
4179 | the GOT entry for the hipage (an aligned 64kb chunk) | |
4180 | is added to .got section if needed. The offset field | |
4181 | of the GOT16-relocated instruction is replaced by the | |
4182 | index of this GOT entry for the hipage. */ | |
4183 | if ((rel + 1) < relend | |
4184 | && ELF32_R_TYPE ((rel + 1)->r_info) == R_MIPS_LO16) | |
4185 | { | |
4186 | mips_elf_relocate_got_local (output_bfd, input_bfd, sgot, | |
4187 | rel, rel + 1, | |
4188 | contents, | |
4189 | relocation + addend); | |
4190 | r = bfd_reloc_ok; | |
4191 | } | |
4192 | else | |
4193 | r = bfd_reloc_outofrange; | |
4194 | } | |
4195 | else if (r_type == R_MIPS_CALL16 | |
4196 | || r_type == R_MIPS_GOT16 | |
4197 | || r_type == R_MIPS_CALL_LO16 | |
4198 | || r_type == R_MIPS_GOT_LO16) | |
4199 | { | |
4200 | bfd_vma offset; | |
4201 | ||
4202 | /* This symbol must be registered as a global symbol | |
4203 | having the corresponding got entry. */ | |
4204 | BFD_ASSERT (h->got_offset != (bfd_vma) -1); | |
4205 | ||
4206 | offset = (h->dynindx - g->global_gotsym + g->local_gotno) * 4; | |
4207 | BFD_ASSERT (g->local_gotno <= offset | |
4208 | && offset < sgot->_raw_size); | |
4209 | bfd_put_32 (output_bfd, relocation + addend, | |
4210 | sgot->contents + offset); | |
4211 | offset = (sgot->output_section->vma + sgot->output_offset | |
cba3f8a9 | 4212 | + offset - gp); |
5b3b9ff6 ILT |
4213 | mips_elf_relocate_global_got (input_bfd, rel, contents, |
4214 | offset); | |
4215 | r = bfd_reloc_ok; | |
4216 | } | |
4217 | else if (r_type == R_MIPS_CALL_HI16 | |
4218 | || r_type == R_MIPS_GOT_HI16) | |
4219 | { | |
4220 | bfd_vma offset; | |
4221 | ||
4222 | /* This must be a global symbol with a got entry. The | |
4223 | next reloc must be the corresponding LO16 reloc. */ | |
4224 | BFD_ASSERT (h != NULL && h->got_offset != (bfd_vma) -1); | |
4225 | BFD_ASSERT ((rel + 1) < relend); | |
4226 | BFD_ASSERT (ELF32_R_TYPE ((rel + 1)->r_info) | |
4227 | == (r_type == R_MIPS_CALL_HI16 | |
4228 | ? R_MIPS_CALL_LO16 | |
4229 | : R_MIPS_GOT_LO16)); | |
4230 | ||
4231 | offset = (h->dynindx - g->global_gotsym + g->local_gotno) * 4; | |
4232 | BFD_ASSERT (g->local_gotno <= offset | |
4233 | && offset < sgot->_raw_size); | |
4234 | bfd_put_32 (output_bfd, relocation + addend, | |
4235 | sgot->contents + offset); | |
4236 | offset = (sgot->output_section->vma + sgot->output_offset | |
cba3f8a9 | 4237 | + offset - gp); |
5b3b9ff6 ILT |
4238 | mips_elf_relocate_hi16 (input_bfd, rel, rel + 1, contents, |
4239 | offset); | |
4240 | r = bfd_reloc_ok; | |
4241 | } | |
4242 | else if (r_type == R_MIPS_REL32 | |
4243 | || r_type == R_MIPS_32) | |
4244 | { | |
4245 | Elf_Internal_Rel outrel; | |
4246 | Elf32_crinfo cptrel; | |
4247 | bfd_byte *cr; | |
4248 | ||
abec70b9 ILT |
4249 | if ((info->shared |
4250 | || (h != NULL | |
4251 | && ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) | |
4252 | == 0))) | |
5b3b9ff6 ILT |
4253 | && (input_section->flags & SEC_ALLOC) != 0) |
4254 | { | |
4255 | /* When generating a shared object, these | |
4256 | relocations are copied into the output file to be | |
4257 | resolved at run time. */ | |
4258 | if (sreloc == NULL) | |
4259 | { | |
4260 | sreloc = bfd_get_section_by_name (dynobj, ".rel.dyn"); | |
4261 | BFD_ASSERT (sreloc != NULL); | |
4262 | } | |
4263 | ||
4264 | outrel.r_offset = (rel->r_offset | |
4265 | + input_section->output_section->vma | |
4266 | + input_section->output_offset); | |
4267 | ||
4268 | addend = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
4269 | ||
53787b23 ILT |
4270 | if (h != NULL |
4271 | && (! info->symbolic | |
4272 | || (h->elf_link_hash_flags | |
4273 | & ELF_LINK_HASH_DEF_REGULAR) == 0)) | |
5b3b9ff6 ILT |
4274 | { |
4275 | BFD_ASSERT (h->dynindx != -1); | |
4276 | outrel.r_info = ELF32_R_INFO (h->dynindx, R_MIPS_REL32); | |
4277 | sec = input_section; | |
4278 | } | |
4279 | else | |
4280 | { | |
4281 | long indx; | |
4282 | ||
53787b23 ILT |
4283 | if (h == NULL) |
4284 | sec = local_sections[r_symndx]; | |
4285 | else | |
4286 | { | |
4287 | BFD_ASSERT (h->root.type == bfd_link_hash_defined | |
4288 | || (h->root.type | |
4289 | == bfd_link_hash_defweak)); | |
4290 | sec = h->root.u.def.section; | |
4291 | } | |
5b3b9ff6 ILT |
4292 | if (sec != NULL && bfd_is_abs_section (sec)) |
4293 | indx = 0; | |
4294 | else if (sec == NULL || sec->owner == NULL) | |
4295 | { | |
4296 | bfd_set_error (bfd_error_bad_value); | |
4297 | return false; | |
4298 | } | |
4299 | else | |
4300 | { | |
4301 | asection *osec; | |
4302 | ||
4303 | osec = sec->output_section; | |
4304 | indx = elf_section_data (osec)->dynindx; | |
4305 | if (indx == 0) | |
4306 | abort (); | |
4307 | } | |
4308 | ||
4309 | outrel.r_info = ELF32_R_INFO (indx, R_MIPS_REL32); | |
4310 | addend += relocation; | |
4311 | } | |
4312 | ||
4313 | bfd_put_32 (output_bfd, addend, contents + rel->r_offset); | |
4314 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, | |
4315 | (((Elf32_External_Rel *) | |
4316 | sreloc->contents) | |
4317 | + sreloc->reloc_count)); | |
4318 | ++sreloc->reloc_count; | |
4319 | ||
4320 | if (SGI_COMPAT (output_bfd)) | |
4321 | { | |
4322 | if (scpt == NULL) | |
4323 | continue; | |
4324 | ||
4325 | /* Make an entry of compact relocation info. */ | |
4326 | mips_elf_set_cr_format (cptrel, CRF_MIPS_LONG); | |
4327 | cptrel.vaddr = (rel->r_offset | |
4328 | + input_section->output_section->vma | |
4329 | + input_section->output_offset); | |
4330 | if (r_type == R_MIPS_REL32) | |
4331 | mips_elf_set_cr_type (cptrel, CRT_MIPS_REL32); | |
4332 | else | |
4333 | mips_elf_set_cr_type (cptrel, CRT_MIPS_WORD); | |
53787b23 | 4334 | mips_elf_set_cr_dist2to (cptrel, 0); |
5b3b9ff6 ILT |
4335 | cptrel.konst = addend; |
4336 | ||
4337 | cr = (scpt->contents | |
4338 | + sizeof (Elf32_External_compact_rel)); | |
4339 | bfd_elf32_swap_crinfo_out (output_bfd, &cptrel, | |
4340 | ((Elf32_External_crinfo *) cr | |
4341 | + scpt->reloc_count)); | |
4342 | ++scpt->reloc_count; | |
4343 | } | |
4344 | ||
4345 | /* This reloc will be computed at runtime, so | |
4346 | there's no need to do anything now. */ | |
4347 | continue; | |
4348 | } | |
4349 | else | |
4350 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
4351 | contents, rel->r_offset, | |
4352 | relocation, addend); | |
4353 | } | |
4354 | else | |
4355 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
4356 | contents, rel->r_offset, | |
4357 | relocation, addend); | |
4358 | ||
4359 | if (SGI_COMPAT (abfd) | |
4360 | && scpt != NULL | |
4361 | && (input_section->flags & SEC_ALLOC) != 0) | |
4362 | { | |
4363 | Elf32_crinfo cptrel; | |
4364 | bfd_byte *cr; | |
4365 | ||
4366 | /* Make an entry of compact relocation info. */ | |
4367 | mips_elf_set_cr_format (cptrel, CRF_MIPS_LONG); | |
4368 | cptrel.vaddr = (rel->r_offset | |
4369 | + input_section->output_section->vma | |
4370 | + input_section->output_offset); | |
4371 | ||
4372 | switch (r_type) | |
4373 | { | |
4374 | case R_MIPS_26: | |
4375 | mips_elf_set_cr_type (cptrel, CRT_MIPS_JMPAD); | |
53787b23 ILT |
4376 | /* XXX How should we set dist2to in this case. */ |
4377 | mips_elf_set_cr_dist2to (cptrel, 8); | |
4378 | cptrel.konst = addend + relocation; | |
5b3b9ff6 ILT |
4379 | cr = scpt->contents + sizeof (Elf32_External_compact_rel); |
4380 | bfd_elf32_swap_crinfo_out (output_bfd, &cptrel, | |
4381 | ((Elf32_External_crinfo *) cr | |
4382 | + scpt->reloc_count)); | |
4383 | ++scpt->reloc_count; | |
4384 | break; | |
4385 | ||
4386 | case R_MIPS_GPREL16: | |
4387 | case R_MIPS_LITERAL: | |
4388 | case R_MIPS_GPREL32: | |
4389 | mips_elf_set_cr_type (cptrel, CRT_MIPS_GPHI_LO); | |
cba3f8a9 | 4390 | cptrel.konst = gp - cptrel.vaddr; |
53787b23 | 4391 | mips_elf_set_cr_dist2to (cptrel, 4); |
5b3b9ff6 ILT |
4392 | cr = scpt->contents + sizeof (Elf32_External_compact_rel); |
4393 | bfd_elf32_swap_crinfo_out (output_bfd, &cptrel, | |
4394 | ((Elf32_External_crinfo *) cr | |
4395 | + scpt->reloc_count)); | |
4396 | ++scpt->reloc_count; | |
4397 | break; | |
4398 | ||
4399 | default: | |
4400 | break; | |
4401 | } | |
4402 | } | |
aac6b32f ILT |
4403 | } |
4404 | ||
4405 | if (r != bfd_reloc_ok) | |
4406 | { | |
4407 | switch (r) | |
4408 | { | |
4409 | default: | |
4410 | case bfd_reloc_outofrange: | |
4411 | abort (); | |
4412 | case bfd_reloc_overflow: | |
4413 | { | |
4414 | const char *name; | |
4415 | ||
4416 | if (h != NULL) | |
4417 | name = h->root.root.string; | |
4418 | else | |
4419 | { | |
ede4eed4 KR |
4420 | name = bfd_elf_string_from_elf_section (input_bfd, |
4421 | symtab_hdr->sh_link, | |
4422 | sym->st_name); | |
aac6b32f ILT |
4423 | if (name == NULL) |
4424 | return false; | |
4425 | if (*name == '\0') | |
4426 | name = bfd_section_name (input_bfd, sec); | |
4427 | } | |
4428 | if (! ((*info->callbacks->reloc_overflow) | |
4429 | (info, name, howto->name, (bfd_vma) 0, | |
4430 | input_bfd, input_section, rel->r_offset))) | |
4431 | return false; | |
4432 | } | |
4433 | break; | |
4434 | } | |
4435 | } | |
b3c0fc57 | 4436 | } |
aac6b32f ILT |
4437 | |
4438 | return true; | |
b3c0fc57 ILT |
4439 | } |
4440 | \f | |
5b3b9ff6 ILT |
4441 | /* Functions for the dynamic linker. */ |
4442 | ||
4443 | /* The name of the dynamic interpreter. This is put in the .interp | |
4444 | section. */ | |
4445 | ||
4446 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1" | |
4447 | ||
4448 | /* Create dynamic sections when linking against a dynamic object. */ | |
5b3b9ff6 ILT |
4449 | |
4450 | static boolean | |
4451 | mips_elf_create_dynamic_sections (abfd, info) | |
a16fcab3 | 4452 | bfd *abfd; |
5b3b9ff6 | 4453 | struct bfd_link_info *info; |
a16fcab3 | 4454 | { |
5b3b9ff6 ILT |
4455 | struct elf_link_hash_entry *h; |
4456 | flagword flags; | |
4457 | register asection *s; | |
4458 | const char * const *namep; | |
a16fcab3 | 4459 | |
5b3b9ff6 ILT |
4460 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
4461 | | SEC_READONLY); | |
a16fcab3 | 4462 | |
5b3b9ff6 ILT |
4463 | /* Mips ABI requests the .dynamic section to be read only. */ |
4464 | s = bfd_get_section_by_name (abfd, ".dynamic"); | |
4465 | if (s != NULL) | |
4466 | { | |
4467 | if (! bfd_set_section_flags (abfd, s, flags)) | |
4468 | return false; | |
4469 | } | |
a16fcab3 | 4470 | |
5b3b9ff6 ILT |
4471 | /* We need to create .got section. */ |
4472 | if (! mips_elf_create_got_section (abfd, info)) | |
4473 | return false; | |
4474 | ||
4475 | /* Create .stub section. */ | |
4476 | if (bfd_get_section_by_name (abfd, ".stub") == NULL) | |
a16fcab3 | 4477 | { |
5b3b9ff6 ILT |
4478 | s = bfd_make_section (abfd, ".stub"); |
4479 | if (s == NULL | |
4480 | || ! bfd_set_section_flags (abfd, s, flags) | |
4481 | || ! bfd_set_section_alignment (abfd, s, 2)) | |
4482 | return false; | |
4483 | } | |
4484 | ||
4485 | if (SGI_COMPAT (abfd)) | |
4486 | { | |
4487 | for (namep = mips_elf_dynsym_rtproc_names; *namep != NULL; namep++) | |
4488 | { | |
4489 | h = NULL; | |
4490 | if (! (_bfd_generic_link_add_one_symbol | |
4491 | (info, abfd, *namep, BSF_GLOBAL, bfd_und_section_ptr, | |
4492 | (bfd_vma) 0, (const char *) NULL, false, | |
4493 | get_elf_backend_data (abfd)->collect, | |
4494 | (struct bfd_link_hash_entry **) &h))) | |
4495 | return false; | |
e9f03cd4 | 4496 | h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF; |
5b3b9ff6 ILT |
4497 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; |
4498 | h->type = STT_SECTION; | |
4499 | ||
53787b23 | 4500 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) |
5b3b9ff6 ILT |
4501 | return false; |
4502 | } | |
4503 | ||
53787b23 ILT |
4504 | /* We need to create a .compact_rel section. */ |
4505 | if (! mips_elf_create_compact_rel_section (abfd, info)) | |
4506 | return false; | |
5b3b9ff6 ILT |
4507 | |
4508 | /* Change aligments of some sections. */ | |
4509 | s = bfd_get_section_by_name (abfd, ".hash"); | |
4510 | if (s != NULL) | |
4511 | bfd_set_section_alignment (abfd, s, 4); | |
4512 | s = bfd_get_section_by_name (abfd, ".dynsym"); | |
4513 | if (s != NULL) | |
4514 | bfd_set_section_alignment (abfd, s, 4); | |
4515 | s = bfd_get_section_by_name (abfd, ".dynstr"); | |
4516 | if (s != NULL) | |
4517 | bfd_set_section_alignment (abfd, s, 4); | |
4518 | s = bfd_get_section_by_name (abfd, ".reginfo"); | |
4519 | if (s != NULL) | |
4520 | bfd_set_section_alignment (abfd, s, 4); | |
4521 | s = bfd_get_section_by_name (abfd, ".dynamic"); | |
4522 | if (s != NULL) | |
4523 | bfd_set_section_alignment (abfd, s, 4); | |
a16fcab3 KR |
4524 | } |
4525 | ||
53787b23 ILT |
4526 | if (!info->shared) |
4527 | { | |
4528 | h = NULL; | |
4529 | if (! (_bfd_generic_link_add_one_symbol | |
4530 | (info, abfd, "_DYNAMIC_LINK", BSF_GLOBAL, bfd_abs_section_ptr, | |
4531 | (bfd_vma) 0, (const char *) NULL, false, | |
4532 | get_elf_backend_data (abfd)->collect, | |
4533 | (struct bfd_link_hash_entry **) &h))) | |
4534 | return false; | |
e9f03cd4 | 4535 | h->elf_link_hash_flags ^=~ ELF_LINK_NON_ELF; |
53787b23 ILT |
4536 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; |
4537 | h->type = STT_SECTION; | |
4538 | ||
4539 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) | |
4540 | return false; | |
4541 | } | |
4542 | ||
5b3b9ff6 ILT |
4543 | return true; |
4544 | } | |
4545 | ||
53787b23 ILT |
4546 | /* Create the .compact_rel section. */ |
4547 | ||
4548 | static boolean | |
4549 | mips_elf_create_compact_rel_section (abfd, info) | |
4550 | bfd *abfd; | |
4551 | struct bfd_link_info *info; | |
4552 | { | |
4553 | flagword flags; | |
4554 | register asection *s; | |
4555 | ||
4556 | if (bfd_get_section_by_name (abfd, ".compact_rel") == NULL) | |
4557 | { | |
4558 | flags = SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_READONLY; | |
4559 | ||
4560 | s = bfd_make_section (abfd, ".compact_rel"); | |
4561 | if (s == NULL | |
4562 | || ! bfd_set_section_flags (abfd, s, flags) | |
4563 | || ! bfd_set_section_alignment (abfd, s, 2)) | |
4564 | return false; | |
4565 | ||
4566 | s->_raw_size = sizeof (Elf32_External_compact_rel); | |
4567 | } | |
4568 | ||
4569 | return true; | |
4570 | } | |
4571 | ||
5b3b9ff6 ILT |
4572 | /* Create the .got section to hold the global offset table. */ |
4573 | ||
4574 | static boolean | |
4575 | mips_elf_create_got_section (abfd, info) | |
4576 | bfd *abfd; | |
4577 | struct bfd_link_info *info; | |
4578 | { | |
4579 | flagword flags; | |
4580 | register asection *s; | |
4581 | struct elf_link_hash_entry *h; | |
4582 | struct mips_got_info *g; | |
4583 | ||
4584 | /* This function may be called more than once. */ | |
4585 | if (bfd_get_section_by_name (abfd, ".got") != NULL) | |
4586 | return true; | |
4587 | ||
4588 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY; | |
4589 | ||
4590 | s = bfd_make_section (abfd, ".got"); | |
4591 | if (s == NULL | |
4592 | || ! bfd_set_section_flags (abfd, s, flags) | |
4593 | || ! bfd_set_section_alignment (abfd, s, 4)) | |
4594 | return false; | |
4595 | ||
4596 | /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the | |
4597 | linker script because we don't want to define the symbol if we | |
53787b23 | 4598 | are not creating a global offset table. */ |
5b3b9ff6 ILT |
4599 | h = NULL; |
4600 | if (! (_bfd_generic_link_add_one_symbol | |
4601 | (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s, | |
4602 | (bfd_vma) 0, (const char *) NULL, false, | |
4603 | get_elf_backend_data (abfd)->collect, | |
4604 | (struct bfd_link_hash_entry **) &h))) | |
4605 | return false; | |
e9f03cd4 | 4606 | h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF; |
5b3b9ff6 ILT |
4607 | h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; |
4608 | h->type = STT_OBJECT; | |
4609 | ||
4610 | if (info->shared | |
4611 | && ! bfd_elf32_link_record_dynamic_symbol (info, h)) | |
4612 | return false; | |
4613 | ||
4614 | /* The first several global offset table entries are reserved. */ | |
4615 | s->_raw_size = MIPS_RESERVED_GOTNO * 4; | |
4616 | ||
4617 | g = (struct mips_got_info *) bfd_alloc (abfd, | |
4618 | sizeof (struct mips_got_info)); | |
4619 | if (g == NULL) | |
4620 | return false; | |
4621 | g->global_gotsym = 0; | |
4622 | g->local_gotno = MIPS_RESERVED_GOTNO; | |
4623 | if (elf_section_data (s) == NULL) | |
4624 | { | |
4625 | s->used_by_bfd = | |
4626 | (PTR) bfd_zalloc (abfd, sizeof (struct bfd_elf_section_data)); | |
4627 | if (elf_section_data (s) == NULL) | |
4628 | return false; | |
4629 | } | |
4630 | elf_section_data (s)->tdata = (PTR) g; | |
4631 | ||
4632 | return true; | |
4633 | } | |
4634 | ||
4635 | /* Look through the relocs for a section during the first phase, and | |
4636 | allocate space in the global offset table. */ | |
4637 | ||
4638 | static boolean | |
4639 | mips_elf_check_relocs (abfd, info, sec, relocs) | |
4640 | bfd *abfd; | |
4641 | struct bfd_link_info *info; | |
4642 | asection *sec; | |
4643 | const Elf_Internal_Rela *relocs; | |
4644 | { | |
4645 | bfd *dynobj; | |
4646 | Elf_Internal_Shdr *symtab_hdr; | |
4647 | struct elf_link_hash_entry **sym_hashes; | |
4648 | struct mips_got_info *g; | |
4649 | size_t extsymoff; | |
4650 | const Elf_Internal_Rela *rel; | |
4651 | const Elf_Internal_Rela *rel_end; | |
4652 | asection *sgot; | |
4653 | asection *sreloc; | |
5b3b9ff6 ILT |
4654 | |
4655 | if (info->relocateable) | |
4656 | return true; | |
4657 | ||
4658 | dynobj = elf_hash_table (info)->dynobj; | |
4659 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
4660 | sym_hashes = elf_sym_hashes (abfd); | |
4661 | extsymoff = (elf_bad_symtab (abfd)) ? 0 : symtab_hdr->sh_info; | |
4662 | ||
4663 | sgot = NULL; | |
4664 | sreloc = NULL; | |
5b3b9ff6 ILT |
4665 | |
4666 | rel_end = relocs + sec->reloc_count; | |
4667 | for (rel = relocs; rel < rel_end; rel++) | |
4668 | { | |
4669 | unsigned long r_symndx; | |
4670 | struct elf_link_hash_entry *h; | |
4671 | ||
4672 | r_symndx = ELF32_R_SYM (rel->r_info); | |
4673 | ||
4674 | if (r_symndx < extsymoff) | |
4675 | h = NULL; | |
4676 | else | |
4677 | h = sym_hashes[r_symndx - extsymoff]; | |
4678 | ||
4679 | /* Some relocs require a global offset table. */ | |
4680 | if (dynobj == NULL) | |
4681 | { | |
4682 | switch (ELF32_R_TYPE (rel->r_info)) | |
4683 | { | |
4684 | case R_MIPS_GOT16: | |
4685 | case R_MIPS_CALL16: | |
4686 | case R_MIPS_CALL_HI16: | |
4687 | case R_MIPS_CALL_LO16: | |
4688 | case R_MIPS_GOT_HI16: | |
4689 | case R_MIPS_GOT_LO16: | |
4690 | elf_hash_table (info)->dynobj = dynobj = abfd; | |
4691 | if (! mips_elf_create_got_section (dynobj, info)) | |
4692 | return false; | |
4693 | break; | |
4694 | ||
4695 | default: | |
4696 | break; | |
4697 | } | |
4698 | } | |
4699 | ||
4700 | switch (ELF32_R_TYPE (rel->r_info)) | |
4701 | { | |
4702 | case R_MIPS_CALL16: | |
4703 | case R_MIPS_CALL_HI16: | |
4704 | case R_MIPS_CALL_LO16: | |
4705 | /* This symbol requires a global offset table entry. */ | |
4706 | if (sgot == NULL) | |
4707 | { | |
4708 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
4709 | BFD_ASSERT (sgot != NULL); | |
4710 | BFD_ASSERT (elf_section_data (sgot) != NULL); | |
4711 | g = (struct mips_got_info *) elf_section_data (sgot)->tdata; | |
4712 | BFD_ASSERT (g != NULL); | |
4713 | } | |
4714 | ||
4715 | BFD_ASSERT (h != NULL); | |
4716 | ||
4717 | /* Make sure this symbol is output as a dynamic symbol. */ | |
4718 | if (h->dynindx == -1) | |
4719 | { | |
4720 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) | |
4721 | return false; | |
4722 | } | |
4723 | ||
4724 | if (h->got_offset != (bfd_vma) -1) | |
4725 | { | |
4726 | /* We have already allocated space in the .got. */ | |
4727 | break; | |
4728 | } | |
4729 | ||
4730 | /* Note the index of the first global got symbol in .dynsym. */ | |
4731 | if (g->global_gotsym == 0 | |
4732 | || g->global_gotsym > (unsigned long) h->dynindx) | |
4733 | g->global_gotsym = h->dynindx; | |
4734 | ||
4735 | /* Make this symbol to have the corresponding got entry. */ | |
4736 | h->got_offset = 0; | |
4737 | ||
4738 | /* We need a stub, not a plt entry for the undefined | |
4739 | function. But we record it as if it needs plt. See | |
4740 | elf_adjust_dynamic_symbol in elflink.h. */ | |
4741 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
4742 | h->type = STT_FUNC; | |
4743 | ||
4744 | break; | |
4745 | ||
4746 | case R_MIPS_GOT16: | |
4747 | case R_MIPS_GOT_HI16: | |
4748 | case R_MIPS_GOT_LO16: | |
4749 | /* This symbol requires a global offset table entry. */ | |
4750 | if (sgot == NULL) | |
4751 | { | |
4752 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
4753 | BFD_ASSERT (sgot != NULL); | |
4754 | BFD_ASSERT (elf_section_data (sgot) != NULL); | |
4755 | g = (struct mips_got_info *) elf_section_data (sgot)->tdata; | |
4756 | BFD_ASSERT (g != NULL); | |
4757 | } | |
4758 | ||
4759 | if (h != NULL) | |
4760 | { | |
4761 | /* Make sure this symbol is output as a dynamic symbol. */ | |
4762 | if (h->dynindx == -1) | |
4763 | { | |
4764 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) | |
4765 | return false; | |
4766 | } | |
4767 | ||
4768 | if (h->got_offset != (bfd_vma) -1) | |
4769 | { | |
4770 | /* We have already allocated space in the .got. */ | |
4771 | break; | |
4772 | } | |
4773 | /* Note the index of the first global got symbol in | |
4774 | .dynsym. */ | |
4775 | if (g->global_gotsym == 0 | |
4776 | || g->global_gotsym > (unsigned long) h->dynindx) | |
4777 | g->global_gotsym = h->dynindx; | |
4778 | ||
4779 | /* Make this symbol to be the global got symbol. */ | |
4780 | h->got_offset = 0; | |
4781 | } | |
4782 | ||
4783 | break; | |
4784 | ||
4785 | case R_MIPS_32: | |
4786 | case R_MIPS_REL32: | |
abec70b9 | 4787 | if ((info->shared || h != NULL) |
5b3b9ff6 ILT |
4788 | && (sec->flags & SEC_ALLOC) != 0) |
4789 | { | |
4790 | /* When creating a shared object, we must copy these | |
4791 | reloc types into the output file as R_MIPS_REL32 | |
4792 | relocs. We create the .rel.dyn reloc section in | |
4793 | dynobj and make room for this reloc. */ | |
4794 | if (sreloc == NULL) | |
4795 | { | |
4796 | const char *name = ".rel.dyn"; | |
4797 | ||
4798 | sreloc = bfd_get_section_by_name (dynobj, name); | |
4799 | if (sreloc == NULL) | |
4800 | { | |
4801 | sreloc = bfd_make_section (dynobj, name); | |
4802 | if (sreloc == NULL | |
4803 | || ! bfd_set_section_flags (dynobj, sreloc, | |
4804 | (SEC_ALLOC | |
4805 | | SEC_LOAD | |
4806 | | SEC_HAS_CONTENTS | |
4807 | | SEC_IN_MEMORY | |
4808 | | SEC_READONLY)) | |
4809 | || ! bfd_set_section_alignment (dynobj, sreloc, 4)) | |
4810 | return false; | |
4811 | ||
4812 | /* Add a null element. */ | |
4813 | sreloc->_raw_size += sizeof (Elf32_External_Rel); | |
4814 | ++sreloc->reloc_count; | |
4815 | } | |
4816 | } | |
4817 | ||
abec70b9 ILT |
4818 | if (info->shared) |
4819 | sreloc->_raw_size += sizeof (Elf32_External_Rel); | |
4820 | else | |
4821 | { | |
4822 | struct mips_elf_link_hash_entry *hmips; | |
4823 | ||
4824 | /* We only need to copy this reloc if the symbol is | |
4825 | defined in a dynamic object. */ | |
4826 | hmips = (struct mips_elf_link_hash_entry *) h; | |
4827 | ++hmips->mips_32_relocs; | |
4828 | } | |
5b3b9ff6 ILT |
4829 | } |
4830 | ||
53787b23 ILT |
4831 | if (SGI_COMPAT (abfd)) |
4832 | mips_elf_hash_table (info)->compact_rel_size += | |
4833 | sizeof (Elf32_External_crinfo); | |
4834 | ||
5b3b9ff6 ILT |
4835 | break; |
4836 | ||
4837 | case R_MIPS_26: | |
4838 | case R_MIPS_GPREL16: | |
4839 | case R_MIPS_LITERAL: | |
4840 | case R_MIPS_GPREL32: | |
53787b23 ILT |
4841 | if (SGI_COMPAT (abfd)) |
4842 | mips_elf_hash_table (info)->compact_rel_size += | |
4843 | sizeof (Elf32_External_crinfo); | |
5b3b9ff6 ILT |
4844 | break; |
4845 | ||
4846 | default: | |
4847 | break; | |
4848 | } | |
4849 | } | |
4850 | ||
4851 | return true; | |
4852 | } | |
4853 | ||
4854 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
4855 | regular object. The current definition is in some section of the | |
4856 | dynamic object, but we're not including those sections. We have to | |
4857 | change the definition to something the rest of the link can | |
4858 | understand. */ | |
4859 | ||
4860 | static boolean | |
4861 | mips_elf_adjust_dynamic_symbol (info, h) | |
4862 | struct bfd_link_info *info; | |
4863 | struct elf_link_hash_entry *h; | |
4864 | { | |
4865 | bfd *dynobj; | |
abec70b9 | 4866 | struct mips_elf_link_hash_entry *hmips; |
5b3b9ff6 ILT |
4867 | asection *s; |
4868 | ||
4869 | dynobj = elf_hash_table (info)->dynobj; | |
4870 | ||
4871 | /* Make sure we know what is going on here. */ | |
4872 | BFD_ASSERT (dynobj != NULL | |
4873 | && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) | |
4874 | || h->weakdef != NULL | |
4875 | || ((h->elf_link_hash_flags | |
4876 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
4877 | && (h->elf_link_hash_flags | |
4878 | & ELF_LINK_HASH_REF_REGULAR) != 0 | |
4879 | && (h->elf_link_hash_flags | |
4880 | & ELF_LINK_HASH_DEF_REGULAR) == 0))); | |
4881 | ||
abec70b9 ILT |
4882 | /* If this symbol is defined in a dynamic object, we need to copy |
4883 | any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output | |
4884 | file. */ | |
4885 | hmips = (struct mips_elf_link_hash_entry *) h; | |
4886 | if (! info->relocateable | |
4887 | && hmips->mips_32_relocs != 0 | |
4888 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
4889 | { | |
4890 | s = bfd_get_section_by_name (dynobj, ".rel.dyn"); | |
4891 | BFD_ASSERT (s != NULL); | |
4892 | ||
4893 | s->_raw_size += hmips->mips_32_relocs * sizeof (Elf32_External_Rel); | |
4894 | } | |
4895 | ||
5b3b9ff6 ILT |
4896 | /* For a function, create a stub, if needed. */ |
4897 | if (h->type == STT_FUNC | |
4898 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) | |
4899 | { | |
4900 | if (! elf_hash_table (info)->dynamic_sections_created) | |
4901 | return true; | |
4902 | ||
4903 | /* If this symbol is not defined in a regular file, then set | |
4904 | the symbol to the stub location. This is required to make | |
4905 | function pointers compare as equal between the normal | |
4906 | executable and the shared library. */ | |
4907 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
4908 | { | |
4909 | /* We need .stub section. */ | |
4910 | s = bfd_get_section_by_name (dynobj, ".stub"); | |
4911 | BFD_ASSERT (s != NULL); | |
4912 | ||
4913 | h->root.u.def.section = s; | |
4914 | h->root.u.def.value = s->_raw_size; | |
4915 | ||
4916 | /* XXX Write this stub address somewhere. */ | |
4917 | h->plt_offset = s->_raw_size; | |
4918 | ||
4919 | /* Make room for this stub code. */ | |
4920 | s->_raw_size += MIPS_FUNCTION_STUB_SIZE; | |
4921 | ||
4922 | /* The last half word of the stub will be filled with the index | |
4923 | of this symbol in .dynsym section. */ | |
4924 | return true; | |
4925 | } | |
4926 | } | |
4927 | ||
4928 | /* If this is a weak symbol, and there is a real definition, the | |
4929 | processor independent code will have arranged for us to see the | |
4930 | real definition first, and we can just use the same value. */ | |
4931 | if (h->weakdef != NULL) | |
4932 | { | |
4933 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
4934 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
4935 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
4936 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
4937 | return true; | |
4938 | } | |
4939 | ||
4940 | /* This is a reference to a symbol defined by a dynamic object which | |
4941 | is not a function. */ | |
4942 | ||
4943 | return true; | |
4944 | } | |
4945 | ||
4946 | /* Set the sizes of the dynamic sections. */ | |
4947 | ||
4948 | static boolean | |
4949 | mips_elf_size_dynamic_sections (output_bfd, info) | |
4950 | bfd *output_bfd; | |
4951 | struct bfd_link_info *info; | |
4952 | { | |
4953 | bfd *dynobj; | |
4954 | asection *s; | |
4955 | boolean reltext; | |
4956 | asection *sgot; | |
4957 | struct mips_got_info *g; | |
4958 | ||
4959 | dynobj = elf_hash_table (info)->dynobj; | |
4960 | BFD_ASSERT (dynobj != NULL); | |
4961 | ||
4962 | if (elf_hash_table (info)->dynamic_sections_created) | |
4963 | { | |
4964 | /* Set the contents of the .interp section to the interpreter. */ | |
4965 | if (! info->shared) | |
4966 | { | |
4967 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
4968 | BFD_ASSERT (s != NULL); | |
4969 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; | |
4970 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
4971 | } | |
4972 | } | |
4973 | ||
4974 | /* Recompute the size of .got for local entires (reserved and | |
4975 | hipages) if needed. To estimate it, get the upper bound of total | |
4976 | size of loadable sections. */ | |
4977 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
4978 | ||
4979 | if (sgot != NULL) | |
4980 | { | |
4981 | bfd_size_type loadable_size = 0; | |
4982 | bfd_size_type local_gotno; | |
4983 | struct _bfd *sub; | |
4984 | ||
4985 | BFD_ASSERT (elf_section_data (sgot) != NULL); | |
4986 | g = (struct mips_got_info *) elf_section_data (sgot)->tdata; | |
4987 | BFD_ASSERT (g != NULL); | |
4988 | ||
4989 | for (sub = info->input_bfds; sub; sub = sub->link_next) | |
4990 | for (s = sub->sections; s != NULL; s = s->next) | |
4991 | { | |
4992 | if ((s->flags & SEC_ALLOC) == 0) | |
4993 | continue; | |
4994 | loadable_size += (s->_raw_size + 0xf) & ~0xf; | |
4995 | } | |
4996 | ||
4997 | loadable_size += MIPS_FUNCTION_STUB_SIZE; | |
4998 | ||
4999 | /* Assume there are two loadable segments consisting of | |
5000 | contiguous sections. Is 5 enough? */ | |
5001 | local_gotno = (loadable_size >> 16) + 5 + MIPS_RESERVED_GOTNO; | |
5002 | g->local_gotno = local_gotno; | |
5003 | sgot->_raw_size += local_gotno * 4; | |
5004 | } | |
5005 | ||
5006 | /* The check_relocs and adjust_dynamic_symbol entry points have | |
5007 | determined the sizes of the various dynamic sections. Allocate | |
5008 | memory for them. */ | |
5009 | reltext = false; | |
5010 | for (s = dynobj->sections; s != NULL; s = s->next) | |
5011 | { | |
5012 | const char *name; | |
5013 | boolean strip; | |
5014 | ||
5015 | /* It's OK to base decisions on the section name, because none | |
5016 | of the dynobj section names depend upon the input files. */ | |
5017 | name = bfd_get_section_name (dynobj, s); | |
5018 | ||
5019 | if ((s->flags & SEC_IN_MEMORY) == 0) | |
5020 | continue; | |
5021 | ||
5022 | strip = false; | |
5023 | ||
5024 | if (strncmp (name, ".rel", 4) == 0) | |
5025 | { | |
5026 | if (s->_raw_size == 0) | |
5027 | strip = true; | |
5028 | else | |
5029 | { | |
5030 | asection *target; | |
5031 | ||
5032 | /* If this relocation section applies to a read only | |
5033 | section, then we probably need a DT_TEXTREL entry. | |
5034 | If the relocation section is .rel.dyn, we always | |
5035 | assert a DT_TEXTREL entry rather than testing whether | |
5036 | there exists a relocation to a read only section or | |
5037 | not. */ | |
5038 | target = bfd_get_section_by_name (output_bfd, name + 4); | |
5039 | if ((target != NULL && (target->flags & SEC_READONLY) != 0) | |
5040 | || strcmp (name, ".rel.dyn") == 0) | |
5041 | reltext = true; | |
5042 | ||
5043 | /* We use the reloc_count field as a counter if we need | |
5044 | to copy relocs into the output file. */ | |
5045 | if (strcmp (name, ".rel.dyn") != 0) | |
5046 | s->reloc_count = 0; | |
5047 | } | |
5048 | } | |
5049 | else if (strncmp (name, ".got", 4) == 0) | |
5050 | { | |
5051 | int i; | |
5052 | ||
5053 | BFD_ASSERT (elf_section_data (s) != NULL); | |
5054 | g = (struct mips_got_info *) elf_section_data (s)->tdata; | |
5055 | BFD_ASSERT (g != NULL); | |
5056 | ||
5057 | /* Fix the size of .got section for the correspondence of | |
5058 | global symbols and got entries. This adds some useless | |
5059 | got entries. Is this required by ABI really? */ | |
5060 | i = elf_hash_table (info)->dynsymcount - g->global_gotsym; | |
5061 | s->_raw_size += i * 4; | |
5062 | } | |
5063 | else if (strncmp (name, ".stub", 5) == 0) | |
5064 | { | |
5065 | /* Irix rld assumes that the function stub isn't at the end | |
5066 | of .text section. So put a dummy. XXX */ | |
5067 | s->_raw_size += MIPS_FUNCTION_STUB_SIZE; | |
5068 | } | |
53787b23 ILT |
5069 | else if (SGI_COMPAT (output_bfd) |
5070 | && strncmp (name, ".compact_rel", 12) == 0) | |
5071 | s->_raw_size += mips_elf_hash_table (info)->compact_rel_size; | |
5072 | else if (strncmp (name, ".init", 5) != 0) | |
5b3b9ff6 ILT |
5073 | { |
5074 | /* It's not one of our sections, so don't allocate space. */ | |
5075 | continue; | |
5076 | } | |
5077 | ||
5078 | if (strip) | |
5079 | { | |
5080 | asection **spp; | |
5081 | ||
5082 | for (spp = &s->output_section->owner->sections; | |
5083 | *spp != s->output_section; | |
5084 | spp = &(*spp)->next) | |
5085 | ; | |
5086 | *spp = s->output_section->next; | |
5087 | --s->output_section->owner->section_count; | |
5088 | ||
5089 | continue; | |
5090 | } | |
5091 | ||
5092 | /* Allocate memory for the section contents. */ | |
5093 | s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size); | |
5094 | if (s->contents == NULL && s->_raw_size != 0) | |
5095 | { | |
5096 | bfd_set_error (bfd_error_no_memory); | |
5097 | return false; | |
5098 | } | |
5099 | memset (s->contents, 0, s->_raw_size); | |
5100 | } | |
5101 | ||
5102 | if (elf_hash_table (info)->dynamic_sections_created) | |
5103 | { | |
5104 | /* Add some entries to the .dynamic section. We fill in the | |
5105 | values later, in elf_mips_finish_dynamic_sections, but we | |
5106 | must add the entries now so that we get the correct size for | |
5107 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
5108 | dynamic linker and used by the debugger. */ | |
5109 | if (! info->shared) | |
5110 | { | |
5111 | if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0)) | |
5112 | return false; | |
5113 | } | |
5114 | ||
5115 | if (reltext) | |
5116 | { | |
5117 | if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0)) | |
5118 | return false; | |
5119 | } | |
5120 | ||
5121 | if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0)) | |
5122 | return false; | |
5123 | ||
5124 | if (bfd_get_section_by_name (dynobj, ".rel.dyn")) | |
5125 | { | |
5126 | if (! bfd_elf32_add_dynamic_entry (info, DT_REL, 0)) | |
5127 | return false; | |
5128 | ||
5129 | if (! bfd_elf32_add_dynamic_entry (info, DT_RELSZ, 0)) | |
5130 | return false; | |
5131 | ||
5132 | if (! bfd_elf32_add_dynamic_entry (info, DT_RELENT, 0)) | |
5133 | return false; | |
5134 | } | |
5135 | ||
5136 | if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_CONFLICTNO, 0)) | |
5137 | return false; | |
5138 | ||
5139 | if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_LIBLISTNO, 0)) | |
5140 | return false; | |
5141 | ||
53787b23 | 5142 | if (bfd_get_section_by_name (dynobj, ".conflict") != NULL) |
5b3b9ff6 ILT |
5143 | { |
5144 | if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_CONFLICT, 0)) | |
5145 | return false; | |
5146 | ||
5147 | s = bfd_get_section_by_name (dynobj, ".liblist"); | |
5148 | BFD_ASSERT (s != NULL); | |
5149 | ||
5150 | if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_LIBLIST, 0)) | |
5151 | return false; | |
5152 | } | |
5153 | ||
5154 | if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_RLD_VERSION, 0)) | |
5155 | return false; | |
5156 | ||
5157 | if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_FLAGS, 0)) | |
5158 | return false; | |
5159 | ||
53787b23 ILT |
5160 | #if 0 |
5161 | /* Time stamps in executable files are a bad idea. */ | |
5b3b9ff6 ILT |
5162 | if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_TIME_STAMP, 0)) |
5163 | return false; | |
53787b23 | 5164 | #endif |
5b3b9ff6 ILT |
5165 | |
5166 | #if 0 /* FIXME */ | |
5167 | if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_ICHECKSUM, 0)) | |
5168 | return false; | |
5169 | #endif | |
5170 | ||
5171 | #if 0 /* FIXME */ | |
5172 | if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_IVERSION, 0)) | |
5173 | return false; | |
5174 | #endif | |
5175 | ||
5176 | if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_BASE_ADDRESS, 0)) | |
5177 | return false; | |
5178 | ||
5179 | if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_LOCAL_GOTNO, 0)) | |
5180 | return false; | |
5181 | ||
5182 | if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_SYMTABNO, 0)) | |
5183 | return false; | |
5184 | ||
5185 | if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_UNREFEXTNO, 0)) | |
5186 | return false; | |
5187 | ||
5188 | if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_GOTSYM, 0)) | |
5189 | return false; | |
5190 | ||
5191 | if (! bfd_elf32_add_dynamic_entry (info, DT_MIPS_HIPAGENO, 0)) | |
5192 | return false; | |
5193 | ||
5194 | #if 0 /* (SGI_COMPAT) */ | |
5195 | if (! bfd_get_section_by_name (dynobj, ".init")) | |
5196 | if (! bfd_elf32_add_dynamic_entry (info, DT_INIT, 0)) | |
5197 | return false; | |
5198 | ||
5199 | if (! bfd_get_section_by_name (dynobj, ".fini")) | |
5200 | if (! bfd_elf32_add_dynamic_entry (info, DT_FINI, 0)) | |
5201 | return false; | |
5202 | #endif | |
5203 | } | |
5204 | ||
53787b23 ILT |
5205 | /* If we use dynamic linking, we generate a section symbol for each |
5206 | output section. These are local symbols, which means that they | |
5207 | must come first in the dynamic symbol table. | |
5b3b9ff6 ILT |
5208 | That means we must increment the dynamic symbol index of every |
5209 | other dynamic symbol. */ | |
53787b23 ILT |
5210 | { |
5211 | const char * const *namep; | |
5212 | unsigned int c, i; | |
5213 | bfd_size_type strindex; | |
5214 | struct bfd_strtab_hash *dynstr; | |
5215 | struct mips_got_info *g; | |
5216 | ||
5217 | if (elf_hash_table (info)->dynamic_sections_created) | |
5218 | { | |
5219 | if (SGI_COMPAT (output_bfd)) | |
5220 | { | |
5221 | c = SIZEOF_MIPS_DYNSYM_SECNAMES - 1; | |
5222 | elf_link_hash_traverse (elf_hash_table (info), | |
5223 | mips_elf_adjust_dynindx, | |
5224 | (PTR) &c); | |
5225 | elf_hash_table (info)->dynsymcount += c; | |
5226 | ||
5227 | dynstr = elf_hash_table (info)->dynstr; | |
5228 | BFD_ASSERT (dynstr != NULL); | |
5229 | ||
5230 | for (i = 1, namep = mips_elf_dynsym_sec_names; | |
5231 | *namep != NULL; | |
5232 | i++, namep++) | |
5233 | { | |
5234 | s = bfd_get_section_by_name (output_bfd, *namep); | |
5235 | if (s != NULL) | |
5236 | elf_section_data (s)->dynindx = i; | |
5b3b9ff6 | 5237 | |
53787b23 ILT |
5238 | strindex = _bfd_stringtab_add (dynstr, *namep, true, false); |
5239 | if (strindex == (bfd_size_type) -1) | |
5240 | return false; | |
5b3b9ff6 | 5241 | |
53787b23 ILT |
5242 | mips_elf_hash_table (info)->dynsym_sec_strindex[i] = strindex; |
5243 | } | |
5244 | } | |
5245 | else | |
5246 | { | |
5247 | c = bfd_count_sections (output_bfd); | |
5248 | elf_link_hash_traverse (elf_hash_table (info), | |
5249 | mips_elf_adjust_dynindx, | |
5250 | (PTR) &c); | |
5251 | elf_hash_table (info)->dynsymcount += c; | |
5b3b9ff6 | 5252 | |
53787b23 ILT |
5253 | for (i = 1, s = output_bfd->sections; s != NULL; s = s->next, i++) |
5254 | { | |
5255 | elf_section_data (s)->dynindx = i; | |
5256 | /* These symbols will have no names, so we don't need to | |
5257 | fiddle with dynstr_index. */ | |
5258 | } | |
5259 | } | |
5260 | } | |
5b3b9ff6 | 5261 | |
53787b23 ILT |
5262 | s = bfd_get_section_by_name (dynobj, ".got"); |
5263 | BFD_ASSERT (s != NULL); | |
5264 | BFD_ASSERT (elf_section_data (s) != NULL); | |
5265 | g = (struct mips_got_info *) elf_section_data (s)->tdata; | |
5266 | BFD_ASSERT (g != NULL); | |
5b3b9ff6 | 5267 | |
53787b23 ILT |
5268 | /* If there are no global got symbols, fake the last symbol so for |
5269 | safety. */ | |
5270 | if (g->global_gotsym) | |
5271 | g->global_gotsym += c; | |
5272 | else | |
5273 | g->global_gotsym = elf_hash_table (info)->dynsymcount - 1; | |
5274 | } | |
5b3b9ff6 ILT |
5275 | |
5276 | return true; | |
5277 | } | |
5278 | ||
5279 | /* Increment the index of a dynamic symbol by a given amount. Called | |
5280 | via elf_link_hash_traverse. */ | |
5281 | ||
5282 | static boolean | |
5283 | mips_elf_adjust_dynindx (h, cparg) | |
5284 | struct elf_link_hash_entry *h; | |
5285 | PTR cparg; | |
5286 | { | |
53787b23 | 5287 | unsigned int *cp = (unsigned int *) cparg; |
5b3b9ff6 ILT |
5288 | |
5289 | if (h->dynindx != -1) | |
5290 | h->dynindx += *cp; | |
5291 | return true; | |
5292 | } | |
5293 | ||
5294 | /* Finish up dynamic symbol handling. We set the contents of various | |
5295 | dynamic sections here. */ | |
5296 | ||
5297 | static boolean | |
5298 | mips_elf_finish_dynamic_symbol (output_bfd, info, h, sym) | |
5299 | bfd *output_bfd; | |
5300 | struct bfd_link_info *info; | |
5301 | struct elf_link_hash_entry *h; | |
5302 | Elf_Internal_Sym *sym; | |
5303 | { | |
5304 | bfd *dynobj; | |
5305 | bfd_vma gval; | |
5306 | asection *sgot; | |
5307 | struct mips_got_info *g; | |
5308 | const char *name; | |
5309 | ||
5310 | dynobj = elf_hash_table (info)->dynobj; | |
5311 | gval = sym->st_value; | |
5312 | ||
5313 | if (h->plt_offset != (bfd_vma) -1) | |
5314 | { | |
5315 | asection *s; | |
5316 | bfd_byte *p; | |
5317 | bfd_byte stub[MIPS_FUNCTION_STUB_SIZE]; | |
5318 | ||
5319 | /* This symbol has a stub. Set it up. */ | |
5320 | ||
5321 | BFD_ASSERT (h->dynindx != -1); | |
5322 | ||
5323 | s = bfd_get_section_by_name (dynobj, ".stub"); | |
5324 | BFD_ASSERT (s != NULL); | |
5325 | ||
5326 | /* Fill the stub. */ | |
5327 | p = stub; | |
5328 | bfd_put_32 (output_bfd, STUB_LW(output_bfd), p); | |
5329 | p += 4; | |
5330 | bfd_put_32 (output_bfd, STUB_MOVE, p); | |
5331 | p += 4; | |
5332 | ||
5333 | /* FIXME: Can h->dynindex be more than 64K? */ | |
5334 | if (h->dynindx & 0xffff0000) | |
5335 | return false; | |
5336 | ||
5337 | bfd_put_32 (output_bfd, STUB_JALR, p); | |
5338 | p += 4; | |
5339 | bfd_put_32 (output_bfd, STUB_LI16 + h->dynindx, p); | |
5340 | ||
5341 | BFD_ASSERT (h->plt_offset <= s->_raw_size); | |
5342 | memcpy (s->contents + h->plt_offset, stub, MIPS_FUNCTION_STUB_SIZE); | |
5343 | ||
5344 | /* Mark the symbol as undefined. plt_offset != -1 occurs | |
5345 | only for the referenced symbol. */ | |
5346 | sym->st_shndx = SHN_UNDEF; | |
5347 | ||
5348 | /* The run-time linker uses the st_value field of the symbol | |
5349 | to reset the global offset table entry for this external | |
5350 | to its stub address when unlinking a shared object. */ | |
5351 | gval = s->output_section->vma + s->output_offset + h->plt_offset; | |
5352 | sym->st_value = gval; | |
5353 | } | |
5354 | ||
5355 | BFD_ASSERT (h->dynindx != -1); | |
5356 | ||
5357 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
5358 | BFD_ASSERT (sgot != NULL); | |
5359 | BFD_ASSERT (elf_section_data (sgot) != NULL); | |
5360 | g = (struct mips_got_info *) elf_section_data (sgot)->tdata; | |
5361 | BFD_ASSERT (g != NULL); | |
5362 | ||
5363 | if ((unsigned long) h->dynindx >= g->global_gotsym) | |
5364 | { | |
5365 | bfd_size_type offset; | |
5366 | ||
5367 | /* This symbol has an entry in the global offset table. Set its | |
5368 | value to the corresponding got entry, if needed. */ | |
5369 | if (h->got_offset == (bfd_vma) -1) | |
5370 | { | |
5371 | offset = (h->dynindx - g->global_gotsym + g->local_gotno) * 4; | |
5372 | BFD_ASSERT (g->local_gotno * 4 <= offset | |
5373 | && offset < sgot->_raw_size); | |
5374 | bfd_put_32 (output_bfd, gval, sgot->contents + offset); | |
5375 | } | |
5376 | } | |
5377 | ||
5378 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */ | |
5379 | name = h->root.root.string; | |
5380 | if (strcmp (name, "_DYNAMIC") == 0 | |
5381 | || strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0) | |
5382 | sym->st_shndx = SHN_ABS; | |
53787b23 ILT |
5383 | else if (strcmp (name, "_DYNAMIC_LINK") == 0) |
5384 | { | |
5385 | sym->st_shndx = SHN_ABS; | |
5386 | sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION); | |
5387 | sym->st_value = 1; | |
5388 | } | |
5389 | else if (SGI_COMPAT (output_bfd)) | |
5b3b9ff6 ILT |
5390 | { |
5391 | if (strcmp (name, "_gp_disp") == 0) | |
5392 | { | |
5393 | sym->st_shndx = SHN_ABS; | |
5394 | sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION); | |
abec70b9 | 5395 | sym->st_value = elf_gp (output_bfd); |
5b3b9ff6 ILT |
5396 | } |
5397 | else if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0 | |
5398 | || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0) | |
5399 | { | |
5400 | sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION); | |
5401 | sym->st_other = STO_PROTECTED; | |
5402 | sym->st_value = 0; | |
5403 | sym->st_shndx = SHN_MIPS_DATA; | |
5404 | } | |
5405 | else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0) | |
5406 | { | |
5407 | sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION); | |
5408 | sym->st_other = STO_PROTECTED; | |
5409 | sym->st_value = mips_elf_hash_table (info)->procedure_count; | |
5410 | sym->st_shndx = SHN_ABS; | |
5411 | } | |
53787b23 | 5412 | else if (sym->st_shndx != SHN_UNDEF) |
5b3b9ff6 ILT |
5413 | { |
5414 | if (h->type == STT_FUNC) | |
5415 | sym->st_shndx = SHN_MIPS_TEXT; | |
5416 | else if (h->type == STT_OBJECT) | |
5417 | sym->st_shndx = SHN_MIPS_DATA; | |
5418 | } | |
5419 | } | |
5420 | ||
5421 | return true; | |
5422 | } | |
5423 | ||
5424 | /* Finish up the dynamic sections. */ | |
5425 | ||
5426 | static boolean | |
5427 | mips_elf_finish_dynamic_sections (output_bfd, info) | |
5428 | bfd *output_bfd; | |
5429 | struct bfd_link_info *info; | |
5430 | { | |
5431 | bfd *dynobj; | |
5432 | asection *sdyn; | |
5433 | asection *sgot; | |
5434 | struct mips_got_info *g; | |
5435 | ||
5436 | dynobj = elf_hash_table (info)->dynobj; | |
5437 | ||
5438 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); | |
5439 | ||
5440 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
5441 | BFD_ASSERT (sgot != NULL); | |
5442 | ||
5443 | BFD_ASSERT (elf_section_data (sgot) != NULL); | |
5444 | g = (struct mips_got_info *) elf_section_data (sgot)->tdata; | |
5445 | BFD_ASSERT (g != NULL); | |
5446 | ||
5447 | if (elf_hash_table (info)->dynamic_sections_created) | |
5448 | { | |
5449 | Elf32_External_Dyn *dyncon, *dynconend; | |
5450 | ||
5451 | BFD_ASSERT (sdyn != NULL); | |
5452 | ||
5453 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
5454 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size); | |
5455 | for (; dyncon < dynconend; dyncon++) | |
5456 | { | |
5457 | Elf_Internal_Dyn dyn; | |
5458 | const char *name; | |
5459 | size_t elemsize; | |
5460 | asection *s; | |
5461 | ||
5462 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); | |
5463 | ||
5464 | switch (dyn.d_tag) | |
5465 | { | |
5466 | default: | |
5467 | break; | |
5468 | ||
5469 | case DT_RELENT: | |
5470 | s = bfd_get_section_by_name (dynobj, ".rel.dyn"); | |
5471 | BFD_ASSERT (s != NULL); | |
5472 | dyn.d_un.d_val = sizeof (Elf32_External_Rel); | |
5473 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5474 | break; | |
5475 | ||
5476 | case DT_STRSZ: | |
5477 | /* Rewrite DT_STRSZ. */ | |
5478 | dyn.d_un.d_val = | |
5479 | _bfd_stringtab_size (elf_hash_table (info)->dynstr); | |
5480 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5481 | break; | |
5482 | ||
5483 | case DT_PLTGOT: | |
5484 | name = ".got"; | |
5485 | goto get_vma; | |
5486 | case DT_MIPS_CONFLICT: | |
5487 | name = ".conflict"; | |
5488 | goto get_vma; | |
5489 | case DT_MIPS_LIBLIST: | |
5490 | name = ".liblist"; | |
5491 | get_vma: | |
5492 | s = bfd_get_section_by_name (output_bfd, name); | |
5493 | BFD_ASSERT (s != NULL); | |
5494 | dyn.d_un.d_ptr = s->vma; | |
5495 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5496 | break; | |
5497 | ||
5498 | case DT_MIPS_RLD_VERSION: | |
5499 | dyn.d_un.d_val = 1; /* XXX */ | |
5500 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5501 | break; | |
5502 | ||
5503 | case DT_MIPS_FLAGS: | |
5504 | dyn.d_un.d_val = RHF_NOTPOT; /* XXX */ | |
5505 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5506 | break; | |
5507 | ||
5508 | case DT_MIPS_CONFLICTNO: | |
5509 | name = ".conflict"; | |
5510 | elemsize = sizeof (Elf32_Conflict); | |
5511 | goto set_elemno; | |
5512 | ||
5513 | case DT_MIPS_LIBLISTNO: | |
5514 | name = ".liblist"; | |
5515 | elemsize = sizeof (Elf32_Lib); | |
5516 | set_elemno: | |
5517 | s = bfd_get_section_by_name (output_bfd, name); | |
5518 | if (s != NULL) | |
5519 | { | |
5520 | if (s->_cooked_size != 0) | |
5521 | dyn.d_un.d_val = s->_cooked_size / elemsize; | |
5522 | else | |
5523 | dyn.d_un.d_val = s->_raw_size / elemsize; | |
5524 | } | |
5525 | else | |
5526 | dyn.d_un.d_val = 0; | |
5527 | ||
5528 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5529 | break; | |
5530 | ||
5531 | case DT_MIPS_TIME_STAMP: | |
5532 | time ((time_t *) &dyn.d_un.d_val); | |
5533 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5534 | break; | |
5535 | ||
5536 | case DT_MIPS_ICHECKSUM: | |
5537 | /* XXX FIXME: */ | |
5538 | break; | |
5539 | ||
5540 | case DT_MIPS_IVERSION: | |
5541 | /* XXX FIXME: */ | |
5542 | break; | |
5543 | ||
5544 | case DT_MIPS_BASE_ADDRESS: | |
5545 | s = output_bfd->sections; | |
5546 | BFD_ASSERT (s != NULL); | |
5547 | dyn.d_un.d_ptr = s->vma & ~(0xffff); | |
5548 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5549 | break; | |
5550 | ||
5551 | case DT_MIPS_LOCAL_GOTNO: | |
5552 | dyn.d_un.d_val = g->local_gotno; | |
5553 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5554 | break; | |
5555 | ||
5556 | case DT_MIPS_SYMTABNO: | |
5557 | name = ".dynsym"; | |
5558 | elemsize = sizeof (Elf32_External_Sym); | |
5559 | s = bfd_get_section_by_name (output_bfd, name); | |
5560 | BFD_ASSERT (s != NULL); | |
5561 | ||
5562 | if (s->_cooked_size != 0) | |
5563 | dyn.d_un.d_val = s->_cooked_size / elemsize; | |
5564 | else | |
5565 | dyn.d_un.d_val = s->_raw_size / elemsize; | |
5566 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5567 | break; | |
5568 | ||
5569 | case DT_MIPS_UNREFEXTNO: | |
5570 | /* XXX FIXME: */ | |
5571 | dyn.d_un.d_val = SIZEOF_MIPS_DYNSYM_SECNAMES; | |
5572 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5573 | break; | |
5574 | ||
5575 | case DT_MIPS_GOTSYM: | |
5576 | dyn.d_un.d_val = g->global_gotsym; | |
5577 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5578 | break; | |
5579 | ||
5580 | case DT_MIPS_HIPAGENO: | |
5581 | dyn.d_un.d_val = g->local_gotno - MIPS_RESERVED_GOTNO; | |
5582 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
5583 | break; | |
5584 | ||
5585 | } | |
5586 | } | |
5587 | } | |
5588 | ||
5589 | /* The first entry of the global offset table will be filled at | |
5590 | runtime. The second entry will be used by some runtime loaders. | |
5591 | This isn't the case of Irix rld. */ | |
5592 | if (sgot->_raw_size > 0) | |
5593 | { | |
5594 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); | |
5595 | bfd_put_32 (output_bfd, (bfd_vma) 0x80000000, sgot->contents + 4); | |
5596 | } | |
5597 | ||
5598 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; | |
5599 | ||
53787b23 ILT |
5600 | { |
5601 | asection *sdynsym; | |
5602 | asection *s; | |
5603 | unsigned int i; | |
5604 | bfd_vma last; | |
5605 | Elf_Internal_Sym sym; | |
5606 | long dindx; | |
5607 | const char *name; | |
5608 | const char * const * namep = mips_elf_dynsym_sec_names; | |
5609 | Elf32_compact_rel cpt; | |
5610 | ||
5611 | /* Set up the section symbols for the output sections. SGI sets | |
5612 | the STT_NOTYPE attribute for these symbols. Should we do so? */ | |
5613 | ||
5614 | sdynsym = bfd_get_section_by_name (dynobj, ".dynsym"); | |
5615 | if (sdynsym != NULL) | |
5616 | { | |
5617 | if (SGI_COMPAT (output_bfd)) | |
5618 | { | |
5619 | sym.st_size = 0; | |
5620 | sym.st_name = 0; | |
5621 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE); | |
5622 | sym.st_other = 0; | |
5b3b9ff6 | 5623 | |
53787b23 ILT |
5624 | i = 0; |
5625 | while ((name = *namep++) != NULL) | |
5626 | { | |
5627 | s = bfd_get_section_by_name (output_bfd, name); | |
5628 | if (s != NULL) | |
5629 | { | |
5630 | sym.st_value = s->vma; | |
5631 | dindx = elf_section_data (s)->dynindx; | |
5632 | last = s->vma + s->_raw_size; | |
5633 | } | |
5634 | else | |
5635 | { | |
5636 | sym.st_value = last; | |
5637 | dindx++; | |
5638 | } | |
5b3b9ff6 | 5639 | |
53787b23 ILT |
5640 | sym.st_shndx = (i < MIPS_TEXT_DYNSYM_SECNO |
5641 | ? SHN_MIPS_TEXT | |
5642 | : SHN_MIPS_DATA); | |
5643 | ++i; | |
5644 | sym.st_name = | |
5645 | mips_elf_hash_table (info)->dynsym_sec_strindex[dindx]; | |
5646 | ||
5647 | bfd_elf32_swap_symbol_out (output_bfd, &sym, | |
5648 | (((Elf32_External_Sym *) | |
5649 | sdynsym->contents) | |
5650 | + dindx)); | |
5651 | } | |
5b3b9ff6 | 5652 | |
53787b23 ILT |
5653 | /* Set the sh_info field of the output .dynsym section to |
5654 | the index of the first global symbol. */ | |
5655 | elf_section_data (sdynsym->output_section)->this_hdr.sh_info = | |
5656 | SIZEOF_MIPS_DYNSYM_SECNAMES; | |
5657 | } | |
5658 | else | |
5659 | { | |
5660 | sym.st_size = 0; | |
5661 | sym.st_name = 0; | |
5662 | sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION); | |
5663 | sym.st_other = 0; | |
5b3b9ff6 | 5664 | |
53787b23 ILT |
5665 | for (s = output_bfd->sections; s != NULL; s = s->next) |
5666 | { | |
5667 | int indx; | |
5b3b9ff6 | 5668 | |
53787b23 | 5669 | sym.st_value = s->vma; |
5b3b9ff6 | 5670 | |
53787b23 ILT |
5671 | indx = elf_section_data (s)->this_idx; |
5672 | BFD_ASSERT (indx > 0); | |
5673 | sym.st_shndx = indx; | |
5b3b9ff6 | 5674 | |
53787b23 ILT |
5675 | bfd_elf32_swap_symbol_out (output_bfd, &sym, |
5676 | (((Elf32_External_Sym *) | |
5677 | sdynsym->contents) | |
5678 | + elf_section_data (s)->dynindx)); | |
5679 | } | |
5b3b9ff6 | 5680 | |
53787b23 ILT |
5681 | /* Set the sh_info field of the output .dynsym section to |
5682 | the index of the first global symbol. */ | |
5683 | elf_section_data (sdynsym->output_section)->this_hdr.sh_info = | |
5684 | bfd_count_sections (output_bfd) + 1; | |
5685 | } | |
5686 | } | |
5b3b9ff6 | 5687 | |
53787b23 ILT |
5688 | if (SGI_COMPAT (output_bfd)) |
5689 | { | |
5690 | /* Write .compact_rel section out. */ | |
5691 | s = bfd_get_section_by_name (dynobj, ".compact_rel"); | |
5692 | if (s != NULL) | |
5693 | { | |
5694 | cpt.id1 = 1; | |
5695 | cpt.num = s->reloc_count; | |
5696 | cpt.id2 = 2; | |
5697 | cpt.offset = (s->output_section->filepos | |
5698 | + sizeof (Elf32_External_compact_rel)); | |
5699 | cpt.reserved0 = 0; | |
5700 | cpt.reserved1 = 0; | |
5701 | bfd_elf32_swap_compact_rel_out (output_bfd, &cpt, | |
5702 | ((Elf32_External_compact_rel *) | |
5703 | s->contents)); | |
5704 | ||
5705 | /* Clean up a dummy stub function entry in .text. */ | |
5706 | s = bfd_get_section_by_name (dynobj, ".stub"); | |
5707 | if (s != NULL) | |
5708 | { | |
5709 | file_ptr dummy_offset; | |
5b3b9ff6 | 5710 | |
53787b23 ILT |
5711 | BFD_ASSERT (s->_raw_size >= MIPS_FUNCTION_STUB_SIZE); |
5712 | dummy_offset = s->_raw_size - MIPS_FUNCTION_STUB_SIZE; | |
5713 | memset (s->contents + dummy_offset, 0, | |
5714 | MIPS_FUNCTION_STUB_SIZE); | |
5715 | } | |
5716 | } | |
5717 | } | |
5b3b9ff6 | 5718 | |
53787b23 ILT |
5719 | /* Clean up a first relocation in .rel.dyn. */ |
5720 | s = bfd_get_section_by_name (dynobj, ".rel.dyn"); | |
5721 | if (s != NULL) | |
5722 | memset (s->contents, 0, sizeof (Elf32_External_Rel)); | |
5723 | } | |
5b3b9ff6 ILT |
5724 | |
5725 | return true; | |
5726 | } | |
5727 | \f | |
5728 | /* This is almost identical to bfd_generic_get_... except that some | |
5729 | MIPS relocations need to be handled specially. Sigh. */ | |
5730 | ||
5731 | static bfd_byte * | |
5732 | elf32_mips_get_relocated_section_contents (abfd, link_info, link_order, data, | |
5733 | relocateable, symbols) | |
5734 | bfd *abfd; | |
5735 | struct bfd_link_info *link_info; | |
5736 | struct bfd_link_order *link_order; | |
5737 | bfd_byte *data; | |
5738 | boolean relocateable; | |
5739 | asymbol **symbols; | |
5740 | { | |
5741 | /* Get enough memory to hold the stuff */ | |
5742 | bfd *input_bfd = link_order->u.indirect.section->owner; | |
5743 | asection *input_section = link_order->u.indirect.section; | |
5744 | ||
5745 | long reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section); | |
5746 | arelent **reloc_vector = NULL; | |
5747 | long reloc_count; | |
5748 | ||
5749 | if (reloc_size < 0) | |
5750 | goto error_return; | |
5751 | ||
5752 | reloc_vector = (arelent **) bfd_malloc (reloc_size); | |
5753 | if (reloc_vector == NULL && reloc_size != 0) | |
5754 | goto error_return; | |
5755 | ||
a16fcab3 KR |
5756 | /* read in the section */ |
5757 | if (!bfd_get_section_contents (input_bfd, | |
5758 | input_section, | |
5759 | (PTR) data, | |
5760 | 0, | |
5761 | input_section->_raw_size)) | |
5762 | goto error_return; | |
5763 | ||
5764 | /* We're not relaxing the section, so just copy the size info */ | |
5765 | input_section->_cooked_size = input_section->_raw_size; | |
5766 | input_section->reloc_done = true; | |
5767 | ||
5768 | reloc_count = bfd_canonicalize_reloc (input_bfd, | |
5769 | input_section, | |
5770 | reloc_vector, | |
5771 | symbols); | |
5772 | if (reloc_count < 0) | |
5773 | goto error_return; | |
5774 | ||
5775 | if (reloc_count > 0) | |
5776 | { | |
5777 | arelent **parent; | |
5778 | /* for mips */ | |
5779 | int gp_found; | |
ede4eed4 | 5780 | bfd_vma gp = 0x12345678; /* initialize just to shut gcc up */ |
a16fcab3 KR |
5781 | |
5782 | { | |
5783 | struct bfd_hash_entry *h; | |
5784 | struct bfd_link_hash_entry *lh; | |
5785 | /* Skip all this stuff if we aren't mixing formats. */ | |
5786 | if (abfd && input_bfd | |
5787 | && abfd->xvec == input_bfd->xvec) | |
5788 | lh = 0; | |
5789 | else | |
5790 | { | |
a2546fce | 5791 | h = bfd_hash_lookup (&link_info->hash->table, "_gp", false, false); |
a16fcab3 KR |
5792 | lh = (struct bfd_link_hash_entry *) h; |
5793 | } | |
5794 | lookup: | |
5795 | if (lh) | |
5796 | { | |
5797 | switch (lh->type) | |
5798 | { | |
5799 | case bfd_link_hash_undefined: | |
5800 | case bfd_link_hash_undefweak: | |
5801 | case bfd_link_hash_common: | |
5802 | gp_found = 0; | |
5803 | break; | |
5804 | case bfd_link_hash_defined: | |
5805 | case bfd_link_hash_defweak: | |
5806 | gp_found = 1; | |
5807 | gp = lh->u.def.value; | |
5808 | break; | |
5809 | case bfd_link_hash_indirect: | |
5810 | case bfd_link_hash_warning: | |
5811 | lh = lh->u.i.link; | |
5812 | /* @@FIXME ignoring warning for now */ | |
5813 | goto lookup; | |
5814 | case bfd_link_hash_new: | |
5815 | default: | |
5816 | abort (); | |
5817 | } | |
5818 | } | |
5819 | else | |
5820 | gp_found = 0; | |
5821 | } | |
5822 | /* end mips */ | |
5823 | for (parent = reloc_vector; *parent != (arelent *) NULL; | |
5824 | parent++) | |
5825 | { | |
5826 | char *error_message = (char *) NULL; | |
5827 | bfd_reloc_status_type r; | |
5828 | ||
5829 | /* Specific to MIPS: Deal with relocation types that require | |
5830 | knowing the gp of the output bfd. */ | |
5831 | asymbol *sym = *(*parent)->sym_ptr_ptr; | |
5832 | if (bfd_is_abs_section (sym->section) && abfd) | |
5833 | { | |
5834 | /* The special_function wouldn't get called anyways. */ | |
5835 | } | |
5836 | else if (!gp_found) | |
5837 | { | |
5838 | /* The gp isn't there; let the special function code | |
5839 | fall over on its own. */ | |
5840 | } | |
5b3b9ff6 ILT |
5841 | else if ((*parent)->howto->special_function |
5842 | == mips_elf_gprel16_reloc) | |
a16fcab3 KR |
5843 | { |
5844 | /* bypass special_function call */ | |
5845 | r = gprel16_with_gp (input_bfd, sym, *parent, input_section, | |
5846 | relocateable, (PTR) data, gp); | |
5847 | goto skip_bfd_perform_relocation; | |
5848 | } | |
5849 | /* end mips specific stuff */ | |
5850 | ||
5851 | r = bfd_perform_relocation (input_bfd, | |
5852 | *parent, | |
5853 | (PTR) data, | |
5854 | input_section, | |
5855 | relocateable ? abfd : (bfd *) NULL, | |
5856 | &error_message); | |
5857 | skip_bfd_perform_relocation: | |
5858 | ||
5859 | if (relocateable) | |
5860 | { | |
5861 | asection *os = input_section->output_section; | |
5862 | ||
5863 | /* A partial link, so keep the relocs */ | |
5864 | os->orelocation[os->reloc_count] = *parent; | |
5865 | os->reloc_count++; | |
5866 | } | |
5867 | ||
5868 | if (r != bfd_reloc_ok) | |
5869 | { | |
5870 | switch (r) | |
5871 | { | |
5872 | case bfd_reloc_undefined: | |
5873 | if (!((*link_info->callbacks->undefined_symbol) | |
5874 | (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr), | |
5875 | input_bfd, input_section, (*parent)->address))) | |
5876 | goto error_return; | |
5877 | break; | |
5878 | case bfd_reloc_dangerous: | |
5879 | BFD_ASSERT (error_message != (char *) NULL); | |
5880 | if (!((*link_info->callbacks->reloc_dangerous) | |
5881 | (link_info, error_message, input_bfd, input_section, | |
5882 | (*parent)->address))) | |
5883 | goto error_return; | |
5884 | break; | |
5885 | case bfd_reloc_overflow: | |
5886 | if (!((*link_info->callbacks->reloc_overflow) | |
5887 | (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr), | |
5888 | (*parent)->howto->name, (*parent)->addend, | |
5889 | input_bfd, input_section, (*parent)->address))) | |
5890 | goto error_return; | |
5891 | break; | |
5892 | case bfd_reloc_outofrange: | |
5893 | default: | |
5894 | abort (); | |
5895 | break; | |
5896 | } | |
5897 | ||
5898 | } | |
5899 | } | |
5900 | } | |
5901 | if (reloc_vector != NULL) | |
5902 | free (reloc_vector); | |
5903 | return data; | |
5904 | ||
5905 | error_return: | |
5906 | if (reloc_vector != NULL) | |
5907 | free (reloc_vector); | |
5908 | return NULL; | |
5909 | } | |
5b3b9ff6 ILT |
5910 | #define bfd_elf32_bfd_get_relocated_section_contents \ |
5911 | elf32_mips_get_relocated_section_contents | |
a16fcab3 | 5912 | \f |
6e07e54f ILT |
5913 | /* ECOFF swapping routines. These are used when dealing with the |
5914 | .mdebug section, which is in the ECOFF debugging format. */ | |
00176555 | 5915 | static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = |
6e07e54f ILT |
5916 | { |
5917 | /* Symbol table magic number. */ | |
5918 | magicSym, | |
5919 | /* Alignment of debugging information. E.g., 4. */ | |
5920 | 4, | |
5921 | /* Sizes of external symbolic information. */ | |
5922 | sizeof (struct hdr_ext), | |
5923 | sizeof (struct dnr_ext), | |
5924 | sizeof (struct pdr_ext), | |
5925 | sizeof (struct sym_ext), | |
5926 | sizeof (struct opt_ext), | |
5927 | sizeof (struct fdr_ext), | |
5928 | sizeof (struct rfd_ext), | |
5929 | sizeof (struct ext_ext), | |
5930 | /* Functions to swap in external symbolic data. */ | |
5931 | ecoff_swap_hdr_in, | |
5932 | ecoff_swap_dnr_in, | |
5933 | ecoff_swap_pdr_in, | |
5934 | ecoff_swap_sym_in, | |
5935 | ecoff_swap_opt_in, | |
5936 | ecoff_swap_fdr_in, | |
5937 | ecoff_swap_rfd_in, | |
5938 | ecoff_swap_ext_in, | |
75f3ef7a ILT |
5939 | _bfd_ecoff_swap_tir_in, |
5940 | _bfd_ecoff_swap_rndx_in, | |
6e07e54f ILT |
5941 | /* Functions to swap out external symbolic data. */ |
5942 | ecoff_swap_hdr_out, | |
5943 | ecoff_swap_dnr_out, | |
5944 | ecoff_swap_pdr_out, | |
5945 | ecoff_swap_sym_out, | |
5946 | ecoff_swap_opt_out, | |
5947 | ecoff_swap_fdr_out, | |
5948 | ecoff_swap_rfd_out, | |
aac6b32f | 5949 | ecoff_swap_ext_out, |
75f3ef7a ILT |
5950 | _bfd_ecoff_swap_tir_out, |
5951 | _bfd_ecoff_swap_rndx_out, | |
aac6b32f | 5952 | /* Function to read in symbolic data. */ |
00176555 | 5953 | _bfd_mips_elf_read_ecoff_info |
6e07e54f ILT |
5954 | }; |
5955 | \f | |
6b4b4d17 JK |
5956 | #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec |
5957 | #define TARGET_LITTLE_NAME "elf32-littlemips" | |
5958 | #define TARGET_BIG_SYM bfd_elf32_bigmips_vec | |
5959 | #define TARGET_BIG_NAME "elf32-bigmips" | |
5960 | #define ELF_ARCH bfd_arch_mips | |
6e07e54f | 5961 | #define ELF_MACHINE_CODE EM_MIPS |
b3c0fc57 | 5962 | #define ELF_MAXPAGESIZE 0x10000 |
497c5434 | 5963 | #define elf_backend_collect true |
5b3b9ff6 | 5964 | #define elf_backend_type_change_ok true |
b3c0fc57 ILT |
5965 | #define elf_info_to_howto 0 |
5966 | #define elf_info_to_howto_rel mips_info_to_howto_rel | |
6e07e54f | 5967 | #define elf_backend_sym_is_global mips_elf_sym_is_global |
00176555 | 5968 | #define elf_backend_object_p mips_elf32_object_p |
d1bf45aa | 5969 | #define elf_backend_section_from_shdr mips_elf32_section_from_shdr |
00176555 | 5970 | #define elf_backend_fake_sections _bfd_mips_elf_fake_sections |
b3c0fc57 | 5971 | #define elf_backend_section_from_bfd_section \ |
00176555 ILT |
5972 | _bfd_mips_elf_section_from_bfd_section |
5973 | #define elf_backend_section_processing mips_elf32_section_processing | |
5974 | #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing | |
5b3b9ff6 ILT |
5975 | #define elf_backend_additional_program_headers \ |
5976 | mips_elf_additional_program_headers | |
5977 | #define elf_backend_modify_segment_map mips_elf_modify_segment_map | |
6e07e54f | 5978 | #define elf_backend_final_write_processing \ |
00176555 ILT |
5979 | _bfd_mips_elf_final_write_processing |
5980 | #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap | |
b3c0fc57 | 5981 | |
a2546fce | 5982 | #define bfd_elf32_bfd_is_local_label mips_elf_is_local_label |
a16fcab3 KR |
5983 | #define bfd_elf32_find_nearest_line mips_elf_find_nearest_line |
5984 | ||
aac6b32f ILT |
5985 | #define bfd_elf32_bfd_link_hash_table_create \ |
5986 | mips_elf_link_hash_table_create | |
6e07e54f | 5987 | #define bfd_elf32_bfd_final_link mips_elf_final_link |
5b3b9ff6 ILT |
5988 | #define bfd_elf32_bfd_copy_private_bfd_data \ |
5989 | mips_elf_copy_private_bfd_data | |
5990 | #define bfd_elf32_bfd_merge_private_bfd_data \ | |
5991 | mips_elf_merge_private_bfd_data | |
5992 | #define bfd_elf32_bfd_set_private_flags mips_elf_set_private_flags | |
aac6b32f | 5993 | #define elf_backend_add_symbol_hook mips_elf_add_symbol_hook |
5b3b9ff6 ILT |
5994 | #define elf_backend_create_dynamic_sections \ |
5995 | mips_elf_create_dynamic_sections | |
5996 | #define elf_backend_check_relocs mips_elf_check_relocs | |
5997 | #define elf_backend_adjust_dynamic_symbol \ | |
5998 | mips_elf_adjust_dynamic_symbol | |
5999 | #define elf_backend_size_dynamic_sections \ | |
6000 | mips_elf_size_dynamic_sections | |
6001 | #define elf_backend_relocate_section mips_elf_relocate_section | |
6002 | #define elf_backend_finish_dynamic_symbol \ | |
6003 | mips_elf_finish_dynamic_symbol | |
6004 | #define elf_backend_finish_dynamic_sections \ | |
6005 | mips_elf_finish_dynamic_sections | |
6b4b4d17 JK |
6006 | |
6007 | #include "elf32-target.h" |