symbols.c revision 33965
1/* symbols.c -symbol table- 2 Copyright (C) 1987, 90, 91, 92, 93, 94, 95, 96, 1997 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 22/* #define DEBUG_SYMS / * to debug symbol list maintenance */ 23 24#include <ctype.h> 25 26#include "as.h" 27 28#include "obstack.h" /* For "symbols.h" */ 29#include "subsegs.h" 30 31/* This is non-zero if symbols are case sensitive, which is the 32 default. */ 33int symbols_case_sensitive = 1; 34 35#ifndef WORKING_DOT_WORD 36extern int new_broken_words; 37#endif 38 39/* symbol-name => struct symbol pointer */ 40static struct hash_control *sy_hash; 41 42/* Below are commented in "symbols.h". */ 43symbolS *symbol_rootP; 44symbolS *symbol_lastP; 45symbolS abs_symbol; 46 47#ifdef DEBUG_SYMS 48#define debug_verify_symchain verify_symbol_chain 49#else 50#define debug_verify_symchain(root, last) ((void) 0) 51#endif 52 53struct obstack notes; 54 55static void fb_label_init PARAMS ((void)); 56static long dollar_label_instance PARAMS ((long)); 57static long fb_label_instance PARAMS ((long)); 58 59/* symbol_new() 60 61 Return a pointer to a new symbol. Die if we can't make a new 62 symbol. Fill in the symbol's values. Add symbol to end of symbol 63 chain. 64 65 This function should be called in the general case of creating a 66 symbol. However, if the output file symbol table has already been 67 set, and you are certain that this symbol won't be wanted in the 68 output file, you can call symbol_create. */ 69 70symbolS * 71symbol_new (name, segment, valu, frag) 72 const char *name; 73 segT segment; 74 valueT valu; 75 fragS *frag; 76{ 77 symbolS *symbolP = symbol_create (name, segment, valu, frag); 78 79 /* 80 * Link to end of symbol chain. 81 */ 82#ifdef BFD_ASSEMBLER 83 { 84 extern int symbol_table_frozen; 85 if (symbol_table_frozen) 86 abort (); 87 } 88#endif 89 symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP); 90 91 return symbolP; 92} 93 94symbolS * 95symbol_create (name, segment, valu, frag) 96 const char *name; /* It is copied, the caller can destroy/modify */ 97 segT segment; /* Segment identifier (SEG_<something>) */ 98 valueT valu; /* Symbol value */ 99 fragS *frag; /* Associated fragment */ 100{ 101 unsigned int name_length; 102 char *preserved_copy_of_name; 103 symbolS *symbolP; 104 105 name_length = strlen (name) + 1; /* +1 for \0 */ 106 obstack_grow (¬es, name, name_length); 107 preserved_copy_of_name = obstack_finish (¬es); 108#ifdef STRIP_UNDERSCORE 109 if (preserved_copy_of_name[0] == '_') 110 preserved_copy_of_name++; 111#endif 112 113#ifdef tc_canonicalize_symbol_name 114 preserved_copy_of_name = 115 tc_canonicalize_symbol_name (preserved_copy_of_name); 116#endif 117 118 if (! symbols_case_sensitive) 119 { 120 unsigned char *s; 121 122 for (s = (unsigned char *) preserved_copy_of_name; *s != '\0'; s++) 123 if (islower (*s)) 124 *s = toupper (*s); 125 } 126 127 symbolP = (symbolS *) obstack_alloc (¬es, sizeof (symbolS)); 128 129 /* symbol must be born in some fixed state. This seems as good as any. */ 130 memset (symbolP, 0, sizeof (symbolS)); 131 132#ifdef BFD_ASSEMBLER 133 symbolP->bsym = bfd_make_empty_symbol (stdoutput); 134 if (symbolP->bsym == NULL) 135 as_perror ("%s", "bfd_make_empty_symbol"); 136 symbolP->bsym->udata.p = (PTR) symbolP; 137#endif 138 S_SET_NAME (symbolP, preserved_copy_of_name); 139 140 S_SET_SEGMENT (symbolP, segment); 141 S_SET_VALUE (symbolP, valu); 142 symbol_clear_list_pointers (symbolP); 143 144 symbolP->sy_frag = frag; 145#ifndef BFD_ASSEMBLER 146 symbolP->sy_number = ~0; 147 symbolP->sy_name_offset = (unsigned int) ~0; 148#endif 149 150 obj_symbol_new_hook (symbolP); 151 152#ifdef tc_symbol_new_hook 153 tc_symbol_new_hook (symbolP); 154#endif 155 156 return symbolP; 157} 158 159 160/* 161 * colon() 162 * 163 * We have just seen "<name>:". 164 * Creates a struct symbol unless it already exists. 165 * 166 * Gripes if we are redefining a symbol incompatibly (and ignores it). 167 * 168 */ 169symbolS * 170colon (sym_name) /* just seen "x:" - rattle symbols & frags */ 171 const char *sym_name; /* symbol name, as a cannonical string */ 172 /* We copy this string: OK to alter later. */ 173{ 174 register symbolS *symbolP; /* symbol we are working with */ 175 176 /* Sun local labels go out of scope whenever a non-local symbol is 177 defined. */ 178 if (LOCAL_LABELS_DOLLAR) 179 { 180 int local; 181 182#ifdef BFD_ASSEMBLER 183 local = bfd_is_local_label_name (stdoutput, sym_name); 184#else 185 local = LOCAL_LABEL (sym_name); 186#endif 187 188 if (! local) 189 dollar_label_clear (); 190 } 191 192#ifndef WORKING_DOT_WORD 193 if (new_broken_words) 194 { 195 struct broken_word *a; 196 int possible_bytes; 197 fragS *frag_tmp; 198 char *frag_opcode; 199 200 extern const int md_short_jump_size; 201 extern const int md_long_jump_size; 202 possible_bytes = (md_short_jump_size 203 + new_broken_words * md_long_jump_size); 204 205 frag_tmp = frag_now; 206 frag_opcode = frag_var (rs_broken_word, 207 possible_bytes, 208 possible_bytes, 209 (relax_substateT) 0, 210 (symbolS *) broken_words, 211 (offsetT) 0, 212 NULL); 213 214 /* We want to store the pointer to where to insert the jump table in the 215 fr_opcode of the rs_broken_word frag. This requires a little 216 hackery. */ 217 while (frag_tmp 218 && (frag_tmp->fr_type != rs_broken_word 219 || frag_tmp->fr_opcode)) 220 frag_tmp = frag_tmp->fr_next; 221 know (frag_tmp); 222 frag_tmp->fr_opcode = frag_opcode; 223 new_broken_words = 0; 224 225 for (a = broken_words; a && a->dispfrag == 0; a = a->next_broken_word) 226 a->dispfrag = frag_tmp; 227 } 228#endif /* WORKING_DOT_WORD */ 229 230 if ((symbolP = symbol_find (sym_name)) != 0) 231 { 232#ifdef RESOLVE_SYMBOL_REDEFINITION 233 if (RESOLVE_SYMBOL_REDEFINITION (symbolP)) 234 return symbolP; 235#endif 236 /* 237 * Now check for undefined symbols 238 */ 239 if (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP)) 240 { 241 if (S_GET_VALUE (symbolP) == 0) 242 { 243 symbolP->sy_frag = frag_now; 244#ifdef OBJ_VMS 245 S_SET_OTHER(symbolP, const_flag); 246#endif 247 S_SET_VALUE (symbolP, (valueT) frag_now_fix ()); 248 S_SET_SEGMENT (symbolP, now_seg); 249#ifdef N_UNDF 250 know (N_UNDF == 0); 251#endif /* if we have one, it better be zero. */ 252 253 } 254 else 255 { 256 /* 257 * There are still several cases to check: 258 * A .comm/.lcomm symbol being redefined as 259 * initialized data is OK 260 * A .comm/.lcomm symbol being redefined with 261 * a larger size is also OK 262 * 263 * This only used to be allowed on VMS gas, but Sun cc 264 * on the sparc also depends on it. 265 */ 266 267 if (((!S_IS_DEBUG (symbolP) 268 && (!S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP)) 269 && S_IS_EXTERNAL (symbolP)) 270 || S_GET_SEGMENT (symbolP) == bss_section) 271 && (now_seg == data_section 272 || now_seg == S_GET_SEGMENT (symbolP))) 273 { 274 /* 275 * Select which of the 2 cases this is 276 */ 277 if (now_seg != data_section) 278 { 279 /* 280 * New .comm for prev .comm symbol. 281 * If the new size is larger we just 282 * change its value. If the new size 283 * is smaller, we ignore this symbol 284 */ 285 if (S_GET_VALUE (symbolP) 286 < ((unsigned) frag_now_fix ())) 287 { 288 S_SET_VALUE (symbolP, (valueT) frag_now_fix ()); 289 } 290 } 291 else 292 { 293 /* It is a .comm/.lcomm being converted to initialized 294 data. */ 295 symbolP->sy_frag = frag_now; 296#ifdef OBJ_VMS 297 S_SET_OTHER(symbolP, const_flag); 298#endif 299 S_SET_VALUE (symbolP, (valueT) frag_now_fix ()); 300 S_SET_SEGMENT (symbolP, now_seg); /* keep N_EXT bit */ 301 } 302 } 303 else 304 { 305#if defined (S_GET_OTHER) && defined (S_GET_DESC) 306 as_fatal ("Symbol \"%s\" is already defined as \"%s\"/%d.%d.%ld.", 307 sym_name, 308 segment_name (S_GET_SEGMENT (symbolP)), 309 S_GET_OTHER (symbolP), S_GET_DESC (symbolP), 310 (long) S_GET_VALUE (symbolP)); 311#else 312 as_fatal ("Symbol \"%s\" is already defined as \"%s\"/%ld.", 313 sym_name, 314 segment_name (S_GET_SEGMENT (symbolP)), 315 (long) S_GET_VALUE (symbolP)); 316#endif 317 } 318 } /* if the undefined symbol has no value */ 319 } 320 else 321 { 322 /* Don't blow up if the definition is the same */ 323 if (!(frag_now == symbolP->sy_frag 324 && S_GET_VALUE (symbolP) == frag_now_fix () 325 && S_GET_SEGMENT (symbolP) == now_seg)) 326 as_fatal ("Symbol %s already defined.", sym_name); 327 } /* if this symbol is not yet defined */ 328 329 } 330 else 331 { 332 symbolP = symbol_new (sym_name, now_seg, (valueT) frag_now_fix (), 333 frag_now); 334#ifdef OBJ_VMS 335 S_SET_OTHER (symbolP, const_flag); 336#endif /* OBJ_VMS */ 337 338 symbol_table_insert (symbolP); 339 } /* if we have seen this symbol before */ 340 341 if (mri_common_symbol != NULL) 342 { 343 /* This symbol is actually being defined within an MRI common 344 section. This requires special handling. */ 345 symbolP->sy_value.X_op = O_symbol; 346 symbolP->sy_value.X_add_symbol = mri_common_symbol; 347 symbolP->sy_value.X_add_number = S_GET_VALUE (mri_common_symbol); 348 symbolP->sy_frag = &zero_address_frag; 349 S_SET_SEGMENT (symbolP, expr_section); 350 symbolP->sy_mri_common = 1; 351 } 352 353#ifdef tc_frob_label 354 tc_frob_label (symbolP); 355#endif 356#ifdef obj_frob_label 357 obj_frob_label (symbolP); 358#endif 359 360 return symbolP; 361} 362 363 364/* 365 * symbol_table_insert() 366 * 367 * Die if we can't insert the symbol. 368 * 369 */ 370 371void 372symbol_table_insert (symbolP) 373 symbolS *symbolP; 374{ 375 register const char *error_string; 376 377 know (symbolP); 378 know (S_GET_NAME (symbolP)); 379 380 if ((error_string = hash_jam (sy_hash, S_GET_NAME (symbolP), (PTR) symbolP))) 381 { 382 as_fatal ("Inserting \"%s\" into symbol table failed: %s", 383 S_GET_NAME (symbolP), error_string); 384 } /* on error */ 385} /* symbol_table_insert() */ 386 387/* 388 * symbol_find_or_make() 389 * 390 * If a symbol name does not exist, create it as undefined, and insert 391 * it into the symbol table. Return a pointer to it. 392 */ 393symbolS * 394symbol_find_or_make (name) 395 const char *name; 396{ 397 register symbolS *symbolP; 398 399 symbolP = symbol_find (name); 400 401 if (symbolP == NULL) 402 { 403 symbolP = symbol_make (name); 404 405 symbol_table_insert (symbolP); 406 } /* if symbol wasn't found */ 407 408 return (symbolP); 409} /* symbol_find_or_make() */ 410 411symbolS * 412symbol_make (name) 413 CONST char *name; 414{ 415 symbolS *symbolP; 416 417 /* Let the machine description default it, e.g. for register names. */ 418 symbolP = md_undefined_symbol ((char *) name); 419 420 if (!symbolP) 421 symbolP = symbol_new (name, undefined_section, (valueT) 0, &zero_address_frag); 422 423 return (symbolP); 424} /* symbol_make() */ 425 426/* 427 * symbol_find() 428 * 429 * Implement symbol table lookup. 430 * In: A symbol's name as a string: '\0' can't be part of a symbol name. 431 * Out: NULL if the name was not in the symbol table, else the address 432 * of a struct symbol associated with that name. 433 */ 434 435symbolS * 436symbol_find (name) 437 CONST char *name; 438{ 439#ifdef STRIP_UNDERSCORE 440 return (symbol_find_base (name, 1)); 441#else /* STRIP_UNDERSCORE */ 442 return (symbol_find_base (name, 0)); 443#endif /* STRIP_UNDERSCORE */ 444} /* symbol_find() */ 445 446symbolS * 447symbol_find_base (name, strip_underscore) 448 CONST char *name; 449 int strip_underscore; 450{ 451 if (strip_underscore && *name == '_') 452 name++; 453 454#ifdef tc_canonicalize_symbol_name 455 { 456 char *copy; 457 458 copy = (char *) alloca (strlen (name) + 1); 459 strcpy (copy, name); 460 name = tc_canonicalize_symbol_name (copy); 461 } 462#endif 463 464 if (! symbols_case_sensitive) 465 { 466 unsigned char *copy; 467 468 copy = (unsigned char *) alloca (strlen (name) + 1); 469 name = (const char *) copy; 470 for (; *copy != '\0'; copy++) 471 if (islower (*copy)) 472 *copy = toupper (*copy); 473 } 474 475 return ((symbolS *) hash_find (sy_hash, name)); 476} 477 478/* 479 * Once upon a time, symbols were kept in a singly linked list. At 480 * least coff needs to be able to rearrange them from time to time, for 481 * which a doubly linked list is much more convenient. Loic did these 482 * as macros which seemed dangerous to me so they're now functions. 483 * xoxorich. 484 */ 485 486/* Link symbol ADDME after symbol TARGET in the chain. */ 487void 488symbol_append (addme, target, rootPP, lastPP) 489 symbolS *addme; 490 symbolS *target; 491 symbolS **rootPP; 492 symbolS **lastPP; 493{ 494 if (target == NULL) 495 { 496 know (*rootPP == NULL); 497 know (*lastPP == NULL); 498 addme->sy_next = NULL; 499#ifdef SYMBOLS_NEED_BACKPOINTERS 500 addme->sy_previous = NULL; 501#endif 502 *rootPP = addme; 503 *lastPP = addme; 504 return; 505 } /* if the list is empty */ 506 507 if (target->sy_next != NULL) 508 { 509#ifdef SYMBOLS_NEED_BACKPOINTERS 510 target->sy_next->sy_previous = addme; 511#endif /* SYMBOLS_NEED_BACKPOINTERS */ 512 } 513 else 514 { 515 know (*lastPP == target); 516 *lastPP = addme; 517 } /* if we have a next */ 518 519 addme->sy_next = target->sy_next; 520 target->sy_next = addme; 521 522#ifdef SYMBOLS_NEED_BACKPOINTERS 523 addme->sy_previous = target; 524#endif /* SYMBOLS_NEED_BACKPOINTERS */ 525 526 debug_verify_symchain (symbol_rootP, symbol_lastP); 527} 528 529/* Set the chain pointers of SYMBOL to null. */ 530void 531symbol_clear_list_pointers (symbolP) 532 symbolS *symbolP; 533{ 534 symbolP->sy_next = NULL; 535#ifdef SYMBOLS_NEED_BACKPOINTERS 536 symbolP->sy_previous = NULL; 537#endif 538} 539 540#ifdef SYMBOLS_NEED_BACKPOINTERS 541/* Remove SYMBOLP from the list. */ 542void 543symbol_remove (symbolP, rootPP, lastPP) 544 symbolS *symbolP; 545 symbolS **rootPP; 546 symbolS **lastPP; 547{ 548 if (symbolP == *rootPP) 549 { 550 *rootPP = symbolP->sy_next; 551 } /* if it was the root */ 552 553 if (symbolP == *lastPP) 554 { 555 *lastPP = symbolP->sy_previous; 556 } /* if it was the tail */ 557 558 if (symbolP->sy_next != NULL) 559 { 560 symbolP->sy_next->sy_previous = symbolP->sy_previous; 561 } /* if not last */ 562 563 if (symbolP->sy_previous != NULL) 564 { 565 symbolP->sy_previous->sy_next = symbolP->sy_next; 566 } /* if not first */ 567 568 debug_verify_symchain (*rootPP, *lastPP); 569} 570 571/* Link symbol ADDME before symbol TARGET in the chain. */ 572void 573symbol_insert (addme, target, rootPP, lastPP) 574 symbolS *addme; 575 symbolS *target; 576 symbolS **rootPP; 577 symbolS **lastPP; 578{ 579 if (target->sy_previous != NULL) 580 { 581 target->sy_previous->sy_next = addme; 582 } 583 else 584 { 585 know (*rootPP == target); 586 *rootPP = addme; 587 } /* if not first */ 588 589 addme->sy_previous = target->sy_previous; 590 target->sy_previous = addme; 591 addme->sy_next = target; 592 593 debug_verify_symchain (*rootPP, *lastPP); 594} 595 596#endif /* SYMBOLS_NEED_BACKPOINTERS */ 597 598void 599verify_symbol_chain (rootP, lastP) 600 symbolS *rootP; 601 symbolS *lastP; 602{ 603 symbolS *symbolP = rootP; 604 605 if (symbolP == NULL) 606 return; 607 608 for (; symbol_next (symbolP) != NULL; symbolP = symbol_next (symbolP)) 609 { 610#ifdef SYMBOLS_NEED_BACKPOINTERS 611 assert (symbolP->sy_next->sy_previous == symbolP); 612#else 613 /* Walk the list anyways, to make sure pointers are still good. */ 614 ; 615#endif /* SYMBOLS_NEED_BACKPOINTERS */ 616 } 617 618 assert (lastP == symbolP); 619} 620 621void 622verify_symbol_chain_2 (sym) 623 symbolS *sym; 624{ 625 symbolS *p = sym, *n = sym; 626#ifdef SYMBOLS_NEED_BACKPOINTERS 627 while (symbol_previous (p)) 628 p = symbol_previous (p); 629#endif 630 while (symbol_next (n)) 631 n = symbol_next (n); 632 verify_symbol_chain (p, n); 633} 634 635/* Resolve the value of a symbol. This is called during the final 636 pass over the symbol table to resolve any symbols with complex 637 values. */ 638 639void 640resolve_symbol_value (symp) 641 symbolS *symp; 642{ 643 int resolved; 644 645 if (symp->sy_resolved) 646 return; 647 648 resolved = 0; 649 650 if (symp->sy_resolving) 651 { 652 as_bad ("Symbol definition loop encountered at %s", 653 S_GET_NAME (symp)); 654 S_SET_VALUE (symp, (valueT) 0); 655 resolved = 1; 656 } 657 else 658 { 659 offsetT left, right, val; 660 segT seg_left, seg_right; 661 662 symp->sy_resolving = 1; 663 664 /* Simplify addition or subtraction of a constant by folding the 665 constant into X_add_number. */ 666 if (symp->sy_value.X_op == O_add 667 || symp->sy_value.X_op == O_subtract) 668 { 669 resolve_symbol_value (symp->sy_value.X_add_symbol); 670 resolve_symbol_value (symp->sy_value.X_op_symbol); 671 if (S_GET_SEGMENT (symp->sy_value.X_op_symbol) == absolute_section) 672 { 673 right = S_GET_VALUE (symp->sy_value.X_op_symbol); 674 if (symp->sy_value.X_op == O_add) 675 symp->sy_value.X_add_number += right; 676 else 677 symp->sy_value.X_add_number -= right; 678 symp->sy_value.X_op = O_symbol; 679 symp->sy_value.X_op_symbol = NULL; 680 } 681 else if ((S_GET_SEGMENT (symp->sy_value.X_add_symbol) 682 == absolute_section) 683 && symp->sy_value.X_op == O_add) 684 { 685 left = S_GET_VALUE (symp->sy_value.X_add_symbol); 686 symp->sy_value.X_add_symbol = symp->sy_value.X_op_symbol; 687 symp->sy_value.X_add_number += left; 688 symp->sy_value.X_op = O_symbol; 689 symp->sy_value.X_op_symbol = NULL; 690 } 691 } 692 693 switch (symp->sy_value.X_op) 694 { 695 case O_absent: 696 S_SET_VALUE (symp, 0); 697 /* Fall through. */ 698 case O_constant: 699 S_SET_VALUE (symp, S_GET_VALUE (symp) + symp->sy_frag->fr_address); 700 if (S_GET_SEGMENT (symp) == expr_section) 701 S_SET_SEGMENT (symp, absolute_section); 702 resolved = 1; 703 break; 704 705 case O_symbol: 706 resolve_symbol_value (symp->sy_value.X_add_symbol); 707 708 if (symp->sy_mri_common) 709 { 710 /* This is a symbol inside an MRI common section. The 711 relocation routines are going to handle it specially. 712 Don't change the value. */ 713 S_SET_VALUE (symp, symp->sy_value.X_add_number); 714 resolved = symp->sy_value.X_add_symbol->sy_resolved; 715 break; 716 } 717 718 if (symp->sy_value.X_add_number == 0) 719 copy_symbol_attributes (symp, symp->sy_value.X_add_symbol); 720 721 /* If we have equated this symbol to an undefined symbol, we 722 keep X_op set to O_symbol, and we don't change 723 X_add_number. This permits the routine which writes out 724 relocation to detect this case, and convert the 725 relocation to be against the symbol to which this symbol 726 is equated. */ 727 if (! S_IS_DEFINED (symp->sy_value.X_add_symbol) 728 || S_IS_COMMON (symp->sy_value.X_add_symbol)) 729 { 730 symp->sy_value.X_op = O_symbol; 731 S_SET_SEGMENT (symp, 732 S_GET_SEGMENT (symp->sy_value.X_add_symbol)); 733 } 734 else 735 { 736 S_SET_VALUE (symp, 737 (symp->sy_value.X_add_number 738 + symp->sy_frag->fr_address 739 + S_GET_VALUE (symp->sy_value.X_add_symbol))); 740 if (S_GET_SEGMENT (symp) == expr_section 741 || S_GET_SEGMENT (symp) == undefined_section) 742 S_SET_SEGMENT (symp, 743 S_GET_SEGMENT (symp->sy_value.X_add_symbol)); 744 } 745 746 resolved = symp->sy_value.X_add_symbol->sy_resolved; 747 break; 748 749 case O_uminus: 750 case O_bit_not: 751 case O_logical_not: 752 resolve_symbol_value (symp->sy_value.X_add_symbol); 753 if (symp->sy_value.X_op == O_uminus) 754 val = - S_GET_VALUE (symp->sy_value.X_add_symbol); 755 else if (symp->sy_value.X_op == O_logical_not) 756 val = ! S_GET_VALUE (symp->sy_value.X_add_symbol); 757 else 758 val = ~ S_GET_VALUE (symp->sy_value.X_add_symbol); 759 S_SET_VALUE (symp, 760 (val 761 + symp->sy_value.X_add_number 762 + symp->sy_frag->fr_address)); 763 if (S_GET_SEGMENT (symp) == expr_section 764 || S_GET_SEGMENT (symp) == undefined_section) 765 S_SET_SEGMENT (symp, absolute_section); 766 resolved = symp->sy_value.X_add_symbol->sy_resolved; 767 break; 768 769 case O_multiply: 770 case O_divide: 771 case O_modulus: 772 case O_left_shift: 773 case O_right_shift: 774 case O_bit_inclusive_or: 775 case O_bit_or_not: 776 case O_bit_exclusive_or: 777 case O_bit_and: 778 case O_add: 779 case O_subtract: 780 case O_eq: 781 case O_ne: 782 case O_lt: 783 case O_le: 784 case O_ge: 785 case O_gt: 786 case O_logical_and: 787 case O_logical_or: 788 resolve_symbol_value (symp->sy_value.X_add_symbol); 789 resolve_symbol_value (symp->sy_value.X_op_symbol); 790 seg_left = S_GET_SEGMENT (symp->sy_value.X_add_symbol); 791 seg_right = S_GET_SEGMENT (symp->sy_value.X_op_symbol); 792 left = S_GET_VALUE (symp->sy_value.X_add_symbol); 793 right = S_GET_VALUE (symp->sy_value.X_op_symbol); 794 795 /* Subtraction is permitted if both operands are in the same 796 section. Otherwise, both operands must be absolute. We 797 already handled the case of addition or subtraction of a 798 constant above. This will probably need to be changed 799 for an object file format which supports arbitrary 800 expressions, such as IEEE-695. */ 801 if ((seg_left != absolute_section 802 || seg_right != absolute_section) 803 && (symp->sy_value.X_op != O_subtract 804 || seg_left != seg_right)) 805 { 806 char *file; 807 unsigned int line; 808 809 if (expr_symbol_where (symp, &file, &line)) 810 { 811 if (seg_left == undefined_section) 812 as_bad_where (file, line, 813 "undefined symbol %s in operation", 814 S_GET_NAME (symp->sy_value.X_add_symbol)); 815 if (seg_right == undefined_section) 816 as_bad_where (file, line, 817 "undefined symbol %s in operation", 818 S_GET_NAME (symp->sy_value.X_op_symbol)); 819 if (seg_left != undefined_section 820 && seg_right != undefined_section) 821 as_bad_where (file, line, "invalid section for operation"); 822 } 823 else 824 { 825 if (seg_left == undefined_section) 826 as_bad ("undefined symbol %s in operation setting %s", 827 S_GET_NAME (symp->sy_value.X_add_symbol), 828 S_GET_NAME (symp)); 829 if (seg_right == undefined_section) 830 as_bad ("undefined symbol %s in operation setting %s", 831 S_GET_NAME (symp->sy_value.X_op_symbol), 832 S_GET_NAME (symp)); 833 if (seg_left != undefined_section 834 && seg_right != undefined_section) 835 as_bad ("invalid section for operation setting %s", 836 S_GET_NAME (symp)); 837 } 838 } 839 840 switch (symp->sy_value.X_op) 841 { 842 case O_multiply: val = left * right; break; 843 case O_divide: val = left / right; break; 844 case O_modulus: val = left % right; break; 845 case O_left_shift: val = left << right; break; 846 case O_right_shift: val = left >> right; break; 847 case O_bit_inclusive_or: val = left | right; break; 848 case O_bit_or_not: val = left |~ right; break; 849 case O_bit_exclusive_or: val = left ^ right; break; 850 case O_bit_and: val = left & right; break; 851 case O_add: val = left + right; break; 852 case O_subtract: val = left - right; break; 853 case O_eq: val = left == right ? ~ (offsetT) 0 : 0; 854 case O_ne: val = left != right ? ~ (offsetT) 0 : 0; 855 case O_lt: val = left < right ? ~ (offsetT) 0 : 0; 856 case O_le: val = left <= right ? ~ (offsetT) 0 : 0; 857 case O_ge: val = left >= right ? ~ (offsetT) 0 : 0; 858 case O_gt: val = left > right ? ~ (offsetT) 0 : 0; 859 case O_logical_and: val = left && right; break; 860 case O_logical_or: val = left || right; break; 861 default: abort (); 862 } 863 S_SET_VALUE (symp, 864 (symp->sy_value.X_add_number 865 + symp->sy_frag->fr_address 866 + val)); 867 if (S_GET_SEGMENT (symp) == expr_section 868 || S_GET_SEGMENT (symp) == undefined_section) 869 S_SET_SEGMENT (symp, absolute_section); 870 resolved = (symp->sy_value.X_add_symbol->sy_resolved 871 && symp->sy_value.X_op_symbol->sy_resolved); 872 break; 873 874 case O_register: 875 case O_big: 876 case O_illegal: 877 /* Give an error (below) if not in expr_section. We don't 878 want to worry about expr_section symbols, because they 879 are fictional (they are created as part of expression 880 resolution), and any problems may not actually mean 881 anything. */ 882 break; 883 } 884 } 885 886 /* Don't worry if we can't resolve an expr_section symbol. */ 887 if (resolved) 888 symp->sy_resolved = 1; 889 else if (S_GET_SEGMENT (symp) != expr_section) 890 { 891 as_bad ("can't resolve value for symbol \"%s\"", S_GET_NAME (symp)); 892 symp->sy_resolved = 1; 893 } 894} 895 896/* Dollar labels look like a number followed by a dollar sign. Eg, "42$". 897 They are *really* local. That is, they go out of scope whenever we see a 898 label that isn't local. Also, like fb labels, there can be multiple 899 instances of a dollar label. Therefor, we name encode each instance with 900 the instance number, keep a list of defined symbols separate from the real 901 symbol table, and we treat these buggers as a sparse array. */ 902 903static long *dollar_labels; 904static long *dollar_label_instances; 905static char *dollar_label_defines; 906static long dollar_label_count; 907static unsigned long dollar_label_max; 908 909int 910dollar_label_defined (label) 911 long label; 912{ 913 long *i; 914 915 know ((dollar_labels != NULL) || (dollar_label_count == 0)); 916 917 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i) 918 if (*i == label) 919 return dollar_label_defines[i - dollar_labels]; 920 921 /* if we get here, label isn't defined */ 922 return 0; 923} /* dollar_label_defined() */ 924 925static long 926dollar_label_instance (label) 927 long label; 928{ 929 long *i; 930 931 know ((dollar_labels != NULL) || (dollar_label_count == 0)); 932 933 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i) 934 if (*i == label) 935 return (dollar_label_instances[i - dollar_labels]); 936 937 /* If we get here, we haven't seen the label before, therefore its instance 938 count is zero. */ 939 return 0; 940} 941 942void 943dollar_label_clear () 944{ 945 memset (dollar_label_defines, '\0', (unsigned int) dollar_label_count); 946} 947 948#define DOLLAR_LABEL_BUMP_BY 10 949 950void 951define_dollar_label (label) 952 long label; 953{ 954 long *i; 955 956 for (i = dollar_labels; i < dollar_labels + dollar_label_count; ++i) 957 if (*i == label) 958 { 959 ++dollar_label_instances[i - dollar_labels]; 960 dollar_label_defines[i - dollar_labels] = 1; 961 return; 962 } 963 964 /* if we get to here, we don't have label listed yet. */ 965 966 if (dollar_labels == NULL) 967 { 968 dollar_labels = (long *) xmalloc (DOLLAR_LABEL_BUMP_BY * sizeof (long)); 969 dollar_label_instances = (long *) xmalloc (DOLLAR_LABEL_BUMP_BY * sizeof (long)); 970 dollar_label_defines = xmalloc (DOLLAR_LABEL_BUMP_BY); 971 dollar_label_max = DOLLAR_LABEL_BUMP_BY; 972 dollar_label_count = 0; 973 } 974 else if (dollar_label_count == dollar_label_max) 975 { 976 dollar_label_max += DOLLAR_LABEL_BUMP_BY; 977 dollar_labels = (long *) xrealloc ((char *) dollar_labels, 978 dollar_label_max * sizeof (long)); 979 dollar_label_instances = (long *) xrealloc ((char *) dollar_label_instances, 980 dollar_label_max * sizeof (long)); 981 dollar_label_defines = xrealloc (dollar_label_defines, dollar_label_max); 982 } /* if we needed to grow */ 983 984 dollar_labels[dollar_label_count] = label; 985 dollar_label_instances[dollar_label_count] = 1; 986 dollar_label_defines[dollar_label_count] = 1; 987 ++dollar_label_count; 988} 989 990/* 991 * dollar_label_name() 992 * 993 * Caller must copy returned name: we re-use the area for the next name. 994 * 995 * The mth occurence of label n: is turned into the symbol "Ln^Am" 996 * where n is the label number and m is the instance number. "L" makes 997 * it a label discarded unless debugging and "^A"('\1') ensures no 998 * ordinary symbol SHOULD get the same name as a local label 999 * symbol. The first "4:" is "L4^A1" - the m numbers begin at 1. 1000 * 1001 * fb labels get the same treatment, except that ^B is used in place of ^A. 1002 */ 1003 1004char * /* Return local label name. */ 1005dollar_label_name (n, augend) 1006 register long n; /* we just saw "n$:" : n a number */ 1007 register int augend; /* 0 for current instance, 1 for new instance */ 1008{ 1009 long i; 1010 /* Returned to caller, then copied. used for created names ("4f") */ 1011 static char symbol_name_build[24]; 1012 register char *p; 1013 register char *q; 1014 char symbol_name_temporary[20]; /* build up a number, BACKWARDS */ 1015 1016 know (n >= 0); 1017 know (augend == 0 || augend == 1); 1018 p = symbol_name_build; 1019 *p++ = 'L'; 1020 1021 /* Next code just does sprintf( {}, "%d", n); */ 1022 /* label number */ 1023 q = symbol_name_temporary; 1024 for (*q++ = 0, i = n; i; ++q) 1025 { 1026 *q = i % 10 + '0'; 1027 i /= 10; 1028 } 1029 while ((*p = *--q) != '\0') 1030 ++p; 1031 1032 *p++ = 1; /* ^A */ 1033 1034 /* instance number */ 1035 q = symbol_name_temporary; 1036 for (*q++ = 0, i = dollar_label_instance (n) + augend; i; ++q) 1037 { 1038 *q = i % 10 + '0'; 1039 i /= 10; 1040 } 1041 while ((*p++ = *--q) != '\0');; 1042 1043 /* The label, as a '\0' ended string, starts at symbol_name_build. */ 1044 return symbol_name_build; 1045} 1046 1047/* 1048 * Sombody else's idea of local labels. They are made by "n:" where n 1049 * is any decimal digit. Refer to them with 1050 * "nb" for previous (backward) n: 1051 * or "nf" for next (forward) n:. 1052 * 1053 * We do a little better and let n be any number, not just a single digit, but 1054 * since the other guy's assembler only does ten, we treat the first ten 1055 * specially. 1056 * 1057 * Like someone else's assembler, we have one set of local label counters for 1058 * entire assembly, not one set per (sub)segment like in most assemblers. This 1059 * implies that one can refer to a label in another segment, and indeed some 1060 * crufty compilers have done just that. 1061 * 1062 * Since there could be a LOT of these things, treat them as a sparse array. 1063 */ 1064 1065#define FB_LABEL_SPECIAL (10) 1066 1067static long fb_low_counter[FB_LABEL_SPECIAL]; 1068static long *fb_labels; 1069static long *fb_label_instances; 1070static long fb_label_count; 1071static long fb_label_max; 1072 1073/* this must be more than FB_LABEL_SPECIAL */ 1074#define FB_LABEL_BUMP_BY (FB_LABEL_SPECIAL + 6) 1075 1076static void 1077fb_label_init () 1078{ 1079 memset ((void *) fb_low_counter, '\0', sizeof (fb_low_counter)); 1080} /* fb_label_init() */ 1081 1082/* add one to the instance number of this fb label */ 1083void 1084fb_label_instance_inc (label) 1085 long label; 1086{ 1087 long *i; 1088 1089 if (label < FB_LABEL_SPECIAL) 1090 { 1091 ++fb_low_counter[label]; 1092 return; 1093 } 1094 1095 if (fb_labels != NULL) 1096 { 1097 for (i = fb_labels + FB_LABEL_SPECIAL; 1098 i < fb_labels + fb_label_count; ++i) 1099 { 1100 if (*i == label) 1101 { 1102 ++fb_label_instances[i - fb_labels]; 1103 return; 1104 } /* if we find it */ 1105 } /* for each existing label */ 1106 } 1107 1108 /* if we get to here, we don't have label listed yet. */ 1109 1110 if (fb_labels == NULL) 1111 { 1112 fb_labels = (long *) xmalloc (FB_LABEL_BUMP_BY * sizeof (long)); 1113 fb_label_instances = (long *) xmalloc (FB_LABEL_BUMP_BY * sizeof (long)); 1114 fb_label_max = FB_LABEL_BUMP_BY; 1115 fb_label_count = FB_LABEL_SPECIAL; 1116 1117 } 1118 else if (fb_label_count == fb_label_max) 1119 { 1120 fb_label_max += FB_LABEL_BUMP_BY; 1121 fb_labels = (long *) xrealloc ((char *) fb_labels, 1122 fb_label_max * sizeof (long)); 1123 fb_label_instances = (long *) xrealloc ((char *) fb_label_instances, 1124 fb_label_max * sizeof (long)); 1125 } /* if we needed to grow */ 1126 1127 fb_labels[fb_label_count] = label; 1128 fb_label_instances[fb_label_count] = 1; 1129 ++fb_label_count; 1130} 1131 1132static long 1133fb_label_instance (label) 1134 long label; 1135{ 1136 long *i; 1137 1138 if (label < FB_LABEL_SPECIAL) 1139 { 1140 return (fb_low_counter[label]); 1141 } 1142 1143 if (fb_labels != NULL) 1144 { 1145 for (i = fb_labels + FB_LABEL_SPECIAL; 1146 i < fb_labels + fb_label_count; ++i) 1147 { 1148 if (*i == label) 1149 { 1150 return (fb_label_instances[i - fb_labels]); 1151 } /* if we find it */ 1152 } /* for each existing label */ 1153 } 1154 1155 /* We didn't find the label, so this must be a reference to the 1156 first instance. */ 1157 return 0; 1158} 1159 1160/* 1161 * fb_label_name() 1162 * 1163 * Caller must copy returned name: we re-use the area for the next name. 1164 * 1165 * The mth occurence of label n: is turned into the symbol "Ln^Bm" 1166 * where n is the label number and m is the instance number. "L" makes 1167 * it a label discarded unless debugging and "^B"('\2') ensures no 1168 * ordinary symbol SHOULD get the same name as a local label 1169 * symbol. The first "4:" is "L4^B1" - the m numbers begin at 1. 1170 * 1171 * dollar labels get the same treatment, except that ^A is used in place of ^B. */ 1172 1173char * /* Return local label name. */ 1174fb_label_name (n, augend) 1175 long n; /* we just saw "n:", "nf" or "nb" : n a number */ 1176 long augend; /* 0 for nb, 1 for n:, nf */ 1177{ 1178 long i; 1179 /* Returned to caller, then copied. used for created names ("4f") */ 1180 static char symbol_name_build[24]; 1181 register char *p; 1182 register char *q; 1183 char symbol_name_temporary[20]; /* build up a number, BACKWARDS */ 1184 1185 know (n >= 0); 1186 know (augend == 0 || augend == 1); 1187 p = symbol_name_build; 1188 *p++ = 'L'; 1189 1190 /* Next code just does sprintf( {}, "%d", n); */ 1191 /* label number */ 1192 q = symbol_name_temporary; 1193 for (*q++ = 0, i = n; i; ++q) 1194 { 1195 *q = i % 10 + '0'; 1196 i /= 10; 1197 } 1198 while ((*p = *--q) != '\0') 1199 ++p; 1200 1201 *p++ = 2; /* ^B */ 1202 1203 /* instance number */ 1204 q = symbol_name_temporary; 1205 for (*q++ = 0, i = fb_label_instance (n) + augend; i; ++q) 1206 { 1207 *q = i % 10 + '0'; 1208 i /= 10; 1209 } 1210 while ((*p++ = *--q) != '\0');; 1211 1212 /* The label, as a '\0' ended string, starts at symbol_name_build. */ 1213 return (symbol_name_build); 1214} /* fb_label_name() */ 1215 1216/* 1217 * decode name that may have been generated by foo_label_name() above. If 1218 * the name wasn't generated by foo_label_name(), then return it unaltered. 1219 * This is used for error messages. 1220 */ 1221 1222char * 1223decode_local_label_name (s) 1224 char *s; 1225{ 1226 char *p; 1227 char *symbol_decode; 1228 int label_number; 1229 int instance_number; 1230 char *type; 1231 const char *message_format = "\"%d\" (instance number %d of a %s label)"; 1232 1233 if (s[0] != 'L') 1234 return s; 1235 1236 for (label_number = 0, p = s + 1; isdigit (*p); ++p) 1237 label_number = (10 * label_number) + *p - '0'; 1238 1239 if (*p == 1) 1240 type = "dollar"; 1241 else if (*p == 2) 1242 type = "fb"; 1243 else 1244 return s; 1245 1246 for (instance_number = 0, p++; isdigit (*p); ++p) 1247 instance_number = (10 * instance_number) + *p - '0'; 1248 1249 symbol_decode = obstack_alloc (¬es, strlen (message_format) + 30); 1250 sprintf (symbol_decode, message_format, label_number, instance_number, type); 1251 1252 return symbol_decode; 1253} 1254 1255/* Get the value of a symbol. */ 1256 1257valueT 1258S_GET_VALUE (s) 1259 symbolS *s; 1260{ 1261 if (!s->sy_resolved && !s->sy_resolving && s->sy_value.X_op != O_constant) 1262 resolve_symbol_value (s); 1263 if (s->sy_value.X_op != O_constant) 1264 { 1265 static symbolS *recur; 1266 1267 /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON 1268 may call S_GET_VALUE. We use a static symbol to avoid the 1269 immediate recursion. */ 1270 if (recur == s) 1271 return (valueT) s->sy_value.X_add_number; 1272 recur = s; 1273 if (! s->sy_resolved 1274 || s->sy_value.X_op != O_symbol 1275 || (S_IS_DEFINED (s) && ! S_IS_COMMON (s))) 1276 as_bad ("Attempt to get value of unresolved symbol %s", 1277 S_GET_NAME (s)); 1278 recur = NULL; 1279 } 1280 return (valueT) s->sy_value.X_add_number; 1281} 1282 1283/* Set the value of a symbol. */ 1284 1285void 1286S_SET_VALUE (s, val) 1287 symbolS *s; 1288 valueT val; 1289{ 1290 s->sy_value.X_op = O_constant; 1291 s->sy_value.X_add_number = (offsetT) val; 1292 s->sy_value.X_unsigned = 0; 1293} 1294 1295void 1296copy_symbol_attributes (dest, src) 1297 symbolS *dest, *src; 1298{ 1299#ifdef BFD_ASSEMBLER 1300 /* In an expression, transfer the settings of these flags. 1301 The user can override later, of course. */ 1302#define COPIED_SYMFLAGS (BSF_FUNCTION) 1303 dest->bsym->flags |= src->bsym->flags & COPIED_SYMFLAGS; 1304#endif 1305 1306#ifdef OBJ_COPY_SYMBOL_ATTRIBUTES 1307 OBJ_COPY_SYMBOL_ATTRIBUTES (dest, src); 1308#endif 1309} 1310 1311#ifdef BFD_ASSEMBLER 1312 1313int 1314S_IS_EXTERNAL (s) 1315 symbolS *s; 1316{ 1317 flagword flags = s->bsym->flags; 1318 1319 /* sanity check */ 1320 if (flags & BSF_LOCAL && flags & BSF_GLOBAL) 1321 abort (); 1322 1323 return (flags & BSF_GLOBAL) != 0; 1324} 1325 1326int 1327S_IS_WEAK (s) 1328 symbolS *s; 1329{ 1330 return (s->bsym->flags & BSF_WEAK) != 0; 1331} 1332 1333int 1334S_IS_COMMON (s) 1335 symbolS *s; 1336{ 1337 return bfd_is_com_section (s->bsym->section); 1338} 1339 1340int 1341S_IS_DEFINED (s) 1342 symbolS *s; 1343{ 1344 return s->bsym->section != undefined_section; 1345} 1346 1347int 1348S_IS_DEBUG (s) 1349 symbolS *s; 1350{ 1351 if (s->bsym->flags & BSF_DEBUGGING) 1352 return 1; 1353 return 0; 1354} 1355 1356int 1357S_IS_LOCAL (s) 1358 symbolS *s; 1359{ 1360 flagword flags = s->bsym->flags; 1361 const char *name; 1362 1363 /* sanity check */ 1364 if (flags & BSF_LOCAL && flags & BSF_GLOBAL) 1365 abort (); 1366 1367 if (bfd_get_section (s->bsym) == reg_section) 1368 return 1; 1369 1370 name = S_GET_NAME (s); 1371 return (name != NULL 1372 && ! S_IS_DEBUG (s) 1373 && (strchr (name, '\001') 1374 || strchr (name, '\002') 1375 || (! flag_keep_locals 1376 && (bfd_is_local_label (stdoutput, s->bsym) 1377 || (flag_mri 1378 && name[0] == '?' 1379 && name[1] == '?'))))); 1380} 1381 1382int 1383S_IS_EXTERN (s) 1384 symbolS *s; 1385{ 1386 return S_IS_EXTERNAL (s); 1387} 1388 1389int 1390S_IS_STABD (s) 1391 symbolS *s; 1392{ 1393 return S_GET_NAME (s) == 0; 1394} 1395 1396CONST char * 1397S_GET_NAME (s) 1398 symbolS *s; 1399{ 1400 return s->bsym->name; 1401} 1402 1403segT 1404S_GET_SEGMENT (s) 1405 symbolS *s; 1406{ 1407 return s->bsym->section; 1408} 1409 1410void 1411S_SET_SEGMENT (s, seg) 1412 symbolS *s; 1413 segT seg; 1414{ 1415 s->bsym->section = seg; 1416} 1417 1418void 1419S_SET_EXTERNAL (s) 1420 symbolS *s; 1421{ 1422 if ((s->bsym->flags & BSF_WEAK) != 0) 1423 { 1424 /* Let .weak override .global. */ 1425 return; 1426 } 1427 s->bsym->flags |= BSF_GLOBAL; 1428 s->bsym->flags &= ~(BSF_LOCAL|BSF_WEAK); 1429} 1430 1431void 1432S_CLEAR_EXTERNAL (s) 1433 symbolS *s; 1434{ 1435 if ((s->bsym->flags & BSF_WEAK) != 0) 1436 { 1437 /* Let .weak override. */ 1438 return; 1439 } 1440 s->bsym->flags |= BSF_LOCAL; 1441 s->bsym->flags &= ~(BSF_GLOBAL|BSF_WEAK); 1442} 1443 1444void 1445S_SET_WEAK (s) 1446 symbolS *s; 1447{ 1448 s->bsym->flags |= BSF_WEAK; 1449 s->bsym->flags &= ~(BSF_GLOBAL|BSF_LOCAL); 1450} 1451 1452void 1453S_SET_NAME (s, name) 1454 symbolS *s; 1455 char *name; 1456{ 1457 s->bsym->name = name; 1458} 1459#endif /* BFD_ASSEMBLER */ 1460 1461void 1462symbol_begin () 1463{ 1464 symbol_lastP = NULL; 1465 symbol_rootP = NULL; /* In case we have 0 symbols (!!) */ 1466 sy_hash = hash_new (); 1467 1468 memset ((char *) (&abs_symbol), '\0', sizeof (abs_symbol)); 1469#ifdef BFD_ASSEMBLER 1470#if defined (EMIT_SECTION_SYMBOLS) || !defined (RELOC_REQUIRES_SYMBOL) 1471 abs_symbol.bsym = bfd_abs_section.symbol; 1472#endif 1473#else 1474 /* Can't initialise a union. Sigh. */ 1475 S_SET_SEGMENT (&abs_symbol, absolute_section); 1476#endif 1477 abs_symbol.sy_value.X_op = O_constant; 1478 abs_symbol.sy_frag = &zero_address_frag; 1479 1480 if (LOCAL_LABELS_FB) 1481 fb_label_init (); 1482} 1483 1484 1485int indent_level; 1486 1487#if 0 1488 1489static void 1490indent () 1491{ 1492 printf ("%*s", indent_level * 4, ""); 1493} 1494 1495#endif 1496 1497void 1498print_symbol_value_1 (file, sym) 1499 FILE *file; 1500 symbolS *sym; 1501{ 1502 const char *name = S_GET_NAME (sym); 1503 if (!name || !name[0]) 1504 name = "(unnamed)"; 1505 fprintf (file, "sym %lx %s", (unsigned long) sym, name); 1506 if (sym->sy_frag != &zero_address_frag) 1507 fprintf (file, " frag %lx", (long) sym->sy_frag); 1508 if (sym->written) 1509 fprintf (file, " written"); 1510 if (sym->sy_resolved) 1511 fprintf (file, " resolved"); 1512 else if (sym->sy_resolving) 1513 fprintf (file, " resolving"); 1514 if (sym->sy_used_in_reloc) 1515 fprintf (file, " used-in-reloc"); 1516 if (sym->sy_used) 1517 fprintf (file, " used"); 1518 if (S_IS_LOCAL (sym)) 1519 fprintf (file, " local"); 1520 if (S_IS_EXTERN (sym)) 1521 fprintf (file, " extern"); 1522 if (S_IS_DEBUG (sym)) 1523 fprintf (file, " debug"); 1524 if (S_IS_DEFINED (sym)) 1525 fprintf (file, " defined"); 1526 fprintf (file, " %s", segment_name (S_GET_SEGMENT (sym))); 1527 if (sym->sy_resolved) 1528 { 1529 segT s = S_GET_SEGMENT (sym); 1530 1531 if (s != undefined_section 1532 && s != expr_section) 1533 fprintf (file, " %lx", (long) S_GET_VALUE (sym)); 1534 } 1535 else if (indent_level < 8 && S_GET_SEGMENT (sym) != undefined_section) 1536 { 1537 indent_level++; 1538 fprintf (file, "\n%*s<", indent_level * 4, ""); 1539 print_expr_1 (file, &sym->sy_value); 1540 fprintf (file, ">"); 1541 indent_level--; 1542 } 1543 fflush (file); 1544} 1545 1546void 1547print_symbol_value (sym) 1548 symbolS *sym; 1549{ 1550 indent_level = 0; 1551 print_symbol_value_1 (stderr, sym); 1552 fprintf (stderr, "\n"); 1553} 1554 1555void 1556print_expr_1 (file, exp) 1557 FILE *file; 1558 expressionS *exp; 1559{ 1560 fprintf (file, "expr %lx ", (long) exp); 1561 switch (exp->X_op) 1562 { 1563 case O_illegal: 1564 fprintf (file, "illegal"); 1565 break; 1566 case O_absent: 1567 fprintf (file, "absent"); 1568 break; 1569 case O_constant: 1570 fprintf (file, "constant %lx", (long) exp->X_add_number); 1571 break; 1572 case O_symbol: 1573 indent_level++; 1574 fprintf (file, "symbol\n%*s<", indent_level * 4, ""); 1575 print_symbol_value_1 (file, exp->X_add_symbol); 1576 fprintf (file, ">"); 1577 maybe_print_addnum: 1578 if (exp->X_add_number) 1579 fprintf (file, "\n%*s%lx", indent_level * 4, "", 1580 (long) exp->X_add_number); 1581 indent_level--; 1582 break; 1583 case O_register: 1584 fprintf (file, "register #%d", (int) exp->X_add_number); 1585 break; 1586 case O_big: 1587 fprintf (file, "big"); 1588 break; 1589 case O_uminus: 1590 fprintf (file, "uminus -<"); 1591 indent_level++; 1592 print_symbol_value_1 (file, exp->X_add_symbol); 1593 fprintf (file, ">"); 1594 goto maybe_print_addnum; 1595 case O_bit_not: 1596 fprintf (file, "bit_not"); 1597 break; 1598 case O_multiply: 1599 fprintf (file, "multiply"); 1600 break; 1601 case O_divide: 1602 fprintf (file, "divide"); 1603 break; 1604 case O_modulus: 1605 fprintf (file, "modulus"); 1606 break; 1607 case O_left_shift: 1608 fprintf (file, "lshift"); 1609 break; 1610 case O_right_shift: 1611 fprintf (file, "rshift"); 1612 break; 1613 case O_bit_inclusive_or: 1614 fprintf (file, "bit_ior"); 1615 break; 1616 case O_bit_exclusive_or: 1617 fprintf (file, "bit_xor"); 1618 break; 1619 case O_bit_and: 1620 fprintf (file, "bit_and"); 1621 break; 1622 case O_eq: 1623 fprintf (file, "eq"); 1624 break; 1625 case O_ne: 1626 fprintf (file, "ne"); 1627 break; 1628 case O_lt: 1629 fprintf (file, "lt"); 1630 break; 1631 case O_le: 1632 fprintf (file, "le"); 1633 break; 1634 case O_ge: 1635 fprintf (file, "ge"); 1636 break; 1637 case O_gt: 1638 fprintf (file, "gt"); 1639 break; 1640 case O_logical_and: 1641 fprintf (file, "logical_and"); 1642 break; 1643 case O_logical_or: 1644 fprintf (file, "logical_or"); 1645 break; 1646 case O_add: 1647 indent_level++; 1648 fprintf (file, "add\n%*s<", indent_level * 4, ""); 1649 print_symbol_value_1 (file, exp->X_add_symbol); 1650 fprintf (file, ">\n%*s<", indent_level * 4, ""); 1651 print_symbol_value_1 (file, exp->X_op_symbol); 1652 fprintf (file, ">"); 1653 goto maybe_print_addnum; 1654 case O_subtract: 1655 indent_level++; 1656 fprintf (file, "subtract\n%*s<", indent_level * 4, ""); 1657 print_symbol_value_1 (file, exp->X_add_symbol); 1658 fprintf (file, ">\n%*s<", indent_level * 4, ""); 1659 print_symbol_value_1 (file, exp->X_op_symbol); 1660 fprintf (file, ">"); 1661 goto maybe_print_addnum; 1662 default: 1663 fprintf (file, "{unknown opcode %d}", (int) exp->X_op); 1664 break; 1665 } 1666 fflush (stdout); 1667} 1668 1669void 1670print_expr (exp) 1671 expressionS *exp; 1672{ 1673 print_expr_1 (stderr, exp); 1674 fprintf (stderr, "\n"); 1675} 1676 1677void 1678symbol_print_statistics (file) 1679 FILE *file; 1680{ 1681 hash_print_statistics (file, "symbol table", sy_hash); 1682} 1683 1684/* end of symbols.c */ 1685