Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* symbols.c -symbol table- |
4c63da97 | 2 | Copyright (C) 1987, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000 |
252b5132 RH |
3 | Free Software Foundation, Inc. |
4 | ||
5 | This file is part of GAS, the GNU Assembler. | |
6 | ||
7 | GAS is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GAS is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GAS; see the file COPYING. If not, write to the Free | |
19 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
21 | ||
7c743825 | 22 | /* #define DEBUG_SYMS / * to debug symbol list maintenance. */ |
252b5132 RH |
23 | |
24 | #include <ctype.h> | |
25 | ||
26 | #include "as.h" | |
27 | ||
28 | #include "obstack.h" /* For "symbols.h" */ | |
29 | #include "subsegs.h" | |
30 | ||
49309057 ILT |
31 | #include "struc-symbol.h" |
32 | ||
252b5132 RH |
33 | /* This is non-zero if symbols are case sensitive, which is the |
34 | default. */ | |
35 | int symbols_case_sensitive = 1; | |
36 | ||
37 | #ifndef WORKING_DOT_WORD | |
38 | extern int new_broken_words; | |
39 | #endif | |
40 | ||
41 | /* symbol-name => struct symbol pointer */ | |
42 | static struct hash_control *sy_hash; | |
43 | ||
49309057 ILT |
44 | /* Table of local symbols. */ |
45 | static struct hash_control *local_hash; | |
46 | ||
7c743825 | 47 | /* Below are commented in "symbols.h". */ |
252b5132 RH |
48 | symbolS *symbol_rootP; |
49 | symbolS *symbol_lastP; | |
50 | symbolS abs_symbol; | |
51 | ||
52 | #ifdef DEBUG_SYMS | |
53 | #define debug_verify_symchain verify_symbol_chain | |
54 | #else | |
55 | #define debug_verify_symchain(root, last) ((void) 0) | |
56 | #endif | |
57 | ||
58 | struct obstack notes; | |
59 | ||
60 | static void fb_label_init PARAMS ((void)); | |
61 | static long dollar_label_instance PARAMS ((long)); | |
62 | static long fb_label_instance PARAMS ((long)); | |
63 | ||
64 | static void print_binary PARAMS ((FILE *, const char *, expressionS *)); | |
65 | ||
7c743825 | 66 | /* Return a pointer to a new symbol. Die if we can't make a new |
252b5132 RH |
67 | symbol. Fill in the symbol's values. Add symbol to end of symbol |
68 | chain. | |
7c743825 | 69 | |
252b5132 RH |
70 | This function should be called in the general case of creating a |
71 | symbol. However, if the output file symbol table has already been | |
72 | set, and you are certain that this symbol won't be wanted in the | |
73 | output file, you can call symbol_create. */ | |
74 | ||
75 | symbolS * | |
76 | symbol_new (name, segment, valu, frag) | |
77 | const char *name; | |
78 | segT segment; | |
79 | valueT valu; | |
80 | fragS *frag; | |
81 | { | |
82 | symbolS *symbolP = symbol_create (name, segment, valu, frag); | |
83 | ||
7c743825 | 84 | /* Link to end of symbol chain. */ |
252b5132 RH |
85 | #ifdef BFD_ASSEMBLER |
86 | { | |
87 | extern int symbol_table_frozen; | |
88 | if (symbol_table_frozen) | |
89 | abort (); | |
90 | } | |
91 | #endif | |
92 | symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP); | |
93 | ||
94 | return symbolP; | |
95 | } | |
96 | ||
49309057 ILT |
97 | /* Save a symbol name on a permanent obstack, and convert it according |
98 | to the object file format. */ | |
99 | ||
100 | static char * | |
101 | save_symbol_name (name) | |
102 | const char *name; | |
252b5132 RH |
103 | { |
104 | unsigned int name_length; | |
49309057 | 105 | char *ret; |
252b5132 | 106 | |
7c743825 | 107 | name_length = strlen (name) + 1; /* +1 for \0. */ |
252b5132 | 108 | obstack_grow (¬es, name, name_length); |
49309057 ILT |
109 | ret = obstack_finish (¬es); |
110 | ||
252b5132 | 111 | #ifdef STRIP_UNDERSCORE |
49309057 ILT |
112 | if (ret[0] == '_') |
113 | ++ret; | |
252b5132 RH |
114 | #endif |
115 | ||
116 | #ifdef tc_canonicalize_symbol_name | |
49309057 | 117 | ret = tc_canonicalize_symbol_name (ret); |
252b5132 RH |
118 | #endif |
119 | ||
120 | if (! symbols_case_sensitive) | |
121 | { | |
122 | unsigned char *s; | |
123 | ||
49309057 | 124 | for (s = (unsigned char *) ret; *s != '\0'; s++) |
252b5132 RH |
125 | if (islower (*s)) |
126 | *s = toupper (*s); | |
127 | } | |
128 | ||
49309057 ILT |
129 | return ret; |
130 | } | |
131 | ||
132 | symbolS * | |
133 | symbol_create (name, segment, valu, frag) | |
7c743825 KH |
134 | const char *name; /* It is copied, the caller can destroy/modify. */ |
135 | segT segment; /* Segment identifier (SEG_<something>). */ | |
136 | valueT valu; /* Symbol value. */ | |
137 | fragS *frag; /* Associated fragment. */ | |
49309057 ILT |
138 | { |
139 | char *preserved_copy_of_name; | |
140 | symbolS *symbolP; | |
141 | ||
142 | preserved_copy_of_name = save_symbol_name (name); | |
143 | ||
252b5132 RH |
144 | symbolP = (symbolS *) obstack_alloc (¬es, sizeof (symbolS)); |
145 | ||
7c743825 | 146 | /* symbol must be born in some fixed state. This seems as good as any. */ |
252b5132 RH |
147 | memset (symbolP, 0, sizeof (symbolS)); |
148 | ||
149 | #ifdef BFD_ASSEMBLER | |
150 | symbolP->bsym = bfd_make_empty_symbol (stdoutput); | |
151 | if (symbolP->bsym == NULL) | |
152 | as_perror ("%s", "bfd_make_empty_symbol"); | |
153 | symbolP->bsym->udata.p = (PTR) symbolP; | |
154 | #endif | |
155 | S_SET_NAME (symbolP, preserved_copy_of_name); | |
156 | ||
157 | S_SET_SEGMENT (symbolP, segment); | |
158 | S_SET_VALUE (symbolP, valu); | |
159 | symbol_clear_list_pointers (symbolP); | |
160 | ||
161 | symbolP->sy_frag = frag; | |
162 | #ifndef BFD_ASSEMBLER | |
163 | symbolP->sy_number = ~0; | |
164 | symbolP->sy_name_offset = (unsigned int) ~0; | |
165 | #endif | |
166 | ||
167 | obj_symbol_new_hook (symbolP); | |
168 | ||
169 | #ifdef tc_symbol_new_hook | |
170 | tc_symbol_new_hook (symbolP); | |
171 | #endif | |
172 | ||
173 | return symbolP; | |
174 | } | |
175 | \f | |
49309057 ILT |
176 | #ifdef BFD_ASSEMBLER |
177 | ||
178 | /* Local symbol support. If we can get away with it, we keep only a | |
179 | small amount of information for local symbols. */ | |
180 | ||
181 | static struct local_symbol *local_symbol_make PARAMS ((const char *, segT, | |
182 | valueT, fragS *)); | |
183 | static symbolS *local_symbol_convert PARAMS ((struct local_symbol *)); | |
184 | ||
185 | /* Used for statistics. */ | |
186 | ||
187 | static unsigned long local_symbol_count; | |
188 | static unsigned long local_symbol_conversion_count; | |
189 | ||
190 | /* This macro is called with a symbol argument passed by reference. | |
191 | It returns whether this is a local symbol. If necessary, it | |
192 | changes its argument to the real symbol. */ | |
193 | ||
194 | #define LOCAL_SYMBOL_CHECK(s) \ | |
195 | (s->bsym == NULL \ | |
196 | ? (local_symbol_converted_p ((struct local_symbol *) s) \ | |
197 | ? (s = local_symbol_get_real_symbol ((struct local_symbol *) s), \ | |
198 | 0) \ | |
199 | : 1) \ | |
200 | : 0) | |
201 | ||
202 | /* Create a local symbol and insert it into the local hash table. */ | |
203 | ||
204 | static struct local_symbol * | |
205 | local_symbol_make (name, section, offset, frag) | |
206 | const char *name; | |
207 | segT section; | |
208 | valueT offset; | |
209 | fragS *frag; | |
210 | { | |
211 | char *name_copy; | |
212 | struct local_symbol *ret; | |
213 | ||
214 | ++local_symbol_count; | |
215 | ||
216 | name_copy = save_symbol_name (name); | |
217 | ||
218 | ret = (struct local_symbol *) obstack_alloc (¬es, sizeof *ret); | |
219 | ret->lsy_marker = NULL; | |
220 | ret->lsy_name = name_copy; | |
221 | ret->lsy_section = section; | |
222 | local_symbol_set_frag (ret, frag); | |
223 | ret->lsy_offset = offset; | |
224 | ||
225 | hash_jam (local_hash, name_copy, (PTR) ret); | |
226 | ||
227 | return ret; | |
228 | } | |
229 | ||
230 | /* Convert a local symbol into a real symbol. Note that we do not | |
231 | reclaim the space used by the local symbol. */ | |
232 | ||
233 | static symbolS * | |
234 | local_symbol_convert (locsym) | |
235 | struct local_symbol *locsym; | |
236 | { | |
237 | symbolS *ret; | |
238 | ||
239 | assert (locsym->lsy_marker == NULL); | |
240 | if (local_symbol_converted_p (locsym)) | |
241 | return local_symbol_get_real_symbol (locsym); | |
242 | ||
243 | ++local_symbol_conversion_count; | |
244 | ||
245 | ret = symbol_new (locsym->lsy_name, locsym->lsy_section, locsym->lsy_offset, | |
246 | local_symbol_get_frag (locsym)); | |
247 | ||
248 | if (local_symbol_resolved_p (locsym)) | |
249 | ret->sy_resolved = 1; | |
250 | ||
251 | /* Local symbols are always either defined or used. */ | |
252 | ret->sy_used = 1; | |
253 | ||
254 | symbol_table_insert (ret); | |
255 | ||
256 | local_symbol_mark_converted (locsym); | |
257 | local_symbol_set_real_symbol (locsym, ret); | |
258 | ||
259 | hash_jam (local_hash, locsym->lsy_name, NULL); | |
260 | ||
261 | return ret; | |
262 | } | |
263 | ||
264 | #else /* ! BFD_ASSEMBLER */ | |
265 | ||
266 | #define LOCAL_SYMBOL_CHECK(s) 0 | |
267 | #define local_symbol_convert(s) ((symbolS *) s) | |
268 | ||
269 | #endif /* ! BFD_ASSEMBLER */ | |
270 | \f | |
7c743825 KH |
271 | /* We have just seen "<name>:". |
272 | Creates a struct symbol unless it already exists. | |
273 | ||
274 | Gripes if we are redefining a symbol incompatibly (and ignores it). */ | |
252b5132 | 275 | |
252b5132 | 276 | symbolS * |
7c743825 KH |
277 | colon (sym_name) /* Just seen "x:" - rattle symbols & frags. */ |
278 | const char *sym_name; /* Symbol name, as a cannonical string. */ | |
279 | /* We copy this string: OK to alter later. */ | |
252b5132 | 280 | { |
7c743825 | 281 | register symbolS *symbolP; /* Symbol we are working with. */ |
252b5132 RH |
282 | |
283 | /* Sun local labels go out of scope whenever a non-local symbol is | |
284 | defined. */ | |
285 | if (LOCAL_LABELS_DOLLAR) | |
286 | { | |
287 | int local; | |
288 | ||
289 | #ifdef BFD_ASSEMBLER | |
290 | local = bfd_is_local_label_name (stdoutput, sym_name); | |
291 | #else | |
292 | local = LOCAL_LABEL (sym_name); | |
293 | #endif | |
294 | ||
295 | if (! local) | |
296 | dollar_label_clear (); | |
297 | } | |
298 | ||
299 | #ifndef WORKING_DOT_WORD | |
300 | if (new_broken_words) | |
301 | { | |
302 | struct broken_word *a; | |
303 | int possible_bytes; | |
304 | fragS *frag_tmp; | |
305 | char *frag_opcode; | |
306 | ||
307 | extern const int md_short_jump_size; | |
308 | extern const int md_long_jump_size; | |
309 | possible_bytes = (md_short_jump_size | |
310 | + new_broken_words * md_long_jump_size); | |
311 | ||
312 | frag_tmp = frag_now; | |
313 | frag_opcode = frag_var (rs_broken_word, | |
314 | possible_bytes, | |
315 | possible_bytes, | |
316 | (relax_substateT) 0, | |
317 | (symbolS *) broken_words, | |
318 | (offsetT) 0, | |
319 | NULL); | |
320 | ||
7c743825 KH |
321 | /* We want to store the pointer to where to insert the jump |
322 | table in the fr_opcode of the rs_broken_word frag. This | |
323 | requires a little hackery. */ | |
252b5132 RH |
324 | while (frag_tmp |
325 | && (frag_tmp->fr_type != rs_broken_word | |
326 | || frag_tmp->fr_opcode)) | |
327 | frag_tmp = frag_tmp->fr_next; | |
328 | know (frag_tmp); | |
329 | frag_tmp->fr_opcode = frag_opcode; | |
330 | new_broken_words = 0; | |
331 | ||
332 | for (a = broken_words; a && a->dispfrag == 0; a = a->next_broken_word) | |
333 | a->dispfrag = frag_tmp; | |
334 | } | |
335 | #endif /* WORKING_DOT_WORD */ | |
336 | ||
337 | if ((symbolP = symbol_find (sym_name)) != 0) | |
338 | { | |
339 | #ifdef RESOLVE_SYMBOL_REDEFINITION | |
340 | if (RESOLVE_SYMBOL_REDEFINITION (symbolP)) | |
341 | return symbolP; | |
342 | #endif | |
7c743825 | 343 | /* Now check for undefined symbols. */ |
49309057 ILT |
344 | if (LOCAL_SYMBOL_CHECK (symbolP)) |
345 | { | |
a1605869 | 346 | #ifdef BFD_ASSEMBLER |
49309057 ILT |
347 | struct local_symbol *locsym = (struct local_symbol *) symbolP; |
348 | ||
349 | if (locsym->lsy_section != undefined_section | |
350 | && (local_symbol_get_frag (locsym) != frag_now | |
351 | || locsym->lsy_section != now_seg | |
352 | || locsym->lsy_offset != frag_now_fix ())) | |
353 | { | |
354 | as_bad (_("Symbol %s already defined."), sym_name); | |
355 | return symbolP; | |
356 | } | |
357 | ||
358 | locsym->lsy_section = now_seg; | |
359 | local_symbol_set_frag (locsym, frag_now); | |
360 | locsym->lsy_offset = frag_now_fix (); | |
a1605869 | 361 | #endif |
49309057 ILT |
362 | } |
363 | else if (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP)) | |
252b5132 RH |
364 | { |
365 | if (S_GET_VALUE (symbolP) == 0) | |
366 | { | |
367 | symbolP->sy_frag = frag_now; | |
368 | #ifdef OBJ_VMS | |
7c743825 | 369 | S_SET_OTHER (symbolP, const_flag); |
252b5132 RH |
370 | #endif |
371 | S_SET_VALUE (symbolP, (valueT) frag_now_fix ()); | |
372 | S_SET_SEGMENT (symbolP, now_seg); | |
373 | #ifdef N_UNDF | |
374 | know (N_UNDF == 0); | |
7c743825 | 375 | #endif /* if we have one, it better be zero. */ |
252b5132 RH |
376 | |
377 | } | |
378 | else | |
379 | { | |
7c743825 KH |
380 | /* There are still several cases to check: |
381 | ||
382 | A .comm/.lcomm symbol being redefined as initialized | |
383 | data is OK | |
384 | ||
385 | A .comm/.lcomm symbol being redefined with a larger | |
386 | size is also OK | |
387 | ||
388 | This only used to be allowed on VMS gas, but Sun cc | |
389 | on the sparc also depends on it. */ | |
252b5132 RH |
390 | |
391 | if (((!S_IS_DEBUG (symbolP) | |
392 | && (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP)) | |
393 | && S_IS_EXTERNAL (symbolP)) | |
394 | || S_GET_SEGMENT (symbolP) == bss_section) | |
395 | && (now_seg == data_section | |
396 | || now_seg == S_GET_SEGMENT (symbolP))) | |
397 | { | |
7c743825 | 398 | /* Select which of the 2 cases this is. */ |
252b5132 RH |
399 | if (now_seg != data_section) |
400 | { | |
7c743825 KH |
401 | /* New .comm for prev .comm symbol. |
402 | ||
403 | If the new size is larger we just change its | |
404 | value. If the new size is smaller, we ignore | |
405 | this symbol. */ | |
252b5132 RH |
406 | if (S_GET_VALUE (symbolP) |
407 | < ((unsigned) frag_now_fix ())) | |
408 | { | |
409 | S_SET_VALUE (symbolP, (valueT) frag_now_fix ()); | |
410 | } | |
411 | } | |
412 | else | |
413 | { | |
414 | /* It is a .comm/.lcomm being converted to initialized | |
415 | data. */ | |
416 | symbolP->sy_frag = frag_now; | |
417 | #ifdef OBJ_VMS | |
7c743825 | 418 | S_SET_OTHER (symbolP, const_flag); |
252b5132 RH |
419 | #endif |
420 | S_SET_VALUE (symbolP, (valueT) frag_now_fix ()); | |
7c743825 | 421 | S_SET_SEGMENT (symbolP, now_seg); /* Keep N_EXT bit. */ |
252b5132 RH |
422 | } |
423 | } | |
424 | else | |
425 | { | |
4c63da97 AM |
426 | #if (!defined (OBJ_AOUT) && !defined (OBJ_MAYBE_AOUT) \ |
427 | && !defined (OBJ_BOUT) && !defined (OBJ_MAYBE_BOUT)) | |
428 | static const char *od_buf = ""; | |
252b5132 | 429 | #else |
4c63da97 AM |
430 | char od_buf[100]; |
431 | od_buf[0] = '\0'; | |
432 | #ifdef BFD_ASSEMBLER | |
433 | if (OUTPUT_FLAVOR == bfd_target_aout_flavour) | |
434 | #endif | |
435 | sprintf(od_buf, "%d.%d.", | |
436 | S_GET_OTHER (symbolP), | |
437 | S_GET_DESC (symbolP)); | |
438 | #endif | |
439 | as_fatal (_("Symbol \"%s\" is already defined as \"%s\"/%s%ld."), | |
252b5132 RH |
440 | sym_name, |
441 | segment_name (S_GET_SEGMENT (symbolP)), | |
4c63da97 | 442 | od_buf, |
252b5132 | 443 | (long) S_GET_VALUE (symbolP)); |
252b5132 | 444 | } |
7c743825 | 445 | } /* if the undefined symbol has no value */ |
252b5132 RH |
446 | } |
447 | else | |
448 | { | |
7c743825 | 449 | /* Don't blow up if the definition is the same. */ |
252b5132 RH |
450 | if (!(frag_now == symbolP->sy_frag |
451 | && S_GET_VALUE (symbolP) == frag_now_fix () | |
452 | && S_GET_SEGMENT (symbolP) == now_seg)) | |
453 | as_fatal (_("Symbol %s already defined."), sym_name); | |
7c743825 | 454 | } /* if this symbol is not yet defined */ |
252b5132 RH |
455 | |
456 | } | |
49309057 ILT |
457 | #ifdef BFD_ASSEMBLER |
458 | else if (! flag_keep_locals && bfd_is_local_label_name (stdoutput, sym_name)) | |
459 | { | |
460 | symbolP = (symbolS *) local_symbol_make (sym_name, now_seg, | |
461 | (valueT) frag_now_fix (), | |
462 | frag_now); | |
463 | } | |
464 | #endif /* BFD_ASSEMBLER */ | |
252b5132 RH |
465 | else |
466 | { | |
467 | symbolP = symbol_new (sym_name, now_seg, (valueT) frag_now_fix (), | |
468 | frag_now); | |
469 | #ifdef OBJ_VMS | |
470 | S_SET_OTHER (symbolP, const_flag); | |
471 | #endif /* OBJ_VMS */ | |
472 | ||
473 | symbol_table_insert (symbolP); | |
7c743825 | 474 | } /* if we have seen this symbol before */ |
252b5132 RH |
475 | |
476 | if (mri_common_symbol != NULL) | |
477 | { | |
478 | /* This symbol is actually being defined within an MRI common | |
479 | section. This requires special handling. */ | |
49309057 ILT |
480 | if (LOCAL_SYMBOL_CHECK (symbolP)) |
481 | symbolP = local_symbol_convert ((struct local_symbol *) symbolP); | |
252b5132 RH |
482 | symbolP->sy_value.X_op = O_symbol; |
483 | symbolP->sy_value.X_add_symbol = mri_common_symbol; | |
484 | symbolP->sy_value.X_add_number = S_GET_VALUE (mri_common_symbol); | |
485 | symbolP->sy_frag = &zero_address_frag; | |
486 | S_SET_SEGMENT (symbolP, expr_section); | |
487 | symbolP->sy_mri_common = 1; | |
488 | } | |
489 | ||
490 | #ifdef tc_frob_label | |
491 | tc_frob_label (symbolP); | |
492 | #endif | |
493 | #ifdef obj_frob_label | |
494 | obj_frob_label (symbolP); | |
495 | #endif | |
496 | ||
497 | return symbolP; | |
498 | } | |
499 | \f | |
7c743825 | 500 | /* Die if we can't insert the symbol. */ |
252b5132 | 501 | |
7c743825 | 502 | void |
252b5132 RH |
503 | symbol_table_insert (symbolP) |
504 | symbolS *symbolP; | |
505 | { | |
506 | register const char *error_string; | |
507 | ||
508 | know (symbolP); | |
509 | know (S_GET_NAME (symbolP)); | |
510 | ||
49309057 ILT |
511 | if (LOCAL_SYMBOL_CHECK (symbolP)) |
512 | { | |
513 | error_string = hash_jam (local_hash, S_GET_NAME (symbolP), | |
514 | (PTR) symbolP); | |
515 | if (error_string != NULL) | |
516 | as_fatal (_("Inserting \"%s\" into symbol table failed: %s"), | |
517 | S_GET_NAME (symbolP), error_string); | |
518 | return; | |
519 | } | |
520 | ||
252b5132 RH |
521 | if ((error_string = hash_jam (sy_hash, S_GET_NAME (symbolP), (PTR) symbolP))) |
522 | { | |
523 | as_fatal (_("Inserting \"%s\" into symbol table failed: %s"), | |
524 | S_GET_NAME (symbolP), error_string); | |
7c743825 KH |
525 | } /* on error */ |
526 | } | |
252b5132 | 527 | \f |
7c743825 KH |
528 | /* If a symbol name does not exist, create it as undefined, and insert |
529 | it into the symbol table. Return a pointer to it. */ | |
530 | ||
252b5132 RH |
531 | symbolS * |
532 | symbol_find_or_make (name) | |
533 | const char *name; | |
534 | { | |
535 | register symbolS *symbolP; | |
536 | ||
537 | symbolP = symbol_find (name); | |
538 | ||
539 | if (symbolP == NULL) | |
540 | { | |
49309057 ILT |
541 | #ifdef BFD_ASSEMBLER |
542 | if (! flag_keep_locals && bfd_is_local_label_name (stdoutput, name)) | |
543 | { | |
544 | symbolP = md_undefined_symbol ((char *) name); | |
545 | if (symbolP != NULL) | |
546 | return symbolP; | |
547 | ||
548 | symbolP = (symbolS *) local_symbol_make (name, undefined_section, | |
549 | (valueT) 0, | |
550 | &zero_address_frag); | |
551 | return symbolP; | |
552 | } | |
553 | #endif | |
554 | ||
252b5132 RH |
555 | symbolP = symbol_make (name); |
556 | ||
557 | symbol_table_insert (symbolP); | |
558 | } /* if symbol wasn't found */ | |
559 | ||
560 | return (symbolP); | |
7c743825 | 561 | } |
252b5132 RH |
562 | |
563 | symbolS * | |
564 | symbol_make (name) | |
565 | CONST char *name; | |
566 | { | |
567 | symbolS *symbolP; | |
568 | ||
7c743825 | 569 | /* Let the machine description default it, e.g. for register names. */ |
252b5132 RH |
570 | symbolP = md_undefined_symbol ((char *) name); |
571 | ||
572 | if (!symbolP) | |
573 | symbolP = symbol_new (name, undefined_section, (valueT) 0, &zero_address_frag); | |
574 | ||
575 | return (symbolP); | |
7c743825 | 576 | } |
252b5132 | 577 | |
7c743825 KH |
578 | /* Implement symbol table lookup. |
579 | In: A symbol's name as a string: '\0' can't be part of a symbol name. | |
580 | Out: NULL if the name was not in the symbol table, else the address | |
581 | of a struct symbol associated with that name. */ | |
252b5132 RH |
582 | |
583 | symbolS * | |
584 | symbol_find (name) | |
585 | CONST char *name; | |
586 | { | |
587 | #ifdef STRIP_UNDERSCORE | |
588 | return (symbol_find_base (name, 1)); | |
589 | #else /* STRIP_UNDERSCORE */ | |
590 | return (symbol_find_base (name, 0)); | |
591 | #endif /* STRIP_UNDERSCORE */ | |
7c743825 | 592 | } |
252b5132 RH |
593 | |
594 | symbolS * | |
595 | symbol_find_base (name, strip_underscore) | |
596 | CONST char *name; | |
597 | int strip_underscore; | |
598 | { | |
599 | if (strip_underscore && *name == '_') | |
600 | name++; | |
601 | ||
602 | #ifdef tc_canonicalize_symbol_name | |
603 | { | |
604 | char *copy; | |
03987ced | 605 | size_t len = strlen (name) + 1; |
252b5132 | 606 | |
03987ced RH |
607 | copy = (char *) alloca (len); |
608 | memcpy (copy, name, len); | |
252b5132 RH |
609 | name = tc_canonicalize_symbol_name (copy); |
610 | } | |
611 | #endif | |
612 | ||
613 | if (! symbols_case_sensitive) | |
614 | { | |
03987ced RH |
615 | char *copy; |
616 | const char *orig; | |
617 | unsigned char c; | |
618 | ||
619 | orig = name; | |
620 | name = copy = (char *) alloca (strlen (name) + 1); | |
621 | ||
622 | while ((c = *orig++) != '\0') | |
623 | { | |
624 | if (islower (c)) | |
625 | c = toupper (c); | |
626 | *copy++ = c; | |
627 | } | |
628 | *copy = '\0'; | |
252b5132 RH |
629 | } |
630 | ||
a1605869 ILT |
631 | #ifdef BFD_ASSEMBLER |
632 | { | |
633 | struct local_symbol *locsym; | |
634 | ||
635 | locsym = (struct local_symbol *) hash_find (local_hash, name); | |
636 | if (locsym != NULL) | |
637 | return (symbolS *) locsym; | |
638 | } | |
639 | #endif | |
49309057 | 640 | |
252b5132 RH |
641 | return ((symbolS *) hash_find (sy_hash, name)); |
642 | } | |
643 | ||
7c743825 KH |
644 | /* Once upon a time, symbols were kept in a singly linked list. At |
645 | least coff needs to be able to rearrange them from time to time, for | |
646 | which a doubly linked list is much more convenient. Loic did these | |
647 | as macros which seemed dangerous to me so they're now functions. | |
648 | xoxorich. */ | |
649 | ||
650 | /* Link symbol ADDME after symbol TARGET in the chain. */ | |
252b5132 | 651 | |
7c743825 | 652 | void |
252b5132 RH |
653 | symbol_append (addme, target, rootPP, lastPP) |
654 | symbolS *addme; | |
655 | symbolS *target; | |
656 | symbolS **rootPP; | |
657 | symbolS **lastPP; | |
658 | { | |
49309057 ILT |
659 | if (LOCAL_SYMBOL_CHECK (addme)) |
660 | abort (); | |
661 | if (target != NULL && LOCAL_SYMBOL_CHECK (target)) | |
662 | abort (); | |
663 | ||
252b5132 RH |
664 | if (target == NULL) |
665 | { | |
666 | know (*rootPP == NULL); | |
667 | know (*lastPP == NULL); | |
668 | addme->sy_next = NULL; | |
669 | #ifdef SYMBOLS_NEED_BACKPOINTERS | |
670 | addme->sy_previous = NULL; | |
671 | #endif | |
672 | *rootPP = addme; | |
673 | *lastPP = addme; | |
674 | return; | |
7c743825 | 675 | } /* if the list is empty */ |
252b5132 RH |
676 | |
677 | if (target->sy_next != NULL) | |
678 | { | |
679 | #ifdef SYMBOLS_NEED_BACKPOINTERS | |
680 | target->sy_next->sy_previous = addme; | |
681 | #endif /* SYMBOLS_NEED_BACKPOINTERS */ | |
682 | } | |
683 | else | |
684 | { | |
685 | know (*lastPP == target); | |
686 | *lastPP = addme; | |
7c743825 | 687 | } /* if we have a next */ |
252b5132 RH |
688 | |
689 | addme->sy_next = target->sy_next; | |
690 | target->sy_next = addme; | |
691 | ||
692 | #ifdef SYMBOLS_NEED_BACKPOINTERS | |
693 | addme->sy_previous = target; | |
694 | #endif /* SYMBOLS_NEED_BACKPOINTERS */ | |
695 | ||
696 | debug_verify_symchain (symbol_rootP, symbol_lastP); | |
697 | } | |
698 | ||
7c743825 KH |
699 | /* Set the chain pointers of SYMBOL to null. */ |
700 | ||
701 | void | |
252b5132 RH |
702 | symbol_clear_list_pointers (symbolP) |
703 | symbolS *symbolP; | |
704 | { | |
49309057 ILT |
705 | if (LOCAL_SYMBOL_CHECK (symbolP)) |
706 | abort (); | |
252b5132 RH |
707 | symbolP->sy_next = NULL; |
708 | #ifdef SYMBOLS_NEED_BACKPOINTERS | |
709 | symbolP->sy_previous = NULL; | |
710 | #endif | |
711 | } | |
712 | ||
713 | #ifdef SYMBOLS_NEED_BACKPOINTERS | |
7c743825 KH |
714 | /* Remove SYMBOLP from the list. */ |
715 | ||
716 | void | |
252b5132 RH |
717 | symbol_remove (symbolP, rootPP, lastPP) |
718 | symbolS *symbolP; | |
719 | symbolS **rootPP; | |
720 | symbolS **lastPP; | |
721 | { | |
49309057 ILT |
722 | if (LOCAL_SYMBOL_CHECK (symbolP)) |
723 | abort (); | |
724 | ||
252b5132 RH |
725 | if (symbolP == *rootPP) |
726 | { | |
727 | *rootPP = symbolP->sy_next; | |
7c743825 | 728 | } /* if it was the root */ |
252b5132 RH |
729 | |
730 | if (symbolP == *lastPP) | |
731 | { | |
732 | *lastPP = symbolP->sy_previous; | |
7c743825 | 733 | } /* if it was the tail */ |
252b5132 RH |
734 | |
735 | if (symbolP->sy_next != NULL) | |
736 | { | |
737 | symbolP->sy_next->sy_previous = symbolP->sy_previous; | |
7c743825 | 738 | } /* if not last */ |
252b5132 RH |
739 | |
740 | if (symbolP->sy_previous != NULL) | |
741 | { | |
742 | symbolP->sy_previous->sy_next = symbolP->sy_next; | |
7c743825 | 743 | } /* if not first */ |
252b5132 RH |
744 | |
745 | debug_verify_symchain (*rootPP, *lastPP); | |
746 | } | |
747 | ||
7c743825 KH |
748 | /* Link symbol ADDME before symbol TARGET in the chain. */ |
749 | ||
750 | void | |
252b5132 RH |
751 | symbol_insert (addme, target, rootPP, lastPP) |
752 | symbolS *addme; | |
753 | symbolS *target; | |
754 | symbolS **rootPP; | |
ab9da554 | 755 | symbolS **lastPP ATTRIBUTE_UNUSED; |
252b5132 | 756 | { |
49309057 ILT |
757 | if (LOCAL_SYMBOL_CHECK (addme)) |
758 | abort (); | |
759 | if (LOCAL_SYMBOL_CHECK (target)) | |
760 | abort (); | |
761 | ||
252b5132 RH |
762 | if (target->sy_previous != NULL) |
763 | { | |
764 | target->sy_previous->sy_next = addme; | |
765 | } | |
766 | else | |
767 | { | |
768 | know (*rootPP == target); | |
769 | *rootPP = addme; | |
7c743825 | 770 | } /* if not first */ |
252b5132 RH |
771 | |
772 | addme->sy_previous = target->sy_previous; | |
773 | target->sy_previous = addme; | |
774 | addme->sy_next = target; | |
775 | ||
776 | debug_verify_symchain (*rootPP, *lastPP); | |
777 | } | |
778 | ||
779 | #endif /* SYMBOLS_NEED_BACKPOINTERS */ | |
780 | ||
7c743825 | 781 | void |
252b5132 RH |
782 | verify_symbol_chain (rootP, lastP) |
783 | symbolS *rootP; | |
784 | symbolS *lastP; | |
785 | { | |
786 | symbolS *symbolP = rootP; | |
787 | ||
788 | if (symbolP == NULL) | |
789 | return; | |
790 | ||
791 | for (; symbol_next (symbolP) != NULL; symbolP = symbol_next (symbolP)) | |
792 | { | |
49309057 ILT |
793 | #ifdef BFD_ASSEMBLER |
794 | assert (symbolP->bsym != NULL); | |
795 | #endif | |
252b5132 RH |
796 | #ifdef SYMBOLS_NEED_BACKPOINTERS |
797 | assert (symbolP->sy_next->sy_previous == symbolP); | |
798 | #else | |
799 | /* Walk the list anyways, to make sure pointers are still good. */ | |
800 | ; | |
801 | #endif /* SYMBOLS_NEED_BACKPOINTERS */ | |
802 | } | |
803 | ||
804 | assert (lastP == symbolP); | |
805 | } | |
806 | ||
807 | void | |
808 | verify_symbol_chain_2 (sym) | |
809 | symbolS *sym; | |
810 | { | |
811 | symbolS *p = sym, *n = sym; | |
812 | #ifdef SYMBOLS_NEED_BACKPOINTERS | |
813 | while (symbol_previous (p)) | |
814 | p = symbol_previous (p); | |
815 | #endif | |
816 | while (symbol_next (n)) | |
817 | n = symbol_next (n); | |
818 | verify_symbol_chain (p, n); | |
819 | } | |
820 | ||
821 | /* Resolve the value of a symbol. This is called during the final | |
822 | pass over the symbol table to resolve any symbols with complex | |
823 | values. */ | |
824 | ||
825 | valueT | |
826 | resolve_symbol_value (symp, finalize) | |
827 | symbolS *symp; | |
828 | int finalize; | |
829 | { | |
830 | int resolved; | |
831 | valueT final_val; | |
832 | segT final_seg; | |
833 | ||
a1605869 | 834 | #ifdef BFD_ASSEMBLER |
49309057 ILT |
835 | if (LOCAL_SYMBOL_CHECK (symp)) |
836 | { | |
837 | struct local_symbol *locsym = (struct local_symbol *) symp; | |
838 | ||
839 | if (local_symbol_resolved_p (locsym)) | |
24ef8152 | 840 | return locsym->lsy_offset / bfd_octets_per_byte (stdoutput); |
49309057 ILT |
841 | |
842 | final_val = (local_symbol_get_frag (locsym)->fr_address | |
24ef8152 | 843 | + locsym->lsy_offset) / bfd_octets_per_byte (stdoutput); |
49309057 ILT |
844 | |
845 | if (finalize) | |
846 | { | |
847 | locsym->lsy_offset = final_val; | |
848 | local_symbol_mark_resolved (locsym); | |
849 | } | |
850 | ||
851 | return final_val; | |
852 | } | |
a1605869 | 853 | #endif |
49309057 | 854 | |
252b5132 RH |
855 | if (symp->sy_resolved) |
856 | { | |
857 | if (symp->sy_value.X_op == O_constant) | |
858 | return (valueT) symp->sy_value.X_add_number; | |
859 | else | |
860 | return 0; | |
861 | } | |
862 | ||
863 | resolved = 0; | |
864 | final_seg = S_GET_SEGMENT (symp); | |
865 | ||
866 | if (symp->sy_resolving) | |
867 | { | |
868 | if (finalize) | |
7c743825 KH |
869 | as_bad (_("Symbol definition loop encountered at %s"), |
870 | S_GET_NAME (symp)); | |
252b5132 RH |
871 | final_val = 0; |
872 | resolved = 1; | |
873 | } | |
874 | else | |
875 | { | |
876 | symbolS *add_symbol, *op_symbol; | |
877 | offsetT left, right; | |
878 | segT seg_left, seg_right; | |
879 | operatorT op; | |
880 | ||
881 | symp->sy_resolving = 1; | |
882 | ||
883 | /* Help out with CSE. */ | |
884 | add_symbol = symp->sy_value.X_add_symbol; | |
885 | op_symbol = symp->sy_value.X_op_symbol; | |
886 | final_val = symp->sy_value.X_add_number; | |
887 | op = symp->sy_value.X_op; | |
888 | ||
889 | switch (op) | |
890 | { | |
891 | default: | |
892 | BAD_CASE (op); | |
893 | break; | |
894 | ||
895 | case O_absent: | |
896 | final_val = 0; | |
897 | /* Fall through. */ | |
898 | ||
899 | case O_constant: | |
bea9907b | 900 | final_val += symp->sy_frag->fr_address / OCTETS_PER_BYTE; |
252b5132 RH |
901 | if (final_seg == expr_section) |
902 | final_seg = absolute_section; | |
903 | resolved = 1; | |
904 | break; | |
905 | ||
906 | case O_symbol: | |
907 | case O_symbol_rva: | |
908 | left = resolve_symbol_value (add_symbol, finalize); | |
909 | do_symbol: | |
910 | ||
911 | if (symp->sy_mri_common) | |
912 | { | |
913 | /* This is a symbol inside an MRI common section. The | |
914 | relocation routines are going to handle it specially. | |
915 | Don't change the value. */ | |
49309057 | 916 | resolved = symbol_resolved_p (add_symbol); |
252b5132 RH |
917 | break; |
918 | } | |
919 | ||
920 | if (finalize && final_val == 0) | |
49309057 ILT |
921 | { |
922 | if (LOCAL_SYMBOL_CHECK (add_symbol)) | |
923 | add_symbol = local_symbol_convert ((struct local_symbol *) | |
924 | add_symbol); | |
925 | copy_symbol_attributes (symp, add_symbol); | |
926 | } | |
252b5132 RH |
927 | |
928 | /* If we have equated this symbol to an undefined symbol, we | |
929 | keep X_op set to O_symbol, and we don't change | |
930 | X_add_number. This permits the routine which writes out | |
931 | relocation to detect this case, and convert the | |
932 | relocation to be against the symbol to which this symbol | |
933 | is equated. */ | |
934 | if (! S_IS_DEFINED (add_symbol) || S_IS_COMMON (add_symbol)) | |
935 | { | |
936 | if (finalize) | |
937 | { | |
938 | S_SET_SEGMENT (symp, S_GET_SEGMENT (add_symbol)); | |
939 | symp->sy_value.X_op = O_symbol; | |
940 | symp->sy_value.X_add_symbol = add_symbol; | |
941 | symp->sy_value.X_add_number = final_val; | |
942 | } | |
943 | final_val = 0; | |
49309057 | 944 | resolved = symbol_resolved_p (add_symbol); |
252b5132 RH |
945 | goto exit_dont_set_value; |
946 | } | |
947 | else | |
948 | { | |
949 | final_val += symp->sy_frag->fr_address + left; | |
950 | if (final_seg == expr_section || final_seg == undefined_section) | |
951 | final_seg = S_GET_SEGMENT (add_symbol); | |
952 | } | |
953 | ||
49309057 | 954 | resolved = symbol_resolved_p (add_symbol); |
252b5132 RH |
955 | break; |
956 | ||
957 | case O_uminus: | |
958 | case O_bit_not: | |
959 | case O_logical_not: | |
960 | left = resolve_symbol_value (add_symbol, finalize); | |
961 | ||
962 | if (op == O_uminus) | |
963 | left = -left; | |
964 | else if (op == O_logical_not) | |
965 | left = !left; | |
966 | else | |
967 | left = ~left; | |
968 | ||
969 | final_val += left + symp->sy_frag->fr_address; | |
970 | if (final_seg == expr_section || final_seg == undefined_section) | |
971 | final_seg = absolute_section; | |
972 | ||
49309057 | 973 | resolved = symbol_resolved_p (add_symbol); |
252b5132 RH |
974 | break; |
975 | ||
976 | case O_multiply: | |
977 | case O_divide: | |
978 | case O_modulus: | |
979 | case O_left_shift: | |
980 | case O_right_shift: | |
981 | case O_bit_inclusive_or: | |
982 | case O_bit_or_not: | |
983 | case O_bit_exclusive_or: | |
984 | case O_bit_and: | |
985 | case O_add: | |
986 | case O_subtract: | |
987 | case O_eq: | |
988 | case O_ne: | |
989 | case O_lt: | |
990 | case O_le: | |
991 | case O_ge: | |
992 | case O_gt: | |
993 | case O_logical_and: | |
994 | case O_logical_or: | |
995 | left = resolve_symbol_value (add_symbol, finalize); | |
996 | right = resolve_symbol_value (op_symbol, finalize); | |
997 | seg_left = S_GET_SEGMENT (add_symbol); | |
998 | seg_right = S_GET_SEGMENT (op_symbol); | |
999 | ||
1000 | /* Simplify addition or subtraction of a constant by folding the | |
1001 | constant into X_add_number. */ | |
1002 | if (op == O_add || op == O_subtract) | |
1003 | { | |
1004 | if (seg_right == absolute_section) | |
1005 | { | |
1006 | if (op == O_add) | |
1007 | final_val += right; | |
1008 | else | |
1009 | final_val -= right; | |
1010 | op = O_symbol; | |
1011 | op_symbol = NULL; | |
1012 | goto do_symbol; | |
1013 | } | |
1014 | else if (seg_left == absolute_section && op == O_add) | |
1015 | { | |
1016 | op = O_symbol; | |
1017 | final_val += left; | |
1018 | add_symbol = op_symbol; | |
1019 | left = right; | |
1020 | op_symbol = NULL; | |
1021 | goto do_symbol; | |
1022 | } | |
1023 | } | |
1024 | ||
1025 | /* Subtraction is permitted if both operands are in the same | |
1026 | section. Otherwise, both operands must be absolute. We | |
1027 | already handled the case of addition or subtraction of a | |
1028 | constant above. This will probably need to be changed | |
1029 | for an object file format which supports arbitrary | |
1030 | expressions, such as IEEE-695. */ | |
1031 | /* Don't emit messages unless we're finalizing the symbol value, | |
1032 | otherwise we may get the same message multiple times. */ | |
9b4d630b ILT |
1033 | if ((seg_left != absolute_section |
1034 | || seg_right != absolute_section) | |
1035 | && (op != O_subtract | |
1036 | || seg_left != seg_right | |
1037 | || seg_left == undefined_section) | |
252b5132 RH |
1038 | && finalize) |
1039 | { | |
1040 | char *file; | |
1041 | unsigned int line; | |
1042 | ||
1043 | if (expr_symbol_where (symp, &file, &line)) | |
1044 | { | |
1045 | if (seg_left == undefined_section) | |
1046 | as_bad_where (file, line, | |
1047 | _("undefined symbol %s in operation"), | |
1048 | S_GET_NAME (symp->sy_value.X_add_symbol)); | |
1049 | if (seg_right == undefined_section) | |
1050 | as_bad_where (file, line, | |
1051 | _("undefined symbol %s in operation"), | |
1052 | S_GET_NAME (symp->sy_value.X_op_symbol)); | |
1053 | if (seg_left != undefined_section | |
1054 | && seg_right != undefined_section) | |
7c743825 KH |
1055 | as_bad_where (file, line, |
1056 | _("invalid section for operation")); | |
252b5132 RH |
1057 | } |
1058 | else | |
1059 | { | |
1060 | if (seg_left == undefined_section) | |
1061 | as_bad (_("undefined symbol %s in operation setting %s"), | |
1062 | S_GET_NAME (symp->sy_value.X_add_symbol), | |
1063 | S_GET_NAME (symp)); | |
1064 | if (seg_right == undefined_section) | |
1065 | as_bad (_("undefined symbol %s in operation setting %s"), | |
1066 | S_GET_NAME (symp->sy_value.X_op_symbol), | |
1067 | S_GET_NAME (symp)); | |
1068 | if (seg_left != undefined_section | |
1069 | && seg_right != undefined_section) | |
1070 | as_bad (_("invalid section for operation setting %s"), | |
1071 | S_GET_NAME (symp)); | |
1072 | } | |
1073 | } | |
1074 | ||
1075 | /* Check for division by zero. */ | |
1076 | if ((op == O_divide || op == O_modulus) && right == 0) | |
1077 | { | |
1078 | /* If seg_right is not absolute_section, then we've | |
1079 | already issued a warning about using a bad symbol. */ | |
1080 | if (seg_right == absolute_section && finalize) | |
1081 | { | |
1082 | char *file; | |
1083 | unsigned int line; | |
1084 | ||
1085 | if (expr_symbol_where (symp, &file, &line)) | |
1086 | as_bad_where (file, line, _("division by zero")); | |
1087 | else | |
1088 | as_bad (_("division by zero when setting %s"), | |
1089 | S_GET_NAME (symp)); | |
1090 | } | |
1091 | ||
1092 | right = 1; | |
1093 | } | |
1094 | ||
1095 | switch (symp->sy_value.X_op) | |
1096 | { | |
1097 | case O_multiply: left *= right; break; | |
1098 | case O_divide: left /= right; break; | |
1099 | case O_modulus: left %= right; break; | |
1100 | case O_left_shift: left <<= right; break; | |
1101 | case O_right_shift: left >>= right; break; | |
1102 | case O_bit_inclusive_or: left |= right; break; | |
1103 | case O_bit_or_not: left |= ~right; break; | |
1104 | case O_bit_exclusive_or: left ^= right; break; | |
1105 | case O_bit_and: left &= right; break; | |
1106 | case O_add: left += right; break; | |
1107 | case O_subtract: left -= right; break; | |
1108 | case O_eq: left = left == right ? ~ (offsetT) 0 : 0; break; | |
1109 | case O_ne: left = left != right ? ~ (offsetT) 0 : 0; break; | |
1110 | case O_lt: left = left < right ? ~ (offsetT) 0 : 0; break; | |
1111 | case O_le: left = left <= right ? ~ (offsetT) 0 : 0; break; | |
1112 | case O_ge: left = left >= right ? ~ (offsetT) 0 : 0; break; | |
1113 | case O_gt: left = left > right ? ~ (offsetT) 0 : 0; break; | |
1114 | case O_logical_and: left = left && right; break; | |
1115 | case O_logical_or: left = left || right; break; | |
1116 | default: abort (); | |
1117 | } | |
1118 | ||
1119 | final_val += symp->sy_frag->fr_address + left; | |
1120 | if (final_seg == expr_section || final_seg == undefined_section) | |
1121 | final_seg = absolute_section; | |
49309057 ILT |
1122 | resolved = (symbol_resolved_p (add_symbol) |
1123 | && symbol_resolved_p (op_symbol)); | |
7c743825 | 1124 | break; |
252b5132 RH |
1125 | |
1126 | case O_register: | |
1127 | case O_big: | |
1128 | case O_illegal: | |
1129 | /* Give an error (below) if not in expr_section. We don't | |
1130 | want to worry about expr_section symbols, because they | |
1131 | are fictional (they are created as part of expression | |
1132 | resolution), and any problems may not actually mean | |
1133 | anything. */ | |
1134 | break; | |
1135 | } | |
1136 | ||
1137 | symp->sy_resolving = 0; | |
1138 | } | |
1139 | ||
1140 | if (finalize) | |
1141 | { | |
1142 | S_SET_VALUE (symp, final_val); | |
1143 | ||
1144 | #if defined (OBJ_AOUT) && ! defined (BFD_ASSEMBLER) | |
1145 | /* The old a.out backend does not handle S_SET_SEGMENT correctly | |
1146 | for a stab symbol, so we use this bad hack. */ | |
1147 | if (final_seg != S_GET_SEGMENT (symp)) | |
1148 | #endif | |
1149 | S_SET_SEGMENT (symp, final_seg); | |
1150 | } | |
1151 | ||
1152 | exit_dont_set_value: | |
1153 | /* Don't worry if we can't resolve an expr_section symbol. */ | |
1154 | if (finalize) | |
1155 | { | |
1156 | if (resolved) | |
1157 | symp->sy_resolved = 1; | |
1158 | else if (S_GET_SEGMENT (symp) != expr_section) | |
1159 | { | |
7c743825 KH |
1160 | as_bad (_("can't resolve value for symbol \"%s\""), |
1161 | S_GET_NAME (symp)); | |
252b5132 RH |
1162 | symp->sy_resolved = 1; |
1163 | } | |
1164 | } | |
1165 | ||
1166 | return final_val; | |
1167 | } | |
1168 | ||
49309057 ILT |
1169 | #ifdef BFD_ASSEMBLER |
1170 | ||
1171 | static void resolve_local_symbol PARAMS ((const char *, PTR)); | |
1172 | ||
1173 | /* A static function passed to hash_traverse. */ | |
1174 | ||
1175 | static void | |
1176 | resolve_local_symbol (key, value) | |
ab9da554 | 1177 | const char *key ATTRIBUTE_UNUSED; |
49309057 ILT |
1178 | PTR value; |
1179 | { | |
1180 | if (value != NULL) | |
1181 | resolve_symbol_value (value, 1); | |
1182 | } | |
1183 | ||
1184 | #endif | |
1185 | ||
1186 | /* Resolve all local symbols. */ | |
1187 | ||
1188 | void | |
1189 | resolve_local_symbol_values () | |
1190 | { | |
1191 | #ifdef BFD_ASSEMBLER | |
1192 | hash_traverse (local_hash, resolve_local_symbol); | |
1193 | #endif | |
1194 | } | |
1195 | ||
252b5132 RH |
1196 | /* Dollar labels look like a number followed by a dollar sign. Eg, "42$". |
1197 | They are *really* local. That is, they go out of scope whenever we see a | |
1198 | label that isn't local. Also, like fb labels, there can be multiple | |
1199 | instances of a dollar label. Therefor, we name encode each instance with | |
1200 | the instance number, keep a list of defined symbols separate from the real | |
1201 | symbol table, and we treat these buggers as a sparse array. */ | |
1202 | ||
1203 | static long *dollar_labels; | |
1204 | static long *dollar_label_instances; | |
1205 | static char *dollar_label_defines; | |
1206 | static unsigned long dollar_label_count; | |
1207 | static unsigned long dollar_label_max; | |
1208 | ||
7c743825 | 1209 | int |
252b5132 RH |
1210 | dollar_label_defined (label) |
1211 | long label; | |
1212 | { | |
1213 | long *i; | |
1214 | ||
1215 | know ((dollar_labels != NULL) || (dollar_label_count == 0)); | |
1216 | ||
1217 | for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i) | |
1218 | if (*i == label) | |
1219 | return dollar_label_defines[i - dollar_labels]; | |
1220 | ||
7c743825 | 1221 | /* If we get here, label isn't defined. */ |
252b5132 | 1222 | return 0; |
7c743825 | 1223 | } |
252b5132 RH |
1224 | |
1225 | static long | |
1226 | dollar_label_instance (label) | |
1227 | long label; | |
1228 | { | |
1229 | long *i; | |
1230 | ||
1231 | know ((dollar_labels != NULL) || (dollar_label_count == 0)); | |
1232 | ||
1233 | for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i) | |
1234 | if (*i == label) | |
1235 | return (dollar_label_instances[i - dollar_labels]); | |
1236 | ||
7c743825 KH |
1237 | /* If we get here, we haven't seen the label before. |
1238 | Therefore its instance count is zero. */ | |
252b5132 RH |
1239 | return 0; |
1240 | } | |
1241 | ||
7c743825 | 1242 | void |
252b5132 RH |
1243 | dollar_label_clear () |
1244 | { | |
1245 | memset (dollar_label_defines, '\0', (unsigned int) dollar_label_count); | |
1246 | } | |
1247 | ||
1248 | #define DOLLAR_LABEL_BUMP_BY 10 | |
1249 | ||
7c743825 | 1250 | void |
252b5132 RH |
1251 | define_dollar_label (label) |
1252 | long label; | |
1253 | { | |
1254 | long *i; | |
1255 | ||
1256 | for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i) | |
1257 | if (*i == label) | |
1258 | { | |
1259 | ++dollar_label_instances[i - dollar_labels]; | |
1260 | dollar_label_defines[i - dollar_labels] = 1; | |
1261 | return; | |
1262 | } | |
1263 | ||
7c743825 | 1264 | /* If we get to here, we don't have label listed yet. */ |
252b5132 RH |
1265 | |
1266 | if (dollar_labels == NULL) | |
1267 | { | |
1268 | dollar_labels = (long *) xmalloc (DOLLAR_LABEL_BUMP_BY * sizeof (long)); | |
1269 | dollar_label_instances = (long *) xmalloc (DOLLAR_LABEL_BUMP_BY * sizeof (long)); | |
1270 | dollar_label_defines = xmalloc (DOLLAR_LABEL_BUMP_BY); | |
1271 | dollar_label_max = DOLLAR_LABEL_BUMP_BY; | |
1272 | dollar_label_count = 0; | |
1273 | } | |
1274 | else if (dollar_label_count == dollar_label_max) | |
1275 | { | |
1276 | dollar_label_max += DOLLAR_LABEL_BUMP_BY; | |
1277 | dollar_labels = (long *) xrealloc ((char *) dollar_labels, | |
1278 | dollar_label_max * sizeof (long)); | |
1279 | dollar_label_instances = (long *) xrealloc ((char *) dollar_label_instances, | |
1280 | dollar_label_max * sizeof (long)); | |
1281 | dollar_label_defines = xrealloc (dollar_label_defines, dollar_label_max); | |
7c743825 | 1282 | } /* if we needed to grow */ |
252b5132 RH |
1283 | |
1284 | dollar_labels[dollar_label_count] = label; | |
1285 | dollar_label_instances[dollar_label_count] = 1; | |
1286 | dollar_label_defines[dollar_label_count] = 1; | |
1287 | ++dollar_label_count; | |
1288 | } | |
1289 | ||
7c743825 KH |
1290 | /* Caller must copy returned name: we re-use the area for the next name. |
1291 | ||
1292 | The mth occurence of label n: is turned into the symbol "Ln^Am" | |
1293 | where n is the label number and m is the instance number. "L" makes | |
1294 | it a label discarded unless debugging and "^A"('\1') ensures no | |
1295 | ordinary symbol SHOULD get the same name as a local label | |
1296 | symbol. The first "4:" is "L4^A1" - the m numbers begin at 1. | |
1297 | ||
1298 | fb labels get the same treatment, except that ^B is used in place | |
1299 | of ^A. */ | |
1300 | ||
1301 | char * /* Return local label name. */ | |
252b5132 | 1302 | dollar_label_name (n, augend) |
7c743825 KH |
1303 | register long n; /* we just saw "n$:" : n a number. */ |
1304 | register int augend; /* 0 for current instance, 1 for new instance. */ | |
252b5132 RH |
1305 | { |
1306 | long i; | |
7c743825 | 1307 | /* Returned to caller, then copied. Used for created names ("4f"). */ |
252b5132 RH |
1308 | static char symbol_name_build[24]; |
1309 | register char *p; | |
1310 | register char *q; | |
7c743825 | 1311 | char symbol_name_temporary[20]; /* Build up a number, BACKWARDS. */ |
252b5132 RH |
1312 | |
1313 | know (n >= 0); | |
1314 | know (augend == 0 || augend == 1); | |
1315 | p = symbol_name_build; | |
f84dd1f0 NC |
1316 | #ifdef LOCAL_LABEL_PREFIX |
1317 | *p++ = LOCAL_LABEL_PREFIX; | |
1318 | #endif | |
252b5132 RH |
1319 | *p++ = 'L'; |
1320 | ||
7c743825 KH |
1321 | /* Next code just does sprintf( {}, "%d", n); */ |
1322 | /* Label number. */ | |
252b5132 RH |
1323 | q = symbol_name_temporary; |
1324 | for (*q++ = 0, i = n; i; ++q) | |
1325 | { | |
1326 | *q = i % 10 + '0'; | |
1327 | i /= 10; | |
1328 | } | |
1329 | while ((*p = *--q) != '\0') | |
1330 | ++p; | |
1331 | ||
7c743825 | 1332 | *p++ = 1; /* ^A */ |
252b5132 | 1333 | |
7c743825 | 1334 | /* Instance number. */ |
252b5132 RH |
1335 | q = symbol_name_temporary; |
1336 | for (*q++ = 0, i = dollar_label_instance (n) + augend; i; ++q) | |
1337 | { | |
1338 | *q = i % 10 + '0'; | |
1339 | i /= 10; | |
1340 | } | |
1341 | while ((*p++ = *--q) != '\0');; | |
1342 | ||
7c743825 | 1343 | /* The label, as a '\0' ended string, starts at symbol_name_build. */ |
252b5132 RH |
1344 | return symbol_name_build; |
1345 | } | |
1346 | ||
7c743825 KH |
1347 | /* Sombody else's idea of local labels. They are made by "n:" where n |
1348 | is any decimal digit. Refer to them with | |
1349 | "nb" for previous (backward) n: | |
1350 | or "nf" for next (forward) n:. | |
1351 | ||
1352 | We do a little better and let n be any number, not just a single digit, but | |
1353 | since the other guy's assembler only does ten, we treat the first ten | |
1354 | specially. | |
1355 | ||
1356 | Like someone else's assembler, we have one set of local label counters for | |
1357 | entire assembly, not one set per (sub)segment like in most assemblers. This | |
1358 | implies that one can refer to a label in another segment, and indeed some | |
1359 | crufty compilers have done just that. | |
1360 | ||
1361 | Since there could be a LOT of these things, treat them as a sparse | |
1362 | array. */ | |
252b5132 RH |
1363 | |
1364 | #define FB_LABEL_SPECIAL (10) | |
1365 | ||
1366 | static long fb_low_counter[FB_LABEL_SPECIAL]; | |
1367 | static long *fb_labels; | |
1368 | static long *fb_label_instances; | |
1369 | static long fb_label_count; | |
1370 | static long fb_label_max; | |
1371 | ||
7c743825 | 1372 | /* This must be more than FB_LABEL_SPECIAL. */ |
252b5132 RH |
1373 | #define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6) |
1374 | ||
7c743825 | 1375 | static void |
252b5132 RH |
1376 | fb_label_init () |
1377 | { | |
1378 | memset ((void *) fb_low_counter, '\0', sizeof (fb_low_counter)); | |
7c743825 | 1379 | } |
252b5132 | 1380 | |
7c743825 KH |
1381 | /* Add one to the instance number of this fb label. */ |
1382 | ||
1383 | void | |
252b5132 RH |
1384 | fb_label_instance_inc (label) |
1385 | long label; | |
1386 | { | |
1387 | long *i; | |
1388 | ||
1389 | if (label < FB_LABEL_SPECIAL) | |
1390 | { | |
1391 | ++fb_low_counter[label]; | |
1392 | return; | |
1393 | } | |
1394 | ||
1395 | if (fb_labels != NULL) | |
1396 | { | |
1397 | for (i = fb_labels + FB_LABEL_SPECIAL; | |
1398 | i < fb_labels + fb_label_count; ++i) | |
1399 | { | |
1400 | if (*i == label) | |
1401 | { | |
1402 | ++fb_label_instances[i - fb_labels]; | |
1403 | return; | |
7c743825 KH |
1404 | } /* if we find it */ |
1405 | } /* for each existing label */ | |
252b5132 RH |
1406 | } |
1407 | ||
7c743825 | 1408 | /* If we get to here, we don't have label listed yet. */ |
252b5132 RH |
1409 | |
1410 | if (fb_labels == NULL) | |
1411 | { | |
1412 | fb_labels = (long *) xmalloc (FB_LABEL_BUMP_BY * sizeof (long)); | |
1413 | fb_label_instances = (long *) xmalloc (FB_LABEL_BUMP_BY * sizeof (long)); | |
1414 | fb_label_max = FB_LABEL_BUMP_BY; | |
1415 | fb_label_count = FB_LABEL_SPECIAL; | |
1416 | ||
1417 | } | |
1418 | else if (fb_label_count == fb_label_max) | |
1419 | { | |
1420 | fb_label_max += FB_LABEL_BUMP_BY; | |
1421 | fb_labels = (long *) xrealloc ((char *) fb_labels, | |
1422 | fb_label_max * sizeof (long)); | |
1423 | fb_label_instances = (long *) xrealloc ((char *) fb_label_instances, | |
1424 | fb_label_max * sizeof (long)); | |
7c743825 | 1425 | } /* if we needed to grow */ |
252b5132 RH |
1426 | |
1427 | fb_labels[fb_label_count] = label; | |
1428 | fb_label_instances[fb_label_count] = 1; | |
1429 | ++fb_label_count; | |
1430 | } | |
1431 | ||
7c743825 | 1432 | static long |
252b5132 RH |
1433 | fb_label_instance (label) |
1434 | long label; | |
1435 | { | |
1436 | long *i; | |
1437 | ||
1438 | if (label < FB_LABEL_SPECIAL) | |
1439 | { | |
1440 | return (fb_low_counter[label]); | |
1441 | } | |
1442 | ||
1443 | if (fb_labels != NULL) | |
1444 | { | |
1445 | for (i = fb_labels + FB_LABEL_SPECIAL; | |
1446 | i < fb_labels + fb_label_count; ++i) | |
1447 | { | |
1448 | if (*i == label) | |
1449 | { | |
1450 | return (fb_label_instances[i - fb_labels]); | |
7c743825 KH |
1451 | } /* if we find it */ |
1452 | } /* for each existing label */ | |
252b5132 RH |
1453 | } |
1454 | ||
1455 | /* We didn't find the label, so this must be a reference to the | |
1456 | first instance. */ | |
1457 | return 0; | |
1458 | } | |
1459 | ||
7c743825 KH |
1460 | /* Caller must copy returned name: we re-use the area for the next name. |
1461 | ||
1462 | The mth occurence of label n: is turned into the symbol "Ln^Bm" | |
1463 | where n is the label number and m is the instance number. "L" makes | |
1464 | it a label discarded unless debugging and "^B"('\2') ensures no | |
1465 | ordinary symbol SHOULD get the same name as a local label | |
1466 | symbol. The first "4:" is "L4^B1" - the m numbers begin at 1. | |
1467 | ||
1468 | dollar labels get the same treatment, except that ^A is used in | |
1469 | place of ^B. */ | |
1470 | ||
1471 | char * /* Return local label name. */ | |
252b5132 | 1472 | fb_label_name (n, augend) |
7c743825 KH |
1473 | long n; /* We just saw "n:", "nf" or "nb" : n a number. */ |
1474 | long augend; /* 0 for nb, 1 for n:, nf. */ | |
252b5132 RH |
1475 | { |
1476 | long i; | |
7c743825 | 1477 | /* Returned to caller, then copied. Used for created names ("4f"). */ |
252b5132 RH |
1478 | static char symbol_name_build[24]; |
1479 | register char *p; | |
1480 | register char *q; | |
7c743825 | 1481 | char symbol_name_temporary[20]; /* Build up a number, BACKWARDS. */ |
252b5132 RH |
1482 | |
1483 | know (n >= 0); | |
1484 | know (augend == 0 || augend == 1); | |
1485 | p = symbol_name_build; | |
1486 | *p++ = 'L'; | |
1487 | ||
7c743825 KH |
1488 | /* Next code just does sprintf( {}, "%d", n); */ |
1489 | /* Label number. */ | |
252b5132 RH |
1490 | q = symbol_name_temporary; |
1491 | for (*q++ = 0, i = n; i; ++q) | |
1492 | { | |
1493 | *q = i % 10 + '0'; | |
1494 | i /= 10; | |
1495 | } | |
1496 | while ((*p = *--q) != '\0') | |
1497 | ++p; | |
1498 | ||
7c743825 | 1499 | *p++ = 2; /* ^B */ |
252b5132 | 1500 | |
7c743825 | 1501 | /* Instance number. */ |
252b5132 RH |
1502 | q = symbol_name_temporary; |
1503 | for (*q++ = 0, i = fb_label_instance (n) + augend; i; ++q) | |
1504 | { | |
1505 | *q = i % 10 + '0'; | |
1506 | i /= 10; | |
1507 | } | |
1508 | while ((*p++ = *--q) != '\0');; | |
1509 | ||
7c743825 | 1510 | /* The label, as a '\0' ended string, starts at symbol_name_build. */ |
252b5132 | 1511 | return (symbol_name_build); |
7c743825 | 1512 | } |
252b5132 | 1513 | |
7c743825 KH |
1514 | /* Decode name that may have been generated by foo_label_name() above. |
1515 | If the name wasn't generated by foo_label_name(), then return it | |
1516 | unaltered. This is used for error messages. */ | |
252b5132 RH |
1517 | |
1518 | char * | |
1519 | decode_local_label_name (s) | |
1520 | char *s; | |
1521 | { | |
1522 | char *p; | |
1523 | char *symbol_decode; | |
1524 | int label_number; | |
1525 | int instance_number; | |
1526 | char *type; | |
1527 | const char *message_format = _("\"%d\" (instance number %d of a %s label)"); | |
1528 | ||
1529 | if (s[0] != 'L') | |
1530 | return s; | |
1531 | ||
1532 | for (label_number = 0, p = s + 1; isdigit ((unsigned char) *p); ++p) | |
1533 | label_number = (10 * label_number) + *p - '0'; | |
1534 | ||
1535 | if (*p == 1) | |
1536 | type = "dollar"; | |
1537 | else if (*p == 2) | |
1538 | type = "fb"; | |
1539 | else | |
1540 | return s; | |
1541 | ||
1542 | for (instance_number = 0, p++; isdigit ((unsigned char) *p); ++p) | |
1543 | instance_number = (10 * instance_number) + *p - '0'; | |
1544 | ||
1545 | symbol_decode = obstack_alloc (¬es, strlen (message_format) + 30); | |
1546 | sprintf (symbol_decode, message_format, label_number, instance_number, type); | |
1547 | ||
1548 | return symbol_decode; | |
1549 | } | |
1550 | ||
1551 | /* Get the value of a symbol. */ | |
1552 | ||
1553 | valueT | |
1554 | S_GET_VALUE (s) | |
1555 | symbolS *s; | |
1556 | { | |
a1605869 | 1557 | #ifdef BFD_ASSEMBLER |
49309057 ILT |
1558 | if (LOCAL_SYMBOL_CHECK (s)) |
1559 | return ((struct local_symbol *) s)->lsy_offset; | |
a1605869 | 1560 | #endif |
49309057 | 1561 | |
252b5132 RH |
1562 | if (!s->sy_resolved && s->sy_value.X_op != O_constant) |
1563 | resolve_symbol_value (s, 1); | |
1564 | if (s->sy_value.X_op != O_constant) | |
1565 | { | |
1566 | static symbolS *recur; | |
1567 | ||
1568 | /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON | |
1569 | may call S_GET_VALUE. We use a static symbol to avoid the | |
1570 | immediate recursion. */ | |
1571 | if (recur == s) | |
1572 | return (valueT) s->sy_value.X_add_number; | |
1573 | recur = s; | |
1574 | if (! s->sy_resolved | |
1575 | || s->sy_value.X_op != O_symbol | |
1576 | || (S_IS_DEFINED (s) && ! S_IS_COMMON (s))) | |
1577 | as_bad (_("Attempt to get value of unresolved symbol %s"), | |
1578 | S_GET_NAME (s)); | |
1579 | recur = NULL; | |
1580 | } | |
1581 | return (valueT) s->sy_value.X_add_number; | |
1582 | } | |
1583 | ||
1584 | /* Set the value of a symbol. */ | |
1585 | ||
1586 | void | |
1587 | S_SET_VALUE (s, val) | |
1588 | symbolS *s; | |
1589 | valueT val; | |
1590 | { | |
a1605869 | 1591 | #ifdef BFD_ASSEMBLER |
49309057 ILT |
1592 | if (LOCAL_SYMBOL_CHECK (s)) |
1593 | { | |
1594 | ((struct local_symbol *) s)->lsy_offset = val; | |
1595 | return; | |
1596 | } | |
a1605869 | 1597 | #endif |
49309057 | 1598 | |
252b5132 RH |
1599 | s->sy_value.X_op = O_constant; |
1600 | s->sy_value.X_add_number = (offsetT) val; | |
1601 | s->sy_value.X_unsigned = 0; | |
1602 | } | |
1603 | ||
1604 | void | |
1605 | copy_symbol_attributes (dest, src) | |
1606 | symbolS *dest, *src; | |
1607 | { | |
49309057 | 1608 | if (LOCAL_SYMBOL_CHECK (dest)) |
7f2f689c | 1609 | dest = local_symbol_convert ((struct local_symbol *) dest); |
49309057 | 1610 | if (LOCAL_SYMBOL_CHECK (src)) |
7f2f689c | 1611 | src = local_symbol_convert ((struct local_symbol *) src); |
49309057 | 1612 | |
252b5132 RH |
1613 | #ifdef BFD_ASSEMBLER |
1614 | /* In an expression, transfer the settings of these flags. | |
1615 | The user can override later, of course. */ | |
1616 | #define COPIED_SYMFLAGS (BSF_FUNCTION | BSF_OBJECT) | |
1617 | dest->bsym->flags |= src->bsym->flags & COPIED_SYMFLAGS; | |
1618 | #endif | |
1619 | ||
1620 | #ifdef OBJ_COPY_SYMBOL_ATTRIBUTES | |
1621 | OBJ_COPY_SYMBOL_ATTRIBUTES (dest, src); | |
1622 | #endif | |
1623 | } | |
1624 | ||
1625 | #ifdef BFD_ASSEMBLER | |
1626 | ||
1627 | int | |
1628 | S_IS_FUNCTION (s) | |
1629 | symbolS *s; | |
1630 | { | |
49309057 ILT |
1631 | flagword flags; |
1632 | ||
1633 | if (LOCAL_SYMBOL_CHECK (s)) | |
1634 | return 0; | |
1635 | ||
1636 | flags = s->bsym->flags; | |
252b5132 RH |
1637 | |
1638 | return (flags & BSF_FUNCTION) != 0; | |
1639 | } | |
1640 | ||
1641 | int | |
1642 | S_IS_EXTERNAL (s) | |
1643 | symbolS *s; | |
1644 | { | |
49309057 ILT |
1645 | flagword flags; |
1646 | ||
1647 | if (LOCAL_SYMBOL_CHECK (s)) | |
1648 | return 0; | |
1649 | ||
1650 | flags = s->bsym->flags; | |
252b5132 | 1651 | |
7c743825 | 1652 | /* Sanity check. */ |
252b5132 RH |
1653 | if ((flags & BSF_LOCAL) && (flags & BSF_GLOBAL)) |
1654 | abort (); | |
1655 | ||
1656 | return (flags & BSF_GLOBAL) != 0; | |
1657 | } | |
1658 | ||
1659 | int | |
1660 | S_IS_WEAK (s) | |
1661 | symbolS *s; | |
1662 | { | |
49309057 ILT |
1663 | if (LOCAL_SYMBOL_CHECK (s)) |
1664 | return 0; | |
252b5132 RH |
1665 | return (s->bsym->flags & BSF_WEAK) != 0; |
1666 | } | |
1667 | ||
1668 | int | |
1669 | S_IS_COMMON (s) | |
1670 | symbolS *s; | |
1671 | { | |
49309057 ILT |
1672 | if (LOCAL_SYMBOL_CHECK (s)) |
1673 | return 0; | |
252b5132 RH |
1674 | return bfd_is_com_section (s->bsym->section); |
1675 | } | |
1676 | ||
1677 | int | |
1678 | S_IS_DEFINED (s) | |
1679 | symbolS *s; | |
1680 | { | |
49309057 ILT |
1681 | if (LOCAL_SYMBOL_CHECK (s)) |
1682 | return ((struct local_symbol *) s)->lsy_section != undefined_section; | |
252b5132 RH |
1683 | return s->bsym->section != undefined_section; |
1684 | } | |
1685 | ||
1686 | int | |
1687 | S_IS_DEBUG (s) | |
1688 | symbolS *s; | |
1689 | { | |
49309057 ILT |
1690 | if (LOCAL_SYMBOL_CHECK (s)) |
1691 | return 0; | |
252b5132 RH |
1692 | if (s->bsym->flags & BSF_DEBUGGING) |
1693 | return 1; | |
1694 | return 0; | |
1695 | } | |
1696 | ||
1697 | int | |
1698 | S_IS_LOCAL (s) | |
1699 | symbolS *s; | |
1700 | { | |
49309057 | 1701 | flagword flags; |
252b5132 RH |
1702 | const char *name; |
1703 | ||
49309057 ILT |
1704 | if (LOCAL_SYMBOL_CHECK (s)) |
1705 | return 1; | |
1706 | ||
1707 | flags = s->bsym->flags; | |
1708 | ||
7c743825 | 1709 | /* Sanity check. */ |
252b5132 RH |
1710 | if ((flags & BSF_LOCAL) && (flags & BSF_GLOBAL)) |
1711 | abort (); | |
1712 | ||
1713 | if (bfd_get_section (s->bsym) == reg_section) | |
1714 | return 1; | |
1715 | ||
1716 | if (flag_strip_local_absolute | |
1717 | && (flags & BSF_GLOBAL) == 0 | |
1718 | && bfd_get_section (s->bsym) == absolute_section) | |
1719 | return 1; | |
1720 | ||
1721 | name = S_GET_NAME (s); | |
1722 | return (name != NULL | |
1723 | && ! S_IS_DEBUG (s) | |
1724 | && (strchr (name, '\001') | |
1725 | || strchr (name, '\002') | |
1726 | || (! flag_keep_locals | |
1727 | && (bfd_is_local_label (stdoutput, s->bsym) | |
1728 | || (flag_mri | |
1729 | && name[0] == '?' | |
1730 | && name[1] == '?'))))); | |
1731 | } | |
1732 | ||
1733 | int | |
1734 | S_IS_EXTERN (s) | |
1735 | symbolS *s; | |
1736 | { | |
1737 | return S_IS_EXTERNAL (s); | |
1738 | } | |
1739 | ||
1740 | int | |
1741 | S_IS_STABD (s) | |
1742 | symbolS *s; | |
1743 | { | |
1744 | return S_GET_NAME (s) == 0; | |
1745 | } | |
1746 | ||
1747 | CONST char * | |
1748 | S_GET_NAME (s) | |
1749 | symbolS *s; | |
1750 | { | |
49309057 ILT |
1751 | if (LOCAL_SYMBOL_CHECK (s)) |
1752 | return ((struct local_symbol *) s)->lsy_name; | |
252b5132 RH |
1753 | return s->bsym->name; |
1754 | } | |
1755 | ||
1756 | segT | |
1757 | S_GET_SEGMENT (s) | |
1758 | symbolS *s; | |
1759 | { | |
49309057 ILT |
1760 | if (LOCAL_SYMBOL_CHECK (s)) |
1761 | return ((struct local_symbol *) s)->lsy_section; | |
252b5132 RH |
1762 | return s->bsym->section; |
1763 | } | |
1764 | ||
1765 | void | |
1766 | S_SET_SEGMENT (s, seg) | |
1767 | symbolS *s; | |
1768 | segT seg; | |
1769 | { | |
1770 | /* Don't reassign section symbols. The direct reason is to prevent seg | |
1771 | faults assigning back to const global symbols such as *ABS*, but it | |
1772 | shouldn't happen anyway. */ | |
1773 | ||
49309057 ILT |
1774 | if (LOCAL_SYMBOL_CHECK (s)) |
1775 | { | |
1776 | if (seg == reg_section) | |
1777 | s = local_symbol_convert ((struct local_symbol *) s); | |
1778 | else | |
1779 | { | |
1780 | ((struct local_symbol *) s)->lsy_section = seg; | |
1781 | return; | |
1782 | } | |
1783 | } | |
1784 | ||
252b5132 RH |
1785 | if (s->bsym->flags & BSF_SECTION_SYM) |
1786 | { | |
1787 | if (s->bsym->section != seg) | |
7c743825 | 1788 | abort (); |
252b5132 RH |
1789 | } |
1790 | else | |
1791 | s->bsym->section = seg; | |
1792 | } | |
1793 | ||
1794 | void | |
1795 | S_SET_EXTERNAL (s) | |
1796 | symbolS *s; | |
1797 | { | |
49309057 ILT |
1798 | if (LOCAL_SYMBOL_CHECK (s)) |
1799 | s = local_symbol_convert ((struct local_symbol *) s); | |
252b5132 RH |
1800 | if ((s->bsym->flags & BSF_WEAK) != 0) |
1801 | { | |
1802 | /* Let .weak override .global. */ | |
1803 | return; | |
1804 | } | |
1805 | s->bsym->flags |= BSF_GLOBAL; | |
7c743825 | 1806 | s->bsym->flags &= ~(BSF_LOCAL | BSF_WEAK); |
252b5132 RH |
1807 | } |
1808 | ||
1809 | void | |
1810 | S_CLEAR_EXTERNAL (s) | |
1811 | symbolS *s; | |
1812 | { | |
49309057 ILT |
1813 | if (LOCAL_SYMBOL_CHECK (s)) |
1814 | return; | |
252b5132 RH |
1815 | if ((s->bsym->flags & BSF_WEAK) != 0) |
1816 | { | |
1817 | /* Let .weak override. */ | |
1818 | return; | |
1819 | } | |
1820 | s->bsym->flags |= BSF_LOCAL; | |
7c743825 | 1821 | s->bsym->flags &= ~(BSF_GLOBAL | BSF_WEAK); |
252b5132 RH |
1822 | } |
1823 | ||
1824 | void | |
1825 | S_SET_WEAK (s) | |
1826 | symbolS *s; | |
1827 | { | |
49309057 ILT |
1828 | if (LOCAL_SYMBOL_CHECK (s)) |
1829 | s = local_symbol_convert ((struct local_symbol *) s); | |
252b5132 | 1830 | s->bsym->flags |= BSF_WEAK; |
7c743825 | 1831 | s->bsym->flags &= ~(BSF_GLOBAL | BSF_LOCAL); |
252b5132 RH |
1832 | } |
1833 | ||
1834 | void | |
1835 | S_SET_NAME (s, name) | |
1836 | symbolS *s; | |
1837 | char *name; | |
1838 | { | |
49309057 ILT |
1839 | if (LOCAL_SYMBOL_CHECK (s)) |
1840 | { | |
1841 | ((struct local_symbol *) s)->lsy_name = name; | |
1842 | return; | |
1843 | } | |
252b5132 RH |
1844 | s->bsym->name = name; |
1845 | } | |
1846 | #endif /* BFD_ASSEMBLER */ | |
1847 | ||
49309057 ILT |
1848 | #ifdef SYMBOLS_NEED_BACKPOINTERS |
1849 | ||
1850 | /* Return the previous symbol in a chain. */ | |
1851 | ||
1852 | symbolS * | |
1853 | symbol_previous (s) | |
1854 | symbolS *s; | |
1855 | { | |
1856 | if (LOCAL_SYMBOL_CHECK (s)) | |
1857 | abort (); | |
1858 | return s->sy_previous; | |
1859 | } | |
1860 | ||
1861 | #endif /* SYMBOLS_NEED_BACKPOINTERS */ | |
1862 | ||
1863 | /* Return the next symbol in a chain. */ | |
1864 | ||
1865 | symbolS * | |
1866 | symbol_next (s) | |
1867 | symbolS *s; | |
1868 | { | |
1869 | if (LOCAL_SYMBOL_CHECK (s)) | |
1870 | abort (); | |
1871 | return s->sy_next; | |
1872 | } | |
1873 | ||
1874 | /* Return a pointer to the value of a symbol as an expression. */ | |
1875 | ||
1876 | expressionS * | |
1877 | symbol_get_value_expression (s) | |
1878 | symbolS *s; | |
1879 | { | |
1880 | if (LOCAL_SYMBOL_CHECK (s)) | |
1881 | s = local_symbol_convert ((struct local_symbol *) s); | |
1882 | return &s->sy_value; | |
1883 | } | |
1884 | ||
1885 | /* Set the value of a symbol to an expression. */ | |
1886 | ||
1887 | void | |
1888 | symbol_set_value_expression (s, exp) | |
1889 | symbolS *s; | |
1890 | const expressionS *exp; | |
1891 | { | |
1892 | if (LOCAL_SYMBOL_CHECK (s)) | |
1893 | s = local_symbol_convert ((struct local_symbol *) s); | |
1894 | s->sy_value = *exp; | |
1895 | } | |
1896 | ||
1897 | /* Set the frag of a symbol. */ | |
1898 | ||
1899 | void | |
1900 | symbol_set_frag (s, f) | |
1901 | symbolS *s; | |
1902 | fragS *f; | |
1903 | { | |
a1605869 | 1904 | #ifdef BFD_ASSEMBLER |
49309057 ILT |
1905 | if (LOCAL_SYMBOL_CHECK (s)) |
1906 | { | |
1907 | local_symbol_set_frag ((struct local_symbol *) s, f); | |
1908 | return; | |
1909 | } | |
a1605869 | 1910 | #endif |
49309057 ILT |
1911 | s->sy_frag = f; |
1912 | } | |
1913 | ||
1914 | /* Return the frag of a symbol. */ | |
1915 | ||
1916 | fragS * | |
1917 | symbol_get_frag (s) | |
1918 | symbolS *s; | |
1919 | { | |
a1605869 | 1920 | #ifdef BFD_ASSEMBLER |
49309057 ILT |
1921 | if (LOCAL_SYMBOL_CHECK (s)) |
1922 | return local_symbol_get_frag ((struct local_symbol *) s); | |
a1605869 | 1923 | #endif |
49309057 ILT |
1924 | return s->sy_frag; |
1925 | } | |
1926 | ||
1927 | /* Mark a symbol as having been used. */ | |
1928 | ||
1929 | void | |
1930 | symbol_mark_used (s) | |
1931 | symbolS *s; | |
1932 | { | |
1933 | if (LOCAL_SYMBOL_CHECK (s)) | |
1934 | return; | |
1935 | s->sy_used = 1; | |
1936 | } | |
1937 | ||
1938 | /* Clear the mark of whether a symbol has been used. */ | |
1939 | ||
1940 | void | |
1941 | symbol_clear_used (s) | |
1942 | symbolS *s; | |
1943 | { | |
1944 | if (LOCAL_SYMBOL_CHECK (s)) | |
1945 | s = local_symbol_convert ((struct local_symbol *) s); | |
1946 | s->sy_used = 0; | |
1947 | } | |
1948 | ||
1949 | /* Return whether a symbol has been used. */ | |
1950 | ||
1951 | int | |
1952 | symbol_used_p (s) | |
1953 | symbolS *s; | |
1954 | { | |
1955 | if (LOCAL_SYMBOL_CHECK (s)) | |
1956 | return 1; | |
1957 | return s->sy_used; | |
1958 | } | |
1959 | ||
1960 | /* Mark a symbol as having been used in a reloc. */ | |
1961 | ||
1962 | void | |
1963 | symbol_mark_used_in_reloc (s) | |
1964 | symbolS *s; | |
1965 | { | |
1966 | if (LOCAL_SYMBOL_CHECK (s)) | |
1967 | s = local_symbol_convert ((struct local_symbol *) s); | |
1968 | s->sy_used_in_reloc = 1; | |
1969 | } | |
1970 | ||
1971 | /* Clear the mark of whether a symbol has been used in a reloc. */ | |
1972 | ||
1973 | void | |
1974 | symbol_clear_used_in_reloc (s) | |
1975 | symbolS *s; | |
1976 | { | |
1977 | if (LOCAL_SYMBOL_CHECK (s)) | |
1978 | return; | |
1979 | s->sy_used_in_reloc = 0; | |
1980 | } | |
1981 | ||
1982 | /* Return whether a symbol has been used in a reloc. */ | |
1983 | ||
1984 | int | |
1985 | symbol_used_in_reloc_p (s) | |
1986 | symbolS *s; | |
1987 | { | |
1988 | if (LOCAL_SYMBOL_CHECK (s)) | |
1989 | return 0; | |
1990 | return s->sy_used_in_reloc; | |
1991 | } | |
1992 | ||
1993 | /* Mark a symbol as an MRI common symbol. */ | |
1994 | ||
1995 | void | |
1996 | symbol_mark_mri_common (s) | |
1997 | symbolS *s; | |
1998 | { | |
1999 | if (LOCAL_SYMBOL_CHECK (s)) | |
2000 | s = local_symbol_convert ((struct local_symbol *) s); | |
2001 | s->sy_mri_common = 1; | |
2002 | } | |
2003 | ||
2004 | /* Clear the mark of whether a symbol is an MRI common symbol. */ | |
2005 | ||
2006 | void | |
2007 | symbol_clear_mri_common (s) | |
2008 | symbolS *s; | |
2009 | { | |
2010 | if (LOCAL_SYMBOL_CHECK (s)) | |
2011 | return; | |
2012 | s->sy_mri_common = 0; | |
2013 | } | |
2014 | ||
2015 | /* Return whether a symbol is an MRI common symbol. */ | |
2016 | ||
2017 | int | |
2018 | symbol_mri_common_p (s) | |
2019 | symbolS *s; | |
2020 | { | |
2021 | if (LOCAL_SYMBOL_CHECK (s)) | |
2022 | return 0; | |
2023 | return s->sy_mri_common; | |
2024 | } | |
2025 | ||
2026 | /* Mark a symbol as having been written. */ | |
2027 | ||
2028 | void | |
2029 | symbol_mark_written (s) | |
2030 | symbolS *s; | |
2031 | { | |
2032 | if (LOCAL_SYMBOL_CHECK (s)) | |
2033 | return; | |
2034 | s->written = 1; | |
2035 | } | |
2036 | ||
2037 | /* Clear the mark of whether a symbol has been written. */ | |
2038 | ||
2039 | void | |
2040 | symbol_clear_written (s) | |
2041 | symbolS *s; | |
2042 | { | |
2043 | if (LOCAL_SYMBOL_CHECK (s)) | |
2044 | return; | |
2045 | s->written = 0; | |
2046 | } | |
2047 | ||
2048 | /* Return whether a symbol has been written. */ | |
2049 | ||
2050 | int | |
2051 | symbol_written_p (s) | |
2052 | symbolS *s; | |
2053 | { | |
2054 | if (LOCAL_SYMBOL_CHECK (s)) | |
2055 | return 0; | |
2056 | return s->written; | |
2057 | } | |
2058 | ||
2059 | /* Mark a symbol has having been resolved. */ | |
2060 | ||
2061 | void | |
2062 | symbol_mark_resolved (s) | |
2063 | symbolS *s; | |
2064 | { | |
a1605869 | 2065 | #ifdef BFD_ASSEMBLER |
49309057 ILT |
2066 | if (LOCAL_SYMBOL_CHECK (s)) |
2067 | { | |
2068 | local_symbol_mark_resolved ((struct local_symbol *) s); | |
2069 | return; | |
2070 | } | |
a1605869 | 2071 | #endif |
49309057 ILT |
2072 | s->sy_resolved = 1; |
2073 | } | |
2074 | ||
2075 | /* Return whether a symbol has been resolved. */ | |
2076 | ||
2077 | int | |
2078 | symbol_resolved_p (s) | |
2079 | symbolS *s; | |
2080 | { | |
a1605869 | 2081 | #ifdef BFD_ASSEMBLER |
49309057 ILT |
2082 | if (LOCAL_SYMBOL_CHECK (s)) |
2083 | return local_symbol_resolved_p ((struct local_symbol *) s); | |
a1605869 | 2084 | #endif |
49309057 ILT |
2085 | return s->sy_resolved; |
2086 | } | |
2087 | ||
2088 | /* Return whether a symbol is a section symbol. */ | |
2089 | ||
2090 | int | |
2091 | symbol_section_p (s) | |
a04b544b | 2092 | symbolS *s ATTRIBUTE_UNUSED; |
49309057 ILT |
2093 | { |
2094 | if (LOCAL_SYMBOL_CHECK (s)) | |
2095 | return 0; | |
2096 | #ifdef BFD_ASSEMBLER | |
2097 | return (s->bsym->flags & BSF_SECTION_SYM) != 0; | |
2098 | #else | |
7c743825 | 2099 | /* FIXME. */ |
49309057 ILT |
2100 | return 0; |
2101 | #endif | |
2102 | } | |
2103 | ||
2104 | /* Return whether a symbol is equated to another symbol. */ | |
2105 | ||
2106 | int | |
2107 | symbol_equated_p (s) | |
2108 | symbolS *s; | |
2109 | { | |
2110 | if (LOCAL_SYMBOL_CHECK (s)) | |
2111 | return 0; | |
2112 | return s->sy_value.X_op == O_symbol; | |
2113 | } | |
2114 | ||
2115 | /* Return whether a symbol has a constant value. */ | |
2116 | ||
2117 | int | |
2118 | symbol_constant_p (s) | |
2119 | symbolS *s; | |
2120 | { | |
2121 | if (LOCAL_SYMBOL_CHECK (s)) | |
2122 | return 1; | |
2123 | return s->sy_value.X_op == O_constant; | |
2124 | } | |
2125 | ||
2126 | #ifdef BFD_ASSEMBLER | |
2127 | ||
2128 | /* Return the BFD symbol for a symbol. */ | |
2129 | ||
2130 | asymbol * | |
2131 | symbol_get_bfdsym (s) | |
2132 | symbolS *s; | |
2133 | { | |
2134 | if (LOCAL_SYMBOL_CHECK (s)) | |
2135 | s = local_symbol_convert ((struct local_symbol *) s); | |
2136 | return s->bsym; | |
2137 | } | |
2138 | ||
2139 | /* Set the BFD symbol for a symbol. */ | |
2140 | ||
2141 | void | |
2142 | symbol_set_bfdsym (s, bsym) | |
2143 | symbolS *s; | |
2144 | asymbol *bsym; | |
2145 | { | |
2146 | if (LOCAL_SYMBOL_CHECK (s)) | |
2147 | s = local_symbol_convert ((struct local_symbol *) s); | |
2148 | s->bsym = bsym; | |
2149 | } | |
2150 | ||
2151 | #endif /* BFD_ASSEMBLER */ | |
2152 | ||
2153 | #ifdef OBJ_SYMFIELD_TYPE | |
2154 | ||
2155 | /* Get a pointer to the object format information for a symbol. */ | |
2156 | ||
2157 | OBJ_SYMFIELD_TYPE * | |
2158 | symbol_get_obj (s) | |
2159 | symbolS *s; | |
2160 | { | |
2161 | if (LOCAL_SYMBOL_CHECK (s)) | |
2162 | s = local_symbol_convert ((struct local_symbol *) s); | |
2163 | return &s->sy_obj; | |
2164 | } | |
2165 | ||
2166 | /* Set the object format information for a symbol. */ | |
2167 | ||
2168 | void | |
2169 | symbol_set_obj (s, o) | |
2170 | symbolS *s; | |
2171 | OBJ_SYMFIELD_TYPE *o; | |
2172 | { | |
2173 | if (LOCAL_SYMBOL_CHECK (s)) | |
2174 | s = local_symbol_convert ((struct local_symbol *) s); | |
2175 | s->sy_obj = *o; | |
2176 | } | |
2177 | ||
2178 | #endif /* OBJ_SYMFIELD_TYPE */ | |
2179 | ||
2180 | #ifdef TC_SYMFIELD_TYPE | |
2181 | ||
2182 | /* Get a pointer to the processor information for a symbol. */ | |
2183 | ||
2184 | TC_SYMFIELD_TYPE * | |
2185 | symbol_get_tc (s) | |
2186 | symbolS *s; | |
2187 | { | |
2188 | if (LOCAL_SYMBOL_CHECK (s)) | |
2189 | s = local_symbol_convert ((struct local_symbol *) s); | |
2190 | return &s->sy_tc; | |
2191 | } | |
2192 | ||
2193 | /* Set the processor information for a symbol. */ | |
2194 | ||
2195 | void | |
bf27257e | 2196 | symbol_set_tc (s, o) |
49309057 ILT |
2197 | symbolS *s; |
2198 | TC_SYMFIELD_TYPE *o; | |
2199 | { | |
2200 | if (LOCAL_SYMBOL_CHECK (s)) | |
2201 | s = local_symbol_convert ((struct local_symbol *) s); | |
2202 | s->sy_tc = *o; | |
2203 | } | |
2204 | ||
2205 | #endif /* TC_SYMFIELD_TYPE */ | |
2206 | ||
252b5132 RH |
2207 | void |
2208 | symbol_begin () | |
2209 | { | |
2210 | symbol_lastP = NULL; | |
7c743825 | 2211 | symbol_rootP = NULL; /* In case we have 0 symbols (!!) */ |
252b5132 | 2212 | sy_hash = hash_new (); |
49309057 ILT |
2213 | #ifdef BFD_ASSEMBLER |
2214 | local_hash = hash_new (); | |
2215 | #endif | |
252b5132 RH |
2216 | |
2217 | memset ((char *) (&abs_symbol), '\0', sizeof (abs_symbol)); | |
2218 | #ifdef BFD_ASSEMBLER | |
2219 | #if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL) | |
2220 | abs_symbol.bsym = bfd_abs_section.symbol; | |
2221 | #endif | |
2222 | #else | |
7c743825 | 2223 | /* Can't initialise a union. Sigh. */ |
252b5132 RH |
2224 | S_SET_SEGMENT (&abs_symbol, absolute_section); |
2225 | #endif | |
2226 | abs_symbol.sy_value.X_op = O_constant; | |
2227 | abs_symbol.sy_frag = &zero_address_frag; | |
2228 | ||
2229 | if (LOCAL_LABELS_FB) | |
2230 | fb_label_init (); | |
2231 | } | |
252b5132 RH |
2232 | \f |
2233 | int indent_level; | |
2234 | ||
2235 | /* Maximum indent level. | |
2236 | Available for modification inside a gdb session. */ | |
2237 | int max_indent_level = 8; | |
2238 | ||
2239 | #if 0 | |
2240 | ||
2241 | static void | |
2242 | indent () | |
2243 | { | |
2244 | printf ("%*s", indent_level * 4, ""); | |
2245 | } | |
2246 | ||
2247 | #endif | |
2248 | ||
2249 | void | |
2250 | print_symbol_value_1 (file, sym) | |
2251 | FILE *file; | |
2252 | symbolS *sym; | |
2253 | { | |
2254 | const char *name = S_GET_NAME (sym); | |
2255 | if (!name || !name[0]) | |
2256 | name = "(unnamed)"; | |
2257 | fprintf (file, "sym %lx %s", (unsigned long) sym, name); | |
49309057 ILT |
2258 | |
2259 | if (LOCAL_SYMBOL_CHECK (sym)) | |
2260 | { | |
a1605869 | 2261 | #ifdef BFD_ASSEMBLER |
49309057 ILT |
2262 | struct local_symbol *locsym = (struct local_symbol *) sym; |
2263 | if (local_symbol_get_frag (locsym) != &zero_address_frag | |
2264 | && local_symbol_get_frag (locsym) != NULL) | |
2265 | fprintf (file, " frag %lx", (long) local_symbol_get_frag (locsym)); | |
2266 | if (local_symbol_resolved_p (locsym)) | |
2267 | fprintf (file, " resolved"); | |
2268 | fprintf (file, " local"); | |
a1605869 | 2269 | #endif |
49309057 ILT |
2270 | } |
2271 | else | |
2272 | { | |
2273 | if (sym->sy_frag != &zero_address_frag) | |
2274 | fprintf (file, " frag %lx", (long) sym->sy_frag); | |
2275 | if (sym->written) | |
2276 | fprintf (file, " written"); | |
2277 | if (sym->sy_resolved) | |
2278 | fprintf (file, " resolved"); | |
2279 | else if (sym->sy_resolving) | |
2280 | fprintf (file, " resolving"); | |
2281 | if (sym->sy_used_in_reloc) | |
2282 | fprintf (file, " used-in-reloc"); | |
2283 | if (sym->sy_used) | |
2284 | fprintf (file, " used"); | |
2285 | if (S_IS_LOCAL (sym)) | |
2286 | fprintf (file, " local"); | |
2287 | if (S_IS_EXTERN (sym)) | |
2288 | fprintf (file, " extern"); | |
2289 | if (S_IS_DEBUG (sym)) | |
2290 | fprintf (file, " debug"); | |
2291 | if (S_IS_DEFINED (sym)) | |
2292 | fprintf (file, " defined"); | |
2293 | } | |
252b5132 | 2294 | fprintf (file, " %s", segment_name (S_GET_SEGMENT (sym))); |
49309057 | 2295 | if (symbol_resolved_p (sym)) |
252b5132 RH |
2296 | { |
2297 | segT s = S_GET_SEGMENT (sym); | |
2298 | ||
2299 | if (s != undefined_section | |
2300 | && s != expr_section) | |
2301 | fprintf (file, " %lx", (long) S_GET_VALUE (sym)); | |
2302 | } | |
2303 | else if (indent_level < max_indent_level | |
2304 | && S_GET_SEGMENT (sym) != undefined_section) | |
2305 | { | |
2306 | indent_level++; | |
2307 | fprintf (file, "\n%*s<", indent_level * 4, ""); | |
a1605869 | 2308 | #ifdef BFD_ASSEMBLER |
49309057 ILT |
2309 | if (LOCAL_SYMBOL_CHECK (sym)) |
2310 | fprintf (file, "constant %lx", | |
2311 | (long) ((struct local_symbol *) sym)->lsy_offset); | |
2312 | else | |
a1605869 | 2313 | #endif |
49309057 | 2314 | print_expr_1 (file, &sym->sy_value); |
252b5132 RH |
2315 | fprintf (file, ">"); |
2316 | indent_level--; | |
2317 | } | |
2318 | fflush (file); | |
2319 | } | |
2320 | ||
2321 | void | |
2322 | print_symbol_value (sym) | |
2323 | symbolS *sym; | |
2324 | { | |
2325 | indent_level = 0; | |
2326 | print_symbol_value_1 (stderr, sym); | |
2327 | fprintf (stderr, "\n"); | |
2328 | } | |
2329 | ||
2330 | static void | |
2331 | print_binary (file, name, exp) | |
2332 | FILE *file; | |
7c743825 | 2333 | const char *name; |
252b5132 RH |
2334 | expressionS *exp; |
2335 | { | |
2336 | indent_level++; | |
2337 | fprintf (file, "%s\n%*s<", name, indent_level * 4, ""); | |
2338 | print_symbol_value_1 (file, exp->X_add_symbol); | |
2339 | fprintf (file, ">\n%*s<", indent_level * 4, ""); | |
2340 | print_symbol_value_1 (file, exp->X_op_symbol); | |
2341 | fprintf (file, ">"); | |
2342 | indent_level--; | |
2343 | } | |
2344 | ||
2345 | void | |
2346 | print_expr_1 (file, exp) | |
2347 | FILE *file; | |
2348 | expressionS *exp; | |
2349 | { | |
2350 | fprintf (file, "expr %lx ", (long) exp); | |
2351 | switch (exp->X_op) | |
2352 | { | |
2353 | case O_illegal: | |
2354 | fprintf (file, "illegal"); | |
2355 | break; | |
2356 | case O_absent: | |
2357 | fprintf (file, "absent"); | |
2358 | break; | |
2359 | case O_constant: | |
2360 | fprintf (file, "constant %lx", (long) exp->X_add_number); | |
2361 | break; | |
2362 | case O_symbol: | |
2363 | indent_level++; | |
2364 | fprintf (file, "symbol\n%*s<", indent_level * 4, ""); | |
2365 | print_symbol_value_1 (file, exp->X_add_symbol); | |
2366 | fprintf (file, ">"); | |
2367 | maybe_print_addnum: | |
2368 | if (exp->X_add_number) | |
2369 | fprintf (file, "\n%*s%lx", indent_level * 4, "", | |
2370 | (long) exp->X_add_number); | |
2371 | indent_level--; | |
2372 | break; | |
2373 | case O_register: | |
2374 | fprintf (file, "register #%d", (int) exp->X_add_number); | |
2375 | break; | |
2376 | case O_big: | |
2377 | fprintf (file, "big"); | |
2378 | break; | |
2379 | case O_uminus: | |
2380 | fprintf (file, "uminus -<"); | |
2381 | indent_level++; | |
2382 | print_symbol_value_1 (file, exp->X_add_symbol); | |
2383 | fprintf (file, ">"); | |
2384 | goto maybe_print_addnum; | |
2385 | case O_bit_not: | |
2386 | fprintf (file, "bit_not"); | |
2387 | break; | |
2388 | case O_multiply: | |
2389 | print_binary (file, "multiply", exp); | |
2390 | break; | |
2391 | case O_divide: | |
2392 | print_binary (file, "divide", exp); | |
2393 | break; | |
2394 | case O_modulus: | |
2395 | print_binary (file, "modulus", exp); | |
2396 | break; | |
2397 | case O_left_shift: | |
2398 | print_binary (file, "lshift", exp); | |
2399 | break; | |
2400 | case O_right_shift: | |
2401 | print_binary (file, "rshift", exp); | |
2402 | break; | |
2403 | case O_bit_inclusive_or: | |
2404 | print_binary (file, "bit_ior", exp); | |
2405 | break; | |
2406 | case O_bit_exclusive_or: | |
2407 | print_binary (file, "bit_xor", exp); | |
2408 | break; | |
2409 | case O_bit_and: | |
2410 | print_binary (file, "bit_and", exp); | |
2411 | break; | |
2412 | case O_eq: | |
2413 | print_binary (file, "eq", exp); | |
2414 | break; | |
2415 | case O_ne: | |
2416 | print_binary (file, "ne", exp); | |
2417 | break; | |
2418 | case O_lt: | |
2419 | print_binary (file, "lt", exp); | |
2420 | break; | |
2421 | case O_le: | |
2422 | print_binary (file, "le", exp); | |
2423 | break; | |
2424 | case O_ge: | |
2425 | print_binary (file, "ge", exp); | |
2426 | break; | |
2427 | case O_gt: | |
2428 | print_binary (file, "gt", exp); | |
2429 | break; | |
2430 | case O_logical_and: | |
2431 | print_binary (file, "logical_and", exp); | |
2432 | break; | |
2433 | case O_logical_or: | |
2434 | print_binary (file, "logical_or", exp); | |
2435 | break; | |
2436 | case O_add: | |
2437 | indent_level++; | |
2438 | fprintf (file, "add\n%*s<", indent_level * 4, ""); | |
2439 | print_symbol_value_1 (file, exp->X_add_symbol); | |
2440 | fprintf (file, ">\n%*s<", indent_level * 4, ""); | |
2441 | print_symbol_value_1 (file, exp->X_op_symbol); | |
2442 | fprintf (file, ">"); | |
2443 | goto maybe_print_addnum; | |
2444 | case O_subtract: | |
2445 | indent_level++; | |
2446 | fprintf (file, "subtract\n%*s<", indent_level * 4, ""); | |
2447 | print_symbol_value_1 (file, exp->X_add_symbol); | |
2448 | fprintf (file, ">\n%*s<", indent_level * 4, ""); | |
2449 | print_symbol_value_1 (file, exp->X_op_symbol); | |
2450 | fprintf (file, ">"); | |
2451 | goto maybe_print_addnum; | |
2452 | default: | |
2453 | fprintf (file, "{unknown opcode %d}", (int) exp->X_op); | |
2454 | break; | |
2455 | } | |
2456 | fflush (stdout); | |
2457 | } | |
2458 | ||
2459 | void | |
2460 | print_expr (exp) | |
2461 | expressionS *exp; | |
2462 | { | |
2463 | print_expr_1 (stderr, exp); | |
2464 | fprintf (stderr, "\n"); | |
2465 | } | |
2466 | ||
2467 | void | |
2468 | symbol_print_statistics (file) | |
2469 | FILE *file; | |
2470 | { | |
2471 | hash_print_statistics (file, "symbol table", sy_hash); | |
49309057 ILT |
2472 | #ifdef BFD_ASSEMBLER |
2473 | hash_print_statistics (file, "mini local symbol table", local_hash); | |
2474 | fprintf (file, "%lu mini local symbols created, %lu converted\n", | |
2475 | local_symbol_count, local_symbol_conversion_count); | |
2476 | #endif | |
252b5132 | 2477 | } |