1 /* read.c - read a source file -
2 Copyright (C) 1986-2020 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 /* If your chars aren't 8 bits, you will change this a bit (eg. to 0xFF).
22 But then, GNU isn't supposed to run on your machine anyway.
23 (RMS is so shortsighted sometimes.) */
24 #define MASK_CHAR ((int)(unsigned char) -1)
26 /* This is the largest known floating point format (for now). It will
27 grow when we do 4361 style flonums. */
28 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
30 /* Routines that read assembler source text to build spaghetti in memory.
31 Another group of these functions is in the expr.c module. */
34 #include "safe-ctype.h"
40 #include "dw2gencfi.h"
45 #ifndef TC_START_LABEL
46 #define TC_START_LABEL(STR, NUL_CHAR, NEXT_CHAR) (NEXT_CHAR == ':')
49 /* Set by the object-format or the target. */
50 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
51 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) \
56 else if ((SIZE) >= 4) \
58 else if ((SIZE) >= 2) \
66 char *input_line_pointer
; /*->next char of source file to parse. */
67 bfd_boolean input_from_string
= FALSE
;
69 #if BITS_PER_CHAR != 8
70 /* The following table is indexed by[(char)] and will break if
71 a char does not have exactly 256 states (hopefully 0:255!)! */
80 /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */
85 /* The Delta 68k assembler permits % inside label names. */
90 /* The PowerPC Windows NT assemblers permits ? inside label names. */
95 /* The IA-64 assembler uses # as a suffix designating a symbol. We include
96 it in the symbol and strip it out in tc_canonicalize_symbol_name. */
105 /* The Delta 68k assembler permits ~ at start of label names. */
109 /* Used by is_... macros. our ctype[]. */
110 char lex_type
[256] = {
111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
113 0, 0, 0, LEX_HASH
, LEX_DOLLAR
, LEX_PCT
, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
114 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM
, /* 0123456789:;<=>? */
115 LEX_AT
, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
116 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, 0, 3, /* PQRSTUVWXYZ[\]^_ */
117 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
118 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR
, 0, LEX_BR
, LEX_TILDE
, 0, /* pqrstuvwxyz{|}~. */
119 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
120 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
121 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
122 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
123 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
124 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
125 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
126 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
130 Out: 1 if this character ends a line.
131 2 if this character is a line separator. */
132 char is_end_of_line
[256] = {
134 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
136 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
138 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
139 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* _!"#$%&'()*+,-./ */
140 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
141 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
144 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
147 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
148 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
150 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
151 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
152 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* */
155 #ifndef TC_CASE_SENSITIVE
156 char original_case_string
[128];
159 /* Functions private to this file. */
161 static char *buffer
; /* 1st char of each buffer of lines is here. */
162 static char *buffer_limit
; /*->1 + last char in buffer. */
164 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
165 in the tc-<CPU>.h file. See the "Porting GAS" section of the
167 int target_big_endian
= TARGET_BYTES_BIG_ENDIAN
;
169 /* Variables for handling include file directory table. */
171 /* Table of pointers to directories to search for .include's. */
172 const char **include_dirs
;
174 /* How many are in the table. */
175 int include_dir_count
;
177 /* Length of longest in table. */
178 int include_dir_maxlen
= 1;
180 #ifndef WORKING_DOT_WORD
181 struct broken_word
*broken_words
;
182 int new_broken_words
;
185 /* The current offset into the absolute section. We don't try to
186 build frags in the absolute section, since no data can be stored
187 there. We just keep track of the current offset. */
188 addressT abs_section_offset
;
190 /* If this line had an MRI style label, it is stored in this variable.
191 This is used by some of the MRI pseudo-ops. */
194 /* This global variable is used to support MRI common sections. We
195 translate such sections into a common symbol. This variable is
196 non-NULL when we are in an MRI common section. */
197 symbolS
*mri_common_symbol
;
199 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
200 need to align to an even byte boundary unless the next pseudo-op is
201 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment
203 static int mri_pending_align
;
207 /* This variable is set to be non-zero if the next string we see might
208 be the name of the source file in DWARF debugging information. See
209 the comment in emit_expr for the format we look for. */
210 static int dwarf_file_string
;
214 /* If the target defines the md_frag_max_var hook then we know
215 enough to implement the .bundle_align_mode features. */
216 #ifdef md_frag_max_var
217 # define HANDLE_BUNDLE
221 /* .bundle_align_mode sets this. Normally it's zero. When nonzero,
222 it's the exponent of the bundle size, and aligned instruction bundle
223 mode is in effect. */
224 static unsigned int bundle_align_p2
;
226 /* These are set by .bundle_lock and .bundle_unlock. .bundle_lock sets
227 bundle_lock_frag to frag_now and then starts a new frag with
228 frag_align_code. At the same time, bundle_lock_frain gets frchain_now,
229 so that .bundle_unlock can verify that we didn't change segments.
230 .bundle_unlock resets both to NULL. If we detect a bundling violation,
231 then we reset bundle_lock_frchain to NULL as an indicator that we've
232 already diagnosed the error with as_bad and don't need a cascade of
233 redundant errors, but bundle_lock_frag remains set to indicate that
234 we are expecting to see .bundle_unlock. */
235 static fragS
*bundle_lock_frag
;
236 static frchainS
*bundle_lock_frchain
;
238 /* This is incremented by .bundle_lock and decremented by .bundle_unlock,
240 static unsigned int bundle_lock_depth
;
243 static void do_s_func (int end_p
, const char *default_prefix
);
244 static void s_align (int, int);
245 static void s_altmacro (int);
246 static void s_bad_end (int);
247 static void s_reloc (int);
248 static int hex_float (int, char *);
249 static segT
get_known_segmented_expression (expressionS
* expP
);
250 static void pobegin (void);
251 static size_t get_non_macro_line_sb (sb
*);
252 static void generate_file_debug (void);
253 static char *_find_end_of_line (char *, int, int, int);
261 obj_read_begin_hook ();
263 /* Something close -- but not too close -- to a multiple of 1024.
264 The debugging malloc I'm using has 24 bytes of overhead. */
265 obstack_begin (¬es
, chunksize
);
266 obstack_begin (&cond_obstack
, chunksize
);
268 #ifndef tc_line_separator_chars
269 #define tc_line_separator_chars line_separator_chars
271 /* Use machine dependent syntax. */
272 for (p
= tc_line_separator_chars
; *p
; p
++)
273 is_end_of_line
[(unsigned char) *p
] = 2;
274 /* Use more. FIXME-SOMEDAY. */
280 #ifndef TC_ADDRESS_BYTES
281 #define TC_ADDRESS_BYTES address_bytes
286 /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
287 contain an address. */
288 int n
= (stdoutput
->arch_info
->bits_per_address
- 1) / 8;
296 /* Set up pseudo-op tables. */
298 static struct hash_control
*po_hash
;
300 static const pseudo_typeS potable
[] = {
301 {"abort", s_abort
, 0},
302 {"align", s_align_ptwo
, 0},
303 {"altmacro", s_altmacro
, 1},
304 {"ascii", stringer
, 8+0},
305 {"asciz", stringer
, 8+1},
306 {"balign", s_align_bytes
, 0},
307 {"balignw", s_align_bytes
, -2},
308 {"balignl", s_align_bytes
, -4},
311 {"bundle_align_mode", s_bundle_align_mode
, 0},
312 {"bundle_lock", s_bundle_lock
, 0},
313 {"bundle_unlock", s_bundle_unlock
, 0},
317 {"common", s_mri_common
, 0},
318 {"common.s", s_mri_common
, 1},
321 #ifdef TC_ADDRESS_BYTES
325 {"dc.d", float_cons
, 'd'},
327 {"dc.s", float_cons
, 'f'},
329 {"dc.x", float_cons
, 'x'},
331 {"dcb.b", s_space
, 1},
332 {"dcb.d", s_float_space
, 'd'},
333 {"dcb.l", s_space
, 4},
334 {"dcb.s", s_float_space
, 'f'},
335 {"dcb.w", s_space
, 2},
336 {"dcb.x", s_float_space
, 'x'},
338 {"ds.b", s_space
, 1},
339 {"ds.d", s_space
, 8},
340 {"ds.l", s_space
, 4},
341 {"ds.p", s_space
, 12},
342 {"ds.s", s_space
, 4},
343 {"ds.w", s_space
, 2},
344 {"ds.x", s_space
, 12},
345 {"debug", s_ignore
, 0},
350 {"double", float_cons
, 'd'},
352 {"eject", listing_eject
, 0}, /* Formfeed listing. */
354 {"elsec", s_else
, 0},
355 {"elseif", s_elseif
, (int) O_ne
},
357 {"endc", s_endif
, 0},
358 {"endfunc", s_func
, 1},
359 {"endif", s_endif
, 0},
360 {"endm", s_bad_end
, 0},
361 {"endr", s_bad_end
, 1},
367 {"error", s_errwarn
, 1},
368 {"exitm", s_mexit
, 0},
370 {"extern", s_ignore
, 0}, /* We treat all undef as ext. */
371 {"appfile", s_app_file
, 1},
372 {"appline", s_app_line
, 1},
374 {"file", s_app_file
, 0},
376 {"float", float_cons
, 'f'},
377 {"format", s_ignore
, 0},
379 {"global", s_globl
, 0},
380 {"globl", s_globl
, 0},
382 {"if", s_if
, (int) O_ne
},
385 {"ifdef", s_ifdef
, 0},
386 {"ifeq", s_if
, (int) O_eq
},
387 {"ifeqs", s_ifeqs
, 0},
388 {"ifge", s_if
, (int) O_ge
},
389 {"ifgt", s_if
, (int) O_gt
},
390 {"ifle", s_if
, (int) O_le
},
391 {"iflt", s_if
, (int) O_lt
},
394 {"ifndef", s_ifdef
, 1},
395 {"ifne", s_if
, (int) O_ne
},
396 {"ifnes", s_ifeqs
, 1},
397 {"ifnotdef", s_ifdef
, 1},
398 {"incbin", s_incbin
, 0},
399 {"include", s_include
, 0},
405 {"lcomm", s_lcomm
, 0},
406 {"lflags", s_ignore
, 0}, /* Listing flags. */
407 {"linefile", s_app_line
, 0},
408 {"linkonce", s_linkonce
, 0},
409 {"list", listing_list
, 1}, /* Turn listing on. */
410 {"llen", listing_psize
, 1},
413 {"macro", s_macro
, 0},
414 {"mexit", s_mexit
, 0},
416 {".mri", s_mri
, 0}, /* Special case so .mri works in MRI mode. */
417 {"name", s_ignore
, 0},
418 {"noaltmacro", s_altmacro
, 0},
419 {"noformat", s_ignore
, 0},
420 {"nolist", listing_list
, 0}, /* Turn listing off. */
421 {"nopage", listing_nopage
, 0},
424 {"offset", s_struct
, 0},
426 {"p2align", s_align_ptwo
, 0},
427 {"p2alignw", s_align_ptwo
, -2},
428 {"p2alignl", s_align_ptwo
, -4},
429 {"page", listing_eject
, 0},
430 {"plen", listing_psize
, 0},
431 {"print", s_print
, 0},
432 {"psize", listing_psize
, 0}, /* Set paper size. */
433 {"purgem", s_purgem
, 0},
435 {"reloc", s_reloc
, 0},
439 {"sbttl", listing_title
, 1}, /* Subtitle of listing. */
444 {"single", float_cons
, 'f'},
446 {"space", s_space
, 0},
447 {"skip", s_space
, 0},
448 {"sleb128", s_leb128
, 1},
449 {"spc", s_ignore
, 0},
450 {"stabd", s_stab
, 'd'},
451 {"stabn", s_stab
, 'n'},
452 {"stabs", s_stab
, 's'},
453 {"string", stringer
, 8+1},
454 {"string8", stringer
, 8+1},
455 {"string16", stringer
, 16+1},
456 {"string32", stringer
, 32+1},
457 {"string64", stringer
, 64+1},
458 {"struct", s_struct
, 0},
462 /* This is for gcc to use. It's only just been added (2/94), so gcc
463 won't be able to use it for a while -- probably a year or more.
464 But once this has been released, check with gcc maintainers
465 before deleting it or even changing the spelling. */
466 {"this_GCC_requires_the_GNU_assembler", s_ignore
, 0},
467 /* If we're folding case -- done for some targets, not necessarily
468 all -- the above string in an input file will be converted to
469 this one. Match it either way... */
470 {"this_gcc_requires_the_gnu_assembler", s_ignore
, 0},
472 {"title", listing_title
, 0}, /* Listing title. */
473 {"ttl", listing_title
, 0},
475 {"uleb128", s_leb128
, 0},
479 {"xdef", s_globl
, 0},
480 {"xref", s_ignore
, 0},
481 {"xstabs", s_xstab
, 's'},
482 {"warning", s_errwarn
, 0},
483 {"weakref", s_weakref
, 0},
485 {"zero", s_space
, 0},
486 {NULL
, NULL
, 0} /* End sentinel. */
490 get_absolute_expr (expressionS
*exp
)
492 expression_and_evaluate (exp
);
494 if (exp
->X_op
!= O_constant
)
496 if (exp
->X_op
!= O_absent
)
497 as_bad (_("bad or irreducible absolute expression"));
498 exp
->X_add_number
= 0;
500 return exp
->X_add_number
;
504 get_absolute_expression (void)
508 return get_absolute_expr (&exp
);
511 static int pop_override_ok
= 0;
512 static const char *pop_table_name
;
515 pop_insert (const pseudo_typeS
*table
)
518 const pseudo_typeS
*pop
;
519 for (pop
= table
; pop
->poc_name
; pop
++)
521 errtxt
= hash_insert (po_hash
, pop
->poc_name
, (char *) pop
);
522 if (errtxt
&& (!pop_override_ok
|| strcmp (errtxt
, "exists")))
523 as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name
,
528 #ifndef md_pop_insert
529 #define md_pop_insert() pop_insert(md_pseudo_table)
532 #ifndef obj_pop_insert
533 #define obj_pop_insert() pop_insert(obj_pseudo_table)
536 #ifndef cfi_pop_insert
537 #define cfi_pop_insert() pop_insert(cfi_pseudo_table)
543 po_hash
= hash_new ();
545 /* Do the target-specific pseudo ops. */
546 pop_table_name
= "md";
549 /* Now object specific. Skip any that were in the target table. */
550 pop_table_name
= "obj";
554 /* Now portable ones. Skip any that we've seen already. */
555 pop_table_name
= "standard";
556 pop_insert (potable
);
559 pop_table_name
= "cfi";
564 #define HANDLE_CONDITIONAL_ASSEMBLY(num_read) \
565 if (ignore_input ()) \
567 char *eol = find_end_of_line (input_line_pointer - (num_read), \
569 input_line_pointer = (input_line_pointer <= buffer_limit \
570 && eol >= buffer_limit) \
576 /* This function is used when scrubbing the characters between #APP
579 static char *scrub_string
;
580 static char *scrub_string_end
;
583 scrub_from_string (char *buf
, size_t buflen
)
587 copy
= scrub_string_end
- scrub_string
;
590 memcpy (buf
, scrub_string
, copy
);
591 scrub_string
+= copy
;
595 /* Helper function of read_a_source_file, which tries to expand a macro. */
597 try_macro (char term
, const char *line
)
603 if (check_macro (line
, &out
, &err
, ¯o
))
607 *input_line_pointer
++ = term
;
608 input_scrub_include_sb (&out
,
609 input_line_pointer
, 1);
612 input_scrub_next_buffer (&input_line_pointer
);
614 md_macro_info (macro
);
622 /* Start a new instruction bundle. Returns the rs_align_code frag that
623 will be used to align the new bundle. */
627 fragS
*frag
= frag_now
;
629 frag_align_code (0, 0);
631 while (frag
->fr_type
!= rs_align_code
)
632 frag
= frag
->fr_next
;
634 gas_assert (frag
!= frag_now
);
639 /* Calculate the maximum size after relaxation of the region starting
640 at the given frag and extending through frag_now (which is unfinished). */
642 pending_bundle_size (fragS
*frag
)
644 unsigned int offset
= frag
->fr_fix
;
645 unsigned int size
= 0;
647 gas_assert (frag
!= frag_now
);
648 gas_assert (frag
->fr_type
== rs_align_code
);
650 while (frag
!= frag_now
)
652 /* This should only happen in what will later become an error case. */
656 size
+= frag
->fr_fix
;
657 if (frag
->fr_type
== rs_machine_dependent
)
658 size
+= md_frag_max_var (frag
);
660 frag
= frag
->fr_next
;
663 gas_assert (frag
== frag_now
);
664 size
+= frag_now_fix ();
665 if (frag
->fr_type
== rs_machine_dependent
)
666 size
+= md_frag_max_var (frag
);
668 gas_assert (size
>= offset
);
670 return size
- offset
;
673 /* Finish off the frag created to ensure bundle alignment. */
675 finish_bundle (fragS
*frag
, unsigned int size
)
677 gas_assert (bundle_align_p2
> 0);
678 gas_assert (frag
->fr_type
== rs_align_code
);
682 /* If there is more than a single byte, then we need to set up the
683 alignment frag. Otherwise we leave it at its initial state from
684 calling frag_align_code (0, 0), so that it does nothing. */
685 frag
->fr_offset
= bundle_align_p2
;
686 frag
->fr_subtype
= size
- 1;
689 /* We do this every time rather than just in s_bundle_align_mode
690 so that we catch any affected section without needing hooks all
691 over for all paths that do section changes. It's cheap enough. */
692 if (bundle_align_p2
> OCTETS_PER_BYTE_POWER
)
693 record_alignment (now_seg
, bundle_align_p2
- OCTETS_PER_BYTE_POWER
);
696 /* Assemble one instruction. This takes care of the bundle features
697 around calling md_assemble. */
699 assemble_one (char *line
)
701 fragS
*insn_start_frag
= NULL
;
703 if (bundle_lock_frchain
!= NULL
&& bundle_lock_frchain
!= frchain_now
)
705 as_bad (_("cannot change section or subsection inside .bundle_lock"));
706 /* Clearing this serves as a marker that we have already complained. */
707 bundle_lock_frchain
= NULL
;
710 if (bundle_lock_frchain
== NULL
&& bundle_align_p2
> 0)
711 insn_start_frag
= start_bundle ();
715 if (bundle_lock_frchain
!= NULL
)
717 /* Make sure this hasn't pushed the locked sequence
718 past the bundle size. */
719 unsigned int bundle_size
= pending_bundle_size (bundle_lock_frag
);
720 if (bundle_size
> 1U << bundle_align_p2
)
721 as_bad (_ (".bundle_lock sequence at %u bytes, "
722 "but .bundle_align_mode limit is %u bytes"),
723 bundle_size
, 1U << bundle_align_p2
);
725 else if (bundle_align_p2
> 0)
727 unsigned int insn_size
= pending_bundle_size (insn_start_frag
);
729 if (insn_size
> 1U << bundle_align_p2
)
730 as_bad (_("single instruction is %u bytes long, "
731 "but .bundle_align_mode limit is %u bytes"),
732 insn_size
, 1U << bundle_align_p2
);
734 finish_bundle (insn_start_frag
, insn_size
);
738 #else /* !HANDLE_BUNDLE */
740 # define assemble_one(line) md_assemble(line)
742 #endif /* HANDLE_BUNDLE */
747 flagword flags
= bfd_section_flags (now_seg
);
749 return (flags
& SEC_ALLOC
) && !(flags
& (SEC_LOAD
| SEC_HAS_CONTENTS
));
752 /* Guts of .align directive:
753 N is the power of two to which to align. A value of zero is accepted but
754 ignored: the default alignment of the section will be at least this.
755 FILL may be NULL, or it may point to the bytes of the fill pattern.
756 LEN is the length of whatever FILL points to, if anything. If LEN is zero
757 but FILL is not NULL then LEN is treated as if it were one.
758 MAX is the maximum number of characters to skip when doing the alignment,
759 or 0 if there is no maximum. */
762 do_align (unsigned int n
, char *fill
, unsigned int len
, unsigned int max
)
764 if (now_seg
== absolute_section
|| in_bss ())
770 if (now_seg
== absolute_section
)
771 as_warn (_("ignoring fill value in absolute section"));
773 as_warn (_("ignoring fill value in section `%s'"),
774 segment_name (now_seg
));
781 #ifdef md_flush_pending_output
782 md_flush_pending_output ();
786 md_do_align (n
, fill
, len
, max
, just_record_alignment
);
789 /* Only make a frag if we HAVE to... */
790 if ((n
> OCTETS_PER_BYTE_POWER
) && !need_pass_2
)
794 if (subseg_text_p (now_seg
))
795 frag_align_code (n
, max
);
797 frag_align (n
, 0, max
);
800 frag_align (n
, *fill
, max
);
802 frag_align_pattern (n
, fill
, len
, max
);
806 just_record_alignment
: ATTRIBUTE_UNUSED_LABEL
809 if (n
> OCTETS_PER_BYTE_POWER
)
810 record_alignment (now_seg
, n
- OCTETS_PER_BYTE_POWER
);
813 /* We read the file, putting things into a web that represents what we
814 have been reading. */
816 read_a_source_file (const char *name
)
820 char *s
; /* String of symbol, '\0' appended. */
828 buffer
= input_scrub_new_file (name
);
831 listing_newline (NULL
);
832 register_dependency (name
);
834 /* Generate debugging information before we've read anything in to denote
835 this file as the "main" source file and not a subordinate one
836 (e.g. N_SO vs N_SOL in stabs). */
837 generate_file_debug ();
839 while ((buffer_limit
= input_scrub_next_buffer (&input_line_pointer
)) != 0)
840 { /* We have another line to parse. */
842 /* In order to avoid listing macro expansion lines with labels
843 multiple times, keep track of which line was last issued. */
844 static char *last_eol
;
848 while (input_line_pointer
< buffer_limit
)
850 bfd_boolean was_new_line
;
851 /* We have more of this buffer to parse. */
853 /* We now have input_line_pointer->1st char of next line.
854 If input_line_pointer [-1] == '\n' then we just
855 scanned another line: so bump line counters. */
856 was_new_line
= is_end_of_line
[(unsigned char) input_line_pointer
[-1]];
859 symbol_set_value_now (&dot_symbol
);
860 #ifdef md_start_line_hook
861 md_start_line_hook ();
863 if (input_line_pointer
[-1] == '\n')
864 bump_line_counters ();
868 /* If listing is on, and we are expanding a macro, then give
869 the listing code the contents of the expanded line. */
872 if ((listing
& LISTING_MACEXP
) && macro_nest
> 0)
874 /* Find the end of the current expanded macro line. */
875 s
= find_end_of_line (input_line_pointer
, flag_m68k_mri
);
883 /* Copy it for safe keeping. Also give an indication of
884 how much macro nesting is involved at this point. */
885 len
= s
- input_line_pointer
;
886 copy
= XNEWVEC (char, len
+ macro_nest
+ 2);
887 memset (copy
, '>', macro_nest
);
888 copy
[macro_nest
] = ' ';
889 memcpy (copy
+ macro_nest
+ 1, input_line_pointer
, len
);
890 copy
[macro_nest
+ 1 + len
] = '\0';
892 /* Install the line with the listing facility. */
893 listing_newline (copy
);
897 listing_newline (NULL
);
904 if (LABELS_WITHOUT_COLONS
|| flag_m68k_mri
)
906 next_char
= * input_line_pointer
;
907 /* Text at the start of a line must be a label, we
908 run down and stick a colon in. */
909 if (is_name_beginner (next_char
) || next_char
== '"')
914 HANDLE_CONDITIONAL_ASSEMBLY (0);
916 nul_char
= get_symbol_name (& line_start
);
917 next_char
= (nul_char
== '"' ? input_line_pointer
[1] : nul_char
);
919 /* In MRI mode, the EQU and MACRO pseudoops must
920 be handled specially. */
924 char *rest
= input_line_pointer
+ 1;
928 if (*rest
== ' ' || *rest
== '\t')
930 if ((strncasecmp (rest
, "EQU", 3) == 0
931 || strncasecmp (rest
, "SET", 3) == 0)
932 && (rest
[3] == ' ' || rest
[3] == '\t'))
934 input_line_pointer
= rest
+ 3;
936 strncasecmp (rest
, "SET", 3) == 0);
939 if (strncasecmp (rest
, "MACRO", 5) == 0
942 || is_end_of_line
[(unsigned char) rest
[5]]))
946 /* In MRI mode, we need to handle the MACRO
947 pseudo-op specially: we don't want to put the
948 symbol in the symbol table. */
950 #ifdef TC_START_LABEL_WITHOUT_COLON
951 && TC_START_LABEL_WITHOUT_COLON (nul_char
, next_char
)
954 line_label
= colon (line_start
);
956 line_label
= symbol_create (line_start
,
961 next_char
= restore_line_pointer (nul_char
);
962 if (next_char
== ':')
963 input_line_pointer
++;
968 /* We are at the beginning of a line, or similar place.
969 We expect a well-formed assembler statement.
970 A "symbol-name:" is a statement.
972 Depending on what compiler is used, the order of these tests
973 may vary to catch most common case 1st.
974 Each test is independent of all other tests at the (top)
977 nul_char
= next_char
= *input_line_pointer
++;
978 while (next_char
== '\t' || next_char
== ' ' || next_char
== '\f');
980 /* C is the 1st significant character.
981 Input_line_pointer points after that character. */
982 if (is_name_beginner (next_char
) || next_char
== '"')
986 /* Want user-defined label or pseudo/opcode. */
987 HANDLE_CONDITIONAL_ASSEMBLY (1);
989 --input_line_pointer
;
990 nul_char
= get_symbol_name (& s
); /* name's delimiter. */
991 next_char
= (nul_char
== '"' ? input_line_pointer
[1] : nul_char
);
992 rest
= input_line_pointer
+ (nul_char
== '"' ? 2 : 1);
994 /* NEXT_CHAR is character after symbol.
995 The end of symbol in the input line is now '\0'.
996 S points to the beginning of the symbol.
997 [In case of pseudo-op, s->'.'.]
998 Input_line_pointer->'\0' where NUL_CHAR was. */
999 if (TC_START_LABEL (s
, nul_char
, next_char
))
1003 /* In MRI mode, \tsym: set 0 is permitted. */
1007 if (*rest
== ' ' || *rest
== '\t')
1010 if ((strncasecmp (rest
, "EQU", 3) == 0
1011 || strncasecmp (rest
, "SET", 3) == 0)
1012 && (rest
[3] == ' ' || rest
[3] == '\t'))
1014 input_line_pointer
= rest
+ 3;
1020 line_label
= colon (s
); /* User-defined label. */
1021 restore_line_pointer (nul_char
);
1022 ++ input_line_pointer
;
1023 #ifdef tc_check_label
1024 tc_check_label (line_label
);
1026 /* Input_line_pointer->after ':'. */
1029 else if ((next_char
== '=' && *rest
== '=')
1030 || ((next_char
== ' ' || next_char
== '\t')
1035 demand_empty_rest_of_line ();
1037 else if ((next_char
== '='
1038 || ((next_char
== ' ' || next_char
== '\t')
1040 #ifdef TC_EQUAL_IN_INSN
1041 && !TC_EQUAL_IN_INSN (next_char
, s
)
1046 demand_empty_rest_of_line ();
1050 /* Expect pseudo-op or machine instruction. */
1053 #ifndef TC_CASE_SENSITIVE
1057 strncpy (original_case_string
, s2
,
1058 sizeof (original_case_string
) - 1);
1059 original_case_string
[sizeof (original_case_string
) - 1] = 0;
1063 *s2
= TOLOWER (*s2
);
1068 if (NO_PSEUDO_DOT
|| flag_m68k_mri
)
1070 /* The MRI assembler uses pseudo-ops without
1072 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
);
1073 if (pop
!= NULL
&& pop
->poc_handler
== NULL
)
1078 || (!flag_m68k_mri
&& *s
== '.'))
1082 WARNING: next_char may be end-of-line.
1083 We lookup the pseudo-op table with s+1 because we
1084 already know that the pseudo-op begins with a '.'. */
1087 pop
= (pseudo_typeS
*) hash_find (po_hash
, s
+ 1);
1088 if (pop
&& !pop
->poc_handler
)
1091 /* In MRI mode, we may need to insert an
1092 automatic alignment directive. What a hack
1094 if (mri_pending_align
1096 || !((pop
->poc_handler
== cons
1097 && pop
->poc_val
== 1)
1098 || (pop
->poc_handler
== s_space
1099 && pop
->poc_val
== 1)
1100 #ifdef tc_conditional_pseudoop
1101 || tc_conditional_pseudoop (pop
)
1103 || pop
->poc_handler
== s_if
1104 || pop
->poc_handler
== s_ifdef
1105 || pop
->poc_handler
== s_ifc
1106 || pop
->poc_handler
== s_ifeqs
1107 || pop
->poc_handler
== s_else
1108 || pop
->poc_handler
== s_endif
1109 || pop
->poc_handler
== s_globl
1110 || pop
->poc_handler
== s_ignore
)))
1112 do_align (1, (char *) NULL
, 0, 0);
1113 mri_pending_align
= 0;
1115 if (line_label
!= NULL
)
1117 symbol_set_frag (line_label
, frag_now
);
1118 S_SET_VALUE (line_label
, frag_now_fix ());
1122 /* Print the error msg now, while we still can. */
1125 char *end
= input_line_pointer
;
1127 (void) restore_line_pointer (nul_char
);
1129 nul_char
= next_char
= *--input_line_pointer
;
1130 *input_line_pointer
= '\0';
1131 if (! macro_defined
|| ! try_macro (next_char
, s
))
1134 as_bad (_("unknown pseudo-op: `%s'"), s
);
1135 *input_line_pointer
++ = nul_char
;
1140 /* Put it back for error messages etc. */
1141 next_char
= restore_line_pointer (nul_char
);
1142 /* The following skip of whitespace is compulsory.
1143 A well shaped space is sometimes all that separates
1144 keyword from operands. */
1145 if (next_char
== ' ' || next_char
== '\t')
1146 input_line_pointer
++;
1148 /* Input_line is restored.
1149 Input_line_pointer->1st non-blank char
1150 after pseudo-operation. */
1151 (*pop
->poc_handler
) (pop
->poc_val
);
1153 /* If that was .end, just get out now. */
1154 if (pop
->poc_handler
== s_end
)
1159 /* WARNING: next_char may be end-of-line. */
1160 /* Also: input_line_pointer->`\0` where nul_char was. */
1161 (void) restore_line_pointer (nul_char
);
1162 input_line_pointer
= _find_end_of_line (input_line_pointer
, flag_m68k_mri
, 1, 0);
1163 next_char
= nul_char
= *input_line_pointer
;
1164 *input_line_pointer
= '\0';
1166 generate_lineno_debug ();
1168 if (macro_defined
&& try_macro (next_char
, s
))
1171 if (mri_pending_align
)
1173 do_align (1, (char *) NULL
, 0, 0);
1174 mri_pending_align
= 0;
1175 if (line_label
!= NULL
)
1177 symbol_set_frag (line_label
, frag_now
);
1178 S_SET_VALUE (line_label
, frag_now_fix ());
1182 assemble_one (s
); /* Assemble 1 instruction. */
1184 /* PR 19630: The backend may have set ilp to NULL
1185 if it encountered a catastrophic failure. */
1186 if (input_line_pointer
== NULL
)
1187 as_fatal (_("unable to continue with assembly."));
1189 *input_line_pointer
++ = nul_char
;
1191 /* We resume loop AFTER the end-of-line from
1192 this instruction. */
1198 /* Empty statement? */
1199 if (is_end_of_line
[(unsigned char) next_char
])
1202 if ((LOCAL_LABELS_DOLLAR
|| LOCAL_LABELS_FB
) && ISDIGIT (next_char
))
1204 /* local label ("4:") */
1205 char *backup
= input_line_pointer
;
1207 HANDLE_CONDITIONAL_ASSEMBLY (1);
1209 temp
= next_char
- '0';
1211 if (nul_char
== '"')
1212 ++ input_line_pointer
;
1214 /* Read the whole number. */
1215 while (ISDIGIT (*input_line_pointer
))
1217 const long digit
= *input_line_pointer
- '0';
1218 if (temp
> (LONG_MAX
- digit
) / 10)
1220 as_bad (_("local label too large near %s"), backup
);
1224 temp
= temp
* 10 + digit
;
1225 ++input_line_pointer
;
1228 /* Overflow: stop processing the label. */
1231 ignore_rest_of_line ();
1235 if (LOCAL_LABELS_DOLLAR
1236 && *input_line_pointer
== '$'
1237 && *(input_line_pointer
+ 1) == ':')
1239 input_line_pointer
+= 2;
1241 if (dollar_label_defined (temp
))
1243 as_fatal (_("label \"%ld$\" redefined"), temp
);
1246 define_dollar_label (temp
);
1247 colon (dollar_label_name (temp
, 0));
1252 && *input_line_pointer
++ == ':')
1254 fb_label_instance_inc (temp
);
1255 colon (fb_label_name (temp
, 0));
1259 input_line_pointer
= backup
;
1262 if (next_char
&& strchr (line_comment_chars
, next_char
))
1263 { /* Its a comment. Better say APP or NO_APP. */
1268 unsigned int new_length
;
1271 s
= input_line_pointer
;
1272 if (strncmp (s
, "APP\n", 4))
1275 ignore_rest_of_line ();
1278 bump_line_counters ();
1281 ends
= strstr (s
, "#NO_APP\n");
1285 unsigned int tmp_len
;
1288 /* The end of the #APP wasn't in this buffer. We
1289 keep reading in buffers until we find the #NO_APP
1290 that goes with this #APP There is one. The specs
1292 tmp_len
= buffer_limit
- s
;
1293 tmp_buf
= XNEWVEC (char, tmp_len
+ 1);
1294 memcpy (tmp_buf
, s
, tmp_len
);
1297 new_tmp
= input_scrub_next_buffer (&buffer
);
1301 buffer_limit
= new_tmp
;
1302 input_line_pointer
= buffer
;
1303 ends
= strstr (buffer
, "#NO_APP\n");
1305 num
= ends
- buffer
;
1307 num
= buffer_limit
- buffer
;
1309 tmp_buf
= XRESIZEVEC (char, tmp_buf
, tmp_len
+ num
);
1310 memcpy (tmp_buf
+ tmp_len
, buffer
, num
);
1315 input_line_pointer
= ends
? ends
+ 8 : NULL
;
1323 input_line_pointer
= ends
+ 8;
1327 scrub_string_end
= ends
;
1329 new_length
= ends
- s
;
1330 new_buf
= XNEWVEC (char, new_length
);
1337 space
= (new_buf
+ new_length
) - new_tmp
;
1338 size
= do_scrub_chars (scrub_from_string
, new_tmp
, space
);
1346 new_buf
= XRESIZEVEC (char, new_buf
, new_length
+ 100);
1347 new_tmp
= new_buf
+ new_length
;
1353 /* We've "scrubbed" input to the preferred format. In the
1354 process we may have consumed the whole of the remaining
1355 file (and included files). We handle this formatted
1356 input similar to that of macro expansion, letting
1357 actual macro expansion (possibly nested) and other
1358 input expansion work. Beware that in messages, line
1359 numbers and possibly file names will be incorrect. */
1360 new_length
= strlen (new_buf
);
1361 sb_build (&sbuf
, new_length
);
1362 sb_add_buffer (&sbuf
, new_buf
, new_length
);
1363 input_scrub_include_sb (&sbuf
, input_line_pointer
, 0);
1365 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
1370 HANDLE_CONDITIONAL_ASSEMBLY (1);
1372 #ifdef tc_unrecognized_line
1373 if (tc_unrecognized_line (next_char
))
1376 input_line_pointer
--;
1377 /* Report unknown char as error. */
1378 demand_empty_rest_of_line ();
1383 symbol_set_value_now (&dot_symbol
);
1385 #ifdef HANDLE_BUNDLE
1386 if (bundle_lock_frag
!= NULL
)
1388 as_bad_where (bundle_lock_frag
->fr_file
, bundle_lock_frag
->fr_line
,
1389 _(".bundle_lock with no matching .bundle_unlock"));
1390 bundle_lock_frag
= NULL
;
1391 bundle_lock_frchain
= NULL
;
1392 bundle_lock_depth
= 0;
1399 /* Close the input file. */
1400 input_scrub_close ();
1401 #ifdef WARN_COMMENTS
1403 if (warn_comment
&& found_comment
)
1404 as_warn_where (found_comment_file
, found_comment
,
1405 "first comment found here");
1410 /* Convert O_constant expression EXP into the equivalent O_big representation.
1411 Take the sign of the number from SIGN rather than X_add_number. */
1414 convert_to_bignum (expressionS
*exp
, int sign
)
1419 value
= exp
->X_add_number
;
1420 for (i
= 0; i
< sizeof (exp
->X_add_number
) / CHARS_PER_LITTLENUM
; i
++)
1422 generic_bignum
[i
] = value
& LITTLENUM_MASK
;
1423 value
>>= LITTLENUM_NUMBER_OF_BITS
;
1425 /* Add a sequence of sign bits if the top bit of X_add_number is not
1426 the sign of the original value. */
1427 if ((exp
->X_add_number
< 0) == !sign
)
1428 generic_bignum
[i
++] = sign
? LITTLENUM_MASK
: 0;
1430 exp
->X_add_number
= i
;
1433 /* For most MRI pseudo-ops, the line actually ends at the first
1434 nonquoted space. This function looks for that point, stuffs a null
1435 in, and sets *STOPCP to the character that used to be there, and
1436 returns the location.
1438 Until I hear otherwise, I am going to assume that this is only true
1439 for the m68k MRI assembler. */
1442 mri_comment_field (char *stopcp
)
1448 know (flag_m68k_mri
);
1450 for (s
= input_line_pointer
;
1451 ((!is_end_of_line
[(unsigned char) *s
] && *s
!= ' ' && *s
!= '\t')
1459 for (s
= input_line_pointer
;
1460 !is_end_of_line
[(unsigned char) *s
];
1470 /* Skip to the end of an MRI comment field. */
1473 mri_comment_end (char *stop
, int stopc
)
1477 input_line_pointer
= stop
;
1479 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
1480 ++input_line_pointer
;
1484 s_abort (int ignore ATTRIBUTE_UNUSED
)
1486 as_fatal (_(".abort detected. Abandoning ship."));
1489 /* Handle the .align pseudo-op. A positive ARG is a default alignment
1490 (in bytes). A negative ARG is the negative of the length of the
1491 fill pattern. BYTES_P is non-zero if the alignment value should be
1492 interpreted as the byte boundary, rather than the power of 2. */
1493 #ifndef TC_ALIGN_LIMIT
1494 #define TC_ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1498 s_align (signed int arg
, int bytes_p
)
1500 unsigned int align_limit
= TC_ALIGN_LIMIT
;
1509 stop
= mri_comment_field (&stopc
);
1511 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
1516 align
= arg
; /* Default value from pseudo-op table. */
1520 align
= get_absolute_expression ();
1523 #ifdef TC_ALIGN_ZERO_IS_DEFAULT
1524 if (arg
> 0 && align
== 0)
1531 /* Convert to a power of 2. */
1536 for (i
= 0; (align
& 1) == 0; align
>>= 1, ++i
)
1539 as_bad (_("alignment not a power of 2"));
1545 if (align
> align_limit
)
1547 align
= align_limit
;
1548 as_warn (_("alignment too large: %u assumed"), align
);
1551 if (*input_line_pointer
!= ',')
1558 ++input_line_pointer
;
1559 if (*input_line_pointer
== ',')
1563 fill
= get_absolute_expression ();
1568 if (*input_line_pointer
!= ',')
1572 ++input_line_pointer
;
1573 max
= get_absolute_expression ();
1580 as_warn (_("expected fill pattern missing"));
1581 do_align (align
, (char *) NULL
, 0, max
);
1585 unsigned int fill_len
;
1597 do_align (align
, &fill_char
, fill_len
, max
);
1603 if ((size_t) fill_len
> sizeof ab
)
1605 as_warn (_("fill pattern too long, truncating to %u"),
1606 (unsigned) sizeof ab
);
1607 fill_len
= sizeof ab
;
1610 md_number_to_chars (ab
, fill
, fill_len
);
1611 do_align (align
, ab
, fill_len
, max
);
1615 demand_empty_rest_of_line ();
1618 mri_comment_end (stop
, stopc
);
1621 /* Handle the .align pseudo-op on machines where ".align 4" means
1622 align to a 4 byte boundary. */
1625 s_align_bytes (int arg
)
1630 /* Handle the .align pseudo-op on machines where ".align 4" means align
1631 to a 2**4 boundary. */
1634 s_align_ptwo (int arg
)
1639 /* Switch in and out of alternate macro mode. */
1644 demand_empty_rest_of_line ();
1645 macro_set_alternate (on
);
1648 /* Read a symbol name from input_line_pointer.
1650 Stores the symbol name in a buffer and returns a pointer to this buffer.
1651 The buffer is xalloc'ed. It is the caller's responsibility to free
1654 The name is not left in the i_l_p buffer as it may need processing
1655 to handle escape characters.
1657 Advances i_l_p to the next non-whitespace character.
1659 If a symbol name could not be read, the routine issues an error
1660 messages, skips to the end of the line and returns NULL. */
1663 read_symbol_name (void)
1669 c
= *input_line_pointer
++;
1673 #define SYM_NAME_CHUNK_LEN 128
1674 ptrdiff_t len
= SYM_NAME_CHUNK_LEN
;
1678 start
= name
= XNEWVEC (char, len
+ 1);
1680 name_end
= name
+ SYM_NAME_CHUNK_LEN
;
1682 while (is_a_char (C
= next_char_of_string ()))
1684 if (name
>= name_end
)
1688 sofar
= name
- start
;
1689 len
+= SYM_NAME_CHUNK_LEN
;
1690 start
= XRESIZEVEC (char, start
, len
+ 1);
1691 name_end
= start
+ len
;
1692 name
= start
+ sofar
;
1699 /* Since quoted symbol names can contain non-ASCII characters,
1700 check the string and warn if it cannot be recognised by the
1701 current character set. */
1702 if (mbstowcs (NULL
, name
, len
) == (size_t) -1)
1703 as_warn (_("symbol name not recognised in the current locale"));
1705 else if (is_name_beginner (c
) || (input_from_string
&& c
== FAKE_LABEL_CHAR
))
1709 name
= input_line_pointer
- 1;
1711 /* We accept FAKE_LABEL_CHAR in a name in case this is
1712 being called with a constructed string. */
1713 while (is_part_of_name (c
= *input_line_pointer
++)
1714 || (input_from_string
&& c
== FAKE_LABEL_CHAR
))
1717 len
= (input_line_pointer
- name
) - 1;
1718 start
= XNEWVEC (char, len
+ 1);
1720 memcpy (start
, name
, len
);
1723 /* Skip a name ender char if one is present. */
1724 if (! is_name_ender (c
))
1725 --input_line_pointer
;
1728 name
= start
= NULL
;
1732 as_bad (_("expected symbol name"));
1733 ignore_rest_of_line ();
1744 s_comm_internal (int param
,
1745 symbolS
*(*comm_parse_extra
) (int, symbolS
*, addressT
))
1749 symbolS
*symbolP
= NULL
;
1755 stop
= mri_comment_field (&stopc
);
1757 if ((name
= read_symbol_name ()) == NULL
)
1760 /* Accept an optional comma after the name. The comma used to be
1761 required, but Irix 5 cc does not generate it for .lcomm. */
1762 if (*input_line_pointer
== ',')
1763 input_line_pointer
++;
1765 temp
= get_absolute_expr (&exp
);
1767 size
&= ((addressT
) 2 << (stdoutput
->arch_info
->bits_per_address
- 1)) - 1;
1768 if (exp
.X_op
== O_absent
)
1770 as_bad (_("missing size expression"));
1771 ignore_rest_of_line ();
1774 else if (temp
!= size
|| !exp
.X_unsigned
)
1776 as_warn (_("size (%ld) out of range, ignored"), (long) temp
);
1777 ignore_rest_of_line ();
1781 symbolP
= symbol_find_or_make (name
);
1782 if ((S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
1783 && !S_IS_COMMON (symbolP
))
1785 if (!S_IS_VOLATILE (symbolP
))
1788 as_bad (_("symbol `%s' is already defined"), name
);
1789 ignore_rest_of_line ();
1792 symbolP
= symbol_clone (symbolP
, 1);
1793 S_SET_SEGMENT (symbolP
, undefined_section
);
1794 S_SET_VALUE (symbolP
, 0);
1795 symbol_set_frag (symbolP
, &zero_address_frag
);
1796 S_CLEAR_VOLATILE (symbolP
);
1799 size
= S_GET_VALUE (symbolP
);
1802 else if (size
!= temp
)
1803 as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1804 name
, (long) size
, (long) temp
);
1806 if (comm_parse_extra
!= NULL
)
1807 symbolP
= (*comm_parse_extra
) (param
, symbolP
, size
);
1810 S_SET_VALUE (symbolP
, (valueT
) size
);
1811 S_SET_EXTERNAL (symbolP
);
1812 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
1815 demand_empty_rest_of_line ();
1818 mri_comment_end (stop
, stopc
);
1826 s_comm_internal (ignore
, NULL
);
1829 /* The MRI COMMON pseudo-op. We handle this by creating a common
1830 symbol with the appropriate name. We make s_space do the right
1831 thing by increasing the size. */
1834 s_mri_common (int small ATTRIBUTE_UNUSED
)
1850 stop
= mri_comment_field (&stopc
);
1854 name
= input_line_pointer
;
1855 if (!ISDIGIT (*name
))
1856 c
= get_symbol_name (& name
);
1861 ++input_line_pointer
;
1863 while (ISDIGIT (*input_line_pointer
));
1865 c
= *input_line_pointer
;
1866 *input_line_pointer
= '\0';
1868 if (line_label
!= NULL
)
1870 alc
= XNEWVEC (char, strlen (S_GET_NAME (line_label
))
1871 + (input_line_pointer
- name
) + 1);
1872 sprintf (alc
, "%s%s", name
, S_GET_NAME (line_label
));
1877 sym
= symbol_find_or_make (name
);
1878 c
= restore_line_pointer (c
);
1881 if (*input_line_pointer
!= ',')
1885 ++input_line_pointer
;
1886 align
= get_absolute_expression ();
1889 if (S_IS_DEFINED (sym
) && !S_IS_COMMON (sym
))
1891 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym
));
1892 ignore_rest_of_line ();
1893 mri_comment_end (stop
, stopc
);
1897 S_SET_EXTERNAL (sym
);
1898 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
1899 mri_common_symbol
= sym
;
1903 S_SET_ALIGN (sym
, align
);
1908 if (line_label
!= NULL
)
1911 exp
.X_op
= O_symbol
;
1912 exp
.X_add_symbol
= sym
;
1913 exp
.X_add_number
= 0;
1914 symbol_set_value_expression (line_label
, &exp
);
1915 symbol_set_frag (line_label
, &zero_address_frag
);
1916 S_SET_SEGMENT (line_label
, expr_section
);
1919 /* FIXME: We just ignore the small argument, which distinguishes
1920 COMMON and COMMON.S. I don't know what we can do about it. */
1922 /* Ignore the type and hptype. */
1923 if (*input_line_pointer
== ',')
1924 input_line_pointer
+= 2;
1925 if (*input_line_pointer
== ',')
1926 input_line_pointer
+= 2;
1928 demand_empty_rest_of_line ();
1930 mri_comment_end (stop
, stopc
);
1934 s_data (int ignore ATTRIBUTE_UNUSED
)
1939 temp
= get_absolute_expression ();
1940 if (flag_readonly_data_in_text
)
1942 section
= text_section
;
1946 section
= data_section
;
1948 subseg_set (section
, (subsegT
) temp
);
1950 demand_empty_rest_of_line ();
1953 /* Handle the .appfile pseudo-op. This is automatically generated by
1954 do_scrub_chars when a preprocessor # line comment is seen with a
1955 file name. This default definition may be overridden by the object
1956 or CPU specific pseudo-ops. This function is also the default
1957 definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1961 s_app_file_string (char *file
, int appfile ATTRIBUTE_UNUSED
)
1965 listing_source_file (file
);
1967 register_dependency (file
);
1969 obj_app_file (file
, appfile
);
1974 s_app_file (int appfile
)
1979 /* Some assemblers tolerate immediately following '"'. */
1980 if ((s
= demand_copy_string (&length
)) != 0)
1983 = (!new_logical_line_flags (s
, -1, 1) && appfile
);
1985 /* In MRI mode, the preprocessor may have inserted an extraneous
1988 && *input_line_pointer
== '\''
1989 && is_end_of_line
[(unsigned char) input_line_pointer
[1]])
1990 ++input_line_pointer
;
1992 demand_empty_rest_of_line ();
1994 s_app_file_string (s
, appfile
);
1999 get_linefile_number (int *flag
)
2003 if (*input_line_pointer
< '0' || *input_line_pointer
> '9')
2006 *flag
= get_absolute_expression ();
2011 /* Handle the .appline pseudo-op. This is automatically generated by
2012 do_scrub_chars when a preprocessor # line comment is seen. This
2013 default definition may be overridden by the object or CPU specific
2017 s_app_line (int appline
)
2022 /* The given number is that of the next line. */
2024 l
= get_absolute_expression ();
2025 else if (!get_linefile_number (&l
))
2027 ignore_rest_of_line ();
2034 /* Some of the back ends can't deal with non-positive line numbers.
2035 Besides, it's silly. GCC however will generate a line number of
2036 zero when it is pre-processing builtins for assembler-with-cpp files:
2040 We do not want to barf on this, especially since such files are used
2041 in the GCC and GDB testsuites. So we check for negative line numbers
2042 rather than non-positive line numbers. */
2043 as_warn (_("line numbers must be positive; line number %d rejected"),
2054 if (*input_line_pointer
== '"')
2055 file
= demand_copy_string (&length
);
2061 while (get_linefile_number (&this_flag
))
2064 /* From GCC's cpp documentation:
2065 1: start of a new file.
2066 2: returning to a file after having included
2068 3: following text comes from a system header file.
2069 4: following text should be treated as extern "C".
2071 4 is nonsensical for the assembler; 3, we don't
2072 care about, so we ignore it just in case a
2073 system header file is included while
2074 preprocessing assembly. So 1 and 2 are all we
2075 care about, and they are mutually incompatible.
2076 new_logical_line_flags() demands this. */
2079 if (flags
&& flags
!= (1 << this_flag
))
2080 as_warn (_("incompatible flag %i in line directive"),
2083 flags
|= 1 << this_flag
;
2088 /* We ignore these. */
2092 as_warn (_("unsupported flag %i in line directive"),
2097 if (!is_end_of_line
[(unsigned char)*input_line_pointer
])
2102 if (appline
|| file
)
2104 new_logical_line_flags (file
, l
, flags
);
2107 listing_source_line (l
);
2111 if (appline
|| file
)
2112 demand_empty_rest_of_line ();
2114 ignore_rest_of_line ();
2117 /* Handle the .end pseudo-op. Actually, the real work is done in
2118 read_a_source_file. */
2121 s_end (int ignore ATTRIBUTE_UNUSED
)
2125 /* The MRI assembler permits the start symbol to follow .end,
2126 but we don't support that. */
2128 if (!is_end_of_line
[(unsigned char) *input_line_pointer
]
2129 && *input_line_pointer
!= '*'
2130 && *input_line_pointer
!= '!')
2131 as_warn (_("start address not supported"));
2135 /* Handle the .err pseudo-op. */
2138 s_err (int ignore ATTRIBUTE_UNUSED
)
2140 as_bad (_(".err encountered"));
2141 demand_empty_rest_of_line ();
2144 /* Handle the .error and .warning pseudo-ops. */
2150 /* The purpose for the conditional assignment is not to
2151 internationalize the directive itself, but that we need a
2152 self-contained message, one that can be passed like the
2153 demand_copy_C_string return value, and with no assumption on the
2154 location of the name of the directive within the message. */
2156 = (err
? _(".error directive invoked in source file")
2157 : _(".warning directive invoked in source file"));
2159 if (!is_it_end_of_statement ())
2161 if (*input_line_pointer
!= '\"')
2163 as_bad (_("%s argument must be a string"),
2164 err
? ".error" : ".warning");
2165 ignore_rest_of_line ();
2169 msg
= demand_copy_C_string (&len
);
2177 as_warn ("%s", msg
);
2178 demand_empty_rest_of_line ();
2181 /* Handle the MRI fail pseudo-op. */
2184 s_fail (int ignore ATTRIBUTE_UNUSED
)
2191 stop
= mri_comment_field (&stopc
);
2193 temp
= get_absolute_expression ();
2195 as_warn (_(".fail %ld encountered"), (long) temp
);
2197 as_bad (_(".fail %ld encountered"), (long) temp
);
2199 demand_empty_rest_of_line ();
2202 mri_comment_end (stop
, stopc
);
2206 s_fill (int ignore ATTRIBUTE_UNUSED
)
2208 expressionS rep_exp
;
2213 #ifdef md_flush_pending_output
2214 md_flush_pending_output ();
2217 #ifdef md_cons_align
2221 expression (&rep_exp
);
2222 if (*input_line_pointer
== ',')
2224 input_line_pointer
++;
2225 size
= get_absolute_expression ();
2226 if (*input_line_pointer
== ',')
2228 input_line_pointer
++;
2229 fill
= get_absolute_expression ();
2233 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
2234 #define BSD_FILL_SIZE_CROCK_8 (8)
2235 if (size
> BSD_FILL_SIZE_CROCK_8
)
2237 as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8
);
2238 size
= BSD_FILL_SIZE_CROCK_8
;
2242 as_warn (_("size negative; .fill ignored"));
2245 else if (rep_exp
.X_op
== O_constant
&& rep_exp
.X_add_number
<= 0)
2247 if (rep_exp
.X_add_number
< 0)
2248 as_warn (_("repeat < 0; .fill ignored"));
2252 if (size
&& !need_pass_2
)
2254 if (now_seg
== absolute_section
)
2256 if (rep_exp
.X_op
!= O_constant
)
2257 as_bad (_("non-constant fill count for absolute section"));
2258 else if (fill
&& rep_exp
.X_add_number
!= 0)
2259 as_bad (_("attempt to fill absolute section with non-zero value"));
2260 abs_section_offset
+= rep_exp
.X_add_number
* size
;
2263 && (rep_exp
.X_op
!= O_constant
|| rep_exp
.X_add_number
!= 0)
2265 as_bad (_("attempt to fill section `%s' with non-zero value"),
2266 segment_name (now_seg
));
2268 if (rep_exp
.X_op
== O_constant
)
2270 p
= frag_var (rs_fill
, (int) size
, (int) size
,
2271 (relax_substateT
) 0, (symbolS
*) 0,
2272 (offsetT
) rep_exp
.X_add_number
,
2277 /* We don't have a constant repeat count, so we can't use
2278 rs_fill. We can get the same results out of rs_space,
2279 but its argument is in bytes, so we must multiply the
2280 repeat count by size. */
2283 rep_sym
= make_expr_symbol (&rep_exp
);
2286 expressionS size_exp
;
2287 size_exp
.X_op
= O_constant
;
2288 size_exp
.X_add_number
= size
;
2290 rep_exp
.X_op
= O_multiply
;
2291 rep_exp
.X_add_symbol
= rep_sym
;
2292 rep_exp
.X_op_symbol
= make_expr_symbol (&size_exp
);
2293 rep_exp
.X_add_number
= 0;
2294 rep_sym
= make_expr_symbol (&rep_exp
);
2297 p
= frag_var (rs_space
, (int) size
, (int) size
,
2298 (relax_substateT
) 0, rep_sym
, (offsetT
) 0, (char *) 0);
2301 memset (p
, 0, (unsigned int) size
);
2303 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
2304 flavoured AS. The following bizarre behaviour is to be
2305 compatible with above. I guess they tried to take up to 8
2306 bytes from a 4-byte expression and they forgot to sign
2308 #define BSD_FILL_SIZE_CROCK_4 (4)
2309 md_number_to_chars (p
, (valueT
) fill
,
2310 (size
> BSD_FILL_SIZE_CROCK_4
2311 ? BSD_FILL_SIZE_CROCK_4
2313 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
2314 but emits no error message because it seems a legal thing to do.
2315 It is a degenerate case of .fill but could be emitted by a
2318 demand_empty_rest_of_line ();
2322 s_globl (int ignore ATTRIBUTE_UNUSED
)
2331 stop
= mri_comment_field (&stopc
);
2335 if ((name
= read_symbol_name ()) == NULL
)
2338 symbolP
= symbol_find_or_make (name
);
2339 S_SET_EXTERNAL (symbolP
);
2342 c
= *input_line_pointer
;
2345 input_line_pointer
++;
2347 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
2355 demand_empty_rest_of_line ();
2358 mri_comment_end (stop
, stopc
);
2361 /* Handle the MRI IRP and IRPC pseudo-ops. */
2373 file
= as_where (&line
);
2375 eol
= find_end_of_line (input_line_pointer
, 0);
2376 sb_build (&s
, eol
- input_line_pointer
);
2377 sb_add_buffer (&s
, input_line_pointer
, eol
- input_line_pointer
);
2378 input_line_pointer
= eol
;
2382 err
= expand_irp (irpc
, 0, &s
, &out
, get_non_macro_line_sb
);
2384 as_bad_where (file
, line
, "%s", err
);
2388 input_scrub_include_sb (&out
, input_line_pointer
, 1);
2390 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2393 /* Handle the .linkonce pseudo-op. This tells the assembler to mark
2394 the section to only be linked once. However, this is not supported
2395 by most object file formats. This takes an optional argument,
2396 which is what to do about duplicates. */
2399 s_linkonce (int ignore ATTRIBUTE_UNUSED
)
2401 enum linkonce_type type
;
2405 type
= LINKONCE_DISCARD
;
2407 if (!is_end_of_line
[(unsigned char) *input_line_pointer
])
2412 c
= get_symbol_name (& s
);
2413 if (strcasecmp (s
, "discard") == 0)
2414 type
= LINKONCE_DISCARD
;
2415 else if (strcasecmp (s
, "one_only") == 0)
2416 type
= LINKONCE_ONE_ONLY
;
2417 else if (strcasecmp (s
, "same_size") == 0)
2418 type
= LINKONCE_SAME_SIZE
;
2419 else if (strcasecmp (s
, "same_contents") == 0)
2420 type
= LINKONCE_SAME_CONTENTS
;
2422 as_warn (_("unrecognized .linkonce type `%s'"), s
);
2424 (void) restore_line_pointer (c
);
2427 #ifdef obj_handle_link_once
2428 obj_handle_link_once (type
);
2429 #else /* ! defined (obj_handle_link_once) */
2433 if ((bfd_applicable_section_flags (stdoutput
) & SEC_LINK_ONCE
) == 0)
2434 as_warn (_(".linkonce is not supported for this object file format"));
2436 flags
= bfd_section_flags (now_seg
);
2437 flags
|= SEC_LINK_ONCE
;
2442 case LINKONCE_DISCARD
:
2443 flags
|= SEC_LINK_DUPLICATES_DISCARD
;
2445 case LINKONCE_ONE_ONLY
:
2446 flags
|= SEC_LINK_DUPLICATES_ONE_ONLY
;
2448 case LINKONCE_SAME_SIZE
:
2449 flags
|= SEC_LINK_DUPLICATES_SAME_SIZE
;
2451 case LINKONCE_SAME_CONTENTS
:
2452 flags
|= SEC_LINK_DUPLICATES_SAME_CONTENTS
;
2455 if (!bfd_set_section_flags (now_seg
, flags
))
2456 as_bad (_("bfd_set_section_flags: %s"),
2457 bfd_errmsg (bfd_get_error ()));
2459 #endif /* ! defined (obj_handle_link_once) */
2461 demand_empty_rest_of_line ();
2465 bss_alloc (symbolS
*symbolP
, addressT size
, unsigned int align
)
2468 segT current_seg
= now_seg
;
2469 subsegT current_subseg
= now_subseg
;
2470 segT bss_seg
= bss_section
;
2472 #if defined (TC_MIPS) || defined (TC_ALPHA)
2473 if (OUTPUT_FLAVOR
== bfd_target_ecoff_flavour
2474 || OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
2476 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */
2477 if (size
<= bfd_get_gp_size (stdoutput
))
2479 bss_seg
= subseg_new (".sbss", 1);
2480 seg_info (bss_seg
)->bss
= 1;
2481 if (!bfd_set_section_flags (bss_seg
, SEC_ALLOC
| SEC_SMALL_DATA
))
2482 as_warn (_("error setting flags for \".sbss\": %s"),
2483 bfd_errmsg (bfd_get_error ()));
2487 subseg_set (bss_seg
, 1);
2489 if (align
> OCTETS_PER_BYTE_POWER
)
2491 record_alignment (bss_seg
, align
);
2492 frag_align (align
, 0, 0);
2495 /* Detach from old frag. */
2496 if (S_GET_SEGMENT (symbolP
) == bss_seg
)
2497 symbol_get_frag (symbolP
)->fr_symbol
= NULL
;
2499 symbol_set_frag (symbolP
, frag_now
);
2500 pfrag
= frag_var (rs_org
, 1, 1, 0, symbolP
, size
, NULL
);
2504 S_SET_SIZE (symbolP
, size
);
2506 S_SET_SEGMENT (symbolP
, bss_seg
);
2509 /* The symbol may already have been created with a preceding
2510 ".globl" directive -- be careful not to step on storage class
2511 in that case. Otherwise, set it to static. */
2512 if (S_GET_STORAGE_CLASS (symbolP
) != C_EXT
)
2513 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2514 #endif /* OBJ_COFF */
2516 subseg_set (current_seg
, current_subseg
);
2520 parse_align (int align_bytes
)
2526 if (*input_line_pointer
!= ',')
2529 as_bad (_("expected alignment after size"));
2530 ignore_rest_of_line ();
2534 input_line_pointer
++;
2537 align
= get_absolute_expr (&exp
);
2538 if (exp
.X_op
== O_absent
)
2541 if (!exp
.X_unsigned
)
2543 as_warn (_("alignment negative; 0 assumed"));
2547 if (align_bytes
&& align
!= 0)
2549 /* convert to a power of 2 alignment */
2550 unsigned int alignp2
= 0;
2551 while ((align
& 1) == 0)
2552 align
>>= 1, ++alignp2
;
2555 as_bad (_("alignment not a power of 2"));
2556 ignore_rest_of_line ();
2564 /* Called from s_comm_internal after symbol name and size have been
2565 parsed. NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2566 1 if this was a ".bss" directive which has a 3rd argument
2567 (alignment as a power of 2), or 2 if this was a ".bss" directive
2568 with alignment in bytes. */
2571 s_lcomm_internal (int needs_align
, symbolS
*symbolP
, addressT size
)
2577 align
= parse_align (needs_align
- 1);
2578 if (align
== (addressT
) -1)
2582 /* Assume some objects may require alignment on some systems. */
2583 TC_IMPLICIT_LCOMM_ALIGNMENT (size
, align
);
2585 bss_alloc (symbolP
, size
, align
);
2590 s_lcomm (int needs_align
)
2592 s_comm_internal (needs_align
, s_lcomm_internal
);
2596 s_lcomm_bytes (int needs_align
)
2598 s_comm_internal (needs_align
* 2, s_lcomm_internal
);
2602 s_lsym (int ignore ATTRIBUTE_UNUSED
)
2608 /* We permit ANY defined expression: BSD4.2 demands constants. */
2609 if ((name
= read_symbol_name ()) == NULL
)
2612 if (*input_line_pointer
!= ',')
2614 as_bad (_("expected comma after \"%s\""), name
);
2618 input_line_pointer
++;
2619 expression_and_evaluate (&exp
);
2621 if (exp
.X_op
!= O_constant
2622 && exp
.X_op
!= O_register
)
2624 as_bad (_("bad expression"));
2628 symbolP
= symbol_find_or_make (name
);
2630 if (S_GET_SEGMENT (symbolP
) == undefined_section
)
2632 /* The name might be an undefined .global symbol; be sure to
2633 keep the "external" bit. */
2634 S_SET_SEGMENT (symbolP
,
2635 (exp
.X_op
== O_constant
2638 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
2642 as_bad (_("symbol `%s' is already defined"), name
);
2645 demand_empty_rest_of_line ();
2650 ignore_rest_of_line ();
2655 /* Read a line into an sb. Returns the character that ended the line
2656 or zero if there are no more lines. */
2659 get_line_sb (sb
*line
, int in_macro
)
2663 if (input_line_pointer
[-1] == '\n')
2664 bump_line_counters ();
2666 if (input_line_pointer
>= buffer_limit
)
2668 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2669 if (buffer_limit
== 0)
2673 eol
= _find_end_of_line (input_line_pointer
, flag_m68k_mri
, 0, in_macro
);
2674 sb_add_buffer (line
, input_line_pointer
, eol
- input_line_pointer
);
2675 input_line_pointer
= eol
;
2677 /* Don't skip multiple end-of-line characters, because that breaks support
2678 for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2679 characters but isn't. Instead just skip one end of line character and
2680 return the character skipped so that the caller can re-insert it if
2682 return *input_line_pointer
++;
2686 get_non_macro_line_sb (sb
*line
)
2688 return get_line_sb (line
, 0);
2692 get_macro_line_sb (sb
*line
)
2694 return get_line_sb (line
, 1);
2697 /* Define a macro. This is an interface to macro.c. */
2700 s_macro (int ignore ATTRIBUTE_UNUSED
)
2709 file
= as_where (&line
);
2711 eol
= find_end_of_line (input_line_pointer
, 0);
2712 sb_build (&s
, eol
- input_line_pointer
);
2713 sb_add_buffer (&s
, input_line_pointer
, eol
- input_line_pointer
);
2714 input_line_pointer
= eol
;
2716 if (line_label
!= NULL
)
2721 name
= S_GET_NAME (line_label
);
2722 len
= strlen (name
);
2723 sb_build (&label
, len
);
2724 sb_add_buffer (&label
, name
, len
);
2725 err
= define_macro (0, &s
, &label
, get_macro_line_sb
, file
, line
, &name
);
2729 err
= define_macro (0, &s
, NULL
, get_macro_line_sb
, file
, line
, &name
);
2731 as_bad_where (file
, line
, err
, name
);
2734 if (line_label
!= NULL
)
2736 S_SET_SEGMENT (line_label
, absolute_section
);
2737 S_SET_VALUE (line_label
, 0);
2738 symbol_set_frag (line_label
, &zero_address_frag
);
2741 if (((NO_PSEUDO_DOT
|| flag_m68k_mri
)
2742 && hash_find (po_hash
, name
) != NULL
)
2745 && hash_find (po_hash
, name
+ 1) != NULL
))
2746 as_warn_where (file
,
2748 _("attempt to redefine pseudo-op `%s' ignored"),
2755 /* Handle the .mexit pseudo-op, which immediately exits a macro
2759 s_mexit (int ignore ATTRIBUTE_UNUSED
)
2763 cond_exit_macro (macro_nest
);
2764 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
2767 as_warn (_("ignoring macro exit outside a macro definition."));
2770 /* Switch in and out of MRI mode. */
2773 s_mri (int ignore ATTRIBUTE_UNUSED
)
2776 #ifdef MRI_MODE_CHANGE
2780 on
= get_absolute_expression ();
2781 #ifdef MRI_MODE_CHANGE
2782 old_flag
= flag_mri
;
2801 /* Operator precedence changes in m68k MRI mode, so we need to
2802 update the operator rankings. */
2803 expr_set_precedence ();
2805 #ifdef MRI_MODE_CHANGE
2807 MRI_MODE_CHANGE (on
);
2810 demand_empty_rest_of_line ();
2813 /* Handle changing the location counter. */
2816 do_org (segT segment
, expressionS
*exp
, int fill
)
2818 if (segment
!= now_seg
2819 && segment
!= absolute_section
2820 && segment
!= expr_section
)
2821 as_bad (_("invalid segment \"%s\""), segment_name (segment
));
2823 if (now_seg
== absolute_section
)
2826 as_warn (_("ignoring fill value in absolute section"));
2827 if (exp
->X_op
!= O_constant
)
2829 as_bad (_("only constant offsets supported in absolute section"));
2830 exp
->X_add_number
= 0;
2832 abs_section_offset
= exp
->X_add_number
;
2837 symbolS
*sym
= exp
->X_add_symbol
;
2838 offsetT off
= exp
->X_add_number
* OCTETS_PER_BYTE
;
2840 if (fill
&& in_bss ())
2841 as_warn (_("ignoring fill value in section `%s'"),
2842 segment_name (now_seg
));
2844 if (exp
->X_op
!= O_constant
&& exp
->X_op
!= O_symbol
)
2846 /* Handle complex expressions. */
2847 sym
= make_expr_symbol (exp
);
2851 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, sym
, off
, (char *) 0);
2857 s_org (int ignore ATTRIBUTE_UNUSED
)
2863 #ifdef md_flush_pending_output
2864 md_flush_pending_output ();
2867 /* The m68k MRI assembler has a different meaning for .org. It
2868 means to create an absolute section at a given address. We can't
2869 support that--use a linker script instead. */
2872 as_bad (_("MRI style ORG pseudo-op not supported"));
2873 ignore_rest_of_line ();
2877 /* Don't believe the documentation of BSD 4.2 AS. There is no such
2878 thing as a sub-segment-relative origin. Any absolute origin is
2879 given a warning, then assumed to be segment-relative. Any
2880 segmented origin expression ("foo+42") had better be in the right
2881 segment or the .org is ignored.
2883 BSD 4.2 AS warns if you try to .org backwards. We cannot because
2884 we never know sub-segment sizes when we are reading code. BSD
2885 will crash trying to emit negative numbers of filler bytes in
2886 certain .orgs. We don't crash, but see as-write for that code.
2888 Don't make frag if need_pass_2==1. */
2889 segment
= get_known_segmented_expression (&exp
);
2890 if (*input_line_pointer
== ',')
2892 input_line_pointer
++;
2893 temp_fill
= get_absolute_expression ();
2899 do_org (segment
, &exp
, temp_fill
);
2901 demand_empty_rest_of_line ();
2904 /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be
2905 called by the obj-format routine which handles section changing
2906 when in MRI mode. It will create a new section, and return it. It
2907 will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2908 'M' (mixed), or 'R' (romable). The flags will be set in the section. */
2911 s_mri_sect (char *type ATTRIBUTE_UNUSED
)
2921 name
= input_line_pointer
;
2922 if (!ISDIGIT (*name
))
2923 c
= get_symbol_name (& name
);
2928 ++input_line_pointer
;
2930 while (ISDIGIT (*input_line_pointer
));
2932 c
= *input_line_pointer
;
2933 *input_line_pointer
= '\0';
2936 name
= xstrdup (name
);
2938 c
= restore_line_pointer (c
);
2940 seg
= subseg_new (name
, 0);
2946 ++input_line_pointer
;
2947 align
= get_absolute_expression ();
2948 record_alignment (seg
, align
);
2952 if (*input_line_pointer
== ',')
2954 c
= *++input_line_pointer
;
2956 if (c
== 'C' || c
== 'D' || c
== 'M' || c
== 'R')
2959 as_bad (_("unrecognized section type"));
2960 ++input_line_pointer
;
2965 flags
= SEC_NO_FLAGS
;
2967 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
;
2968 else if (*type
== 'D' || *type
== 'M')
2969 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
;
2970 else if (*type
== 'R')
2971 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_DATA
| SEC_READONLY
| SEC_ROM
;
2972 if (flags
!= SEC_NO_FLAGS
)
2974 if (!bfd_set_section_flags (seg
, flags
))
2975 as_warn (_("error setting flags for \"%s\": %s"),
2976 bfd_section_name (seg
),
2977 bfd_errmsg (bfd_get_error ()));
2982 /* Ignore the HP type. */
2983 if (*input_line_pointer
== ',')
2984 input_line_pointer
+= 2;
2986 demand_empty_rest_of_line ();
2988 #else /* ! TC_M68K */
2989 /* The MRI assembler seems to use different forms of .sect for
2990 different targets. */
2991 as_bad ("MRI mode not supported for this target");
2992 ignore_rest_of_line ();
2993 #endif /* ! TC_M68K */
2996 /* Handle the .print pseudo-op. */
2999 s_print (int ignore ATTRIBUTE_UNUSED
)
3004 s
= demand_copy_C_string (&len
);
3007 demand_empty_rest_of_line ();
3010 /* Handle the .purgem pseudo-op. */
3013 s_purgem (int ignore ATTRIBUTE_UNUSED
)
3015 if (is_it_end_of_statement ())
3017 demand_empty_rest_of_line ();
3027 c
= get_symbol_name (& name
);
3028 delete_macro (name
);
3029 *input_line_pointer
= c
;
3030 SKIP_WHITESPACE_AFTER_NAME ();
3032 while (*input_line_pointer
++ == ',');
3034 --input_line_pointer
;
3035 demand_empty_rest_of_line ();
3038 /* Handle the .endm/.endr pseudo-ops. */
3041 s_bad_end (int endr
)
3043 as_warn (_(".end%c encountered without preceding %s"),
3045 endr
? ".rept, .irp, or .irpc" : ".macro");
3046 demand_empty_rest_of_line ();
3049 /* Handle the .rept pseudo-op. */
3052 s_rept (int ignore ATTRIBUTE_UNUSED
)
3056 count
= (size_t) get_absolute_expression ();
3058 do_repeat (count
, "REPT", "ENDR");
3061 /* This function provides a generic repeat block implementation. It allows
3062 different directives to be used as the start/end keys. */
3065 do_repeat (size_t count
, const char *start
, const char *end
)
3070 if (((ssize_t
) count
) < 0)
3072 as_bad (_("negative count for %s - ignored"), start
);
3077 if (!buffer_and_nest (start
, end
, &one
, get_non_macro_line_sb
))
3079 as_bad (_("%s without %s"), start
, end
);
3083 sb_build (&many
, count
* one
.len
);
3085 sb_add_sb (&many
, &one
);
3089 input_scrub_include_sb (&many
, input_line_pointer
, 1);
3091 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
3094 /* Like do_repeat except that any text matching EXPANDER in the
3095 block is replaced by the iteration count. */
3098 do_repeat_with_expander (size_t count
,
3101 const char * expander
)
3106 if (((ssize_t
) count
) < 0)
3108 as_bad (_("negative count for %s - ignored"), start
);
3113 if (!buffer_and_nest (start
, end
, &one
, get_non_macro_line_sb
))
3115 as_bad (_("%s without %s"), start
, end
);
3121 if (expander
!= NULL
&& strstr (one
.ptr
, expander
) != NULL
)
3123 while (count
-- > 0)
3129 sb_build (& processed
, one
.len
);
3130 sb_add_sb (& processed
, & one
);
3131 sub
= strstr (processed
.ptr
, expander
);
3132 len
= sprintf (sub
, "%lu", (unsigned long) count
);
3133 gas_assert (len
< 8);
3134 memmove (sub
+ len
, sub
+ 8,
3135 processed
.ptr
+ processed
.len
- (sub
+ 8));
3136 processed
.len
-= (8 - len
);
3137 sb_add_sb (& many
, & processed
);
3138 sb_kill (& processed
);
3143 sb_add_sb (&many
, &one
);
3147 input_scrub_include_sb (&many
, input_line_pointer
, 1);
3149 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
3152 /* Skip to end of current repeat loop; EXTRA indicates how many additional
3153 input buffers to skip. Assumes that conditionals preceding the loop end
3154 are properly nested.
3156 This function makes it easier to implement a premature "break" out of the
3157 loop. The EXTRA arg accounts for other buffers we might have inserted,
3158 such as line substitutions. */
3161 end_repeat (int extra
)
3163 cond_exit_macro (macro_nest
);
3164 while (extra
-- >= 0)
3165 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
3169 assign_symbol (char *name
, int mode
)
3173 if (name
[0] == '.' && name
[1] == '\0')
3175 /* Turn '. = mumble' into a .org mumble. */
3179 segment
= get_known_segmented_expression (&exp
);
3182 do_org (segment
, &exp
, 0);
3187 if ((symbolP
= symbol_find (name
)) == NULL
3188 && (symbolP
= md_undefined_symbol (name
)) == NULL
)
3190 symbolP
= symbol_find_or_make (name
);
3192 /* When doing symbol listings, play games with dummy fragments living
3193 outside the normal fragment chain to record the file and line info
3195 if (listing
& LISTING_SYMBOLS
)
3197 extern struct list_info_struct
*listing_tail
;
3198 fragS
*dummy_frag
= XCNEW (fragS
);
3199 dummy_frag
->line
= listing_tail
;
3200 dummy_frag
->fr_symbol
= symbolP
;
3201 symbol_set_frag (symbolP
, dummy_frag
);
3204 #if defined (OBJ_COFF) && !defined (TE_PE)
3205 /* "set" symbols are local unless otherwise specified. */
3206 SF_SET_LOCAL (symbolP
);
3210 if (S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
3212 if ((mode
!= 0 || !S_IS_VOLATILE (symbolP
))
3213 && !S_CAN_BE_REDEFINED (symbolP
))
3215 as_bad (_("symbol `%s' is already defined"), name
);
3216 ignore_rest_of_line ();
3217 input_line_pointer
--;
3220 /* If the symbol is volatile, copy the symbol and replace the
3221 original with the copy, so that previous uses of the symbol will
3222 retain the value of the symbol at the point of use. */
3223 else if (S_IS_VOLATILE (symbolP
))
3224 symbolP
= symbol_clone (symbolP
, 1);
3228 S_SET_VOLATILE (symbolP
);
3230 S_SET_FORWARD_REF (symbolP
);
3232 pseudo_set (symbolP
);
3235 /* Handle the .equ, .equiv, .eqv, and .set directives. If EQUIV is 1,
3236 then this is .equiv, and it is an error if the symbol is already
3237 defined. If EQUIV is -1, the symbol additionally is a forward
3245 /* Especial apologies for the random logic:
3246 this just grew, and could be parsed much more simply!
3248 if ((name
= read_symbol_name ()) == NULL
)
3251 if (*input_line_pointer
!= ',')
3253 as_bad (_("expected comma after \"%s\""), name
);
3254 ignore_rest_of_line ();
3259 input_line_pointer
++;
3260 assign_symbol (name
, equiv
);
3261 demand_empty_rest_of_line ();
3275 #ifdef md_flush_pending_output
3276 md_flush_pending_output ();
3279 #ifdef md_cons_align
3284 stop
= mri_comment_field (&stopc
);
3286 /* In m68k MRI mode, we need to align to a word boundary, unless
3288 if (flag_m68k_mri
&& mult
> 1)
3290 if (now_seg
== absolute_section
)
3292 abs_section_offset
+= abs_section_offset
& 1;
3293 if (line_label
!= NULL
)
3294 S_SET_VALUE (line_label
, abs_section_offset
);
3296 else if (mri_common_symbol
!= NULL
)
3300 mri_val
= S_GET_VALUE (mri_common_symbol
);
3301 if ((mri_val
& 1) != 0)
3303 S_SET_VALUE (mri_common_symbol
, mri_val
+ 1);
3304 if (line_label
!= NULL
)
3306 expressionS
*symexp
;
3308 symexp
= symbol_get_value_expression (line_label
);
3309 know (symexp
->X_op
== O_symbol
);
3310 know (symexp
->X_add_symbol
== mri_common_symbol
);
3311 symexp
->X_add_number
+= 1;
3317 do_align (1, (char *) NULL
, 0, 0);
3318 if (line_label
!= NULL
)
3320 symbol_set_frag (line_label
, frag_now
);
3321 S_SET_VALUE (line_label
, frag_now_fix ());
3331 if (*input_line_pointer
== ',')
3333 ++input_line_pointer
;
3338 val
.X_op
= O_constant
;
3339 val
.X_add_number
= 0;
3342 if ((val
.X_op
!= O_constant
3343 || val
.X_add_number
< - 0x80
3344 || val
.X_add_number
> 0xff
3345 || (mult
!= 0 && mult
!= 1 && val
.X_add_number
!= 0))
3346 && (now_seg
!= absolute_section
&& !in_bss ()))
3348 resolve_expression (&exp
);
3349 if (exp
.X_op
!= O_constant
)
3350 as_bad (_("unsupported variable size or fill value"));
3355 /* PR 20901: Check for excessive values.
3356 FIXME: 1<<10 is an arbitrary limit. Maybe use maxpagesize instead ? */
3357 if (exp
.X_add_number
< 0 || exp
.X_add_number
> (1 << 10))
3358 as_bad (_("size value for space directive too large: %lx"),
3359 (long) exp
.X_add_number
);
3364 bytes
= mult
* exp
.X_add_number
;
3366 for (i
= 0; i
< exp
.X_add_number
; i
++)
3367 emit_expr (&val
, mult
);
3373 if (now_seg
== absolute_section
|| mri_common_symbol
!= NULL
)
3374 resolve_expression (&exp
);
3376 if (exp
.X_op
== O_constant
)
3380 repeat
= exp
.X_add_number
;
3387 as_warn (_(".space repeat count is zero, ignored"));
3388 else if (repeat
< 0)
3389 as_warn (_(".space repeat count is negative, ignored"));
3393 /* If we are in the absolute section, just bump the offset. */
3394 if (now_seg
== absolute_section
)
3396 if (val
.X_op
!= O_constant
|| val
.X_add_number
!= 0)
3397 as_warn (_("ignoring fill value in absolute section"));
3398 abs_section_offset
+= repeat
;
3402 /* If we are secretly in an MRI common section, then
3403 creating space just increases the size of the common
3405 if (mri_common_symbol
!= NULL
)
3407 S_SET_VALUE (mri_common_symbol
,
3408 S_GET_VALUE (mri_common_symbol
) + repeat
);
3413 p
= frag_var (rs_fill
, 1, 1, (relax_substateT
) 0, (symbolS
*) 0,
3414 (offsetT
) repeat
, (char *) 0);
3418 if (now_seg
== absolute_section
)
3420 as_bad (_("space allocation too complex in absolute section"));
3421 subseg_set (text_section
, 0);
3424 if (mri_common_symbol
!= NULL
)
3426 as_bad (_("space allocation too complex in common section"));
3427 mri_common_symbol
= NULL
;
3431 p
= frag_var (rs_space
, 1, 1, (relax_substateT
) 0,
3432 make_expr_symbol (&exp
), (offsetT
) 0, (char *) 0);
3435 if ((val
.X_op
!= O_constant
|| val
.X_add_number
!= 0) && in_bss ())
3436 as_warn (_("ignoring fill value in section `%s'"),
3437 segment_name (now_seg
));
3439 *p
= val
.X_add_number
;
3444 /* In MRI mode, after an odd number of bytes, we must align to an
3445 even word boundary, unless the next instruction is a dc.b, ds.b
3447 if (flag_mri
&& (bytes
& 1) != 0)
3448 mri_pending_align
= 1;
3450 demand_empty_rest_of_line ();
3453 mri_comment_end (stop
, stopc
);
3457 s_nops (int ignore ATTRIBUTE_UNUSED
)
3462 #ifdef md_flush_pending_output
3463 md_flush_pending_output ();
3466 #ifdef md_cons_align
3472 if (*input_line_pointer
== ',')
3474 ++input_line_pointer
;
3479 val
.X_op
= O_constant
;
3480 val
.X_add_number
= 0;
3483 if (val
.X_op
== O_constant
)
3485 if (val
.X_add_number
< 0)
3487 as_warn (_("negative nop control byte, ignored"));
3488 val
.X_add_number
= 0;
3493 /* Store the no-op instruction control byte in the first byte
3496 symbolS
*sym
= make_expr_symbol (&exp
);
3497 p
= frag_var (rs_space_nop
, 1, 1, (relax_substateT
) 0,
3498 sym
, (offsetT
) 0, (char *) 0);
3499 *p
= val
.X_add_number
;
3503 as_bad (_("unsupported variable nop control in .nops directive"));
3505 demand_empty_rest_of_line ();
3508 /* This is like s_space, but the value is a floating point number with
3509 the given precision. This is for the MRI dcb.s pseudo-op and
3513 s_float_space (int float_type
)
3517 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
3521 #ifdef md_cons_align
3526 stop
= mri_comment_field (&stopc
);
3528 count
= get_absolute_expression ();
3531 if (*input_line_pointer
!= ',')
3533 as_bad (_("missing value"));
3534 ignore_rest_of_line ();
3536 mri_comment_end (stop
, stopc
);
3540 ++input_line_pointer
;
3544 /* Skip any 0{letter} that may be present. Don't even check if the
3545 * letter is legal. */
3546 if (input_line_pointer
[0] == '0'
3547 && ISALPHA (input_line_pointer
[1]))
3548 input_line_pointer
+= 2;
3550 /* Accept :xxxx, where the x's are hex digits, for a floating point
3551 with the exact digits specified. */
3552 if (input_line_pointer
[0] == ':')
3554 flen
= hex_float (float_type
, temp
);
3557 ignore_rest_of_line ();
3559 mri_comment_end (stop
, stopc
);
3567 err
= md_atof (float_type
, temp
, &flen
);
3568 know (flen
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
3569 know (err
!= NULL
|| flen
> 0);
3572 as_bad (_("bad floating literal: %s"), err
);
3573 ignore_rest_of_line ();
3575 mri_comment_end (stop
, stopc
);
3580 while (--count
>= 0)
3584 p
= frag_more (flen
);
3585 memcpy (p
, temp
, (unsigned int) flen
);
3588 demand_empty_rest_of_line ();
3591 mri_comment_end (stop
, stopc
);
3594 /* Handle the .struct pseudo-op, as found in MIPS assemblers. */
3597 s_struct (int ignore ATTRIBUTE_UNUSED
)
3603 stop
= mri_comment_field (&stopc
);
3604 abs_section_offset
= get_absolute_expression ();
3605 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3606 /* The ELF backend needs to know that we are changing sections, so
3607 that .previous works correctly. */
3609 obj_elf_section_change_hook ();
3611 subseg_set (absolute_section
, 0);
3612 demand_empty_rest_of_line ();
3614 mri_comment_end (stop
, stopc
);
3618 s_text (int ignore ATTRIBUTE_UNUSED
)
3622 temp
= get_absolute_expression ();
3623 subseg_set (text_section
, (subsegT
) temp
);
3624 demand_empty_rest_of_line ();
3627 /* .weakref x, y sets x as an alias to y that, as long as y is not
3628 referenced directly, will cause y to become a weak symbol. */
3630 s_weakref (int ignore ATTRIBUTE_UNUSED
)
3637 if ((name
= read_symbol_name ()) == NULL
)
3640 symbolP
= symbol_find_or_make (name
);
3642 if (S_IS_DEFINED (symbolP
) || symbol_equated_p (symbolP
))
3644 if (!S_IS_VOLATILE (symbolP
))
3646 as_bad (_("symbol `%s' is already defined"), name
);
3649 symbolP
= symbol_clone (symbolP
, 1);
3650 S_CLEAR_VOLATILE (symbolP
);
3655 if (*input_line_pointer
!= ',')
3657 as_bad (_("expected comma after \"%s\""), name
);
3661 input_line_pointer
++;
3666 if ((name
= read_symbol_name ()) == NULL
)
3669 if ((symbolP2
= symbol_find_noref (name
, 1)) == NULL
3670 && (symbolP2
= md_undefined_symbol (name
)) == NULL
)
3672 symbolP2
= symbol_find_or_make (name
);
3673 S_SET_WEAKREFD (symbolP2
);
3677 symbolS
*symp
= symbolP2
;
3679 while (S_IS_WEAKREFR (symp
) && symp
!= symbolP
)
3681 expressionS
*expP
= symbol_get_value_expression (symp
);
3683 gas_assert (expP
->X_op
== O_symbol
3684 && expP
->X_add_number
== 0);
3685 symp
= expP
->X_add_symbol
;
3687 if (symp
== symbolP
)
3691 loop
= concat (S_GET_NAME (symbolP
),
3692 " => ", S_GET_NAME (symbolP2
), (const char *) NULL
);
3695 while (symp
!= symbolP
)
3697 char *old_loop
= loop
;
3699 symp
= symbol_get_value_expression (symp
)->X_add_symbol
;
3700 loop
= concat (loop
, " => ", S_GET_NAME (symp
),
3701 (const char *) NULL
);
3705 as_bad (_("%s: would close weakref loop: %s"),
3706 S_GET_NAME (symbolP
), loop
);
3710 ignore_rest_of_line ();
3714 /* Short-circuiting instead of just checking here might speed
3715 things up a tiny little bit, but loop error messages would
3716 miss intermediate links. */
3717 /* symbolP2 = symp; */
3720 memset (&exp
, 0, sizeof (exp
));
3721 exp
.X_op
= O_symbol
;
3722 exp
.X_add_symbol
= symbolP2
;
3724 S_SET_SEGMENT (symbolP
, undefined_section
);
3725 symbol_set_value_expression (symbolP
, &exp
);
3726 symbol_set_frag (symbolP
, &zero_address_frag
);
3727 S_SET_WEAKREFR (symbolP
);
3729 demand_empty_rest_of_line ();
3734 ignore_rest_of_line ();
3740 /* Verify that we are at the end of a line. If not, issue an error and
3744 demand_empty_rest_of_line (void)
3747 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
3748 input_line_pointer
++;
3751 if (ISPRINT (*input_line_pointer
))
3752 as_bad (_("junk at end of line, first unrecognized character is `%c'"),
3753 *input_line_pointer
);
3755 as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
3756 *input_line_pointer
);
3757 ignore_rest_of_line ();
3760 /* Return pointing just after end-of-line. */
3761 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
3764 /* Silently advance to the end of line. Use this after already having
3765 issued an error about something bad. */
3768 ignore_rest_of_line (void)
3770 while (input_line_pointer
< buffer_limit
3771 && !is_end_of_line
[(unsigned char) *input_line_pointer
])
3772 input_line_pointer
++;
3774 input_line_pointer
++;
3776 /* Return pointing just after end-of-line. */
3777 if (input_line_pointer
<= buffer_limit
)
3778 know (is_end_of_line
[(unsigned char) input_line_pointer
[-1]]);
3781 /* Sets frag for given symbol to zero_address_frag, except when the
3782 symbol frag is already set to a dummy listing frag. */
3785 set_zero_frag (symbolS
*symbolP
)
3787 if (symbol_get_frag (symbolP
)->fr_type
!= rs_dummy
)
3788 symbol_set_frag (symbolP
, &zero_address_frag
);
3791 /* In: Pointer to a symbol.
3792 Input_line_pointer->expression.
3794 Out: Input_line_pointer->just after any whitespace after expression.
3795 Tried to set symbol to value of expression.
3796 Will change symbols type, value, and frag; */
3799 pseudo_set (symbolS
*symbolP
)
3804 know (symbolP
); /* NULL pointer is logic error. */
3806 if (!S_IS_FORWARD_REF (symbolP
))
3807 (void) expression (&exp
);
3809 (void) deferred_expression (&exp
);
3811 if (exp
.X_op
== O_illegal
)
3812 as_bad (_("illegal expression"));
3813 else if (exp
.X_op
== O_absent
)
3814 as_bad (_("missing expression"));
3815 else if (exp
.X_op
== O_big
)
3817 if (exp
.X_add_number
> 0)
3818 as_bad (_("bignum invalid"));
3820 as_bad (_("floating point number invalid"));
3822 else if (exp
.X_op
== O_subtract
3823 && !S_IS_FORWARD_REF (symbolP
)
3824 && SEG_NORMAL (S_GET_SEGMENT (exp
.X_add_symbol
))
3825 && (symbol_get_frag (exp
.X_add_symbol
)
3826 == symbol_get_frag (exp
.X_op_symbol
)))
3828 exp
.X_op
= O_constant
;
3829 exp
.X_add_number
= (S_GET_VALUE (exp
.X_add_symbol
)
3830 - S_GET_VALUE (exp
.X_op_symbol
));
3833 if (symbol_section_p (symbolP
))
3835 as_bad ("attempt to set value of section symbol");
3844 exp
.X_add_number
= 0;
3847 S_SET_SEGMENT (symbolP
, absolute_section
);
3848 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
3849 set_zero_frag (symbolP
);
3853 #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
3854 if (S_IS_EXTERNAL (symbolP
))
3856 as_bad ("can't equate global symbol `%s' with register name",
3857 S_GET_NAME (symbolP
));
3861 S_SET_SEGMENT (symbolP
, reg_section
);
3862 S_SET_VALUE (symbolP
, (valueT
) exp
.X_add_number
);
3863 set_zero_frag (symbolP
);
3864 symbol_get_value_expression (symbolP
)->X_op
= O_register
;
3868 seg
= S_GET_SEGMENT (exp
.X_add_symbol
);
3869 /* For x=undef+const, create an expression symbol.
3870 For x=x+const, just update x except when x is an undefined symbol
3871 For x=defined+const, evaluate x. */
3872 if (symbolP
== exp
.X_add_symbol
3873 && (seg
!= undefined_section
3874 || !symbol_constant_p (symbolP
)))
3876 *symbol_X_add_number (symbolP
) += exp
.X_add_number
;
3879 else if (!S_IS_FORWARD_REF (symbolP
) && seg
!= undefined_section
)
3881 symbolS
*s
= exp
.X_add_symbol
;
3883 if (S_IS_COMMON (s
))
3884 as_bad (_("`%s' can't be equated to common symbol `%s'"),
3885 S_GET_NAME (symbolP
), S_GET_NAME (s
));
3887 S_SET_SEGMENT (symbolP
, seg
);
3888 S_SET_VALUE (symbolP
, exp
.X_add_number
+ S_GET_VALUE (s
));
3889 symbol_set_frag (symbolP
, symbol_get_frag (s
));
3890 copy_symbol_attributes (symbolP
, s
);
3893 S_SET_SEGMENT (symbolP
, undefined_section
);
3894 symbol_set_value_expression (symbolP
, &exp
);
3895 copy_symbol_attributes (symbolP
, exp
.X_add_symbol
);
3896 set_zero_frag (symbolP
);
3900 /* The value is some complex expression. */
3901 S_SET_SEGMENT (symbolP
, expr_section
);
3902 symbol_set_value_expression (symbolP
, &exp
);
3903 set_zero_frag (symbolP
);
3910 CONStruct more frag of .bytes, or .words etc.
3911 Should need_pass_2 be 1 then emit no frag(s).
3912 This understands EXPRESSIONS.
3916 This has a split personality. We use expression() to read the
3917 value. We can detect if the value won't fit in a byte or word.
3918 But we can't detect if expression() discarded significant digits
3919 in the case of a long. Not worth the crocks required to fix it. */
3921 /* Select a parser for cons expressions. */
3923 /* Some targets need to parse the expression in various fancy ways.
3924 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3925 (for example, the HPPA does this). Otherwise, you can define
3926 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
3927 are defined, which is the normal case, then only simple expressions
3932 parse_mri_cons (expressionS
*exp
, unsigned int nbytes
);
3935 #ifndef TC_PARSE_CONS_EXPRESSION
3936 #ifdef REPEAT_CONS_EXPRESSIONS
3937 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
3938 (parse_repeat_cons (EXP, NBYTES), TC_PARSE_CONS_RETURN_NONE)
3940 parse_repeat_cons (expressionS
*exp
, unsigned int nbytes
);
3943 /* If we haven't gotten one yet, just call expression. */
3944 #ifndef TC_PARSE_CONS_EXPRESSION
3945 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
3946 (expression (EXP), TC_PARSE_CONS_RETURN_NONE)
3951 do_parse_cons_expression (expressionS
*exp
,
3952 int nbytes ATTRIBUTE_UNUSED
)
3954 (void) TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
3958 /* Worker to do .byte etc statements.
3959 Clobbers input_line_pointer and checks end-of-line. */
3962 cons_worker (int nbytes
, /* 1=.byte, 2=.word, 4=.long. */
3970 #ifdef md_flush_pending_output
3971 md_flush_pending_output ();
3975 stop
= mri_comment_field (&stopc
);
3977 if (is_it_end_of_statement ())
3979 demand_empty_rest_of_line ();
3981 mri_comment_end (stop
, stopc
);
3985 #ifdef TC_ADDRESS_BYTES
3987 nbytes
= TC_ADDRESS_BYTES ();
3990 #ifdef md_cons_align
3991 md_cons_align (nbytes
);
3997 TC_PARSE_CONS_RETURN_TYPE ret
= TC_PARSE_CONS_RETURN_NONE
;
3998 #ifdef TC_CONS_FIX_CHECK
3999 fixS
**cur_fix
= &frchain_now
->fix_tail
;
4001 if (*cur_fix
!= NULL
)
4002 cur_fix
= &(*cur_fix
)->fx_next
;
4007 parse_mri_cons (&exp
, (unsigned int) nbytes
);
4012 if (*input_line_pointer
== '"')
4014 as_bad (_("unexpected `\"' in expression"));
4015 ignore_rest_of_line ();
4019 ret
= TC_PARSE_CONS_EXPRESSION (&exp
, (unsigned int) nbytes
);
4024 if (exp
.X_op
== O_symbol
)
4025 exp
.X_op
= O_symbol_rva
;
4027 as_fatal (_("rva without symbol"));
4029 emit_expr_with_reloc (&exp
, (unsigned int) nbytes
, ret
);
4030 #ifdef TC_CONS_FIX_CHECK
4031 TC_CONS_FIX_CHECK (&exp
, nbytes
, *cur_fix
);
4035 while (*input_line_pointer
++ == ',');
4037 /* In MRI mode, after an odd number of bytes, we must align to an
4038 even word boundary, unless the next instruction is a dc.b, ds.b
4040 if (flag_mri
&& nbytes
== 1 && (c
& 1) != 0)
4041 mri_pending_align
= 1;
4043 input_line_pointer
--; /* Put terminator back into stream. */
4045 demand_empty_rest_of_line ();
4048 mri_comment_end (stop
, stopc
);
4054 cons_worker (size
, 0);
4060 cons_worker (size
, 1);
4063 /* .reloc offset, reloc_name, symbol+addend. */
4066 s_reloc (int ignore ATTRIBUTE_UNUSED
)
4073 struct reloc_list
*reloc
;
4074 struct _bfd_rel
{ const char * name
; bfd_reloc_code_real_type code
; };
4075 static struct _bfd_rel bfd_relocs
[] =
4077 { "NONE", BFD_RELOC_NONE
},
4078 { "8", BFD_RELOC_8
},
4079 { "16", BFD_RELOC_16
},
4080 { "32", BFD_RELOC_32
},
4081 { "64", BFD_RELOC_64
}
4084 reloc
= XNEW (struct reloc_list
);
4087 stop
= mri_comment_field (&stopc
);
4096 as_bad (_("missing or bad offset expression"));
4099 exp
.X_add_symbol
= section_symbol (now_seg
);
4100 exp
.X_op
= O_symbol
;
4103 if (exp
.X_add_number
== 0)
4105 reloc
->u
.a
.offset_sym
= exp
.X_add_symbol
;
4110 reloc
->u
.a
.offset_sym
= make_expr_symbol (&exp
);
4115 if (*input_line_pointer
!= ',')
4117 as_bad (_("missing reloc type"));
4121 ++input_line_pointer
;
4123 c
= get_symbol_name (& r_name
);
4124 if (strncasecmp (r_name
, "BFD_RELOC_", 10) == 0)
4128 for (reloc
->u
.a
.howto
= NULL
, i
= 0; i
< ARRAY_SIZE (bfd_relocs
); i
++)
4129 if (strcasecmp (r_name
+ 10, bfd_relocs
[i
].name
) == 0)
4131 reloc
->u
.a
.howto
= bfd_reloc_type_lookup (stdoutput
,
4132 bfd_relocs
[i
].code
);
4137 reloc
->u
.a
.howto
= bfd_reloc_name_lookup (stdoutput
, r_name
);
4138 *input_line_pointer
= c
;
4139 if (reloc
->u
.a
.howto
== NULL
)
4141 as_bad (_("unrecognized reloc type"));
4145 exp
.X_op
= O_absent
;
4146 SKIP_WHITESPACE_AFTER_NAME ();
4147 if (*input_line_pointer
== ',')
4149 ++input_line_pointer
;
4157 as_bad (_("bad reloc expression"));
4159 ignore_rest_of_line ();
4162 mri_comment_end (stop
, stopc
);
4165 reloc
->u
.a
.sym
= NULL
;
4166 reloc
->u
.a
.addend
= 0;
4169 reloc
->u
.a
.sym
= NULL
;
4170 reloc
->u
.a
.addend
= exp
.X_add_number
;
4173 reloc
->u
.a
.sym
= exp
.X_add_symbol
;
4174 reloc
->u
.a
.addend
= exp
.X_add_number
;
4177 reloc
->u
.a
.sym
= make_expr_symbol (&exp
);
4178 reloc
->u
.a
.addend
= 0;
4182 reloc
->file
= as_where (&reloc
->line
);
4183 reloc
->next
= reloc_list
;
4186 demand_empty_rest_of_line ();
4188 mri_comment_end (stop
, stopc
);
4191 /* Put the contents of expression EXP into the object file using
4192 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
4195 emit_expr (expressionS
*exp
, unsigned int nbytes
)
4197 emit_expr_with_reloc (exp
, nbytes
, TC_PARSE_CONS_RETURN_NONE
);
4201 emit_expr_with_reloc (expressionS
*exp
,
4202 unsigned int nbytes
,
4203 TC_PARSE_CONS_RETURN_TYPE reloc
)
4207 valueT extra_digit
= 0;
4209 /* Don't do anything if we are going to make another pass. */
4214 dot_value
= frag_now_fix ();
4215 dot_frag
= frag_now
;
4219 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
4220 appear as a four byte positive constant in the .line section,
4221 followed by a 2 byte 0xffff. Look for that case here. */
4223 static int dwarf_line
= -1;
4225 if (strcmp (segment_name (now_seg
), ".line") != 0)
4227 else if (dwarf_line
>= 0
4229 && exp
->X_op
== O_constant
4230 && (exp
->X_add_number
== -1 || exp
->X_add_number
== 0xffff))
4231 listing_source_line ((unsigned int) dwarf_line
);
4232 else if (nbytes
== 4
4233 && exp
->X_op
== O_constant
4234 && exp
->X_add_number
>= 0)
4235 dwarf_line
= exp
->X_add_number
;
4240 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
4241 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
4242 AT_sibling (0x12) followed by a four byte address of the sibling
4243 followed by a 2 byte AT_name (0x38) followed by the name of the
4244 file. We look for that case here. */
4246 static int dwarf_file
= 0;
4248 if (strcmp (segment_name (now_seg
), ".debug") != 0)
4250 else if (dwarf_file
== 0
4252 && exp
->X_op
== O_constant
4253 && exp
->X_add_number
== 0x11)
4255 else if (dwarf_file
== 1
4257 && exp
->X_op
== O_constant
4258 && exp
->X_add_number
== 0x12)
4260 else if (dwarf_file
== 2
4263 else if (dwarf_file
== 3
4265 && exp
->X_op
== O_constant
4266 && exp
->X_add_number
== 0x38)
4271 /* The variable dwarf_file_string tells stringer that the string
4272 may be the name of the source file. */
4273 if (dwarf_file
== 4)
4274 dwarf_file_string
= 1;
4276 dwarf_file_string
= 0;
4281 if (check_eh_frame (exp
, &nbytes
))
4286 /* Handle a negative bignum. */
4288 && exp
->X_add_number
== 0
4289 && symbol_get_value_expression (exp
->X_add_symbol
)->X_op
== O_big
4290 && symbol_get_value_expression (exp
->X_add_symbol
)->X_add_number
> 0)
4293 unsigned long carry
;
4295 exp
= symbol_get_value_expression (exp
->X_add_symbol
);
4297 /* Negate the bignum: one's complement each digit and add 1. */
4299 for (i
= 0; i
< exp
->X_add_number
; i
++)
4303 next
= (((~(generic_bignum
[i
] & LITTLENUM_MASK
))
4306 generic_bignum
[i
] = next
& LITTLENUM_MASK
;
4307 carry
= next
>> LITTLENUM_NUMBER_OF_BITS
;
4310 /* We can ignore any carry out, because it will be handled by
4311 extra_digit if it is needed. */
4313 extra_digit
= (valueT
) -1;
4317 if (op
== O_absent
|| op
== O_illegal
)
4319 as_warn (_("zero assumed for missing expression"));
4320 exp
->X_add_number
= 0;
4323 else if (op
== O_big
&& exp
->X_add_number
<= 0)
4325 as_bad (_("floating point number invalid"));
4326 exp
->X_add_number
= 0;
4329 else if (op
== O_register
)
4331 as_warn (_("register value used as expression"));
4335 /* Allow `.word 0' in the absolute section. */
4336 if (now_seg
== absolute_section
)
4338 if (op
!= O_constant
|| exp
->X_add_number
!= 0)
4339 as_bad (_("attempt to store value in absolute section"));
4340 abs_section_offset
+= nbytes
;
4344 /* Allow `.word 0' in BSS style sections. */
4345 if ((op
!= O_constant
|| exp
->X_add_number
!= 0) && in_bss ())
4346 as_bad (_("attempt to store non-zero value in section `%s'"),
4347 segment_name (now_seg
));
4349 p
= frag_more ((int) nbytes
);
4351 if (reloc
!= TC_PARSE_CONS_RETURN_NONE
)
4353 emit_expr_fix (exp
, nbytes
, frag_now
, p
, reloc
);
4357 #ifndef WORKING_DOT_WORD
4358 /* If we have the difference of two symbols in a word, save it on
4359 the broken_words list. See the code in write.c. */
4360 if (op
== O_subtract
&& nbytes
== 2)
4362 struct broken_word
*x
;
4364 x
= XNEW (struct broken_word
);
4365 x
->next_broken_word
= broken_words
;
4368 x
->subseg
= now_subseg
;
4370 x
->word_goes_here
= p
;
4372 x
->add
= exp
->X_add_symbol
;
4373 x
->sub
= exp
->X_op_symbol
;
4374 x
->addnum
= exp
->X_add_number
;
4382 /* If we have an integer, but the number of bytes is too large to
4383 pass to md_number_to_chars, handle it as a bignum. */
4384 if (op
== O_constant
&& nbytes
> sizeof (valueT
))
4386 extra_digit
= exp
->X_unsigned
? 0 : -1;
4387 convert_to_bignum (exp
, !exp
->X_unsigned
);
4391 if (op
== O_constant
)
4399 /* JF << of >= number of bits in the object is undefined. In
4400 particular SPARC (Sun 4) has problems. */
4401 if (nbytes
>= sizeof (valueT
))
4404 if (nbytes
> sizeof (valueT
))
4407 hibit
= (valueT
) 1 << (nbytes
* BITS_PER_CHAR
- 1);
4411 /* Don't store these bits. */
4412 mask
= ~(valueT
) 0 << (BITS_PER_CHAR
* nbytes
);
4413 hibit
= (valueT
) 1 << (nbytes
* BITS_PER_CHAR
- 1);
4416 unmask
= ~mask
; /* Do store these bits. */
4419 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
4420 mask
= ~(unmask
>> 1); /* Includes sign bit now. */
4423 get
= exp
->X_add_number
;
4425 if ((get
& mask
) != 0
4426 && ((get
& mask
) != mask
4427 || (get
& hibit
) == 0))
4429 /* Leading bits contain both 0s & 1s. */
4430 #if defined (BFD64) && BFD_HOST_64BIT_LONG_LONG
4432 as_warn (_("value 0x%llx truncated to 0x%llx"),
4433 (unsigned long long) get
, (unsigned long long) use
);
4435 as_warn (_("value 0x%I64x truncated to 0x%I64x"),
4436 (unsigned long long) get
, (unsigned long long) use
);
4439 as_warn (_("value 0x%lx truncated to 0x%lx"),
4440 (unsigned long) get
, (unsigned long) use
);
4443 /* Put bytes in right order. */
4444 md_number_to_chars (p
, use
, (int) nbytes
);
4446 else if (op
== O_big
)
4449 LITTLENUM_TYPE
*nums
;
4451 size
= exp
->X_add_number
* CHARS_PER_LITTLENUM
;
4454 int i
= nbytes
/ CHARS_PER_LITTLENUM
;
4458 LITTLENUM_TYPE sign
= 0;
4459 if ((generic_bignum
[--i
]
4460 & (1 << (LITTLENUM_NUMBER_OF_BITS
- 1))) != 0)
4461 sign
= ~(LITTLENUM_TYPE
) 0;
4463 while (++i
< exp
->X_add_number
)
4464 if (generic_bignum
[i
] != sign
)
4467 else if (nbytes
== 1)
4469 /* We have nbytes == 1 and CHARS_PER_LITTLENUM == 2 (probably).
4470 Check that bits 8.. of generic_bignum[0] match bit 7
4471 and that they match all of generic_bignum[1..exp->X_add_number]. */
4472 LITTLENUM_TYPE sign
= (generic_bignum
[0] & (1 << 7)) ? -1 : 0;
4473 LITTLENUM_TYPE himask
= LITTLENUM_MASK
& ~ 0xFF;
4475 if ((generic_bignum
[0] & himask
) == (sign
& himask
))
4477 while (++i
< exp
->X_add_number
)
4478 if (generic_bignum
[i
] != sign
)
4483 if (i
< exp
->X_add_number
)
4484 as_warn (ngettext ("bignum truncated to %d byte",
4485 "bignum truncated to %d bytes",
4493 md_number_to_chars (p
, (valueT
) generic_bignum
[0], 1);
4496 know (nbytes
% CHARS_PER_LITTLENUM
== 0);
4498 if (target_big_endian
)
4500 while (nbytes
> size
)
4502 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
4503 nbytes
-= CHARS_PER_LITTLENUM
;
4504 p
+= CHARS_PER_LITTLENUM
;
4507 nums
= generic_bignum
+ size
/ CHARS_PER_LITTLENUM
;
4508 while (size
>= CHARS_PER_LITTLENUM
)
4511 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
4512 size
-= CHARS_PER_LITTLENUM
;
4513 p
+= CHARS_PER_LITTLENUM
;
4518 nums
= generic_bignum
;
4519 while (size
>= CHARS_PER_LITTLENUM
)
4521 md_number_to_chars (p
, (valueT
) *nums
, CHARS_PER_LITTLENUM
);
4523 size
-= CHARS_PER_LITTLENUM
;
4524 p
+= CHARS_PER_LITTLENUM
;
4525 nbytes
-= CHARS_PER_LITTLENUM
;
4528 while (nbytes
>= CHARS_PER_LITTLENUM
)
4530 md_number_to_chars (p
, extra_digit
, CHARS_PER_LITTLENUM
);
4531 nbytes
-= CHARS_PER_LITTLENUM
;
4532 p
+= CHARS_PER_LITTLENUM
;
4537 emit_expr_fix (exp
, nbytes
, frag_now
, p
, TC_PARSE_CONS_RETURN_NONE
);
4541 emit_expr_fix (expressionS
*exp
, unsigned int nbytes
, fragS
*frag
, char *p
,
4542 TC_PARSE_CONS_RETURN_TYPE r ATTRIBUTE_UNUSED
)
4545 unsigned int size
= nbytes
;
4547 memset (p
, 0, size
);
4549 /* Generate a fixS to record the symbol value. */
4551 #ifdef TC_CONS_FIX_NEW
4552 TC_CONS_FIX_NEW (frag
, p
- frag
->fr_literal
+ offset
, size
, exp
, r
);
4554 if (r
!= TC_PARSE_CONS_RETURN_NONE
)
4556 reloc_howto_type
*reloc_howto
;
4558 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, r
);
4559 size
= bfd_get_reloc_size (reloc_howto
);
4563 as_bad (ngettext ("%s relocations do not fit in %u byte",
4564 "%s relocations do not fit in %u bytes",
4566 reloc_howto
->name
, nbytes
);
4569 else if (target_big_endian
)
4570 offset
= nbytes
- size
;
4591 as_bad (_("unsupported BFD relocation size %u"), size
);
4594 fix_new_exp (frag
, p
- frag
->fr_literal
+ offset
, size
,
4599 /* Handle an MRI style string expression. */
4603 parse_mri_cons (expressionS
*exp
, unsigned int nbytes
)
4605 if (*input_line_pointer
!= '\''
4606 && (input_line_pointer
[1] != '\''
4607 || (*input_line_pointer
!= 'A'
4608 && *input_line_pointer
!= 'E')))
4609 (void) TC_PARSE_CONS_EXPRESSION (exp
, nbytes
);
4613 unsigned int result
= 0;
4615 /* An MRI style string. Cut into as many bytes as will fit into
4616 a nbyte chunk, left justify if necessary, and separate with
4617 commas so we can try again later. */
4618 if (*input_line_pointer
== 'A')
4619 ++input_line_pointer
;
4620 else if (*input_line_pointer
== 'E')
4622 as_bad (_("EBCDIC constants are not supported"));
4623 ++input_line_pointer
;
4626 input_line_pointer
++;
4627 for (scan
= 0; scan
< nbytes
; scan
++)
4629 if (*input_line_pointer
== '\'')
4631 if (input_line_pointer
[1] == '\'')
4633 input_line_pointer
++;
4638 result
= (result
<< 8) | (*input_line_pointer
++);
4642 while (scan
< nbytes
)
4648 /* Create correct expression. */
4649 exp
->X_op
= O_constant
;
4650 exp
->X_add_number
= result
;
4652 /* Fake it so that we can read the next char too. */
4653 if (input_line_pointer
[0] != '\'' ||
4654 (input_line_pointer
[0] == '\'' && input_line_pointer
[1] == '\''))
4656 input_line_pointer
-= 2;
4657 input_line_pointer
[0] = ',';
4658 input_line_pointer
[1] = '\'';
4661 input_line_pointer
++;
4664 #endif /* TC_M68K */
4666 #ifdef REPEAT_CONS_EXPRESSIONS
4668 /* Parse a repeat expression for cons. This is used by the MIPS
4669 assembler. The format is NUMBER:COUNT; NUMBER appears in the
4670 object file COUNT times.
4672 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
4675 parse_repeat_cons (expressionS
*exp
, unsigned int nbytes
)
4682 if (*input_line_pointer
!= ':')
4684 /* No repeat count. */
4688 ++input_line_pointer
;
4689 expression (&count
);
4690 if (count
.X_op
!= O_constant
4691 || count
.X_add_number
<= 0)
4693 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4697 /* The cons function is going to output this expression once. So we
4698 output it count - 1 times. */
4699 for (i
= count
.X_add_number
- 1; i
> 0; i
--)
4700 emit_expr (exp
, nbytes
);
4703 #endif /* REPEAT_CONS_EXPRESSIONS */
4705 /* Parse a floating point number represented as a hex constant. This
4706 permits users to specify the exact bits they want in the floating
4710 hex_float (int float_type
, char *bytes
)
4742 as_bad (_("unknown floating type type '%c'"), float_type
);
4746 /* It would be nice if we could go through expression to parse the
4747 hex constant, but if we get a bignum it's a pain to sort it into
4748 the buffer correctly. */
4750 while (hex_p (*input_line_pointer
) || *input_line_pointer
== '_')
4754 /* The MRI assembler accepts arbitrary underscores strewn about
4755 through the hex constant, so we ignore them as well. */
4756 if (*input_line_pointer
== '_')
4758 ++input_line_pointer
;
4764 as_warn (_("floating point constant too large"));
4767 d
= hex_value (*input_line_pointer
) << 4;
4768 ++input_line_pointer
;
4769 while (*input_line_pointer
== '_')
4770 ++input_line_pointer
;
4771 if (hex_p (*input_line_pointer
))
4773 d
+= hex_value (*input_line_pointer
);
4774 ++input_line_pointer
;
4776 if (target_big_endian
)
4779 bytes
[length
- i
- 1] = d
;
4785 if (target_big_endian
)
4786 memset (bytes
+ i
, 0, length
- i
);
4788 memset (bytes
, 0, length
- i
);
4796 CONStruct some more frag chars of .floats .ffloats etc.
4797 Makes 0 or more new frags.
4798 If need_pass_2 == 1, no frags are emitted.
4799 This understands only floating literals, not expressions. Sorry.
4801 A floating constant is defined by atof_generic(), except it is preceded
4802 by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4803 reading, I decided to be incompatible. This always tries to give you
4804 rounded bits to the precision of the pseudo-op. Former AS did premature
4805 truncation, restored noisy bits instead of trailing 0s AND gave you
4806 a choice of 2 flavours of noise according to which of 2 floating-point
4807 scanners you directed AS to use.
4809 In: input_line_pointer->whitespace before, or '0' of flonum. */
4812 float_cons (/* Clobbers input_line-pointer, checks end-of-line. */
4813 int float_type
/* 'f':.ffloat ... 'F':.float ... */)
4816 int length
; /* Number of chars in an object. */
4817 const char *err
; /* Error from scanning floating literal. */
4818 char temp
[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
];
4820 if (is_it_end_of_statement ())
4822 demand_empty_rest_of_line ();
4826 if (now_seg
== absolute_section
)
4828 as_bad (_("attempt to store float in absolute section"));
4829 ignore_rest_of_line ();
4835 as_bad (_("attempt to store float in section `%s'"),
4836 segment_name (now_seg
));
4837 ignore_rest_of_line ();
4841 #ifdef md_flush_pending_output
4842 md_flush_pending_output ();
4845 #ifdef md_cons_align
4851 /* input_line_pointer->1st char of a flonum (we hope!). */
4854 /* Skip any 0{letter} that may be present. Don't even check if the
4855 letter is legal. Someone may invent a "z" format and this routine
4856 has no use for such information. Lusers beware: you get
4857 diagnostics if your input is ill-conditioned. */
4858 if (input_line_pointer
[0] == '0'
4859 && ISALPHA (input_line_pointer
[1]))
4860 input_line_pointer
+= 2;
4862 /* Accept :xxxx, where the x's are hex digits, for a floating
4863 point with the exact digits specified. */
4864 if (input_line_pointer
[0] == ':')
4866 ++input_line_pointer
;
4867 length
= hex_float (float_type
, temp
);
4870 ignore_rest_of_line ();
4876 err
= md_atof (float_type
, temp
, &length
);
4877 know (length
<= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT
);
4878 know (err
!= NULL
|| length
> 0);
4881 as_bad (_("bad floating literal: %s"), err
);
4882 ignore_rest_of_line ();
4893 #ifdef REPEAT_CONS_EXPRESSIONS
4894 if (*input_line_pointer
== ':')
4896 expressionS count_exp
;
4898 ++input_line_pointer
;
4899 expression (&count_exp
);
4901 if (count_exp
.X_op
!= O_constant
4902 || count_exp
.X_add_number
<= 0)
4903 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4905 count
= count_exp
.X_add_number
;
4909 while (--count
>= 0)
4911 p
= frag_more (length
);
4912 memcpy (p
, temp
, (unsigned int) length
);
4917 while (*input_line_pointer
++ == ',');
4919 /* Put terminator back into stream. */
4920 --input_line_pointer
;
4921 demand_empty_rest_of_line ();
4926 Note - we are using the DWARF standard's definition of LEB128 encoding
4927 where each 7-bit value is a stored in a byte, *not* an octet. This
4928 means that on targets where a byte contains multiple octets there is
4929 a *huge waste of space*. (This also means that we do not have to
4930 have special versions of these functions for when OCTETS_PER_BYTE_POWER
4933 If the 7-bit values were to be packed into N-bit bytes (where N > 8)
4934 we would then have to consider whether multiple, successive LEB128
4935 values should be packed into the bytes without padding (bad idea) or
4936 whether each LEB128 number is padded out to a whole number of bytes.
4937 Plus you have to decide on the endianness of packing octets into a
4940 /* Return the size of a LEB128 value in bytes. */
4942 static inline unsigned int
4943 sizeof_sleb128 (offsetT value
)
4950 byte
= (value
& 0x7f);
4951 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4952 Fortunately, we can structure things so that the extra work reduces
4953 to a noop on systems that do things "properly". */
4954 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
4957 while (!(((value
== 0) && ((byte
& 0x40) == 0))
4958 || ((value
== -1) && ((byte
& 0x40) != 0))));
4963 static inline unsigned int
4964 sizeof_uleb128 (valueT value
)
4979 sizeof_leb128 (valueT value
, int sign
)
4982 return sizeof_sleb128 ((offsetT
) value
);
4984 return sizeof_uleb128 (value
);
4987 /* Output a LEB128 value. Returns the number of bytes used. */
4989 static inline unsigned int
4990 output_sleb128 (char *p
, offsetT value
)
4997 unsigned byte
= (value
& 0x7f);
4999 /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5000 Fortunately, we can structure things so that the extra work reduces
5001 to a noop on systems that do things "properly". */
5002 value
= (value
>> 7) | ~(-(offsetT
)1 >> 7);
5004 more
= !((((value
== 0) && ((byte
& 0x40) == 0))
5005 || ((value
== -1) && ((byte
& 0x40) != 0))));
5016 static inline unsigned int
5017 output_uleb128 (char *p
, valueT value
)
5023 unsigned byte
= (value
& 0x7f);
5027 /* More bytes to follow. */
5038 output_leb128 (char *p
, valueT value
, int sign
)
5041 return output_sleb128 (p
, (offsetT
) value
);
5043 return output_uleb128 (p
, value
);
5046 /* Do the same for bignums. We combine sizeof with output here in that
5047 we don't output for NULL values of P. It isn't really as critical as
5048 for "normal" values that this be streamlined. Returns the number of
5051 static inline unsigned int
5052 output_big_sleb128 (char *p
, LITTLENUM_TYPE
*bignum
, unsigned int size
)
5059 /* Strip leading sign extensions off the bignum. */
5061 && bignum
[size
- 1] == LITTLENUM_MASK
5062 && bignum
[size
- 2] > LITTLENUM_MASK
/ 2)
5067 /* OR in the next part of the littlenum. */
5068 val
|= (*bignum
<< loaded
);
5069 loaded
+= LITTLENUM_NUMBER_OF_BITS
;
5073 /* Add bytes until there are less than 7 bits left in VAL
5074 or until every non-sign bit has been written. */
5081 || val
!= ((byte
& 0x40) == 0 ? 0 : ((valueT
) 1 << loaded
) - 1))
5088 while ((byte
& 0x80) != 0 && loaded
>= 7);
5092 /* Mop up any left-over bits (of which there will be less than 7). */
5093 if ((byte
& 0x80) != 0)
5095 /* Sign-extend VAL. */
5096 if (val
& (1 << (loaded
- 1)))
5097 val
|= ~0U << loaded
;
5106 static inline unsigned int
5107 output_big_uleb128 (char *p
, LITTLENUM_TYPE
*bignum
, unsigned int size
)
5114 /* Strip leading zeros off the bignum. */
5115 /* XXX: Is this needed? */
5116 while (size
> 0 && bignum
[size
- 1] == 0)
5121 if (loaded
< 7 && size
> 0)
5123 val
|= (*bignum
<< loaded
);
5124 loaded
+= 8 * CHARS_PER_LITTLENUM
;
5133 if (size
> 0 || val
)
5140 while (byte
& 0x80);
5146 output_big_leb128 (char *p
, LITTLENUM_TYPE
*bignum
, unsigned int size
, int sign
)
5149 return output_big_sleb128 (p
, bignum
, size
);
5151 return output_big_uleb128 (p
, bignum
, size
);
5154 /* Generate the appropriate fragments for a given expression to emit a
5155 leb128 value. SIGN is 1 for sleb, 0 for uleb. */
5158 emit_leb128_expr (expressionS
*exp
, int sign
)
5160 operatorT op
= exp
->X_op
;
5161 unsigned int nbytes
;
5163 if (op
== O_absent
|| op
== O_illegal
)
5165 as_warn (_("zero assumed for missing expression"));
5166 exp
->X_add_number
= 0;
5169 else if (op
== O_big
&& exp
->X_add_number
<= 0)
5171 as_bad (_("floating point number invalid"));
5172 exp
->X_add_number
= 0;
5175 else if (op
== O_register
)
5177 as_warn (_("register value used as expression"));
5180 else if (op
== O_constant
5182 && (exp
->X_add_number
< 0) == !exp
->X_extrabit
)
5184 /* We're outputting a signed leb128 and the sign of X_add_number
5185 doesn't reflect the sign of the original value. Convert EXP
5186 to a correctly-extended bignum instead. */
5187 convert_to_bignum (exp
, exp
->X_extrabit
);
5191 if (now_seg
== absolute_section
)
5193 if (op
!= O_constant
|| exp
->X_add_number
!= 0)
5194 as_bad (_("attempt to store value in absolute section"));
5195 abs_section_offset
++;
5199 if ((op
!= O_constant
|| exp
->X_add_number
!= 0) && in_bss ())
5200 as_bad (_("attempt to store non-zero value in section `%s'"),
5201 segment_name (now_seg
));
5203 /* Let check_eh_frame know that data is being emitted. nbytes == -1 is
5204 a signal that this is leb128 data. It shouldn't optimize this away. */
5205 nbytes
= (unsigned int) -1;
5206 if (check_eh_frame (exp
, &nbytes
))
5209 /* Let the backend know that subsequent data may be byte aligned. */
5210 #ifdef md_cons_align
5214 if (op
== O_constant
)
5216 /* If we've got a constant, emit the thing directly right now. */
5218 valueT value
= exp
->X_add_number
;
5222 size
= sizeof_leb128 (value
, sign
);
5223 p
= frag_more (size
);
5224 if (output_leb128 (p
, value
, sign
) > size
)
5227 else if (op
== O_big
)
5229 /* O_big is a different sort of constant. */
5230 int nbr_digits
= exp
->X_add_number
;
5234 /* If the leading littenum is 0xffff, prepend a 0 to avoid confusion with
5235 a signed number. Unary operators like - or ~ always extend the
5236 bignum to its largest size. */
5238 && nbr_digits
< SIZE_OF_LARGE_NUMBER
5239 && generic_bignum
[nbr_digits
- 1] == LITTLENUM_MASK
)
5240 generic_bignum
[nbr_digits
++] = 0;
5242 size
= output_big_leb128 (NULL
, generic_bignum
, nbr_digits
, sign
);
5243 p
= frag_more (size
);
5244 if (output_big_leb128 (p
, generic_bignum
, nbr_digits
, sign
) > size
)
5249 /* Otherwise, we have to create a variable sized fragment and
5250 resolve things later. */
5252 frag_var (rs_leb128
, sizeof_uleb128 (~(valueT
) 0), 0, sign
,
5253 make_expr_symbol (exp
), 0, (char *) NULL
);
5257 /* Parse the .sleb128 and .uleb128 pseudos. */
5264 #ifdef md_flush_pending_output
5265 md_flush_pending_output ();
5271 emit_leb128_expr (&exp
, sign
);
5273 while (*input_line_pointer
++ == ',');
5275 input_line_pointer
--;
5276 demand_empty_rest_of_line ();
5280 stringer_append_char (int c
, int bitsize
)
5283 as_bad (_("attempt to store non-empty string in section `%s'"),
5284 segment_name (now_seg
));
5286 if (!target_big_endian
)
5287 FRAG_APPEND_1_CHAR (c
);
5292 FRAG_APPEND_1_CHAR (0);
5293 FRAG_APPEND_1_CHAR (0);
5294 FRAG_APPEND_1_CHAR (0);
5295 FRAG_APPEND_1_CHAR (0);
5298 FRAG_APPEND_1_CHAR (0);
5299 FRAG_APPEND_1_CHAR (0);
5302 FRAG_APPEND_1_CHAR (0);
5307 /* Called with invalid bitsize argument. */
5311 if (target_big_endian
)
5312 FRAG_APPEND_1_CHAR (c
);
5315 /* Worker to do .ascii etc statements.
5316 Reads 0 or more ',' separated, double-quoted strings.
5317 Caller should have checked need_pass_2 is FALSE because we don't
5319 Checks for end-of-line.
5320 BITS_APPENDZERO says how many bits are in a target char.
5321 The bottom bit is set if a NUL char should be appended to the strings. */
5324 stringer (int bits_appendzero
)
5326 const int bitsize
= bits_appendzero
& ~7;
5327 const int append_zero
= bits_appendzero
& 1;
5329 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5333 #ifdef md_flush_pending_output
5334 md_flush_pending_output ();
5337 #ifdef md_cons_align
5341 /* If we have been switched into the abs_section then we
5342 will not have an obstack onto which we can hang strings. */
5343 if (now_seg
== absolute_section
)
5345 as_bad (_("strings must be placed into a section"));
5346 ignore_rest_of_line ();
5350 /* The following awkward logic is to parse ZERO or more strings,
5351 comma separated. Recall a string expression includes spaces
5352 before the opening '\"' and spaces after the closing '\"'.
5353 We fake a leading ',' if there is (supposed to be)
5354 a 1st, expression. We keep demanding expressions for each ','. */
5355 if (is_it_end_of_statement ())
5357 c
= 0; /* Skip loop. */
5358 ++input_line_pointer
; /* Compensate for end of loop. */
5362 c
= ','; /* Do loop. */
5365 while (c
== ',' || c
== '<' || c
== '"')
5368 switch (*input_line_pointer
)
5371 ++input_line_pointer
; /*->1st char of string. */
5372 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5373 start
= input_line_pointer
;
5376 while (is_a_char (c
= next_char_of_string ()))
5377 stringer_append_char (c
, bitsize
);
5380 stringer_append_char (0, bitsize
);
5382 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5383 /* In ELF, when gcc is emitting DWARF 1 debugging output, it
5384 will emit .string with a filename in the .debug section
5385 after a sequence of constants. See the comment in
5386 emit_expr for the sequence. emit_expr will set
5387 dwarf_file_string to non-zero if this string might be a
5388 source file name. */
5389 if (strcmp (segment_name (now_seg
), ".debug") != 0)
5390 dwarf_file_string
= 0;
5391 else if (dwarf_file_string
)
5393 c
= input_line_pointer
[-1];
5394 input_line_pointer
[-1] = '\0';
5395 listing_source_file (start
);
5396 input_line_pointer
[-1] = c
;
5402 input_line_pointer
++;
5403 c
= get_single_number ();
5404 stringer_append_char (c
, bitsize
);
5405 if (*input_line_pointer
!= '>')
5407 as_bad (_("expected <nn>"));
5408 ignore_rest_of_line ();
5411 input_line_pointer
++;
5414 input_line_pointer
++;
5418 c
= *input_line_pointer
;
5421 demand_empty_rest_of_line ();
5424 /* FIXME-SOMEDAY: I had trouble here on characters with the
5425 high bits set. We'll probably also have trouble with
5426 multibyte chars, wide chars, etc. Also be careful about
5427 returning values bigger than 1 byte. xoxorich. */
5430 next_char_of_string (void)
5434 c
= *input_line_pointer
++ & CHAR_MASK
;
5438 /* PR 20902: Do not advance past the end of the buffer. */
5439 -- input_line_pointer
;
5448 as_warn (_("unterminated string; newline inserted"));
5449 bump_line_counters ();
5453 if (!TC_STRING_ESCAPES
)
5455 switch (c
= *input_line_pointer
++ & CHAR_MASK
)
5483 break; /* As itself. */
5499 for (i
= 0, number
= 0;
5500 ISDIGIT (c
) && i
< 3;
5501 c
= *input_line_pointer
++, i
++)
5503 number
= number
* 8 + c
- '0';
5506 c
= number
& CHAR_MASK
;
5508 --input_line_pointer
;
5517 c
= *input_line_pointer
++;
5518 while (ISXDIGIT (c
))
5521 number
= number
* 16 + c
- '0';
5522 else if (ISUPPER (c
))
5523 number
= number
* 16 + c
- 'A' + 10;
5525 number
= number
* 16 + c
- 'a' + 10;
5526 c
= *input_line_pointer
++;
5528 c
= number
& CHAR_MASK
;
5529 --input_line_pointer
;
5534 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
5535 as_warn (_("unterminated string; newline inserted"));
5537 bump_line_counters ();
5541 /* Do not advance past the end of the buffer. */
5542 -- input_line_pointer
;
5548 #ifdef ONLY_STANDARD_ESCAPES
5549 as_bad (_("bad escaped character in string"));
5551 #endif /* ONLY_STANDARD_ESCAPES */
5564 get_segmented_expression (expressionS
*expP
)
5568 retval
= expression (expP
);
5569 if (expP
->X_op
== O_illegal
5570 || expP
->X_op
== O_absent
5571 || expP
->X_op
== O_big
)
5573 as_bad (_("expected address expression"));
5574 expP
->X_op
= O_constant
;
5575 expP
->X_add_number
= 0;
5576 retval
= absolute_section
;
5582 get_known_segmented_expression (expressionS
*expP
)
5584 segT retval
= get_segmented_expression (expP
);
5586 if (retval
== undefined_section
)
5588 /* There is no easy way to extract the undefined symbol from the
5590 if (expP
->X_add_symbol
!= NULL
5591 && S_GET_SEGMENT (expP
->X_add_symbol
) != expr_section
)
5592 as_warn (_("symbol \"%s\" undefined; zero assumed"),
5593 S_GET_NAME (expP
->X_add_symbol
));
5595 as_warn (_("some symbol undefined; zero assumed"));
5596 retval
= absolute_section
;
5597 expP
->X_op
= O_constant
;
5598 expP
->X_add_number
= 0;
5603 char /* Return terminator. */
5604 get_absolute_expression_and_terminator (long *val_pointer
/* Return value of expression. */)
5606 /* FIXME: val_pointer should probably be offsetT *. */
5607 *val_pointer
= (long) get_absolute_expression ();
5608 return (*input_line_pointer
++);
5611 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
5612 Give a warning if that happens. */
5615 demand_copy_C_string (int *len_pointer
)
5619 if ((s
= demand_copy_string (len_pointer
)) != 0)
5623 for (len
= *len_pointer
; len
> 0; len
--)
5630 as_bad (_("this string may not contain \'\\0\'"));
5638 /* Demand string, but return a safe (=private) copy of the string.
5639 Return NULL if we can't read a string here. */
5642 demand_copy_string (int *lenP
)
5650 if (*input_line_pointer
== '\"')
5652 input_line_pointer
++; /* Skip opening quote. */
5654 while (is_a_char (c
= next_char_of_string ()))
5656 obstack_1grow (¬es
, c
);
5659 /* JF this next line is so demand_copy_C_string will return a
5660 null terminated string. */
5661 obstack_1grow (¬es
, '\0');
5662 retval
= (char *) obstack_finish (¬es
);
5666 as_bad (_("missing string"));
5668 ignore_rest_of_line ();
5674 /* In: Input_line_pointer->next character.
5676 Do: Skip input_line_pointer over all whitespace.
5678 Out: 1 if input_line_pointer->end-of-line. */
5681 is_it_end_of_statement (void)
5684 return (is_end_of_line
[(unsigned char) *input_line_pointer
]);
5688 equals (char *sym_name
, int reassign
)
5693 input_line_pointer
++;
5694 if (*input_line_pointer
== '=')
5695 input_line_pointer
++;
5696 if (reassign
< 0 && *input_line_pointer
== '=')
5697 input_line_pointer
++;
5699 while (*input_line_pointer
== ' ' || *input_line_pointer
== '\t')
5700 input_line_pointer
++;
5703 stop
= mri_comment_field (&stopc
);
5705 assign_symbol (sym_name
, reassign
>= 0 ? !reassign
: reassign
);
5709 demand_empty_rest_of_line ();
5710 mri_comment_end (stop
, stopc
);
5714 /* .incbin -- include a file verbatim at the current location. */
5717 s_incbin (int x ATTRIBUTE_UNUSED
)
5728 #ifdef md_flush_pending_output
5729 md_flush_pending_output ();
5732 #ifdef md_cons_align
5737 filename
= demand_copy_string (& len
);
5738 if (filename
== NULL
)
5743 /* Look for optional skip and count. */
5744 if (* input_line_pointer
== ',')
5746 ++ input_line_pointer
;
5747 skip
= get_absolute_expression ();
5751 if (* input_line_pointer
== ',')
5753 ++ input_line_pointer
;
5755 count
= get_absolute_expression ();
5757 as_warn (_(".incbin count zero, ignoring `%s'"), filename
);
5763 demand_empty_rest_of_line ();
5765 /* Try opening absolute path first, then try include dirs. */
5766 binfile
= fopen (filename
, FOPEN_RB
);
5767 if (binfile
== NULL
)
5771 path
= XNEWVEC (char, (unsigned long) len
+ include_dir_maxlen
+ 5);
5773 for (i
= 0; i
< include_dir_count
; i
++)
5775 sprintf (path
, "%s/%s", include_dirs
[i
], filename
);
5777 binfile
= fopen (path
, FOPEN_RB
);
5778 if (binfile
!= NULL
)
5782 if (binfile
== NULL
)
5783 as_bad (_("file not found: %s"), filename
);
5786 path
= xstrdup (filename
);
5792 register_dependency (path
);
5794 /* Compute the length of the file. */
5795 if (fseek (binfile
, 0, SEEK_END
) != 0)
5797 as_bad (_("seek to end of .incbin file failed `%s'"), path
);
5800 file_len
= ftell (binfile
);
5802 /* If a count was not specified use the remainder of the file. */
5804 count
= file_len
- skip
;
5806 if (skip
< 0 || count
< 0 || file_len
< 0 || skip
+ count
> file_len
)
5808 as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
5809 skip
, count
, file_len
);
5813 if (fseek (binfile
, skip
, SEEK_SET
) != 0)
5815 as_bad (_("could not skip to %ld in file `%s'"), skip
, path
);
5819 /* Allocate frag space and store file contents in it. */
5820 binfrag
= frag_more (count
);
5822 bytes
= fread (binfrag
, 1, count
, binfile
);
5824 as_warn (_("truncated file `%s', %ld of %ld bytes read"),
5825 path
, bytes
, count
);
5828 if (binfile
!= NULL
)
5833 /* .include -- include a file at this point. */
5836 s_include (int arg ATTRIBUTE_UNUSED
)
5845 filename
= demand_copy_string (&i
);
5846 if (filename
== NULL
)
5848 /* demand_copy_string has already printed an error and
5849 called ignore_rest_of_line. */
5857 while (!is_end_of_line
[(unsigned char) *input_line_pointer
]
5858 && *input_line_pointer
!= ' '
5859 && *input_line_pointer
!= '\t')
5861 obstack_1grow (¬es
, *input_line_pointer
);
5862 ++input_line_pointer
;
5866 obstack_1grow (¬es
, '\0');
5867 filename
= (char *) obstack_finish (¬es
);
5868 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
5869 ++input_line_pointer
;
5872 demand_empty_rest_of_line ();
5873 path
= XNEWVEC (char, (unsigned long) i
5874 + include_dir_maxlen
+ 5 /* slop */ );
5876 for (i
= 0; i
< include_dir_count
; i
++)
5878 strcpy (path
, include_dirs
[i
]);
5880 strcat (path
, filename
);
5881 if (0 != (try_file
= fopen (path
, FOPEN_RT
)))
5891 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
5892 register_dependency (path
);
5893 input_scrub_insert_file (path
);
5897 add_include_dir (char *path
)
5901 if (include_dir_count
== 0)
5903 include_dirs
= XNEWVEC (const char *, 2);
5904 include_dirs
[0] = "."; /* Current dir. */
5905 include_dir_count
= 2;
5909 include_dir_count
++;
5910 include_dirs
= XRESIZEVEC (const char *, include_dirs
,
5914 include_dirs
[include_dir_count
- 1] = path
; /* New one. */
5917 if (i
> include_dir_maxlen
)
5918 include_dir_maxlen
= i
;
5921 /* Output debugging information to denote the source file. */
5924 generate_file_debug (void)
5926 if (debug_type
== DEBUG_STABS
)
5927 stabs_generate_asm_file ();
5930 /* Output line number debugging information for the current source line. */
5933 generate_lineno_debug (void)
5937 case DEBUG_UNSPECIFIED
:
5942 stabs_generate_asm_lineno ();
5945 ecoff_generate_asm_lineno ();
5948 /* ??? We could here indicate to dwarf2dbg.c that something
5949 has changed. However, since there is additional backend
5950 support that is required (calling dwarf2_emit_insn), we
5951 let dwarf2dbg.c call as_where on its own. */
5956 /* Output debugging information to mark a function entry point or end point.
5957 END_P is zero for .func, and non-zero for .endfunc. */
5962 do_s_func (end_p
, NULL
);
5965 /* Subroutine of s_func so targets can choose a different default prefix.
5966 If DEFAULT_PREFIX is NULL, use the target's "leading char". */
5969 do_s_func (int end_p
, const char *default_prefix
)
5971 /* Record the current function so that we can issue an error message for
5972 misplaced .func,.endfunc, and also so that .endfunc needs no
5974 static char *current_name
;
5975 static char *current_label
;
5979 if (current_name
== NULL
)
5981 as_bad (_("missing .func"));
5982 ignore_rest_of_line ();
5986 if (debug_type
== DEBUG_STABS
)
5987 stabs_generate_asm_endfunc (current_name
, current_label
);
5989 current_name
= current_label
= NULL
;
5994 char delim1
, delim2
;
5996 if (current_name
!= NULL
)
5998 as_bad (_(".endfunc missing for previous .func"));
5999 ignore_rest_of_line ();
6003 delim1
= get_symbol_name (& name
);
6004 name
= xstrdup (name
);
6005 *input_line_pointer
= delim1
;
6006 SKIP_WHITESPACE_AFTER_NAME ();
6007 if (*input_line_pointer
!= ',')
6011 if (asprintf (&label
, "%s%s", default_prefix
, name
) == -1)
6012 as_fatal ("%s", xstrerror (errno
));
6016 char leading_char
= bfd_get_symbol_leading_char (stdoutput
);
6017 /* Missing entry point, use function's name with the leading
6021 if (asprintf (&label
, "%c%s", leading_char
, name
) == -1)
6022 as_fatal ("%s", xstrerror (errno
));
6030 ++input_line_pointer
;
6032 delim2
= get_symbol_name (& label
);
6033 label
= xstrdup (label
);
6034 restore_line_pointer (delim2
);
6037 if (debug_type
== DEBUG_STABS
)
6038 stabs_generate_asm_func (name
, label
);
6040 current_name
= name
;
6041 current_label
= label
;
6044 demand_empty_rest_of_line ();
6047 #ifdef HANDLE_BUNDLE
6050 s_bundle_align_mode (int arg ATTRIBUTE_UNUSED
)
6052 unsigned int align
= get_absolute_expression ();
6054 demand_empty_rest_of_line ();
6056 if (align
> (unsigned int) TC_ALIGN_LIMIT
)
6057 as_fatal (_(".bundle_align_mode alignment too large (maximum %u)"),
6058 (unsigned int) TC_ALIGN_LIMIT
);
6060 if (bundle_lock_frag
!= NULL
)
6062 as_bad (_("cannot change .bundle_align_mode inside .bundle_lock"));
6066 bundle_align_p2
= align
;
6070 s_bundle_lock (int arg ATTRIBUTE_UNUSED
)
6072 demand_empty_rest_of_line ();
6074 if (bundle_align_p2
== 0)
6076 as_bad (_(".bundle_lock is meaningless without .bundle_align_mode"));
6080 if (bundle_lock_depth
== 0)
6082 bundle_lock_frchain
= frchain_now
;
6083 bundle_lock_frag
= start_bundle ();
6085 ++bundle_lock_depth
;
6089 s_bundle_unlock (int arg ATTRIBUTE_UNUSED
)
6093 demand_empty_rest_of_line ();
6095 if (bundle_lock_frag
== NULL
)
6097 as_bad (_(".bundle_unlock without preceding .bundle_lock"));
6101 gas_assert (bundle_align_p2
> 0);
6103 gas_assert (bundle_lock_depth
> 0);
6104 if (--bundle_lock_depth
> 0)
6107 size
= pending_bundle_size (bundle_lock_frag
);
6109 if (size
> 1U << bundle_align_p2
)
6110 as_bad (_(".bundle_lock sequence is %u bytes, "
6111 "but bundle size is only %u bytes"),
6112 size
, 1u << bundle_align_p2
);
6114 finish_bundle (bundle_lock_frag
, size
);
6116 bundle_lock_frag
= NULL
;
6117 bundle_lock_frchain
= NULL
;
6120 #endif /* HANDLE_BUNDLE */
6123 s_ignore (int arg ATTRIBUTE_UNUSED
)
6125 ignore_rest_of_line ();
6129 read_print_statistics (FILE *file
)
6131 hash_print_statistics (file
, "pseudo-op table", po_hash
);
6134 /* Inserts the given line into the input stream.
6136 This call avoids macro/conditionals nesting checking, since the contents of
6137 the line are assumed to replace the contents of a line already scanned.
6139 An appropriate use of this function would be substitution of input lines when
6140 called by md_start_line_hook(). The given line is assumed to already be
6141 properly scrubbed. */
6144 input_scrub_insert_line (const char *line
)
6147 size_t len
= strlen (line
);
6148 sb_build (&newline
, len
);
6149 sb_add_buffer (&newline
, line
, len
);
6150 input_scrub_include_sb (&newline
, input_line_pointer
, 0);
6152 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
6155 /* Insert a file into the input stream; the path must resolve to an actual
6156 file; no include path searching or dependency registering is performed. */
6159 input_scrub_insert_file (char *path
)
6161 input_scrub_include_file (path
, input_line_pointer
);
6162 buffer_limit
= input_scrub_next_buffer (&input_line_pointer
);
6165 /* Find the end of a line, considering quotation and escaping of quotes. */
6167 #if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
6168 # define TC_SINGLE_QUOTE_STRINGS 1
6172 _find_end_of_line (char *s
, int mri_string
, int insn ATTRIBUTE_UNUSED
,
6175 char inquote
= '\0';
6178 while (!is_end_of_line
[(unsigned char) *s
]
6179 || (inquote
&& !ISCNTRL (*s
))
6180 || (inquote
== '\'' && flag_mri
)
6181 #ifdef TC_EOL_IN_INSN
6182 || (insn
&& TC_EOL_IN_INSN (s
))
6184 /* PR 6926: When we are parsing the body of a macro the sequence
6185 \@ is special - it refers to the invocation count. If the @
6186 character happens to be registered as a line-separator character
6187 by the target, then the is_end_of_line[] test above will have
6188 returned true, but we need to ignore the line separating
6189 semantics in this particular case. */
6190 || (in_macro
&& inescape
&& *s
== '@')
6193 if (mri_string
&& *s
== '\'')
6197 else if (*s
== '\\')
6201 #ifdef TC_SINGLE_QUOTE_STRINGS
6202 || (TC_SINGLE_QUOTE_STRINGS
&& *s
== '\'')
6209 as_warn (_("missing closing `%c'"), inquote
);
6210 if (inescape
&& !ignore_input ())
6211 as_warn (_("stray `\\'"));
6216 find_end_of_line (char *s
, int mri_string
)
6218 return _find_end_of_line (s
, mri_string
, 0, 0);
6221 static char *saved_ilp
= NULL
;
6222 static char *saved_limit
;
6224 /* Use BUF as a temporary input pointer for calling other functions in this
6225 file. BUF must be a C string, so that its end can be found by strlen.
6226 Also sets the buffer_limit variable (local to this file) so that buffer
6227 overruns should not occur. Saves the current input line pointer so that
6228 it can be restored by calling restore_ilp().
6230 Does not support recursion. */
6233 temp_ilp (char *buf
)
6235 gas_assert (saved_ilp
== NULL
);
6236 gas_assert (buf
!= NULL
);
6238 saved_ilp
= input_line_pointer
;
6239 saved_limit
= buffer_limit
;
6240 /* Prevent the assert in restore_ilp from triggering if
6241 the input_line_pointer has not yet been initialised. */
6242 if (saved_ilp
== NULL
)
6243 saved_limit
= saved_ilp
= (char *) "";
6245 input_line_pointer
= buf
;
6246 buffer_limit
= buf
+ strlen (buf
);
6247 input_from_string
= TRUE
;
6250 /* Restore a saved input line pointer. */
6255 gas_assert (saved_ilp
!= NULL
);
6257 input_line_pointer
= saved_ilp
;
6258 buffer_limit
= saved_limit
;
6259 input_from_string
= FALSE
;