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