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