]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD back-end for ALPHA Extended-Coff files. |
d87bef3a | 2 | Copyright (C) 1993-2023 Free Software Foundation, Inc. |
252b5132 RH |
3 | Modified from coff-mips.c by Steve Chamberlain <sac@cygnus.com> and |
4 | Ian Lance Taylor <ian@cygnus.com>. | |
5 | ||
cd123cb7 | 6 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 7 | |
cd123cb7 NC |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 3 of the License, or | |
11 | (at your option) any later version. | |
252b5132 | 12 | |
cd123cb7 NC |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
252b5132 | 17 | |
cd123cb7 NC |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
21 | MA 02110-1301, USA. */ | |
252b5132 | 22 | |
252b5132 | 23 | #include "sysdep.h" |
3db64b00 | 24 | #include "bfd.h" |
252b5132 RH |
25 | #include "bfdlink.h" |
26 | #include "libbfd.h" | |
27 | #include "coff/internal.h" | |
28 | #include "coff/sym.h" | |
29 | #include "coff/symconst.h" | |
30 | #include "coff/ecoff.h" | |
31 | #include "coff/alpha.h" | |
32 | #include "aout/ar.h" | |
33 | #include "libcoff.h" | |
34 | #include "libecoff.h" | |
35 | \f | |
36 | /* Prototypes for static functions. */ | |
37 | ||
2c3fc389 | 38 | |
252b5132 RH |
39 | \f |
40 | /* ECOFF has COFF sections, but the debugging information is stored in | |
41 | a completely different format. ECOFF targets use some of the | |
42 | swapping routines from coffswap.h, and some of the generic COFF | |
43 | routines in coffgen.c, but, unlike the real COFF targets, do not | |
44 | use coffcode.h itself. | |
45 | ||
46 | Get the generic COFF swapping routines, except for the reloc, | |
47 | symbol, and lineno ones. Give them ecoff names. Define some | |
48 | accessor macros for the large sizes used for Alpha ECOFF. */ | |
49 | ||
dc810e39 AM |
50 | #define GET_FILEHDR_SYMPTR H_GET_64 |
51 | #define PUT_FILEHDR_SYMPTR H_PUT_64 | |
52 | #define GET_AOUTHDR_TSIZE H_GET_64 | |
53 | #define PUT_AOUTHDR_TSIZE H_PUT_64 | |
54 | #define GET_AOUTHDR_DSIZE H_GET_64 | |
55 | #define PUT_AOUTHDR_DSIZE H_PUT_64 | |
56 | #define GET_AOUTHDR_BSIZE H_GET_64 | |
57 | #define PUT_AOUTHDR_BSIZE H_PUT_64 | |
58 | #define GET_AOUTHDR_ENTRY H_GET_64 | |
59 | #define PUT_AOUTHDR_ENTRY H_PUT_64 | |
60 | #define GET_AOUTHDR_TEXT_START H_GET_64 | |
61 | #define PUT_AOUTHDR_TEXT_START H_PUT_64 | |
62 | #define GET_AOUTHDR_DATA_START H_GET_64 | |
63 | #define PUT_AOUTHDR_DATA_START H_PUT_64 | |
64 | #define GET_SCNHDR_PADDR H_GET_64 | |
65 | #define PUT_SCNHDR_PADDR H_PUT_64 | |
66 | #define GET_SCNHDR_VADDR H_GET_64 | |
67 | #define PUT_SCNHDR_VADDR H_PUT_64 | |
68 | #define GET_SCNHDR_SIZE H_GET_64 | |
69 | #define PUT_SCNHDR_SIZE H_PUT_64 | |
70 | #define GET_SCNHDR_SCNPTR H_GET_64 | |
71 | #define PUT_SCNHDR_SCNPTR H_PUT_64 | |
72 | #define GET_SCNHDR_RELPTR H_GET_64 | |
73 | #define PUT_SCNHDR_RELPTR H_PUT_64 | |
74 | #define GET_SCNHDR_LNNOPTR H_GET_64 | |
75 | #define PUT_SCNHDR_LNNOPTR H_PUT_64 | |
252b5132 RH |
76 | |
77 | #define ALPHAECOFF | |
78 | ||
79 | #define NO_COFF_RELOCS | |
80 | #define NO_COFF_SYMBOLS | |
81 | #define NO_COFF_LINENOS | |
82 | #define coff_swap_filehdr_in alpha_ecoff_swap_filehdr_in | |
83 | #define coff_swap_filehdr_out alpha_ecoff_swap_filehdr_out | |
84 | #define coff_swap_aouthdr_in alpha_ecoff_swap_aouthdr_in | |
85 | #define coff_swap_aouthdr_out alpha_ecoff_swap_aouthdr_out | |
86 | #define coff_swap_scnhdr_in alpha_ecoff_swap_scnhdr_in | |
87 | #define coff_swap_scnhdr_out alpha_ecoff_swap_scnhdr_out | |
88 | #include "coffswap.h" | |
89 | ||
90 | /* Get the ECOFF swapping routines. */ | |
91 | #define ECOFF_64 | |
92 | #include "ecoffswap.h" | |
93 | \f | |
94 | /* How to process the various reloc types. */ | |
95 | ||
252b5132 | 96 | static bfd_reloc_status_type |
2c3fc389 NC |
97 | reloc_nil (bfd *abfd ATTRIBUTE_UNUSED, |
98 | arelent *reloc ATTRIBUTE_UNUSED, | |
99 | asymbol *sym ATTRIBUTE_UNUSED, | |
100 | void * data ATTRIBUTE_UNUSED, | |
101 | asection *sec ATTRIBUTE_UNUSED, | |
102 | bfd *output_bfd ATTRIBUTE_UNUSED, | |
103 | char **error_message ATTRIBUTE_UNUSED) | |
252b5132 RH |
104 | { |
105 | return bfd_reloc_ok; | |
106 | } | |
107 | ||
108 | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value | |
109 | from smaller values. Start with zero, widen, *then* decrement. */ | |
110 | #define MINUS_ONE (((bfd_vma)0) - 1) | |
111 | ||
112 | static reloc_howto_type alpha_howto_table[] = | |
113 | { | |
114 | /* Reloc type 0 is ignored by itself. However, it appears after a | |
115 | GPDISP reloc to identify the location where the low order 16 bits | |
116 | of the gp register are loaded. */ | |
117 | HOWTO (ALPHA_R_IGNORE, /* type */ | |
118 | 0, /* rightshift */ | |
c94cb026 | 119 | 1, /* size */ |
252b5132 | 120 | 8, /* bitsize */ |
0a1b45a2 | 121 | true, /* pc_relative */ |
252b5132 RH |
122 | 0, /* bitpos */ |
123 | complain_overflow_dont, /* complain_on_overflow */ | |
124 | reloc_nil, /* special_function */ | |
125 | "IGNORE", /* name */ | |
0a1b45a2 | 126 | true, /* partial_inplace */ |
252b5132 RH |
127 | 0, /* src_mask */ |
128 | 0, /* dst_mask */ | |
0a1b45a2 | 129 | true), /* pcrel_offset */ |
252b5132 RH |
130 | |
131 | /* A 32 bit reference to a symbol. */ | |
132 | HOWTO (ALPHA_R_REFLONG, /* type */ | |
133 | 0, /* rightshift */ | |
c94cb026 | 134 | 4, /* size */ |
252b5132 | 135 | 32, /* bitsize */ |
0a1b45a2 | 136 | false, /* pc_relative */ |
252b5132 RH |
137 | 0, /* bitpos */ |
138 | complain_overflow_bitfield, /* complain_on_overflow */ | |
139 | 0, /* special_function */ | |
140 | "REFLONG", /* name */ | |
0a1b45a2 | 141 | true, /* partial_inplace */ |
252b5132 RH |
142 | 0xffffffff, /* src_mask */ |
143 | 0xffffffff, /* dst_mask */ | |
0a1b45a2 | 144 | false), /* pcrel_offset */ |
252b5132 RH |
145 | |
146 | /* A 64 bit reference to a symbol. */ | |
147 | HOWTO (ALPHA_R_REFQUAD, /* type */ | |
148 | 0, /* rightshift */ | |
c94cb026 | 149 | 8, /* size */ |
252b5132 | 150 | 64, /* bitsize */ |
0a1b45a2 | 151 | false, /* pc_relative */ |
252b5132 RH |
152 | 0, /* bitpos */ |
153 | complain_overflow_bitfield, /* complain_on_overflow */ | |
154 | 0, /* special_function */ | |
155 | "REFQUAD", /* name */ | |
0a1b45a2 | 156 | true, /* partial_inplace */ |
252b5132 RH |
157 | MINUS_ONE, /* src_mask */ |
158 | MINUS_ONE, /* dst_mask */ | |
0a1b45a2 | 159 | false), /* pcrel_offset */ |
252b5132 RH |
160 | |
161 | /* A 32 bit GP relative offset. This is just like REFLONG except | |
162 | that when the value is used the value of the gp register will be | |
163 | added in. */ | |
164 | HOWTO (ALPHA_R_GPREL32, /* type */ | |
165 | 0, /* rightshift */ | |
c94cb026 | 166 | 4, /* size */ |
252b5132 | 167 | 32, /* bitsize */ |
0a1b45a2 | 168 | false, /* pc_relative */ |
252b5132 RH |
169 | 0, /* bitpos */ |
170 | complain_overflow_bitfield, /* complain_on_overflow */ | |
171 | 0, /* special_function */ | |
172 | "GPREL32", /* name */ | |
0a1b45a2 | 173 | true, /* partial_inplace */ |
252b5132 RH |
174 | 0xffffffff, /* src_mask */ |
175 | 0xffffffff, /* dst_mask */ | |
0a1b45a2 | 176 | false), /* pcrel_offset */ |
252b5132 RH |
177 | |
178 | /* Used for an instruction that refers to memory off the GP | |
179 | register. The offset is 16 bits of the 32 bit instruction. This | |
180 | reloc always seems to be against the .lita section. */ | |
181 | HOWTO (ALPHA_R_LITERAL, /* type */ | |
182 | 0, /* rightshift */ | |
c94cb026 | 183 | 4, /* size */ |
252b5132 | 184 | 16, /* bitsize */ |
0a1b45a2 | 185 | false, /* pc_relative */ |
252b5132 RH |
186 | 0, /* bitpos */ |
187 | complain_overflow_signed, /* complain_on_overflow */ | |
188 | 0, /* special_function */ | |
189 | "LITERAL", /* name */ | |
0a1b45a2 | 190 | true, /* partial_inplace */ |
252b5132 RH |
191 | 0xffff, /* src_mask */ |
192 | 0xffff, /* dst_mask */ | |
0a1b45a2 | 193 | false), /* pcrel_offset */ |
252b5132 RH |
194 | |
195 | /* This reloc only appears immediately following a LITERAL reloc. | |
196 | It identifies a use of the literal. It seems that the linker can | |
197 | use this to eliminate a portion of the .lita section. The symbol | |
198 | index is special: 1 means the literal address is in the base | |
199 | register of a memory format instruction; 2 means the literal | |
200 | address is in the byte offset register of a byte-manipulation | |
201 | instruction; 3 means the literal address is in the target | |
202 | register of a jsr instruction. This does not actually do any | |
203 | relocation. */ | |
204 | HOWTO (ALPHA_R_LITUSE, /* type */ | |
205 | 0, /* rightshift */ | |
c94cb026 | 206 | 4, /* size */ |
252b5132 | 207 | 32, /* bitsize */ |
0a1b45a2 | 208 | false, /* pc_relative */ |
252b5132 RH |
209 | 0, /* bitpos */ |
210 | complain_overflow_dont, /* complain_on_overflow */ | |
211 | reloc_nil, /* special_function */ | |
212 | "LITUSE", /* name */ | |
0a1b45a2 | 213 | false, /* partial_inplace */ |
252b5132 RH |
214 | 0, /* src_mask */ |
215 | 0, /* dst_mask */ | |
0a1b45a2 | 216 | false), /* pcrel_offset */ |
252b5132 RH |
217 | |
218 | /* Load the gp register. This is always used for a ldah instruction | |
219 | which loads the upper 16 bits of the gp register. The next reloc | |
220 | will be an IGNORE reloc which identifies the location of the lda | |
221 | instruction which loads the lower 16 bits. The symbol index of | |
222 | the GPDISP instruction appears to actually be the number of bytes | |
223 | between the ldah and lda instructions. This gives two different | |
224 | ways to determine where the lda instruction is; I don't know why | |
225 | both are used. The value to use for the relocation is the | |
226 | difference between the GP value and the current location; the | |
227 | load will always be done against a register holding the current | |
228 | address. */ | |
229 | HOWTO (ALPHA_R_GPDISP, /* type */ | |
230 | 16, /* rightshift */ | |
c94cb026 | 231 | 4, /* size */ |
252b5132 | 232 | 16, /* bitsize */ |
0a1b45a2 | 233 | true, /* pc_relative */ |
252b5132 RH |
234 | 0, /* bitpos */ |
235 | complain_overflow_dont, /* complain_on_overflow */ | |
236 | reloc_nil, /* special_function */ | |
237 | "GPDISP", /* name */ | |
0a1b45a2 | 238 | true, /* partial_inplace */ |
252b5132 RH |
239 | 0xffff, /* src_mask */ |
240 | 0xffff, /* dst_mask */ | |
0a1b45a2 | 241 | true), /* pcrel_offset */ |
252b5132 RH |
242 | |
243 | /* A 21 bit branch. The native assembler generates these for | |
244 | branches within the text segment, and also fills in the PC | |
245 | relative offset in the instruction. */ | |
246 | HOWTO (ALPHA_R_BRADDR, /* type */ | |
247 | 2, /* rightshift */ | |
c94cb026 | 248 | 4, /* size */ |
252b5132 | 249 | 21, /* bitsize */ |
0a1b45a2 | 250 | true, /* pc_relative */ |
252b5132 RH |
251 | 0, /* bitpos */ |
252 | complain_overflow_signed, /* complain_on_overflow */ | |
253 | 0, /* special_function */ | |
254 | "BRADDR", /* name */ | |
0a1b45a2 | 255 | true, /* partial_inplace */ |
252b5132 RH |
256 | 0x1fffff, /* src_mask */ |
257 | 0x1fffff, /* dst_mask */ | |
0a1b45a2 | 258 | false), /* pcrel_offset */ |
252b5132 RH |
259 | |
260 | /* A hint for a jump to a register. */ | |
261 | HOWTO (ALPHA_R_HINT, /* type */ | |
262 | 2, /* rightshift */ | |
c94cb026 | 263 | 4, /* size */ |
252b5132 | 264 | 14, /* bitsize */ |
0a1b45a2 | 265 | true, /* pc_relative */ |
252b5132 RH |
266 | 0, /* bitpos */ |
267 | complain_overflow_dont, /* complain_on_overflow */ | |
268 | 0, /* special_function */ | |
269 | "HINT", /* name */ | |
0a1b45a2 | 270 | true, /* partial_inplace */ |
252b5132 RH |
271 | 0x3fff, /* src_mask */ |
272 | 0x3fff, /* dst_mask */ | |
0a1b45a2 | 273 | false), /* pcrel_offset */ |
252b5132 RH |
274 | |
275 | /* 16 bit PC relative offset. */ | |
276 | HOWTO (ALPHA_R_SREL16, /* type */ | |
277 | 0, /* rightshift */ | |
c94cb026 | 278 | 2, /* size */ |
252b5132 | 279 | 16, /* bitsize */ |
0a1b45a2 | 280 | true, /* pc_relative */ |
252b5132 RH |
281 | 0, /* bitpos */ |
282 | complain_overflow_signed, /* complain_on_overflow */ | |
283 | 0, /* special_function */ | |
284 | "SREL16", /* name */ | |
0a1b45a2 | 285 | true, /* partial_inplace */ |
252b5132 RH |
286 | 0xffff, /* src_mask */ |
287 | 0xffff, /* dst_mask */ | |
0a1b45a2 | 288 | false), /* pcrel_offset */ |
252b5132 RH |
289 | |
290 | /* 32 bit PC relative offset. */ | |
291 | HOWTO (ALPHA_R_SREL32, /* type */ | |
292 | 0, /* rightshift */ | |
c94cb026 | 293 | 4, /* size */ |
252b5132 | 294 | 32, /* bitsize */ |
0a1b45a2 | 295 | true, /* pc_relative */ |
252b5132 RH |
296 | 0, /* bitpos */ |
297 | complain_overflow_signed, /* complain_on_overflow */ | |
298 | 0, /* special_function */ | |
299 | "SREL32", /* name */ | |
0a1b45a2 | 300 | true, /* partial_inplace */ |
252b5132 RH |
301 | 0xffffffff, /* src_mask */ |
302 | 0xffffffff, /* dst_mask */ | |
0a1b45a2 | 303 | false), /* pcrel_offset */ |
252b5132 RH |
304 | |
305 | /* A 64 bit PC relative offset. */ | |
306 | HOWTO (ALPHA_R_SREL64, /* type */ | |
307 | 0, /* rightshift */ | |
c94cb026 | 308 | 8, /* size */ |
252b5132 | 309 | 64, /* bitsize */ |
0a1b45a2 | 310 | true, /* pc_relative */ |
252b5132 RH |
311 | 0, /* bitpos */ |
312 | complain_overflow_signed, /* complain_on_overflow */ | |
313 | 0, /* special_function */ | |
314 | "SREL64", /* name */ | |
0a1b45a2 | 315 | true, /* partial_inplace */ |
252b5132 RH |
316 | MINUS_ONE, /* src_mask */ |
317 | MINUS_ONE, /* dst_mask */ | |
0a1b45a2 | 318 | false), /* pcrel_offset */ |
252b5132 RH |
319 | |
320 | /* Push a value on the reloc evaluation stack. */ | |
321 | HOWTO (ALPHA_R_OP_PUSH, /* type */ | |
322 | 0, /* rightshift */ | |
5d0feb98 | 323 | 0, /* size */ |
252b5132 | 324 | 0, /* bitsize */ |
0a1b45a2 | 325 | false, /* pc_relative */ |
252b5132 RH |
326 | 0, /* bitpos */ |
327 | complain_overflow_dont, /* complain_on_overflow */ | |
328 | 0, /* special_function */ | |
329 | "OP_PUSH", /* name */ | |
0a1b45a2 | 330 | false, /* partial_inplace */ |
252b5132 RH |
331 | 0, /* src_mask */ |
332 | 0, /* dst_mask */ | |
0a1b45a2 | 333 | false), /* pcrel_offset */ |
252b5132 RH |
334 | |
335 | /* Store the value from the stack at the given address. Store it in | |
336 | a bitfield of size r_size starting at bit position r_offset. */ | |
337 | HOWTO (ALPHA_R_OP_STORE, /* type */ | |
338 | 0, /* rightshift */ | |
c94cb026 | 339 | 8, /* size */ |
252b5132 | 340 | 64, /* bitsize */ |
0a1b45a2 | 341 | false, /* pc_relative */ |
252b5132 RH |
342 | 0, /* bitpos */ |
343 | complain_overflow_dont, /* complain_on_overflow */ | |
344 | 0, /* special_function */ | |
345 | "OP_STORE", /* name */ | |
0a1b45a2 | 346 | false, /* partial_inplace */ |
252b5132 RH |
347 | 0, /* src_mask */ |
348 | MINUS_ONE, /* dst_mask */ | |
0a1b45a2 | 349 | false), /* pcrel_offset */ |
252b5132 RH |
350 | |
351 | /* Subtract the reloc address from the value on the top of the | |
352 | relocation stack. */ | |
353 | HOWTO (ALPHA_R_OP_PSUB, /* type */ | |
354 | 0, /* rightshift */ | |
5d0feb98 | 355 | 0, /* size */ |
252b5132 | 356 | 0, /* bitsize */ |
0a1b45a2 | 357 | false, /* pc_relative */ |
252b5132 RH |
358 | 0, /* bitpos */ |
359 | complain_overflow_dont, /* complain_on_overflow */ | |
360 | 0, /* special_function */ | |
361 | "OP_PSUB", /* name */ | |
0a1b45a2 | 362 | false, /* partial_inplace */ |
252b5132 RH |
363 | 0, /* src_mask */ |
364 | 0, /* dst_mask */ | |
0a1b45a2 | 365 | false), /* pcrel_offset */ |
252b5132 RH |
366 | |
367 | /* Shift the value on the top of the relocation stack right by the | |
368 | given value. */ | |
369 | HOWTO (ALPHA_R_OP_PRSHIFT, /* type */ | |
370 | 0, /* rightshift */ | |
5d0feb98 | 371 | 0, /* size */ |
252b5132 | 372 | 0, /* bitsize */ |
0a1b45a2 | 373 | false, /* pc_relative */ |
252b5132 RH |
374 | 0, /* bitpos */ |
375 | complain_overflow_dont, /* complain_on_overflow */ | |
376 | 0, /* special_function */ | |
377 | "OP_PRSHIFT", /* name */ | |
0a1b45a2 | 378 | false, /* partial_inplace */ |
252b5132 RH |
379 | 0, /* src_mask */ |
380 | 0, /* dst_mask */ | |
0a1b45a2 | 381 | false), /* pcrel_offset */ |
252b5132 RH |
382 | |
383 | /* Adjust the GP value for a new range in the object file. */ | |
384 | HOWTO (ALPHA_R_GPVALUE, /* type */ | |
385 | 0, /* rightshift */ | |
5d0feb98 | 386 | 0, /* size */ |
252b5132 | 387 | 0, /* bitsize */ |
0a1b45a2 | 388 | false, /* pc_relative */ |
252b5132 RH |
389 | 0, /* bitpos */ |
390 | complain_overflow_dont, /* complain_on_overflow */ | |
391 | 0, /* special_function */ | |
392 | "GPVALUE", /* name */ | |
0a1b45a2 | 393 | false, /* partial_inplace */ |
252b5132 RH |
394 | 0, /* src_mask */ |
395 | 0, /* dst_mask */ | |
0a1b45a2 | 396 | false) /* pcrel_offset */ |
252b5132 RH |
397 | }; |
398 | \f | |
399 | /* Recognize an Alpha ECOFF file. */ | |
400 | ||
cb001c0d | 401 | static bfd_cleanup |
2c3fc389 | 402 | alpha_ecoff_object_p (bfd *abfd) |
252b5132 | 403 | { |
cb001c0d | 404 | bfd_cleanup ret; |
252b5132 RH |
405 | |
406 | ret = coff_object_p (abfd); | |
407 | ||
408 | if (ret != NULL) | |
409 | { | |
410 | asection *sec; | |
411 | ||
412 | /* Alpha ECOFF has a .pdata section. The lnnoptr field of the | |
413 | .pdata section is the number of entries it contains. Each | |
414 | entry takes up 8 bytes. The number of entries is required | |
415 | since the section is aligned to a 16 byte boundary. When we | |
416 | link .pdata sections together, we do not want to include the | |
417 | alignment bytes. We handle this on input by faking the size | |
418 | of the .pdata section to remove the unwanted alignment bytes. | |
419 | On output we will set the lnnoptr field and force the | |
420 | alignment. */ | |
421 | sec = bfd_get_section_by_name (abfd, _PDATA); | |
422 | if (sec != (asection *) NULL) | |
423 | { | |
424 | bfd_size_type size; | |
425 | ||
71780f45 | 426 | size = (bfd_size_type) sec->line_filepos * 8; |
eea6121a AM |
427 | BFD_ASSERT (size == sec->size |
428 | || size + 8 == sec->size); | |
fd361982 | 429 | if (!bfd_set_section_size (sec, size)) |
252b5132 RH |
430 | return NULL; |
431 | } | |
432 | } | |
433 | ||
434 | return ret; | |
435 | } | |
436 | ||
437 | /* See whether the magic number matches. */ | |
438 | ||
0a1b45a2 | 439 | static bool |
2c3fc389 NC |
440 | alpha_ecoff_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, |
441 | void * filehdr) | |
252b5132 RH |
442 | { |
443 | struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; | |
444 | ||
15ac1d4f | 445 | if (! ALPHA_ECOFF_BADMAG (*internal_f)) |
0a1b45a2 | 446 | return true; |
252b5132 | 447 | |
15ac1d4f | 448 | if (ALPHA_ECOFF_COMPRESSEDMAG (*internal_f)) |
4eca0228 | 449 | _bfd_error_handler |
59d08d6c AM |
450 | (_("%pB: cannot handle compressed Alpha binaries; " |
451 | "use compiler flags, or objZ, to generate uncompressed binaries"), | |
15ac1d4f NC |
452 | abfd); |
453 | ||
0a1b45a2 | 454 | return false; |
252b5132 RH |
455 | } |
456 | ||
457 | /* This is a hook called by coff_real_object_p to create any backend | |
458 | specific information. */ | |
459 | ||
2c3fc389 NC |
460 | static void * |
461 | alpha_ecoff_mkobject_hook (bfd *abfd, void * filehdr, void * aouthdr) | |
252b5132 | 462 | { |
2c3fc389 | 463 | void * ecoff; |
252b5132 RH |
464 | |
465 | ecoff = _bfd_ecoff_mkobject_hook (abfd, filehdr, aouthdr); | |
466 | ||
467 | if (ecoff != NULL) | |
468 | { | |
469 | struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; | |
470 | ||
471 | /* Set additional BFD flags according to the object type from the | |
472 | machine specific file header flags. */ | |
473 | switch (internal_f->f_flags & F_ALPHA_OBJECT_TYPE_MASK) | |
474 | { | |
475 | case F_ALPHA_SHARABLE: | |
476 | abfd->flags |= DYNAMIC; | |
477 | break; | |
478 | case F_ALPHA_CALL_SHARED: | |
479 | /* Always executable if using shared libraries as the run time | |
480 | loader might resolve undefined references. */ | |
481 | abfd->flags |= (DYNAMIC | EXEC_P); | |
482 | break; | |
483 | } | |
484 | } | |
485 | return ecoff; | |
486 | } | |
487 | \f | |
488 | /* Reloc handling. */ | |
489 | ||
490 | /* Swap a reloc in. */ | |
491 | ||
492 | static void | |
2c3fc389 NC |
493 | alpha_ecoff_swap_reloc_in (bfd *abfd, |
494 | void * ext_ptr, | |
495 | struct internal_reloc *intern) | |
252b5132 RH |
496 | { |
497 | const RELOC *ext = (RELOC *) ext_ptr; | |
498 | ||
dc810e39 AM |
499 | intern->r_vaddr = H_GET_64 (abfd, ext->r_vaddr); |
500 | intern->r_symndx = H_GET_32 (abfd, ext->r_symndx); | |
252b5132 RH |
501 | |
502 | BFD_ASSERT (bfd_header_little_endian (abfd)); | |
503 | ||
504 | intern->r_type = ((ext->r_bits[0] & RELOC_BITS0_TYPE_LITTLE) | |
505 | >> RELOC_BITS0_TYPE_SH_LITTLE); | |
506 | intern->r_extern = (ext->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0; | |
507 | intern->r_offset = ((ext->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE) | |
508 | >> RELOC_BITS1_OFFSET_SH_LITTLE); | |
509 | /* Ignored the reserved bits. */ | |
510 | intern->r_size = ((ext->r_bits[3] & RELOC_BITS3_SIZE_LITTLE) | |
511 | >> RELOC_BITS3_SIZE_SH_LITTLE); | |
512 | ||
513 | if (intern->r_type == ALPHA_R_LITUSE | |
514 | || intern->r_type == ALPHA_R_GPDISP) | |
515 | { | |
516 | /* Handle the LITUSE and GPDISP relocs specially. Its symndx | |
517 | value is not actually a symbol index, but is instead a | |
518 | special code. We put the code in the r_size field, and | |
519 | clobber the symndx. */ | |
520 | if (intern->r_size != 0) | |
521 | abort (); | |
522 | intern->r_size = intern->r_symndx; | |
523 | intern->r_symndx = RELOC_SECTION_NONE; | |
524 | } | |
525 | else if (intern->r_type == ALPHA_R_IGNORE) | |
526 | { | |
527 | /* The IGNORE reloc generally follows a GPDISP reloc, and is | |
528 | against the .lita section. The section is irrelevant. */ | |
529 | if (! intern->r_extern && | |
530 | intern->r_symndx == RELOC_SECTION_ABS) | |
531 | abort (); | |
532 | if (! intern->r_extern && intern->r_symndx == RELOC_SECTION_LITA) | |
533 | intern->r_symndx = RELOC_SECTION_ABS; | |
534 | } | |
535 | } | |
536 | ||
537 | /* Swap a reloc out. */ | |
538 | ||
539 | static void | |
2c3fc389 NC |
540 | alpha_ecoff_swap_reloc_out (bfd *abfd, |
541 | const struct internal_reloc *intern, | |
542 | void * dst) | |
252b5132 RH |
543 | { |
544 | RELOC *ext = (RELOC *) dst; | |
545 | long symndx; | |
546 | unsigned char size; | |
547 | ||
548 | /* Undo the hackery done in swap_reloc_in. */ | |
549 | if (intern->r_type == ALPHA_R_LITUSE | |
550 | || intern->r_type == ALPHA_R_GPDISP) | |
551 | { | |
552 | symndx = intern->r_size; | |
553 | size = 0; | |
554 | } | |
555 | else if (intern->r_type == ALPHA_R_IGNORE | |
556 | && ! intern->r_extern | |
557 | && intern->r_symndx == RELOC_SECTION_ABS) | |
558 | { | |
559 | symndx = RELOC_SECTION_LITA; | |
560 | size = intern->r_size; | |
561 | } | |
562 | else | |
563 | { | |
564 | symndx = intern->r_symndx; | |
565 | size = intern->r_size; | |
566 | } | |
567 | ||
15ac1d4f | 568 | /* XXX FIXME: The maximum symndx value used to be 14 but this |
bfaaa3c2 | 569 | fails with object files produced by DEC's C++ compiler. |
15ac1d4f | 570 | Where does the value 14 (or 15) come from anyway ? */ |
252b5132 | 571 | BFD_ASSERT (intern->r_extern |
15ac1d4f | 572 | || (intern->r_symndx >= 0 && intern->r_symndx <= 15)); |
252b5132 | 573 | |
dc810e39 AM |
574 | H_PUT_64 (abfd, intern->r_vaddr, ext->r_vaddr); |
575 | H_PUT_32 (abfd, symndx, ext->r_symndx); | |
252b5132 RH |
576 | |
577 | BFD_ASSERT (bfd_header_little_endian (abfd)); | |
578 | ||
579 | ext->r_bits[0] = ((intern->r_type << RELOC_BITS0_TYPE_SH_LITTLE) | |
580 | & RELOC_BITS0_TYPE_LITTLE); | |
581 | ext->r_bits[1] = ((intern->r_extern ? RELOC_BITS1_EXTERN_LITTLE : 0) | |
582 | | ((intern->r_offset << RELOC_BITS1_OFFSET_SH_LITTLE) | |
583 | & RELOC_BITS1_OFFSET_LITTLE)); | |
584 | ext->r_bits[2] = 0; | |
585 | ext->r_bits[3] = ((size << RELOC_BITS3_SIZE_SH_LITTLE) | |
586 | & RELOC_BITS3_SIZE_LITTLE); | |
587 | } | |
588 | ||
589 | /* Finish canonicalizing a reloc. Part of this is generic to all | |
590 | ECOFF targets, and that part is in ecoff.c. The rest is done in | |
591 | this backend routine. It must fill in the howto field. */ | |
592 | ||
593 | static void | |
2c3fc389 NC |
594 | alpha_adjust_reloc_in (bfd *abfd, |
595 | const struct internal_reloc *intern, | |
596 | arelent *rptr) | |
252b5132 RH |
597 | { |
598 | if (intern->r_type > ALPHA_R_GPVALUE) | |
0adc9281 | 599 | { |
695344c0 | 600 | /* xgettext:c-format */ |
0aa13fee AM |
601 | _bfd_error_handler (_("%pB: unsupported relocation type %#x"), |
602 | abfd, intern->r_type); | |
0adc9281 NC |
603 | bfd_set_error (bfd_error_bad_value); |
604 | rptr->addend = 0; | |
605 | rptr->howto = NULL; | |
606 | return; | |
607 | } | |
252b5132 RH |
608 | |
609 | switch (intern->r_type) | |
610 | { | |
611 | case ALPHA_R_BRADDR: | |
612 | case ALPHA_R_SREL16: | |
613 | case ALPHA_R_SREL32: | |
614 | case ALPHA_R_SREL64: | |
615 | /* This relocs appear to be fully resolved when they are against | |
07d6d2b8 AM |
616 | internal symbols. Against external symbols, BRADDR at least |
617 | appears to be resolved against the next instruction. */ | |
252b5132 RH |
618 | if (! intern->r_extern) |
619 | rptr->addend = 0; | |
620 | else | |
621 | rptr->addend = - (intern->r_vaddr + 4); | |
622 | break; | |
623 | ||
624 | case ALPHA_R_GPREL32: | |
625 | case ALPHA_R_LITERAL: | |
626 | /* Copy the gp value for this object file into the addend, to | |
627 | ensure that we are not confused by the linker. */ | |
628 | if (! intern->r_extern) | |
629 | rptr->addend += ecoff_data (abfd)->gp; | |
630 | break; | |
631 | ||
632 | case ALPHA_R_LITUSE: | |
633 | case ALPHA_R_GPDISP: | |
634 | /* The LITUSE and GPDISP relocs do not use a symbol, or an | |
635 | addend, but they do use a special code. Put this code in the | |
636 | addend field. */ | |
637 | rptr->addend = intern->r_size; | |
638 | break; | |
639 | ||
640 | case ALPHA_R_OP_STORE: | |
641 | /* The STORE reloc needs the size and offset fields. We store | |
642 | them in the addend. */ | |
ca724bf2 | 643 | BFD_ASSERT (intern->r_offset <= 256); |
252b5132 RH |
644 | rptr->addend = (intern->r_offset << 8) + intern->r_size; |
645 | break; | |
646 | ||
647 | case ALPHA_R_OP_PUSH: | |
648 | case ALPHA_R_OP_PSUB: | |
649 | case ALPHA_R_OP_PRSHIFT: | |
650 | /* The PUSH, PSUB and PRSHIFT relocs do not actually use an | |
651 | address. I believe that the address supplied is really an | |
652 | addend. */ | |
653 | rptr->addend = intern->r_vaddr; | |
654 | break; | |
655 | ||
656 | case ALPHA_R_GPVALUE: | |
657 | /* Set the addend field to the new GP value. */ | |
658 | rptr->addend = intern->r_symndx + ecoff_data (abfd)->gp; | |
659 | break; | |
660 | ||
661 | case ALPHA_R_IGNORE: | |
662 | /* If the type is ALPHA_R_IGNORE, make sure this is a reference | |
663 | to the absolute section so that the reloc is ignored. For | |
664 | some reason the address of this reloc type is not adjusted by | |
665 | the section vma. We record the gp value for this object file | |
666 | here, for convenience when doing the GPDISP relocation. */ | |
667 | rptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; | |
668 | rptr->address = intern->r_vaddr; | |
669 | rptr->addend = ecoff_data (abfd)->gp; | |
670 | break; | |
671 | ||
672 | default: | |
673 | break; | |
674 | } | |
675 | ||
676 | rptr->howto = &alpha_howto_table[intern->r_type]; | |
677 | } | |
678 | ||
679 | /* When writing out a reloc we need to pull some values back out of | |
680 | the addend field into the reloc. This is roughly the reverse of | |
681 | alpha_adjust_reloc_in, except that there are several changes we do | |
682 | not need to undo. */ | |
683 | ||
684 | static void | |
2c3fc389 NC |
685 | alpha_adjust_reloc_out (bfd *abfd ATTRIBUTE_UNUSED, |
686 | const arelent *rel, | |
687 | struct internal_reloc *intern) | |
252b5132 RH |
688 | { |
689 | switch (intern->r_type) | |
690 | { | |
691 | case ALPHA_R_LITUSE: | |
692 | case ALPHA_R_GPDISP: | |
693 | intern->r_size = rel->addend; | |
694 | break; | |
695 | ||
696 | case ALPHA_R_OP_STORE: | |
697 | intern->r_size = rel->addend & 0xff; | |
698 | intern->r_offset = (rel->addend >> 8) & 0xff; | |
699 | break; | |
700 | ||
701 | case ALPHA_R_OP_PUSH: | |
702 | case ALPHA_R_OP_PSUB: | |
703 | case ALPHA_R_OP_PRSHIFT: | |
704 | intern->r_vaddr = rel->addend; | |
705 | break; | |
706 | ||
707 | case ALPHA_R_IGNORE: | |
708 | intern->r_vaddr = rel->address; | |
709 | break; | |
710 | ||
711 | default: | |
712 | break; | |
713 | } | |
714 | } | |
715 | ||
716 | /* The size of the stack for the relocation evaluator. */ | |
717 | #define RELOC_STACKSIZE (10) | |
718 | ||
719 | /* Alpha ECOFF relocs have a built in expression evaluator as well as | |
720 | other interdependencies. Rather than use a bunch of special | |
721 | functions and global variables, we use a single routine to do all | |
722 | the relocation for a section. I haven't yet worked out how the | |
723 | assembler is going to handle this. */ | |
724 | ||
725 | static bfd_byte * | |
2c3fc389 NC |
726 | alpha_ecoff_get_relocated_section_contents (bfd *abfd, |
727 | struct bfd_link_info *link_info, | |
728 | struct bfd_link_order *link_order, | |
729 | bfd_byte *data, | |
0a1b45a2 | 730 | bool relocatable, |
2c3fc389 | 731 | asymbol **symbols) |
252b5132 RH |
732 | { |
733 | bfd *input_bfd = link_order->u.indirect.section->owner; | |
734 | asection *input_section = link_order->u.indirect.section; | |
8b78cbec AM |
735 | long reloc_size; |
736 | arelent **reloc_vector; | |
252b5132 | 737 | long reloc_count; |
1049f94e | 738 | bfd *output_bfd = relocatable ? abfd : (bfd *) NULL; |
252b5132 | 739 | bfd_vma gp; |
0a1b45a2 | 740 | bool gp_undefined; |
252b5132 RH |
741 | bfd_vma stack[RELOC_STACKSIZE]; |
742 | int tos = 0; | |
743 | ||
8b78cbec | 744 | reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section); |
252b5132 | 745 | if (reloc_size < 0) |
8b78cbec | 746 | return NULL; |
252b5132 | 747 | |
56ba7527 | 748 | bfd_byte *orig_data = data; |
8b78cbec AM |
749 | if (!bfd_get_full_section_contents (input_bfd, input_section, &data)) |
750 | return NULL; | |
751 | ||
752 | if (data == NULL) | |
753 | return NULL; | |
754 | ||
755 | if (reloc_size == 0) | |
756 | return data; | |
757 | ||
758 | reloc_vector = (arelent **) bfd_malloc (reloc_size); | |
759 | if (reloc_vector == NULL) | |
56ba7527 | 760 | goto error_return; |
252b5132 | 761 | |
252b5132 RH |
762 | reloc_count = bfd_canonicalize_reloc (input_bfd, input_section, |
763 | reloc_vector, symbols); | |
764 | if (reloc_count < 0) | |
765 | goto error_return; | |
766 | if (reloc_count == 0) | |
767 | goto successful_return; | |
768 | ||
769 | /* Get the GP value for the output BFD. */ | |
0a1b45a2 | 770 | gp_undefined = false; |
252b5132 RH |
771 | gp = _bfd_get_gp_value (abfd); |
772 | if (gp == 0) | |
773 | { | |
1049f94e | 774 | if (relocatable) |
252b5132 RH |
775 | { |
776 | asection *sec; | |
777 | bfd_vma lo; | |
778 | ||
779 | /* Make up a value. */ | |
780 | lo = (bfd_vma) -1; | |
781 | for (sec = abfd->sections; sec != NULL; sec = sec->next) | |
782 | { | |
783 | if (sec->vma < lo | |
784 | && (strcmp (sec->name, ".sbss") == 0 | |
785 | || strcmp (sec->name, ".sdata") == 0 | |
786 | || strcmp (sec->name, ".lit4") == 0 | |
787 | || strcmp (sec->name, ".lit8") == 0 | |
788 | || strcmp (sec->name, ".lita") == 0)) | |
789 | lo = sec->vma; | |
790 | } | |
791 | gp = lo + 0x8000; | |
792 | _bfd_set_gp_value (abfd, gp); | |
793 | } | |
794 | else | |
795 | { | |
796 | struct bfd_link_hash_entry *h; | |
797 | ||
0a1b45a2 AM |
798 | h = bfd_link_hash_lookup (link_info->hash, "_gp", false, false, |
799 | true); | |
252b5132 RH |
800 | if (h == (struct bfd_link_hash_entry *) NULL |
801 | || h->type != bfd_link_hash_defined) | |
0a1b45a2 | 802 | gp_undefined = true; |
252b5132 RH |
803 | else |
804 | { | |
805 | gp = (h->u.def.value | |
806 | + h->u.def.section->output_section->vma | |
807 | + h->u.def.section->output_offset); | |
808 | _bfd_set_gp_value (abfd, gp); | |
809 | } | |
810 | } | |
811 | } | |
812 | ||
813 | for (; *reloc_vector != (arelent *) NULL; reloc_vector++) | |
814 | { | |
815 | arelent *rel; | |
816 | bfd_reloc_status_type r; | |
817 | char *err; | |
818 | ||
819 | rel = *reloc_vector; | |
820 | r = bfd_reloc_ok; | |
821 | switch (rel->howto->type) | |
822 | { | |
823 | case ALPHA_R_IGNORE: | |
824 | rel->address += input_section->output_offset; | |
825 | break; | |
826 | ||
827 | case ALPHA_R_REFLONG: | |
828 | case ALPHA_R_REFQUAD: | |
829 | case ALPHA_R_BRADDR: | |
830 | case ALPHA_R_HINT: | |
831 | case ALPHA_R_SREL16: | |
832 | case ALPHA_R_SREL32: | |
833 | case ALPHA_R_SREL64: | |
1049f94e | 834 | if (relocatable |
252b5132 RH |
835 | && ((*rel->sym_ptr_ptr)->flags & BSF_SECTION_SYM) == 0) |
836 | { | |
837 | rel->address += input_section->output_offset; | |
838 | break; | |
839 | } | |
840 | r = bfd_perform_relocation (input_bfd, rel, data, input_section, | |
841 | output_bfd, &err); | |
842 | break; | |
843 | ||
844 | case ALPHA_R_GPREL32: | |
845 | /* This relocation is used in a switch table. It is a 32 | |
846 | bit offset from the current GP value. We must adjust it | |
847 | by the different between the original GP value and the | |
848 | current GP value. The original GP value is stored in the | |
849 | addend. We adjust the addend and let | |
850 | bfd_perform_relocation finish the job. */ | |
851 | rel->addend -= gp; | |
852 | r = bfd_perform_relocation (input_bfd, rel, data, input_section, | |
853 | output_bfd, &err); | |
854 | if (r == bfd_reloc_ok && gp_undefined) | |
855 | { | |
856 | r = bfd_reloc_dangerous; | |
857 | err = (char *) _("GP relative relocation used when GP not defined"); | |
858 | } | |
859 | break; | |
860 | ||
861 | case ALPHA_R_LITERAL: | |
862 | /* This is a reference to a literal value, generally | |
863 | (always?) in the .lita section. This is a 16 bit GP | |
864 | relative relocation. Sometimes the subsequent reloc is a | |
865 | LITUSE reloc, which indicates how this reloc is used. | |
866 | This sometimes permits rewriting the two instructions | |
867 | referred to by the LITERAL and the LITUSE into different | |
868 | instructions which do not refer to .lita. This can save | |
869 | a memory reference, and permits removing a value from | |
870 | .lita thus saving GP relative space. | |
871 | ||
872 | We do not these optimizations. To do them we would need | |
873 | to arrange to link the .lita section first, so that by | |
874 | the time we got here we would know the final values to | |
875 | use. This would not be particularly difficult, but it is | |
876 | not currently implemented. */ | |
877 | ||
878 | { | |
879 | unsigned long insn; | |
880 | ||
881 | /* I believe that the LITERAL reloc will only apply to a | |
882 | ldq or ldl instruction, so check my assumption. */ | |
883 | insn = bfd_get_32 (input_bfd, data + rel->address); | |
884 | BFD_ASSERT (((insn >> 26) & 0x3f) == 0x29 | |
885 | || ((insn >> 26) & 0x3f) == 0x28); | |
886 | ||
887 | rel->addend -= gp; | |
888 | r = bfd_perform_relocation (input_bfd, rel, data, input_section, | |
889 | output_bfd, &err); | |
890 | if (r == bfd_reloc_ok && gp_undefined) | |
891 | { | |
892 | r = bfd_reloc_dangerous; | |
893 | err = | |
894 | (char *) _("GP relative relocation used when GP not defined"); | |
895 | } | |
896 | } | |
897 | break; | |
898 | ||
899 | case ALPHA_R_LITUSE: | |
900 | /* See ALPHA_R_LITERAL above for the uses of this reloc. It | |
901 | does not cause anything to happen, itself. */ | |
902 | rel->address += input_section->output_offset; | |
903 | break; | |
346ceb11 | 904 | |
252b5132 RH |
905 | case ALPHA_R_GPDISP: |
906 | /* This marks the ldah of an ldah/lda pair which loads the | |
907 | gp register with the difference of the gp value and the | |
908 | current location. The second of the pair is r_size bytes | |
909 | ahead; it used to be marked with an ALPHA_R_IGNORE reloc, | |
910 | but that no longer happens in OSF/1 3.2. */ | |
911 | { | |
912 | unsigned long insn1, insn2; | |
913 | bfd_vma addend; | |
914 | ||
915 | /* Get the two instructions. */ | |
916 | insn1 = bfd_get_32 (input_bfd, data + rel->address); | |
917 | insn2 = bfd_get_32 (input_bfd, data + rel->address + rel->addend); | |
918 | ||
919 | BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */ | |
920 | BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */ | |
921 | ||
922 | /* Get the existing addend. We must account for the sign | |
923 | extension done by lda and ldah. */ | |
924 | addend = ((insn1 & 0xffff) << 16) + (insn2 & 0xffff); | |
925 | if (insn1 & 0x8000) | |
926 | { | |
927 | addend -= 0x80000000; | |
928 | addend -= 0x80000000; | |
929 | } | |
930 | if (insn2 & 0x8000) | |
931 | addend -= 0x10000; | |
932 | ||
933 | /* The existing addend includes the different between the | |
934 | gp of the input BFD and the address in the input BFD. | |
935 | Subtract this out. */ | |
936 | addend -= (ecoff_data (input_bfd)->gp | |
937 | - (input_section->vma + rel->address)); | |
938 | ||
939 | /* Now add in the final gp value, and subtract out the | |
940 | final address. */ | |
941 | addend += (gp | |
942 | - (input_section->output_section->vma | |
943 | + input_section->output_offset | |
944 | + rel->address)); | |
945 | ||
946 | /* Change the instructions, accounting for the sign | |
947 | extension, and write them out. */ | |
948 | if (addend & 0x8000) | |
949 | addend += 0x10000; | |
950 | insn1 = (insn1 & 0xffff0000) | ((addend >> 16) & 0xffff); | |
951 | insn2 = (insn2 & 0xffff0000) | (addend & 0xffff); | |
952 | ||
953 | bfd_put_32 (input_bfd, (bfd_vma) insn1, data + rel->address); | |
954 | bfd_put_32 (input_bfd, (bfd_vma) insn2, | |
955 | data + rel->address + rel->addend); | |
956 | ||
957 | rel->address += input_section->output_offset; | |
958 | } | |
959 | break; | |
346ceb11 | 960 | |
252b5132 RH |
961 | case ALPHA_R_OP_PUSH: |
962 | /* Push a value on the reloc evaluation stack. */ | |
963 | { | |
964 | asymbol *symbol; | |
965 | bfd_vma relocation; | |
966 | ||
1049f94e | 967 | if (relocatable) |
252b5132 RH |
968 | { |
969 | rel->address += input_section->output_offset; | |
970 | break; | |
971 | } | |
972 | ||
973 | /* Figure out the relocation of this symbol. */ | |
974 | symbol = *rel->sym_ptr_ptr; | |
975 | ||
976 | if (bfd_is_und_section (symbol->section)) | |
977 | r = bfd_reloc_undefined; | |
978 | ||
979 | if (bfd_is_com_section (symbol->section)) | |
980 | relocation = 0; | |
981 | else | |
982 | relocation = symbol->value; | |
983 | relocation += symbol->section->output_section->vma; | |
984 | relocation += symbol->section->output_offset; | |
985 | relocation += rel->addend; | |
986 | ||
987 | if (tos >= RELOC_STACKSIZE) | |
988 | abort (); | |
989 | ||
990 | stack[tos++] = relocation; | |
991 | } | |
992 | break; | |
993 | ||
994 | case ALPHA_R_OP_STORE: | |
995 | /* Store a value from the reloc stack into a bitfield. */ | |
996 | { | |
997 | bfd_vma val; | |
998 | int offset, size; | |
999 | ||
1049f94e | 1000 | if (relocatable) |
252b5132 RH |
1001 | { |
1002 | rel->address += input_section->output_offset; | |
1003 | break; | |
1004 | } | |
1005 | ||
1006 | if (tos == 0) | |
1007 | abort (); | |
1008 | ||
1009 | /* The offset and size for this reloc are encoded into the | |
1010 | addend field by alpha_adjust_reloc_in. */ | |
1011 | offset = (rel->addend >> 8) & 0xff; | |
1012 | size = rel->addend & 0xff; | |
1013 | ||
1014 | val = bfd_get_64 (abfd, data + rel->address); | |
1015 | val &=~ (((1 << size) - 1) << offset); | |
1016 | val |= (stack[--tos] & ((1 << size) - 1)) << offset; | |
1017 | bfd_put_64 (abfd, val, data + rel->address); | |
1018 | } | |
1019 | break; | |
1020 | ||
1021 | case ALPHA_R_OP_PSUB: | |
1022 | /* Subtract a value from the top of the stack. */ | |
1023 | { | |
1024 | asymbol *symbol; | |
1025 | bfd_vma relocation; | |
1026 | ||
1049f94e | 1027 | if (relocatable) |
252b5132 RH |
1028 | { |
1029 | rel->address += input_section->output_offset; | |
1030 | break; | |
1031 | } | |
1032 | ||
1033 | /* Figure out the relocation of this symbol. */ | |
1034 | symbol = *rel->sym_ptr_ptr; | |
1035 | ||
1036 | if (bfd_is_und_section (symbol->section)) | |
1037 | r = bfd_reloc_undefined; | |
1038 | ||
1039 | if (bfd_is_com_section (symbol->section)) | |
1040 | relocation = 0; | |
1041 | else | |
1042 | relocation = symbol->value; | |
1043 | relocation += symbol->section->output_section->vma; | |
1044 | relocation += symbol->section->output_offset; | |
1045 | relocation += rel->addend; | |
1046 | ||
1047 | if (tos == 0) | |
1048 | abort (); | |
1049 | ||
1050 | stack[tos - 1] -= relocation; | |
1051 | } | |
1052 | break; | |
1053 | ||
1054 | case ALPHA_R_OP_PRSHIFT: | |
1055 | /* Shift the value on the top of the stack. */ | |
1056 | { | |
1057 | asymbol *symbol; | |
1058 | bfd_vma relocation; | |
1059 | ||
1049f94e | 1060 | if (relocatable) |
252b5132 RH |
1061 | { |
1062 | rel->address += input_section->output_offset; | |
1063 | break; | |
1064 | } | |
1065 | ||
1066 | /* Figure out the relocation of this symbol. */ | |
1067 | symbol = *rel->sym_ptr_ptr; | |
1068 | ||
1069 | if (bfd_is_und_section (symbol->section)) | |
1070 | r = bfd_reloc_undefined; | |
1071 | ||
1072 | if (bfd_is_com_section (symbol->section)) | |
1073 | relocation = 0; | |
1074 | else | |
1075 | relocation = symbol->value; | |
1076 | relocation += symbol->section->output_section->vma; | |
1077 | relocation += symbol->section->output_offset; | |
1078 | relocation += rel->addend; | |
1079 | ||
1080 | if (tos == 0) | |
1081 | abort (); | |
1082 | ||
1083 | stack[tos - 1] >>= relocation; | |
1084 | } | |
1085 | break; | |
346ceb11 | 1086 | |
252b5132 RH |
1087 | case ALPHA_R_GPVALUE: |
1088 | /* I really don't know if this does the right thing. */ | |
1089 | gp = rel->addend; | |
0a1b45a2 | 1090 | gp_undefined = false; |
252b5132 RH |
1091 | break; |
1092 | ||
1093 | default: | |
1094 | abort (); | |
1095 | } | |
1096 | ||
1049f94e | 1097 | if (relocatable) |
252b5132 RH |
1098 | { |
1099 | asection *os = input_section->output_section; | |
1100 | ||
1101 | /* A partial link, so keep the relocs. */ | |
1102 | os->orelocation[os->reloc_count] = rel; | |
1103 | os->reloc_count++; | |
1104 | } | |
1105 | ||
346ceb11 | 1106 | if (r != bfd_reloc_ok) |
252b5132 RH |
1107 | { |
1108 | switch (r) | |
1109 | { | |
1110 | case bfd_reloc_undefined: | |
1a72702b AM |
1111 | (*link_info->callbacks->undefined_symbol) |
1112 | (link_info, bfd_asymbol_name (*rel->sym_ptr_ptr), | |
0a1b45a2 | 1113 | input_bfd, input_section, rel->address, true); |
252b5132 | 1114 | break; |
346ceb11 | 1115 | case bfd_reloc_dangerous: |
1a72702b AM |
1116 | (*link_info->callbacks->reloc_dangerous) |
1117 | (link_info, err, input_bfd, input_section, rel->address); | |
252b5132 RH |
1118 | break; |
1119 | case bfd_reloc_overflow: | |
1a72702b AM |
1120 | (*link_info->callbacks->reloc_overflow) |
1121 | (link_info, NULL, bfd_asymbol_name (*rel->sym_ptr_ptr), | |
1122 | rel->howto->name, rel->addend, input_bfd, | |
1123 | input_section, rel->address); | |
252b5132 RH |
1124 | break; |
1125 | case bfd_reloc_outofrange: | |
1126 | default: | |
1127 | abort (); | |
1128 | break; | |
1129 | } | |
1130 | } | |
1131 | } | |
1132 | ||
1133 | if (tos != 0) | |
1134 | abort (); | |
1135 | ||
1136 | successful_return: | |
c9594989 | 1137 | free (reloc_vector); |
252b5132 RH |
1138 | return data; |
1139 | ||
1140 | error_return: | |
c9594989 | 1141 | free (reloc_vector); |
56ba7527 AM |
1142 | if (orig_data == NULL) |
1143 | free (data); | |
252b5132 RH |
1144 | return NULL; |
1145 | } | |
1146 | ||
1147 | /* Get the howto structure for a generic reloc type. */ | |
1148 | ||
1149 | static reloc_howto_type * | |
2c3fc389 NC |
1150 | alpha_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
1151 | bfd_reloc_code_real_type code) | |
252b5132 RH |
1152 | { |
1153 | int alpha_type; | |
1154 | ||
1155 | switch (code) | |
1156 | { | |
1157 | case BFD_RELOC_32: | |
1158 | alpha_type = ALPHA_R_REFLONG; | |
1159 | break; | |
1160 | case BFD_RELOC_64: | |
1161 | case BFD_RELOC_CTOR: | |
1162 | alpha_type = ALPHA_R_REFQUAD; | |
1163 | break; | |
1164 | case BFD_RELOC_GPREL32: | |
1165 | alpha_type = ALPHA_R_GPREL32; | |
1166 | break; | |
1167 | case BFD_RELOC_ALPHA_LITERAL: | |
1168 | alpha_type = ALPHA_R_LITERAL; | |
1169 | break; | |
1170 | case BFD_RELOC_ALPHA_LITUSE: | |
1171 | alpha_type = ALPHA_R_LITUSE; | |
1172 | break; | |
1173 | case BFD_RELOC_ALPHA_GPDISP_HI16: | |
1174 | alpha_type = ALPHA_R_GPDISP; | |
1175 | break; | |
1176 | case BFD_RELOC_ALPHA_GPDISP_LO16: | |
1177 | alpha_type = ALPHA_R_IGNORE; | |
1178 | break; | |
1179 | case BFD_RELOC_23_PCREL_S2: | |
1180 | alpha_type = ALPHA_R_BRADDR; | |
1181 | break; | |
1182 | case BFD_RELOC_ALPHA_HINT: | |
1183 | alpha_type = ALPHA_R_HINT; | |
1184 | break; | |
1185 | case BFD_RELOC_16_PCREL: | |
1186 | alpha_type = ALPHA_R_SREL16; | |
1187 | break; | |
1188 | case BFD_RELOC_32_PCREL: | |
1189 | alpha_type = ALPHA_R_SREL32; | |
1190 | break; | |
1191 | case BFD_RELOC_64_PCREL: | |
1192 | alpha_type = ALPHA_R_SREL64; | |
1193 | break; | |
252b5132 RH |
1194 | default: |
1195 | return (reloc_howto_type *) NULL; | |
1196 | } | |
1197 | ||
1198 | return &alpha_howto_table[alpha_type]; | |
1199 | } | |
157090f7 AM |
1200 | |
1201 | static reloc_howto_type * | |
1202 | alpha_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
1203 | const char *r_name) | |
1204 | { | |
1205 | unsigned int i; | |
1206 | ||
1207 | for (i = 0; | |
1208 | i < sizeof (alpha_howto_table) / sizeof (alpha_howto_table[0]); | |
1209 | i++) | |
1210 | if (alpha_howto_table[i].name != NULL | |
1211 | && strcasecmp (alpha_howto_table[i].name, r_name) == 0) | |
1212 | return &alpha_howto_table[i]; | |
1213 | ||
1214 | return NULL; | |
1215 | } | |
252b5132 RH |
1216 | \f |
1217 | /* A helper routine for alpha_relocate_section which converts an | |
1049f94e | 1218 | external reloc when generating relocatable output. Returns the |
252b5132 RH |
1219 | relocation amount. */ |
1220 | ||
1221 | static bfd_vma | |
2c3fc389 NC |
1222 | alpha_convert_external_reloc (bfd *output_bfd ATTRIBUTE_UNUSED, |
1223 | struct bfd_link_info *info, | |
1224 | bfd *input_bfd, | |
1225 | struct external_reloc *ext_rel, | |
1226 | struct ecoff_link_hash_entry *h) | |
252b5132 RH |
1227 | { |
1228 | unsigned long r_symndx; | |
1229 | bfd_vma relocation; | |
1230 | ||
0e1862bb | 1231 | BFD_ASSERT (bfd_link_relocatable (info)); |
252b5132 RH |
1232 | |
1233 | if (h->root.type == bfd_link_hash_defined | |
1234 | || h->root.type == bfd_link_hash_defweak) | |
1235 | { | |
1236 | asection *hsec; | |
1237 | const char *name; | |
1238 | ||
1239 | /* This symbol is defined in the output. Convert the reloc from | |
1240 | being against the symbol to being against the section. */ | |
1241 | ||
1242 | /* Clear the r_extern bit. */ | |
1243 | ext_rel->r_bits[1] &=~ RELOC_BITS1_EXTERN_LITTLE; | |
1244 | ||
1245 | /* Compute a new r_symndx value. */ | |
1246 | hsec = h->root.u.def.section; | |
fd361982 | 1247 | name = bfd_section_name (hsec->output_section); |
252b5132 | 1248 | |
dc810e39 | 1249 | r_symndx = (unsigned long) -1; |
252b5132 RH |
1250 | switch (name[1]) |
1251 | { | |
1252 | case 'A': | |
1253 | if (strcmp (name, "*ABS*") == 0) | |
1254 | r_symndx = RELOC_SECTION_ABS; | |
1255 | break; | |
1256 | case 'b': | |
1257 | if (strcmp (name, ".bss") == 0) | |
1258 | r_symndx = RELOC_SECTION_BSS; | |
1259 | break; | |
1260 | case 'd': | |
1261 | if (strcmp (name, ".data") == 0) | |
1262 | r_symndx = RELOC_SECTION_DATA; | |
1263 | break; | |
1264 | case 'f': | |
1265 | if (strcmp (name, ".fini") == 0) | |
1266 | r_symndx = RELOC_SECTION_FINI; | |
1267 | break; | |
1268 | case 'i': | |
1269 | if (strcmp (name, ".init") == 0) | |
1270 | r_symndx = RELOC_SECTION_INIT; | |
1271 | break; | |
1272 | case 'l': | |
1273 | if (strcmp (name, ".lita") == 0) | |
1274 | r_symndx = RELOC_SECTION_LITA; | |
1275 | else if (strcmp (name, ".lit8") == 0) | |
1276 | r_symndx = RELOC_SECTION_LIT8; | |
1277 | else if (strcmp (name, ".lit4") == 0) | |
1278 | r_symndx = RELOC_SECTION_LIT4; | |
1279 | break; | |
1280 | case 'p': | |
1281 | if (strcmp (name, ".pdata") == 0) | |
1282 | r_symndx = RELOC_SECTION_PDATA; | |
1283 | break; | |
1284 | case 'r': | |
1285 | if (strcmp (name, ".rdata") == 0) | |
1286 | r_symndx = RELOC_SECTION_RDATA; | |
1287 | else if (strcmp (name, ".rconst") == 0) | |
1288 | r_symndx = RELOC_SECTION_RCONST; | |
1289 | break; | |
1290 | case 's': | |
1291 | if (strcmp (name, ".sdata") == 0) | |
1292 | r_symndx = RELOC_SECTION_SDATA; | |
1293 | else if (strcmp (name, ".sbss") == 0) | |
1294 | r_symndx = RELOC_SECTION_SBSS; | |
1295 | break; | |
1296 | case 't': | |
1297 | if (strcmp (name, ".text") == 0) | |
1298 | r_symndx = RELOC_SECTION_TEXT; | |
1299 | break; | |
1300 | case 'x': | |
1301 | if (strcmp (name, ".xdata") == 0) | |
1302 | r_symndx = RELOC_SECTION_XDATA; | |
1303 | break; | |
1304 | } | |
346ceb11 | 1305 | |
cea4409c | 1306 | if (r_symndx == (unsigned long) -1) |
252b5132 RH |
1307 | abort (); |
1308 | ||
1309 | /* Add the section VMA and the symbol value. */ | |
1310 | relocation = (h->root.u.def.value | |
1311 | + hsec->output_section->vma | |
1312 | + hsec->output_offset); | |
1313 | } | |
1314 | else | |
1315 | { | |
1316 | /* Change the symndx value to the right one for | |
1317 | the output BFD. */ | |
1318 | r_symndx = h->indx; | |
cea4409c | 1319 | if (r_symndx == (unsigned long) -1) |
252b5132 RH |
1320 | { |
1321 | /* Caller must give an error. */ | |
1322 | r_symndx = 0; | |
1323 | } | |
1324 | relocation = 0; | |
1325 | } | |
1326 | ||
1327 | /* Write out the new r_symndx value. */ | |
dc810e39 | 1328 | H_PUT_32 (input_bfd, r_symndx, ext_rel->r_symndx); |
252b5132 RH |
1329 | |
1330 | return relocation; | |
1331 | } | |
1332 | ||
1333 | /* Relocate a section while linking an Alpha ECOFF file. This is | |
1334 | quite similar to get_relocated_section_contents. Perhaps they | |
1335 | could be combined somehow. */ | |
1336 | ||
0a1b45a2 | 1337 | static bool |
2c3fc389 NC |
1338 | alpha_relocate_section (bfd *output_bfd, |
1339 | struct bfd_link_info *info, | |
1340 | bfd *input_bfd, | |
1341 | asection *input_section, | |
1342 | bfd_byte *contents, | |
1343 | void * external_relocs) | |
252b5132 RH |
1344 | { |
1345 | asection **symndx_to_section, *lita_sec; | |
1346 | struct ecoff_link_hash_entry **sym_hashes; | |
1347 | bfd_vma gp; | |
0a1b45a2 | 1348 | bool gp_undefined; |
252b5132 RH |
1349 | bfd_vma stack[RELOC_STACKSIZE]; |
1350 | int tos = 0; | |
1351 | struct external_reloc *ext_rel; | |
1352 | struct external_reloc *ext_rel_end; | |
dc810e39 | 1353 | bfd_size_type amt; |
252b5132 RH |
1354 | |
1355 | /* We keep a table mapping the symndx found in an internal reloc to | |
1356 | the appropriate section. This is faster than looking up the | |
1357 | section by name each time. */ | |
1358 | symndx_to_section = ecoff_data (input_bfd)->symndx_to_section; | |
1359 | if (symndx_to_section == (asection **) NULL) | |
1360 | { | |
dc810e39 AM |
1361 | amt = NUM_RELOC_SECTIONS * sizeof (asection *); |
1362 | symndx_to_section = (asection **) bfd_alloc (input_bfd, amt); | |
252b5132 | 1363 | if (!symndx_to_section) |
0a1b45a2 | 1364 | return false; |
252b5132 RH |
1365 | |
1366 | symndx_to_section[RELOC_SECTION_NONE] = NULL; | |
1367 | symndx_to_section[RELOC_SECTION_TEXT] = | |
1368 | bfd_get_section_by_name (input_bfd, ".text"); | |
1369 | symndx_to_section[RELOC_SECTION_RDATA] = | |
1370 | bfd_get_section_by_name (input_bfd, ".rdata"); | |
1371 | symndx_to_section[RELOC_SECTION_DATA] = | |
1372 | bfd_get_section_by_name (input_bfd, ".data"); | |
1373 | symndx_to_section[RELOC_SECTION_SDATA] = | |
1374 | bfd_get_section_by_name (input_bfd, ".sdata"); | |
1375 | symndx_to_section[RELOC_SECTION_SBSS] = | |
1376 | bfd_get_section_by_name (input_bfd, ".sbss"); | |
1377 | symndx_to_section[RELOC_SECTION_BSS] = | |
1378 | bfd_get_section_by_name (input_bfd, ".bss"); | |
1379 | symndx_to_section[RELOC_SECTION_INIT] = | |
1380 | bfd_get_section_by_name (input_bfd, ".init"); | |
1381 | symndx_to_section[RELOC_SECTION_LIT8] = | |
1382 | bfd_get_section_by_name (input_bfd, ".lit8"); | |
1383 | symndx_to_section[RELOC_SECTION_LIT4] = | |
1384 | bfd_get_section_by_name (input_bfd, ".lit4"); | |
1385 | symndx_to_section[RELOC_SECTION_XDATA] = | |
1386 | bfd_get_section_by_name (input_bfd, ".xdata"); | |
1387 | symndx_to_section[RELOC_SECTION_PDATA] = | |
1388 | bfd_get_section_by_name (input_bfd, ".pdata"); | |
1389 | symndx_to_section[RELOC_SECTION_FINI] = | |
1390 | bfd_get_section_by_name (input_bfd, ".fini"); | |
1391 | symndx_to_section[RELOC_SECTION_LITA] = | |
1392 | bfd_get_section_by_name (input_bfd, ".lita"); | |
1393 | symndx_to_section[RELOC_SECTION_ABS] = bfd_abs_section_ptr; | |
1394 | symndx_to_section[RELOC_SECTION_RCONST] = | |
1395 | bfd_get_section_by_name (input_bfd, ".rconst"); | |
1396 | ||
1397 | ecoff_data (input_bfd)->symndx_to_section = symndx_to_section; | |
1398 | } | |
1399 | ||
1400 | sym_hashes = ecoff_data (input_bfd)->sym_hashes; | |
1401 | ||
1402 | /* On the Alpha, the .lita section must be addressable by the global | |
1403 | pointer. To support large programs, we need to allow multiple | |
1404 | global pointers. This works as long as each input .lita section | |
1405 | is <64KB big. This implies that when producing relocatable | |
346ceb11 | 1406 | output, the .lita section is limited to 64KB. . */ |
252b5132 RH |
1407 | |
1408 | lita_sec = symndx_to_section[RELOC_SECTION_LITA]; | |
1409 | gp = _bfd_get_gp_value (output_bfd); | |
0e1862bb | 1410 | if (! bfd_link_relocatable (info) && lita_sec != NULL) |
252b5132 RH |
1411 | { |
1412 | struct ecoff_section_tdata *lita_sec_data; | |
1413 | ||
1414 | /* Make sure we have a section data structure to which we can | |
1415 | hang on to the gp value we pick for the section. */ | |
1416 | lita_sec_data = ecoff_section_data (input_bfd, lita_sec); | |
1417 | if (lita_sec_data == NULL) | |
1418 | { | |
dc810e39 | 1419 | amt = sizeof (struct ecoff_section_tdata); |
252b5132 | 1420 | lita_sec_data = ((struct ecoff_section_tdata *) |
dc810e39 | 1421 | bfd_zalloc (input_bfd, amt)); |
e9edc808 | 1422 | lita_sec->used_by_bfd = lita_sec_data; |
252b5132 RH |
1423 | } |
1424 | ||
1425 | if (lita_sec_data->gp != 0) | |
1426 | { | |
1427 | /* If we already assigned a gp to this section, we better | |
1428 | stick with that value. */ | |
1429 | gp = lita_sec_data->gp; | |
1430 | } | |
1431 | else | |
1432 | { | |
1433 | bfd_vma lita_vma; | |
1434 | bfd_size_type lita_size; | |
1435 | ||
1436 | lita_vma = lita_sec->output_offset + lita_sec->output_section->vma; | |
eea6121a | 1437 | lita_size = lita_sec->size; |
252b5132 RH |
1438 | |
1439 | if (gp == 0 | |
1440 | || lita_vma < gp - 0x8000 | |
1441 | || lita_vma + lita_size >= gp + 0x8000) | |
1442 | { | |
1443 | /* Either gp hasn't been set at all or the current gp | |
1444 | cannot address this .lita section. In both cases we | |
1445 | reset the gp to point into the "middle" of the | |
1446 | current input .lita section. */ | |
1447 | if (gp && !ecoff_data (output_bfd)->issued_multiple_gp_warning) | |
1448 | { | |
1449 | (*info->callbacks->warning) (info, | |
1450 | _("using multiple gp values"), | |
1451 | (char *) NULL, output_bfd, | |
1452 | (asection *) NULL, (bfd_vma) 0); | |
0a1b45a2 | 1453 | ecoff_data (output_bfd)->issued_multiple_gp_warning = true; |
252b5132 RH |
1454 | } |
1455 | if (lita_vma < gp - 0x8000) | |
1456 | gp = lita_vma + lita_size - 0x8000; | |
1457 | else | |
1458 | gp = lita_vma + 0x8000; | |
1459 | ||
1460 | } | |
1461 | ||
1462 | lita_sec_data->gp = gp; | |
1463 | } | |
1464 | ||
1465 | _bfd_set_gp_value (output_bfd, gp); | |
1466 | } | |
1467 | ||
1468 | gp_undefined = (gp == 0); | |
1469 | ||
1470 | BFD_ASSERT (bfd_header_little_endian (output_bfd)); | |
1471 | BFD_ASSERT (bfd_header_little_endian (input_bfd)); | |
1472 | ||
1473 | ext_rel = (struct external_reloc *) external_relocs; | |
1474 | ext_rel_end = ext_rel + input_section->reloc_count; | |
1475 | for (; ext_rel < ext_rel_end; ext_rel++) | |
1476 | { | |
1477 | bfd_vma r_vaddr; | |
1478 | unsigned long r_symndx; | |
1479 | int r_type; | |
1480 | int r_extern; | |
1481 | int r_offset; | |
1482 | int r_size; | |
0a1b45a2 AM |
1483 | bool relocatep; |
1484 | bool adjust_addrp; | |
1485 | bool gp_usedp; | |
252b5132 RH |
1486 | bfd_vma addend; |
1487 | ||
dc810e39 AM |
1488 | r_vaddr = H_GET_64 (input_bfd, ext_rel->r_vaddr); |
1489 | r_symndx = H_GET_32 (input_bfd, ext_rel->r_symndx); | |
252b5132 RH |
1490 | |
1491 | r_type = ((ext_rel->r_bits[0] & RELOC_BITS0_TYPE_LITTLE) | |
1492 | >> RELOC_BITS0_TYPE_SH_LITTLE); | |
1493 | r_extern = (ext_rel->r_bits[1] & RELOC_BITS1_EXTERN_LITTLE) != 0; | |
1494 | r_offset = ((ext_rel->r_bits[1] & RELOC_BITS1_OFFSET_LITTLE) | |
1495 | >> RELOC_BITS1_OFFSET_SH_LITTLE); | |
1496 | /* Ignored the reserved bits. */ | |
1497 | r_size = ((ext_rel->r_bits[3] & RELOC_BITS3_SIZE_LITTLE) | |
1498 | >> RELOC_BITS3_SIZE_SH_LITTLE); | |
1499 | ||
0a1b45a2 AM |
1500 | relocatep = false; |
1501 | adjust_addrp = true; | |
1502 | gp_usedp = false; | |
252b5132 RH |
1503 | addend = 0; |
1504 | ||
1505 | switch (r_type) | |
1506 | { | |
0adc9281 | 1507 | case ALPHA_R_GPRELHIGH: |
0aa13fee AM |
1508 | _bfd_error_handler (_("%pB: %s unsupported"), |
1509 | input_bfd, "ALPHA_R_GPRELHIGH"); | |
0adc9281 NC |
1510 | bfd_set_error (bfd_error_bad_value); |
1511 | continue; | |
68ffbac6 | 1512 | |
0adc9281 | 1513 | case ALPHA_R_GPRELLOW: |
0aa13fee AM |
1514 | _bfd_error_handler (_("%pB: %s unsupported"), |
1515 | input_bfd, "ALPHA_R_GPRELLOW"); | |
0adc9281 NC |
1516 | bfd_set_error (bfd_error_bad_value); |
1517 | continue; | |
68ffbac6 | 1518 | |
252b5132 | 1519 | default: |
0aa13fee AM |
1520 | /* xgettext:c-format */ |
1521 | _bfd_error_handler (_("%pB: unsupported relocation type %#x"), | |
1522 | input_bfd, (int) r_type); | |
0adc9281 NC |
1523 | bfd_set_error (bfd_error_bad_value); |
1524 | continue; | |
252b5132 RH |
1525 | |
1526 | case ALPHA_R_IGNORE: | |
1527 | /* This reloc appears after a GPDISP reloc. On earlier | |
1528 | versions of OSF/1, It marked the position of the second | |
1529 | instruction to be altered by the GPDISP reloc, but it is | |
1530 | not otherwise used for anything. For some reason, the | |
1531 | address of the relocation does not appear to include the | |
1532 | section VMA, unlike the other relocation types. */ | |
0e1862bb | 1533 | if (bfd_link_relocatable (info)) |
dc810e39 AM |
1534 | H_PUT_64 (input_bfd, input_section->output_offset + r_vaddr, |
1535 | ext_rel->r_vaddr); | |
0a1b45a2 | 1536 | adjust_addrp = false; |
252b5132 RH |
1537 | break; |
1538 | ||
1539 | case ALPHA_R_REFLONG: | |
1540 | case ALPHA_R_REFQUAD: | |
1541 | case ALPHA_R_HINT: | |
0a1b45a2 | 1542 | relocatep = true; |
252b5132 RH |
1543 | break; |
1544 | ||
1545 | case ALPHA_R_BRADDR: | |
1546 | case ALPHA_R_SREL16: | |
1547 | case ALPHA_R_SREL32: | |
1548 | case ALPHA_R_SREL64: | |
1549 | if (r_extern) | |
1550 | addend += - (r_vaddr + 4); | |
0a1b45a2 | 1551 | relocatep = true; |
252b5132 RH |
1552 | break; |
1553 | ||
1554 | case ALPHA_R_GPREL32: | |
1555 | /* This relocation is used in a switch table. It is a 32 | |
1556 | bit offset from the current GP value. We must adjust it | |
1557 | by the different between the original GP value and the | |
1558 | current GP value. */ | |
0a1b45a2 | 1559 | relocatep = true; |
252b5132 | 1560 | addend = ecoff_data (input_bfd)->gp - gp; |
0a1b45a2 | 1561 | gp_usedp = true; |
252b5132 RH |
1562 | break; |
1563 | ||
1564 | case ALPHA_R_LITERAL: | |
1565 | /* This is a reference to a literal value, generally | |
1566 | (always?) in the .lita section. This is a 16 bit GP | |
1567 | relative relocation. Sometimes the subsequent reloc is a | |
1568 | LITUSE reloc, which indicates how this reloc is used. | |
1569 | This sometimes permits rewriting the two instructions | |
1570 | referred to by the LITERAL and the LITUSE into different | |
1571 | instructions which do not refer to .lita. This can save | |
1572 | a memory reference, and permits removing a value from | |
1573 | .lita thus saving GP relative space. | |
1574 | ||
1575 | We do not these optimizations. To do them we would need | |
1576 | to arrange to link the .lita section first, so that by | |
1577 | the time we got here we would know the final values to | |
1578 | use. This would not be particularly difficult, but it is | |
1579 | not currently implemented. */ | |
1580 | ||
1581 | /* I believe that the LITERAL reloc will only apply to a ldq | |
1582 | or ldl instruction, so check my assumption. */ | |
1583 | { | |
1584 | unsigned long insn; | |
1585 | ||
1586 | insn = bfd_get_32 (input_bfd, | |
1587 | contents + r_vaddr - input_section->vma); | |
1588 | BFD_ASSERT (((insn >> 26) & 0x3f) == 0x29 | |
1589 | || ((insn >> 26) & 0x3f) == 0x28); | |
1590 | } | |
1591 | ||
0a1b45a2 | 1592 | relocatep = true; |
252b5132 | 1593 | addend = ecoff_data (input_bfd)->gp - gp; |
0a1b45a2 | 1594 | gp_usedp = true; |
252b5132 RH |
1595 | break; |
1596 | ||
1597 | case ALPHA_R_LITUSE: | |
1598 | /* See ALPHA_R_LITERAL above for the uses of this reloc. It | |
1599 | does not cause anything to happen, itself. */ | |
1600 | break; | |
346ceb11 | 1601 | |
252b5132 RH |
1602 | case ALPHA_R_GPDISP: |
1603 | /* This marks the ldah of an ldah/lda pair which loads the | |
1604 | gp register with the difference of the gp value and the | |
1605 | current location. The second of the pair is r_symndx | |
1606 | bytes ahead. It used to be marked with an ALPHA_R_IGNORE | |
1607 | reloc, but OSF/1 3.2 no longer does that. */ | |
1608 | { | |
1609 | unsigned long insn1, insn2; | |
1610 | ||
1611 | /* Get the two instructions. */ | |
1612 | insn1 = bfd_get_32 (input_bfd, | |
1613 | contents + r_vaddr - input_section->vma); | |
1614 | insn2 = bfd_get_32 (input_bfd, | |
1615 | (contents | |
1616 | + r_vaddr | |
1617 | - input_section->vma | |
1618 | + r_symndx)); | |
1619 | ||
1620 | BFD_ASSERT (((insn1 >> 26) & 0x3f) == 0x09); /* ldah */ | |
1621 | BFD_ASSERT (((insn2 >> 26) & 0x3f) == 0x08); /* lda */ | |
1622 | ||
1623 | /* Get the existing addend. We must account for the sign | |
1624 | extension done by lda and ldah. */ | |
1625 | addend = ((insn1 & 0xffff) << 16) + (insn2 & 0xffff); | |
1626 | if (insn1 & 0x8000) | |
1627 | { | |
1628 | /* This is addend -= 0x100000000 without causing an | |
1629 | integer overflow on a 32 bit host. */ | |
1630 | addend -= 0x80000000; | |
1631 | addend -= 0x80000000; | |
1632 | } | |
1633 | if (insn2 & 0x8000) | |
1634 | addend -= 0x10000; | |
1635 | ||
1636 | /* The existing addend includes the difference between the | |
1637 | gp of the input BFD and the address in the input BFD. | |
1638 | We want to change this to the difference between the | |
1639 | final GP and the final address. */ | |
1640 | addend += (gp | |
1641 | - ecoff_data (input_bfd)->gp | |
1642 | + input_section->vma | |
1643 | - (input_section->output_section->vma | |
1644 | + input_section->output_offset)); | |
1645 | ||
1646 | /* Change the instructions, accounting for the sign | |
1647 | extension, and write them out. */ | |
1648 | if (addend & 0x8000) | |
1649 | addend += 0x10000; | |
1650 | insn1 = (insn1 & 0xffff0000) | ((addend >> 16) & 0xffff); | |
1651 | insn2 = (insn2 & 0xffff0000) | (addend & 0xffff); | |
1652 | ||
1653 | bfd_put_32 (input_bfd, (bfd_vma) insn1, | |
1654 | contents + r_vaddr - input_section->vma); | |
1655 | bfd_put_32 (input_bfd, (bfd_vma) insn2, | |
1656 | contents + r_vaddr - input_section->vma + r_symndx); | |
1657 | ||
0a1b45a2 | 1658 | gp_usedp = true; |
252b5132 RH |
1659 | } |
1660 | break; | |
346ceb11 | 1661 | |
252b5132 RH |
1662 | case ALPHA_R_OP_PUSH: |
1663 | case ALPHA_R_OP_PSUB: | |
1664 | case ALPHA_R_OP_PRSHIFT: | |
1665 | /* Manipulate values on the reloc evaluation stack. The | |
1666 | r_vaddr field is not an address in input_section, it is | |
1667 | the current value (including any addend) of the object | |
1668 | being used. */ | |
1669 | if (! r_extern) | |
1670 | { | |
1671 | asection *s; | |
1672 | ||
1673 | s = symndx_to_section[r_symndx]; | |
1674 | if (s == (asection *) NULL) | |
1675 | abort (); | |
1676 | addend = s->output_section->vma + s->output_offset - s->vma; | |
1677 | } | |
1678 | else | |
1679 | { | |
1680 | struct ecoff_link_hash_entry *h; | |
1681 | ||
1682 | h = sym_hashes[r_symndx]; | |
1683 | if (h == (struct ecoff_link_hash_entry *) NULL) | |
1684 | abort (); | |
1685 | ||
0e1862bb | 1686 | if (! bfd_link_relocatable (info)) |
252b5132 RH |
1687 | { |
1688 | if (h->root.type == bfd_link_hash_defined | |
1689 | || h->root.type == bfd_link_hash_defweak) | |
1690 | addend = (h->root.u.def.value | |
1691 | + h->root.u.def.section->output_section->vma | |
1692 | + h->root.u.def.section->output_offset); | |
1693 | else | |
1694 | { | |
1695 | /* Note that we pass the address as 0, since we | |
1696 | do not have a meaningful number for the | |
1697 | location within the section that is being | |
1698 | relocated. */ | |
1a72702b AM |
1699 | (*info->callbacks->undefined_symbol) |
1700 | (info, h->root.root.string, input_bfd, | |
0a1b45a2 | 1701 | input_section, (bfd_vma) 0, true); |
252b5132 RH |
1702 | addend = 0; |
1703 | } | |
1704 | } | |
1705 | else | |
1706 | { | |
1707 | if (h->root.type != bfd_link_hash_defined | |
1708 | && h->root.type != bfd_link_hash_defweak | |
1709 | && h->indx == -1) | |
1710 | { | |
1711 | /* This symbol is not being written out. Pass | |
1712 | the address as 0, as with undefined_symbol, | |
1713 | above. */ | |
1a72702b AM |
1714 | (*info->callbacks->unattached_reloc) |
1715 | (info, h->root.root.string, | |
1716 | input_bfd, input_section, (bfd_vma) 0); | |
252b5132 RH |
1717 | } |
1718 | ||
1719 | addend = alpha_convert_external_reloc (output_bfd, info, | |
1720 | input_bfd, | |
1721 | ext_rel, h); | |
1722 | } | |
1723 | } | |
1724 | ||
1725 | addend += r_vaddr; | |
1726 | ||
0e1862bb | 1727 | if (bfd_link_relocatable (info)) |
252b5132 RH |
1728 | { |
1729 | /* Adjust r_vaddr by the addend. */ | |
dc810e39 | 1730 | H_PUT_64 (input_bfd, addend, ext_rel->r_vaddr); |
252b5132 RH |
1731 | } |
1732 | else | |
1733 | { | |
1734 | switch (r_type) | |
1735 | { | |
1736 | case ALPHA_R_OP_PUSH: | |
1737 | if (tos >= RELOC_STACKSIZE) | |
1738 | abort (); | |
1739 | stack[tos++] = addend; | |
1740 | break; | |
1741 | ||
1742 | case ALPHA_R_OP_PSUB: | |
1743 | if (tos == 0) | |
1744 | abort (); | |
1745 | stack[tos - 1] -= addend; | |
1746 | break; | |
1747 | ||
1748 | case ALPHA_R_OP_PRSHIFT: | |
1749 | if (tos == 0) | |
1750 | abort (); | |
1751 | stack[tos - 1] >>= addend; | |
1752 | break; | |
1753 | } | |
1754 | } | |
1755 | ||
0a1b45a2 | 1756 | adjust_addrp = false; |
252b5132 RH |
1757 | break; |
1758 | ||
1759 | case ALPHA_R_OP_STORE: | |
1760 | /* Store a value from the reloc stack into a bitfield. If | |
1049f94e | 1761 | we are generating relocatable output, all we do is |
252b5132 | 1762 | adjust the address of the reloc. */ |
0e1862bb | 1763 | if (! bfd_link_relocatable (info)) |
252b5132 RH |
1764 | { |
1765 | bfd_vma mask; | |
1766 | bfd_vma val; | |
1767 | ||
1768 | if (tos == 0) | |
1769 | abort (); | |
1770 | ||
1771 | /* Get the relocation mask. The separate steps and the | |
1772 | casts to bfd_vma are attempts to avoid a bug in the | |
1773 | Alpha OSF 1.3 C compiler. See reloc.c for more | |
1774 | details. */ | |
1775 | mask = 1; | |
1776 | mask <<= (bfd_vma) r_size; | |
1777 | mask -= 1; | |
1778 | ||
1779 | /* FIXME: I don't know what kind of overflow checking, | |
1780 | if any, should be done here. */ | |
1781 | val = bfd_get_64 (input_bfd, | |
1782 | contents + r_vaddr - input_section->vma); | |
1783 | val &=~ mask << (bfd_vma) r_offset; | |
1784 | val |= (stack[--tos] & mask) << (bfd_vma) r_offset; | |
1785 | bfd_put_64 (input_bfd, val, | |
1786 | contents + r_vaddr - input_section->vma); | |
1787 | } | |
1788 | break; | |
1789 | ||
1790 | case ALPHA_R_GPVALUE: | |
1791 | /* I really don't know if this does the right thing. */ | |
1792 | gp = ecoff_data (input_bfd)->gp + r_symndx; | |
0a1b45a2 | 1793 | gp_undefined = false; |
252b5132 RH |
1794 | break; |
1795 | } | |
1796 | ||
1797 | if (relocatep) | |
1798 | { | |
1799 | reloc_howto_type *howto; | |
1800 | struct ecoff_link_hash_entry *h = NULL; | |
1801 | asection *s = NULL; | |
1802 | bfd_vma relocation; | |
1803 | bfd_reloc_status_type r; | |
1804 | ||
1805 | /* Perform a relocation. */ | |
1806 | ||
1807 | howto = &alpha_howto_table[r_type]; | |
1808 | ||
1809 | if (r_extern) | |
1810 | { | |
1811 | h = sym_hashes[r_symndx]; | |
1812 | /* If h is NULL, that means that there is a reloc | |
1813 | against an external symbol which we thought was just | |
1814 | a debugging symbol. This should not happen. */ | |
1815 | if (h == (struct ecoff_link_hash_entry *) NULL) | |
1816 | abort (); | |
1817 | } | |
1818 | else | |
1819 | { | |
1820 | if (r_symndx >= NUM_RELOC_SECTIONS) | |
1821 | s = NULL; | |
1822 | else | |
1823 | s = symndx_to_section[r_symndx]; | |
1824 | ||
1825 | if (s == (asection *) NULL) | |
1826 | abort (); | |
1827 | } | |
1828 | ||
0e1862bb | 1829 | if (bfd_link_relocatable (info)) |
252b5132 | 1830 | { |
1049f94e | 1831 | /* We are generating relocatable output, and must |
252b5132 RH |
1832 | convert the existing reloc. */ |
1833 | if (r_extern) | |
1834 | { | |
1835 | if (h->root.type != bfd_link_hash_defined | |
1836 | && h->root.type != bfd_link_hash_defweak | |
1837 | && h->indx == -1) | |
1838 | { | |
1839 | /* This symbol is not being written out. */ | |
1a72702b AM |
1840 | (*info->callbacks->unattached_reloc) |
1841 | (info, h->root.root.string, input_bfd, | |
1842 | input_section, r_vaddr - input_section->vma); | |
252b5132 RH |
1843 | } |
1844 | ||
1845 | relocation = alpha_convert_external_reloc (output_bfd, | |
1846 | info, | |
1847 | input_bfd, | |
1848 | ext_rel, | |
1849 | h); | |
1850 | } | |
1851 | else | |
1852 | { | |
1853 | /* This is a relocation against a section. Adjust | |
1854 | the value by the amount the section moved. */ | |
1855 | relocation = (s->output_section->vma | |
1856 | + s->output_offset | |
1857 | - s->vma); | |
1858 | } | |
1859 | ||
1860 | /* If this is PC relative, the existing object file | |
1861 | appears to already have the reloc worked out. We | |
1862 | must subtract out the old value and add in the new | |
1863 | one. */ | |
1864 | if (howto->pc_relative) | |
1865 | relocation -= (input_section->output_section->vma | |
1866 | + input_section->output_offset | |
1867 | - input_section->vma); | |
1868 | ||
1869 | /* Put in any addend. */ | |
1870 | relocation += addend; | |
1871 | ||
1872 | /* Adjust the contents. */ | |
1873 | r = _bfd_relocate_contents (howto, input_bfd, relocation, | |
1874 | (contents | |
1875 | + r_vaddr | |
1876 | - input_section->vma)); | |
1877 | } | |
1878 | else | |
1879 | { | |
1880 | /* We are producing a final executable. */ | |
1881 | if (r_extern) | |
1882 | { | |
1883 | /* This is a reloc against a symbol. */ | |
1884 | if (h->root.type == bfd_link_hash_defined | |
1885 | || h->root.type == bfd_link_hash_defweak) | |
1886 | { | |
1887 | asection *hsec; | |
1888 | ||
1889 | hsec = h->root.u.def.section; | |
1890 | relocation = (h->root.u.def.value | |
1891 | + hsec->output_section->vma | |
1892 | + hsec->output_offset); | |
1893 | } | |
1894 | else | |
1895 | { | |
1a72702b AM |
1896 | (*info->callbacks->undefined_symbol) |
1897 | (info, h->root.root.string, input_bfd, input_section, | |
0a1b45a2 | 1898 | r_vaddr - input_section->vma, true); |
252b5132 RH |
1899 | relocation = 0; |
1900 | } | |
1901 | } | |
1902 | else | |
1903 | { | |
1904 | /* This is a reloc against a section. */ | |
1905 | relocation = (s->output_section->vma | |
1906 | + s->output_offset | |
1907 | - s->vma); | |
1908 | ||
1909 | /* Adjust a PC relative relocation by removing the | |
1910 | reference to the original source section. */ | |
1911 | if (howto->pc_relative) | |
1912 | relocation += input_section->vma; | |
1913 | } | |
1914 | ||
1915 | r = _bfd_final_link_relocate (howto, | |
1916 | input_bfd, | |
1917 | input_section, | |
1918 | contents, | |
1919 | r_vaddr - input_section->vma, | |
1920 | relocation, | |
1921 | addend); | |
1922 | } | |
1923 | ||
1924 | if (r != bfd_reloc_ok) | |
1925 | { | |
1926 | switch (r) | |
1927 | { | |
1928 | default: | |
1929 | case bfd_reloc_outofrange: | |
1930 | abort (); | |
1931 | case bfd_reloc_overflow: | |
1932 | { | |
1933 | const char *name; | |
1934 | ||
1935 | if (r_extern) | |
1936 | name = sym_hashes[r_symndx]->root.root.string; | |
1937 | else | |
fd361982 | 1938 | name = bfd_section_name (symndx_to_section[r_symndx]); |
1a72702b AM |
1939 | (*info->callbacks->reloc_overflow) |
1940 | (info, NULL, name, alpha_howto_table[r_type].name, | |
1941 | (bfd_vma) 0, input_bfd, input_section, | |
1942 | r_vaddr - input_section->vma); | |
252b5132 RH |
1943 | } |
1944 | break; | |
1945 | } | |
1946 | } | |
1947 | } | |
1948 | ||
0e1862bb | 1949 | if (bfd_link_relocatable (info) && adjust_addrp) |
252b5132 RH |
1950 | { |
1951 | /* Change the address of the relocation. */ | |
dc810e39 AM |
1952 | H_PUT_64 (input_bfd, |
1953 | (input_section->output_section->vma | |
1954 | + input_section->output_offset | |
1955 | - input_section->vma | |
1956 | + r_vaddr), | |
1957 | ext_rel->r_vaddr); | |
252b5132 RH |
1958 | } |
1959 | ||
1960 | if (gp_usedp && gp_undefined) | |
1961 | { | |
1a72702b AM |
1962 | (*info->callbacks->reloc_dangerous) |
1963 | (info, _("GP relative relocation used when GP not defined"), | |
1964 | input_bfd, input_section, r_vaddr - input_section->vma); | |
252b5132 RH |
1965 | /* Only give the error once per link. */ |
1966 | gp = 4; | |
1967 | _bfd_set_gp_value (output_bfd, gp); | |
0a1b45a2 | 1968 | gp_undefined = false; |
252b5132 RH |
1969 | } |
1970 | } | |
1971 | ||
1972 | if (tos != 0) | |
1973 | abort (); | |
1974 | ||
0a1b45a2 | 1975 | return true; |
252b5132 RH |
1976 | } |
1977 | \f | |
1978 | /* Do final adjustments to the filehdr and the aouthdr. This routine | |
1979 | sets the dynamic bits in the file header. */ | |
1980 | ||
0a1b45a2 | 1981 | static bool |
2c3fc389 NC |
1982 | alpha_adjust_headers (bfd *abfd, |
1983 | struct internal_filehdr *fhdr, | |
1984 | struct internal_aouthdr *ahdr ATTRIBUTE_UNUSED) | |
252b5132 RH |
1985 | { |
1986 | if ((abfd->flags & (DYNAMIC | EXEC_P)) == (DYNAMIC | EXEC_P)) | |
1987 | fhdr->f_flags |= F_ALPHA_CALL_SHARED; | |
1988 | else if ((abfd->flags & DYNAMIC) != 0) | |
1989 | fhdr->f_flags |= F_ALPHA_SHARABLE; | |
0a1b45a2 | 1990 | return true; |
252b5132 RH |
1991 | } |
1992 | \f | |
1993 | /* Archive handling. In OSF/1 (or Digital Unix) v3.2, Digital | |
1994 | introduced archive packing, in which the elements in an archive are | |
1995 | optionally compressed using a simple dictionary scheme. We know | |
1996 | how to read such archives, but we don't write them. */ | |
1997 | ||
1998 | #define alpha_ecoff_slurp_armap _bfd_ecoff_slurp_armap | |
1999 | #define alpha_ecoff_slurp_extended_name_table \ | |
2000 | _bfd_ecoff_slurp_extended_name_table | |
2001 | #define alpha_ecoff_construct_extended_name_table \ | |
2002 | _bfd_ecoff_construct_extended_name_table | |
2003 | #define alpha_ecoff_truncate_arname _bfd_ecoff_truncate_arname | |
2004 | #define alpha_ecoff_write_armap _bfd_ecoff_write_armap | |
8f95b6e4 | 2005 | #define alpha_ecoff_write_ar_hdr _bfd_generic_write_ar_hdr |
252b5132 RH |
2006 | #define alpha_ecoff_generic_stat_arch_elt _bfd_ecoff_generic_stat_arch_elt |
2007 | #define alpha_ecoff_update_armap_timestamp _bfd_ecoff_update_armap_timestamp | |
2008 | ||
2009 | /* A compressed file uses this instead of ARFMAG. */ | |
2010 | ||
2011 | #define ARFZMAG "Z\012" | |
2012 | ||
2013 | /* Read an archive header. This is like the standard routine, but it | |
2014 | also accepts ARFZMAG. */ | |
2015 | ||
2c3fc389 NC |
2016 | static void * |
2017 | alpha_ecoff_read_ar_hdr (bfd *abfd) | |
252b5132 RH |
2018 | { |
2019 | struct areltdata *ret; | |
2020 | struct ar_hdr *h; | |
2021 | ||
2022 | ret = (struct areltdata *) _bfd_generic_read_ar_hdr_mag (abfd, ARFZMAG); | |
2023 | if (ret == NULL) | |
2024 | return NULL; | |
2025 | ||
2026 | h = (struct ar_hdr *) ret->arch_header; | |
2027 | if (strncmp (h->ar_fmag, ARFZMAG, 2) == 0) | |
2028 | { | |
2029 | bfd_byte ab[8]; | |
2030 | ||
2031 | /* This is a compressed file. We must set the size correctly. | |
07d6d2b8 | 2032 | The size is the eight bytes after the dummy file header. */ |
dc810e39 AM |
2033 | if (bfd_seek (abfd, (file_ptr) FILHSZ, SEEK_CUR) != 0 |
2034 | || bfd_bread (ab, (bfd_size_type) 8, abfd) != 8 | |
2035 | || bfd_seek (abfd, (file_ptr) (- (FILHSZ + 8)), SEEK_CUR) != 0) | |
fcc5d04f AM |
2036 | { |
2037 | free (ret); | |
2038 | return NULL; | |
2039 | } | |
252b5132 | 2040 | |
dc810e39 | 2041 | ret->parsed_size = H_GET_64 (abfd, ab); |
252b5132 RH |
2042 | } |
2043 | ||
2c3fc389 | 2044 | return ret; |
252b5132 RH |
2045 | } |
2046 | ||
2047 | /* Get an archive element at a specified file position. This is where | |
2048 | we uncompress the archive element if necessary. */ | |
2049 | ||
2050 | static bfd * | |
6395a102 L |
2051 | alpha_ecoff_get_elt_at_filepos (bfd *archive, file_ptr filepos, |
2052 | struct bfd_link_info *info) | |
252b5132 RH |
2053 | { |
2054 | bfd *nbfd = NULL; | |
2055 | struct areltdata *tdata; | |
2056 | struct ar_hdr *hdr; | |
2057 | bfd_byte ab[8]; | |
2058 | bfd_size_type size; | |
2059 | bfd_byte *buf, *p; | |
2060 | struct bfd_in_memory *bim; | |
7d4b2d2d | 2061 | ufile_ptr filesize; |
252b5132 | 2062 | |
493152cb | 2063 | buf = NULL; |
6395a102 | 2064 | nbfd = _bfd_get_elt_at_filepos (archive, filepos, info); |
252b5132 RH |
2065 | if (nbfd == NULL) |
2066 | goto error_return; | |
2067 | ||
2068 | if ((nbfd->flags & BFD_IN_MEMORY) != 0) | |
2069 | { | |
2070 | /* We have already expanded this BFD. */ | |
2071 | return nbfd; | |
2072 | } | |
2073 | ||
2074 | tdata = (struct areltdata *) nbfd->arelt_data; | |
2075 | hdr = (struct ar_hdr *) tdata->arch_header; | |
2076 | if (strncmp (hdr->ar_fmag, ARFZMAG, 2) != 0) | |
2077 | return nbfd; | |
2078 | ||
2079 | /* We must uncompress this element. We do this by copying it into a | |
dc810e39 | 2080 | memory buffer, and making bfd_bread and bfd_seek use that buffer. |
252b5132 RH |
2081 | This can use a lot of memory, but it's simpler than getting a |
2082 | temporary file, making that work with the file descriptor caching | |
2083 | code, and making sure that it is deleted at all appropriate | |
2084 | times. It can be changed if it ever becomes important. */ | |
2085 | ||
2086 | /* The compressed file starts with a dummy ECOFF file header. */ | |
dc810e39 | 2087 | if (bfd_seek (nbfd, (file_ptr) FILHSZ, SEEK_SET) != 0) |
252b5132 RH |
2088 | goto error_return; |
2089 | ||
2090 | /* The next eight bytes are the real file size. */ | |
dc810e39 | 2091 | if (bfd_bread (ab, (bfd_size_type) 8, nbfd) != 8) |
252b5132 | 2092 | goto error_return; |
dc810e39 | 2093 | size = H_GET_64 (nbfd, ab); |
252b5132 | 2094 | |
7d4b2d2d AM |
2095 | /* The decompression algorithm will at most expand by eight times. */ |
2096 | filesize = bfd_get_file_size (archive); | |
2097 | if (filesize != 0 && size / 8 > filesize) | |
2098 | { | |
2099 | bfd_set_error (bfd_error_malformed_archive); | |
2100 | goto error_return; | |
2101 | } | |
2102 | ||
493152cb | 2103 | if (size != 0) |
252b5132 RH |
2104 | { |
2105 | bfd_size_type left; | |
2106 | bfd_byte dict[4096]; | |
2107 | unsigned int h; | |
2108 | bfd_byte b; | |
2109 | ||
493152cb | 2110 | buf = (bfd_byte *) bfd_malloc (size); |
252b5132 RH |
2111 | if (buf == NULL) |
2112 | goto error_return; | |
2113 | p = buf; | |
2114 | ||
2115 | left = size; | |
2116 | ||
346ceb11 | 2117 | /* I don't know what the next eight bytes are for. */ |
dc810e39 | 2118 | if (bfd_bread (ab, (bfd_size_type) 8, nbfd) != 8) |
252b5132 RH |
2119 | goto error_return; |
2120 | ||
2121 | /* This is the uncompression algorithm. It's a simple | |
2122 | dictionary based scheme in which each character is predicted | |
2123 | by a hash of the previous three characters. A control byte | |
2124 | indicates whether the character is predicted or whether it | |
2125 | appears in the input stream; each control byte manages the | |
2126 | next eight bytes in the output stream. */ | |
2127 | memset (dict, 0, sizeof dict); | |
2128 | h = 0; | |
dc810e39 | 2129 | while (bfd_bread (&b, (bfd_size_type) 1, nbfd) == 1) |
252b5132 RH |
2130 | { |
2131 | unsigned int i; | |
2132 | ||
2133 | for (i = 0; i < 8; i++, b >>= 1) | |
2134 | { | |
2135 | bfd_byte n; | |
2136 | ||
2137 | if ((b & 1) == 0) | |
2138 | n = dict[h]; | |
2139 | else | |
2140 | { | |
89b599df | 2141 | if (bfd_bread (&n, 1, nbfd) != 1) |
252b5132 RH |
2142 | goto error_return; |
2143 | dict[h] = n; | |
2144 | } | |
2145 | ||
2146 | *p++ = n; | |
2147 | ||
2148 | --left; | |
2149 | if (left == 0) | |
2150 | break; | |
2151 | ||
2152 | h <<= 4; | |
2153 | h ^= n; | |
2154 | h &= sizeof dict - 1; | |
2155 | } | |
2156 | ||
2157 | if (left == 0) | |
2158 | break; | |
2159 | } | |
2160 | } | |
2161 | ||
2162 | /* Now the uncompressed file contents are in buf. */ | |
2163 | bim = ((struct bfd_in_memory *) | |
493152cb | 2164 | bfd_malloc ((bfd_size_type) sizeof (struct bfd_in_memory))); |
252b5132 RH |
2165 | if (bim == NULL) |
2166 | goto error_return; | |
2167 | bim->size = size; | |
2168 | bim->buffer = buf; | |
2169 | ||
0a1b45a2 | 2170 | nbfd->mtime_set = true; |
252b5132 RH |
2171 | nbfd->mtime = strtol (hdr->ar_date, (char **) NULL, 10); |
2172 | ||
2173 | nbfd->flags |= BFD_IN_MEMORY; | |
2c3fc389 | 2174 | nbfd->iostream = bim; |
65077aa8 TG |
2175 | nbfd->iovec = &_bfd_memory_iovec; |
2176 | nbfd->origin = 0; | |
252b5132 RH |
2177 | BFD_ASSERT (! nbfd->cacheable); |
2178 | ||
2179 | return nbfd; | |
2180 | ||
2181 | error_return: | |
c9594989 | 2182 | free (buf); |
252b5132 RH |
2183 | if (nbfd != NULL) |
2184 | bfd_close (nbfd); | |
346ceb11 | 2185 | return NULL; |
252b5132 RH |
2186 | } |
2187 | ||
2188 | /* Open the next archived file. */ | |
2189 | ||
2190 | static bfd * | |
2c3fc389 | 2191 | alpha_ecoff_openr_next_archived_file (bfd *archive, bfd *last_file) |
252b5132 | 2192 | { |
4978e369 | 2193 | ufile_ptr filestart; |
252b5132 RH |
2194 | |
2195 | if (last_file == NULL) | |
2196 | filestart = bfd_ardata (archive)->first_file_filepos; | |
2197 | else | |
2198 | { | |
2199 | struct areltdata *t; | |
2200 | struct ar_hdr *h; | |
2201 | bfd_size_type size; | |
2202 | ||
2203 | /* We can't use arelt_size here, because that uses parsed_size, | |
07d6d2b8 | 2204 | which is the uncompressed size. We need the compressed size. */ |
252b5132 RH |
2205 | t = (struct areltdata *) last_file->arelt_data; |
2206 | h = (struct ar_hdr *) t->arch_header; | |
2207 | size = strtol (h->ar_size, (char **) NULL, 10); | |
2208 | ||
2209 | /* Pad to an even boundary... | |
2210 | Note that last_file->origin can be odd in the case of | |
346ceb11 | 2211 | BSD-4.4-style element with a long odd size. */ |
65077aa8 | 2212 | filestart = last_file->proxy_origin + size; |
252b5132 | 2213 | filestart += filestart % 2; |
03ee8583 | 2214 | if (filestart < last_file->proxy_origin) |
4978e369 AM |
2215 | { |
2216 | /* Prevent looping. See PR19256. */ | |
2217 | bfd_set_error (bfd_error_malformed_archive); | |
2218 | return NULL; | |
2219 | } | |
252b5132 RH |
2220 | } |
2221 | ||
6395a102 | 2222 | return alpha_ecoff_get_elt_at_filepos (archive, filestart, NULL); |
252b5132 RH |
2223 | } |
2224 | ||
2225 | /* Open the archive file given an index into the armap. */ | |
2226 | ||
2227 | static bfd * | |
91d6fa6a | 2228 | alpha_ecoff_get_elt_at_index (bfd *abfd, symindex sym_index) |
252b5132 RH |
2229 | { |
2230 | carsym *entry; | |
2231 | ||
91d6fa6a | 2232 | entry = bfd_ardata (abfd)->symdefs + sym_index; |
6395a102 L |
2233 | return alpha_ecoff_get_elt_at_filepos (abfd, entry->file_offset, |
2234 | NULL); | |
252b5132 | 2235 | } |
d00dd7dc AM |
2236 | |
2237 | static void | |
2238 | alpha_ecoff_swap_coff_aux_in (bfd *abfd ATTRIBUTE_UNUSED, | |
2239 | void *ext1 ATTRIBUTE_UNUSED, | |
2240 | int type ATTRIBUTE_UNUSED, | |
2241 | int in_class ATTRIBUTE_UNUSED, | |
2242 | int indx ATTRIBUTE_UNUSED, | |
2243 | int numaux ATTRIBUTE_UNUSED, | |
2244 | void *in1 ATTRIBUTE_UNUSED) | |
2245 | { | |
2246 | } | |
2247 | ||
2248 | static void | |
2249 | alpha_ecoff_swap_coff_sym_in (bfd *abfd ATTRIBUTE_UNUSED, | |
2250 | void *ext1 ATTRIBUTE_UNUSED, | |
2251 | void *in1 ATTRIBUTE_UNUSED) | |
2252 | { | |
2253 | } | |
2254 | ||
2255 | static void | |
2256 | alpha_ecoff_swap_coff_lineno_in (bfd *abfd ATTRIBUTE_UNUSED, | |
2257 | void *ext1 ATTRIBUTE_UNUSED, | |
2258 | void *in1 ATTRIBUTE_UNUSED) | |
2259 | { | |
2260 | } | |
2261 | ||
2262 | static unsigned int | |
2263 | alpha_ecoff_swap_coff_aux_out (bfd *abfd ATTRIBUTE_UNUSED, | |
2264 | void *inp ATTRIBUTE_UNUSED, | |
2265 | int type ATTRIBUTE_UNUSED, | |
2266 | int in_class ATTRIBUTE_UNUSED, | |
2267 | int indx ATTRIBUTE_UNUSED, | |
2268 | int numaux ATTRIBUTE_UNUSED, | |
2269 | void *extp ATTRIBUTE_UNUSED) | |
2270 | { | |
2271 | return 0; | |
2272 | } | |
2273 | ||
2274 | static unsigned int | |
2275 | alpha_ecoff_swap_coff_sym_out (bfd *abfd ATTRIBUTE_UNUSED, | |
2276 | void *inp ATTRIBUTE_UNUSED, | |
2277 | void *extp ATTRIBUTE_UNUSED) | |
2278 | { | |
2279 | return 0; | |
2280 | } | |
2281 | ||
2282 | static unsigned int | |
2283 | alpha_ecoff_swap_coff_lineno_out (bfd *abfd ATTRIBUTE_UNUSED, | |
2284 | void *inp ATTRIBUTE_UNUSED, | |
2285 | void *extp ATTRIBUTE_UNUSED) | |
2286 | { | |
2287 | return 0; | |
2288 | } | |
2289 | ||
2290 | static unsigned int | |
2291 | alpha_ecoff_swap_coff_reloc_out (bfd *abfd ATTRIBUTE_UNUSED, | |
2292 | void *inp ATTRIBUTE_UNUSED, | |
2293 | void *extp ATTRIBUTE_UNUSED) | |
2294 | { | |
2295 | return 0; | |
2296 | } | |
252b5132 RH |
2297 | \f |
2298 | /* This is the ECOFF backend structure. The backend field of the | |
2299 | target vector points to this. */ | |
2300 | ||
2301 | static const struct ecoff_backend_data alpha_ecoff_backend_data = | |
2302 | { | |
2303 | /* COFF backend structure. */ | |
2304 | { | |
d00dd7dc AM |
2305 | alpha_ecoff_swap_coff_aux_in, alpha_ecoff_swap_coff_sym_in, |
2306 | alpha_ecoff_swap_coff_lineno_in, alpha_ecoff_swap_coff_aux_out, | |
2307 | alpha_ecoff_swap_coff_sym_out, alpha_ecoff_swap_coff_lineno_out, | |
2308 | alpha_ecoff_swap_coff_reloc_out, | |
252b5132 RH |
2309 | alpha_ecoff_swap_filehdr_out, alpha_ecoff_swap_aouthdr_out, |
2310 | alpha_ecoff_swap_scnhdr_out, | |
0a1b45a2 AM |
2311 | FILHSZ, AOUTSZ, SCNHSZ, 0, 0, 0, 0, FILNMLEN, true, |
2312 | ECOFF_NO_LONG_SECTION_NAMES, 4, false, 2, 32768, | |
252b5132 RH |
2313 | alpha_ecoff_swap_filehdr_in, alpha_ecoff_swap_aouthdr_in, |
2314 | alpha_ecoff_swap_scnhdr_in, NULL, | |
2315 | alpha_ecoff_bad_format_hook, _bfd_ecoff_set_arch_mach_hook, | |
2316 | alpha_ecoff_mkobject_hook, _bfd_ecoff_styp_to_sec_flags, | |
2317 | _bfd_ecoff_set_alignment_hook, _bfd_ecoff_slurp_symbol_table, | |
7b50b349 | 2318 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
2b5c217d | 2319 | NULL, NULL, NULL, NULL |
252b5132 RH |
2320 | }, |
2321 | /* Supported architecture. */ | |
2322 | bfd_arch_alpha, | |
2323 | /* Initial portion of armap string. */ | |
2324 | "________64", | |
2325 | /* The page boundary used to align sections in a demand-paged | |
2326 | executable file. E.g., 0x1000. */ | |
2327 | 0x2000, | |
b34976b6 AM |
2328 | /* TRUE if the .rdata section is part of the text segment, as on the |
2329 | Alpha. FALSE if .rdata is part of the data segment, as on the | |
252b5132 | 2330 | MIPS. */ |
0a1b45a2 | 2331 | true, |
252b5132 RH |
2332 | /* Bitsize of constructor entries. */ |
2333 | 64, | |
2334 | /* Reloc to use for constructor entries. */ | |
2335 | &alpha_howto_table[ALPHA_R_REFQUAD], | |
2336 | { | |
2337 | /* Symbol table magic number. */ | |
2338 | magicSym2, | |
2339 | /* Alignment of debugging information. E.g., 4. */ | |
2340 | 8, | |
2341 | /* Sizes of external symbolic information. */ | |
2342 | sizeof (struct hdr_ext), | |
2343 | sizeof (struct dnr_ext), | |
2344 | sizeof (struct pdr_ext), | |
2345 | sizeof (struct sym_ext), | |
2346 | sizeof (struct opt_ext), | |
2347 | sizeof (struct fdr_ext), | |
2348 | sizeof (struct rfd_ext), | |
2349 | sizeof (struct ext_ext), | |
2350 | /* Functions to swap in external symbolic data. */ | |
2351 | ecoff_swap_hdr_in, | |
2352 | ecoff_swap_dnr_in, | |
2353 | ecoff_swap_pdr_in, | |
2354 | ecoff_swap_sym_in, | |
2355 | ecoff_swap_opt_in, | |
2356 | ecoff_swap_fdr_in, | |
2357 | ecoff_swap_rfd_in, | |
2358 | ecoff_swap_ext_in, | |
2359 | _bfd_ecoff_swap_tir_in, | |
2360 | _bfd_ecoff_swap_rndx_in, | |
2361 | /* Functions to swap out external symbolic data. */ | |
2362 | ecoff_swap_hdr_out, | |
2363 | ecoff_swap_dnr_out, | |
2364 | ecoff_swap_pdr_out, | |
2365 | ecoff_swap_sym_out, | |
2366 | ecoff_swap_opt_out, | |
2367 | ecoff_swap_fdr_out, | |
2368 | ecoff_swap_rfd_out, | |
2369 | ecoff_swap_ext_out, | |
2370 | _bfd_ecoff_swap_tir_out, | |
2371 | _bfd_ecoff_swap_rndx_out, | |
2372 | /* Function to read in symbolic data. */ | |
2373 | _bfd_ecoff_slurp_symbolic_info | |
2374 | }, | |
2375 | /* External reloc size. */ | |
2376 | RELSZ, | |
2377 | /* Reloc swapping functions. */ | |
2378 | alpha_ecoff_swap_reloc_in, | |
2379 | alpha_ecoff_swap_reloc_out, | |
2380 | /* Backend reloc tweaking. */ | |
2381 | alpha_adjust_reloc_in, | |
2382 | alpha_adjust_reloc_out, | |
2383 | /* Relocate section contents while linking. */ | |
2384 | alpha_relocate_section, | |
2385 | /* Do final adjustments to filehdr and aouthdr. */ | |
2386 | alpha_adjust_headers, | |
2387 | /* Read an element from an archive at a given file position. */ | |
2388 | alpha_ecoff_get_elt_at_filepos | |
2389 | }; | |
2390 | ||
2391 | /* Looking up a reloc type is Alpha specific. */ | |
2392 | #define _bfd_ecoff_bfd_reloc_type_lookup alpha_bfd_reloc_type_lookup | |
157090f7 AM |
2393 | #define _bfd_ecoff_bfd_reloc_name_lookup \ |
2394 | alpha_bfd_reloc_name_lookup | |
252b5132 RH |
2395 | |
2396 | /* So is getting relocated section contents. */ | |
2397 | #define _bfd_ecoff_bfd_get_relocated_section_contents \ | |
2398 | alpha_ecoff_get_relocated_section_contents | |
2399 | ||
2400 | /* Handling file windows is generic. */ | |
2401 | #define _bfd_ecoff_get_section_contents_in_window \ | |
2402 | _bfd_generic_get_section_contents_in_window | |
2403 | ||
ae17ab41 CM |
2404 | /* Input section flag lookup is generic. */ |
2405 | #define _bfd_ecoff_bfd_lookup_section_flags bfd_generic_lookup_section_flags | |
2406 | ||
252b5132 RH |
2407 | /* Relaxing sections is generic. */ |
2408 | #define _bfd_ecoff_bfd_relax_section bfd_generic_relax_section | |
2409 | #define _bfd_ecoff_bfd_gc_sections bfd_generic_gc_sections | |
8550eb6e | 2410 | #define _bfd_ecoff_bfd_merge_sections bfd_generic_merge_sections |
72adc230 | 2411 | #define _bfd_ecoff_bfd_is_group_section bfd_generic_is_group_section |
cb7f4b29 | 2412 | #define _bfd_ecoff_bfd_group_name bfd_generic_group_name |
e61463e1 | 2413 | #define _bfd_ecoff_bfd_discard_group bfd_generic_discard_group |
082b7297 | 2414 | #define _bfd_ecoff_section_already_linked \ |
c77ec726 | 2415 | _bfd_coff_section_already_linked |
3023e3f6 | 2416 | #define _bfd_ecoff_bfd_define_common_symbol bfd_generic_define_common_symbol |
34a87bb0 | 2417 | #define _bfd_ecoff_bfd_link_hide_symbol _bfd_generic_link_hide_symbol |
7dba9362 | 2418 | #define _bfd_ecoff_bfd_define_start_stop bfd_generic_define_start_stop |
4f3b23b3 | 2419 | #define _bfd_ecoff_bfd_link_check_relocs _bfd_generic_link_check_relocs |
252b5132 | 2420 | |
23186865 JM |
2421 | /* Installing internal relocations in a section is also generic. */ |
2422 | #define _bfd_ecoff_set_reloc _bfd_generic_set_reloc | |
2423 | ||
6d00b590 | 2424 | const bfd_target alpha_ecoff_le_vec = |
252b5132 RH |
2425 | { |
2426 | "ecoff-littlealpha", /* name */ | |
2427 | bfd_target_ecoff_flavour, | |
2428 | BFD_ENDIAN_LITTLE, /* data byte order is little */ | |
2429 | BFD_ENDIAN_LITTLE, /* header byte order is little */ | |
2430 | ||
d00dd7dc AM |
2431 | (HAS_RELOC | EXEC_P /* object flags */ |
2432 | | HAS_LINENO | HAS_DEBUG | |
2433 | | HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED), | |
252b5132 | 2434 | |
a4dd6c97 AM |
2435 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE |
2436 | | SEC_DATA | SEC_SMALL_DATA), | |
252b5132 RH |
2437 | 0, /* leading underscore */ |
2438 | ' ', /* ar_pad_char */ | |
2439 | 15, /* ar_max_namelen */ | |
0aabe54e | 2440 | 0, /* match priority. */ |
d1bcae83 | 2441 | TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ |
252b5132 RH |
2442 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
2443 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
2444 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ | |
2445 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, | |
2446 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
2447 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */ | |
2448 | ||
d00dd7dc AM |
2449 | { /* bfd_check_format */ |
2450 | _bfd_dummy_target, | |
2451 | alpha_ecoff_object_p, | |
2452 | bfd_generic_archive_p, | |
2453 | _bfd_dummy_target | |
2454 | }, | |
2455 | { /* bfd_set_format */ | |
2456 | _bfd_bool_bfd_false_error, | |
2457 | _bfd_ecoff_mkobject, | |
2458 | _bfd_generic_mkarchive, | |
2459 | _bfd_bool_bfd_false_error | |
2460 | }, | |
2461 | { /* bfd_write_contents */ | |
2462 | _bfd_bool_bfd_false_error, | |
2463 | _bfd_ecoff_write_object_contents, | |
2464 | _bfd_write_archive_contents, | |
2465 | _bfd_bool_bfd_false_error | |
2466 | }, | |
2467 | ||
2468 | BFD_JUMP_TABLE_GENERIC (_bfd_ecoff), | |
2469 | BFD_JUMP_TABLE_COPY (_bfd_ecoff), | |
2470 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
2471 | BFD_JUMP_TABLE_ARCHIVE (alpha_ecoff), | |
2472 | BFD_JUMP_TABLE_SYMBOLS (_bfd_ecoff), | |
2473 | BFD_JUMP_TABLE_RELOCS (_bfd_ecoff), | |
2474 | BFD_JUMP_TABLE_WRITE (_bfd_ecoff), | |
2475 | BFD_JUMP_TABLE_LINK (_bfd_ecoff), | |
2476 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
252b5132 | 2477 | |
c3c89269 | 2478 | NULL, |
346ceb11 | 2479 | |
d00dd7dc | 2480 | &alpha_ecoff_backend_data |
252b5132 | 2481 | }; |