]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000) |
23e1d84c | 2 | Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 |
2c1c4c62 | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | Written by Ian Lance Taylor, Cygnus Support. |
5 | ||
6 | This file is part of GAS, the GNU Assembler. | |
7 | ||
8 | GAS 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 2, or (at your option) | |
11 | any later version. | |
12 | ||
13 | GAS 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. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GAS; see the file COPYING. If not, write to the Free | |
20 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
81d4177b | 21 | 02111-1307, USA. */ |
252b5132 RH |
22 | |
23 | #include <stdio.h> | |
252b5132 | 24 | #include "as.h" |
3882b010 | 25 | #include "safe-ctype.h" |
252b5132 RH |
26 | #include "subsegs.h" |
27 | ||
28 | #include "opcode/ppc.h" | |
29 | ||
30 | #ifdef OBJ_ELF | |
31 | #include "elf/ppc.h" | |
5d6f4f16 | 32 | #include "dwarf2dbg.h" |
252b5132 RH |
33 | #endif |
34 | ||
35 | #ifdef TE_PE | |
36 | #include "coff/pe.h" | |
37 | #endif | |
38 | ||
39 | /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */ | |
40 | ||
41 | /* Tell the main code what the endianness is. */ | |
42 | extern int target_big_endian; | |
43 | ||
44 | /* Whether or not, we've set target_big_endian. */ | |
45 | static int set_target_endian = 0; | |
46 | ||
47 | /* Whether to use user friendly register names. */ | |
48 | #ifndef TARGET_REG_NAMES_P | |
49 | #ifdef TE_PE | |
50 | #define TARGET_REG_NAMES_P true | |
51 | #else | |
52 | #define TARGET_REG_NAMES_P false | |
53 | #endif | |
54 | #endif | |
55 | ||
0baf16f2 AM |
56 | /* Macros for calculating LO, HI, HA, HIGHER, HIGHERA, HIGHEST, |
57 | HIGHESTA. */ | |
58 | ||
59 | /* #lo(value) denotes the least significant 16 bits of the indicated. */ | |
60 | #define PPC_LO(v) ((v) & 0xffff) | |
61 | ||
62 | /* #hi(value) denotes bits 16 through 31 of the indicated value. */ | |
63 | #define PPC_HI(v) (((v) >> 16) & 0xffff) | |
64 | ||
65 | /* #ha(value) denotes the high adjusted value: bits 16 through 31 of | |
66 | the indicated value, compensating for #lo() being treated as a | |
67 | signed number. */ | |
15c1449b | 68 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) |
0baf16f2 AM |
69 | |
70 | /* #higher(value) denotes bits 32 through 47 of the indicated value. */ | |
71 | #define PPC_HIGHER(v) (((v) >> 32) & 0xffff) | |
72 | ||
73 | /* #highera(value) denotes bits 32 through 47 of the indicated value, | |
74 | compensating for #lo() being treated as a signed number. */ | |
15c1449b | 75 | #define PPC_HIGHERA(v) PPC_HIGHER ((v) + 0x8000) |
0baf16f2 AM |
76 | |
77 | /* #highest(value) denotes bits 48 through 63 of the indicated value. */ | |
78 | #define PPC_HIGHEST(v) (((v) >> 48) & 0xffff) | |
79 | ||
80 | /* #highesta(value) denotes bits 48 through 63 of the indicated value, | |
15c1449b AM |
81 | compensating for #lo being treated as a signed number. */ |
82 | #define PPC_HIGHESTA(v) PPC_HIGHEST ((v) + 0x8000) | |
0baf16f2 AM |
83 | |
84 | #define SEX16(val) ((((val) & 0xffff) ^ 0x8000) - 0x8000) | |
85 | ||
252b5132 RH |
86 | static boolean reg_names_p = TARGET_REG_NAMES_P; |
87 | ||
88 | static boolean register_name PARAMS ((expressionS *)); | |
89 | static void ppc_set_cpu PARAMS ((void)); | |
90 | static unsigned long ppc_insert_operand | |
91 | PARAMS ((unsigned long insn, const struct powerpc_operand *operand, | |
92 | offsetT val, char *file, unsigned int line)); | |
93 | static void ppc_macro PARAMS ((char *str, const struct powerpc_macro *macro)); | |
94 | static void ppc_byte PARAMS ((int)); | |
0baf16f2 AM |
95 | |
96 | #if defined (OBJ_XCOFF) || defined (OBJ_ELF) | |
252b5132 RH |
97 | static int ppc_is_toc_sym PARAMS ((symbolS *sym)); |
98 | static void ppc_tc PARAMS ((int)); | |
0baf16f2 AM |
99 | static void ppc_machine PARAMS ((int)); |
100 | #endif | |
252b5132 RH |
101 | |
102 | #ifdef OBJ_XCOFF | |
103 | static void ppc_comm PARAMS ((int)); | |
104 | static void ppc_bb PARAMS ((int)); | |
105 | static void ppc_bc PARAMS ((int)); | |
106 | static void ppc_bf PARAMS ((int)); | |
107 | static void ppc_biei PARAMS ((int)); | |
108 | static void ppc_bs PARAMS ((int)); | |
109 | static void ppc_eb PARAMS ((int)); | |
110 | static void ppc_ec PARAMS ((int)); | |
111 | static void ppc_ef PARAMS ((int)); | |
112 | static void ppc_es PARAMS ((int)); | |
113 | static void ppc_csect PARAMS ((int)); | |
114 | static void ppc_change_csect PARAMS ((symbolS *)); | |
115 | static void ppc_function PARAMS ((int)); | |
116 | static void ppc_extern PARAMS ((int)); | |
117 | static void ppc_lglobl PARAMS ((int)); | |
118 | static void ppc_section PARAMS ((int)); | |
119 | static void ppc_named_section PARAMS ((int)); | |
120 | static void ppc_stabx PARAMS ((int)); | |
121 | static void ppc_rename PARAMS ((int)); | |
122 | static void ppc_toc PARAMS ((int)); | |
123 | static void ppc_xcoff_cons PARAMS ((int)); | |
124 | static void ppc_vbyte PARAMS ((int)); | |
125 | #endif | |
126 | ||
127 | #ifdef OBJ_ELF | |
128 | static bfd_reloc_code_real_type ppc_elf_suffix PARAMS ((char **, expressionS *)); | |
129 | static void ppc_elf_cons PARAMS ((int)); | |
130 | static void ppc_elf_rdata PARAMS ((int)); | |
131 | static void ppc_elf_lcomm PARAMS ((int)); | |
132 | static void ppc_elf_validate_fix PARAMS ((fixS *, segT)); | |
6a0c61b7 | 133 | static void ppc_apuinfo_section_add PARAMS((unsigned int apu, unsigned int version)); |
252b5132 RH |
134 | #endif |
135 | ||
136 | #ifdef TE_PE | |
137 | static void ppc_set_current_section PARAMS ((segT)); | |
138 | static void ppc_previous PARAMS ((int)); | |
139 | static void ppc_pdata PARAMS ((int)); | |
140 | static void ppc_ydata PARAMS ((int)); | |
141 | static void ppc_reldata PARAMS ((int)); | |
142 | static void ppc_rdata PARAMS ((int)); | |
143 | static void ppc_ualong PARAMS ((int)); | |
144 | static void ppc_znop PARAMS ((int)); | |
145 | static void ppc_pe_comm PARAMS ((int)); | |
146 | static void ppc_pe_section PARAMS ((int)); | |
147 | static void ppc_pe_function PARAMS ((int)); | |
148 | static void ppc_pe_tocd PARAMS ((int)); | |
149 | #endif | |
150 | \f | |
151 | /* Generic assembler global variables which must be defined by all | |
152 | targets. */ | |
153 | ||
154 | #ifdef OBJ_ELF | |
155 | /* This string holds the chars that always start a comment. If the | |
156 | pre-processor is disabled, these aren't very useful. The macro | |
157 | tc_comment_chars points to this. We use this, rather than the | |
158 | usual comment_chars, so that we can switch for Solaris conventions. */ | |
159 | static const char ppc_solaris_comment_chars[] = "#!"; | |
160 | static const char ppc_eabi_comment_chars[] = "#"; | |
161 | ||
162 | #ifdef TARGET_SOLARIS_COMMENT | |
163 | const char *ppc_comment_chars = ppc_solaris_comment_chars; | |
164 | #else | |
165 | const char *ppc_comment_chars = ppc_eabi_comment_chars; | |
166 | #endif | |
167 | #else | |
168 | const char comment_chars[] = "#"; | |
169 | #endif | |
170 | ||
171 | /* Characters which start a comment at the beginning of a line. */ | |
172 | const char line_comment_chars[] = "#"; | |
173 | ||
174 | /* Characters which may be used to separate multiple commands on a | |
175 | single line. */ | |
176 | const char line_separator_chars[] = ";"; | |
177 | ||
178 | /* Characters which are used to indicate an exponent in a floating | |
179 | point number. */ | |
180 | const char EXP_CHARS[] = "eE"; | |
181 | ||
182 | /* Characters which mean that a number is a floating point constant, | |
183 | as in 0d1.0. */ | |
184 | const char FLT_CHARS[] = "dD"; | |
185 | \f | |
186 | /* The target specific pseudo-ops which we support. */ | |
187 | ||
188 | const pseudo_typeS md_pseudo_table[] = | |
189 | { | |
190 | /* Pseudo-ops which must be overridden. */ | |
191 | { "byte", ppc_byte, 0 }, | |
192 | ||
193 | #ifdef OBJ_XCOFF | |
194 | /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these | |
195 | legitimately belong in the obj-*.c file. However, XCOFF is based | |
196 | on COFF, and is only implemented for the RS/6000. We just use | |
197 | obj-coff.c, and add what we need here. */ | |
198 | { "comm", ppc_comm, 0 }, | |
199 | { "lcomm", ppc_comm, 1 }, | |
200 | { "bb", ppc_bb, 0 }, | |
201 | { "bc", ppc_bc, 0 }, | |
202 | { "bf", ppc_bf, 0 }, | |
203 | { "bi", ppc_biei, 0 }, | |
204 | { "bs", ppc_bs, 0 }, | |
205 | { "csect", ppc_csect, 0 }, | |
206 | { "data", ppc_section, 'd' }, | |
207 | { "eb", ppc_eb, 0 }, | |
208 | { "ec", ppc_ec, 0 }, | |
209 | { "ef", ppc_ef, 0 }, | |
210 | { "ei", ppc_biei, 1 }, | |
211 | { "es", ppc_es, 0 }, | |
212 | { "extern", ppc_extern, 0 }, | |
213 | { "function", ppc_function, 0 }, | |
214 | { "lglobl", ppc_lglobl, 0 }, | |
215 | { "rename", ppc_rename, 0 }, | |
216 | { "section", ppc_named_section, 0 }, | |
217 | { "stabx", ppc_stabx, 0 }, | |
218 | { "text", ppc_section, 't' }, | |
219 | { "toc", ppc_toc, 0 }, | |
220 | { "long", ppc_xcoff_cons, 2 }, | |
7f6d05e8 | 221 | { "llong", ppc_xcoff_cons, 3 }, |
252b5132 RH |
222 | { "word", ppc_xcoff_cons, 1 }, |
223 | { "short", ppc_xcoff_cons, 1 }, | |
224 | { "vbyte", ppc_vbyte, 0 }, | |
225 | #endif | |
226 | ||
227 | #ifdef OBJ_ELF | |
0baf16f2 AM |
228 | { "llong", ppc_elf_cons, 8 }, |
229 | { "quad", ppc_elf_cons, 8 }, | |
252b5132 RH |
230 | { "long", ppc_elf_cons, 4 }, |
231 | { "word", ppc_elf_cons, 2 }, | |
232 | { "short", ppc_elf_cons, 2 }, | |
233 | { "rdata", ppc_elf_rdata, 0 }, | |
234 | { "rodata", ppc_elf_rdata, 0 }, | |
235 | { "lcomm", ppc_elf_lcomm, 0 }, | |
2b3c4602 | 236 | { "file", (void (*) PARAMS ((int))) dwarf2_directive_file, 0 }, |
5d6f4f16 | 237 | { "loc", dwarf2_directive_loc, 0 }, |
252b5132 RH |
238 | #endif |
239 | ||
240 | #ifdef TE_PE | |
99a814a1 | 241 | /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */ |
252b5132 RH |
242 | { "previous", ppc_previous, 0 }, |
243 | { "pdata", ppc_pdata, 0 }, | |
244 | { "ydata", ppc_ydata, 0 }, | |
245 | { "reldata", ppc_reldata, 0 }, | |
246 | { "rdata", ppc_rdata, 0 }, | |
247 | { "ualong", ppc_ualong, 0 }, | |
248 | { "znop", ppc_znop, 0 }, | |
249 | { "comm", ppc_pe_comm, 0 }, | |
250 | { "lcomm", ppc_pe_comm, 1 }, | |
251 | { "section", ppc_pe_section, 0 }, | |
252 | { "function", ppc_pe_function,0 }, | |
253 | { "tocd", ppc_pe_tocd, 0 }, | |
254 | #endif | |
255 | ||
0baf16f2 | 256 | #if defined (OBJ_XCOFF) || defined (OBJ_ELF) |
252b5132 | 257 | { "tc", ppc_tc, 0 }, |
0baf16f2 AM |
258 | { "machine", ppc_machine, 0 }, |
259 | #endif | |
252b5132 RH |
260 | |
261 | { NULL, NULL, 0 } | |
262 | }; | |
263 | ||
264 | \f | |
99a814a1 AM |
265 | /* Predefined register names if -mregnames (or default for Windows NT). |
266 | In general, there are lots of them, in an attempt to be compatible | |
267 | with a number of other Windows NT assemblers. */ | |
252b5132 RH |
268 | |
269 | /* Structure to hold information about predefined registers. */ | |
270 | struct pd_reg | |
271 | { | |
272 | char *name; | |
273 | int value; | |
274 | }; | |
275 | ||
276 | /* List of registers that are pre-defined: | |
277 | ||
278 | Each general register has predefined names of the form: | |
279 | 1. r<reg_num> which has the value <reg_num>. | |
280 | 2. r.<reg_num> which has the value <reg_num>. | |
281 | ||
252b5132 RH |
282 | Each floating point register has predefined names of the form: |
283 | 1. f<reg_num> which has the value <reg_num>. | |
284 | 2. f.<reg_num> which has the value <reg_num>. | |
285 | ||
7a899fff C |
286 | Each vector unit register has predefined names of the form: |
287 | 1. v<reg_num> which has the value <reg_num>. | |
288 | 2. v.<reg_num> which has the value <reg_num>. | |
289 | ||
252b5132 RH |
290 | Each condition register has predefined names of the form: |
291 | 1. cr<reg_num> which has the value <reg_num>. | |
292 | 2. cr.<reg_num> which has the value <reg_num>. | |
293 | ||
294 | There are individual registers as well: | |
295 | sp or r.sp has the value 1 | |
296 | rtoc or r.toc has the value 2 | |
297 | fpscr has the value 0 | |
298 | xer has the value 1 | |
299 | lr has the value 8 | |
300 | ctr has the value 9 | |
301 | pmr has the value 0 | |
302 | dar has the value 19 | |
303 | dsisr has the value 18 | |
304 | dec has the value 22 | |
305 | sdr1 has the value 25 | |
306 | srr0 has the value 26 | |
307 | srr1 has the value 27 | |
308 | ||
81d4177b | 309 | The table is sorted. Suitable for searching by a binary search. */ |
252b5132 RH |
310 | |
311 | static const struct pd_reg pre_defined_registers[] = | |
312 | { | |
313 | { "cr.0", 0 }, /* Condition Registers */ | |
314 | { "cr.1", 1 }, | |
315 | { "cr.2", 2 }, | |
316 | { "cr.3", 3 }, | |
317 | { "cr.4", 4 }, | |
318 | { "cr.5", 5 }, | |
319 | { "cr.6", 6 }, | |
320 | { "cr.7", 7 }, | |
321 | ||
322 | { "cr0", 0 }, | |
323 | { "cr1", 1 }, | |
324 | { "cr2", 2 }, | |
325 | { "cr3", 3 }, | |
326 | { "cr4", 4 }, | |
327 | { "cr5", 5 }, | |
328 | { "cr6", 6 }, | |
329 | { "cr7", 7 }, | |
330 | ||
331 | { "ctr", 9 }, | |
332 | ||
333 | { "dar", 19 }, /* Data Access Register */ | |
334 | { "dec", 22 }, /* Decrementer */ | |
335 | { "dsisr", 18 }, /* Data Storage Interrupt Status Register */ | |
336 | ||
337 | { "f.0", 0 }, /* Floating point registers */ | |
81d4177b KH |
338 | { "f.1", 1 }, |
339 | { "f.10", 10 }, | |
340 | { "f.11", 11 }, | |
341 | { "f.12", 12 }, | |
342 | { "f.13", 13 }, | |
343 | { "f.14", 14 }, | |
344 | { "f.15", 15 }, | |
345 | { "f.16", 16 }, | |
346 | { "f.17", 17 }, | |
347 | { "f.18", 18 }, | |
348 | { "f.19", 19 }, | |
349 | { "f.2", 2 }, | |
350 | { "f.20", 20 }, | |
351 | { "f.21", 21 }, | |
352 | { "f.22", 22 }, | |
353 | { "f.23", 23 }, | |
354 | { "f.24", 24 }, | |
355 | { "f.25", 25 }, | |
356 | { "f.26", 26 }, | |
357 | { "f.27", 27 }, | |
358 | { "f.28", 28 }, | |
359 | { "f.29", 29 }, | |
360 | { "f.3", 3 }, | |
252b5132 RH |
361 | { "f.30", 30 }, |
362 | { "f.31", 31 }, | |
81d4177b KH |
363 | { "f.4", 4 }, |
364 | { "f.5", 5 }, | |
365 | { "f.6", 6 }, | |
366 | { "f.7", 7 }, | |
367 | { "f.8", 8 }, | |
368 | { "f.9", 9 }, | |
369 | ||
370 | { "f0", 0 }, | |
371 | { "f1", 1 }, | |
372 | { "f10", 10 }, | |
373 | { "f11", 11 }, | |
374 | { "f12", 12 }, | |
375 | { "f13", 13 }, | |
376 | { "f14", 14 }, | |
377 | { "f15", 15 }, | |
378 | { "f16", 16 }, | |
379 | { "f17", 17 }, | |
380 | { "f18", 18 }, | |
381 | { "f19", 19 }, | |
382 | { "f2", 2 }, | |
383 | { "f20", 20 }, | |
384 | { "f21", 21 }, | |
385 | { "f22", 22 }, | |
386 | { "f23", 23 }, | |
387 | { "f24", 24 }, | |
388 | { "f25", 25 }, | |
389 | { "f26", 26 }, | |
390 | { "f27", 27 }, | |
391 | { "f28", 28 }, | |
392 | { "f29", 29 }, | |
393 | { "f3", 3 }, | |
252b5132 RH |
394 | { "f30", 30 }, |
395 | { "f31", 31 }, | |
81d4177b KH |
396 | { "f4", 4 }, |
397 | { "f5", 5 }, | |
398 | { "f6", 6 }, | |
399 | { "f7", 7 }, | |
400 | { "f8", 8 }, | |
401 | { "f9", 9 }, | |
252b5132 RH |
402 | |
403 | { "fpscr", 0 }, | |
404 | ||
405 | { "lr", 8 }, /* Link Register */ | |
406 | ||
407 | { "pmr", 0 }, | |
408 | ||
409 | { "r.0", 0 }, /* General Purpose Registers */ | |
410 | { "r.1", 1 }, | |
411 | { "r.10", 10 }, | |
412 | { "r.11", 11 }, | |
413 | { "r.12", 12 }, | |
414 | { "r.13", 13 }, | |
415 | { "r.14", 14 }, | |
416 | { "r.15", 15 }, | |
417 | { "r.16", 16 }, | |
418 | { "r.17", 17 }, | |
419 | { "r.18", 18 }, | |
420 | { "r.19", 19 }, | |
421 | { "r.2", 2 }, | |
422 | { "r.20", 20 }, | |
423 | { "r.21", 21 }, | |
424 | { "r.22", 22 }, | |
425 | { "r.23", 23 }, | |
426 | { "r.24", 24 }, | |
427 | { "r.25", 25 }, | |
428 | { "r.26", 26 }, | |
429 | { "r.27", 27 }, | |
430 | { "r.28", 28 }, | |
431 | { "r.29", 29 }, | |
432 | { "r.3", 3 }, | |
433 | { "r.30", 30 }, | |
434 | { "r.31", 31 }, | |
435 | { "r.4", 4 }, | |
436 | { "r.5", 5 }, | |
437 | { "r.6", 6 }, | |
438 | { "r.7", 7 }, | |
439 | { "r.8", 8 }, | |
440 | { "r.9", 9 }, | |
441 | ||
442 | { "r.sp", 1 }, /* Stack Pointer */ | |
443 | ||
444 | { "r.toc", 2 }, /* Pointer to the table of contents */ | |
445 | ||
446 | { "r0", 0 }, /* More general purpose registers */ | |
447 | { "r1", 1 }, | |
448 | { "r10", 10 }, | |
449 | { "r11", 11 }, | |
450 | { "r12", 12 }, | |
451 | { "r13", 13 }, | |
452 | { "r14", 14 }, | |
453 | { "r15", 15 }, | |
454 | { "r16", 16 }, | |
455 | { "r17", 17 }, | |
456 | { "r18", 18 }, | |
457 | { "r19", 19 }, | |
458 | { "r2", 2 }, | |
459 | { "r20", 20 }, | |
460 | { "r21", 21 }, | |
461 | { "r22", 22 }, | |
462 | { "r23", 23 }, | |
463 | { "r24", 24 }, | |
464 | { "r25", 25 }, | |
465 | { "r26", 26 }, | |
466 | { "r27", 27 }, | |
467 | { "r28", 28 }, | |
468 | { "r29", 29 }, | |
469 | { "r3", 3 }, | |
470 | { "r30", 30 }, | |
471 | { "r31", 31 }, | |
472 | { "r4", 4 }, | |
473 | { "r5", 5 }, | |
474 | { "r6", 6 }, | |
475 | { "r7", 7 }, | |
476 | { "r8", 8 }, | |
477 | { "r9", 9 }, | |
478 | ||
479 | { "rtoc", 2 }, /* Table of contents */ | |
480 | ||
481 | { "sdr1", 25 }, /* Storage Description Register 1 */ | |
482 | ||
483 | { "sp", 1 }, | |
484 | ||
485 | { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */ | |
486 | { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */ | |
81d4177b | 487 | |
7a899fff | 488 | { "v.0", 0 }, /* Vector registers */ |
81d4177b KH |
489 | { "v.1", 1 }, |
490 | { "v.10", 10 }, | |
491 | { "v.11", 11 }, | |
492 | { "v.12", 12 }, | |
493 | { "v.13", 13 }, | |
494 | { "v.14", 14 }, | |
495 | { "v.15", 15 }, | |
496 | { "v.16", 16 }, | |
497 | { "v.17", 17 }, | |
498 | { "v.18", 18 }, | |
499 | { "v.19", 19 }, | |
500 | { "v.2", 2 }, | |
501 | { "v.20", 20 }, | |
502 | { "v.21", 21 }, | |
503 | { "v.22", 22 }, | |
504 | { "v.23", 23 }, | |
505 | { "v.24", 24 }, | |
506 | { "v.25", 25 }, | |
507 | { "v.26", 26 }, | |
508 | { "v.27", 27 }, | |
509 | { "v.28", 28 }, | |
510 | { "v.29", 29 }, | |
511 | { "v.3", 3 }, | |
7a899fff C |
512 | { "v.30", 30 }, |
513 | { "v.31", 31 }, | |
81d4177b KH |
514 | { "v.4", 4 }, |
515 | { "v.5", 5 }, | |
516 | { "v.6", 6 }, | |
517 | { "v.7", 7 }, | |
518 | { "v.8", 8 }, | |
519 | { "v.9", 9 }, | |
7a899fff C |
520 | |
521 | { "v0", 0 }, | |
81d4177b KH |
522 | { "v1", 1 }, |
523 | { "v10", 10 }, | |
524 | { "v11", 11 }, | |
525 | { "v12", 12 }, | |
526 | { "v13", 13 }, | |
527 | { "v14", 14 }, | |
528 | { "v15", 15 }, | |
529 | { "v16", 16 }, | |
530 | { "v17", 17 }, | |
531 | { "v18", 18 }, | |
532 | { "v19", 19 }, | |
533 | { "v2", 2 }, | |
534 | { "v20", 20 }, | |
535 | { "v21", 21 }, | |
536 | { "v22", 22 }, | |
537 | { "v23", 23 }, | |
538 | { "v24", 24 }, | |
539 | { "v25", 25 }, | |
540 | { "v26", 26 }, | |
541 | { "v27", 27 }, | |
542 | { "v28", 28 }, | |
543 | { "v29", 29 }, | |
544 | { "v3", 3 }, | |
7a899fff C |
545 | { "v30", 30 }, |
546 | { "v31", 31 }, | |
81d4177b KH |
547 | { "v4", 4 }, |
548 | { "v5", 5 }, | |
549 | { "v6", 6 }, | |
550 | { "v7", 7 }, | |
551 | { "v8", 8 }, | |
7a899fff | 552 | { "v9", 9 }, |
252b5132 RH |
553 | |
554 | { "xer", 1 }, | |
555 | ||
556 | }; | |
557 | ||
bc805888 | 558 | #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg)) |
252b5132 RH |
559 | |
560 | /* Given NAME, find the register number associated with that name, return | |
561 | the integer value associated with the given name or -1 on failure. */ | |
562 | ||
563 | static int reg_name_search | |
564 | PARAMS ((const struct pd_reg *, int, const char * name)); | |
565 | ||
566 | static int | |
567 | reg_name_search (regs, regcount, name) | |
568 | const struct pd_reg *regs; | |
569 | int regcount; | |
570 | const char *name; | |
571 | { | |
572 | int middle, low, high; | |
573 | int cmp; | |
574 | ||
575 | low = 0; | |
576 | high = regcount - 1; | |
577 | ||
578 | do | |
579 | { | |
580 | middle = (low + high) / 2; | |
581 | cmp = strcasecmp (name, regs[middle].name); | |
582 | if (cmp < 0) | |
583 | high = middle - 1; | |
584 | else if (cmp > 0) | |
585 | low = middle + 1; | |
586 | else | |
587 | return regs[middle].value; | |
588 | } | |
589 | while (low <= high); | |
590 | ||
591 | return -1; | |
592 | } | |
593 | ||
594 | /* | |
99a814a1 | 595 | * Summary of register_name. |
252b5132 RH |
596 | * |
597 | * in: Input_line_pointer points to 1st char of operand. | |
598 | * | |
599 | * out: A expressionS. | |
600 | * The operand may have been a register: in this case, X_op == O_register, | |
601 | * X_add_number is set to the register number, and truth is returned. | |
602 | * Input_line_pointer->(next non-blank) char after operand, or is in its | |
603 | * original state. | |
604 | */ | |
605 | ||
606 | static boolean | |
607 | register_name (expressionP) | |
608 | expressionS *expressionP; | |
609 | { | |
610 | int reg_number; | |
611 | char *name; | |
612 | char *start; | |
613 | char c; | |
614 | ||
99a814a1 | 615 | /* Find the spelling of the operand. */ |
252b5132 | 616 | start = name = input_line_pointer; |
3882b010 | 617 | if (name[0] == '%' && ISALPHA (name[1])) |
252b5132 RH |
618 | name = ++input_line_pointer; |
619 | ||
3882b010 | 620 | else if (!reg_names_p || !ISALPHA (name[0])) |
252b5132 RH |
621 | return false; |
622 | ||
623 | c = get_symbol_end (); | |
624 | reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name); | |
625 | ||
468cced8 AM |
626 | /* Put back the delimiting char. */ |
627 | *input_line_pointer = c; | |
628 | ||
99a814a1 | 629 | /* Look to see if it's in the register table. */ |
81d4177b | 630 | if (reg_number >= 0) |
252b5132 RH |
631 | { |
632 | expressionP->X_op = O_register; | |
633 | expressionP->X_add_number = reg_number; | |
81d4177b | 634 | |
99a814a1 | 635 | /* Make the rest nice. */ |
252b5132 RH |
636 | expressionP->X_add_symbol = NULL; |
637 | expressionP->X_op_symbol = NULL; | |
252b5132 RH |
638 | return true; |
639 | } | |
468cced8 AM |
640 | |
641 | /* Reset the line as if we had not done anything. */ | |
642 | input_line_pointer = start; | |
643 | return false; | |
252b5132 RH |
644 | } |
645 | \f | |
646 | /* This function is called for each symbol seen in an expression. It | |
647 | handles the special parsing which PowerPC assemblers are supposed | |
648 | to use for condition codes. */ | |
649 | ||
650 | /* Whether to do the special parsing. */ | |
651 | static boolean cr_operand; | |
652 | ||
653 | /* Names to recognize in a condition code. This table is sorted. */ | |
654 | static const struct pd_reg cr_names[] = | |
655 | { | |
656 | { "cr0", 0 }, | |
657 | { "cr1", 1 }, | |
658 | { "cr2", 2 }, | |
659 | { "cr3", 3 }, | |
660 | { "cr4", 4 }, | |
661 | { "cr5", 5 }, | |
662 | { "cr6", 6 }, | |
663 | { "cr7", 7 }, | |
664 | { "eq", 2 }, | |
665 | { "gt", 1 }, | |
666 | { "lt", 0 }, | |
667 | { "so", 3 }, | |
668 | { "un", 3 } | |
669 | }; | |
670 | ||
671 | /* Parsing function. This returns non-zero if it recognized an | |
672 | expression. */ | |
673 | ||
674 | int | |
675 | ppc_parse_name (name, expr) | |
676 | const char *name; | |
677 | expressionS *expr; | |
678 | { | |
679 | int val; | |
680 | ||
681 | if (! cr_operand) | |
682 | return 0; | |
683 | ||
684 | val = reg_name_search (cr_names, sizeof cr_names / sizeof cr_names[0], | |
685 | name); | |
686 | if (val < 0) | |
687 | return 0; | |
688 | ||
689 | expr->X_op = O_constant; | |
690 | expr->X_add_number = val; | |
691 | ||
692 | return 1; | |
693 | } | |
694 | \f | |
695 | /* Local variables. */ | |
696 | ||
697 | /* The type of processor we are assembling for. This is one or more | |
698 | of the PPC_OPCODE flags defined in opcode/ppc.h. */ | |
2b3c4602 | 699 | static unsigned long ppc_cpu = 0; |
252b5132 | 700 | |
2b3c4602 AM |
701 | /* Whether to target xcoff64/elf64. */ |
702 | static unsigned int ppc_obj64 = BFD_DEFAULT_TARGET_SIZE == 64; | |
7f6d05e8 | 703 | |
252b5132 RH |
704 | /* Opcode hash table. */ |
705 | static struct hash_control *ppc_hash; | |
706 | ||
707 | /* Macro hash table. */ | |
708 | static struct hash_control *ppc_macro_hash; | |
709 | ||
710 | #ifdef OBJ_ELF | |
99a814a1 | 711 | /* What type of shared library support to use. */ |
5d6f4f16 | 712 | static enum { SHLIB_NONE, SHLIB_PIC, SHLIB_MRELOCATABLE } shlib = SHLIB_NONE; |
252b5132 | 713 | |
99a814a1 | 714 | /* Flags to set in the elf header. */ |
252b5132 RH |
715 | static flagword ppc_flags = 0; |
716 | ||
717 | /* Whether this is Solaris or not. */ | |
718 | #ifdef TARGET_SOLARIS_COMMENT | |
719 | #define SOLARIS_P true | |
720 | #else | |
721 | #define SOLARIS_P false | |
722 | #endif | |
723 | ||
724 | static boolean msolaris = SOLARIS_P; | |
725 | #endif | |
726 | ||
727 | #ifdef OBJ_XCOFF | |
728 | ||
729 | /* The RS/6000 assembler uses the .csect pseudo-op to generate code | |
730 | using a bunch of different sections. These assembler sections, | |
731 | however, are all encompassed within the .text or .data sections of | |
732 | the final output file. We handle this by using different | |
733 | subsegments within these main segments. */ | |
734 | ||
735 | /* Next subsegment to allocate within the .text segment. */ | |
736 | static subsegT ppc_text_subsegment = 2; | |
737 | ||
738 | /* Linked list of csects in the text section. */ | |
739 | static symbolS *ppc_text_csects; | |
740 | ||
741 | /* Next subsegment to allocate within the .data segment. */ | |
742 | static subsegT ppc_data_subsegment = 2; | |
743 | ||
744 | /* Linked list of csects in the data section. */ | |
745 | static symbolS *ppc_data_csects; | |
746 | ||
747 | /* The current csect. */ | |
748 | static symbolS *ppc_current_csect; | |
749 | ||
750 | /* The RS/6000 assembler uses a TOC which holds addresses of functions | |
751 | and variables. Symbols are put in the TOC with the .tc pseudo-op. | |
752 | A special relocation is used when accessing TOC entries. We handle | |
753 | the TOC as a subsegment within the .data segment. We set it up if | |
754 | we see a .toc pseudo-op, and save the csect symbol here. */ | |
755 | static symbolS *ppc_toc_csect; | |
756 | ||
757 | /* The first frag in the TOC subsegment. */ | |
758 | static fragS *ppc_toc_frag; | |
759 | ||
760 | /* The first frag in the first subsegment after the TOC in the .data | |
761 | segment. NULL if there are no subsegments after the TOC. */ | |
762 | static fragS *ppc_after_toc_frag; | |
763 | ||
764 | /* The current static block. */ | |
765 | static symbolS *ppc_current_block; | |
766 | ||
767 | /* The COFF debugging section; set by md_begin. This is not the | |
768 | .debug section, but is instead the secret BFD section which will | |
769 | cause BFD to set the section number of a symbol to N_DEBUG. */ | |
770 | static asection *ppc_coff_debug_section; | |
771 | ||
772 | #endif /* OBJ_XCOFF */ | |
773 | ||
774 | #ifdef TE_PE | |
775 | ||
776 | /* Various sections that we need for PE coff support. */ | |
777 | static segT ydata_section; | |
778 | static segT pdata_section; | |
779 | static segT reldata_section; | |
780 | static segT rdata_section; | |
781 | static segT tocdata_section; | |
782 | ||
81d4177b | 783 | /* The current section and the previous section. See ppc_previous. */ |
252b5132 RH |
784 | static segT ppc_previous_section; |
785 | static segT ppc_current_section; | |
786 | ||
787 | #endif /* TE_PE */ | |
788 | ||
789 | #ifdef OBJ_ELF | |
790 | symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */ | |
6a0c61b7 EZ |
791 | #define PPC_APUINFO_ISEL 0x40 |
792 | #define PPC_APUINFO_PMR 0x41 | |
793 | #define PPC_APUINFO_RFMCI 0x42 | |
794 | #define PPC_APUINFO_CACHELCK 0x43 | |
795 | #define PPC_APUINFO_SPE 0x100 | |
796 | #define PPC_APUINFO_EFS 0x101 | |
797 | #define PPC_APUINFO_BRLOCK 0x102 | |
798 | ||
799 | /* | |
800 | * We keep a list of APUinfo | |
801 | */ | |
802 | unsigned long *ppc_apuinfo_list; | |
803 | unsigned int ppc_apuinfo_num; | |
804 | unsigned int ppc_apuinfo_num_alloc; | |
252b5132 RH |
805 | #endif /* OBJ_ELF */ |
806 | \f | |
807 | #ifdef OBJ_ELF | |
15c1449b | 808 | const char *const md_shortopts = "b:l:usm:K:VQ:"; |
252b5132 | 809 | #else |
15c1449b | 810 | const char *const md_shortopts = "um:"; |
252b5132 | 811 | #endif |
15c1449b | 812 | const struct option md_longopts[] = { |
252b5132 RH |
813 | {NULL, no_argument, NULL, 0} |
814 | }; | |
15c1449b | 815 | const size_t md_longopts_size = sizeof (md_longopts); |
252b5132 RH |
816 | |
817 | int | |
818 | md_parse_option (c, arg) | |
819 | int c; | |
820 | char *arg; | |
821 | { | |
822 | switch (c) | |
823 | { | |
824 | case 'u': | |
825 | /* -u means that any undefined symbols should be treated as | |
826 | external, which is the default for gas anyhow. */ | |
827 | break; | |
828 | ||
829 | #ifdef OBJ_ELF | |
830 | case 'l': | |
831 | /* Solaris as takes -le (presumably for little endian). For completeness | |
99a814a1 | 832 | sake, recognize -be also. */ |
252b5132 RH |
833 | if (strcmp (arg, "e") == 0) |
834 | { | |
835 | target_big_endian = 0; | |
836 | set_target_endian = 1; | |
837 | } | |
838 | else | |
839 | return 0; | |
840 | ||
841 | break; | |
842 | ||
843 | case 'b': | |
844 | if (strcmp (arg, "e") == 0) | |
845 | { | |
846 | target_big_endian = 1; | |
847 | set_target_endian = 1; | |
848 | } | |
849 | else | |
850 | return 0; | |
851 | ||
852 | break; | |
853 | ||
854 | case 'K': | |
99a814a1 | 855 | /* Recognize -K PIC. */ |
252b5132 RH |
856 | if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0) |
857 | { | |
858 | shlib = SHLIB_PIC; | |
859 | ppc_flags |= EF_PPC_RELOCATABLE_LIB; | |
860 | } | |
861 | else | |
862 | return 0; | |
863 | ||
864 | break; | |
865 | #endif | |
866 | ||
7f6d05e8 CP |
867 | /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */ |
868 | case 'a': | |
869 | if (strcmp (arg, "64") == 0) | |
2b3c4602 | 870 | ppc_obj64 = 1; |
7f6d05e8 | 871 | else if (strcmp (arg, "32") == 0) |
2b3c4602 | 872 | ppc_obj64 = 0; |
7f6d05e8 CP |
873 | else |
874 | return 0; | |
875 | break; | |
81d4177b | 876 | |
252b5132 RH |
877 | case 'm': |
878 | /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2 | |
99a814a1 | 879 | (RIOS2). */ |
252b5132 | 880 | if (strcmp (arg, "pwrx") == 0 || strcmp (arg, "pwr2") == 0) |
2b3c4602 | 881 | ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2 | PPC_OPCODE_32; |
252b5132 RH |
882 | /* -mpwr means to assemble for the IBM POWER (RIOS1). */ |
883 | else if (strcmp (arg, "pwr") == 0) | |
2b3c4602 | 884 | ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_32; |
23e1d84c | 885 | /* -m601 means to assemble for the PowerPC 601, which includes |
99a814a1 | 886 | instructions that are holdovers from the Power. */ |
252b5132 | 887 | else if (strcmp (arg, "601") == 0) |
6a0c61b7 EZ |
888 | ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC |
889 | | PPC_OPCODE_601 | PPC_OPCODE_32; | |
252b5132 | 890 | /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the |
23e1d84c | 891 | PowerPC 603/604. */ |
252b5132 RH |
892 | else if (strcmp (arg, "ppc") == 0 |
893 | || strcmp (arg, "ppc32") == 0 | |
252b5132 RH |
894 | || strcmp (arg, "603") == 0 |
895 | || strcmp (arg, "604") == 0) | |
6a0c61b7 | 896 | ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_32; |
23e1d84c | 897 | /* -m403 and -m405 mean to assemble for the PowerPC 403/405. */ |
418c1742 MG |
898 | else if (strcmp (arg, "403") == 0 |
899 | || strcmp (arg, "405") == 0) | |
6a0c61b7 EZ |
900 | ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC |
901 | | PPC_OPCODE_403 | PPC_OPCODE_32; | |
418c1742 MG |
902 | else if (strcmp (arg, "7400") == 0 |
903 | || strcmp (arg, "7410") == 0 | |
904 | || strcmp (arg, "7450") == 0 | |
905 | || strcmp (arg, "7455") == 0) | |
6a0c61b7 EZ |
906 | ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC |
907 | | PPC_OPCODE_ALTIVEC | PPC_OPCODE_32; | |
418c1742 | 908 | else if (strcmp (arg, "altivec") == 0) |
8a588659 MG |
909 | { |
910 | if (ppc_cpu == 0) | |
6a0c61b7 | 911 | ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_ALTIVEC; |
8a588659 MG |
912 | else |
913 | ppc_cpu |= PPC_OPCODE_ALTIVEC; | |
914 | } | |
6a0c61b7 EZ |
915 | else if (strcmp (arg, "e500") == 0 || strcmp (arg, "e500x2") == 0) |
916 | { | |
917 | ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_BOOKE | PPC_OPCODE_SPE | |
918 | | PPC_OPCODE_ISEL | PPC_OPCODE_EFS | PPC_OPCODE_BRLOCK | |
919 | | PPC_OPCODE_PMR | PPC_OPCODE_CACHELCK | PPC_OPCODE_RFMCI; | |
920 | } | |
921 | else if (strcmp (arg, "spe") == 0) | |
922 | { | |
923 | if (ppc_cpu == 0) | |
924 | ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_SPE | PPC_OPCODE_EFS; | |
925 | else | |
926 | ppc_cpu |= PPC_OPCODE_SPE; | |
927 | } | |
252b5132 | 928 | /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC |
99a814a1 | 929 | 620. */ |
252b5132 RH |
930 | else if (strcmp (arg, "ppc64") == 0 || strcmp (arg, "620") == 0) |
931 | { | |
6a0c61b7 | 932 | ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_64; |
252b5132 | 933 | } |
d0e9a01c RH |
934 | else if (strcmp (arg, "ppc64bridge") == 0) |
935 | { | |
6a0c61b7 EZ |
936 | ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC |
937 | | PPC_OPCODE_64_BRIDGE | PPC_OPCODE_64; | |
418c1742 MG |
938 | } |
939 | /* -mbooke/-mbooke32 mean enable 32-bit BookE support. */ | |
940 | else if (strcmp (arg, "booke") == 0 || strcmp (arg, "booke32") == 0) | |
6a0c61b7 EZ |
941 | { |
942 | ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_BOOKE | PPC_OPCODE_32; | |
943 | } | |
418c1742 MG |
944 | /* -mbooke64 means enable 64-bit BookE support. */ |
945 | else if (strcmp (arg, "booke64") == 0) | |
946 | { | |
5d6255fe | 947 | ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_BOOKE | |
418c1742 | 948 | PPC_OPCODE_BOOKE64 | PPC_OPCODE_64; |
d0e9a01c | 949 | } |
23e1d84c AM |
950 | else if (strcmp (arg, "power4") == 0) |
951 | { | |
6a0c61b7 EZ |
952 | ppc_cpu = PPC_OPCODE_PPC| PPC_OPCODE_CLASSIC |
953 | | PPC_OPCODE_64 | PPC_OPCODE_POWER4; | |
23e1d84c | 954 | } |
252b5132 RH |
955 | /* -mcom means assemble for the common intersection between Power |
956 | and PowerPC. At present, we just allow the union, rather | |
957 | than the intersection. */ | |
958 | else if (strcmp (arg, "com") == 0) | |
2b3c4602 | 959 | ppc_cpu = PPC_OPCODE_COMMON | PPC_OPCODE_32; |
252b5132 RH |
960 | /* -many means to assemble for any architecture (PWR/PWRX/PPC). */ |
961 | else if (strcmp (arg, "any") == 0) | |
2b3c4602 | 962 | ppc_cpu = PPC_OPCODE_ANY | PPC_OPCODE_32; |
252b5132 RH |
963 | |
964 | else if (strcmp (arg, "regnames") == 0) | |
965 | reg_names_p = true; | |
966 | ||
967 | else if (strcmp (arg, "no-regnames") == 0) | |
968 | reg_names_p = false; | |
969 | ||
970 | #ifdef OBJ_ELF | |
99a814a1 AM |
971 | /* -mrelocatable/-mrelocatable-lib -- warn about initializations |
972 | that require relocation. */ | |
252b5132 RH |
973 | else if (strcmp (arg, "relocatable") == 0) |
974 | { | |
5d6f4f16 | 975 | shlib = SHLIB_MRELOCATABLE; |
252b5132 RH |
976 | ppc_flags |= EF_PPC_RELOCATABLE; |
977 | } | |
978 | ||
979 | else if (strcmp (arg, "relocatable-lib") == 0) | |
980 | { | |
5d6f4f16 | 981 | shlib = SHLIB_MRELOCATABLE; |
252b5132 RH |
982 | ppc_flags |= EF_PPC_RELOCATABLE_LIB; |
983 | } | |
984 | ||
99a814a1 | 985 | /* -memb, set embedded bit. */ |
252b5132 RH |
986 | else if (strcmp (arg, "emb") == 0) |
987 | ppc_flags |= EF_PPC_EMB; | |
988 | ||
99a814a1 AM |
989 | /* -mlittle/-mbig set the endianess. */ |
990 | else if (strcmp (arg, "little") == 0 | |
991 | || strcmp (arg, "little-endian") == 0) | |
252b5132 RH |
992 | { |
993 | target_big_endian = 0; | |
994 | set_target_endian = 1; | |
995 | } | |
996 | ||
997 | else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0) | |
998 | { | |
999 | target_big_endian = 1; | |
1000 | set_target_endian = 1; | |
1001 | } | |
1002 | ||
1003 | else if (strcmp (arg, "solaris") == 0) | |
1004 | { | |
1005 | msolaris = true; | |
1006 | ppc_comment_chars = ppc_solaris_comment_chars; | |
1007 | } | |
1008 | ||
1009 | else if (strcmp (arg, "no-solaris") == 0) | |
1010 | { | |
1011 | msolaris = false; | |
1012 | ppc_comment_chars = ppc_eabi_comment_chars; | |
1013 | } | |
1014 | #endif | |
1015 | else | |
1016 | { | |
1017 | as_bad (_("invalid switch -m%s"), arg); | |
1018 | return 0; | |
1019 | } | |
1020 | break; | |
1021 | ||
1022 | #ifdef OBJ_ELF | |
1023 | /* -V: SVR4 argument to print version ID. */ | |
1024 | case 'V': | |
1025 | print_version_id (); | |
1026 | break; | |
1027 | ||
1028 | /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section | |
1029 | should be emitted or not. FIXME: Not implemented. */ | |
1030 | case 'Q': | |
1031 | break; | |
1032 | ||
1033 | /* Solaris takes -s to specify that .stabs go in a .stabs section, | |
1034 | rather than .stabs.excl, which is ignored by the linker. | |
1035 | FIXME: Not implemented. */ | |
1036 | case 's': | |
1037 | if (arg) | |
1038 | return 0; | |
1039 | ||
1040 | break; | |
1041 | #endif | |
1042 | ||
1043 | default: | |
1044 | return 0; | |
1045 | } | |
1046 | ||
1047 | return 1; | |
1048 | } | |
1049 | ||
1050 | void | |
1051 | md_show_usage (stream) | |
1052 | FILE *stream; | |
1053 | { | |
bc805888 | 1054 | fprintf (stream, _("\ |
252b5132 RH |
1055 | PowerPC options:\n\ |
1056 | -u ignored\n\ | |
23e1d84c AM |
1057 | -mpwrx, -mpwr2 generate code for POWER/2 (RIOS2)\n\ |
1058 | -mpwr generate code for POWER (RIOS1)\n\ | |
1059 | -m601 generate code for PowerPC 601\n\ | |
418c1742 | 1060 | -mppc, -mppc32, -m603, -m604\n\ |
23e1d84c AM |
1061 | generate code for PowerPC 603/604\n\ |
1062 | -m403, -m405 generate code for PowerPC 403/405\n\ | |
f5c120c5 | 1063 | -m7400, -m7410, -m7450, -m7455\n\ |
23e1d84c AM |
1064 | generate code For PowerPC 7400/7410/7450/7455\n\ |
1065 | -mppc64, -m620 generate code for PowerPC 620/625/630\n\ | |
d0e9a01c | 1066 | -mppc64bridge generate code for PowerPC 64, including bridge insns\n\ |
a09cf9bd MG |
1067 | -mbooke64 generate code for 64-bit PowerPC BookE\n\ |
1068 | -mbooke, mbooke32 generate code for 32-bit PowerPC BookE\n\ | |
23e1d84c | 1069 | -mpower4 generate code for Power4 architecture\n\ |
f5c120c5 | 1070 | -maltivec generate code for AltiVec\n\ |
252b5132 RH |
1071 | -mcom generate code Power/PowerPC common instructions\n\ |
1072 | -many generate code for any architecture (PWR/PWRX/PPC)\n\ | |
1073 | -mregnames Allow symbolic names for registers\n\ | |
1074 | -mno-regnames Do not allow symbolic names for registers\n")); | |
6a0c61b7 EZ |
1075 | fprintf (stream, _("\ |
1076 | -me500, -me500x2 generate code for Motorola e500 core complex\n\ | |
1077 | -mspe generate code for Motorola SPE instructions\n")); | |
252b5132 | 1078 | #ifdef OBJ_ELF |
bc805888 | 1079 | fprintf (stream, _("\ |
252b5132 RH |
1080 | -mrelocatable support for GCC's -mrelocatble option\n\ |
1081 | -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\ | |
1082 | -memb set PPC_EMB bit in ELF flags\n\ | |
1083 | -mlittle, -mlittle-endian\n\ | |
1084 | generate code for a little endian machine\n\ | |
1085 | -mbig, -mbig-endian generate code for a big endian machine\n\ | |
1086 | -msolaris generate code for Solaris\n\ | |
1087 | -mno-solaris do not generate code for Solaris\n\ | |
1088 | -V print assembler version number\n\ | |
1089 | -Qy, -Qn ignored\n")); | |
1090 | #endif | |
1091 | } | |
1092 | \f | |
1093 | /* Set ppc_cpu if it is not already set. */ | |
1094 | ||
1095 | static void | |
1096 | ppc_set_cpu () | |
1097 | { | |
1098 | const char *default_os = TARGET_OS; | |
1099 | const char *default_cpu = TARGET_CPU; | |
1100 | ||
1101 | if (ppc_cpu == 0) | |
1102 | { | |
1103 | if (strncmp (default_os, "aix", 3) == 0 | |
1104 | && default_os[3] >= '4' && default_os[3] <= '9') | |
2b3c4602 | 1105 | ppc_cpu = PPC_OPCODE_COMMON | PPC_OPCODE_32; |
252b5132 | 1106 | else if (strncmp (default_os, "aix3", 4) == 0) |
2b3c4602 | 1107 | ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_32; |
252b5132 | 1108 | else if (strcmp (default_cpu, "rs6000") == 0) |
2b3c4602 | 1109 | ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_32; |
0baf16f2 | 1110 | else if (strncmp (default_cpu, "powerpc", 7) == 0) |
6a0c61b7 EZ |
1111 | { |
1112 | if (default_cpu[7] == '6' && default_cpu[8] == '4') | |
1113 | ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_64; | |
1114 | else | |
1115 | ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_32; | |
1116 | } | |
252b5132 | 1117 | else |
99a814a1 AM |
1118 | as_fatal (_("Unknown default cpu = %s, os = %s"), |
1119 | default_cpu, default_os); | |
252b5132 RH |
1120 | } |
1121 | } | |
1122 | ||
1123 | /* Figure out the BFD architecture to use. */ | |
1124 | ||
1125 | enum bfd_architecture | |
1126 | ppc_arch () | |
1127 | { | |
1128 | const char *default_cpu = TARGET_CPU; | |
1129 | ppc_set_cpu (); | |
1130 | ||
1131 | if ((ppc_cpu & PPC_OPCODE_PPC) != 0) | |
1132 | return bfd_arch_powerpc; | |
1133 | else if ((ppc_cpu & PPC_OPCODE_POWER) != 0) | |
1134 | return bfd_arch_rs6000; | |
1135 | else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0) | |
1136 | { | |
1137 | if (strcmp (default_cpu, "rs6000") == 0) | |
1138 | return bfd_arch_rs6000; | |
0baf16f2 | 1139 | else if (strncmp (default_cpu, "powerpc", 7) == 0) |
252b5132 RH |
1140 | return bfd_arch_powerpc; |
1141 | } | |
1142 | ||
1143 | as_fatal (_("Neither Power nor PowerPC opcodes were selected.")); | |
1144 | return bfd_arch_unknown; | |
1145 | } | |
1146 | ||
7f6d05e8 CP |
1147 | unsigned long |
1148 | ppc_mach () | |
1149 | { | |
2b3c4602 | 1150 | return ppc_obj64 ? bfd_mach_ppc64 : bfd_mach_ppc; |
7f6d05e8 CP |
1151 | } |
1152 | ||
81d4177b | 1153 | extern char* |
99a814a1 | 1154 | ppc_target_format () |
7f6d05e8 CP |
1155 | { |
1156 | #ifdef OBJ_COFF | |
1157 | #ifdef TE_PE | |
99a814a1 | 1158 | return target_big_endian ? "pe-powerpc" : "pe-powerpcle"; |
7f6d05e8 | 1159 | #elif TE_POWERMAC |
0baf16f2 | 1160 | return "xcoff-powermac"; |
7f6d05e8 | 1161 | #else |
eb1e0e80 | 1162 | # ifdef TE_AIX5 |
2b3c4602 | 1163 | return (ppc_obj64 ? "aix5coff64-rs6000" : "aixcoff-rs6000"); |
eb1e0e80 | 1164 | # else |
2b3c4602 | 1165 | return (ppc_obj64 ? "aixcoff64-rs6000" : "aixcoff-rs6000"); |
eb1e0e80 | 1166 | # endif |
7f6d05e8 | 1167 | #endif |
7f6d05e8 CP |
1168 | #endif |
1169 | #ifdef OBJ_ELF | |
0baf16f2 | 1170 | return (target_big_endian |
2b3c4602 AM |
1171 | ? (ppc_obj64 ? "elf64-powerpc" : "elf32-powerpc") |
1172 | : (ppc_obj64 ? "elf64-powerpcle" : "elf32-powerpcle")); | |
7f6d05e8 CP |
1173 | #endif |
1174 | } | |
1175 | ||
252b5132 RH |
1176 | /* This function is called when the assembler starts up. It is called |
1177 | after the options have been parsed and the output file has been | |
1178 | opened. */ | |
1179 | ||
1180 | void | |
1181 | md_begin () | |
1182 | { | |
1183 | register const struct powerpc_opcode *op; | |
1184 | const struct powerpc_opcode *op_end; | |
1185 | const struct powerpc_macro *macro; | |
1186 | const struct powerpc_macro *macro_end; | |
1187 | boolean dup_insn = false; | |
1188 | ||
1189 | ppc_set_cpu (); | |
1190 | ||
1191 | #ifdef OBJ_ELF | |
81d4177b | 1192 | /* Set the ELF flags if desired. */ |
252b5132 RH |
1193 | if (ppc_flags && !msolaris) |
1194 | bfd_set_private_flags (stdoutput, ppc_flags); | |
1195 | #endif | |
1196 | ||
1197 | /* Insert the opcodes into a hash table. */ | |
1198 | ppc_hash = hash_new (); | |
1199 | ||
1200 | op_end = powerpc_opcodes + powerpc_num_opcodes; | |
1201 | for (op = powerpc_opcodes; op < op_end; op++) | |
1202 | { | |
1203 | know ((op->opcode & op->mask) == op->opcode); | |
1204 | ||
2b3c4602 | 1205 | if ((op->flags & ppc_cpu & ~(PPC_OPCODE_32 | PPC_OPCODE_64)) != 0 |
252b5132 | 1206 | && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0 |
2b3c4602 AM |
1207 | || ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) |
1208 | == (ppc_cpu & (PPC_OPCODE_32 | PPC_OPCODE_64))) | |
23e1d84c AM |
1209 | || (ppc_cpu & PPC_OPCODE_64_BRIDGE) != 0) |
1210 | && ((op->flags & (PPC_OPCODE_POWER4 | PPC_OPCODE_NOPOWER4)) == 0 | |
1211 | || ((op->flags & PPC_OPCODE_POWER4) | |
1212 | == (ppc_cpu & PPC_OPCODE_POWER4)))) | |
252b5132 RH |
1213 | { |
1214 | const char *retval; | |
1215 | ||
1216 | retval = hash_insert (ppc_hash, op->name, (PTR) op); | |
1217 | if (retval != (const char *) NULL) | |
1218 | { | |
99a814a1 | 1219 | /* Ignore Power duplicates for -m601. */ |
252b5132 RH |
1220 | if ((ppc_cpu & PPC_OPCODE_601) != 0 |
1221 | && (op->flags & PPC_OPCODE_POWER) != 0) | |
1222 | continue; | |
1223 | ||
99a814a1 AM |
1224 | as_bad (_("Internal assembler error for instruction %s"), |
1225 | op->name); | |
252b5132 RH |
1226 | dup_insn = true; |
1227 | } | |
1228 | } | |
1229 | } | |
1230 | ||
1231 | /* Insert the macros into a hash table. */ | |
1232 | ppc_macro_hash = hash_new (); | |
1233 | ||
1234 | macro_end = powerpc_macros + powerpc_num_macros; | |
1235 | for (macro = powerpc_macros; macro < macro_end; macro++) | |
1236 | { | |
1237 | if ((macro->flags & ppc_cpu) != 0) | |
1238 | { | |
1239 | const char *retval; | |
1240 | ||
1241 | retval = hash_insert (ppc_macro_hash, macro->name, (PTR) macro); | |
1242 | if (retval != (const char *) NULL) | |
1243 | { | |
1244 | as_bad (_("Internal assembler error for macro %s"), macro->name); | |
1245 | dup_insn = true; | |
1246 | } | |
1247 | } | |
1248 | } | |
1249 | ||
1250 | if (dup_insn) | |
1251 | abort (); | |
1252 | ||
99a814a1 AM |
1253 | /* Tell the main code what the endianness is if it is not overidden |
1254 | by the user. */ | |
252b5132 RH |
1255 | if (!set_target_endian) |
1256 | { | |
1257 | set_target_endian = 1; | |
1258 | target_big_endian = PPC_BIG_ENDIAN; | |
1259 | } | |
1260 | ||
1261 | #ifdef OBJ_XCOFF | |
1262 | ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG); | |
1263 | ||
1264 | /* Create dummy symbols to serve as initial csects. This forces the | |
1265 | text csects to precede the data csects. These symbols will not | |
1266 | be output. */ | |
1267 | ppc_text_csects = symbol_make ("dummy\001"); | |
809ffe0d | 1268 | symbol_get_tc (ppc_text_csects)->within = ppc_text_csects; |
252b5132 | 1269 | ppc_data_csects = symbol_make ("dummy\001"); |
809ffe0d | 1270 | symbol_get_tc (ppc_data_csects)->within = ppc_data_csects; |
252b5132 RH |
1271 | #endif |
1272 | ||
1273 | #ifdef TE_PE | |
1274 | ||
1275 | ppc_current_section = text_section; | |
81d4177b | 1276 | ppc_previous_section = 0; |
252b5132 RH |
1277 | |
1278 | #endif | |
1279 | } | |
1280 | ||
6a0c61b7 EZ |
1281 | void |
1282 | ppc_cleanup () | |
1283 | { | |
1284 | if (ppc_apuinfo_list == NULL) | |
1285 | return; | |
1286 | ||
1287 | /* Ok, so write the section info out. We have this layout: | |
1288 | ||
1289 | byte data what | |
1290 | ---- ---- ---- | |
1291 | 0 8 length of "APUinfo\0" | |
1292 | 4 (n*4) number of APU's (4 bytes each) | |
1293 | 8 2 note type 2 | |
1294 | 12 "APUinfo\0" name | |
1295 | 20 APU#1 first APU's info | |
1296 | 24 APU#2 second APU's info | |
1297 | ... ... | |
1298 | */ | |
1299 | { | |
1300 | char *p; | |
1301 | asection *seg = now_seg; | |
1302 | subsegT subseg = now_subseg; | |
1303 | asection *apuinfo_secp = (asection *) NULL; | |
1304 | int i; | |
1305 | ||
1306 | /* Create the .PPC.EMB.apuinfo section. */ | |
1307 | apuinfo_secp = subseg_new (".PPC.EMB.apuinfo", 0); | |
1308 | bfd_set_section_flags (stdoutput, | |
1309 | apuinfo_secp, | |
1310 | SEC_HAS_CONTENTS | SEC_READONLY | SEC_MERGE); | |
1311 | ||
1312 | p = frag_more (4); | |
1313 | md_number_to_chars (p, (valueT) 8, 4); | |
1314 | ||
1315 | p = frag_more (4); | |
1316 | md_number_to_chars (p, (valueT) ppc_apuinfo_num, 4); | |
1317 | ||
1318 | p = frag_more (4); | |
1319 | md_number_to_chars (p, (valueT) 2, 4); | |
1320 | ||
1321 | p = frag_more (8); | |
1322 | strcpy (p, "APUinfo"); | |
1323 | ||
1324 | for (i = 0; i < ppc_apuinfo_num; i++) | |
1325 | { | |
1326 | p = frag_more (4); | |
1327 | md_number_to_chars (p, (valueT) ppc_apuinfo_list[i], 4); | |
1328 | } | |
1329 | ||
1330 | frag_align (2, 0, 0); | |
1331 | ||
1332 | /* We probably can't restore the current segment, for there likely | |
1333 | isn't one yet... */ | |
1334 | if (seg && subseg) | |
1335 | subseg_set (seg, subseg); | |
1336 | } | |
1337 | } | |
1338 | ||
252b5132 RH |
1339 | /* Insert an operand value into an instruction. */ |
1340 | ||
1341 | static unsigned long | |
1342 | ppc_insert_operand (insn, operand, val, file, line) | |
1343 | unsigned long insn; | |
1344 | const struct powerpc_operand *operand; | |
1345 | offsetT val; | |
1346 | char *file; | |
1347 | unsigned int line; | |
1348 | { | |
1349 | if (operand->bits != 32) | |
1350 | { | |
1351 | long min, max; | |
1352 | offsetT test; | |
1353 | ||
1354 | if ((operand->flags & PPC_OPERAND_SIGNED) != 0) | |
1355 | { | |
d0e9a01c | 1356 | if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0) |
252b5132 RH |
1357 | max = (1 << operand->bits) - 1; |
1358 | else | |
1359 | max = (1 << (operand->bits - 1)) - 1; | |
1360 | min = - (1 << (operand->bits - 1)); | |
1361 | ||
2b3c4602 | 1362 | if (!ppc_obj64) |
252b5132 RH |
1363 | { |
1364 | /* Some people write 32 bit hex constants with the sign | |
1365 | extension done by hand. This shouldn't really be | |
1366 | valid, but, to permit this code to assemble on a 64 | |
1367 | bit host, we sign extend the 32 bit value. */ | |
1368 | if (val > 0 | |
92161534 ILT |
1369 | && (val & (offsetT) 0x80000000) != 0 |
1370 | && (val & (offsetT) 0xffffffff) == val) | |
252b5132 RH |
1371 | { |
1372 | val -= 0x80000000; | |
1373 | val -= 0x80000000; | |
1374 | } | |
1375 | } | |
1376 | } | |
1377 | else | |
1378 | { | |
1379 | max = (1 << operand->bits) - 1; | |
1380 | min = 0; | |
1381 | } | |
1382 | ||
1383 | if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0) | |
1384 | test = - val; | |
1385 | else | |
1386 | test = val; | |
1387 | ||
1388 | if (test < (offsetT) min || test > (offsetT) max) | |
1389 | { | |
1390 | const char *err = | |
1391 | _("operand out of range (%s not between %ld and %ld)"); | |
1392 | char buf[100]; | |
1393 | ||
1394 | sprint_value (buf, test); | |
0baf16f2 | 1395 | as_bad_where (file, line, err, buf, min, max); |
252b5132 RH |
1396 | } |
1397 | } | |
1398 | ||
1399 | if (operand->insert) | |
1400 | { | |
1401 | const char *errmsg; | |
1402 | ||
1403 | errmsg = NULL; | |
2b3c4602 | 1404 | insn = (*operand->insert) (insn, (long) val, ppc_cpu, &errmsg); |
252b5132 | 1405 | if (errmsg != (const char *) NULL) |
0baf16f2 | 1406 | as_bad_where (file, line, errmsg); |
252b5132 RH |
1407 | } |
1408 | else | |
1409 | insn |= (((long) val & ((1 << operand->bits) - 1)) | |
1410 | << operand->shift); | |
1411 | ||
1412 | return insn; | |
1413 | } | |
1414 | ||
1415 | \f | |
1416 | #ifdef OBJ_ELF | |
1417 | /* Parse @got, etc. and return the desired relocation. */ | |
1418 | static bfd_reloc_code_real_type | |
1419 | ppc_elf_suffix (str_p, exp_p) | |
1420 | char **str_p; | |
1421 | expressionS *exp_p; | |
1422 | { | |
1423 | struct map_bfd { | |
1424 | char *string; | |
1425 | int length; | |
15c1449b | 1426 | int reloc; |
252b5132 RH |
1427 | }; |
1428 | ||
1429 | char ident[20]; | |
1430 | char *str = *str_p; | |
1431 | char *str2; | |
1432 | int ch; | |
1433 | int len; | |
15c1449b | 1434 | const struct map_bfd *ptr; |
252b5132 | 1435 | |
bc805888 | 1436 | #define MAP(str,reloc) { str, sizeof (str)-1, reloc } |
252b5132 | 1437 | |
15c1449b AM |
1438 | static const struct map_bfd mapping[] = { |
1439 | MAP ("l", (int) BFD_RELOC_LO16), | |
1440 | MAP ("h", (int) BFD_RELOC_HI16), | |
1441 | MAP ("ha", (int) BFD_RELOC_HI16_S), | |
1442 | MAP ("brtaken", (int) BFD_RELOC_PPC_B16_BRTAKEN), | |
1443 | MAP ("brntaken", (int) BFD_RELOC_PPC_B16_BRNTAKEN), | |
1444 | MAP ("got", (int) BFD_RELOC_16_GOTOFF), | |
1445 | MAP ("got@l", (int) BFD_RELOC_LO16_GOTOFF), | |
1446 | MAP ("got@h", (int) BFD_RELOC_HI16_GOTOFF), | |
1447 | MAP ("got@ha", (int) BFD_RELOC_HI16_S_GOTOFF), | |
1448 | MAP ("fixup", (int) BFD_RELOC_CTOR), /* warning with -mrelocatable */ | |
1449 | MAP ("plt", (int) BFD_RELOC_24_PLT_PCREL), | |
1450 | MAP ("pltrel24", (int) BFD_RELOC_24_PLT_PCREL), | |
1451 | MAP ("copy", (int) BFD_RELOC_PPC_COPY), | |
1452 | MAP ("globdat", (int) BFD_RELOC_PPC_GLOB_DAT), | |
1453 | MAP ("local24pc", (int) BFD_RELOC_PPC_LOCAL24PC), | |
1454 | MAP ("local", (int) BFD_RELOC_PPC_LOCAL24PC), | |
1455 | MAP ("pltrel", (int) BFD_RELOC_32_PLT_PCREL), | |
1456 | MAP ("plt@l", (int) BFD_RELOC_LO16_PLTOFF), | |
1457 | MAP ("plt@h", (int) BFD_RELOC_HI16_PLTOFF), | |
1458 | MAP ("plt@ha", (int) BFD_RELOC_HI16_S_PLTOFF), | |
1459 | MAP ("sdarel", (int) BFD_RELOC_GPREL16), | |
1cfc59d5 | 1460 | MAP ("sectoff", (int) BFD_RELOC_16_BASEREL), |
15c1449b AM |
1461 | MAP ("sectoff@l", (int) BFD_RELOC_LO16_BASEREL), |
1462 | MAP ("sectoff@h", (int) BFD_RELOC_HI16_BASEREL), | |
1463 | MAP ("sectoff@ha", (int) BFD_RELOC_HI16_S_BASEREL), | |
1464 | MAP ("naddr", (int) BFD_RELOC_PPC_EMB_NADDR32), | |
1465 | MAP ("naddr16", (int) BFD_RELOC_PPC_EMB_NADDR16), | |
1466 | MAP ("naddr@l", (int) BFD_RELOC_PPC_EMB_NADDR16_LO), | |
1467 | MAP ("naddr@h", (int) BFD_RELOC_PPC_EMB_NADDR16_HI), | |
1468 | MAP ("naddr@ha", (int) BFD_RELOC_PPC_EMB_NADDR16_HA), | |
1469 | MAP ("sdai16", (int) BFD_RELOC_PPC_EMB_SDAI16), | |
1470 | MAP ("sda2rel", (int) BFD_RELOC_PPC_EMB_SDA2REL), | |
1471 | MAP ("sda2i16", (int) BFD_RELOC_PPC_EMB_SDA2I16), | |
1472 | MAP ("sda21", (int) BFD_RELOC_PPC_EMB_SDA21), | |
1473 | MAP ("mrkref", (int) BFD_RELOC_PPC_EMB_MRKREF), | |
1474 | MAP ("relsect", (int) BFD_RELOC_PPC_EMB_RELSEC16), | |
1475 | MAP ("relsect@l", (int) BFD_RELOC_PPC_EMB_RELST_LO), | |
1476 | MAP ("relsect@h", (int) BFD_RELOC_PPC_EMB_RELST_HI), | |
1477 | MAP ("relsect@ha", (int) BFD_RELOC_PPC_EMB_RELST_HA), | |
1478 | MAP ("bitfld", (int) BFD_RELOC_PPC_EMB_BIT_FLD), | |
1479 | MAP ("relsda", (int) BFD_RELOC_PPC_EMB_RELSDA), | |
1480 | MAP ("xgot", (int) BFD_RELOC_PPC_TOC16), | |
2b3c4602 AM |
1481 | /* The following are only valid for ppc64. Negative values are |
1482 | used instead of a flag. */ | |
15c1449b AM |
1483 | MAP ("higher", - (int) BFD_RELOC_PPC64_HIGHER), |
1484 | MAP ("highera", - (int) BFD_RELOC_PPC64_HIGHER_S), | |
1485 | MAP ("highest", - (int) BFD_RELOC_PPC64_HIGHEST), | |
1486 | MAP ("highesta", - (int) BFD_RELOC_PPC64_HIGHEST_S), | |
1487 | MAP ("tocbase", - (int) BFD_RELOC_PPC64_TOC), | |
1488 | MAP ("toc", - (int) BFD_RELOC_PPC_TOC16), | |
1489 | MAP ("toc@l", - (int) BFD_RELOC_PPC64_TOC16_LO), | |
1490 | MAP ("toc@h", - (int) BFD_RELOC_PPC64_TOC16_HI), | |
1491 | MAP ("toc@ha", - (int) BFD_RELOC_PPC64_TOC16_HA), | |
15c1449b | 1492 | { (char *) 0, 0, (int) BFD_RELOC_UNUSED } |
252b5132 RH |
1493 | }; |
1494 | ||
1495 | if (*str++ != '@') | |
1496 | return BFD_RELOC_UNUSED; | |
1497 | ||
1498 | for (ch = *str, str2 = ident; | |
1499 | (str2 < ident + sizeof (ident) - 1 | |
3882b010 | 1500 | && (ISALNUM (ch) || ch == '@')); |
252b5132 RH |
1501 | ch = *++str) |
1502 | { | |
3882b010 | 1503 | *str2++ = TOLOWER (ch); |
252b5132 RH |
1504 | } |
1505 | ||
1506 | *str2 = '\0'; | |
1507 | len = str2 - ident; | |
1508 | ||
1509 | ch = ident[0]; | |
1510 | for (ptr = &mapping[0]; ptr->length > 0; ptr++) | |
1511 | if (ch == ptr->string[0] | |
1512 | && len == ptr->length | |
1513 | && memcmp (ident, ptr->string, ptr->length) == 0) | |
1514 | { | |
15c1449b AM |
1515 | int reloc = ptr->reloc; |
1516 | ||
2b3c4602 | 1517 | if (reloc < 0) |
15c1449b | 1518 | { |
2b3c4602 | 1519 | if (!ppc_obj64) |
15c1449b AM |
1520 | return BFD_RELOC_UNUSED; |
1521 | reloc = -reloc; | |
1522 | } | |
1523 | ||
252b5132 | 1524 | if (exp_p->X_add_number != 0 |
15c1449b AM |
1525 | && (reloc == (int) BFD_RELOC_16_GOTOFF |
1526 | || reloc == (int) BFD_RELOC_LO16_GOTOFF | |
1527 | || reloc == (int) BFD_RELOC_HI16_GOTOFF | |
1528 | || reloc == (int) BFD_RELOC_HI16_S_GOTOFF)) | |
252b5132 RH |
1529 | as_warn (_("identifier+constant@got means identifier@got+constant")); |
1530 | ||
99a814a1 | 1531 | /* Now check for identifier@suffix+constant. */ |
252b5132 RH |
1532 | if (*str == '-' || *str == '+') |
1533 | { | |
1534 | char *orig_line = input_line_pointer; | |
1535 | expressionS new_exp; | |
1536 | ||
1537 | input_line_pointer = str; | |
1538 | expression (&new_exp); | |
1539 | if (new_exp.X_op == O_constant) | |
1540 | { | |
1541 | exp_p->X_add_number += new_exp.X_add_number; | |
1542 | str = input_line_pointer; | |
1543 | } | |
1544 | ||
1545 | if (&input_line_pointer != str_p) | |
1546 | input_line_pointer = orig_line; | |
1547 | } | |
252b5132 | 1548 | *str_p = str; |
0baf16f2 | 1549 | |
2b3c4602 | 1550 | if (reloc == (int) BFD_RELOC_PPC64_TOC |
0baf16f2 AM |
1551 | && exp_p->X_op == O_symbol) |
1552 | { | |
1553 | /* This reloc type ignores the symbol. Change the symbol | |
1554 | so that the dummy .TOC. symbol can be omitted from the | |
1555 | object file. */ | |
1556 | exp_p->X_add_symbol = &abs_symbol; | |
1557 | } | |
1558 | ||
15c1449b | 1559 | return (bfd_reloc_code_real_type) reloc; |
252b5132 RH |
1560 | } |
1561 | ||
1562 | return BFD_RELOC_UNUSED; | |
1563 | } | |
1564 | ||
99a814a1 AM |
1565 | /* Like normal .long/.short/.word, except support @got, etc. |
1566 | Clobbers input_line_pointer, checks end-of-line. */ | |
252b5132 RH |
1567 | static void |
1568 | ppc_elf_cons (nbytes) | |
0baf16f2 | 1569 | register int nbytes; /* 1=.byte, 2=.word, 4=.long, 8=.llong. */ |
252b5132 RH |
1570 | { |
1571 | expressionS exp; | |
1572 | bfd_reloc_code_real_type reloc; | |
1573 | ||
1574 | if (is_it_end_of_statement ()) | |
1575 | { | |
1576 | demand_empty_rest_of_line (); | |
1577 | return; | |
1578 | } | |
1579 | ||
1580 | do | |
1581 | { | |
1582 | expression (&exp); | |
1583 | if (exp.X_op == O_symbol | |
1584 | && *input_line_pointer == '@' | |
99a814a1 AM |
1585 | && (reloc = ppc_elf_suffix (&input_line_pointer, |
1586 | &exp)) != BFD_RELOC_UNUSED) | |
252b5132 | 1587 | { |
99a814a1 AM |
1588 | reloc_howto_type *reloc_howto; |
1589 | int size; | |
1590 | ||
1591 | reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc); | |
1592 | size = bfd_get_reloc_size (reloc_howto); | |
252b5132 RH |
1593 | |
1594 | if (size > nbytes) | |
0baf16f2 AM |
1595 | { |
1596 | as_bad (_("%s relocations do not fit in %d bytes\n"), | |
1597 | reloc_howto->name, nbytes); | |
1598 | } | |
252b5132 RH |
1599 | else |
1600 | { | |
0baf16f2 AM |
1601 | char *p; |
1602 | int offset; | |
252b5132 | 1603 | |
0baf16f2 AM |
1604 | p = frag_more (nbytes); |
1605 | offset = 0; | |
1606 | if (target_big_endian) | |
1607 | offset = nbytes - size; | |
99a814a1 AM |
1608 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, |
1609 | &exp, 0, reloc); | |
252b5132 RH |
1610 | } |
1611 | } | |
1612 | else | |
1613 | emit_expr (&exp, (unsigned int) nbytes); | |
1614 | } | |
1615 | while (*input_line_pointer++ == ','); | |
1616 | ||
99a814a1 AM |
1617 | /* Put terminator back into stream. */ |
1618 | input_line_pointer--; | |
252b5132 RH |
1619 | demand_empty_rest_of_line (); |
1620 | } | |
1621 | ||
1622 | /* Solaris pseduo op to change to the .rodata section. */ | |
1623 | static void | |
1624 | ppc_elf_rdata (xxx) | |
1625 | int xxx; | |
1626 | { | |
1627 | char *save_line = input_line_pointer; | |
1628 | static char section[] = ".rodata\n"; | |
1629 | ||
99a814a1 | 1630 | /* Just pretend this is .section .rodata */ |
252b5132 RH |
1631 | input_line_pointer = section; |
1632 | obj_elf_section (xxx); | |
1633 | ||
1634 | input_line_pointer = save_line; | |
1635 | } | |
1636 | ||
99a814a1 | 1637 | /* Pseudo op to make file scope bss items. */ |
252b5132 | 1638 | static void |
99a814a1 | 1639 | ppc_elf_lcomm (xxx) |
92161534 | 1640 | int xxx ATTRIBUTE_UNUSED; |
252b5132 RH |
1641 | { |
1642 | register char *name; | |
1643 | register char c; | |
1644 | register char *p; | |
1645 | offsetT size; | |
1646 | register symbolS *symbolP; | |
1647 | offsetT align; | |
1648 | segT old_sec; | |
1649 | int old_subsec; | |
1650 | char *pfrag; | |
1651 | int align2; | |
1652 | ||
1653 | name = input_line_pointer; | |
1654 | c = get_symbol_end (); | |
1655 | ||
99a814a1 | 1656 | /* just after name is now '\0'. */ |
252b5132 RH |
1657 | p = input_line_pointer; |
1658 | *p = c; | |
1659 | SKIP_WHITESPACE (); | |
1660 | if (*input_line_pointer != ',') | |
1661 | { | |
1662 | as_bad (_("Expected comma after symbol-name: rest of line ignored.")); | |
1663 | ignore_rest_of_line (); | |
1664 | return; | |
1665 | } | |
1666 | ||
1667 | input_line_pointer++; /* skip ',' */ | |
1668 | if ((size = get_absolute_expression ()) < 0) | |
1669 | { | |
1670 | as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size); | |
1671 | ignore_rest_of_line (); | |
1672 | return; | |
1673 | } | |
1674 | ||
1675 | /* The third argument to .lcomm is the alignment. */ | |
1676 | if (*input_line_pointer != ',') | |
1677 | align = 8; | |
1678 | else | |
1679 | { | |
1680 | ++input_line_pointer; | |
1681 | align = get_absolute_expression (); | |
1682 | if (align <= 0) | |
1683 | { | |
1684 | as_warn (_("ignoring bad alignment")); | |
1685 | align = 8; | |
1686 | } | |
1687 | } | |
1688 | ||
1689 | *p = 0; | |
1690 | symbolP = symbol_find_or_make (name); | |
1691 | *p = c; | |
1692 | ||
1693 | if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP)) | |
1694 | { | |
1695 | as_bad (_("Ignoring attempt to re-define symbol `%s'."), | |
1696 | S_GET_NAME (symbolP)); | |
1697 | ignore_rest_of_line (); | |
1698 | return; | |
1699 | } | |
1700 | ||
1701 | if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size) | |
1702 | { | |
1703 | as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."), | |
1704 | S_GET_NAME (symbolP), | |
1705 | (long) S_GET_VALUE (symbolP), | |
1706 | (long) size); | |
1707 | ||
1708 | ignore_rest_of_line (); | |
1709 | return; | |
1710 | } | |
1711 | ||
99a814a1 | 1712 | /* Allocate_bss. */ |
252b5132 RH |
1713 | old_sec = now_seg; |
1714 | old_subsec = now_subseg; | |
1715 | if (align) | |
1716 | { | |
99a814a1 | 1717 | /* Convert to a power of 2 alignment. */ |
252b5132 RH |
1718 | for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2); |
1719 | if (align != 1) | |
1720 | { | |
1721 | as_bad (_("Common alignment not a power of 2")); | |
1722 | ignore_rest_of_line (); | |
1723 | return; | |
1724 | } | |
1725 | } | |
1726 | else | |
1727 | align2 = 0; | |
1728 | ||
1729 | record_alignment (bss_section, align2); | |
1730 | subseg_set (bss_section, 0); | |
1731 | if (align2) | |
1732 | frag_align (align2, 0, 0); | |
1733 | if (S_GET_SEGMENT (symbolP) == bss_section) | |
49309057 ILT |
1734 | symbol_get_frag (symbolP)->fr_symbol = 0; |
1735 | symbol_set_frag (symbolP, frag_now); | |
252b5132 RH |
1736 | pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size, |
1737 | (char *) 0); | |
1738 | *pfrag = 0; | |
1739 | S_SET_SIZE (symbolP, size); | |
1740 | S_SET_SEGMENT (symbolP, bss_section); | |
1741 | subseg_set (old_sec, old_subsec); | |
1742 | demand_empty_rest_of_line (); | |
1743 | } | |
1744 | ||
1745 | /* Validate any relocations emitted for -mrelocatable, possibly adding | |
1746 | fixups for word relocations in writable segments, so we can adjust | |
1747 | them at runtime. */ | |
1748 | static void | |
1749 | ppc_elf_validate_fix (fixp, seg) | |
1750 | fixS *fixp; | |
1751 | segT seg; | |
1752 | { | |
1753 | if (fixp->fx_done || fixp->fx_pcrel) | |
1754 | return; | |
1755 | ||
1756 | switch (shlib) | |
1757 | { | |
1758 | case SHLIB_NONE: | |
1759 | case SHLIB_PIC: | |
1760 | return; | |
1761 | ||
5d6f4f16 | 1762 | case SHLIB_MRELOCATABLE: |
252b5132 RH |
1763 | if (fixp->fx_r_type <= BFD_RELOC_UNUSED |
1764 | && fixp->fx_r_type != BFD_RELOC_16_GOTOFF | |
1765 | && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF | |
1766 | && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF | |
1767 | && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF | |
1cfc59d5 | 1768 | && fixp->fx_r_type != BFD_RELOC_16_BASEREL |
252b5132 RH |
1769 | && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL |
1770 | && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL | |
1771 | && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL | |
e138127a | 1772 | && (seg->flags & SEC_LOAD) != 0 |
252b5132 RH |
1773 | && strcmp (segment_name (seg), ".got2") != 0 |
1774 | && strcmp (segment_name (seg), ".dtors") != 0 | |
1775 | && strcmp (segment_name (seg), ".ctors") != 0 | |
1776 | && strcmp (segment_name (seg), ".fixup") != 0 | |
252b5132 RH |
1777 | && strcmp (segment_name (seg), ".gcc_except_table") != 0 |
1778 | && strcmp (segment_name (seg), ".eh_frame") != 0 | |
1779 | && strcmp (segment_name (seg), ".ex_shared") != 0) | |
1780 | { | |
1781 | if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0 | |
1782 | || fixp->fx_r_type != BFD_RELOC_CTOR) | |
1783 | { | |
1784 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
1785 | _("Relocation cannot be done when using -mrelocatable")); | |
1786 | } | |
1787 | } | |
1788 | return; | |
1789 | } | |
1790 | } | |
0baf16f2 | 1791 | |
7e8d4ab4 AM |
1792 | /* Prevent elf_frob_file_before_adjust removing a weak undefined |
1793 | function descriptor sym if the corresponding code sym is used. */ | |
1794 | ||
1795 | void | |
1796 | ppc_frob_file_before_adjust () | |
0baf16f2 | 1797 | { |
7e8d4ab4 | 1798 | symbolS *symp; |
0baf16f2 | 1799 | |
7e8d4ab4 AM |
1800 | if (!ppc_obj64) |
1801 | return; | |
1802 | ||
1803 | for (symp = symbol_rootP; symp; symp = symbol_next (symp)) | |
0baf16f2 | 1804 | { |
7e8d4ab4 AM |
1805 | const char *name; |
1806 | char *dotname; | |
1807 | symbolS *dotsym; | |
1808 | size_t len; | |
1809 | ||
1810 | name = S_GET_NAME (symp); | |
1811 | if (name[0] == '.') | |
1812 | continue; | |
1813 | ||
1814 | if (! S_IS_WEAK (symp) | |
1815 | || S_IS_DEFINED (symp)) | |
1816 | continue; | |
1817 | ||
1818 | len = strlen (name) + 1; | |
1819 | dotname = xmalloc (len + 1); | |
1820 | dotname[0] = '.'; | |
1821 | memcpy (dotname + 1, name, len); | |
1822 | dotsym = symbol_find (dotname); | |
1823 | free (dotname); | |
1824 | if (dotsym != NULL && (symbol_used_p (dotsym) | |
1825 | || symbol_used_in_reloc_p (dotsym))) | |
1826 | { | |
1827 | symbol_mark_used (symp); | |
1828 | } | |
0baf16f2 AM |
1829 | } |
1830 | ||
7e8d4ab4 AM |
1831 | /* Don't emit .TOC. symbol. */ |
1832 | symp = symbol_find (".TOC."); | |
1833 | if (symp != NULL) | |
1834 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); | |
0baf16f2 | 1835 | } |
252b5132 RH |
1836 | #endif /* OBJ_ELF */ |
1837 | \f | |
1838 | #ifdef TE_PE | |
1839 | ||
1840 | /* | |
99a814a1 | 1841 | * Summary of parse_toc_entry. |
252b5132 RH |
1842 | * |
1843 | * in: Input_line_pointer points to the '[' in one of: | |
1844 | * | |
1845 | * [toc] [tocv] [toc32] [toc64] | |
1846 | * | |
1847 | * Anything else is an error of one kind or another. | |
1848 | * | |
81d4177b | 1849 | * out: |
252b5132 RH |
1850 | * return value: success or failure |
1851 | * toc_kind: kind of toc reference | |
1852 | * input_line_pointer: | |
1853 | * success: first char after the ']' | |
1854 | * failure: unchanged | |
1855 | * | |
1856 | * settings: | |
1857 | * | |
1858 | * [toc] - rv == success, toc_kind = default_toc | |
1859 | * [tocv] - rv == success, toc_kind = data_in_toc | |
1860 | * [toc32] - rv == success, toc_kind = must_be_32 | |
1861 | * [toc64] - rv == success, toc_kind = must_be_64 | |
1862 | * | |
1863 | */ | |
1864 | ||
81d4177b KH |
1865 | enum toc_size_qualifier |
1866 | { | |
252b5132 RH |
1867 | default_toc, /* The toc cell constructed should be the system default size */ |
1868 | data_in_toc, /* This is a direct reference to a toc cell */ | |
1869 | must_be_32, /* The toc cell constructed must be 32 bits wide */ | |
1870 | must_be_64 /* The toc cell constructed must be 64 bits wide */ | |
1871 | }; | |
1872 | ||
1873 | static int | |
99a814a1 | 1874 | parse_toc_entry (toc_kind) |
252b5132 RH |
1875 | enum toc_size_qualifier *toc_kind; |
1876 | { | |
1877 | char *start; | |
1878 | char *toc_spec; | |
1879 | char c; | |
1880 | enum toc_size_qualifier t; | |
1881 | ||
99a814a1 | 1882 | /* Save the input_line_pointer. */ |
252b5132 RH |
1883 | start = input_line_pointer; |
1884 | ||
99a814a1 | 1885 | /* Skip over the '[' , and whitespace. */ |
252b5132 RH |
1886 | ++input_line_pointer; |
1887 | SKIP_WHITESPACE (); | |
81d4177b | 1888 | |
99a814a1 | 1889 | /* Find the spelling of the operand. */ |
252b5132 RH |
1890 | toc_spec = input_line_pointer; |
1891 | c = get_symbol_end (); | |
1892 | ||
99a814a1 | 1893 | if (strcmp (toc_spec, "toc") == 0) |
252b5132 RH |
1894 | { |
1895 | t = default_toc; | |
1896 | } | |
99a814a1 | 1897 | else if (strcmp (toc_spec, "tocv") == 0) |
252b5132 RH |
1898 | { |
1899 | t = data_in_toc; | |
1900 | } | |
99a814a1 | 1901 | else if (strcmp (toc_spec, "toc32") == 0) |
252b5132 RH |
1902 | { |
1903 | t = must_be_32; | |
1904 | } | |
99a814a1 | 1905 | else if (strcmp (toc_spec, "toc64") == 0) |
252b5132 RH |
1906 | { |
1907 | t = must_be_64; | |
1908 | } | |
1909 | else | |
1910 | { | |
1911 | as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec); | |
99a814a1 AM |
1912 | *input_line_pointer = c; |
1913 | input_line_pointer = start; | |
252b5132 RH |
1914 | return 0; |
1915 | } | |
1916 | ||
99a814a1 AM |
1917 | /* Now find the ']'. */ |
1918 | *input_line_pointer = c; | |
252b5132 | 1919 | |
81d4177b KH |
1920 | SKIP_WHITESPACE (); /* leading whitespace could be there. */ |
1921 | c = *input_line_pointer++; /* input_line_pointer->past char in c. */ | |
252b5132 RH |
1922 | |
1923 | if (c != ']') | |
1924 | { | |
1925 | as_bad (_("syntax error: expected `]', found `%c'"), c); | |
99a814a1 | 1926 | input_line_pointer = start; |
252b5132 RH |
1927 | return 0; |
1928 | } | |
1929 | ||
99a814a1 | 1930 | *toc_kind = t; |
252b5132 RH |
1931 | return 1; |
1932 | } | |
1933 | #endif | |
1934 | \f | |
1935 | ||
6a0c61b7 EZ |
1936 | #define APUID(a,v) ((((a) & 0xffff) << 16) | ((v) & 0xffff)) |
1937 | static void | |
1938 | ppc_apuinfo_section_add(apu, version) | |
1939 | unsigned int apu, version; | |
1940 | { | |
1941 | unsigned int i; | |
1942 | ||
1943 | /* Check we don't already exist. */ | |
1944 | for (i = 0; i < ppc_apuinfo_num; i++) | |
1945 | if (ppc_apuinfo_list[i] == APUID(apu, version)) | |
1946 | return; | |
1947 | ||
1948 | if (ppc_apuinfo_num == ppc_apuinfo_num_alloc) | |
1949 | { | |
1950 | if (ppc_apuinfo_num_alloc == 0) | |
1951 | { | |
1952 | ppc_apuinfo_num_alloc = 4; | |
1953 | ppc_apuinfo_list = (unsigned long *) | |
1954 | xmalloc (sizeof (unsigned long) * ppc_apuinfo_num_alloc); | |
1955 | } | |
1956 | else | |
1957 | { | |
1958 | ppc_apuinfo_num_alloc += 4; | |
1959 | ppc_apuinfo_list = (unsigned long *) xrealloc (ppc_apuinfo_list, | |
1960 | sizeof (unsigned long) * ppc_apuinfo_num_alloc); | |
1961 | } | |
1962 | } | |
1963 | ppc_apuinfo_list[ppc_apuinfo_num++] = APUID(apu, version); | |
1964 | } | |
1965 | #undef APUID | |
1966 | \f | |
1967 | ||
252b5132 RH |
1968 | /* We need to keep a list of fixups. We can't simply generate them as |
1969 | we go, because that would require us to first create the frag, and | |
1970 | that would screw up references to ``.''. */ | |
1971 | ||
1972 | struct ppc_fixup | |
1973 | { | |
1974 | expressionS exp; | |
1975 | int opindex; | |
1976 | bfd_reloc_code_real_type reloc; | |
1977 | }; | |
1978 | ||
1979 | #define MAX_INSN_FIXUPS (5) | |
1980 | ||
1981 | /* This routine is called for each instruction to be assembled. */ | |
1982 | ||
1983 | void | |
1984 | md_assemble (str) | |
1985 | char *str; | |
1986 | { | |
1987 | char *s; | |
1988 | const struct powerpc_opcode *opcode; | |
1989 | unsigned long insn; | |
1990 | const unsigned char *opindex_ptr; | |
1991 | int skip_optional; | |
1992 | int need_paren; | |
1993 | int next_opindex; | |
1994 | struct ppc_fixup fixups[MAX_INSN_FIXUPS]; | |
1995 | int fc; | |
1996 | char *f; | |
1997 | int i; | |
1998 | #ifdef OBJ_ELF | |
1999 | bfd_reloc_code_real_type reloc; | |
2000 | #endif | |
2001 | ||
2002 | /* Get the opcode. */ | |
3882b010 | 2003 | for (s = str; *s != '\0' && ! ISSPACE (*s); s++) |
252b5132 RH |
2004 | ; |
2005 | if (*s != '\0') | |
2006 | *s++ = '\0'; | |
2007 | ||
2008 | /* Look up the opcode in the hash table. */ | |
2009 | opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str); | |
2010 | if (opcode == (const struct powerpc_opcode *) NULL) | |
2011 | { | |
2012 | const struct powerpc_macro *macro; | |
2013 | ||
2014 | macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str); | |
2015 | if (macro == (const struct powerpc_macro *) NULL) | |
2016 | as_bad (_("Unrecognized opcode: `%s'"), str); | |
2017 | else | |
2018 | ppc_macro (s, macro); | |
2019 | ||
2020 | return; | |
2021 | } | |
2022 | ||
2023 | insn = opcode->opcode; | |
2024 | ||
2025 | str = s; | |
3882b010 | 2026 | while (ISSPACE (*str)) |
252b5132 RH |
2027 | ++str; |
2028 | ||
2029 | /* PowerPC operands are just expressions. The only real issue is | |
2030 | that a few operand types are optional. All cases which might use | |
2031 | an optional operand separate the operands only with commas (in | |
2032 | some cases parentheses are used, as in ``lwz 1,0(1)'' but such | |
2033 | cases never have optional operands). There is never more than | |
2034 | one optional operand for an instruction. So, before we start | |
2035 | seriously parsing the operands, we check to see if we have an | |
2036 | optional operand, and, if we do, we count the number of commas to | |
2037 | see whether the operand should be omitted. */ | |
2038 | skip_optional = 0; | |
2039 | for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++) | |
2040 | { | |
2041 | const struct powerpc_operand *operand; | |
2042 | ||
2043 | operand = &powerpc_operands[*opindex_ptr]; | |
2044 | if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0) | |
2045 | { | |
2046 | unsigned int opcount; | |
2047 | ||
2048 | /* There is an optional operand. Count the number of | |
2049 | commas in the input line. */ | |
2050 | if (*str == '\0') | |
2051 | opcount = 0; | |
2052 | else | |
2053 | { | |
2054 | opcount = 1; | |
2055 | s = str; | |
2056 | while ((s = strchr (s, ',')) != (char *) NULL) | |
2057 | { | |
2058 | ++opcount; | |
2059 | ++s; | |
2060 | } | |
2061 | } | |
2062 | ||
2063 | /* If there are fewer operands in the line then are called | |
2064 | for by the instruction, we want to skip the optional | |
2065 | operand. */ | |
2066 | if (opcount < strlen (opcode->operands)) | |
2067 | skip_optional = 1; | |
2068 | ||
2069 | break; | |
2070 | } | |
2071 | } | |
2072 | ||
2073 | /* Gather the operands. */ | |
2074 | need_paren = 0; | |
2075 | next_opindex = 0; | |
2076 | fc = 0; | |
2077 | for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++) | |
2078 | { | |
2079 | const struct powerpc_operand *operand; | |
2080 | const char *errmsg; | |
2081 | char *hold; | |
2082 | expressionS ex; | |
2083 | char endc; | |
2084 | ||
2085 | if (next_opindex == 0) | |
2086 | operand = &powerpc_operands[*opindex_ptr]; | |
2087 | else | |
2088 | { | |
2089 | operand = &powerpc_operands[next_opindex]; | |
2090 | next_opindex = 0; | |
2091 | } | |
252b5132 RH |
2092 | errmsg = NULL; |
2093 | ||
2094 | /* If this is a fake operand, then we do not expect anything | |
2095 | from the input. */ | |
2096 | if ((operand->flags & PPC_OPERAND_FAKE) != 0) | |
2097 | { | |
2b3c4602 | 2098 | insn = (*operand->insert) (insn, 0L, ppc_cpu, &errmsg); |
252b5132 RH |
2099 | if (errmsg != (const char *) NULL) |
2100 | as_bad (errmsg); | |
2101 | continue; | |
2102 | } | |
2103 | ||
2104 | /* If this is an optional operand, and we are skipping it, just | |
2105 | insert a zero. */ | |
2106 | if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0 | |
2107 | && skip_optional) | |
2108 | { | |
2109 | if (operand->insert) | |
2110 | { | |
2b3c4602 | 2111 | insn = (*operand->insert) (insn, 0L, ppc_cpu, &errmsg); |
252b5132 RH |
2112 | if (errmsg != (const char *) NULL) |
2113 | as_bad (errmsg); | |
2114 | } | |
2115 | if ((operand->flags & PPC_OPERAND_NEXT) != 0) | |
2116 | next_opindex = *opindex_ptr + 1; | |
2117 | continue; | |
2118 | } | |
2119 | ||
2120 | /* Gather the operand. */ | |
2121 | hold = input_line_pointer; | |
2122 | input_line_pointer = str; | |
2123 | ||
2124 | #ifdef TE_PE | |
81d4177b | 2125 | if (*input_line_pointer == '[') |
252b5132 RH |
2126 | { |
2127 | /* We are expecting something like the second argument here: | |
99a814a1 AM |
2128 | * |
2129 | * lwz r4,[toc].GS.0.static_int(rtoc) | |
2130 | * ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
2131 | * The argument following the `]' must be a symbol name, and the | |
2132 | * register must be the toc register: 'rtoc' or '2' | |
2133 | * | |
2134 | * The effect is to 0 as the displacement field | |
2135 | * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or | |
2136 | * the appropriate variation) reloc against it based on the symbol. | |
2137 | * The linker will build the toc, and insert the resolved toc offset. | |
2138 | * | |
2139 | * Note: | |
2140 | * o The size of the toc entry is currently assumed to be | |
2141 | * 32 bits. This should not be assumed to be a hard coded | |
2142 | * number. | |
2143 | * o In an effort to cope with a change from 32 to 64 bits, | |
2144 | * there are also toc entries that are specified to be | |
2145 | * either 32 or 64 bits: | |
2146 | * lwz r4,[toc32].GS.0.static_int(rtoc) | |
2147 | * lwz r4,[toc64].GS.0.static_int(rtoc) | |
2148 | * These demand toc entries of the specified size, and the | |
2149 | * instruction probably requires it. | |
2150 | */ | |
252b5132 RH |
2151 | |
2152 | int valid_toc; | |
2153 | enum toc_size_qualifier toc_kind; | |
2154 | bfd_reloc_code_real_type toc_reloc; | |
2155 | ||
99a814a1 AM |
2156 | /* Go parse off the [tocXX] part. */ |
2157 | valid_toc = parse_toc_entry (&toc_kind); | |
252b5132 | 2158 | |
81d4177b | 2159 | if (!valid_toc) |
252b5132 | 2160 | { |
99a814a1 AM |
2161 | /* Note: message has already been issued. |
2162 | FIXME: what sort of recovery should we do? | |
2163 | demand_rest_of_line (); return; ? */ | |
252b5132 RH |
2164 | } |
2165 | ||
99a814a1 AM |
2166 | /* Now get the symbol following the ']'. */ |
2167 | expression (&ex); | |
252b5132 RH |
2168 | |
2169 | switch (toc_kind) | |
2170 | { | |
2171 | case default_toc: | |
99a814a1 AM |
2172 | /* In this case, we may not have seen the symbol yet, |
2173 | since it is allowed to appear on a .extern or .globl | |
2174 | or just be a label in the .data section. */ | |
252b5132 RH |
2175 | toc_reloc = BFD_RELOC_PPC_TOC16; |
2176 | break; | |
2177 | case data_in_toc: | |
99a814a1 AM |
2178 | /* 1. The symbol must be defined and either in the toc |
2179 | section, or a global. | |
2180 | 2. The reloc generated must have the TOCDEFN flag set | |
2181 | in upper bit mess of the reloc type. | |
2182 | FIXME: It's a little confusing what the tocv | |
2183 | qualifier can be used for. At the very least, I've | |
2184 | seen three uses, only one of which I'm sure I can | |
2185 | explain. */ | |
81d4177b KH |
2186 | if (ex.X_op == O_symbol) |
2187 | { | |
252b5132 | 2188 | assert (ex.X_add_symbol != NULL); |
fed9b18a ILT |
2189 | if (symbol_get_bfdsym (ex.X_add_symbol)->section |
2190 | != tocdata_section) | |
252b5132 | 2191 | { |
99a814a1 | 2192 | as_bad (_("[tocv] symbol is not a toc symbol")); |
252b5132 RH |
2193 | } |
2194 | } | |
2195 | ||
2196 | toc_reloc = BFD_RELOC_PPC_TOC16; | |
2197 | break; | |
2198 | case must_be_32: | |
99a814a1 AM |
2199 | /* FIXME: these next two specifically specify 32/64 bit |
2200 | toc entries. We don't support them today. Is this | |
2201 | the right way to say that? */ | |
252b5132 RH |
2202 | toc_reloc = BFD_RELOC_UNUSED; |
2203 | as_bad (_("Unimplemented toc32 expression modifier")); | |
2204 | break; | |
2205 | case must_be_64: | |
99a814a1 | 2206 | /* FIXME: see above. */ |
252b5132 RH |
2207 | toc_reloc = BFD_RELOC_UNUSED; |
2208 | as_bad (_("Unimplemented toc64 expression modifier")); | |
2209 | break; | |
2210 | default: | |
bc805888 | 2211 | fprintf (stderr, |
99a814a1 AM |
2212 | _("Unexpected return value [%d] from parse_toc_entry!\n"), |
2213 | toc_kind); | |
bc805888 | 2214 | abort (); |
252b5132 RH |
2215 | break; |
2216 | } | |
2217 | ||
2218 | /* We need to generate a fixup for this expression. */ | |
2219 | if (fc >= MAX_INSN_FIXUPS) | |
2220 | as_fatal (_("too many fixups")); | |
2221 | ||
2222 | fixups[fc].reloc = toc_reloc; | |
2223 | fixups[fc].exp = ex; | |
2224 | fixups[fc].opindex = *opindex_ptr; | |
2225 | ++fc; | |
2226 | ||
99a814a1 AM |
2227 | /* Ok. We've set up the fixup for the instruction. Now make it |
2228 | look like the constant 0 was found here. */ | |
252b5132 RH |
2229 | ex.X_unsigned = 1; |
2230 | ex.X_op = O_constant; | |
2231 | ex.X_add_number = 0; | |
2232 | ex.X_add_symbol = NULL; | |
2233 | ex.X_op_symbol = NULL; | |
2234 | } | |
2235 | ||
2236 | else | |
2237 | #endif /* TE_PE */ | |
2238 | { | |
2239 | if (! register_name (&ex)) | |
2240 | { | |
2241 | if ((operand->flags & PPC_OPERAND_CR) != 0) | |
2242 | cr_operand = true; | |
2243 | expression (&ex); | |
2244 | cr_operand = false; | |
2245 | } | |
2246 | } | |
2247 | ||
2248 | str = input_line_pointer; | |
2249 | input_line_pointer = hold; | |
2250 | ||
2251 | if (ex.X_op == O_illegal) | |
2252 | as_bad (_("illegal operand")); | |
2253 | else if (ex.X_op == O_absent) | |
2254 | as_bad (_("missing operand")); | |
2255 | else if (ex.X_op == O_register) | |
2256 | { | |
2257 | insn = ppc_insert_operand (insn, operand, ex.X_add_number, | |
2258 | (char *) NULL, 0); | |
2259 | } | |
2260 | else if (ex.X_op == O_constant) | |
2261 | { | |
2262 | #ifdef OBJ_ELF | |
81d4177b | 2263 | /* Allow @HA, @L, @H on constants. */ |
252b5132 RH |
2264 | char *orig_str = str; |
2265 | ||
2266 | if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED) | |
2267 | switch (reloc) | |
2268 | { | |
2269 | default: | |
2270 | str = orig_str; | |
2271 | break; | |
2272 | ||
2273 | case BFD_RELOC_LO16: | |
2274 | /* X_unsigned is the default, so if the user has done | |
0baf16f2 AM |
2275 | something which cleared it, we always produce a |
2276 | signed value. */ | |
2277 | if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED)) | |
252b5132 RH |
2278 | ex.X_add_number &= 0xffff; |
2279 | else | |
0baf16f2 | 2280 | ex.X_add_number = SEX16 (ex.X_add_number); |
252b5132 RH |
2281 | break; |
2282 | ||
2283 | case BFD_RELOC_HI16: | |
0baf16f2 AM |
2284 | if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED)) |
2285 | ex.X_add_number = PPC_HI (ex.X_add_number); | |
2286 | else | |
2287 | ex.X_add_number = SEX16 (PPC_HI (ex.X_add_number)); | |
252b5132 RH |
2288 | break; |
2289 | ||
2290 | case BFD_RELOC_HI16_S: | |
0baf16f2 AM |
2291 | if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED)) |
2292 | ex.X_add_number = PPC_HA (ex.X_add_number); | |
2293 | else | |
2294 | ex.X_add_number = SEX16 (PPC_HA (ex.X_add_number)); | |
2295 | break; | |
2296 | ||
0baf16f2 AM |
2297 | case BFD_RELOC_PPC64_HIGHER: |
2298 | if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED)) | |
2299 | ex.X_add_number = PPC_HIGHER (ex.X_add_number); | |
2300 | else | |
2301 | ex.X_add_number = SEX16 (PPC_HIGHER (ex.X_add_number)); | |
2302 | break; | |
2303 | ||
2304 | case BFD_RELOC_PPC64_HIGHER_S: | |
2305 | if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED)) | |
2306 | ex.X_add_number = PPC_HIGHERA (ex.X_add_number); | |
2307 | else | |
2308 | ex.X_add_number = SEX16 (PPC_HIGHERA (ex.X_add_number)); | |
252b5132 | 2309 | break; |
0baf16f2 AM |
2310 | |
2311 | case BFD_RELOC_PPC64_HIGHEST: | |
2312 | if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED)) | |
2313 | ex.X_add_number = PPC_HIGHEST (ex.X_add_number); | |
2314 | else | |
2315 | ex.X_add_number = SEX16 (PPC_HIGHEST (ex.X_add_number)); | |
2316 | break; | |
2317 | ||
2318 | case BFD_RELOC_PPC64_HIGHEST_S: | |
2319 | if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED)) | |
2320 | ex.X_add_number = PPC_HIGHESTA (ex.X_add_number); | |
2321 | else | |
2322 | ex.X_add_number = SEX16 (PPC_HIGHESTA (ex.X_add_number)); | |
2323 | break; | |
252b5132 | 2324 | } |
0baf16f2 | 2325 | #endif /* OBJ_ELF */ |
252b5132 RH |
2326 | insn = ppc_insert_operand (insn, operand, ex.X_add_number, |
2327 | (char *) NULL, 0); | |
2328 | } | |
2329 | #ifdef OBJ_ELF | |
2330 | else if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED) | |
2331 | { | |
99a814a1 AM |
2332 | /* For the absolute forms of branches, convert the PC |
2333 | relative form back into the absolute. */ | |
252b5132 RH |
2334 | if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0) |
2335 | { | |
2336 | switch (reloc) | |
2337 | { | |
2338 | case BFD_RELOC_PPC_B26: | |
2339 | reloc = BFD_RELOC_PPC_BA26; | |
2340 | break; | |
2341 | case BFD_RELOC_PPC_B16: | |
2342 | reloc = BFD_RELOC_PPC_BA16; | |
2343 | break; | |
2344 | case BFD_RELOC_PPC_B16_BRTAKEN: | |
2345 | reloc = BFD_RELOC_PPC_BA16_BRTAKEN; | |
2346 | break; | |
2347 | case BFD_RELOC_PPC_B16_BRNTAKEN: | |
2348 | reloc = BFD_RELOC_PPC_BA16_BRNTAKEN; | |
2349 | break; | |
2350 | default: | |
2351 | break; | |
2352 | } | |
2353 | } | |
2354 | ||
2b3c4602 | 2355 | if (ppc_obj64 |
0baf16f2 AM |
2356 | && (operand->flags & PPC_OPERAND_DS) != 0) |
2357 | { | |
2358 | switch (reloc) | |
2359 | { | |
2360 | case BFD_RELOC_16: | |
2361 | reloc = BFD_RELOC_PPC64_ADDR16_DS; | |
2362 | break; | |
2363 | case BFD_RELOC_LO16: | |
2364 | reloc = BFD_RELOC_PPC64_ADDR16_LO_DS; | |
2365 | break; | |
2366 | case BFD_RELOC_16_GOTOFF: | |
2367 | reloc = BFD_RELOC_PPC64_GOT16_DS; | |
2368 | break; | |
2369 | case BFD_RELOC_LO16_GOTOFF: | |
2370 | reloc = BFD_RELOC_PPC64_GOT16_LO_DS; | |
2371 | break; | |
2372 | case BFD_RELOC_LO16_PLTOFF: | |
2373 | reloc = BFD_RELOC_PPC64_PLT16_LO_DS; | |
2374 | break; | |
1cfc59d5 | 2375 | case BFD_RELOC_16_BASEREL: |
0baf16f2 AM |
2376 | reloc = BFD_RELOC_PPC64_SECTOFF_DS; |
2377 | break; | |
2378 | case BFD_RELOC_LO16_BASEREL: | |
2379 | reloc = BFD_RELOC_PPC64_SECTOFF_LO_DS; | |
2380 | break; | |
2381 | case BFD_RELOC_PPC_TOC16: | |
2382 | reloc = BFD_RELOC_PPC64_TOC16_DS; | |
2383 | break; | |
2384 | case BFD_RELOC_PPC64_TOC16_LO: | |
2385 | reloc = BFD_RELOC_PPC64_TOC16_LO_DS; | |
2386 | break; | |
2387 | case BFD_RELOC_PPC64_PLTGOT16: | |
2388 | reloc = BFD_RELOC_PPC64_PLTGOT16_DS; | |
2389 | break; | |
2390 | case BFD_RELOC_PPC64_PLTGOT16_LO: | |
2391 | reloc = BFD_RELOC_PPC64_PLTGOT16_LO_DS; | |
2392 | break; | |
2393 | default: | |
2394 | as_bad (_("unsupported relocation for DS offset field")); | |
2395 | break; | |
2396 | } | |
2397 | } | |
2398 | ||
252b5132 RH |
2399 | /* We need to generate a fixup for this expression. */ |
2400 | if (fc >= MAX_INSN_FIXUPS) | |
2401 | as_fatal (_("too many fixups")); | |
2402 | fixups[fc].exp = ex; | |
2403 | fixups[fc].opindex = 0; | |
2404 | fixups[fc].reloc = reloc; | |
2405 | ++fc; | |
2406 | } | |
2407 | #endif /* OBJ_ELF */ | |
2408 | ||
2409 | else | |
2410 | { | |
2411 | /* We need to generate a fixup for this expression. */ | |
2412 | if (fc >= MAX_INSN_FIXUPS) | |
2413 | as_fatal (_("too many fixups")); | |
2414 | fixups[fc].exp = ex; | |
2415 | fixups[fc].opindex = *opindex_ptr; | |
2416 | fixups[fc].reloc = BFD_RELOC_UNUSED; | |
2417 | ++fc; | |
2418 | } | |
2419 | ||
2420 | if (need_paren) | |
2421 | { | |
2422 | endc = ')'; | |
2423 | need_paren = 0; | |
2424 | } | |
2425 | else if ((operand->flags & PPC_OPERAND_PARENS) != 0) | |
2426 | { | |
2427 | endc = '('; | |
2428 | need_paren = 1; | |
2429 | } | |
2430 | else | |
2431 | endc = ','; | |
2432 | ||
2433 | /* The call to expression should have advanced str past any | |
2434 | whitespace. */ | |
2435 | if (*str != endc | |
2436 | && (endc != ',' || *str != '\0')) | |
2437 | { | |
2438 | as_bad (_("syntax error; found `%c' but expected `%c'"), *str, endc); | |
2439 | break; | |
2440 | } | |
2441 | ||
2442 | if (*str != '\0') | |
2443 | ++str; | |
2444 | } | |
2445 | ||
3882b010 | 2446 | while (ISSPACE (*str)) |
252b5132 RH |
2447 | ++str; |
2448 | ||
2449 | if (*str != '\0') | |
2450 | as_bad (_("junk at end of line: `%s'"), str); | |
2451 | ||
6a0c61b7 EZ |
2452 | /* Do we need/want a APUinfo section? */ |
2453 | if (ppc_cpu & (PPC_OPCODE_SPE | |
2454 | | PPC_OPCODE_ISEL | PPC_OPCODE_EFS | |
2455 | | PPC_OPCODE_BRLOCK | PPC_OPCODE_PMR | PPC_OPCODE_CACHELCK | |
2456 | | PPC_OPCODE_RFMCI)) | |
2457 | { | |
2458 | /* These are all version "1". */ | |
2459 | if (opcode->flags & PPC_OPCODE_SPE) | |
2460 | ppc_apuinfo_section_add(PPC_APUINFO_SPE, 1); | |
2461 | if (opcode->flags & PPC_OPCODE_ISEL) | |
2462 | ppc_apuinfo_section_add(PPC_APUINFO_ISEL, 1); | |
2463 | if (opcode->flags & PPC_OPCODE_EFS) | |
2464 | ppc_apuinfo_section_add(PPC_APUINFO_EFS, 1); | |
2465 | if (opcode->flags & PPC_OPCODE_BRLOCK) | |
2466 | ppc_apuinfo_section_add(PPC_APUINFO_BRLOCK, 1); | |
2467 | if (opcode->flags & PPC_OPCODE_PMR) | |
2468 | ppc_apuinfo_section_add(PPC_APUINFO_PMR, 1); | |
2469 | if (opcode->flags & PPC_OPCODE_CACHELCK) | |
2470 | ppc_apuinfo_section_add(PPC_APUINFO_CACHELCK, 1); | |
2471 | if (opcode->flags & PPC_OPCODE_RFMCI) | |
2472 | ppc_apuinfo_section_add(PPC_APUINFO_RFMCI, 1); | |
2473 | } | |
2474 | ||
252b5132 RH |
2475 | /* Write out the instruction. */ |
2476 | f = frag_more (4); | |
2477 | md_number_to_chars (f, insn, 4); | |
2478 | ||
5d6f4f16 GK |
2479 | #ifdef OBJ_ELF |
2480 | dwarf2_emit_insn (4); | |
2481 | #endif | |
2482 | ||
252b5132 RH |
2483 | /* Create any fixups. At this point we do not use a |
2484 | bfd_reloc_code_real_type, but instead just use the | |
2485 | BFD_RELOC_UNUSED plus the operand index. This lets us easily | |
2486 | handle fixups for any operand type, although that is admittedly | |
2487 | not a very exciting feature. We pick a BFD reloc type in | |
94f592af | 2488 | md_apply_fix3. */ |
252b5132 RH |
2489 | for (i = 0; i < fc; i++) |
2490 | { | |
2491 | const struct powerpc_operand *operand; | |
2492 | ||
2493 | operand = &powerpc_operands[fixups[i].opindex]; | |
2494 | if (fixups[i].reloc != BFD_RELOC_UNUSED) | |
2495 | { | |
99a814a1 | 2496 | reloc_howto_type *reloc_howto; |
252b5132 RH |
2497 | int size; |
2498 | int offset; | |
2499 | fixS *fixP; | |
2500 | ||
99a814a1 | 2501 | reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc); |
252b5132 RH |
2502 | if (!reloc_howto) |
2503 | abort (); | |
2504 | ||
2505 | size = bfd_get_reloc_size (reloc_howto); | |
2506 | offset = target_big_endian ? (4 - size) : 0; | |
2507 | ||
2508 | if (size < 1 || size > 4) | |
bc805888 | 2509 | abort (); |
252b5132 | 2510 | |
99a814a1 AM |
2511 | fixP = fix_new_exp (frag_now, |
2512 | f - frag_now->fr_literal + offset, | |
2513 | size, | |
2514 | &fixups[i].exp, | |
2515 | reloc_howto->pc_relative, | |
252b5132 RH |
2516 | fixups[i].reloc); |
2517 | ||
2518 | /* Turn off complaints that the addend is too large for things like | |
2519 | foo+100000@ha. */ | |
2520 | switch (fixups[i].reloc) | |
2521 | { | |
2522 | case BFD_RELOC_16_GOTOFF: | |
2523 | case BFD_RELOC_PPC_TOC16: | |
2524 | case BFD_RELOC_LO16: | |
2525 | case BFD_RELOC_HI16: | |
2526 | case BFD_RELOC_HI16_S: | |
0baf16f2 | 2527 | #ifdef OBJ_ELF |
0baf16f2 AM |
2528 | case BFD_RELOC_PPC64_HIGHER: |
2529 | case BFD_RELOC_PPC64_HIGHER_S: | |
2530 | case BFD_RELOC_PPC64_HIGHEST: | |
2531 | case BFD_RELOC_PPC64_HIGHEST_S: | |
0baf16f2 | 2532 | #endif |
252b5132 RH |
2533 | fixP->fx_no_overflow = 1; |
2534 | break; | |
2535 | default: | |
2536 | break; | |
2537 | } | |
2538 | } | |
2539 | else | |
99a814a1 AM |
2540 | fix_new_exp (frag_now, |
2541 | f - frag_now->fr_literal, | |
2542 | 4, | |
252b5132 RH |
2543 | &fixups[i].exp, |
2544 | (operand->flags & PPC_OPERAND_RELATIVE) != 0, | |
2545 | ((bfd_reloc_code_real_type) | |
99a814a1 | 2546 | (fixups[i].opindex + (int) BFD_RELOC_UNUSED))); |
252b5132 RH |
2547 | } |
2548 | } | |
2549 | ||
2550 | /* Handle a macro. Gather all the operands, transform them as | |
2551 | described by the macro, and call md_assemble recursively. All the | |
2552 | operands are separated by commas; we don't accept parentheses | |
2553 | around operands here. */ | |
2554 | ||
2555 | static void | |
2556 | ppc_macro (str, macro) | |
2557 | char *str; | |
2558 | const struct powerpc_macro *macro; | |
2559 | { | |
2560 | char *operands[10]; | |
2561 | unsigned int count; | |
2562 | char *s; | |
2563 | unsigned int len; | |
2564 | const char *format; | |
2565 | int arg; | |
2566 | char *send; | |
2567 | char *complete; | |
2568 | ||
2569 | /* Gather the users operands into the operands array. */ | |
2570 | count = 0; | |
2571 | s = str; | |
2572 | while (1) | |
2573 | { | |
2574 | if (count >= sizeof operands / sizeof operands[0]) | |
2575 | break; | |
2576 | operands[count++] = s; | |
2577 | s = strchr (s, ','); | |
2578 | if (s == (char *) NULL) | |
2579 | break; | |
2580 | *s++ = '\0'; | |
81d4177b | 2581 | } |
252b5132 RH |
2582 | |
2583 | if (count != macro->operands) | |
2584 | { | |
2585 | as_bad (_("wrong number of operands")); | |
2586 | return; | |
2587 | } | |
2588 | ||
2589 | /* Work out how large the string must be (the size is unbounded | |
2590 | because it includes user input). */ | |
2591 | len = 0; | |
2592 | format = macro->format; | |
2593 | while (*format != '\0') | |
2594 | { | |
2595 | if (*format != '%') | |
2596 | { | |
2597 | ++len; | |
2598 | ++format; | |
2599 | } | |
2600 | else | |
2601 | { | |
2602 | arg = strtol (format + 1, &send, 10); | |
2603 | know (send != format && arg >= 0 && arg < count); | |
2604 | len += strlen (operands[arg]); | |
2605 | format = send; | |
2606 | } | |
2607 | } | |
2608 | ||
2609 | /* Put the string together. */ | |
2610 | complete = s = (char *) alloca (len + 1); | |
2611 | format = macro->format; | |
2612 | while (*format != '\0') | |
2613 | { | |
2614 | if (*format != '%') | |
2615 | *s++ = *format++; | |
2616 | else | |
2617 | { | |
2618 | arg = strtol (format + 1, &send, 10); | |
2619 | strcpy (s, operands[arg]); | |
2620 | s += strlen (s); | |
2621 | format = send; | |
2622 | } | |
2623 | } | |
2624 | *s = '\0'; | |
2625 | ||
2626 | /* Assemble the constructed instruction. */ | |
2627 | md_assemble (complete); | |
81d4177b | 2628 | } |
252b5132 RH |
2629 | \f |
2630 | #ifdef OBJ_ELF | |
99a814a1 | 2631 | /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */ |
252b5132 RH |
2632 | |
2633 | int | |
2634 | ppc_section_letter (letter, ptr_msg) | |
2635 | int letter; | |
2636 | char **ptr_msg; | |
2637 | { | |
2638 | if (letter == 'e') | |
2639 | return SHF_EXCLUDE; | |
2640 | ||
13ae64f3 | 2641 | *ptr_msg = _("Bad .section directive: want a,e,w,x,M,S,G,T in string"); |
252b5132 RH |
2642 | return 0; |
2643 | } | |
2644 | ||
2645 | int | |
9de8d8f1 RH |
2646 | ppc_section_word (str, len) |
2647 | char *str; | |
2648 | size_t len; | |
252b5132 | 2649 | { |
9de8d8f1 RH |
2650 | if (len == 7 && strncmp (str, "exclude", 7) == 0) |
2651 | return SHF_EXCLUDE; | |
252b5132 | 2652 | |
9de8d8f1 | 2653 | return -1; |
252b5132 RH |
2654 | } |
2655 | ||
2656 | int | |
9de8d8f1 RH |
2657 | ppc_section_type (str, len) |
2658 | char *str; | |
2659 | size_t len; | |
252b5132 | 2660 | { |
9de8d8f1 RH |
2661 | if (len == 7 && strncmp (str, "ordered", 7) == 0) |
2662 | return SHT_ORDERED; | |
252b5132 | 2663 | |
9de8d8f1 | 2664 | return -1; |
252b5132 RH |
2665 | } |
2666 | ||
2667 | int | |
2668 | ppc_section_flags (flags, attr, type) | |
2669 | int flags; | |
2670 | int attr; | |
2671 | int type; | |
2672 | { | |
2673 | if (type == SHT_ORDERED) | |
2674 | flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES; | |
2675 | ||
2676 | if (attr & SHF_EXCLUDE) | |
2677 | flags |= SEC_EXCLUDE; | |
2678 | ||
2679 | return flags; | |
2680 | } | |
2681 | #endif /* OBJ_ELF */ | |
2682 | ||
2683 | \f | |
2684 | /* Pseudo-op handling. */ | |
2685 | ||
2686 | /* The .byte pseudo-op. This is similar to the normal .byte | |
2687 | pseudo-op, but it can also take a single ASCII string. */ | |
2688 | ||
2689 | static void | |
2690 | ppc_byte (ignore) | |
92161534 | 2691 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
2692 | { |
2693 | if (*input_line_pointer != '\"') | |
2694 | { | |
2695 | cons (1); | |
2696 | return; | |
2697 | } | |
2698 | ||
2699 | /* Gather characters. A real double quote is doubled. Unusual | |
2700 | characters are not permitted. */ | |
2701 | ++input_line_pointer; | |
2702 | while (1) | |
2703 | { | |
2704 | char c; | |
2705 | ||
2706 | c = *input_line_pointer++; | |
2707 | ||
2708 | if (c == '\"') | |
2709 | { | |
2710 | if (*input_line_pointer != '\"') | |
2711 | break; | |
2712 | ++input_line_pointer; | |
2713 | } | |
2714 | ||
2715 | FRAG_APPEND_1_CHAR (c); | |
2716 | } | |
2717 | ||
2718 | demand_empty_rest_of_line (); | |
2719 | } | |
2720 | \f | |
2721 | #ifdef OBJ_XCOFF | |
2722 | ||
2723 | /* XCOFF specific pseudo-op handling. */ | |
2724 | ||
2725 | /* This is set if we are creating a .stabx symbol, since we don't want | |
2726 | to handle symbol suffixes for such symbols. */ | |
2727 | static boolean ppc_stab_symbol; | |
2728 | ||
2729 | /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common | |
2730 | symbols in the .bss segment as though they were local common | |
1ad63b2f TR |
2731 | symbols, and uses a different smclas. The native Aix 4.3.3 assember |
2732 | aligns .comm and .lcomm to 4 bytes. */ | |
252b5132 RH |
2733 | |
2734 | static void | |
2735 | ppc_comm (lcomm) | |
2736 | int lcomm; | |
2737 | { | |
2738 | asection *current_seg = now_seg; | |
2739 | subsegT current_subseg = now_subseg; | |
2740 | char *name; | |
2741 | char endc; | |
2742 | char *end_name; | |
2743 | offsetT size; | |
2744 | offsetT align; | |
2745 | symbolS *lcomm_sym = NULL; | |
2746 | symbolS *sym; | |
2747 | char *pfrag; | |
2748 | ||
2749 | name = input_line_pointer; | |
2750 | endc = get_symbol_end (); | |
2751 | end_name = input_line_pointer; | |
2752 | *end_name = endc; | |
2753 | ||
2754 | if (*input_line_pointer != ',') | |
2755 | { | |
2756 | as_bad (_("missing size")); | |
2757 | ignore_rest_of_line (); | |
2758 | return; | |
2759 | } | |
2760 | ++input_line_pointer; | |
2761 | ||
2762 | size = get_absolute_expression (); | |
2763 | if (size < 0) | |
2764 | { | |
2765 | as_bad (_("negative size")); | |
2766 | ignore_rest_of_line (); | |
2767 | return; | |
2768 | } | |
2769 | ||
2770 | if (! lcomm) | |
2771 | { | |
2772 | /* The third argument to .comm is the alignment. */ | |
2773 | if (*input_line_pointer != ',') | |
1ad63b2f | 2774 | align = 2; |
252b5132 RH |
2775 | else |
2776 | { | |
2777 | ++input_line_pointer; | |
2778 | align = get_absolute_expression (); | |
2779 | if (align <= 0) | |
2780 | { | |
2781 | as_warn (_("ignoring bad alignment")); | |
1ad63b2f | 2782 | align = 2; |
252b5132 RH |
2783 | } |
2784 | } | |
2785 | } | |
2786 | else | |
2787 | { | |
2788 | char *lcomm_name; | |
2789 | char lcomm_endc; | |
2790 | ||
1ad63b2f | 2791 | if (size <= 4) |
252b5132 RH |
2792 | align = 2; |
2793 | else | |
2794 | align = 3; | |
2795 | ||
2796 | /* The third argument to .lcomm appears to be the real local | |
2797 | common symbol to create. References to the symbol named in | |
2798 | the first argument are turned into references to the third | |
2799 | argument. */ | |
2800 | if (*input_line_pointer != ',') | |
2801 | { | |
2802 | as_bad (_("missing real symbol name")); | |
2803 | ignore_rest_of_line (); | |
2804 | return; | |
2805 | } | |
2806 | ++input_line_pointer; | |
2807 | ||
2808 | lcomm_name = input_line_pointer; | |
2809 | lcomm_endc = get_symbol_end (); | |
81d4177b | 2810 | |
252b5132 RH |
2811 | lcomm_sym = symbol_find_or_make (lcomm_name); |
2812 | ||
2813 | *input_line_pointer = lcomm_endc; | |
2814 | } | |
2815 | ||
2816 | *end_name = '\0'; | |
2817 | sym = symbol_find_or_make (name); | |
2818 | *end_name = endc; | |
2819 | ||
2820 | if (S_IS_DEFINED (sym) | |
2821 | || S_GET_VALUE (sym) != 0) | |
2822 | { | |
2823 | as_bad (_("attempt to redefine symbol")); | |
2824 | ignore_rest_of_line (); | |
2825 | return; | |
2826 | } | |
81d4177b | 2827 | |
252b5132 | 2828 | record_alignment (bss_section, align); |
81d4177b | 2829 | |
252b5132 RH |
2830 | if (! lcomm |
2831 | || ! S_IS_DEFINED (lcomm_sym)) | |
2832 | { | |
2833 | symbolS *def_sym; | |
2834 | offsetT def_size; | |
2835 | ||
2836 | if (! lcomm) | |
2837 | { | |
2838 | def_sym = sym; | |
2839 | def_size = size; | |
2840 | S_SET_EXTERNAL (sym); | |
2841 | } | |
2842 | else | |
2843 | { | |
809ffe0d | 2844 | symbol_get_tc (lcomm_sym)->output = 1; |
252b5132 RH |
2845 | def_sym = lcomm_sym; |
2846 | def_size = 0; | |
2847 | } | |
2848 | ||
2849 | subseg_set (bss_section, 1); | |
2850 | frag_align (align, 0, 0); | |
81d4177b | 2851 | |
809ffe0d | 2852 | symbol_set_frag (def_sym, frag_now); |
252b5132 RH |
2853 | pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym, |
2854 | def_size, (char *) NULL); | |
2855 | *pfrag = 0; | |
2856 | S_SET_SEGMENT (def_sym, bss_section); | |
809ffe0d | 2857 | symbol_get_tc (def_sym)->align = align; |
252b5132 RH |
2858 | } |
2859 | else if (lcomm) | |
2860 | { | |
2861 | /* Align the size of lcomm_sym. */ | |
809ffe0d ILT |
2862 | symbol_get_frag (lcomm_sym)->fr_offset = |
2863 | ((symbol_get_frag (lcomm_sym)->fr_offset + (1 << align) - 1) | |
252b5132 | 2864 | &~ ((1 << align) - 1)); |
809ffe0d ILT |
2865 | if (align > symbol_get_tc (lcomm_sym)->align) |
2866 | symbol_get_tc (lcomm_sym)->align = align; | |
252b5132 RH |
2867 | } |
2868 | ||
2869 | if (lcomm) | |
2870 | { | |
2871 | /* Make sym an offset from lcomm_sym. */ | |
2872 | S_SET_SEGMENT (sym, bss_section); | |
809ffe0d ILT |
2873 | symbol_set_frag (sym, symbol_get_frag (lcomm_sym)); |
2874 | S_SET_VALUE (sym, symbol_get_frag (lcomm_sym)->fr_offset); | |
2875 | symbol_get_frag (lcomm_sym)->fr_offset += size; | |
252b5132 RH |
2876 | } |
2877 | ||
2878 | subseg_set (current_seg, current_subseg); | |
2879 | ||
2880 | demand_empty_rest_of_line (); | |
2881 | } | |
2882 | ||
2883 | /* The .csect pseudo-op. This switches us into a different | |
2884 | subsegment. The first argument is a symbol whose value is the | |
2885 | start of the .csect. In COFF, csect symbols get special aux | |
2886 | entries defined by the x_csect field of union internal_auxent. The | |
2887 | optional second argument is the alignment (the default is 2). */ | |
2888 | ||
2889 | static void | |
2890 | ppc_csect (ignore) | |
5480ccf3 | 2891 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
2892 | { |
2893 | char *name; | |
2894 | char endc; | |
2895 | symbolS *sym; | |
2896 | ||
2897 | name = input_line_pointer; | |
2898 | endc = get_symbol_end (); | |
81d4177b | 2899 | |
252b5132 RH |
2900 | sym = symbol_find_or_make (name); |
2901 | ||
2902 | *input_line_pointer = endc; | |
2903 | ||
2904 | if (S_GET_NAME (sym)[0] == '\0') | |
2905 | { | |
2906 | /* An unnamed csect is assumed to be [PR]. */ | |
809ffe0d | 2907 | symbol_get_tc (sym)->class = XMC_PR; |
252b5132 RH |
2908 | } |
2909 | ||
2910 | ppc_change_csect (sym); | |
2911 | ||
2912 | if (*input_line_pointer == ',') | |
2913 | { | |
2914 | ++input_line_pointer; | |
809ffe0d | 2915 | symbol_get_tc (sym)->align = get_absolute_expression (); |
252b5132 RH |
2916 | } |
2917 | ||
2918 | demand_empty_rest_of_line (); | |
2919 | } | |
2920 | ||
2921 | /* Change to a different csect. */ | |
2922 | ||
2923 | static void | |
2924 | ppc_change_csect (sym) | |
2925 | symbolS *sym; | |
2926 | { | |
2927 | if (S_IS_DEFINED (sym)) | |
809ffe0d | 2928 | subseg_set (S_GET_SEGMENT (sym), symbol_get_tc (sym)->subseg); |
252b5132 RH |
2929 | else |
2930 | { | |
2931 | symbolS **list_ptr; | |
2932 | int after_toc; | |
2933 | int hold_chunksize; | |
2934 | symbolS *list; | |
2935 | ||
2936 | /* This is a new csect. We need to look at the symbol class to | |
2937 | figure out whether it should go in the text section or the | |
2938 | data section. */ | |
2939 | after_toc = 0; | |
809ffe0d | 2940 | switch (symbol_get_tc (sym)->class) |
252b5132 RH |
2941 | { |
2942 | case XMC_PR: | |
2943 | case XMC_RO: | |
2944 | case XMC_DB: | |
2945 | case XMC_GL: | |
2946 | case XMC_XO: | |
2947 | case XMC_SV: | |
2948 | case XMC_TI: | |
2949 | case XMC_TB: | |
2950 | S_SET_SEGMENT (sym, text_section); | |
809ffe0d | 2951 | symbol_get_tc (sym)->subseg = ppc_text_subsegment; |
252b5132 RH |
2952 | ++ppc_text_subsegment; |
2953 | list_ptr = &ppc_text_csects; | |
2954 | break; | |
2955 | case XMC_RW: | |
2956 | case XMC_TC0: | |
2957 | case XMC_TC: | |
2958 | case XMC_DS: | |
2959 | case XMC_UA: | |
2960 | case XMC_BS: | |
2961 | case XMC_UC: | |
2962 | if (ppc_toc_csect != NULL | |
809ffe0d ILT |
2963 | && (symbol_get_tc (ppc_toc_csect)->subseg + 1 |
2964 | == ppc_data_subsegment)) | |
252b5132 RH |
2965 | after_toc = 1; |
2966 | S_SET_SEGMENT (sym, data_section); | |
809ffe0d | 2967 | symbol_get_tc (sym)->subseg = ppc_data_subsegment; |
252b5132 RH |
2968 | ++ppc_data_subsegment; |
2969 | list_ptr = &ppc_data_csects; | |
2970 | break; | |
2971 | default: | |
2972 | abort (); | |
2973 | } | |
2974 | ||
2975 | /* We set the obstack chunk size to a small value before | |
99a814a1 AM |
2976 | changing subsegments, so that we don't use a lot of memory |
2977 | space for what may be a small section. */ | |
252b5132 RH |
2978 | hold_chunksize = chunksize; |
2979 | chunksize = 64; | |
2980 | ||
809ffe0d ILT |
2981 | subseg_new (segment_name (S_GET_SEGMENT (sym)), |
2982 | symbol_get_tc (sym)->subseg); | |
252b5132 RH |
2983 | |
2984 | chunksize = hold_chunksize; | |
2985 | ||
2986 | if (after_toc) | |
2987 | ppc_after_toc_frag = frag_now; | |
2988 | ||
809ffe0d | 2989 | symbol_set_frag (sym, frag_now); |
252b5132 RH |
2990 | S_SET_VALUE (sym, (valueT) frag_now_fix ()); |
2991 | ||
b4f96c78 | 2992 | symbol_get_tc (sym)->align = 2; |
809ffe0d ILT |
2993 | symbol_get_tc (sym)->output = 1; |
2994 | symbol_get_tc (sym)->within = sym; | |
81d4177b | 2995 | |
252b5132 | 2996 | for (list = *list_ptr; |
809ffe0d ILT |
2997 | symbol_get_tc (list)->next != (symbolS *) NULL; |
2998 | list = symbol_get_tc (list)->next) | |
252b5132 | 2999 | ; |
809ffe0d | 3000 | symbol_get_tc (list)->next = sym; |
81d4177b | 3001 | |
252b5132 | 3002 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); |
809ffe0d ILT |
3003 | symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP, |
3004 | &symbol_lastP); | |
252b5132 RH |
3005 | } |
3006 | ||
3007 | ppc_current_csect = sym; | |
3008 | } | |
3009 | ||
3010 | /* This function handles the .text and .data pseudo-ops. These | |
3011 | pseudo-ops aren't really used by XCOFF; we implement them for the | |
3012 | convenience of people who aren't used to XCOFF. */ | |
3013 | ||
3014 | static void | |
3015 | ppc_section (type) | |
3016 | int type; | |
3017 | { | |
3018 | const char *name; | |
3019 | symbolS *sym; | |
3020 | ||
3021 | if (type == 't') | |
3022 | name = ".text[PR]"; | |
3023 | else if (type == 'd') | |
3024 | name = ".data[RW]"; | |
3025 | else | |
3026 | abort (); | |
3027 | ||
3028 | sym = symbol_find_or_make (name); | |
3029 | ||
3030 | ppc_change_csect (sym); | |
3031 | ||
3032 | demand_empty_rest_of_line (); | |
3033 | } | |
3034 | ||
3035 | /* This function handles the .section pseudo-op. This is mostly to | |
3036 | give an error, since XCOFF only supports .text, .data and .bss, but | |
3037 | we do permit the user to name the text or data section. */ | |
3038 | ||
3039 | static void | |
3040 | ppc_named_section (ignore) | |
5480ccf3 | 3041 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3042 | { |
3043 | char *user_name; | |
3044 | const char *real_name; | |
3045 | char c; | |
3046 | symbolS *sym; | |
3047 | ||
3048 | user_name = input_line_pointer; | |
3049 | c = get_symbol_end (); | |
3050 | ||
3051 | if (strcmp (user_name, ".text") == 0) | |
3052 | real_name = ".text[PR]"; | |
3053 | else if (strcmp (user_name, ".data") == 0) | |
3054 | real_name = ".data[RW]"; | |
3055 | else | |
3056 | { | |
3057 | as_bad (_("The XCOFF file format does not support arbitrary sections")); | |
3058 | *input_line_pointer = c; | |
3059 | ignore_rest_of_line (); | |
3060 | return; | |
3061 | } | |
3062 | ||
3063 | *input_line_pointer = c; | |
3064 | ||
3065 | sym = symbol_find_or_make (real_name); | |
3066 | ||
3067 | ppc_change_csect (sym); | |
3068 | ||
3069 | demand_empty_rest_of_line (); | |
3070 | } | |
3071 | ||
3072 | /* The .extern pseudo-op. We create an undefined symbol. */ | |
3073 | ||
3074 | static void | |
3075 | ppc_extern (ignore) | |
5480ccf3 | 3076 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3077 | { |
3078 | char *name; | |
3079 | char endc; | |
3080 | ||
3081 | name = input_line_pointer; | |
3082 | endc = get_symbol_end (); | |
3083 | ||
3084 | (void) symbol_find_or_make (name); | |
3085 | ||
3086 | *input_line_pointer = endc; | |
3087 | ||
3088 | demand_empty_rest_of_line (); | |
3089 | } | |
3090 | ||
3091 | /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */ | |
3092 | ||
3093 | static void | |
3094 | ppc_lglobl (ignore) | |
5480ccf3 | 3095 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3096 | { |
3097 | char *name; | |
3098 | char endc; | |
3099 | symbolS *sym; | |
3100 | ||
3101 | name = input_line_pointer; | |
3102 | endc = get_symbol_end (); | |
3103 | ||
3104 | sym = symbol_find_or_make (name); | |
3105 | ||
3106 | *input_line_pointer = endc; | |
3107 | ||
809ffe0d | 3108 | symbol_get_tc (sym)->output = 1; |
252b5132 RH |
3109 | |
3110 | demand_empty_rest_of_line (); | |
3111 | } | |
3112 | ||
3113 | /* The .rename pseudo-op. The RS/6000 assembler can rename symbols, | |
3114 | although I don't know why it bothers. */ | |
3115 | ||
3116 | static void | |
3117 | ppc_rename (ignore) | |
5480ccf3 | 3118 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3119 | { |
3120 | char *name; | |
3121 | char endc; | |
3122 | symbolS *sym; | |
3123 | int len; | |
3124 | ||
3125 | name = input_line_pointer; | |
3126 | endc = get_symbol_end (); | |
3127 | ||
3128 | sym = symbol_find_or_make (name); | |
3129 | ||
3130 | *input_line_pointer = endc; | |
3131 | ||
3132 | if (*input_line_pointer != ',') | |
3133 | { | |
3134 | as_bad (_("missing rename string")); | |
3135 | ignore_rest_of_line (); | |
3136 | return; | |
3137 | } | |
3138 | ++input_line_pointer; | |
3139 | ||
809ffe0d | 3140 | symbol_get_tc (sym)->real_name = demand_copy_C_string (&len); |
252b5132 RH |
3141 | |
3142 | demand_empty_rest_of_line (); | |
3143 | } | |
3144 | ||
3145 | /* The .stabx pseudo-op. This is similar to a normal .stabs | |
3146 | pseudo-op, but slightly different. A sample is | |
3147 | .stabx "main:F-1",.main,142,0 | |
3148 | The first argument is the symbol name to create. The second is the | |
3149 | value, and the third is the storage class. The fourth seems to be | |
3150 | always zero, and I am assuming it is the type. */ | |
3151 | ||
3152 | static void | |
3153 | ppc_stabx (ignore) | |
5480ccf3 | 3154 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3155 | { |
3156 | char *name; | |
3157 | int len; | |
3158 | symbolS *sym; | |
3159 | expressionS exp; | |
3160 | ||
3161 | name = demand_copy_C_string (&len); | |
3162 | ||
3163 | if (*input_line_pointer != ',') | |
3164 | { | |
3165 | as_bad (_("missing value")); | |
3166 | return; | |
3167 | } | |
3168 | ++input_line_pointer; | |
3169 | ||
3170 | ppc_stab_symbol = true; | |
3171 | sym = symbol_make (name); | |
3172 | ppc_stab_symbol = false; | |
3173 | ||
809ffe0d | 3174 | symbol_get_tc (sym)->real_name = name; |
252b5132 RH |
3175 | |
3176 | (void) expression (&exp); | |
3177 | ||
3178 | switch (exp.X_op) | |
3179 | { | |
3180 | case O_illegal: | |
3181 | case O_absent: | |
3182 | case O_big: | |
3183 | as_bad (_("illegal .stabx expression; zero assumed")); | |
3184 | exp.X_add_number = 0; | |
3185 | /* Fall through. */ | |
3186 | case O_constant: | |
3187 | S_SET_VALUE (sym, (valueT) exp.X_add_number); | |
809ffe0d | 3188 | symbol_set_frag (sym, &zero_address_frag); |
252b5132 RH |
3189 | break; |
3190 | ||
3191 | case O_symbol: | |
3192 | if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section) | |
809ffe0d | 3193 | symbol_set_value_expression (sym, &exp); |
252b5132 RH |
3194 | else |
3195 | { | |
3196 | S_SET_VALUE (sym, | |
3197 | exp.X_add_number + S_GET_VALUE (exp.X_add_symbol)); | |
809ffe0d | 3198 | symbol_set_frag (sym, symbol_get_frag (exp.X_add_symbol)); |
252b5132 RH |
3199 | } |
3200 | break; | |
3201 | ||
3202 | default: | |
3203 | /* The value is some complex expression. This will probably | |
99a814a1 AM |
3204 | fail at some later point, but this is probably the right |
3205 | thing to do here. */ | |
809ffe0d | 3206 | symbol_set_value_expression (sym, &exp); |
252b5132 RH |
3207 | break; |
3208 | } | |
3209 | ||
3210 | S_SET_SEGMENT (sym, ppc_coff_debug_section); | |
809ffe0d | 3211 | symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; |
252b5132 RH |
3212 | |
3213 | if (*input_line_pointer != ',') | |
3214 | { | |
3215 | as_bad (_("missing class")); | |
3216 | return; | |
3217 | } | |
3218 | ++input_line_pointer; | |
3219 | ||
3220 | S_SET_STORAGE_CLASS (sym, get_absolute_expression ()); | |
3221 | ||
3222 | if (*input_line_pointer != ',') | |
3223 | { | |
3224 | as_bad (_("missing type")); | |
3225 | return; | |
3226 | } | |
3227 | ++input_line_pointer; | |
3228 | ||
3229 | S_SET_DATA_TYPE (sym, get_absolute_expression ()); | |
3230 | ||
809ffe0d | 3231 | symbol_get_tc (sym)->output = 1; |
252b5132 | 3232 | |
6877bb43 | 3233 | if (S_GET_STORAGE_CLASS (sym) == C_STSYM) { |
99a814a1 | 3234 | |
809ffe0d | 3235 | symbol_get_tc (sym)->within = ppc_current_block; |
252b5132 | 3236 | |
41ea10b1 | 3237 | /* In this case : |
99a814a1 | 3238 | |
41ea10b1 TR |
3239 | .bs name |
3240 | .stabx "z",arrays_,133,0 | |
3241 | .es | |
99a814a1 | 3242 | |
41ea10b1 | 3243 | .comm arrays_,13768,3 |
99a814a1 | 3244 | |
41ea10b1 TR |
3245 | resolve_symbol_value will copy the exp's "within" into sym's when the |
3246 | offset is 0. Since this seems to be corner case problem, | |
3247 | only do the correction for storage class C_STSYM. A better solution | |
0baf16f2 | 3248 | would be to have the tc field updated in ppc_symbol_new_hook. */ |
99a814a1 AM |
3249 | |
3250 | if (exp.X_op == O_symbol) | |
41ea10b1 TR |
3251 | { |
3252 | symbol_get_tc (exp.X_add_symbol)->within = ppc_current_block; | |
3253 | } | |
6877bb43 | 3254 | } |
99a814a1 | 3255 | |
252b5132 RH |
3256 | if (exp.X_op != O_symbol |
3257 | || ! S_IS_EXTERNAL (exp.X_add_symbol) | |
3258 | || S_GET_SEGMENT (exp.X_add_symbol) != bss_section) | |
3259 | ppc_frob_label (sym); | |
3260 | else | |
3261 | { | |
3262 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
3263 | symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP); | |
809ffe0d ILT |
3264 | if (symbol_get_tc (ppc_current_csect)->within == exp.X_add_symbol) |
3265 | symbol_get_tc (ppc_current_csect)->within = sym; | |
252b5132 RH |
3266 | } |
3267 | ||
3268 | demand_empty_rest_of_line (); | |
3269 | } | |
3270 | ||
3271 | /* The .function pseudo-op. This takes several arguments. The first | |
3272 | argument seems to be the external name of the symbol. The second | |
3273 | argment seems to be the label for the start of the function. gcc | |
3274 | uses the same name for both. I have no idea what the third and | |
3275 | fourth arguments are meant to be. The optional fifth argument is | |
3276 | an expression for the size of the function. In COFF this symbol | |
3277 | gets an aux entry like that used for a csect. */ | |
3278 | ||
3279 | static void | |
3280 | ppc_function (ignore) | |
5480ccf3 | 3281 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3282 | { |
3283 | char *name; | |
3284 | char endc; | |
3285 | char *s; | |
3286 | symbolS *ext_sym; | |
3287 | symbolS *lab_sym; | |
3288 | ||
3289 | name = input_line_pointer; | |
3290 | endc = get_symbol_end (); | |
3291 | ||
3292 | /* Ignore any [PR] suffix. */ | |
3293 | name = ppc_canonicalize_symbol_name (name); | |
3294 | s = strchr (name, '['); | |
3295 | if (s != (char *) NULL | |
3296 | && strcmp (s + 1, "PR]") == 0) | |
3297 | *s = '\0'; | |
3298 | ||
3299 | ext_sym = symbol_find_or_make (name); | |
3300 | ||
3301 | *input_line_pointer = endc; | |
3302 | ||
3303 | if (*input_line_pointer != ',') | |
3304 | { | |
3305 | as_bad (_("missing symbol name")); | |
3306 | ignore_rest_of_line (); | |
3307 | return; | |
3308 | } | |
3309 | ++input_line_pointer; | |
3310 | ||
3311 | name = input_line_pointer; | |
3312 | endc = get_symbol_end (); | |
3313 | ||
3314 | lab_sym = symbol_find_or_make (name); | |
3315 | ||
3316 | *input_line_pointer = endc; | |
3317 | ||
3318 | if (ext_sym != lab_sym) | |
3319 | { | |
809ffe0d ILT |
3320 | expressionS exp; |
3321 | ||
3322 | exp.X_op = O_symbol; | |
3323 | exp.X_add_symbol = lab_sym; | |
3324 | exp.X_op_symbol = NULL; | |
3325 | exp.X_add_number = 0; | |
3326 | exp.X_unsigned = 0; | |
3327 | symbol_set_value_expression (ext_sym, &exp); | |
252b5132 RH |
3328 | } |
3329 | ||
809ffe0d ILT |
3330 | if (symbol_get_tc (ext_sym)->class == -1) |
3331 | symbol_get_tc (ext_sym)->class = XMC_PR; | |
3332 | symbol_get_tc (ext_sym)->output = 1; | |
252b5132 RH |
3333 | |
3334 | if (*input_line_pointer == ',') | |
3335 | { | |
3336 | expressionS ignore; | |
3337 | ||
3338 | /* Ignore the third argument. */ | |
3339 | ++input_line_pointer; | |
3340 | expression (&ignore); | |
3341 | if (*input_line_pointer == ',') | |
3342 | { | |
3343 | /* Ignore the fourth argument. */ | |
3344 | ++input_line_pointer; | |
3345 | expression (&ignore); | |
3346 | if (*input_line_pointer == ',') | |
3347 | { | |
3348 | /* The fifth argument is the function size. */ | |
3349 | ++input_line_pointer; | |
809ffe0d ILT |
3350 | symbol_get_tc (ext_sym)->size = symbol_new ("L0\001", |
3351 | absolute_section, | |
3352 | (valueT) 0, | |
3353 | &zero_address_frag); | |
3354 | pseudo_set (symbol_get_tc (ext_sym)->size); | |
252b5132 RH |
3355 | } |
3356 | } | |
3357 | } | |
3358 | ||
3359 | S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT); | |
3360 | SF_SET_FUNCTION (ext_sym); | |
3361 | SF_SET_PROCESS (ext_sym); | |
3362 | coff_add_linesym (ext_sym); | |
3363 | ||
3364 | demand_empty_rest_of_line (); | |
3365 | } | |
3366 | ||
3367 | /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named | |
8642cce8 TR |
3368 | ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym |
3369 | with the correct line number */ | |
5d6255fe | 3370 | |
8642cce8 | 3371 | static symbolS *saved_bi_sym = 0; |
252b5132 RH |
3372 | |
3373 | static void | |
3374 | ppc_bf (ignore) | |
5480ccf3 | 3375 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3376 | { |
3377 | symbolS *sym; | |
3378 | ||
3379 | sym = symbol_make (".bf"); | |
3380 | S_SET_SEGMENT (sym, text_section); | |
809ffe0d | 3381 | symbol_set_frag (sym, frag_now); |
252b5132 RH |
3382 | S_SET_VALUE (sym, frag_now_fix ()); |
3383 | S_SET_STORAGE_CLASS (sym, C_FCN); | |
3384 | ||
3385 | coff_line_base = get_absolute_expression (); | |
3386 | ||
3387 | S_SET_NUMBER_AUXILIARY (sym, 1); | |
3388 | SA_SET_SYM_LNNO (sym, coff_line_base); | |
3389 | ||
8642cce8 | 3390 | /* Line number for bi. */ |
5d6255fe | 3391 | if (saved_bi_sym) |
8642cce8 TR |
3392 | { |
3393 | S_SET_VALUE (saved_bi_sym, coff_n_line_nos); | |
3394 | saved_bi_sym = 0; | |
3395 | } | |
5d6255fe | 3396 | |
8642cce8 | 3397 | |
809ffe0d | 3398 | symbol_get_tc (sym)->output = 1; |
252b5132 RH |
3399 | |
3400 | ppc_frob_label (sym); | |
3401 | ||
3402 | demand_empty_rest_of_line (); | |
3403 | } | |
3404 | ||
3405 | /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named | |
3406 | ".ef", except that the line number is absolute, not relative to the | |
3407 | most recent ".bf" symbol. */ | |
3408 | ||
3409 | static void | |
3410 | ppc_ef (ignore) | |
5480ccf3 | 3411 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3412 | { |
3413 | symbolS *sym; | |
3414 | ||
3415 | sym = symbol_make (".ef"); | |
3416 | S_SET_SEGMENT (sym, text_section); | |
809ffe0d | 3417 | symbol_set_frag (sym, frag_now); |
252b5132 RH |
3418 | S_SET_VALUE (sym, frag_now_fix ()); |
3419 | S_SET_STORAGE_CLASS (sym, C_FCN); | |
3420 | S_SET_NUMBER_AUXILIARY (sym, 1); | |
3421 | SA_SET_SYM_LNNO (sym, get_absolute_expression ()); | |
809ffe0d | 3422 | symbol_get_tc (sym)->output = 1; |
252b5132 RH |
3423 | |
3424 | ppc_frob_label (sym); | |
3425 | ||
3426 | demand_empty_rest_of_line (); | |
3427 | } | |
3428 | ||
3429 | /* The .bi and .ei pseudo-ops. These take a string argument and | |
3430 | generates a C_BINCL or C_EINCL symbol, which goes at the start of | |
8642cce8 TR |
3431 | the symbol list. The value of .bi will be know when the next .bf |
3432 | is encountered. */ | |
252b5132 RH |
3433 | |
3434 | static void | |
3435 | ppc_biei (ei) | |
3436 | int ei; | |
3437 | { | |
3438 | static symbolS *last_biei; | |
3439 | ||
3440 | char *name; | |
3441 | int len; | |
3442 | symbolS *sym; | |
3443 | symbolS *look; | |
3444 | ||
3445 | name = demand_copy_C_string (&len); | |
3446 | ||
3447 | /* The value of these symbols is actually file offset. Here we set | |
3448 | the value to the index into the line number entries. In | |
3449 | ppc_frob_symbols we set the fix_line field, which will cause BFD | |
3450 | to do the right thing. */ | |
3451 | ||
3452 | sym = symbol_make (name); | |
3453 | /* obj-coff.c currently only handles line numbers correctly in the | |
3454 | .text section. */ | |
3455 | S_SET_SEGMENT (sym, text_section); | |
3456 | S_SET_VALUE (sym, coff_n_line_nos); | |
809ffe0d | 3457 | symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; |
252b5132 RH |
3458 | |
3459 | S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL); | |
809ffe0d | 3460 | symbol_get_tc (sym)->output = 1; |
81d4177b | 3461 | |
8642cce8 | 3462 | /* Save bi. */ |
5d6255fe | 3463 | if (ei) |
8642cce8 TR |
3464 | saved_bi_sym = 0; |
3465 | else | |
3466 | saved_bi_sym = sym; | |
3467 | ||
252b5132 RH |
3468 | for (look = last_biei ? last_biei : symbol_rootP; |
3469 | (look != (symbolS *) NULL | |
3470 | && (S_GET_STORAGE_CLASS (look) == C_FILE | |
3471 | || S_GET_STORAGE_CLASS (look) == C_BINCL | |
3472 | || S_GET_STORAGE_CLASS (look) == C_EINCL)); | |
3473 | look = symbol_next (look)) | |
3474 | ; | |
3475 | if (look != (symbolS *) NULL) | |
3476 | { | |
3477 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
3478 | symbol_insert (sym, look, &symbol_rootP, &symbol_lastP); | |
3479 | last_biei = sym; | |
3480 | } | |
3481 | ||
3482 | demand_empty_rest_of_line (); | |
3483 | } | |
3484 | ||
3485 | /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs". | |
3486 | There is one argument, which is a csect symbol. The value of the | |
3487 | .bs symbol is the index of this csect symbol. */ | |
3488 | ||
3489 | static void | |
3490 | ppc_bs (ignore) | |
5480ccf3 | 3491 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3492 | { |
3493 | char *name; | |
3494 | char endc; | |
3495 | symbolS *csect; | |
3496 | symbolS *sym; | |
3497 | ||
3498 | if (ppc_current_block != NULL) | |
3499 | as_bad (_("nested .bs blocks")); | |
3500 | ||
3501 | name = input_line_pointer; | |
3502 | endc = get_symbol_end (); | |
3503 | ||
3504 | csect = symbol_find_or_make (name); | |
3505 | ||
3506 | *input_line_pointer = endc; | |
3507 | ||
3508 | sym = symbol_make (".bs"); | |
3509 | S_SET_SEGMENT (sym, now_seg); | |
3510 | S_SET_STORAGE_CLASS (sym, C_BSTAT); | |
809ffe0d ILT |
3511 | symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; |
3512 | symbol_get_tc (sym)->output = 1; | |
252b5132 | 3513 | |
809ffe0d | 3514 | symbol_get_tc (sym)->within = csect; |
252b5132 RH |
3515 | |
3516 | ppc_frob_label (sym); | |
3517 | ||
3518 | ppc_current_block = sym; | |
3519 | ||
3520 | demand_empty_rest_of_line (); | |
3521 | } | |
3522 | ||
3523 | /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */ | |
3524 | ||
3525 | static void | |
3526 | ppc_es (ignore) | |
5480ccf3 | 3527 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3528 | { |
3529 | symbolS *sym; | |
3530 | ||
3531 | if (ppc_current_block == NULL) | |
3532 | as_bad (_(".es without preceding .bs")); | |
3533 | ||
3534 | sym = symbol_make (".es"); | |
3535 | S_SET_SEGMENT (sym, now_seg); | |
3536 | S_SET_STORAGE_CLASS (sym, C_ESTAT); | |
809ffe0d ILT |
3537 | symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; |
3538 | symbol_get_tc (sym)->output = 1; | |
252b5132 RH |
3539 | |
3540 | ppc_frob_label (sym); | |
3541 | ||
3542 | ppc_current_block = NULL; | |
3543 | ||
3544 | demand_empty_rest_of_line (); | |
3545 | } | |
3546 | ||
3547 | /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a | |
3548 | line number. */ | |
3549 | ||
3550 | static void | |
3551 | ppc_bb (ignore) | |
5480ccf3 | 3552 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3553 | { |
3554 | symbolS *sym; | |
3555 | ||
3556 | sym = symbol_make (".bb"); | |
3557 | S_SET_SEGMENT (sym, text_section); | |
809ffe0d | 3558 | symbol_set_frag (sym, frag_now); |
252b5132 RH |
3559 | S_SET_VALUE (sym, frag_now_fix ()); |
3560 | S_SET_STORAGE_CLASS (sym, C_BLOCK); | |
3561 | ||
3562 | S_SET_NUMBER_AUXILIARY (sym, 1); | |
3563 | SA_SET_SYM_LNNO (sym, get_absolute_expression ()); | |
3564 | ||
809ffe0d | 3565 | symbol_get_tc (sym)->output = 1; |
252b5132 RH |
3566 | |
3567 | SF_SET_PROCESS (sym); | |
3568 | ||
3569 | ppc_frob_label (sym); | |
3570 | ||
3571 | demand_empty_rest_of_line (); | |
3572 | } | |
3573 | ||
3574 | /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a | |
3575 | line number. */ | |
3576 | ||
3577 | static void | |
3578 | ppc_eb (ignore) | |
5480ccf3 | 3579 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3580 | { |
3581 | symbolS *sym; | |
3582 | ||
3583 | sym = symbol_make (".eb"); | |
3584 | S_SET_SEGMENT (sym, text_section); | |
809ffe0d | 3585 | symbol_set_frag (sym, frag_now); |
252b5132 RH |
3586 | S_SET_VALUE (sym, frag_now_fix ()); |
3587 | S_SET_STORAGE_CLASS (sym, C_BLOCK); | |
3588 | S_SET_NUMBER_AUXILIARY (sym, 1); | |
3589 | SA_SET_SYM_LNNO (sym, get_absolute_expression ()); | |
809ffe0d | 3590 | symbol_get_tc (sym)->output = 1; |
252b5132 RH |
3591 | |
3592 | SF_SET_PROCESS (sym); | |
3593 | ||
3594 | ppc_frob_label (sym); | |
3595 | ||
3596 | demand_empty_rest_of_line (); | |
3597 | } | |
3598 | ||
3599 | /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a | |
3600 | specified name. */ | |
3601 | ||
3602 | static void | |
3603 | ppc_bc (ignore) | |
5480ccf3 | 3604 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3605 | { |
3606 | char *name; | |
3607 | int len; | |
3608 | symbolS *sym; | |
3609 | ||
3610 | name = demand_copy_C_string (&len); | |
3611 | sym = symbol_make (name); | |
3612 | S_SET_SEGMENT (sym, ppc_coff_debug_section); | |
809ffe0d | 3613 | symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; |
252b5132 RH |
3614 | S_SET_STORAGE_CLASS (sym, C_BCOMM); |
3615 | S_SET_VALUE (sym, 0); | |
809ffe0d | 3616 | symbol_get_tc (sym)->output = 1; |
252b5132 RH |
3617 | |
3618 | ppc_frob_label (sym); | |
3619 | ||
3620 | demand_empty_rest_of_line (); | |
3621 | } | |
3622 | ||
3623 | /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */ | |
3624 | ||
3625 | static void | |
3626 | ppc_ec (ignore) | |
5480ccf3 | 3627 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3628 | { |
3629 | symbolS *sym; | |
3630 | ||
3631 | sym = symbol_make (".ec"); | |
3632 | S_SET_SEGMENT (sym, ppc_coff_debug_section); | |
809ffe0d | 3633 | symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; |
252b5132 RH |
3634 | S_SET_STORAGE_CLASS (sym, C_ECOMM); |
3635 | S_SET_VALUE (sym, 0); | |
809ffe0d | 3636 | symbol_get_tc (sym)->output = 1; |
252b5132 RH |
3637 | |
3638 | ppc_frob_label (sym); | |
3639 | ||
3640 | demand_empty_rest_of_line (); | |
3641 | } | |
3642 | ||
3643 | /* The .toc pseudo-op. Switch to the .toc subsegment. */ | |
3644 | ||
3645 | static void | |
3646 | ppc_toc (ignore) | |
5480ccf3 | 3647 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3648 | { |
3649 | if (ppc_toc_csect != (symbolS *) NULL) | |
809ffe0d | 3650 | subseg_set (data_section, symbol_get_tc (ppc_toc_csect)->subseg); |
252b5132 RH |
3651 | else |
3652 | { | |
3653 | subsegT subseg; | |
3654 | symbolS *sym; | |
3655 | symbolS *list; | |
81d4177b | 3656 | |
252b5132 RH |
3657 | subseg = ppc_data_subsegment; |
3658 | ++ppc_data_subsegment; | |
3659 | ||
3660 | subseg_new (segment_name (data_section), subseg); | |
3661 | ppc_toc_frag = frag_now; | |
3662 | ||
3663 | sym = symbol_find_or_make ("TOC[TC0]"); | |
809ffe0d | 3664 | symbol_set_frag (sym, frag_now); |
252b5132 RH |
3665 | S_SET_SEGMENT (sym, data_section); |
3666 | S_SET_VALUE (sym, (valueT) frag_now_fix ()); | |
809ffe0d ILT |
3667 | symbol_get_tc (sym)->subseg = subseg; |
3668 | symbol_get_tc (sym)->output = 1; | |
3669 | symbol_get_tc (sym)->within = sym; | |
252b5132 RH |
3670 | |
3671 | ppc_toc_csect = sym; | |
81d4177b | 3672 | |
252b5132 | 3673 | for (list = ppc_data_csects; |
809ffe0d ILT |
3674 | symbol_get_tc (list)->next != (symbolS *) NULL; |
3675 | list = symbol_get_tc (list)->next) | |
252b5132 | 3676 | ; |
809ffe0d | 3677 | symbol_get_tc (list)->next = sym; |
252b5132 RH |
3678 | |
3679 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
809ffe0d ILT |
3680 | symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP, |
3681 | &symbol_lastP); | |
252b5132 RH |
3682 | } |
3683 | ||
3684 | ppc_current_csect = ppc_toc_csect; | |
3685 | ||
3686 | demand_empty_rest_of_line (); | |
3687 | } | |
3688 | ||
3689 | /* The AIX assembler automatically aligns the operands of a .long or | |
3690 | .short pseudo-op, and we want to be compatible. */ | |
3691 | ||
3692 | static void | |
3693 | ppc_xcoff_cons (log_size) | |
3694 | int log_size; | |
3695 | { | |
3696 | frag_align (log_size, 0, 0); | |
3697 | record_alignment (now_seg, log_size); | |
3698 | cons (1 << log_size); | |
3699 | } | |
3700 | ||
3701 | static void | |
3702 | ppc_vbyte (dummy) | |
5480ccf3 | 3703 | int dummy ATTRIBUTE_UNUSED; |
252b5132 RH |
3704 | { |
3705 | expressionS exp; | |
3706 | int byte_count; | |
3707 | ||
3708 | (void) expression (&exp); | |
3709 | ||
3710 | if (exp.X_op != O_constant) | |
3711 | { | |
3712 | as_bad (_("non-constant byte count")); | |
3713 | return; | |
3714 | } | |
3715 | ||
3716 | byte_count = exp.X_add_number; | |
3717 | ||
3718 | if (*input_line_pointer != ',') | |
3719 | { | |
3720 | as_bad (_("missing value")); | |
3721 | return; | |
3722 | } | |
3723 | ||
3724 | ++input_line_pointer; | |
3725 | cons (byte_count); | |
3726 | } | |
3727 | ||
3728 | #endif /* OBJ_XCOFF */ | |
0baf16f2 | 3729 | #if defined (OBJ_XCOFF) || defined (OBJ_ELF) |
252b5132 RH |
3730 | \f |
3731 | /* The .tc pseudo-op. This is used when generating either XCOFF or | |
3732 | ELF. This takes two or more arguments. | |
3733 | ||
3734 | When generating XCOFF output, the first argument is the name to | |
3735 | give to this location in the toc; this will be a symbol with class | |
0baf16f2 | 3736 | TC. The rest of the arguments are N-byte values to actually put at |
252b5132 | 3737 | this location in the TOC; often there is just one more argument, a |
0baf16f2 AM |
3738 | relocateable symbol reference. The size of the value to store |
3739 | depends on target word size. A 32-bit target uses 4-byte values, a | |
3740 | 64-bit target uses 8-byte values. | |
252b5132 RH |
3741 | |
3742 | When not generating XCOFF output, the arguments are the same, but | |
3743 | the first argument is simply ignored. */ | |
3744 | ||
3745 | static void | |
3746 | ppc_tc (ignore) | |
92161534 | 3747 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3748 | { |
3749 | #ifdef OBJ_XCOFF | |
3750 | ||
3751 | /* Define the TOC symbol name. */ | |
3752 | { | |
3753 | char *name; | |
3754 | char endc; | |
3755 | symbolS *sym; | |
3756 | ||
3757 | if (ppc_toc_csect == (symbolS *) NULL | |
3758 | || ppc_toc_csect != ppc_current_csect) | |
3759 | { | |
3760 | as_bad (_(".tc not in .toc section")); | |
3761 | ignore_rest_of_line (); | |
3762 | return; | |
3763 | } | |
3764 | ||
3765 | name = input_line_pointer; | |
3766 | endc = get_symbol_end (); | |
3767 | ||
3768 | sym = symbol_find_or_make (name); | |
3769 | ||
3770 | *input_line_pointer = endc; | |
3771 | ||
3772 | if (S_IS_DEFINED (sym)) | |
3773 | { | |
3774 | symbolS *label; | |
3775 | ||
809ffe0d ILT |
3776 | label = symbol_get_tc (ppc_current_csect)->within; |
3777 | if (symbol_get_tc (label)->class != XMC_TC0) | |
252b5132 RH |
3778 | { |
3779 | as_bad (_(".tc with no label")); | |
3780 | ignore_rest_of_line (); | |
3781 | return; | |
3782 | } | |
3783 | ||
3784 | S_SET_SEGMENT (label, S_GET_SEGMENT (sym)); | |
809ffe0d | 3785 | symbol_set_frag (label, symbol_get_frag (sym)); |
252b5132 RH |
3786 | S_SET_VALUE (label, S_GET_VALUE (sym)); |
3787 | ||
3788 | while (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
3789 | ++input_line_pointer; | |
3790 | ||
3791 | return; | |
3792 | } | |
3793 | ||
3794 | S_SET_SEGMENT (sym, now_seg); | |
809ffe0d | 3795 | symbol_set_frag (sym, frag_now); |
252b5132 | 3796 | S_SET_VALUE (sym, (valueT) frag_now_fix ()); |
809ffe0d ILT |
3797 | symbol_get_tc (sym)->class = XMC_TC; |
3798 | symbol_get_tc (sym)->output = 1; | |
252b5132 RH |
3799 | |
3800 | ppc_frob_label (sym); | |
3801 | } | |
3802 | ||
0baf16f2 AM |
3803 | #endif /* OBJ_XCOFF */ |
3804 | #ifdef OBJ_ELF | |
9c7977b3 | 3805 | int align; |
252b5132 RH |
3806 | |
3807 | /* Skip the TOC symbol name. */ | |
3808 | while (is_part_of_name (*input_line_pointer) | |
3809 | || *input_line_pointer == '[' | |
3810 | || *input_line_pointer == ']' | |
3811 | || *input_line_pointer == '{' | |
3812 | || *input_line_pointer == '}') | |
3813 | ++input_line_pointer; | |
3814 | ||
0baf16f2 | 3815 | /* Align to a four/eight byte boundary. */ |
2b3c4602 | 3816 | align = ppc_obj64 ? 3 : 2; |
9c7977b3 AM |
3817 | frag_align (align, 0, 0); |
3818 | record_alignment (now_seg, align); | |
0baf16f2 | 3819 | #endif /* OBJ_ELF */ |
252b5132 RH |
3820 | |
3821 | if (*input_line_pointer != ',') | |
3822 | demand_empty_rest_of_line (); | |
3823 | else | |
3824 | { | |
3825 | ++input_line_pointer; | |
2b3c4602 | 3826 | cons (ppc_obj64 ? 8 : 4); |
252b5132 RH |
3827 | } |
3828 | } | |
0baf16f2 AM |
3829 | |
3830 | /* Pseudo-op .machine. */ | |
15c1449b | 3831 | /* FIXME: `.machine' is a nop for the moment. It would be nice to |
2b3c4602 | 3832 | accept this directive on the first line of input and set ppc_obj64 |
15c1449b AM |
3833 | and the target format accordingly. Unfortunately, the target |
3834 | format is selected in output-file.c:output_file_create before we | |
3835 | even get to md_begin, so it's not possible without changing | |
3836 | as.c:main. */ | |
0baf16f2 AM |
3837 | |
3838 | static void | |
3839 | ppc_machine (ignore) | |
3840 | int ignore ATTRIBUTE_UNUSED; | |
3841 | { | |
3842 | discard_rest_of_line (); | |
3843 | } | |
3844 | ||
3845 | /* See whether a symbol is in the TOC section. */ | |
3846 | ||
3847 | static int | |
3848 | ppc_is_toc_sym (sym) | |
3849 | symbolS *sym; | |
3850 | { | |
3851 | #ifdef OBJ_XCOFF | |
3852 | return symbol_get_tc (sym)->class == XMC_TC; | |
3853 | #endif | |
3854 | #ifdef OBJ_ELF | |
3855 | const char *sname = segment_name (S_GET_SEGMENT (sym)); | |
2b3c4602 | 3856 | if (ppc_obj64) |
0baf16f2 AM |
3857 | return strcmp (sname, ".toc") == 0; |
3858 | else | |
3859 | return strcmp (sname, ".got") == 0; | |
3860 | #endif | |
3861 | } | |
3862 | #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */ | |
252b5132 RH |
3863 | \f |
3864 | #ifdef TE_PE | |
3865 | ||
99a814a1 | 3866 | /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */ |
252b5132 RH |
3867 | |
3868 | /* Set the current section. */ | |
3869 | static void | |
3870 | ppc_set_current_section (new) | |
3871 | segT new; | |
3872 | { | |
3873 | ppc_previous_section = ppc_current_section; | |
3874 | ppc_current_section = new; | |
3875 | } | |
3876 | ||
3877 | /* pseudo-op: .previous | |
3878 | behaviour: toggles the current section with the previous section. | |
3879 | errors: None | |
99a814a1 AM |
3880 | warnings: "No previous section" */ |
3881 | ||
252b5132 | 3882 | static void |
99a814a1 | 3883 | ppc_previous (ignore) |
5480ccf3 | 3884 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3885 | { |
3886 | symbolS *tmp; | |
3887 | ||
81d4177b | 3888 | if (ppc_previous_section == NULL) |
252b5132 | 3889 | { |
99a814a1 | 3890 | as_warn (_("No previous section to return to. Directive ignored.")); |
252b5132 RH |
3891 | return; |
3892 | } | |
3893 | ||
99a814a1 | 3894 | subseg_set (ppc_previous_section, 0); |
252b5132 | 3895 | |
99a814a1 | 3896 | ppc_set_current_section (ppc_previous_section); |
252b5132 RH |
3897 | } |
3898 | ||
3899 | /* pseudo-op: .pdata | |
3900 | behaviour: predefined read only data section | |
3901 | double word aligned | |
3902 | errors: None | |
3903 | warnings: None | |
3904 | initial: .section .pdata "adr3" | |
3905 | a - don't know -- maybe a misprint | |
3906 | d - initialized data | |
3907 | r - readable | |
3908 | 3 - double word aligned (that would be 4 byte boundary) | |
3909 | ||
3910 | commentary: | |
3911 | Tag index tables (also known as the function table) for exception | |
99a814a1 | 3912 | handling, debugging, etc. */ |
252b5132 | 3913 | |
252b5132 | 3914 | static void |
99a814a1 | 3915 | ppc_pdata (ignore) |
5480ccf3 | 3916 | int ignore ATTRIBUTE_UNUSED; |
252b5132 | 3917 | { |
81d4177b | 3918 | if (pdata_section == 0) |
252b5132 RH |
3919 | { |
3920 | pdata_section = subseg_new (".pdata", 0); | |
81d4177b | 3921 | |
252b5132 RH |
3922 | bfd_set_section_flags (stdoutput, pdata_section, |
3923 | (SEC_ALLOC | SEC_LOAD | SEC_RELOC | |
3924 | | SEC_READONLY | SEC_DATA )); | |
81d4177b | 3925 | |
252b5132 RH |
3926 | bfd_set_section_alignment (stdoutput, pdata_section, 2); |
3927 | } | |
3928 | else | |
3929 | { | |
99a814a1 | 3930 | pdata_section = subseg_new (".pdata", 0); |
252b5132 | 3931 | } |
99a814a1 | 3932 | ppc_set_current_section (pdata_section); |
252b5132 RH |
3933 | } |
3934 | ||
3935 | /* pseudo-op: .ydata | |
3936 | behaviour: predefined read only data section | |
3937 | double word aligned | |
3938 | errors: None | |
3939 | warnings: None | |
3940 | initial: .section .ydata "drw3" | |
3941 | a - don't know -- maybe a misprint | |
3942 | d - initialized data | |
3943 | r - readable | |
3944 | 3 - double word aligned (that would be 4 byte boundary) | |
3945 | commentary: | |
3946 | Tag tables (also known as the scope table) for exception handling, | |
99a814a1 AM |
3947 | debugging, etc. */ |
3948 | ||
252b5132 | 3949 | static void |
99a814a1 | 3950 | ppc_ydata (ignore) |
5480ccf3 | 3951 | int ignore ATTRIBUTE_UNUSED; |
252b5132 | 3952 | { |
81d4177b | 3953 | if (ydata_section == 0) |
252b5132 RH |
3954 | { |
3955 | ydata_section = subseg_new (".ydata", 0); | |
3956 | bfd_set_section_flags (stdoutput, ydata_section, | |
99a814a1 AM |
3957 | (SEC_ALLOC | SEC_LOAD | SEC_RELOC |
3958 | | SEC_READONLY | SEC_DATA )); | |
252b5132 RH |
3959 | |
3960 | bfd_set_section_alignment (stdoutput, ydata_section, 3); | |
3961 | } | |
3962 | else | |
3963 | { | |
3964 | ydata_section = subseg_new (".ydata", 0); | |
3965 | } | |
99a814a1 | 3966 | ppc_set_current_section (ydata_section); |
252b5132 RH |
3967 | } |
3968 | ||
3969 | /* pseudo-op: .reldata | |
3970 | behaviour: predefined read write data section | |
3971 | double word aligned (4-byte) | |
3972 | FIXME: relocation is applied to it | |
3973 | FIXME: what's the difference between this and .data? | |
3974 | errors: None | |
3975 | warnings: None | |
3976 | initial: .section .reldata "drw3" | |
3977 | d - initialized data | |
3978 | r - readable | |
3979 | w - writeable | |
3980 | 3 - double word aligned (that would be 8 byte boundary) | |
3981 | ||
3982 | commentary: | |
3983 | Like .data, but intended to hold data subject to relocation, such as | |
99a814a1 AM |
3984 | function descriptors, etc. */ |
3985 | ||
252b5132 | 3986 | static void |
99a814a1 | 3987 | ppc_reldata (ignore) |
5480ccf3 | 3988 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
3989 | { |
3990 | if (reldata_section == 0) | |
3991 | { | |
3992 | reldata_section = subseg_new (".reldata", 0); | |
3993 | ||
3994 | bfd_set_section_flags (stdoutput, reldata_section, | |
99a814a1 AM |
3995 | (SEC_ALLOC | SEC_LOAD | SEC_RELOC |
3996 | | SEC_DATA)); | |
252b5132 RH |
3997 | |
3998 | bfd_set_section_alignment (stdoutput, reldata_section, 2); | |
3999 | } | |
4000 | else | |
4001 | { | |
4002 | reldata_section = subseg_new (".reldata", 0); | |
4003 | } | |
99a814a1 | 4004 | ppc_set_current_section (reldata_section); |
252b5132 RH |
4005 | } |
4006 | ||
4007 | /* pseudo-op: .rdata | |
4008 | behaviour: predefined read only data section | |
4009 | double word aligned | |
4010 | errors: None | |
4011 | warnings: None | |
4012 | initial: .section .rdata "dr3" | |
4013 | d - initialized data | |
4014 | r - readable | |
99a814a1 AM |
4015 | 3 - double word aligned (that would be 4 byte boundary) */ |
4016 | ||
252b5132 | 4017 | static void |
99a814a1 | 4018 | ppc_rdata (ignore) |
5480ccf3 | 4019 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
4020 | { |
4021 | if (rdata_section == 0) | |
4022 | { | |
4023 | rdata_section = subseg_new (".rdata", 0); | |
4024 | bfd_set_section_flags (stdoutput, rdata_section, | |
4025 | (SEC_ALLOC | SEC_LOAD | SEC_RELOC | |
4026 | | SEC_READONLY | SEC_DATA )); | |
4027 | ||
4028 | bfd_set_section_alignment (stdoutput, rdata_section, 2); | |
4029 | } | |
4030 | else | |
4031 | { | |
4032 | rdata_section = subseg_new (".rdata", 0); | |
4033 | } | |
99a814a1 | 4034 | ppc_set_current_section (rdata_section); |
252b5132 RH |
4035 | } |
4036 | ||
4037 | /* pseudo-op: .ualong | |
81d4177b | 4038 | behaviour: much like .int, with the exception that no alignment is |
252b5132 RH |
4039 | performed. |
4040 | FIXME: test the alignment statement | |
4041 | errors: None | |
99a814a1 AM |
4042 | warnings: None */ |
4043 | ||
252b5132 | 4044 | static void |
99a814a1 | 4045 | ppc_ualong (ignore) |
5480ccf3 | 4046 | int ignore ATTRIBUTE_UNUSED; |
252b5132 | 4047 | { |
99a814a1 AM |
4048 | /* Try for long. */ |
4049 | cons (4); | |
252b5132 RH |
4050 | } |
4051 | ||
4052 | /* pseudo-op: .znop <symbol name> | |
4053 | behaviour: Issue a nop instruction | |
4054 | Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using | |
4055 | the supplied symbol name. | |
4056 | errors: None | |
99a814a1 AM |
4057 | warnings: Missing symbol name */ |
4058 | ||
252b5132 | 4059 | static void |
99a814a1 | 4060 | ppc_znop (ignore) |
5480ccf3 | 4061 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
4062 | { |
4063 | unsigned long insn; | |
4064 | const struct powerpc_opcode *opcode; | |
4065 | expressionS ex; | |
4066 | char *f; | |
252b5132 | 4067 | symbolS *sym; |
252b5132 RH |
4068 | char *symbol_name; |
4069 | char c; | |
4070 | char *name; | |
4071 | unsigned int exp; | |
4072 | flagword flags; | |
4073 | asection *sec; | |
4074 | ||
99a814a1 | 4075 | /* Strip out the symbol name. */ |
252b5132 RH |
4076 | symbol_name = input_line_pointer; |
4077 | c = get_symbol_end (); | |
4078 | ||
4079 | name = xmalloc (input_line_pointer - symbol_name + 1); | |
4080 | strcpy (name, symbol_name); | |
4081 | ||
4082 | sym = symbol_find_or_make (name); | |
4083 | ||
4084 | *input_line_pointer = c; | |
4085 | ||
4086 | SKIP_WHITESPACE (); | |
4087 | ||
4088 | /* Look up the opcode in the hash table. */ | |
4089 | opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop"); | |
4090 | ||
99a814a1 | 4091 | /* Stick in the nop. */ |
252b5132 RH |
4092 | insn = opcode->opcode; |
4093 | ||
4094 | /* Write out the instruction. */ | |
4095 | f = frag_more (4); | |
4096 | md_number_to_chars (f, insn, 4); | |
4097 | fix_new (frag_now, | |
4098 | f - frag_now->fr_literal, | |
4099 | 4, | |
4100 | sym, | |
4101 | 0, | |
4102 | 0, | |
4103 | BFD_RELOC_16_GOT_PCREL); | |
4104 | ||
4105 | } | |
4106 | ||
81d4177b KH |
4107 | /* pseudo-op: |
4108 | behaviour: | |
4109 | errors: | |
99a814a1 AM |
4110 | warnings: */ |
4111 | ||
252b5132 | 4112 | static void |
99a814a1 | 4113 | ppc_pe_comm (lcomm) |
252b5132 RH |
4114 | int lcomm; |
4115 | { | |
4116 | register char *name; | |
4117 | register char c; | |
4118 | register char *p; | |
4119 | offsetT temp; | |
4120 | register symbolS *symbolP; | |
4121 | offsetT align; | |
4122 | ||
4123 | name = input_line_pointer; | |
4124 | c = get_symbol_end (); | |
4125 | ||
99a814a1 | 4126 | /* just after name is now '\0'. */ |
252b5132 RH |
4127 | p = input_line_pointer; |
4128 | *p = c; | |
4129 | SKIP_WHITESPACE (); | |
4130 | if (*input_line_pointer != ',') | |
4131 | { | |
4132 | as_bad (_("Expected comma after symbol-name: rest of line ignored.")); | |
4133 | ignore_rest_of_line (); | |
4134 | return; | |
4135 | } | |
4136 | ||
4137 | input_line_pointer++; /* skip ',' */ | |
4138 | if ((temp = get_absolute_expression ()) < 0) | |
4139 | { | |
4140 | as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp); | |
4141 | ignore_rest_of_line (); | |
4142 | return; | |
4143 | } | |
4144 | ||
4145 | if (! lcomm) | |
4146 | { | |
4147 | /* The third argument to .comm is the alignment. */ | |
4148 | if (*input_line_pointer != ',') | |
4149 | align = 3; | |
4150 | else | |
4151 | { | |
4152 | ++input_line_pointer; | |
4153 | align = get_absolute_expression (); | |
4154 | if (align <= 0) | |
4155 | { | |
4156 | as_warn (_("ignoring bad alignment")); | |
4157 | align = 3; | |
4158 | } | |
4159 | } | |
4160 | } | |
4161 | ||
4162 | *p = 0; | |
4163 | symbolP = symbol_find_or_make (name); | |
4164 | ||
4165 | *p = c; | |
4166 | if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP)) | |
4167 | { | |
4168 | as_bad (_("Ignoring attempt to re-define symbol `%s'."), | |
4169 | S_GET_NAME (symbolP)); | |
4170 | ignore_rest_of_line (); | |
4171 | return; | |
4172 | } | |
4173 | ||
4174 | if (S_GET_VALUE (symbolP)) | |
4175 | { | |
4176 | if (S_GET_VALUE (symbolP) != (valueT) temp) | |
4177 | as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."), | |
4178 | S_GET_NAME (symbolP), | |
4179 | (long) S_GET_VALUE (symbolP), | |
4180 | (long) temp); | |
4181 | } | |
4182 | else | |
4183 | { | |
4184 | S_SET_VALUE (symbolP, (valueT) temp); | |
4185 | S_SET_EXTERNAL (symbolP); | |
4186 | } | |
4187 | ||
4188 | demand_empty_rest_of_line (); | |
4189 | } | |
4190 | ||
4191 | /* | |
4192 | * implement the .section pseudo op: | |
4193 | * .section name {, "flags"} | |
4194 | * ^ ^ | |
4195 | * | +--- optional flags: 'b' for bss | |
4196 | * | 'i' for info | |
4197 | * +-- section name 'l' for lib | |
4198 | * 'n' for noload | |
4199 | * 'o' for over | |
4200 | * 'w' for data | |
4201 | * 'd' (apparently m88k for data) | |
4202 | * 'x' for text | |
4203 | * But if the argument is not a quoted string, treat it as a | |
4204 | * subsegment number. | |
4205 | * | |
4206 | * FIXME: this is a copy of the section processing from obj-coff.c, with | |
4207 | * additions/changes for the moto-pas assembler support. There are three | |
4208 | * categories: | |
4209 | * | |
81d4177b | 4210 | * FIXME: I just noticed this. This doesn't work at all really. It it |
252b5132 RH |
4211 | * setting bits that bfd probably neither understands or uses. The |
4212 | * correct approach (?) will have to incorporate extra fields attached | |
4213 | * to the section to hold the system specific stuff. (krk) | |
4214 | * | |
4215 | * Section Contents: | |
4216 | * 'a' - unknown - referred to in documentation, but no definition supplied | |
4217 | * 'c' - section has code | |
4218 | * 'd' - section has initialized data | |
4219 | * 'u' - section has uninitialized data | |
4220 | * 'i' - section contains directives (info) | |
4221 | * 'n' - section can be discarded | |
4222 | * 'R' - remove section at link time | |
4223 | * | |
4224 | * Section Protection: | |
4225 | * 'r' - section is readable | |
4226 | * 'w' - section is writeable | |
4227 | * 'x' - section is executable | |
4228 | * 's' - section is sharable | |
4229 | * | |
4230 | * Section Alignment: | |
4231 | * '0' - align to byte boundary | |
4232 | * '1' - align to halfword undary | |
4233 | * '2' - align to word boundary | |
4234 | * '3' - align to doubleword boundary | |
4235 | * '4' - align to quadword boundary | |
4236 | * '5' - align to 32 byte boundary | |
4237 | * '6' - align to 64 byte boundary | |
4238 | * | |
4239 | */ | |
4240 | ||
4241 | void | |
4242 | ppc_pe_section (ignore) | |
5480ccf3 | 4243 | int ignore ATTRIBUTE_UNUSED; |
252b5132 | 4244 | { |
99a814a1 | 4245 | /* Strip out the section name. */ |
252b5132 RH |
4246 | char *section_name; |
4247 | char c; | |
4248 | char *name; | |
4249 | unsigned int exp; | |
4250 | flagword flags; | |
4251 | segT sec; | |
4252 | int align; | |
4253 | ||
4254 | section_name = input_line_pointer; | |
4255 | c = get_symbol_end (); | |
4256 | ||
4257 | name = xmalloc (input_line_pointer - section_name + 1); | |
4258 | strcpy (name, section_name); | |
4259 | ||
4260 | *input_line_pointer = c; | |
4261 | ||
4262 | SKIP_WHITESPACE (); | |
4263 | ||
4264 | exp = 0; | |
4265 | flags = SEC_NO_FLAGS; | |
4266 | ||
4267 | if (strcmp (name, ".idata$2") == 0) | |
4268 | { | |
4269 | align = 0; | |
4270 | } | |
4271 | else if (strcmp (name, ".idata$3") == 0) | |
4272 | { | |
4273 | align = 0; | |
4274 | } | |
4275 | else if (strcmp (name, ".idata$4") == 0) | |
4276 | { | |
4277 | align = 2; | |
4278 | } | |
4279 | else if (strcmp (name, ".idata$5") == 0) | |
4280 | { | |
4281 | align = 2; | |
4282 | } | |
4283 | else if (strcmp (name, ".idata$6") == 0) | |
4284 | { | |
4285 | align = 1; | |
4286 | } | |
4287 | else | |
99a814a1 AM |
4288 | /* Default alignment to 16 byte boundary. */ |
4289 | align = 4; | |
252b5132 RH |
4290 | |
4291 | if (*input_line_pointer == ',') | |
4292 | { | |
4293 | ++input_line_pointer; | |
4294 | SKIP_WHITESPACE (); | |
4295 | if (*input_line_pointer != '"') | |
4296 | exp = get_absolute_expression (); | |
4297 | else | |
4298 | { | |
4299 | ++input_line_pointer; | |
4300 | while (*input_line_pointer != '"' | |
4301 | && ! is_end_of_line[(unsigned char) *input_line_pointer]) | |
4302 | { | |
4303 | switch (*input_line_pointer) | |
4304 | { | |
4305 | /* Section Contents */ | |
4306 | case 'a': /* unknown */ | |
4307 | as_bad (_("Unsupported section attribute -- 'a'")); | |
4308 | break; | |
4309 | case 'c': /* code section */ | |
81d4177b | 4310 | flags |= SEC_CODE; |
252b5132 RH |
4311 | break; |
4312 | case 'd': /* section has initialized data */ | |
4313 | flags |= SEC_DATA; | |
4314 | break; | |
4315 | case 'u': /* section has uninitialized data */ | |
4316 | /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA | |
4317 | in winnt.h */ | |
4318 | flags |= SEC_ROM; | |
4319 | break; | |
4320 | case 'i': /* section contains directives (info) */ | |
4321 | /* FIXME: This is IMAGE_SCN_LNK_INFO | |
4322 | in winnt.h */ | |
4323 | flags |= SEC_HAS_CONTENTS; | |
4324 | break; | |
4325 | case 'n': /* section can be discarded */ | |
81d4177b | 4326 | flags &=~ SEC_LOAD; |
252b5132 RH |
4327 | break; |
4328 | case 'R': /* Remove section at link time */ | |
4329 | flags |= SEC_NEVER_LOAD; | |
4330 | break; | |
4331 | ||
4332 | /* Section Protection */ | |
4333 | case 'r': /* section is readable */ | |
4334 | flags |= IMAGE_SCN_MEM_READ; | |
4335 | break; | |
4336 | case 'w': /* section is writeable */ | |
4337 | flags |= IMAGE_SCN_MEM_WRITE; | |
4338 | break; | |
4339 | case 'x': /* section is executable */ | |
4340 | flags |= IMAGE_SCN_MEM_EXECUTE; | |
4341 | break; | |
4342 | case 's': /* section is sharable */ | |
4343 | flags |= IMAGE_SCN_MEM_SHARED; | |
4344 | break; | |
4345 | ||
4346 | /* Section Alignment */ | |
4347 | case '0': /* align to byte boundary */ | |
4348 | flags |= IMAGE_SCN_ALIGN_1BYTES; | |
4349 | align = 0; | |
4350 | break; | |
4351 | case '1': /* align to halfword boundary */ | |
4352 | flags |= IMAGE_SCN_ALIGN_2BYTES; | |
4353 | align = 1; | |
4354 | break; | |
4355 | case '2': /* align to word boundary */ | |
4356 | flags |= IMAGE_SCN_ALIGN_4BYTES; | |
4357 | align = 2; | |
4358 | break; | |
4359 | case '3': /* align to doubleword boundary */ | |
4360 | flags |= IMAGE_SCN_ALIGN_8BYTES; | |
4361 | align = 3; | |
4362 | break; | |
4363 | case '4': /* align to quadword boundary */ | |
4364 | flags |= IMAGE_SCN_ALIGN_16BYTES; | |
4365 | align = 4; | |
4366 | break; | |
4367 | case '5': /* align to 32 byte boundary */ | |
4368 | flags |= IMAGE_SCN_ALIGN_32BYTES; | |
4369 | align = 5; | |
4370 | break; | |
4371 | case '6': /* align to 64 byte boundary */ | |
4372 | flags |= IMAGE_SCN_ALIGN_64BYTES; | |
4373 | align = 6; | |
4374 | break; | |
4375 | ||
4376 | default: | |
99a814a1 AM |
4377 | as_bad (_("unknown section attribute '%c'"), |
4378 | *input_line_pointer); | |
252b5132 RH |
4379 | break; |
4380 | } | |
4381 | ++input_line_pointer; | |
4382 | } | |
4383 | if (*input_line_pointer == '"') | |
4384 | ++input_line_pointer; | |
4385 | } | |
4386 | } | |
4387 | ||
4388 | sec = subseg_new (name, (subsegT) exp); | |
4389 | ||
99a814a1 | 4390 | ppc_set_current_section (sec); |
252b5132 RH |
4391 | |
4392 | if (flags != SEC_NO_FLAGS) | |
4393 | { | |
4394 | if (! bfd_set_section_flags (stdoutput, sec, flags)) | |
4395 | as_bad (_("error setting flags for \"%s\": %s"), | |
4396 | bfd_section_name (stdoutput, sec), | |
4397 | bfd_errmsg (bfd_get_error ())); | |
4398 | } | |
4399 | ||
99a814a1 | 4400 | bfd_set_section_alignment (stdoutput, sec, align); |
252b5132 RH |
4401 | |
4402 | } | |
4403 | ||
4404 | static void | |
4405 | ppc_pe_function (ignore) | |
5480ccf3 | 4406 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
4407 | { |
4408 | char *name; | |
4409 | char endc; | |
4410 | symbolS *ext_sym; | |
4411 | ||
4412 | name = input_line_pointer; | |
4413 | endc = get_symbol_end (); | |
4414 | ||
4415 | ext_sym = symbol_find_or_make (name); | |
4416 | ||
4417 | *input_line_pointer = endc; | |
4418 | ||
4419 | S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT); | |
4420 | SF_SET_FUNCTION (ext_sym); | |
4421 | SF_SET_PROCESS (ext_sym); | |
4422 | coff_add_linesym (ext_sym); | |
4423 | ||
4424 | demand_empty_rest_of_line (); | |
4425 | } | |
4426 | ||
4427 | static void | |
4428 | ppc_pe_tocd (ignore) | |
5480ccf3 | 4429 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
4430 | { |
4431 | if (tocdata_section == 0) | |
4432 | { | |
4433 | tocdata_section = subseg_new (".tocd", 0); | |
99a814a1 | 4434 | /* FIXME: section flags won't work. */ |
252b5132 RH |
4435 | bfd_set_section_flags (stdoutput, tocdata_section, |
4436 | (SEC_ALLOC | SEC_LOAD | SEC_RELOC | |
99a814a1 | 4437 | | SEC_READONLY | SEC_DATA)); |
252b5132 RH |
4438 | |
4439 | bfd_set_section_alignment (stdoutput, tocdata_section, 2); | |
4440 | } | |
4441 | else | |
4442 | { | |
4443 | rdata_section = subseg_new (".tocd", 0); | |
4444 | } | |
4445 | ||
99a814a1 | 4446 | ppc_set_current_section (tocdata_section); |
252b5132 RH |
4447 | |
4448 | demand_empty_rest_of_line (); | |
4449 | } | |
4450 | ||
4451 | /* Don't adjust TOC relocs to use the section symbol. */ | |
4452 | ||
4453 | int | |
4454 | ppc_pe_fix_adjustable (fix) | |
4455 | fixS *fix; | |
4456 | { | |
4457 | return fix->fx_r_type != BFD_RELOC_PPC_TOC16; | |
4458 | } | |
4459 | ||
4460 | #endif | |
4461 | \f | |
4462 | #ifdef OBJ_XCOFF | |
4463 | ||
4464 | /* XCOFF specific symbol and file handling. */ | |
4465 | ||
4466 | /* Canonicalize the symbol name. We use the to force the suffix, if | |
4467 | any, to use square brackets, and to be in upper case. */ | |
4468 | ||
4469 | char * | |
4470 | ppc_canonicalize_symbol_name (name) | |
4471 | char *name; | |
4472 | { | |
4473 | char *s; | |
4474 | ||
4475 | if (ppc_stab_symbol) | |
4476 | return name; | |
4477 | ||
4478 | for (s = name; *s != '\0' && *s != '{' && *s != '['; s++) | |
4479 | ; | |
4480 | if (*s != '\0') | |
4481 | { | |
4482 | char brac; | |
4483 | ||
4484 | if (*s == '[') | |
4485 | brac = ']'; | |
4486 | else | |
4487 | { | |
4488 | *s = '['; | |
4489 | brac = '}'; | |
4490 | } | |
4491 | ||
4492 | for (s++; *s != '\0' && *s != brac; s++) | |
3882b010 | 4493 | *s = TOUPPER (*s); |
252b5132 RH |
4494 | |
4495 | if (*s == '\0' || s[1] != '\0') | |
4496 | as_bad (_("bad symbol suffix")); | |
4497 | ||
4498 | *s = ']'; | |
4499 | } | |
4500 | ||
4501 | return name; | |
4502 | } | |
4503 | ||
4504 | /* Set the class of a symbol based on the suffix, if any. This is | |
4505 | called whenever a new symbol is created. */ | |
4506 | ||
4507 | void | |
4508 | ppc_symbol_new_hook (sym) | |
4509 | symbolS *sym; | |
4510 | { | |
809ffe0d | 4511 | struct ppc_tc_sy *tc; |
252b5132 RH |
4512 | const char *s; |
4513 | ||
809ffe0d ILT |
4514 | tc = symbol_get_tc (sym); |
4515 | tc->next = NULL; | |
4516 | tc->output = 0; | |
4517 | tc->class = -1; | |
4518 | tc->real_name = NULL; | |
4519 | tc->subseg = 0; | |
4520 | tc->align = 0; | |
4521 | tc->size = NULL; | |
4522 | tc->within = NULL; | |
252b5132 RH |
4523 | |
4524 | if (ppc_stab_symbol) | |
4525 | return; | |
4526 | ||
4527 | s = strchr (S_GET_NAME (sym), '['); | |
4528 | if (s == (const char *) NULL) | |
4529 | { | |
4530 | /* There is no suffix. */ | |
4531 | return; | |
4532 | } | |
4533 | ||
4534 | ++s; | |
4535 | ||
4536 | switch (s[0]) | |
4537 | { | |
4538 | case 'B': | |
4539 | if (strcmp (s, "BS]") == 0) | |
809ffe0d | 4540 | tc->class = XMC_BS; |
252b5132 RH |
4541 | break; |
4542 | case 'D': | |
4543 | if (strcmp (s, "DB]") == 0) | |
809ffe0d | 4544 | tc->class = XMC_DB; |
252b5132 | 4545 | else if (strcmp (s, "DS]") == 0) |
809ffe0d | 4546 | tc->class = XMC_DS; |
252b5132 RH |
4547 | break; |
4548 | case 'G': | |
4549 | if (strcmp (s, "GL]") == 0) | |
809ffe0d | 4550 | tc->class = XMC_GL; |
252b5132 RH |
4551 | break; |
4552 | case 'P': | |
4553 | if (strcmp (s, "PR]") == 0) | |
809ffe0d | 4554 | tc->class = XMC_PR; |
252b5132 RH |
4555 | break; |
4556 | case 'R': | |
4557 | if (strcmp (s, "RO]") == 0) | |
809ffe0d | 4558 | tc->class = XMC_RO; |
252b5132 | 4559 | else if (strcmp (s, "RW]") == 0) |
809ffe0d | 4560 | tc->class = XMC_RW; |
252b5132 RH |
4561 | break; |
4562 | case 'S': | |
4563 | if (strcmp (s, "SV]") == 0) | |
809ffe0d | 4564 | tc->class = XMC_SV; |
252b5132 RH |
4565 | break; |
4566 | case 'T': | |
4567 | if (strcmp (s, "TC]") == 0) | |
809ffe0d | 4568 | tc->class = XMC_TC; |
252b5132 | 4569 | else if (strcmp (s, "TI]") == 0) |
809ffe0d | 4570 | tc->class = XMC_TI; |
252b5132 | 4571 | else if (strcmp (s, "TB]") == 0) |
809ffe0d | 4572 | tc->class = XMC_TB; |
252b5132 | 4573 | else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0) |
809ffe0d | 4574 | tc->class = XMC_TC0; |
252b5132 RH |
4575 | break; |
4576 | case 'U': | |
4577 | if (strcmp (s, "UA]") == 0) | |
809ffe0d | 4578 | tc->class = XMC_UA; |
252b5132 | 4579 | else if (strcmp (s, "UC]") == 0) |
809ffe0d | 4580 | tc->class = XMC_UC; |
252b5132 RH |
4581 | break; |
4582 | case 'X': | |
4583 | if (strcmp (s, "XO]") == 0) | |
809ffe0d | 4584 | tc->class = XMC_XO; |
252b5132 RH |
4585 | break; |
4586 | } | |
4587 | ||
809ffe0d | 4588 | if (tc->class == -1) |
252b5132 RH |
4589 | as_bad (_("Unrecognized symbol suffix")); |
4590 | } | |
4591 | ||
4592 | /* Set the class of a label based on where it is defined. This | |
4593 | handles symbols without suffixes. Also, move the symbol so that it | |
4594 | follows the csect symbol. */ | |
4595 | ||
4596 | void | |
4597 | ppc_frob_label (sym) | |
4598 | symbolS *sym; | |
4599 | { | |
4600 | if (ppc_current_csect != (symbolS *) NULL) | |
4601 | { | |
809ffe0d ILT |
4602 | if (symbol_get_tc (sym)->class == -1) |
4603 | symbol_get_tc (sym)->class = symbol_get_tc (ppc_current_csect)->class; | |
252b5132 RH |
4604 | |
4605 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
809ffe0d ILT |
4606 | symbol_append (sym, symbol_get_tc (ppc_current_csect)->within, |
4607 | &symbol_rootP, &symbol_lastP); | |
4608 | symbol_get_tc (ppc_current_csect)->within = sym; | |
252b5132 RH |
4609 | } |
4610 | } | |
4611 | ||
4612 | /* This variable is set by ppc_frob_symbol if any absolute symbols are | |
4613 | seen. It tells ppc_adjust_symtab whether it needs to look through | |
4614 | the symbols. */ | |
4615 | ||
4616 | static boolean ppc_saw_abs; | |
4617 | ||
4618 | /* Change the name of a symbol just before writing it out. Set the | |
4619 | real name if the .rename pseudo-op was used. Otherwise, remove any | |
4620 | class suffix. Return 1 if the symbol should not be included in the | |
4621 | symbol table. */ | |
4622 | ||
4623 | int | |
4624 | ppc_frob_symbol (sym) | |
4625 | symbolS *sym; | |
4626 | { | |
4627 | static symbolS *ppc_last_function; | |
4628 | static symbolS *set_end; | |
4629 | ||
4630 | /* Discard symbols that should not be included in the output symbol | |
4631 | table. */ | |
809ffe0d ILT |
4632 | if (! symbol_used_in_reloc_p (sym) |
4633 | && ((symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0 | |
252b5132 | 4634 | || (! S_IS_EXTERNAL (sym) |
809ffe0d | 4635 | && ! symbol_get_tc (sym)->output |
252b5132 RH |
4636 | && S_GET_STORAGE_CLASS (sym) != C_FILE))) |
4637 | return 1; | |
4638 | ||
809ffe0d ILT |
4639 | if (symbol_get_tc (sym)->real_name != (char *) NULL) |
4640 | S_SET_NAME (sym, symbol_get_tc (sym)->real_name); | |
252b5132 RH |
4641 | else |
4642 | { | |
4643 | const char *name; | |
4644 | const char *s; | |
4645 | ||
4646 | name = S_GET_NAME (sym); | |
4647 | s = strchr (name, '['); | |
4648 | if (s != (char *) NULL) | |
4649 | { | |
4650 | unsigned int len; | |
4651 | char *snew; | |
4652 | ||
4653 | len = s - name; | |
4654 | snew = xmalloc (len + 1); | |
4655 | memcpy (snew, name, len); | |
4656 | snew[len] = '\0'; | |
4657 | ||
4658 | S_SET_NAME (sym, snew); | |
4659 | } | |
4660 | } | |
4661 | ||
4662 | if (set_end != (symbolS *) NULL) | |
4663 | { | |
4664 | SA_SET_SYM_ENDNDX (set_end, sym); | |
4665 | set_end = NULL; | |
4666 | } | |
4667 | ||
4668 | if (SF_GET_FUNCTION (sym)) | |
4669 | { | |
4670 | if (ppc_last_function != (symbolS *) NULL) | |
4671 | as_bad (_("two .function pseudo-ops with no intervening .ef")); | |
4672 | ppc_last_function = sym; | |
809ffe0d | 4673 | if (symbol_get_tc (sym)->size != (symbolS *) NULL) |
252b5132 | 4674 | { |
6386f3a7 | 4675 | resolve_symbol_value (symbol_get_tc (sym)->size); |
809ffe0d ILT |
4676 | SA_SET_SYM_FSIZE (sym, |
4677 | (long) S_GET_VALUE (symbol_get_tc (sym)->size)); | |
252b5132 RH |
4678 | } |
4679 | } | |
4680 | else if (S_GET_STORAGE_CLASS (sym) == C_FCN | |
4681 | && strcmp (S_GET_NAME (sym), ".ef") == 0) | |
4682 | { | |
4683 | if (ppc_last_function == (symbolS *) NULL) | |
4684 | as_bad (_(".ef with no preceding .function")); | |
4685 | else | |
4686 | { | |
4687 | set_end = ppc_last_function; | |
4688 | ppc_last_function = NULL; | |
4689 | ||
4690 | /* We don't have a C_EFCN symbol, but we need to force the | |
4691 | COFF backend to believe that it has seen one. */ | |
4692 | coff_last_function = NULL; | |
4693 | } | |
4694 | } | |
4695 | ||
4696 | if (! S_IS_EXTERNAL (sym) | |
809ffe0d | 4697 | && (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) == 0 |
252b5132 RH |
4698 | && S_GET_STORAGE_CLASS (sym) != C_FILE |
4699 | && S_GET_STORAGE_CLASS (sym) != C_FCN | |
4700 | && S_GET_STORAGE_CLASS (sym) != C_BLOCK | |
4701 | && S_GET_STORAGE_CLASS (sym) != C_BSTAT | |
4702 | && S_GET_STORAGE_CLASS (sym) != C_ESTAT | |
4703 | && S_GET_STORAGE_CLASS (sym) != C_BINCL | |
4704 | && S_GET_STORAGE_CLASS (sym) != C_EINCL | |
4705 | && S_GET_SEGMENT (sym) != ppc_coff_debug_section) | |
4706 | S_SET_STORAGE_CLASS (sym, C_HIDEXT); | |
4707 | ||
4708 | if (S_GET_STORAGE_CLASS (sym) == C_EXT | |
4709 | || S_GET_STORAGE_CLASS (sym) == C_HIDEXT) | |
4710 | { | |
4711 | int i; | |
4712 | union internal_auxent *a; | |
4713 | ||
4714 | /* Create a csect aux. */ | |
4715 | i = S_GET_NUMBER_AUXILIARY (sym); | |
4716 | S_SET_NUMBER_AUXILIARY (sym, i + 1); | |
809ffe0d ILT |
4717 | a = &coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].u.auxent; |
4718 | if (symbol_get_tc (sym)->class == XMC_TC0) | |
252b5132 RH |
4719 | { |
4720 | /* This is the TOC table. */ | |
4721 | know (strcmp (S_GET_NAME (sym), "TOC") == 0); | |
4722 | a->x_csect.x_scnlen.l = 0; | |
4723 | a->x_csect.x_smtyp = (2 << 3) | XTY_SD; | |
4724 | } | |
809ffe0d | 4725 | else if (symbol_get_tc (sym)->subseg != 0) |
252b5132 RH |
4726 | { |
4727 | /* This is a csect symbol. x_scnlen is the size of the | |
4728 | csect. */ | |
809ffe0d | 4729 | if (symbol_get_tc (sym)->next == (symbolS *) NULL) |
252b5132 RH |
4730 | a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput, |
4731 | S_GET_SEGMENT (sym)) | |
4732 | - S_GET_VALUE (sym)); | |
4733 | else | |
4734 | { | |
6386f3a7 | 4735 | resolve_symbol_value (symbol_get_tc (sym)->next); |
809ffe0d | 4736 | a->x_csect.x_scnlen.l = (S_GET_VALUE (symbol_get_tc (sym)->next) |
252b5132 RH |
4737 | - S_GET_VALUE (sym)); |
4738 | } | |
809ffe0d | 4739 | a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_SD; |
252b5132 RH |
4740 | } |
4741 | else if (S_GET_SEGMENT (sym) == bss_section) | |
4742 | { | |
4743 | /* This is a common symbol. */ | |
809ffe0d ILT |
4744 | a->x_csect.x_scnlen.l = symbol_get_frag (sym)->fr_offset; |
4745 | a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_CM; | |
252b5132 | 4746 | if (S_IS_EXTERNAL (sym)) |
809ffe0d | 4747 | symbol_get_tc (sym)->class = XMC_RW; |
252b5132 | 4748 | else |
809ffe0d | 4749 | symbol_get_tc (sym)->class = XMC_BS; |
252b5132 RH |
4750 | } |
4751 | else if (S_GET_SEGMENT (sym) == absolute_section) | |
4752 | { | |
4753 | /* This is an absolute symbol. The csect will be created by | |
99a814a1 | 4754 | ppc_adjust_symtab. */ |
252b5132 RH |
4755 | ppc_saw_abs = true; |
4756 | a->x_csect.x_smtyp = XTY_LD; | |
809ffe0d ILT |
4757 | if (symbol_get_tc (sym)->class == -1) |
4758 | symbol_get_tc (sym)->class = XMC_XO; | |
252b5132 RH |
4759 | } |
4760 | else if (! S_IS_DEFINED (sym)) | |
4761 | { | |
4762 | /* This is an external symbol. */ | |
4763 | a->x_csect.x_scnlen.l = 0; | |
4764 | a->x_csect.x_smtyp = XTY_ER; | |
4765 | } | |
809ffe0d | 4766 | else if (symbol_get_tc (sym)->class == XMC_TC) |
252b5132 RH |
4767 | { |
4768 | symbolS *next; | |
4769 | ||
4770 | /* This is a TOC definition. x_scnlen is the size of the | |
4771 | TOC entry. */ | |
4772 | next = symbol_next (sym); | |
809ffe0d | 4773 | while (symbol_get_tc (next)->class == XMC_TC0) |
252b5132 RH |
4774 | next = symbol_next (next); |
4775 | if (next == (symbolS *) NULL | |
809ffe0d | 4776 | || symbol_get_tc (next)->class != XMC_TC) |
252b5132 RH |
4777 | { |
4778 | if (ppc_after_toc_frag == (fragS *) NULL) | |
4779 | a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput, | |
4780 | data_section) | |
4781 | - S_GET_VALUE (sym)); | |
4782 | else | |
4783 | a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address | |
4784 | - S_GET_VALUE (sym)); | |
4785 | } | |
4786 | else | |
4787 | { | |
6386f3a7 | 4788 | resolve_symbol_value (next); |
252b5132 RH |
4789 | a->x_csect.x_scnlen.l = (S_GET_VALUE (next) |
4790 | - S_GET_VALUE (sym)); | |
4791 | } | |
4792 | a->x_csect.x_smtyp = (2 << 3) | XTY_SD; | |
4793 | } | |
4794 | else | |
4795 | { | |
4796 | symbolS *csect; | |
4797 | ||
4798 | /* This is a normal symbol definition. x_scnlen is the | |
4799 | symbol index of the containing csect. */ | |
4800 | if (S_GET_SEGMENT (sym) == text_section) | |
4801 | csect = ppc_text_csects; | |
4802 | else if (S_GET_SEGMENT (sym) == data_section) | |
4803 | csect = ppc_data_csects; | |
4804 | else | |
4805 | abort (); | |
4806 | ||
4807 | /* Skip the initial dummy symbol. */ | |
809ffe0d | 4808 | csect = symbol_get_tc (csect)->next; |
252b5132 RH |
4809 | |
4810 | if (csect == (symbolS *) NULL) | |
4811 | { | |
4812 | as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym)); | |
4813 | a->x_csect.x_scnlen.l = 0; | |
4814 | } | |
4815 | else | |
4816 | { | |
809ffe0d | 4817 | while (symbol_get_tc (csect)->next != (symbolS *) NULL) |
252b5132 | 4818 | { |
6386f3a7 | 4819 | resolve_symbol_value (symbol_get_tc (csect)->next); |
809ffe0d ILT |
4820 | if (S_GET_VALUE (symbol_get_tc (csect)->next) |
4821 | > S_GET_VALUE (sym)) | |
252b5132 | 4822 | break; |
809ffe0d | 4823 | csect = symbol_get_tc (csect)->next; |
252b5132 RH |
4824 | } |
4825 | ||
809ffe0d ILT |
4826 | a->x_csect.x_scnlen.p = |
4827 | coffsymbol (symbol_get_bfdsym (csect))->native; | |
4828 | coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].fix_scnlen = | |
4829 | 1; | |
252b5132 RH |
4830 | } |
4831 | a->x_csect.x_smtyp = XTY_LD; | |
4832 | } | |
81d4177b | 4833 | |
252b5132 RH |
4834 | a->x_csect.x_parmhash = 0; |
4835 | a->x_csect.x_snhash = 0; | |
809ffe0d | 4836 | if (symbol_get_tc (sym)->class == -1) |
252b5132 RH |
4837 | a->x_csect.x_smclas = XMC_PR; |
4838 | else | |
809ffe0d | 4839 | a->x_csect.x_smclas = symbol_get_tc (sym)->class; |
252b5132 RH |
4840 | a->x_csect.x_stab = 0; |
4841 | a->x_csect.x_snstab = 0; | |
4842 | ||
4843 | /* Don't let the COFF backend resort these symbols. */ | |
809ffe0d | 4844 | symbol_get_bfdsym (sym)->flags |= BSF_NOT_AT_END; |
252b5132 RH |
4845 | } |
4846 | else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT) | |
4847 | { | |
4848 | /* We want the value to be the symbol index of the referenced | |
4849 | csect symbol. BFD will do that for us if we set the right | |
4850 | flags. */ | |
4851 | S_SET_VALUE (sym, | |
809ffe0d ILT |
4852 | ((valueT) |
4853 | coffsymbol (symbol_get_bfdsym | |
4854 | (symbol_get_tc (sym)->within))->native)); | |
4855 | coffsymbol (symbol_get_bfdsym (sym))->native->fix_value = 1; | |
252b5132 RH |
4856 | } |
4857 | else if (S_GET_STORAGE_CLASS (sym) == C_STSYM) | |
4858 | { | |
4859 | symbolS *block; | |
4860 | symbolS *csect; | |
4861 | ||
4862 | /* The value is the offset from the enclosing csect. */ | |
809ffe0d ILT |
4863 | block = symbol_get_tc (sym)->within; |
4864 | csect = symbol_get_tc (block)->within; | |
6386f3a7 | 4865 | resolve_symbol_value (csect); |
252b5132 RH |
4866 | S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect)); |
4867 | } | |
4868 | else if (S_GET_STORAGE_CLASS (sym) == C_BINCL | |
4869 | || S_GET_STORAGE_CLASS (sym) == C_EINCL) | |
4870 | { | |
4871 | /* We want the value to be a file offset into the line numbers. | |
99a814a1 AM |
4872 | BFD will do that for us if we set the right flags. We have |
4873 | already set the value correctly. */ | |
809ffe0d | 4874 | coffsymbol (symbol_get_bfdsym (sym))->native->fix_line = 1; |
252b5132 RH |
4875 | } |
4876 | ||
4877 | return 0; | |
4878 | } | |
4879 | ||
4880 | /* Adjust the symbol table. This creates csect symbols for all | |
4881 | absolute symbols. */ | |
4882 | ||
4883 | void | |
4884 | ppc_adjust_symtab () | |
4885 | { | |
4886 | symbolS *sym; | |
4887 | ||
4888 | if (! ppc_saw_abs) | |
4889 | return; | |
4890 | ||
4891 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) | |
4892 | { | |
4893 | symbolS *csect; | |
4894 | int i; | |
4895 | union internal_auxent *a; | |
4896 | ||
4897 | if (S_GET_SEGMENT (sym) != absolute_section) | |
4898 | continue; | |
4899 | ||
4900 | csect = symbol_create (".abs[XO]", absolute_section, | |
4901 | S_GET_VALUE (sym), &zero_address_frag); | |
809ffe0d | 4902 | symbol_get_bfdsym (csect)->value = S_GET_VALUE (sym); |
252b5132 RH |
4903 | S_SET_STORAGE_CLASS (csect, C_HIDEXT); |
4904 | i = S_GET_NUMBER_AUXILIARY (csect); | |
4905 | S_SET_NUMBER_AUXILIARY (csect, i + 1); | |
809ffe0d | 4906 | a = &coffsymbol (symbol_get_bfdsym (csect))->native[i + 1].u.auxent; |
252b5132 RH |
4907 | a->x_csect.x_scnlen.l = 0; |
4908 | a->x_csect.x_smtyp = XTY_SD; | |
4909 | a->x_csect.x_parmhash = 0; | |
4910 | a->x_csect.x_snhash = 0; | |
4911 | a->x_csect.x_smclas = XMC_XO; | |
4912 | a->x_csect.x_stab = 0; | |
4913 | a->x_csect.x_snstab = 0; | |
4914 | ||
4915 | symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP); | |
4916 | ||
4917 | i = S_GET_NUMBER_AUXILIARY (sym); | |
809ffe0d ILT |
4918 | a = &coffsymbol (symbol_get_bfdsym (sym))->native[i].u.auxent; |
4919 | a->x_csect.x_scnlen.p = coffsymbol (symbol_get_bfdsym (csect))->native; | |
4920 | coffsymbol (symbol_get_bfdsym (sym))->native[i].fix_scnlen = 1; | |
252b5132 RH |
4921 | } |
4922 | ||
4923 | ppc_saw_abs = false; | |
4924 | } | |
4925 | ||
4926 | /* Set the VMA for a section. This is called on all the sections in | |
4927 | turn. */ | |
4928 | ||
4929 | void | |
4930 | ppc_frob_section (sec) | |
4931 | asection *sec; | |
4932 | { | |
4933 | static bfd_size_type vma = 0; | |
4934 | ||
4935 | bfd_set_section_vma (stdoutput, sec, vma); | |
4936 | vma += bfd_section_size (stdoutput, sec); | |
4937 | } | |
4938 | ||
4939 | #endif /* OBJ_XCOFF */ | |
4940 | \f | |
4941 | /* Turn a string in input_line_pointer into a floating point constant | |
bc0d738a NC |
4942 | of type TYPE, and store the appropriate bytes in *LITP. The number |
4943 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
252b5132 RH |
4944 | returned, or NULL on OK. */ |
4945 | ||
4946 | char * | |
4947 | md_atof (type, litp, sizep) | |
4948 | int type; | |
4949 | char *litp; | |
4950 | int *sizep; | |
4951 | { | |
4952 | int prec; | |
4953 | LITTLENUM_TYPE words[4]; | |
4954 | char *t; | |
4955 | int i; | |
4956 | ||
4957 | switch (type) | |
4958 | { | |
4959 | case 'f': | |
4960 | prec = 2; | |
4961 | break; | |
4962 | ||
4963 | case 'd': | |
4964 | prec = 4; | |
4965 | break; | |
4966 | ||
4967 | default: | |
4968 | *sizep = 0; | |
4969 | return _("bad call to md_atof"); | |
4970 | } | |
4971 | ||
4972 | t = atof_ieee (input_line_pointer, type, words); | |
4973 | if (t) | |
4974 | input_line_pointer = t; | |
4975 | ||
4976 | *sizep = prec * 2; | |
4977 | ||
4978 | if (target_big_endian) | |
4979 | { | |
4980 | for (i = 0; i < prec; i++) | |
4981 | { | |
4982 | md_number_to_chars (litp, (valueT) words[i], 2); | |
4983 | litp += 2; | |
4984 | } | |
4985 | } | |
4986 | else | |
4987 | { | |
4988 | for (i = prec - 1; i >= 0; i--) | |
4989 | { | |
4990 | md_number_to_chars (litp, (valueT) words[i], 2); | |
4991 | litp += 2; | |
4992 | } | |
4993 | } | |
81d4177b | 4994 | |
252b5132 RH |
4995 | return NULL; |
4996 | } | |
4997 | ||
4998 | /* Write a value out to the object file, using the appropriate | |
4999 | endianness. */ | |
5000 | ||
5001 | void | |
5002 | md_number_to_chars (buf, val, n) | |
5003 | char *buf; | |
5004 | valueT val; | |
5005 | int n; | |
5006 | { | |
5007 | if (target_big_endian) | |
5008 | number_to_chars_bigendian (buf, val, n); | |
5009 | else | |
5010 | number_to_chars_littleendian (buf, val, n); | |
5011 | } | |
5012 | ||
5013 | /* Align a section (I don't know why this is machine dependent). */ | |
5014 | ||
5015 | valueT | |
5016 | md_section_align (seg, addr) | |
5017 | asection *seg; | |
5018 | valueT addr; | |
5019 | { | |
5020 | int align = bfd_get_section_alignment (stdoutput, seg); | |
5021 | ||
5022 | return ((addr + (1 << align) - 1) & (-1 << align)); | |
5023 | } | |
5024 | ||
5025 | /* We don't have any form of relaxing. */ | |
5026 | ||
5027 | int | |
5028 | md_estimate_size_before_relax (fragp, seg) | |
92161534 ILT |
5029 | fragS *fragp ATTRIBUTE_UNUSED; |
5030 | asection *seg ATTRIBUTE_UNUSED; | |
252b5132 RH |
5031 | { |
5032 | abort (); | |
5033 | return 0; | |
5034 | } | |
5035 | ||
5036 | /* Convert a machine dependent frag. We never generate these. */ | |
5037 | ||
5038 | void | |
5039 | md_convert_frag (abfd, sec, fragp) | |
92161534 ILT |
5040 | bfd *abfd ATTRIBUTE_UNUSED; |
5041 | asection *sec ATTRIBUTE_UNUSED; | |
5042 | fragS *fragp ATTRIBUTE_UNUSED; | |
252b5132 RH |
5043 | { |
5044 | abort (); | |
5045 | } | |
5046 | ||
5047 | /* We have no need to default values of symbols. */ | |
5048 | ||
252b5132 RH |
5049 | symbolS * |
5050 | md_undefined_symbol (name) | |
92161534 | 5051 | char *name ATTRIBUTE_UNUSED; |
252b5132 RH |
5052 | { |
5053 | return 0; | |
5054 | } | |
5055 | \f | |
5056 | /* Functions concerning relocs. */ | |
5057 | ||
5058 | /* The location from which a PC relative jump should be calculated, | |
5059 | given a PC relative reloc. */ | |
5060 | ||
5061 | long | |
5062 | md_pcrel_from_section (fixp, sec) | |
5063 | fixS *fixp; | |
92161534 | 5064 | segT sec ATTRIBUTE_UNUSED; |
252b5132 RH |
5065 | { |
5066 | return fixp->fx_frag->fr_address + fixp->fx_where; | |
5067 | } | |
5068 | ||
5069 | #ifdef OBJ_XCOFF | |
5070 | ||
5071 | /* This is called to see whether a fixup should be adjusted to use a | |
5072 | section symbol. We take the opportunity to change a fixup against | |
5073 | a symbol in the TOC subsegment into a reloc against the | |
5074 | corresponding .tc symbol. */ | |
5075 | ||
5076 | int | |
5077 | ppc_fix_adjustable (fix) | |
5078 | fixS *fix; | |
5079 | { | |
5080 | valueT val; | |
5081 | ||
6386f3a7 | 5082 | resolve_symbol_value (fix->fx_addsy); |
252b5132 RH |
5083 | val = S_GET_VALUE (fix->fx_addsy); |
5084 | if (ppc_toc_csect != (symbolS *) NULL | |
5085 | && fix->fx_addsy != (symbolS *) NULL | |
5086 | && fix->fx_addsy != ppc_toc_csect | |
5087 | && S_GET_SEGMENT (fix->fx_addsy) == data_section | |
5088 | && val >= ppc_toc_frag->fr_address | |
5089 | && (ppc_after_toc_frag == (fragS *) NULL | |
5090 | || val < ppc_after_toc_frag->fr_address)) | |
5091 | { | |
5092 | symbolS *sy; | |
5093 | ||
5094 | for (sy = symbol_next (ppc_toc_csect); | |
5095 | sy != (symbolS *) NULL; | |
5096 | sy = symbol_next (sy)) | |
5097 | { | |
809ffe0d | 5098 | if (symbol_get_tc (sy)->class == XMC_TC0) |
252b5132 | 5099 | continue; |
809ffe0d | 5100 | if (symbol_get_tc (sy)->class != XMC_TC) |
252b5132 | 5101 | break; |
6386f3a7 | 5102 | resolve_symbol_value (sy); |
252b5132 RH |
5103 | if (val == S_GET_VALUE (sy)) |
5104 | { | |
5105 | fix->fx_addsy = sy; | |
5106 | fix->fx_addnumber = val - ppc_toc_frag->fr_address; | |
5107 | return 0; | |
5108 | } | |
5109 | } | |
5110 | ||
5111 | as_bad_where (fix->fx_file, fix->fx_line, | |
5112 | _("symbol in .toc does not match any .tc")); | |
5113 | } | |
5114 | ||
5115 | /* Possibly adjust the reloc to be against the csect. */ | |
5116 | if (fix->fx_addsy != (symbolS *) NULL | |
809ffe0d ILT |
5117 | && symbol_get_tc (fix->fx_addsy)->subseg == 0 |
5118 | && symbol_get_tc (fix->fx_addsy)->class != XMC_TC0 | |
5119 | && symbol_get_tc (fix->fx_addsy)->class != XMC_TC | |
252b5132 RH |
5120 | && S_GET_SEGMENT (fix->fx_addsy) != bss_section |
5121 | /* Don't adjust if this is a reloc in the toc section. */ | |
5122 | && (S_GET_SEGMENT (fix->fx_addsy) != data_section | |
5123 | || ppc_toc_csect == NULL | |
5124 | || val < ppc_toc_frag->fr_address | |
5125 | || (ppc_after_toc_frag != NULL | |
5126 | && val >= ppc_after_toc_frag->fr_address))) | |
5127 | { | |
5128 | symbolS *csect; | |
5129 | ||
5130 | if (S_GET_SEGMENT (fix->fx_addsy) == text_section) | |
5131 | csect = ppc_text_csects; | |
5132 | else if (S_GET_SEGMENT (fix->fx_addsy) == data_section) | |
5133 | csect = ppc_data_csects; | |
5134 | else | |
5135 | abort (); | |
5136 | ||
5137 | /* Skip the initial dummy symbol. */ | |
809ffe0d | 5138 | csect = symbol_get_tc (csect)->next; |
252b5132 RH |
5139 | |
5140 | if (csect != (symbolS *) NULL) | |
5141 | { | |
809ffe0d ILT |
5142 | while (symbol_get_tc (csect)->next != (symbolS *) NULL |
5143 | && (symbol_get_frag (symbol_get_tc (csect)->next)->fr_address | |
2c1c4c62 | 5144 | <= val)) |
252b5132 RH |
5145 | { |
5146 | /* If the csect address equals the symbol value, then we | |
99a814a1 AM |
5147 | have to look through the full symbol table to see |
5148 | whether this is the csect we want. Note that we will | |
5149 | only get here if the csect has zero length. */ | |
2c1c4c62 | 5150 | if ((symbol_get_frag (csect)->fr_address == val) |
252b5132 RH |
5151 | && S_GET_VALUE (csect) == S_GET_VALUE (fix->fx_addsy)) |
5152 | { | |
5153 | symbolS *scan; | |
5154 | ||
809ffe0d | 5155 | for (scan = symbol_next (csect); |
252b5132 | 5156 | scan != NULL; |
809ffe0d | 5157 | scan = symbol_next (scan)) |
252b5132 | 5158 | { |
809ffe0d | 5159 | if (symbol_get_tc (scan)->subseg != 0) |
252b5132 RH |
5160 | break; |
5161 | if (scan == fix->fx_addsy) | |
5162 | break; | |
5163 | } | |
5164 | ||
5165 | /* If we found the symbol before the next csect | |
99a814a1 | 5166 | symbol, then this is the csect we want. */ |
252b5132 RH |
5167 | if (scan == fix->fx_addsy) |
5168 | break; | |
5169 | } | |
5170 | ||
809ffe0d | 5171 | csect = symbol_get_tc (csect)->next; |
252b5132 RH |
5172 | } |
5173 | ||
5174 | fix->fx_offset += (S_GET_VALUE (fix->fx_addsy) | |
809ffe0d | 5175 | - symbol_get_frag (csect)->fr_address); |
252b5132 RH |
5176 | fix->fx_addsy = csect; |
5177 | } | |
5178 | } | |
5179 | ||
5180 | /* Adjust a reloc against a .lcomm symbol to be against the base | |
5181 | .lcomm. */ | |
5182 | if (fix->fx_addsy != (symbolS *) NULL | |
5183 | && S_GET_SEGMENT (fix->fx_addsy) == bss_section | |
5184 | && ! S_IS_EXTERNAL (fix->fx_addsy)) | |
5185 | { | |
6386f3a7 | 5186 | resolve_symbol_value (symbol_get_frag (fix->fx_addsy)->fr_symbol); |
809ffe0d ILT |
5187 | fix->fx_offset += |
5188 | (S_GET_VALUE (fix->fx_addsy) | |
5189 | - S_GET_VALUE (symbol_get_frag (fix->fx_addsy)->fr_symbol)); | |
5190 | fix->fx_addsy = symbol_get_frag (fix->fx_addsy)->fr_symbol; | |
252b5132 RH |
5191 | } |
5192 | ||
5193 | return 0; | |
5194 | } | |
5195 | ||
5196 | /* A reloc from one csect to another must be kept. The assembler | |
5197 | will, of course, keep relocs between sections, and it will keep | |
5198 | absolute relocs, but we need to force it to keep PC relative relocs | |
5199 | between two csects in the same section. */ | |
5200 | ||
5201 | int | |
5202 | ppc_force_relocation (fix) | |
5203 | fixS *fix; | |
5204 | { | |
5205 | /* At this point fix->fx_addsy should already have been converted to | |
5206 | a csect symbol. If the csect does not include the fragment, then | |
5207 | we need to force the relocation. */ | |
5208 | if (fix->fx_pcrel | |
5209 | && fix->fx_addsy != NULL | |
809ffe0d ILT |
5210 | && symbol_get_tc (fix->fx_addsy)->subseg != 0 |
5211 | && ((symbol_get_frag (fix->fx_addsy)->fr_address | |
5212 | > fix->fx_frag->fr_address) | |
5213 | || (symbol_get_tc (fix->fx_addsy)->next != NULL | |
5214 | && (symbol_get_frag (symbol_get_tc (fix->fx_addsy)->next)->fr_address | |
252b5132 RH |
5215 | <= fix->fx_frag->fr_address)))) |
5216 | return 1; | |
5217 | ||
5218 | return 0; | |
5219 | } | |
5220 | ||
5221 | #endif /* OBJ_XCOFF */ | |
5222 | ||
0baf16f2 AM |
5223 | #ifdef OBJ_ELF |
5224 | int | |
5225 | ppc_fix_adjustable (fix) | |
5226 | fixS *fix; | |
252b5132 | 5227 | { |
0baf16f2 AM |
5228 | return (fix->fx_r_type != BFD_RELOC_16_GOTOFF |
5229 | && fix->fx_r_type != BFD_RELOC_LO16_GOTOFF | |
5230 | && fix->fx_r_type != BFD_RELOC_HI16_GOTOFF | |
5231 | && fix->fx_r_type != BFD_RELOC_HI16_S_GOTOFF | |
5232 | && fix->fx_r_type != BFD_RELOC_GPREL16 | |
5233 | && fix->fx_r_type != BFD_RELOC_VTABLE_INHERIT | |
5234 | && fix->fx_r_type != BFD_RELOC_VTABLE_ENTRY | |
5235 | && ! S_IS_EXTERNAL (fix->fx_addsy) | |
5236 | && ! S_IS_WEAK (fix->fx_addsy) | |
5237 | && (fix->fx_pcrel | |
5238 | || (fix->fx_subsy != NULL | |
5239 | && (S_GET_SEGMENT (fix->fx_subsy) | |
5240 | == S_GET_SEGMENT (fix->fx_addsy))) | |
5241 | || S_IS_LOCAL (fix->fx_addsy))); | |
252b5132 | 5242 | } |
0baf16f2 | 5243 | #endif |
252b5132 RH |
5244 | |
5245 | /* Apply a fixup to the object code. This is called for all the | |
5246 | fixups we generated by the call to fix_new_exp, above. In the call | |
5247 | above we used a reloc code which was the largest legal reloc code | |
5248 | plus the operand index. Here we undo that to recover the operand | |
5249 | index. At this point all symbol values should be fully resolved, | |
5250 | and we attempt to completely resolve the reloc. If we can not do | |
5251 | that, we determine the correct reloc code and put it back in the | |
5252 | fixup. */ | |
5253 | ||
94f592af NC |
5254 | void |
5255 | md_apply_fix3 (fixP, valP, seg) | |
5256 | fixS *fixP; | |
5257 | valueT * valP; | |
0baf16f2 | 5258 | segT seg ATTRIBUTE_UNUSED; |
252b5132 | 5259 | { |
94f592af | 5260 | valueT value = * valP; |
252b5132 RH |
5261 | |
5262 | #ifdef OBJ_ELF | |
94f592af | 5263 | if (fixP->fx_addsy != NULL) |
252b5132 RH |
5264 | { |
5265 | /* `*valuep' may contain the value of the symbol on which the reloc | |
5266 | will be based; we have to remove it. */ | |
94f592af NC |
5267 | if (symbol_used_in_reloc_p (fixP->fx_addsy) |
5268 | && S_GET_SEGMENT (fixP->fx_addsy) != absolute_section | |
5269 | && S_GET_SEGMENT (fixP->fx_addsy) != undefined_section | |
5270 | && ! bfd_is_com_section (S_GET_SEGMENT (fixP->fx_addsy))) | |
5271 | value -= S_GET_VALUE (fixP->fx_addsy); | |
252b5132 RH |
5272 | |
5273 | /* FIXME: Why '+'? Better yet, what exactly is '*valuep' | |
5274 | supposed to be? I think this is related to various similar | |
5275 | FIXMEs in tc-i386.c and tc-sparc.c. */ | |
94f592af NC |
5276 | if (fixP->fx_pcrel) |
5277 | value += fixP->fx_frag->fr_address + fixP->fx_where; | |
252b5132 RH |
5278 | } |
5279 | else | |
94f592af | 5280 | fixP->fx_done = 1; |
252b5132 RH |
5281 | #else |
5282 | /* FIXME FIXME FIXME: The value we are passed in *valuep includes | |
5283 | the symbol values. Since we are using BFD_ASSEMBLER, if we are | |
5284 | doing this relocation the code in write.c is going to call | |
5285 | bfd_install_relocation, which is also going to use the symbol | |
5286 | value. That means that if the reloc is fully resolved we want to | |
5287 | use *valuep since bfd_install_relocation is not being used. | |
5288 | However, if the reloc is not fully resolved we do not want to use | |
5289 | *valuep, and must use fx_offset instead. However, if the reloc | |
5290 | is PC relative, we do want to use *valuep since it includes the | |
5291 | result of md_pcrel_from. This is confusing. */ | |
94f592af NC |
5292 | if (fixP->fx_addsy == (symbolS *) NULL) |
5293 | fixP->fx_done = 1; | |
5294 | ||
5295 | else if (fixP->fx_pcrel) | |
5296 | ; | |
5297 | ||
252b5132 RH |
5298 | else |
5299 | { | |
94f592af NC |
5300 | value = fixP->fx_offset; |
5301 | if (fixP->fx_subsy != (symbolS *) NULL) | |
252b5132 | 5302 | { |
94f592af NC |
5303 | if (S_GET_SEGMENT (fixP->fx_subsy) == absolute_section) |
5304 | value -= S_GET_VALUE (fixP->fx_subsy); | |
252b5132 RH |
5305 | else |
5306 | { | |
5307 | /* We can't actually support subtracting a symbol. */ | |
94f592af | 5308 | as_bad_where (fixP->fx_file, fixP->fx_line, |
252b5132 RH |
5309 | _("expression too complex")); |
5310 | } | |
5311 | } | |
5312 | } | |
5313 | #endif | |
5314 | ||
94f592af | 5315 | if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED) |
252b5132 RH |
5316 | { |
5317 | int opindex; | |
5318 | const struct powerpc_operand *operand; | |
5319 | char *where; | |
5320 | unsigned long insn; | |
5321 | ||
94f592af | 5322 | opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED; |
252b5132 RH |
5323 | |
5324 | operand = &powerpc_operands[opindex]; | |
5325 | ||
5326 | #ifdef OBJ_XCOFF | |
0baf16f2 AM |
5327 | /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol |
5328 | does not generate a reloc. It uses the offset of `sym' within its | |
5329 | csect. Other usages, such as `.long sym', generate relocs. This | |
5330 | is the documented behaviour of non-TOC symbols. */ | |
252b5132 RH |
5331 | if ((operand->flags & PPC_OPERAND_PARENS) != 0 |
5332 | && operand->bits == 16 | |
5333 | && operand->shift == 0 | |
2b3c4602 | 5334 | && (operand->insert == NULL || ppc_obj64) |
94f592af NC |
5335 | && fixP->fx_addsy != NULL |
5336 | && symbol_get_tc (fixP->fx_addsy)->subseg != 0 | |
5337 | && symbol_get_tc (fixP->fx_addsy)->class != XMC_TC | |
5338 | && symbol_get_tc (fixP->fx_addsy)->class != XMC_TC0 | |
5339 | && S_GET_SEGMENT (fixP->fx_addsy) != bss_section) | |
252b5132 | 5340 | { |
94f592af NC |
5341 | value = fixP->fx_offset; |
5342 | fixP->fx_done = 1; | |
252b5132 RH |
5343 | } |
5344 | #endif | |
5345 | ||
5346 | /* Fetch the instruction, insert the fully resolved operand | |
5347 | value, and stuff the instruction back again. */ | |
94f592af | 5348 | where = fixP->fx_frag->fr_literal + fixP->fx_where; |
252b5132 RH |
5349 | if (target_big_endian) |
5350 | insn = bfd_getb32 ((unsigned char *) where); | |
5351 | else | |
5352 | insn = bfd_getl32 ((unsigned char *) where); | |
5353 | insn = ppc_insert_operand (insn, operand, (offsetT) value, | |
94f592af | 5354 | fixP->fx_file, fixP->fx_line); |
252b5132 RH |
5355 | if (target_big_endian) |
5356 | bfd_putb32 ((bfd_vma) insn, (unsigned char *) where); | |
5357 | else | |
5358 | bfd_putl32 ((bfd_vma) insn, (unsigned char *) where); | |
5359 | ||
94f592af NC |
5360 | if (fixP->fx_done) |
5361 | /* Nothing else to do here. */ | |
5362 | return; | |
252b5132 | 5363 | |
94f592af | 5364 | assert (fixP->fx_addsy != NULL); |
0baf16f2 | 5365 | |
252b5132 RH |
5366 | /* Determine a BFD reloc value based on the operand information. |
5367 | We are only prepared to turn a few of the operands into | |
0baf16f2 | 5368 | relocs. */ |
11b37b7b AM |
5369 | if ((operand->flags & PPC_OPERAND_RELATIVE) != 0 |
5370 | && operand->bits == 26 | |
5371 | && operand->shift == 0) | |
94f592af | 5372 | fixP->fx_r_type = BFD_RELOC_PPC_B26; |
11b37b7b AM |
5373 | else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0 |
5374 | && operand->bits == 16 | |
5375 | && operand->shift == 0) | |
95210096 AM |
5376 | { |
5377 | fixP->fx_r_type = BFD_RELOC_PPC_B16; | |
5378 | #ifdef OBJ_XCOFF | |
5379 | fixP->fx_size = 2; | |
5380 | if (target_big_endian) | |
5381 | fixP->fx_where += 2; | |
5382 | #endif | |
5383 | } | |
11b37b7b AM |
5384 | else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0 |
5385 | && operand->bits == 26 | |
5386 | && operand->shift == 0) | |
94f592af | 5387 | fixP->fx_r_type = BFD_RELOC_PPC_BA26; |
11b37b7b AM |
5388 | else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0 |
5389 | && operand->bits == 16 | |
5390 | && operand->shift == 0) | |
95210096 AM |
5391 | { |
5392 | fixP->fx_r_type = BFD_RELOC_PPC_BA16; | |
5393 | #ifdef OBJ_XCOFF | |
5394 | fixP->fx_size = 2; | |
5395 | if (target_big_endian) | |
5396 | fixP->fx_where += 2; | |
5397 | #endif | |
5398 | } | |
0baf16f2 | 5399 | #if defined (OBJ_XCOFF) || defined (OBJ_ELF) |
11b37b7b AM |
5400 | else if ((operand->flags & PPC_OPERAND_PARENS) != 0 |
5401 | && operand->bits == 16 | |
5402 | && operand->shift == 0 | |
94f592af | 5403 | && ppc_is_toc_sym (fixP->fx_addsy)) |
11b37b7b | 5404 | { |
94f592af | 5405 | fixP->fx_r_type = BFD_RELOC_PPC_TOC16; |
0baf16f2 | 5406 | #ifdef OBJ_ELF |
2b3c4602 | 5407 | if (ppc_obj64 |
0baf16f2 | 5408 | && (operand->flags & PPC_OPERAND_DS) != 0) |
94f592af | 5409 | fixP->fx_r_type = BFD_RELOC_PPC64_TOC16_DS; |
0baf16f2 | 5410 | #endif |
94f592af | 5411 | fixP->fx_size = 2; |
11b37b7b | 5412 | if (target_big_endian) |
94f592af | 5413 | fixP->fx_where += 2; |
11b37b7b | 5414 | } |
0baf16f2 | 5415 | #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */ |
11b37b7b | 5416 | else |
252b5132 RH |
5417 | { |
5418 | char *sfile; | |
5419 | unsigned int sline; | |
5420 | ||
5421 | /* Use expr_symbol_where to see if this is an expression | |
0baf16f2 | 5422 | symbol. */ |
94f592af NC |
5423 | if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline)) |
5424 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
252b5132 RH |
5425 | _("unresolved expression that must be resolved")); |
5426 | else | |
94f592af | 5427 | as_bad_where (fixP->fx_file, fixP->fx_line, |
0baf16f2 | 5428 | _("unsupported relocation against %s"), |
94f592af NC |
5429 | S_GET_NAME (fixP->fx_addsy)); |
5430 | fixP->fx_done = 1; | |
5431 | return; | |
252b5132 RH |
5432 | } |
5433 | } | |
5434 | else | |
5435 | { | |
5436 | #ifdef OBJ_ELF | |
94f592af | 5437 | ppc_elf_validate_fix (fixP, seg); |
252b5132 | 5438 | #endif |
94f592af | 5439 | switch (fixP->fx_r_type) |
252b5132 | 5440 | { |
252b5132 | 5441 | case BFD_RELOC_CTOR: |
2b3c4602 | 5442 | if (ppc_obj64) |
9c7977b3 AM |
5443 | goto ctor64; |
5444 | /* fall through */ | |
5445 | ||
0baf16f2 | 5446 | case BFD_RELOC_32: |
94f592af NC |
5447 | if (fixP->fx_pcrel) |
5448 | fixP->fx_r_type = BFD_RELOC_32_PCREL; | |
99a814a1 | 5449 | /* fall through */ |
252b5132 RH |
5450 | |
5451 | case BFD_RELOC_RVA: | |
5452 | case BFD_RELOC_32_PCREL: | |
252b5132 | 5453 | case BFD_RELOC_PPC_EMB_NADDR32: |
94f592af | 5454 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, |
252b5132 RH |
5455 | value, 4); |
5456 | break; | |
5457 | ||
7f6d05e8 | 5458 | case BFD_RELOC_64: |
9c7977b3 | 5459 | ctor64: |
94f592af NC |
5460 | if (fixP->fx_pcrel) |
5461 | fixP->fx_r_type = BFD_RELOC_64_PCREL; | |
99a814a1 | 5462 | /* fall through */ |
0baf16f2 | 5463 | |
7f6d05e8 | 5464 | case BFD_RELOC_64_PCREL: |
94f592af | 5465 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, |
7f6d05e8 | 5466 | value, 8); |
81d4177b | 5467 | break; |
0baf16f2 | 5468 | |
252b5132 RH |
5469 | case BFD_RELOC_LO16: |
5470 | case BFD_RELOC_16: | |
5471 | case BFD_RELOC_GPREL16: | |
5472 | case BFD_RELOC_16_GOT_PCREL: | |
5473 | case BFD_RELOC_16_GOTOFF: | |
5474 | case BFD_RELOC_LO16_GOTOFF: | |
5475 | case BFD_RELOC_HI16_GOTOFF: | |
5476 | case BFD_RELOC_HI16_S_GOTOFF: | |
1cfc59d5 | 5477 | case BFD_RELOC_16_BASEREL: |
252b5132 RH |
5478 | case BFD_RELOC_LO16_BASEREL: |
5479 | case BFD_RELOC_HI16_BASEREL: | |
5480 | case BFD_RELOC_HI16_S_BASEREL: | |
5481 | case BFD_RELOC_PPC_EMB_NADDR16: | |
5482 | case BFD_RELOC_PPC_EMB_NADDR16_LO: | |
5483 | case BFD_RELOC_PPC_EMB_NADDR16_HI: | |
5484 | case BFD_RELOC_PPC_EMB_NADDR16_HA: | |
5485 | case BFD_RELOC_PPC_EMB_SDAI16: | |
5486 | case BFD_RELOC_PPC_EMB_SDA2REL: | |
5487 | case BFD_RELOC_PPC_EMB_SDA2I16: | |
5488 | case BFD_RELOC_PPC_EMB_RELSEC16: | |
5489 | case BFD_RELOC_PPC_EMB_RELST_LO: | |
5490 | case BFD_RELOC_PPC_EMB_RELST_HI: | |
5491 | case BFD_RELOC_PPC_EMB_RELST_HA: | |
5492 | case BFD_RELOC_PPC_EMB_RELSDA: | |
5493 | case BFD_RELOC_PPC_TOC16: | |
0baf16f2 | 5494 | #ifdef OBJ_ELF |
0baf16f2 AM |
5495 | case BFD_RELOC_PPC64_TOC16_LO: |
5496 | case BFD_RELOC_PPC64_TOC16_HI: | |
5497 | case BFD_RELOC_PPC64_TOC16_HA: | |
0baf16f2 | 5498 | #endif |
94f592af | 5499 | if (fixP->fx_pcrel) |
252b5132 | 5500 | { |
94f592af NC |
5501 | if (fixP->fx_addsy != NULL) |
5502 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
252b5132 | 5503 | _("cannot emit PC relative %s relocation against %s"), |
94f592af NC |
5504 | bfd_get_reloc_code_name (fixP->fx_r_type), |
5505 | S_GET_NAME (fixP->fx_addsy)); | |
252b5132 | 5506 | else |
94f592af | 5507 | as_bad_where (fixP->fx_file, fixP->fx_line, |
252b5132 | 5508 | _("cannot emit PC relative %s relocation"), |
94f592af | 5509 | bfd_get_reloc_code_name (fixP->fx_r_type)); |
252b5132 RH |
5510 | } |
5511 | ||
94f592af | 5512 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, |
252b5132 RH |
5513 | value, 2); |
5514 | break; | |
5515 | ||
5516 | /* This case happens when you write, for example, | |
5517 | lis %r3,(L1-L2)@ha | |
5518 | where L1 and L2 are defined later. */ | |
5519 | case BFD_RELOC_HI16: | |
94f592af | 5520 | if (fixP->fx_pcrel) |
252b5132 | 5521 | abort (); |
94f592af | 5522 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, |
0baf16f2 | 5523 | PPC_HI (value), 2); |
252b5132 | 5524 | break; |
0baf16f2 | 5525 | |
252b5132 | 5526 | case BFD_RELOC_HI16_S: |
94f592af | 5527 | if (fixP->fx_pcrel) |
252b5132 | 5528 | abort (); |
94f592af | 5529 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, |
0baf16f2 AM |
5530 | PPC_HA (value), 2); |
5531 | break; | |
5532 | ||
5533 | #ifdef OBJ_ELF | |
0baf16f2 | 5534 | case BFD_RELOC_PPC64_HIGHER: |
94f592af | 5535 | if (fixP->fx_pcrel) |
0baf16f2 | 5536 | abort (); |
94f592af | 5537 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, |
0baf16f2 | 5538 | PPC_HIGHER (value), 2); |
252b5132 RH |
5539 | break; |
5540 | ||
0baf16f2 | 5541 | case BFD_RELOC_PPC64_HIGHER_S: |
94f592af | 5542 | if (fixP->fx_pcrel) |
0baf16f2 | 5543 | abort (); |
94f592af | 5544 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, |
0baf16f2 AM |
5545 | PPC_HIGHERA (value), 2); |
5546 | break; | |
5547 | ||
5548 | case BFD_RELOC_PPC64_HIGHEST: | |
94f592af | 5549 | if (fixP->fx_pcrel) |
0baf16f2 | 5550 | abort (); |
94f592af | 5551 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, |
0baf16f2 AM |
5552 | PPC_HIGHEST (value), 2); |
5553 | break; | |
5554 | ||
5555 | case BFD_RELOC_PPC64_HIGHEST_S: | |
94f592af | 5556 | if (fixP->fx_pcrel) |
0baf16f2 | 5557 | abort (); |
94f592af | 5558 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, |
0baf16f2 AM |
5559 | PPC_HIGHESTA (value), 2); |
5560 | break; | |
5561 | ||
5562 | case BFD_RELOC_PPC64_ADDR16_DS: | |
5563 | case BFD_RELOC_PPC64_ADDR16_LO_DS: | |
5564 | case BFD_RELOC_PPC64_GOT16_DS: | |
5565 | case BFD_RELOC_PPC64_GOT16_LO_DS: | |
5566 | case BFD_RELOC_PPC64_PLT16_LO_DS: | |
5567 | case BFD_RELOC_PPC64_SECTOFF_DS: | |
5568 | case BFD_RELOC_PPC64_SECTOFF_LO_DS: | |
5569 | case BFD_RELOC_PPC64_TOC16_DS: | |
5570 | case BFD_RELOC_PPC64_TOC16_LO_DS: | |
5571 | case BFD_RELOC_PPC64_PLTGOT16_DS: | |
5572 | case BFD_RELOC_PPC64_PLTGOT16_LO_DS: | |
94f592af | 5573 | if (fixP->fx_pcrel) |
0baf16f2 AM |
5574 | abort (); |
5575 | { | |
94f592af | 5576 | unsigned char *where = fixP->fx_frag->fr_literal + fixP->fx_where; |
0baf16f2 AM |
5577 | unsigned long val; |
5578 | ||
5579 | if (target_big_endian) | |
5580 | val = bfd_getb16 (where); | |
5581 | else | |
5582 | val = bfd_getl16 (where); | |
5583 | val |= (value & 0xfffc); | |
5584 | if (target_big_endian) | |
5585 | bfd_putb16 ((bfd_vma) val, where); | |
5586 | else | |
5587 | bfd_putl16 ((bfd_vma) val, where); | |
5588 | } | |
5589 | break; | |
0baf16f2 | 5590 | #endif |
252b5132 | 5591 | /* Because SDA21 modifies the register field, the size is set to 4 |
99a814a1 | 5592 | bytes, rather than 2, so offset it here appropriately. */ |
252b5132 | 5593 | case BFD_RELOC_PPC_EMB_SDA21: |
94f592af | 5594 | if (fixP->fx_pcrel) |
252b5132 RH |
5595 | abort (); |
5596 | ||
94f592af | 5597 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where |
252b5132 RH |
5598 | + ((target_big_endian) ? 2 : 0), |
5599 | value, 2); | |
5600 | break; | |
5601 | ||
5602 | case BFD_RELOC_8: | |
94f592af | 5603 | if (fixP->fx_pcrel) |
252b5132 RH |
5604 | abort (); |
5605 | ||
94f592af | 5606 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, |
252b5132 RH |
5607 | value, 1); |
5608 | break; | |
5609 | ||
5610 | case BFD_RELOC_24_PLT_PCREL: | |
5611 | case BFD_RELOC_PPC_LOCAL24PC: | |
94f592af | 5612 | if (!fixP->fx_pcrel && !fixP->fx_done) |
252b5132 RH |
5613 | abort (); |
5614 | ||
94f592af | 5615 | if (fixP->fx_done) |
99a814a1 AM |
5616 | { |
5617 | char *where; | |
5618 | unsigned long insn; | |
5619 | ||
5620 | /* Fetch the instruction, insert the fully resolved operand | |
5621 | value, and stuff the instruction back again. */ | |
94f592af | 5622 | where = fixP->fx_frag->fr_literal + fixP->fx_where; |
99a814a1 AM |
5623 | if (target_big_endian) |
5624 | insn = bfd_getb32 ((unsigned char *) where); | |
5625 | else | |
5626 | insn = bfd_getl32 ((unsigned char *) where); | |
5627 | if ((value & 3) != 0) | |
94f592af | 5628 | as_bad_where (fixP->fx_file, fixP->fx_line, |
99a814a1 AM |
5629 | _("must branch to an address a multiple of 4")); |
5630 | if ((offsetT) value < -0x40000000 | |
5631 | || (offsetT) value >= 0x40000000) | |
94f592af | 5632 | as_bad_where (fixP->fx_file, fixP->fx_line, |
99a814a1 AM |
5633 | _("@local or @plt branch destination is too far away, %ld bytes"), |
5634 | (long) value); | |
5635 | insn = insn | (value & 0x03fffffc); | |
5636 | if (target_big_endian) | |
5637 | bfd_putb32 ((bfd_vma) insn, (unsigned char *) where); | |
5638 | else | |
5639 | bfd_putl32 ((bfd_vma) insn, (unsigned char *) where); | |
5640 | } | |
252b5132 RH |
5641 | break; |
5642 | ||
5643 | case BFD_RELOC_VTABLE_INHERIT: | |
94f592af NC |
5644 | fixP->fx_done = 0; |
5645 | if (fixP->fx_addsy | |
5646 | && !S_IS_DEFINED (fixP->fx_addsy) | |
5647 | && !S_IS_WEAK (fixP->fx_addsy)) | |
5648 | S_SET_WEAK (fixP->fx_addsy); | |
252b5132 RH |
5649 | break; |
5650 | ||
5651 | case BFD_RELOC_VTABLE_ENTRY: | |
94f592af | 5652 | fixP->fx_done = 0; |
252b5132 RH |
5653 | break; |
5654 | ||
0baf16f2 | 5655 | #ifdef OBJ_ELF |
0baf16f2 AM |
5656 | /* Generated by reference to `sym@tocbase'. The sym is |
5657 | ignored by the linker. */ | |
5658 | case BFD_RELOC_PPC64_TOC: | |
94f592af | 5659 | fixP->fx_done = 0; |
0baf16f2 | 5660 | break; |
0baf16f2 | 5661 | #endif |
252b5132 | 5662 | default: |
bc805888 | 5663 | fprintf (stderr, |
94f592af | 5664 | _("Gas failure, reloc value %d\n"), fixP->fx_r_type); |
99a814a1 | 5665 | fflush (stderr); |
252b5132 RH |
5666 | abort (); |
5667 | } | |
5668 | } | |
5669 | ||
5670 | #ifdef OBJ_ELF | |
94f592af | 5671 | fixP->fx_addnumber = value; |
252b5132 | 5672 | #else |
94f592af NC |
5673 | if (fixP->fx_r_type != BFD_RELOC_PPC_TOC16) |
5674 | fixP->fx_addnumber = 0; | |
252b5132 RH |
5675 | else |
5676 | { | |
5677 | #ifdef TE_PE | |
94f592af | 5678 | fixP->fx_addnumber = 0; |
252b5132 RH |
5679 | #else |
5680 | /* We want to use the offset within the data segment of the | |
5681 | symbol, not the actual VMA of the symbol. */ | |
94f592af NC |
5682 | fixP->fx_addnumber = |
5683 | - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixP->fx_addsy)); | |
252b5132 RH |
5684 | #endif |
5685 | } | |
5686 | #endif | |
252b5132 RH |
5687 | } |
5688 | ||
5689 | /* Generate a reloc for a fixup. */ | |
5690 | ||
5691 | arelent * | |
5692 | tc_gen_reloc (seg, fixp) | |
92161534 | 5693 | asection *seg ATTRIBUTE_UNUSED; |
252b5132 RH |
5694 | fixS *fixp; |
5695 | { | |
5696 | arelent *reloc; | |
5697 | ||
5698 | reloc = (arelent *) xmalloc (sizeof (arelent)); | |
5699 | ||
49309057 ILT |
5700 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
5701 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
5702 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; |
5703 | reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type); | |
5704 | if (reloc->howto == (reloc_howto_type *) NULL) | |
5705 | { | |
5706 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
99a814a1 AM |
5707 | _("reloc %d not supported by object file format"), |
5708 | (int) fixp->fx_r_type); | |
252b5132 RH |
5709 | return NULL; |
5710 | } | |
5711 | reloc->addend = fixp->fx_addnumber; | |
5712 | ||
5713 | return reloc; | |
5714 | } |