Coverage Report

Created: 2026-04-04 08:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/gas/read.c
Line
Count
Source
1
/* read.c - read a source file -
2
   Copyright (C) 1986-2026 Free Software Foundation, Inc.
3
4
   This file is part of GAS, the GNU Assembler.
5
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)
9
   any later version.
10
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.
15
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
19
   02110-1301, USA.  */
20
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)
25
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)
29
30
/* Routines that read assembler source text to build spaghetti in memory.
31
   Another group of these functions is in the expr.c module.  */
32
33
#include "as.h"
34
#include "safe-ctype.h"
35
#include "subsegs.h"
36
#include "sb.h"
37
#include "macro.h"
38
#include "obstack.h"
39
#include "ecoff.h"
40
#include "dw2gencfi.h"
41
#include "scfidw2gen.h"
42
#include "codeview.h"
43
#include "wchar.h"
44
#include "filenames.h"
45
#include "ginsn.h"
46
47
#include <limits.h>
48
49
#ifndef TC_START_LABEL
50
#define TC_START_LABEL(STR, NUL_CHAR, NEXT_CHAR) (NEXT_CHAR == ':')
51
#endif
52
53
/* Set by the object-format or the target.  */
54
#ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
55
#define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR)    \
56
4
  do                \
57
4
    {               \
58
4
      if ((SIZE) >= 8)           \
59
4
  (P2VAR) = 3;           \
60
4
      else if ((SIZE) >= 4)         \
61
3
  (P2VAR) = 2;           \
62
3
      else if ((SIZE) >= 2)         \
63
3
  (P2VAR) = 1;           \
64
3
      else              \
65
3
  (P2VAR) = 0;           \
66
4
    }               \
67
4
  while (0)
68
#endif
69
70
char *input_line_pointer; /*->next char of source file to parse.  */
71
bool input_from_string = false;
72
73
#if BITS_PER_CHAR != 8
74
/*  The following table is indexed by[(char)] and will break if
75
    a char does not have exactly 256 states (hopefully 0:255!)!  */
76
die horribly;
77
#endif
78
79
#ifndef CR_EOL
80
#define LEX_CR LEX_WHITE
81
#else
82
#define LEX_CR LEX_EOL
83
#endif
84
85
#ifndef LEX_AT
86
#define LEX_AT 0
87
#endif
88
89
#ifndef LEX_BR
90
/* The RS/6000 assembler uses {,},[,] as parts of symbol names.  */
91
#define LEX_BR 0
92
#endif
93
94
#ifndef LEX_PCT
95
/* The Delta 68k assembler permits % inside label names.  */
96
#define LEX_PCT 0
97
#endif
98
99
#ifndef LEX_QM
100
/* The PowerPC Windows NT assemblers permits ? inside label names.  */
101
17
#define LEX_QM 0
102
#endif
103
104
#ifndef LEX_HASH
105
/* The IA-64 assembler uses # as a suffix designating a symbol.  We include
106
   it in the symbol and strip it out in tc_canonicalize_symbol_name.  */
107
#define LEX_HASH 0
108
#endif
109
110
#ifndef LEX_DOLLAR
111
#define LEX_DOLLAR 3
112
#endif
113
114
#ifndef LEX_TILDE
115
/* The Delta 68k assembler permits ~ at start of label names.  */
116
#define LEX_TILDE 0
117
#endif
118
119
/* Used by is_... macros. our ctype[].  */
120
char lex_type[256] = {
121
  0x20, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0x20, 0, 0, LEX_CR, 0, 0, /* @ABCDEFGHIJKLMNO */
122
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
123
  8, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
124
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM,  /* 0123456789:;<=>? */
125
  LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,  /* @ABCDEFGHIJKLMNO */
126
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
127
  0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
128
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~.  */
129
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
130
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
131
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
132
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
133
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
134
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
135
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
136
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
137
};
138
139
#ifndef TC_CASE_SENSITIVE
140
char original_case_string[128];
141
#endif
142
143
/* Functions private to this file.  */
144
145
static char *buffer;  /* 1st char of each buffer of lines is here.  */
146
static char *buffer_limit;  /*->1 + last char in buffer.  */
147
148
/* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
149
   in the tc-<CPU>.h file.  See the "Porting GAS" section of the
150
   internals manual.  */
151
int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
152
153
/* Variables for handling include file directory table.  */
154
155
/* Table of pointers to directories to search for .include's.  */
156
const char **include_dirs;
157
158
/* How many are in the table.  */
159
size_t include_dir_count;
160
161
/* Length of longest in table.  */
162
size_t include_dir_maxlen;
163
164
#ifndef WORKING_DOT_WORD
165
struct broken_word *broken_words;
166
int new_broken_words;
167
#endif
168
169
/* The current offset into the absolute section.  We don't try to
170
   build frags in the absolute section, since no data can be stored
171
   there.  We just keep track of the current offset.  */
172
addressT abs_section_offset;
173
174
/* If this line had an MRI style label, it is stored in this variable.
175
   This is used by some of the MRI pseudo-ops.  */
176
symbolS *line_label;
177
178
/* This global variable is used to support MRI common sections.  We
179
   translate such sections into a common symbol.  This variable is
180
   non-NULL when we are in an MRI common section.  */
181
symbolS *mri_common_symbol;
182
183
/* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
184
   need to align to an even byte boundary unless the next pseudo-op is
185
   dc.b, ds.b, or dcb.b.  This variable is set to 1 if an alignment
186
   may be needed.  */
187
static int mri_pending_align;
188
189
/* Record the current function so that we can issue an error message for
190
   misplaced .func,.endfunc, and also so that .endfunc needs no
191
   arguments.  */
192
static char *current_name;
193
static char *current_label;
194
195
#ifndef NO_LISTING
196
#ifdef OBJ_ELF
197
static int dwarf_file;
198
static int dwarf_line;
199
200
/* This variable is set to be non-zero if the next string we see might
201
   be the name of the source file in DWARF debugging information.  See
202
   the comment in emit_expr for the format we look for.  */
203
static int dwarf_file_string;
204
#endif
205
#endif
206
207
/* If the target defines the md_frag_max_var hook then we know
208
   enough to implement the .bundle_align_mode features.  */
209
#ifdef md_frag_max_var
210
# define HANDLE_BUNDLE
211
#endif
212
213
#ifdef HANDLE_BUNDLE
214
/* .bundle_align_mode sets this.  Normally it's zero.  When nonzero,
215
   it's the exponent of the bundle size, and aligned instruction bundle
216
   mode is in effect.  */
217
static unsigned int bundle_align_p2;
218
219
/* These are set by .bundle_lock and .bundle_unlock.  .bundle_lock sets
220
   bundle_lock_frag to frag_now and then starts a new frag with
221
   frag_align_code.  At the same time, bundle_lock_frain gets frchain_now,
222
   so that .bundle_unlock can verify that we didn't change segments.
223
   .bundle_unlock resets both to NULL.  If we detect a bundling violation,
224
   then we reset bundle_lock_frchain to NULL as an indicator that we've
225
   already diagnosed the error with as_bad and don't need a cascade of
226
   redundant errors, but bundle_lock_frag remains set to indicate that
227
   we are expecting to see .bundle_unlock.  */
228
static fragS *bundle_lock_frag;
229
static frchainS *bundle_lock_frchain;
230
231
/* This is incremented by .bundle_lock and decremented by .bundle_unlock,
232
   to allow nesting.  */
233
static unsigned int bundle_lock_depth;
234
#endif
235
236
static void do_s_func (int end_p, const char *default_prefix);
237
static void s_altmacro (int);
238
static void s_bad_end (int);
239
static void s_errwarn_if (int);
240
static void s_reloc (int);
241
static int hex_float (int, char *);
242
static segT get_known_segmented_expression (expressionS * expP);
243
static void pobegin (void);
244
static void poend (void);
245
static size_t get_macro_line_sb (sb *);
246
static void generate_file_debug (void);
247
static char *_find_end_of_line (char *, int, int, int);
248
#if defined (TE_PE) && defined (O_secrel)
249
static void s_cv_comp (int sign);
250
#endif
251

252
void
253
read_begin (void)
254
567
{
255
567
  const char *p;
256
257
567
  pobegin ();
258
567
  obj_read_begin_hook ();
259
260
567
  obstack_begin (&cond_obstack, chunksize);
261
262
567
#ifndef tc_line_separator_chars
263
567
#define tc_line_separator_chars line_separator_chars
264
567
#endif
265
  /* Use machine dependent syntax.  */
266
1.13k
  for (p = tc_line_separator_chars; *p; p++)
267
567
    lex_type[(unsigned char) *p] = LEX_EOS;
268
269
567
  if (flag_mri)
270
340
    lex_type['?'] = LEX_BEGIN_NAME | LEX_NAME;
271
272
567
  stabs_begin ();
273
274
#ifndef WORKING_DOT_WORD
275
  broken_words = NULL;
276
  new_broken_words = 0;
277
#endif
278
279
567
  abs_section_offset = 0;
280
281
567
  line_label = NULL;
282
567
  mri_common_symbol = NULL;
283
567
  mri_pending_align = 0;
284
285
567
  current_name = NULL;
286
567
  current_label = NULL;
287
288
567
#ifndef NO_LISTING
289
567
#ifdef OBJ_ELF
290
567
  dwarf_file = 0;
291
567
  dwarf_line = -1;
292
567
  dwarf_file_string = 0;
293
567
#endif
294
567
#endif
295
296
567
#ifdef HANDLE_BUNDLE
297
567
  bundle_align_p2 = 0;
298
567
  bundle_lock_frag = NULL;
299
567
  bundle_lock_frchain = NULL;
300
567
  bundle_lock_depth = 0;
301
567
#endif
302
567
}
303
304
void
305
read_end (void)
306
567
{
307
567
  if (!ENABLE_LEAK_CHECK)
308
0
    return;
309
567
  stabs_end ();
310
567
  poend ();
311
567
  _obstack_free (&cond_obstack, NULL);
312
567
  free (current_name);
313
567
  free (current_label);
314
567
  free (include_dirs);
315
567
}
316

317
#ifndef TC_ADDRESS_BYTES
318
#define TC_ADDRESS_BYTES address_bytes
319
320
static inline int
321
address_bytes (void)
322
{
323
  /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
324
     contain an address.  */
325
  int n = (stdoutput->arch_info->bits_per_address - 1) / 8;
326
  n |= n >> 1;
327
  n |= n >> 2;
328
  n += 1;
329
  return n;
330
}
331
#endif
332
333
/* Set up pseudo-op tables.  */
334
335
static htab_t po_hash;
336
337
static const pseudo_typeS potable[] = {
338
  {"abort", s_abort, 0},
339
  {"align", s_align_ptwo, 0},
340
  {"altmacro", s_altmacro, 1},
341
  {"ascii", stringer, 8+0},
342
  {"asciz", stringer, 8+1},
343
  {"balign", s_align_bytes, 0},
344
  {"balignw", s_align_bytes, -2},
345
  {"balignl", s_align_bytes, -4},
346
  {"base64", s_base64, 0},
347
/* block  */
348
#ifdef HANDLE_BUNDLE
349
  {"bundle_align_mode", s_bundle_align_mode, 0},
350
  {"bundle_lock", s_bundle_lock, 0},
351
  {"bundle_unlock", s_bundle_unlock, 0},
352
#endif
353
  {"byte", cons, 1},
354
  {"comm", s_comm, 0},
355
  {"common", s_mri_common, 0},
356
  {"common.s", s_mri_common, 1},
357
#if defined (TE_PE) && defined (O_secrel)
358
  {"cv_scomp", s_cv_comp, 1},
359
  {"cv_ucomp", s_cv_comp, 0},
360
#endif
361
  {"data", s_data, 0},
362
  {"dc", cons, 2},
363
  {"dc.a", cons, 0},
364
  {"dc.b", cons, 1},
365
  {"dc.d", float_cons, 'd'},
366
  {"dc.l", cons, 4},
367
  {"dc.s", float_cons, 'f'},
368
  {"dc.w", cons, 2},
369
  {"dc.x", float_cons, 'x'},
370
  {"dcb", s_space, 2},
371
  {"dcb.b", s_space, 1},
372
  {"dcb.d", s_float_space, 'd'},
373
  {"dcb.l", s_space, 4},
374
  {"dcb.s", s_float_space, 'f'},
375
  {"dcb.w", s_space, 2},
376
  {"dcb.x", s_float_space, 'x'},
377
  {"ds", s_space, 2},
378
  {"ds.b", s_space, 1},
379
  {"ds.d", s_space, 8},
380
  {"ds.l", s_space, 4},
381
  {"ds.p", s_space, 'p'},
382
  {"ds.s", s_space, 4},
383
  {"ds.w", s_space, 2},
384
  {"ds.x", s_space, 'x'},
385
  {"debug", s_ignore, 0},
386
#ifdef S_SET_DESC
387
  {"desc", s_desc, 0},
388
#endif
389
/* dim  */
390
  {"double", float_cons, 'd'},
391
/* dsect  */
392
  {"eject", listing_eject, 0},  /* Formfeed listing.  */
393
  {"else", s_else, 0},
394
  {"elsec", s_else, 0},
395
  {"elseif", s_elseif, (int) O_ne},
396
  {"end", s_end, 0},
397
  {"endc", s_endif, 0},
398
  {"endfunc", s_func, 1},
399
  {"endif", s_endif, 0},
400
  {"endm", s_bad_end, 0},
401
  {"endr", s_bad_end, 1},
402
/* endef  */
403
  {"equ", s_set, 0},
404
  {"equiv", s_set, 1},
405
  {"eqv", s_set, -1},
406
  {"err", s_err, 0},
407
  {"errif", s_errwarn_if, 1},
408
  {"error", s_errwarn, 1},
409
  {"exitm", s_mexit, 0},
410
/* extend  */
411
  {"extern", s_ignore, 0},  /* We treat all undef as ext.  */
412
  {"fail", s_fail, 0},
413
  {"file", s_file, 0},
414
  {"fill", s_fill, 0},
415
  {"float", float_cons, 'f'},
416
  {"format", s_ignore, 0},
417
  {"func", s_func, 0},
418
  {"global", s_globl, 0},
419
  {"globl", s_globl, 0},
420
  {"hword", cons, 2},
421
  {"if", s_if, (int) O_ne},
422
  {"ifb", s_ifb, 1},
423
  {"ifc", s_ifc, 0},
424
  {"ifdef", s_ifdef, 0},
425
  {"ifeq", s_if, (int) O_eq},
426
  {"ifeqs", s_ifeqs, 0},
427
  {"ifge", s_if, (int) O_ge},
428
  {"ifgt", s_if, (int) O_gt},
429
  {"ifle", s_if, (int) O_le},
430
  {"iflt", s_if, (int) O_lt},
431
  {"ifnb", s_ifb, 0},
432
  {"ifnc", s_ifc, 1},
433
  {"ifndef", s_ifdef, 1},
434
  {"ifne", s_if, (int) O_ne},
435
  {"ifnes", s_ifeqs, 1},
436
  {"ifnotdef", s_ifdef, 1},
437
  {"incbin", s_incbin, 0},
438
  {"include", s_include, 0},
439
  {"int", cons, 4},
440
  {"irp", s_irp, 0},
441
  {"irep", s_irp, 0},
442
  {"irpc", s_irp, 1},
443
  {"irepc", s_irp, 1},
444
  {"lcomm", s_lcomm, 0},
445
  {"lflags", s_ignore, 0},  /* Listing flags.  */
446
  {"linefile", s_linefile, 0},
447
  {"linkonce", s_linkonce, 0},
448
  {"list", listing_list, 1},  /* Turn listing on.  */
449
  {"llen", listing_psize, 1},
450
  {"long", cons, 4},
451
  {"lsym", s_lsym, 0},
452
  {"macro", s_macro, 0},
453
  {"mexit", s_mexit, 0},
454
  {"mri", s_mri, 0},
455
  {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode.  */
456
  {"name", s_ignore, 0},
457
  {"noaltmacro", s_altmacro, 0},
458
  {"noformat", s_ignore, 0},
459
  {"nolist", listing_list, 0},  /* Turn listing off.  */
460
  {"nopage", listing_nopage, 0},
461
  {"nop", s_nop, 0},
462
  {"nops", s_nops, 0},
463
  {"octa", cons, 16},
464
  {"offset", s_struct, 0},
465
  {"org", s_org, 0},
466
  {"p2align", s_align_ptwo, 0},
467
  {"p2alignw", s_align_ptwo, -2},
468
  {"p2alignl", s_align_ptwo, -4},
469
  {"page", listing_eject, 0},
470
  {"plen", listing_psize, 0},
471
  {"print", s_print, 0},
472
  {"psize", listing_psize, 0},  /* Set paper size.  */
473
  {"purgem", s_purgem, 0},
474
  {"quad", cons, 8},
475
  {"reloc", s_reloc, 0},
476
  {"rep", s_rept, 0},
477
  {"rept", s_rept, 1},
478
  {"rva", s_rva, 4},
479
  {"sbttl", listing_title, 1},  /* Subtitle of listing.  */
480
/* scl  */
481
/* sect  */
482
  {"set", s_set, 0},
483
  {"short", cons, 2},
484
  {"single", float_cons, 'f'},
485
/* size  */
486
  {"space", s_space, 0},
487
  {"skip", s_space, 0},
488
  {"sleb128", s_leb128, 1},
489
  {"spc", s_ignore, 0},
490
  {"stabd", s_stab, 'd'},
491
  {"stabn", s_stab, 'n'},
492
  {"stabs", s_stab, 's'},
493
  {"string", stringer, 8+1},
494
  {"string8", stringer, 8+1},
495
  {"string16", stringer, 16+1},
496
  {"string32", stringer, 32+1},
497
  {"string64", stringer, 64+1},
498
  {"struct", s_struct, 0},
499
/* tag  */
500
  {"text", s_text, 0},
501
502
  /* This is for gcc to use.  It's only just been added (2/94), so gcc
503
     won't be able to use it for a while -- probably a year or more.
504
     But once this has been released, check with gcc maintainers
505
     before deleting it or even changing the spelling.  */
506
  {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
507
  /* If we're folding case -- done for some targets, not necessarily
508
     all -- the above string in an input file will be converted to
509
     this one.  Match it either way...  */
510
  {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
511
512
  {"title", listing_title, 0},  /* Listing title.  */
513
  {"ttl", listing_title, 0},
514
/* type  */
515
  {"uleb128", s_leb128, 0},
516
/* use  */
517
/* val  */
518
  {"xcom", s_comm, 0},
519
  {"xdef", s_globl, 0},
520
  {"xref", s_ignore, 0},
521
  {"xstabs", s_xstab, 's'},
522
  {"warnif", s_errwarn_if, 0},
523
  {"warning", s_errwarn, 0},
524
  {"weakref", s_weakref, 0},
525
  {"word", cons, 2},
526
  {"zero", s_space, 0},
527
  {"2byte", cons, 2},
528
  {"4byte", cons, 4},
529
  {"8byte", cons, 8},
530
  {NULL, NULL, 0}     /* End sentinel.  */
531
};
532
533
static offsetT
534
get_absolute_expr (expressionS *exp)
535
22.6k
{
536
22.6k
  expression_and_evaluate (exp);
537
538
22.6k
  if (exp->X_op != O_constant)
539
8.33k
    {
540
8.33k
      if (exp->X_op != O_absent)
541
5.88k
  as_bad (_("bad or irreducible absolute expression"));
542
8.33k
      exp->X_add_number = 0;
543
8.33k
    }
544
22.6k
  return exp->X_add_number;
545
22.6k
}
546
547
offsetT
548
get_absolute_expression (void)
549
22.4k
{
550
22.4k
  expressionS exp;
551
552
22.4k
  return get_absolute_expr (&exp);
553
22.4k
}
554
555
static int pop_override_ok;
556
static const char *pop_table_name;
557
558
void
559
pop_insert (const pseudo_typeS *table)
560
2.26k
{
561
2.26k
  const pseudo_typeS *pop;
562
144k
  for (pop = table; pop->poc_name; pop++)
563
141k
    {
564
141k
      if (str_hash_insert (po_hash, pop->poc_name, pop, 0) != NULL)
565
5.10k
  {
566
5.10k
    if (!pop_override_ok)
567
0
      as_fatal (_("error constructing %s pseudo-op table"),
568
0
          pop_table_name);
569
5.10k
  }
570
141k
    }
571
2.26k
}
572
573
#ifndef md_pop_insert
574
567
#define md_pop_insert()   pop_insert(md_pseudo_table)
575
#endif
576
577
#ifndef obj_pop_insert
578
#define obj_pop_insert()  pop_insert(obj_pseudo_table)
579
#endif
580
581
#ifndef cfi_pop_insert
582
567
#define cfi_pop_insert()  pop_insert(cfi_pseudo_table)
583
#endif
584
585
#ifndef scfi_pop_insert
586
0
#define scfi_pop_insert() pop_insert(scfi_pseudo_table)
587
#endif
588
589
static void
590
pobegin (void)
591
567
{
592
567
  po_hash = str_htab_create ();
593
594
  /* Do the target-specific pseudo ops.  */
595
567
  pop_table_name = "md";
596
567
  pop_override_ok = 0;
597
567
  md_pop_insert ();
598
599
  /* Now object specific.  Skip any that were in the target table.  */
600
567
  pop_table_name = "obj";
601
567
  pop_override_ok = 1;
602
567
  obj_pop_insert ();
603
604
  /* Now portable ones.  Skip any that we've seen already.  */
605
567
  pop_table_name = "standard";
606
567
  pop_insert (potable);
607
608
  /* Now CFI ones.  */
609
567
#if defined (TARGET_USE_SCFI) && defined (TARGET_USE_GINSN)
610
567
  if (flag_synth_cfi)
611
0
    {
612
0
      pop_table_name = "scfi";
613
0
      scfi_pop_insert ();
614
0
    }
615
567
  else
616
567
#endif
617
567
    {
618
567
      pop_table_name = "cfi";
619
567
      cfi_pop_insert ();
620
567
    }
621
567
}
622
623
static void
624
poend (void)
625
567
{
626
567
  if (ENABLE_LEAK_CHECK)
627
567
    htab_delete (po_hash);
628
567
}
629

630
#define HANDLE_CONDITIONAL_ASSEMBLY(num_read)       \
631
396k
  if (ignore_input ())             \
632
396k
    {                 \
633
90
      char *eol = find_end_of_line (input_line_pointer - (num_read),  \
634
90
            flag_m68k_mri);      \
635
90
      input_line_pointer = (input_line_pointer <= buffer_limit    \
636
90
          && eol >= buffer_limit)     \
637
90
         ? buffer_limit        \
638
90
         : eol + 1;         \
639
90
      continue;               \
640
90
    }
641
642
/* Helper function of read_a_source_file, which tries to expand a macro.  */
643
static int
644
try_macro (char term, const char *line)
645
2.69k
{
646
2.69k
  sb out;
647
2.69k
  const char *err;
648
2.69k
  macro_entry *macro;
649
650
2.69k
  if (check_macro (line, &out, &err, &macro))
651
211
    {
652
211
      if (err != NULL)
653
20
  as_bad ("%s", err);
654
211
      *input_line_pointer++ = term;
655
211
      input_scrub_include_sb (&out,
656
211
            input_line_pointer, expanding_macro);
657
211
      sb_kill (&out);
658
211
      buffer_limit =
659
211
  input_scrub_next_buffer (&input_line_pointer);
660
#ifdef md_macro_info
661
      md_macro_info (macro);
662
#endif
663
211
      return 1;
664
211
    }
665
2.48k
  return 0;
666
2.69k
}
667
668
#ifdef HANDLE_BUNDLE
669
/* Start a new instruction bundle.  Returns the rs_align_code frag that
670
   will be used to align the new bundle.  */
671
static fragS *
672
start_bundle (void)
673
238
{
674
238
  fragS *frag = frag_now;
675
676
238
  frag_align_code (bundle_align_p2, 0);
677
678
238
  while (frag->fr_type != rs_align_code)
679
0
    frag = frag->fr_next;
680
681
238
  gas_assert (frag != frag_now);
682
683
  /* Set initial alignment to zero.  */
684
238
  frag->fr_offset = 0;
685
686
238
  return frag;
687
238
}
688
689
/* Calculate the maximum size after relaxation of the region starting
690
   at the given frag and extending through frag_now (which is unfinished).  */
691
static valueT
692
pending_bundle_size (fragS *frag)
693
460
{
694
460
  valueT offset = frag->fr_fix;
695
460
  valueT size = 0;
696
697
460
  gas_assert (frag != frag_now);
698
460
  gas_assert (frag->fr_type == rs_align_code);
699
700
999
  while (frag != frag_now)
701
539
    {
702
      /* This should only happen in what will later become an error case.  */
703
539
      if (frag == NULL)
704
0
  return 0;
705
706
539
      size += frag->fr_fix;
707
539
      if (frag->fr_type == rs_machine_dependent)
708
3
  size += md_frag_max_var (frag);
709
710
539
      frag = frag->fr_next;
711
539
    }
712
713
460
  gas_assert (frag == frag_now);
714
460
  size += frag_now_fix ();
715
460
  if (frag->fr_type == rs_machine_dependent)
716
0
    size += md_frag_max_var (frag);
717
718
460
  gas_assert (size >= offset || now_seg == absolute_section);
719
720
460
  return size - offset;
721
460
}
722
723
/* Finish off the frag created to ensure bundle alignment.  */
724
static void
725
finish_bundle (fragS *frag, valueT size)
726
235
{
727
235
  gas_assert (bundle_align_p2 > 0);
728
235
  gas_assert (frag->fr_type == rs_align_code);
729
730
235
  if (size > 1)
731
40
    {
732
      /* If there is more than a single byte, then we need to set up
733
   the alignment frag.  Otherwise we leave it at its initial
734
   state with zero alignment so that it does nothing.  */
735
40
      frag->fr_offset = bundle_align_p2;
736
40
      frag->fr_subtype = size - 1;
737
40
    }
738
739
  /* We do this every time rather than just in s_bundle_align_mode
740
     so that we catch any affected section without needing hooks all
741
     over for all paths that do section changes.  It's cheap enough.  */
742
235
  if (bundle_align_p2 > OCTETS_PER_BYTE_POWER)
743
235
    record_alignment (now_seg, bundle_align_p2 - OCTETS_PER_BYTE_POWER);
744
235
}
745
746
/* Assemble one instruction.  This takes care of the bundle features
747
   around calling md_assemble.  */
748
static void
749
assemble_one (char *line)
750
78.0k
{
751
78.0k
  fragS *insn_start_frag = NULL;
752
753
78.0k
  if (bundle_lock_frchain != NULL && bundle_lock_frchain != frchain_now)
754
1
    {
755
1
      as_bad (_("cannot change section or subsection inside .bundle_lock"));
756
      /* Clearing this serves as a marker that we have already complained.  */
757
1
      bundle_lock_frchain = NULL;
758
1
    }
759
760
78.0k
  if (bundle_lock_frchain == NULL && bundle_align_p2 > 0)
761
235
    insn_start_frag = start_bundle ();
762
763
78.0k
  md_assemble (line);
764
765
78.0k
  if (bundle_lock_frchain != NULL)
766
225
    {
767
      /* Make sure this hasn't pushed the locked sequence
768
   past the bundle size.  */
769
225
      valueT bundle_size = pending_bundle_size (bundle_lock_frag);
770
225
      if (bundle_size > (valueT) 1 << bundle_align_p2)
771
32
  as_bad (_ (".bundle_lock sequence at %" PRIu64 " bytes, "
772
32
       "but .bundle_align_mode limit is %" PRIu64 " bytes"),
773
32
    (uint64_t) bundle_size, (uint64_t) 1 << bundle_align_p2);
774
225
    }
775
77.7k
  else if (bundle_align_p2 > 0)
776
235
    {
777
235
      valueT insn_size = pending_bundle_size (insn_start_frag);
778
779
235
      if (insn_size > (valueT) 1 << bundle_align_p2)
780
36
  as_bad (_("single instruction is %" PRIu64 " bytes long, "
781
36
      "but .bundle_align_mode limit is %" PRIu64 " bytes"),
782
36
    (uint64_t) insn_size, (uint64_t) 1 << bundle_align_p2);
783
784
235
      finish_bundle (insn_start_frag, insn_size);
785
235
    }
786
78.0k
}
787
788
#else  /* !HANDLE_BUNDLE */
789
790
# define assemble_one(line) md_assemble(line)
791
792
#endif  /* HANDLE_BUNDLE */
793
794
static bool
795
in_bss (void)
796
13.5k
{
797
13.5k
  flagword flags = bfd_section_flags (now_seg);
798
799
13.5k
  return (flags & SEC_ALLOC) && !(flags & (SEC_LOAD | SEC_HAS_CONTENTS));
800
13.5k
}
801
802
/* Guts of .align directive:
803
   N is the power of two to which to align.  A value of zero is accepted but
804
    ignored: the default alignment of the section will be at least this.
805
   FILL may be NULL, or it may point to the bytes of the fill pattern.
806
   LEN is the length of whatever FILL points to, if anything.  If LEN is zero
807
    but FILL is not NULL then LEN is treated as if it were one.
808
   MAX is the maximum number of characters to skip when doing the alignment,
809
    or 0 if there is no maximum.  */
810
811
void
812
do_align (unsigned int n, char *fill, unsigned int len, unsigned int max)
813
1.84k
{
814
1.84k
  if (now_seg == absolute_section || in_bss ())
815
469
    {
816
469
      if (fill != NULL)
817
571
  while (len-- > 0)
818
434
    if (*fill++ != '\0')
819
297
      {
820
297
        if (now_seg == absolute_section)
821
296
    as_warn (_("ignoring fill value in absolute section"));
822
1
        else
823
1
    as_warn (_("ignoring fill value in section `%s'"),
824
1
       segment_name (now_seg));
825
297
        break;
826
297
      }
827
469
      fill = NULL;
828
469
      len = 0;
829
469
    }
830
831
#ifdef md_flush_pending_output
832
  md_flush_pending_output ();
833
#endif
834
835
1.84k
#ifdef md_do_align
836
1.84k
  md_do_align (n, fill, len, max, just_record_alignment);
837
1.69k
#endif
838
839
  /* Only make a frag if we HAVE to...  */
840
1.69k
  if ((n > OCTETS_PER_BYTE_POWER) && !need_pass_2)
841
983
    {
842
983
      if (fill == NULL)
843
336
  {
844
336
    if (subseg_text_p (now_seg))
845
0
      frag_align_code (n, max);
846
336
    else
847
336
      frag_align (n, 0, max);
848
336
  }
849
647
      else if (len <= 1)
850
647
  frag_align (n, *fill, max);
851
0
      else
852
0
  frag_align_pattern (n, fill, len, max);
853
983
    }
854
855
1.69k
#ifdef md_do_align
856
1.84k
 just_record_alignment: ATTRIBUTE_UNUSED_LABEL
857
1.84k
#endif
858
859
1.84k
  if (n > OCTETS_PER_BYTE_POWER)
860
1.13k
    record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
861
1.84k
}
862
863
/* Find first <eol><next_char>NO_APP<eol>, if any, in the supplied buffer.
864
   Return NULL if there's none, or else the position of <next_char>.
865
   
866
   Note: the S parameter to this function is typed as CHAR* rather than
867
   CONST CHAR* because if it is const then the strstr() function will return
868
   a const pointer, which in turn means that the END local would need to be
869
   const, which would mean that the function itself would have to return a
870
   const pointer, which means that input_line_pointer would have to become
871
   const, which would break lots of things.  (See PR 33696).  */
872
873
static char *
874
find_no_app (char *s, char next_char)
875
419
{
876
419
  const char *start = s;
877
419
  const char srch[] = { next_char, 'N', 'O', '_', 'A', 'P', 'P', '\0' };
878
879
419
  for (;;)
880
10.8k
    {
881
10.8k
      char * ends = strstr (s, srch);
882
883
10.8k
      if (ends == NULL)
884
399
  break;
885
10.4k
      if (is_end_of_line (ends[sizeof (srch) - 1])
886
4.18k
    && (ends == start || is_end_of_line (ends[-1])))
887
20
  return ends;
888
10.4k
      s = ends + sizeof (srch) - 1;
889
10.4k
    }
890
891
399
  return NULL;
892
419
}
893
894
/* We read the file, putting things into a web that represents what we
895
   have been reading.  */
896
void
897
read_a_source_file (const char *name)
898
567
{
899
567
  char nul_char;
900
567
  char next_char;
901
567
  char *s;    /* String of symbol, '\0' appended.  */
902
567
  long temp;
903
567
  const pseudo_typeS *pop;
904
905
#ifdef WARN_COMMENTS
906
  found_comment = 0;
907
#endif
908
909
567
  set_identify_name (name);
910
911
567
  buffer = input_scrub_new_file (name);
912
913
567
  listing_file (name);
914
567
  listing_newline (NULL);
915
567
  register_dependency (name);
916
917
  /* Generate debugging information before we've read anything in to denote
918
     this file as the "main" source file and not a subordinate one
919
     (e.g. N_SO vs N_SOL in stabs).  */
920
567
  generate_file_debug ();
921
922
2.05k
  while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
923
1.49k
    {       /* We have another line to parse.  */
924
1.49k
#ifndef NO_LISTING
925
      /* In order to avoid listing macro expansion lines with labels
926
   multiple times, keep track of which line was last issued.  */
927
1.49k
      char *last_eol = NULL;
928
929
1.49k
#endif
930
514k
      while (input_line_pointer < buffer_limit)
931
512k
  {
932
512k
    char was_new_line;
933
    /* We have more of this buffer to parse.  */
934
935
    /* We now have input_line_pointer->1st char of next line.
936
       If input_line_pointer [-1] == '\n' then we just
937
       scanned another line: so bump line counters.  */
938
512k
    was_new_line = lex_type[(unsigned char) input_line_pointer[-1]]
939
512k
       & (LEX_EOL | LEX_EOS);
940
512k
    if (was_new_line)
941
496k
      {
942
496k
        symbol_set_value_now (&dot_symbol);
943
496k
#ifdef md_start_line_hook
944
496k
        md_start_line_hook ();
945
496k
#endif
946
496k
        if (input_line_pointer[-1] == '\n')
947
341k
    bump_line_counters ();
948
496k
      }
949
950
512k
#ifndef NO_LISTING
951
    /* If listing is on, and we are expanding a macro, then give
952
       the listing code the contents of the expanded line.  */
953
512k
    if (listing)
954
0
      {
955
0
        if ((listing & LISTING_MACEXP) && macro_nest > 0)
956
0
    {
957
      /* Find the end of the current expanded macro line.  */
958
0
      s = find_end_of_line (input_line_pointer, flag_m68k_mri);
959
960
0
      if (s != last_eol
961
0
          && !startswith (input_line_pointer,
962
0
              !flag_m68k_mri ? " .linefile "
963
0
                 : " linefile "))
964
0
        {
965
0
          char *copy;
966
0
          size_t len;
967
968
0
          last_eol = s;
969
          /* Copy it for safe keeping.  Also give an indication of
970
       how much macro nesting is involved at this point.  */
971
0
          len = s - input_line_pointer;
972
0
          copy = XNEWVEC (char, len + macro_nest + 2);
973
0
          memset (copy, '>', macro_nest);
974
0
          copy[macro_nest] = ' ';
975
0
          memcpy (copy + macro_nest + 1, input_line_pointer, len);
976
0
          copy[macro_nest + 1 + len] = '\0';
977
978
          /* Install the line with the listing facility.  */
979
0
          listing_newline (copy);
980
0
        }
981
0
    }
982
0
        else
983
0
    listing_newline (NULL);
984
0
      }
985
512k
#endif
986
987
512k
    next_char = *input_line_pointer;
988
512k
    if ((was_new_line & LEX_EOL)
989
395k
             && (strchr (line_comment_chars, '#')
990
395k
      ? next_char == '#'
991
395k
      : next_char && strchr (line_comment_chars, next_char)))
992
1.10k
      {
993
        /* Its a comment.  Check for APP followed by NO_APP.  */
994
1.10k
        sb sbuf;
995
1.10k
        char *ends;
996
1.10k
        size_t len;
997
998
1.10k
        s = input_line_pointer + 1;
999
1.10k
        if (!startswith (s, "APP") || !is_end_of_line (s[3]))
1000
892
    {
1001
      /* We ignore it.  Note: Not ignore_rest_of_line ()!  */
1002
27.3k
      while (s <= buffer_limit)
1003
27.3k
        if (is_end_of_line (*s++))
1004
892
          break;
1005
892
      input_line_pointer = s;
1006
892
      continue;
1007
892
    }
1008
215
        s += 4;
1009
1010
215
        ends = find_no_app (s, next_char);
1011
215
        len = ends ? ends - s : buffer_limit - s;
1012
1013
215
        sb_build (&sbuf, len + 100);
1014
215
        sb_add_buffer (&sbuf, s, len);
1015
215
        if (!ends)
1016
200
    {
1017
      /* The end of the #APP wasn't in this buffer.  We
1018
         keep reading in buffers until we find the #NO_APP
1019
         that goes with this #APP  There is one.  The specs
1020
         guarantee it...  */
1021
200
      do
1022
399
        {
1023
399
          buffer_limit = input_scrub_next_buffer (&buffer);
1024
399
          if (!buffer_limit)
1025
195
      break;
1026
204
          ends = find_no_app (buffer, next_char);
1027
204
          len = ends ? ends - buffer : buffer_limit - buffer;
1028
204
          sb_add_buffer (&sbuf, buffer, len);
1029
204
        }
1030
204
      while (!ends);
1031
200
    }
1032
215
        sb_add_char (&sbuf, '\n');
1033
1034
215
        input_line_pointer = ends ? ends + 8 : NULL;
1035
215
        input_scrub_include_sb (&sbuf, input_line_pointer, expanding_app);
1036
215
        sb_kill (&sbuf);
1037
215
        buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1038
215
        continue;
1039
1.10k
      }
1040
1041
511k
    if (was_new_line)
1042
495k
      {
1043
495k
        line_label = NULL;
1044
1045
495k
        if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
1046
0
    {
1047
0
      next_char = * input_line_pointer;
1048
      /* Text at the start of a line must be a label, we
1049
         run down and stick a colon in.  */
1050
0
      if (is_name_beginner (next_char) || next_char == '"')
1051
0
        {
1052
0
          char *line_start;
1053
0
          int mri_line_macro;
1054
1055
0
          HANDLE_CONDITIONAL_ASSEMBLY (0);
1056
1057
0
          nul_char = get_symbol_name (& line_start);
1058
0
          next_char = (nul_char == '"' ? input_line_pointer[1] : nul_char);
1059
1060
          /* In MRI mode, the EQU and MACRO pseudoops must
1061
       be handled specially.  */
1062
0
          mri_line_macro = 0;
1063
0
          if (flag_m68k_mri)
1064
0
      {
1065
0
        char *rest = input_line_pointer + 1;
1066
1067
0
        if (*rest == ':')
1068
0
          ++rest;
1069
0
        if (is_whitespace (*rest))
1070
0
          ++rest;
1071
0
        if ((strncasecmp (rest, "EQU", 3) == 0
1072
0
             || strncasecmp (rest, "SET", 3) == 0)
1073
0
            && is_whitespace (rest[3]))
1074
0
          {
1075
0
            input_line_pointer = rest + 3;
1076
0
            equals (line_start,
1077
0
              strncasecmp (rest, "SET", 3) == 0);
1078
0
            continue;
1079
0
          }
1080
0
        if (strncasecmp (rest, "MACRO", 5) == 0
1081
0
            && (is_whitespace (rest[5])
1082
0
          || is_end_of_stmt (rest[5])))
1083
0
          mri_line_macro = 1;
1084
0
      }
1085
1086
          /* In MRI mode, we need to handle the MACRO
1087
       pseudo-op specially: we don't want to put the
1088
       symbol in the symbol table.  */
1089
0
          if (!mri_line_macro
1090
#ifdef TC_START_LABEL_WITHOUT_COLON
1091
        && TC_START_LABEL_WITHOUT_COLON (nul_char, next_char)
1092
#endif
1093
0
        )
1094
0
      line_label = colon (line_start);
1095
0
          else
1096
0
      line_label = symbol_create (line_start,
1097
0
                absolute_section,
1098
0
                &zero_address_frag, 0);
1099
1100
0
          next_char = restore_line_pointer (nul_char);
1101
0
          if (next_char == ':')
1102
0
      input_line_pointer++;
1103
0
        }
1104
0
    }
1105
495k
      }
1106
1107
    /* We are at the beginning of a line, or similar place.
1108
       We expect a well-formed assembler statement.
1109
       A "symbol-name:" is a statement.
1110
1111
       Depending on what compiler is used, the order of these tests
1112
       may vary to catch most common case 1st.
1113
       Each test is independent of all other tests at the (top)
1114
       level.  */
1115
511k
    do
1116
724k
      nul_char = next_char = *input_line_pointer++;
1117
724k
    while (is_whitespace (next_char) || next_char == '\f');
1118
1119
    /* C is the 1st significant character.
1120
       Input_line_pointer points after that character.  */
1121
511k
    if (is_name_beginner (next_char) || next_char == '"')
1122
347k
      {
1123
347k
        char *rest;
1124
1125
        /* Want user-defined label or pseudo/opcode.  */
1126
347k
        HANDLE_CONDITIONAL_ASSEMBLY (1);
1127
1128
347k
        --input_line_pointer;
1129
347k
        nul_char = get_symbol_name (& s); /* name's delimiter.  */
1130
347k
        next_char = (nul_char == '"' ? input_line_pointer[1] : nul_char);
1131
347k
        rest = input_line_pointer + (nul_char == '"' ? 2 : 1);
1132
1133
        /* NEXT_CHAR is character after symbol.
1134
     The end of symbol in the input line is now '\0'.
1135
     S points to the beginning of the symbol.
1136
       [In case of pseudo-op, s->'.'.]
1137
     Input_line_pointer->'\0' where NUL_CHAR was.  */
1138
347k
        if (TC_START_LABEL (s, nul_char, next_char))
1139
4.25k
    {
1140
4.25k
      if (flag_m68k_mri)
1141
0
        {
1142
          /* In MRI mode, \tsym: set 0 is permitted.  */
1143
0
          if (*rest == ':')
1144
0
      ++rest;
1145
1146
0
          if (is_whitespace (*rest))
1147
0
      ++rest;
1148
1149
0
          if ((strncasecmp (rest, "EQU", 3) == 0
1150
0
         || strncasecmp (rest, "SET", 3) == 0)
1151
0
        && is_whitespace (rest[3]))
1152
0
      {
1153
0
        input_line_pointer = rest + 3;
1154
0
        equals (s, 1);
1155
0
        continue;
1156
0
      }
1157
0
        }
1158
1159
4.25k
      line_label = colon (s); /* User-defined label.  */
1160
4.25k
      restore_line_pointer (nul_char);
1161
4.25k
      ++ input_line_pointer;
1162
#ifdef tc_check_label
1163
      tc_check_label (line_label);
1164
#endif
1165
      /* Input_line_pointer->after ':'.  */
1166
4.25k
      SKIP_WHITESPACE ();
1167
4.25k
    }
1168
342k
        else if ((next_char == '=' && *rest == '=')
1169
335k
           || (is_whitespace (next_char)
1170
218k
         && rest[0] == '='
1171
1.43k
         && rest[1] == '='))
1172
7.66k
    {
1173
7.66k
      equals (s, -1);
1174
7.66k
      demand_empty_rest_of_line ();
1175
7.66k
    }
1176
335k
        else if ((next_char == '='
1177
322k
           || (is_whitespace (next_char)
1178
218k
          && *rest == '='))
1179
#ifdef TC_EQUAL_IN_INSN
1180
         && !TC_EQUAL_IN_INSN (next_char, s)
1181
#endif
1182
335k
         )
1183
14.6k
    {
1184
14.6k
      equals (s, 1);
1185
14.6k
      demand_empty_rest_of_line ();
1186
14.6k
    }
1187
320k
        else
1188
320k
    {
1189
      /* Expect pseudo-op or machine instruction.  */
1190
320k
      pop = NULL;
1191
1192
320k
#ifndef TC_CASE_SENSITIVE
1193
320k
      {
1194
320k
        char *s2 = s;
1195
1196
320k
        strncpy (original_case_string, s2,
1197
320k
           sizeof (original_case_string) - 1);
1198
320k
        original_case_string[sizeof (original_case_string) - 1] = 0;
1199
1200
2.70M
        while (*s2)
1201
2.38M
          {
1202
2.38M
      *s2 = TOLOWER (*s2);
1203
2.38M
      s2++;
1204
2.38M
          }
1205
320k
      }
1206
320k
#endif
1207
320k
      if (NO_PSEUDO_DOT || flag_m68k_mri)
1208
0
        {
1209
          /* The MRI assembler uses pseudo-ops without
1210
       a period.  */
1211
0
          pop = str_hash_find (po_hash, s);
1212
0
          if (pop != NULL && pop->poc_handler == NULL)
1213
0
      pop = NULL;
1214
0
        }
1215
1216
320k
      if (pop != NULL
1217
320k
          || (!flag_m68k_mri && *s == '.'))
1218
242k
        {
1219
          /* PSEUDO - OP.
1220
1221
       WARNING: next_char may be end-of-line.
1222
       We lookup the pseudo-op table with s+1 because we
1223
       already know that the pseudo-op begins with a '.'.  */
1224
1225
242k
          if (pop == NULL)
1226
242k
      pop = str_hash_find (po_hash, s + 1);
1227
242k
          if (pop && !pop->poc_handler)
1228
0
      pop = NULL;
1229
1230
          /* In MRI mode, we may need to insert an
1231
       automatic alignment directive.  What a hack
1232
       this is.  */
1233
242k
          if (mri_pending_align
1234
52
        && (pop == NULL
1235
38
            || !((pop->poc_handler == cons
1236
4
            && pop->poc_val == 1)
1237
34
           || (pop->poc_handler == s_space
1238
7
               && pop->poc_val == 1)
1239
#ifdef tc_conditional_pseudoop
1240
           || tc_conditional_pseudoop (pop)
1241
#endif
1242
34
           || pop->poc_handler == s_if
1243
34
           || pop->poc_handler == s_ifdef
1244
34
           || pop->poc_handler == s_ifc
1245
28
           || pop->poc_handler == s_ifeqs
1246
28
           || pop->poc_handler == s_else
1247
28
           || pop->poc_handler == s_endif
1248
23
           || pop->poc_handler == s_globl
1249
23
           || pop->poc_handler == s_ignore)))
1250
37
      {
1251
37
        do_align (1, NULL, 0, 0);
1252
37
        mri_pending_align = 0;
1253
1254
37
        if (line_label != NULL)
1255
0
          {
1256
0
            symbol_set_frag (line_label, frag_now);
1257
0
            S_SET_VALUE (line_label, frag_now_fix ());
1258
0
          }
1259
37
      }
1260
1261
          /* Print the error msg now, while we still can.  */
1262
242k
          if (pop == NULL)
1263
45.8k
      {
1264
45.8k
        char *end = input_line_pointer;
1265
1266
45.8k
        (void) restore_line_pointer (nul_char);
1267
45.8k
        s_ignore (0);
1268
45.8k
        nul_char = next_char = *--input_line_pointer;
1269
45.8k
        *input_line_pointer = '\0';
1270
45.8k
        if (! macro_defined || ! try_macro (next_char, s))
1271
45.8k
          {
1272
45.8k
            *end = '\0';
1273
45.8k
            as_bad (_("unknown pseudo-op: `%s'"), s);
1274
45.8k
            *input_line_pointer++ = nul_char;
1275
45.8k
          }
1276
45.8k
        continue;
1277
45.8k
      }
1278
1279
          /* Put it back for error messages etc.  */
1280
196k
          next_char = restore_line_pointer (nul_char);
1281
          /* The following skip of whitespace is compulsory.
1282
       A well shaped space is sometimes all that separates
1283
       keyword from operands.  */
1284
196k
          if (is_whitespace (next_char))
1285
176k
      input_line_pointer++;
1286
1287
          /* Input_line is restored.
1288
       Input_line_pointer->1st non-blank char
1289
       after pseudo-operation.  */
1290
196k
          (*pop->poc_handler) (pop->poc_val);
1291
1292
          /* If that was .end, just get out now.  */
1293
196k
          if (pop->poc_handler == s_end)
1294
3
      goto quit;
1295
196k
        }
1296
78.2k
      else
1297
78.2k
        {
1298
          /* WARNING: next_char may be end-of-line.  */
1299
          /* Also: input_line_pointer->`\0` where nul_char was.  */
1300
78.2k
          (void) restore_line_pointer (nul_char);
1301
78.2k
          input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1, 0);
1302
78.2k
          next_char = nul_char = *input_line_pointer;
1303
78.2k
          *input_line_pointer = '\0';
1304
1305
78.2k
          generate_lineno_debug ();
1306
1307
78.2k
          if (macro_defined && try_macro (next_char, s))
1308
205
      continue;
1309
1310
78.0k
          if (mri_pending_align)
1311
12
      {
1312
12
        do_align (1, NULL, 0, 0);
1313
12
        mri_pending_align = 0;
1314
12
        if (line_label != NULL)
1315
2
          {
1316
2
            symbol_set_frag (line_label, frag_now);
1317
2
            S_SET_VALUE (line_label, frag_now_fix ());
1318
2
          }
1319
12
      }
1320
1321
78.0k
          assemble_one (s); /* Assemble 1 instruction.  */
1322
1323
          /* PR 19630: The backend may have set ilp to NULL
1324
       if it encountered a catastrophic failure.  */
1325
78.0k
          if (input_line_pointer == NULL)
1326
0
      as_fatal (_("unable to continue with assembly."));
1327
 
1328
78.0k
          *input_line_pointer++ = nul_char;
1329
1330
          /* We resume loop AFTER the end-of-line from
1331
       this instruction.  */
1332
78.0k
        }
1333
320k
    }
1334
301k
        continue;
1335
347k
      }
1336
1337
    /* Empty statement?  */
1338
164k
    if (is_end_of_stmt (next_char))
1339
127k
      continue;
1340
1341
37.4k
    if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (next_char))
1342
16.7k
      {
1343
        /* local label  ("4:")  */
1344
16.7k
        char *backup = input_line_pointer;
1345
1346
16.7k
        HANDLE_CONDITIONAL_ASSEMBLY (1);
1347
1348
16.7k
        temp = next_char - '0';
1349
1350
        /* Read the whole number.  */
1351
16.7k
        while (ISDIGIT (*input_line_pointer))
1352
25.1k
    {
1353
25.1k
      const long digit = *input_line_pointer - '0';
1354
1355
      /* Don't accept labels which look like octal numbers.  */
1356
25.1k
      if (temp == 0)
1357
499
        break;
1358
24.6k
      if (temp > (INT_MAX - digit) / 10)
1359
500
        {
1360
500
          as_bad (_("local label too large near %s"), backup);
1361
500
          temp = -1;
1362
500
          break;
1363
500
        }
1364
24.1k
      temp = temp * 10 + digit;
1365
24.1k
      ++input_line_pointer;
1366
24.1k
    }
1367
1368
        /* Overflow: stop processing the label.  */
1369
16.7k
        if (temp == -1)
1370
500
    {
1371
500
      ignore_rest_of_line ();
1372
500
      continue;
1373
500
    }
1374
1375
16.2k
        if (LOCAL_LABELS_DOLLAR
1376
0
      && *input_line_pointer == '$'
1377
0
      && *(input_line_pointer + 1) == ':')
1378
0
    {
1379
0
      input_line_pointer += 2;
1380
1381
0
      if (dollar_label_defined (temp))
1382
0
        {
1383
0
          as_fatal (_("label \"%ld$\" redefined"), temp);
1384
0
        }
1385
1386
0
      define_dollar_label (temp);
1387
0
      colon (dollar_label_name (temp, 0));
1388
0
      continue;
1389
0
    }
1390
1391
16.2k
        if (LOCAL_LABELS_FB
1392
16.2k
      && *input_line_pointer++ == ':')
1393
4.61k
    {
1394
4.61k
      fb_label_instance_inc (temp);
1395
4.61k
      colon (fb_label_name (temp, 0));
1396
4.61k
      continue;
1397
4.61k
    }
1398
1399
11.5k
        input_line_pointer = backup;
1400
11.5k
      }
1401
1402
32.3k
    if (next_char && strchr (line_comment_chars, next_char))
1403
131
      {
1404
        /* Its a comment, ignore it.  Note: Not ignore_rest_of_line ()!  */
1405
131
        s = input_line_pointer;
1406
1.45k
        while (s <= buffer_limit)
1407
1.45k
    if (is_end_of_line (*s++))
1408
131
      break;
1409
131
        input_line_pointer = s;
1410
131
        continue;
1411
131
      }
1412
1413
32.1k
    HANDLE_CONDITIONAL_ASSEMBLY (1);
1414
1415
32.1k
#ifdef tc_unrecognized_line
1416
32.1k
    if (tc_unrecognized_line (next_char))
1417
877
      continue;
1418
31.2k
#endif
1419
31.2k
    input_line_pointer--;
1420
    /* Report unknown char as error.  */
1421
31.2k
    demand_empty_rest_of_line ();
1422
31.2k
  }
1423
1.49k
    }
1424
1425
567
 quit:
1426
567
  symbol_set_value_now (&dot_symbol);
1427
1428
567
#ifdef HANDLE_BUNDLE
1429
567
  if (bundle_lock_frag != NULL)
1430
3
    {
1431
3
      as_bad_where (bundle_lock_frag->fr_file, bundle_lock_frag->fr_line,
1432
3
        _(".bundle_lock with no matching .bundle_unlock"));
1433
3
      bundle_lock_frag = NULL;
1434
3
      bundle_lock_frchain = NULL;
1435
3
      bundle_lock_depth = 0;
1436
3
    }
1437
567
#endif
1438
1439
567
  if (flag_synth_cfi)
1440
0
    ginsn_data_end (symbol_temp_new_now ());
1441
1442
567
#ifdef md_cleanup
1443
567
  md_cleanup ();
1444
567
#endif
1445
  /* Close the input file.  */
1446
567
  input_scrub_close ();
1447
#ifdef WARN_COMMENTS
1448
  {
1449
    if (warn_comment && found_comment)
1450
      as_warn_where (found_comment_file, found_comment,
1451
         "first comment found here");
1452
  }
1453
#endif
1454
567
}
1455
1456
/* Convert O_constant expression EXP into the equivalent O_big
1457
   representation.  */
1458
1459
static bool
1460
convert_to_bignum (expressionS *exp)
1461
278
{
1462
278
  valueT value;
1463
278
  unsigned int i;
1464
278
  bool sign = !exp->X_unsigned && exp->X_extrabit;
1465
1466
278
  value = exp->X_add_number;
1467
1.39k
  for (i = 0; i < sizeof (exp->X_add_number) / CHARS_PER_LITTLENUM; i++)
1468
1.11k
    {
1469
1.11k
      generic_bignum[i] = value & LITTLENUM_MASK;
1470
1.11k
      value >>= LITTLENUM_NUMBER_OF_BITS;
1471
1.11k
    }
1472
  /* Add a sequence of sign bits if the top bit of X_add_number is not
1473
     the sign of the original value.  */
1474
278
  if ((exp->X_add_number < 0) == !sign)
1475
260
    generic_bignum[i++] = sign ? LITTLENUM_MASK : 0;
1476
278
  exp->X_op = O_big;
1477
278
  exp->X_add_number = i;
1478
278
  exp->X_unsigned = !sign;
1479
1480
278
  return sign;
1481
278
}
1482
1483
/* For most MRI pseudo-ops, the line actually ends at the first
1484
   nonquoted space.  This function looks for that point, stuffs a null
1485
   in, and sets *STOPCP to the character that used to be there, and
1486
   returns the location.
1487
1488
   Until I hear otherwise, I am going to assume that this is only true
1489
   for the m68k MRI assembler.  */
1490
1491
char *
1492
mri_comment_field (char *stopcp)
1493
15.2k
{
1494
15.2k
  char *s;
1495
#ifdef TC_M68K
1496
  int inquote = 0;
1497
1498
  know (flag_m68k_mri);
1499
1500
  for (s = input_line_pointer;
1501
       ((!is_end_of_stmt (*s) && !is_whitespace (*s))
1502
  || inquote);
1503
       s++)
1504
    {
1505
      if (*s == '\'')
1506
  inquote = !inquote;
1507
    }
1508
#else
1509
15.2k
  for (s = input_line_pointer;
1510
492k
       !is_end_of_stmt (*s);
1511
476k
       s++)
1512
476k
    ;
1513
15.2k
#endif
1514
15.2k
  *stopcp = *s;
1515
15.2k
  *s = '\0';
1516
1517
15.2k
  return s;
1518
15.2k
}
1519
1520
/* Skip to the end of an MRI comment field.  */
1521
1522
void
1523
mri_comment_end (char *stop, int stopc)
1524
15.2k
{
1525
15.2k
  know (flag_mri);
1526
1527
15.2k
  input_line_pointer = stop;
1528
15.2k
  *stop = stopc;
1529
15.2k
  while (!is_end_of_stmt (*input_line_pointer))
1530
0
    ++input_line_pointer;
1531
15.2k
}
1532
1533
void
1534
s_abort (int ignore ATTRIBUTE_UNUSED)
1535
0
{
1536
0
  as_fatal (_(".abort detected.  Abandoning ship."));
1537
0
}
1538
1539
#ifndef TC_ALIGN_LIMIT
1540
1.81k
#define TC_ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1541
#endif
1542
1543
/* Handle the .align pseudo-op.  A positive ARG is a default alignment
1544
   (in bytes).  A negative ARG is the negative of the length of the
1545
   fill pattern.  BYTES_P is non-zero if the alignment value should be
1546
   interpreted as the byte boundary, rather than the power of 2.  */
1547
1548
static void
1549
s_align (signed int arg, int bytes_p)
1550
1.79k
{
1551
1.79k
  unsigned int align_limit = TC_ALIGN_LIMIT;
1552
1.79k
  addressT align;
1553
1.79k
  char *stop = NULL;
1554
1.79k
  char stopc = 0;
1555
1.79k
  offsetT fill = 0;
1556
1.79k
  unsigned int max;
1557
1.79k
  int fill_p;
1558
1559
1.79k
  if (flag_mri)
1560
867
    stop = mri_comment_field (&stopc);
1561
1562
1.79k
  if (is_end_of_stmt (*input_line_pointer))
1563
2
    {
1564
2
      if (arg < 0)
1565
0
  align = 0;
1566
2
      else
1567
2
  align = arg; /* Default value from pseudo-op table.  */
1568
2
    }
1569
1.79k
  else
1570
1.79k
    {
1571
1.79k
      align = get_absolute_expression ();
1572
1.79k
      SKIP_WHITESPACE ();
1573
1574
#ifdef TC_ALIGN_ZERO_IS_DEFAULT
1575
      if (arg > 0 && align == 0)
1576
  align = arg;
1577
#endif
1578
1.79k
    }
1579
1580
1.79k
  if (bytes_p)
1581
1.78k
    {
1582
      /* Convert to a power of 2.  */
1583
1.78k
      if (align != 0)
1584
1.52k
  {
1585
1.52k
    unsigned int i;
1586
1587
2.77k
    for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1588
1.24k
      ;
1589
1.52k
    if (align != 1)
1590
1.48k
      as_bad (_("alignment not a power of 2"));
1591
1592
1.52k
    align = i;
1593
1.52k
  }
1594
1.78k
    }
1595
1596
1.79k
  if (align > align_limit)
1597
4
    {
1598
4
      align = align_limit;
1599
4
      as_warn (_("alignment too large: %u assumed"),
1600
4
         bytes_p ? 1u << align_limit : align_limit);
1601
4
    }
1602
1603
1.79k
  if (*input_line_pointer != ',')
1604
268
    {
1605
268
      fill_p = 0;
1606
268
      max = 0;
1607
268
    }
1608
1.52k
  else
1609
1.52k
    {
1610
1.52k
      ++input_line_pointer;
1611
1.52k
      if (*input_line_pointer == ',')
1612
3
  fill_p = 0;
1613
1.52k
      else
1614
1.52k
  {
1615
1.52k
    fill = get_absolute_expression ();
1616
1.52k
    SKIP_WHITESPACE ();
1617
1.52k
    fill_p = 1;
1618
1.52k
  }
1619
1620
1.52k
      if (*input_line_pointer != ',')
1621
727
  max = 0;
1622
799
      else
1623
799
  {
1624
799
    ++input_line_pointer;
1625
799
    offsetT val = get_absolute_expression ();
1626
799
    max = val;
1627
799
    if (val < 0 || max != (valueT) val)
1628
134
      {
1629
134
        as_warn (_("ignoring out of range alignment maximum"));
1630
134
        max = 0;
1631
134
      }
1632
799
  }
1633
1.52k
    }
1634
1635
1.79k
  if (!fill_p)
1636
271
    {
1637
271
      if (arg < 0)
1638
2
  as_warn (_("expected fill pattern missing"));
1639
271
      do_align (align, NULL, 0, max);
1640
271
    }
1641
1.52k
  else
1642
1.52k
    {
1643
1.52k
      unsigned int fill_len;
1644
1645
1.52k
      if (arg >= 0)
1646
1.08k
  fill_len = 1;
1647
441
      else
1648
441
  fill_len = -arg;
1649
1650
1.52k
      if (fill_len <= 1)
1651
1.08k
  {
1652
1.08k
    char fill_char = 0;
1653
1654
1.08k
    fill_char = fill;
1655
1.08k
    do_align (align, &fill_char, fill_len, max);
1656
1.08k
  }
1657
441
      else
1658
441
  {
1659
441
    char ab[16];
1660
1661
441
    if ((size_t) fill_len > sizeof ab)
1662
0
      {
1663
0
        as_warn (_("fill pattern too long, truncating to %u"),
1664
0
           (unsigned) sizeof ab);
1665
0
        fill_len = sizeof ab;
1666
0
      }
1667
1668
441
    md_number_to_chars (ab, fill, fill_len);
1669
441
    do_align (align, ab, fill_len, max);
1670
441
  }
1671
1.52k
    }
1672
1673
1.79k
  demand_empty_rest_of_line ();
1674
1675
1.79k
  if (flag_mri)
1676
867
    mri_comment_end (stop, stopc);
1677
1.79k
}
1678
1679
/* Handle the .align pseudo-op on machines where ".align 4" means
1680
   align to a 4 byte boundary.  */
1681
1682
void
1683
s_align_bytes (int arg)
1684
1.78k
{
1685
1.78k
  s_align (arg, 1);
1686
1.78k
}
1687
1688
/* Handle the .align pseudo-op on machines where ".align 4" means align
1689
   to a 2**4 boundary.  */
1690
1691
void
1692
s_align_ptwo (int arg)
1693
5
{
1694
5
  s_align (arg, 0);
1695
5
}
1696
1697
/* Switch in and out of alternate macro mode.  */
1698
1699
static void
1700
s_altmacro (int on)
1701
0
{
1702
0
  demand_empty_rest_of_line ();
1703
0
  flag_macro_alternate = on;
1704
0
}
1705
1706
/* Read a symbol name from input_line_pointer.
1707
1708
   Stores the symbol name in a buffer and returns a pointer to this buffer.
1709
   The buffer is xalloc'ed.  It is the caller's responsibility to free
1710
   this buffer.
1711
1712
   The name is not left in the i_l_p buffer as it may need processing
1713
   to handle escape characters.
1714
1715
   Advances i_l_p to the next non-whitespace character.
1716
1717
   If a symbol name could not be read, the routine issues an error
1718
   messages, skips to the end of the line and returns NULL.  */
1719
1720
char *
1721
read_symbol_name (void)
1722
676
{
1723
676
  char * name;
1724
676
  char * start;
1725
676
  char c;
1726
1727
676
  c = *input_line_pointer++;
1728
1729
676
  if (c == '"')
1730
3
    {
1731
6
#define SYM_NAME_CHUNK_LEN 128
1732
3
      ptrdiff_t len = SYM_NAME_CHUNK_LEN;
1733
3
      char * name_end;
1734
3
      unsigned int C;
1735
1736
3
      start = name = XNEWVEC (char, len + 1);
1737
1738
3
      name_end = name + SYM_NAME_CHUNK_LEN;
1739
1740
90
      while (is_a_char (C = next_char_of_string ()))
1741
87
  {
1742
87
    if (name >= name_end)
1743
0
      {
1744
0
        ptrdiff_t sofar;
1745
1746
0
        sofar = name - start;
1747
0
        len += SYM_NAME_CHUNK_LEN;
1748
0
        start = XRESIZEVEC (char, start, len + 1);
1749
0
        name_end = start + len;
1750
0
        name = start + sofar;
1751
0
      }
1752
1753
87
    *name++ = (char) C;
1754
87
  }
1755
3
      *name = 0;
1756
1757
      /* Since quoted symbol names can contain non-ASCII characters,
1758
   check the string and warn if it cannot be recognised by the
1759
   current character set.  */
1760
      /* PR 29447: mbstowcs ignores the third (length) parameter when
1761
   the first (destination) parameter is NULL.  For clarity sake
1762
   therefore we pass 0 rather than 'len' as the third parameter.  */
1763
3
      if (mbstowcs (NULL, name, 0) == (size_t) -1)
1764
0
  as_warn (_("symbol name not recognised in the current locale"));
1765
3
    }
1766
673
  else if (is_name_beginner (c) || (input_from_string && c == FAKE_LABEL_CHAR))
1767
574
    {
1768
574
      ptrdiff_t len;
1769
1770
574
      name = input_line_pointer - 1;
1771
1772
      /* We accept FAKE_LABEL_CHAR in a name in case this is
1773
   being called with a constructed string.  */
1774
1.66k
      while (is_part_of_name (c = *input_line_pointer++)
1775
574
       || (input_from_string && c == FAKE_LABEL_CHAR))
1776
1.09k
  ;
1777
1778
574
      len = (input_line_pointer - name) - 1;
1779
574
      start = XNEWVEC (char, len + 1);
1780
1781
574
      memcpy (start, name, len);
1782
574
      start[len] = 0;
1783
1784
      /* Skip a name ender char if one is present.  */
1785
574
      if (! is_name_ender (c))
1786
574
  --input_line_pointer;
1787
574
    }
1788
99
  else
1789
99
    name = start = NULL;
1790
1791
676
  if (name == start)
1792
99
    {
1793
99
      as_bad (_("expected symbol name"));
1794
99
      ignore_rest_of_line ();
1795
99
      free (start);
1796
99
      return NULL;
1797
99
    }
1798
1799
577
  SKIP_WHITESPACE ();
1800
1801
577
  return start;
1802
676
}
1803
1804
1805
symbolS *
1806
s_comm_internal (int param,
1807
     symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
1808
295
{
1809
295
  char *name;
1810
295
  offsetT temp, size;
1811
295
  symbolS *symbolP = NULL;
1812
295
  char *stop = NULL;
1813
295
  char stopc = 0;
1814
295
  expressionS exp;
1815
1816
295
  if (flag_mri)
1817
243
    stop = mri_comment_field (&stopc);
1818
1819
295
  if ((name = read_symbol_name ()) == NULL)
1820
22
    goto out;
1821
1822
  /* Accept an optional comma after the name.  The comma used to be
1823
     required, but Irix 5 cc does not generate it for .lcomm.  */
1824
273
  if (*input_line_pointer == ',')
1825
148
    input_line_pointer++;
1826
1827
273
  temp = get_absolute_expr (&exp);
1828
273
  size = temp;
1829
273
  size &= ((addressT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
1830
273
  if (exp.X_op == O_absent)
1831
69
    {
1832
69
      as_bad (_("missing size expression"));
1833
69
      ignore_rest_of_line ();
1834
69
      goto out;
1835
69
    }
1836
204
  else if (temp != size || (!exp.X_unsigned && exp.X_add_number < 0))
1837
0
    {
1838
0
      as_warn (_("size (%ld) out of range, ignored"), (long) temp);
1839
0
      ignore_rest_of_line ();
1840
0
      goto out;
1841
0
    }
1842
1843
204
  symbolP = symbol_find_or_make (name);
1844
204
  if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
1845
175
      && !S_IS_COMMON (symbolP))
1846
139
    {
1847
139
      if (!S_IS_VOLATILE (symbolP))
1848
139
  {
1849
139
    symbolP = NULL;
1850
139
    as_bad (_("symbol `%s' is already defined"), name);
1851
139
    ignore_rest_of_line ();
1852
139
    goto out;
1853
139
  }
1854
0
      symbolP = symbol_clone (symbolP, 1);
1855
0
      S_SET_SEGMENT (symbolP, undefined_section);
1856
0
      S_SET_VALUE (symbolP, 0);
1857
0
      symbol_set_frag (symbolP, &zero_address_frag);
1858
0
      S_CLEAR_VOLATILE (symbolP);
1859
0
    }
1860
1861
65
  size = S_GET_VALUE (symbolP);
1862
65
  if (size == 0)
1863
60
    size = temp;
1864
5
  else if (size != temp)
1865
5
    as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1866
5
       name, (long) size, (long) temp);
1867
1868
65
  if (comm_parse_extra != NULL)
1869
65
    symbolP = (*comm_parse_extra) (param, symbolP, size);
1870
0
  else
1871
0
    {
1872
0
      S_SET_VALUE (symbolP, size);
1873
0
      S_SET_EXTERNAL (symbolP);
1874
0
      S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
1875
0
    }
1876
1877
65
  demand_empty_rest_of_line ();
1878
295
 out:
1879
295
  if (flag_mri)
1880
243
    mri_comment_end (stop, stopc);
1881
295
  free (name);
1882
295
  return symbolP;
1883
65
}
1884
1885
void
1886
s_comm (int ignore)
1887
0
{
1888
0
  s_comm_internal (ignore, NULL);
1889
0
}
1890
1891
/* The MRI COMMON pseudo-op.  We handle this by creating a common
1892
   symbol with the appropriate name.  We make s_space do the right
1893
   thing by increasing the size.  */
1894
1895
void
1896
s_mri_common (int small ATTRIBUTE_UNUSED)
1897
12
{
1898
12
  char *name;
1899
12
  char c;
1900
12
  char *alc = NULL;
1901
12
  symbolS *sym;
1902
12
  offsetT align;
1903
12
  char *stop = NULL;
1904
12
  char stopc = 0;
1905
1906
12
  if (!flag_mri)
1907
0
    {
1908
0
      s_comm (0);
1909
0
      return;
1910
0
    }
1911
1912
12
  stop = mri_comment_field (&stopc);
1913
1914
12
  SKIP_WHITESPACE ();
1915
1916
12
  name = input_line_pointer;
1917
12
  if (!ISDIGIT (*name))
1918
12
    c = get_symbol_name (& name);
1919
0
  else
1920
0
    {
1921
0
      do
1922
0
  {
1923
0
    ++input_line_pointer;
1924
0
  }
1925
0
      while (ISDIGIT (*input_line_pointer));
1926
1927
0
      c = *input_line_pointer;
1928
0
      *input_line_pointer = '\0';
1929
1930
0
      if (line_label != NULL)
1931
0
  {
1932
0
    alc = XNEWVEC (char, strlen (S_GET_NAME (line_label))
1933
0
       + (input_line_pointer - name) + 1);
1934
0
    sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1935
0
    name = alc;
1936
0
  }
1937
0
    }
1938
1939
12
  sym = symbol_find_or_make (name);
1940
12
  c = restore_line_pointer (c);
1941
12
  free (alc);
1942
1943
12
  if (*input_line_pointer != ',')
1944
11
    align = 0;
1945
1
  else
1946
1
    {
1947
1
      ++input_line_pointer;
1948
1
      align = get_absolute_expression ();
1949
1
    }
1950
1951
12
  if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1952
0
    {
1953
0
      as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
1954
0
      mri_comment_end (stop, stopc);
1955
0
      return;
1956
0
    }
1957
1958
12
  S_SET_EXTERNAL (sym);
1959
12
  S_SET_SEGMENT (sym, bfd_com_section_ptr);
1960
12
  mri_common_symbol = sym;
1961
1962
12
#ifdef S_SET_ALIGN
1963
12
  if (align != 0)
1964
0
    S_SET_ALIGN (sym, align);
1965
#else
1966
  (void) align;
1967
#endif
1968
1969
12
  if (line_label != NULL)
1970
0
    {
1971
0
      expressionS exp = { .X_op = O_symbol, .X_add_symbol = sym };
1972
0
      symbol_set_value_expression (line_label, &exp);
1973
0
      symbol_set_frag (line_label, &zero_address_frag);
1974
0
      S_SET_SEGMENT (line_label, expr_section);
1975
0
    }
1976
1977
  /* FIXME: We just ignore the small argument, which distinguishes
1978
     COMMON and COMMON.S.  I don't know what we can do about it.  */
1979
1980
  /* Ignore the type and hptype.  */
1981
12
  if (*input_line_pointer == ',')
1982
0
    input_line_pointer += 2;
1983
12
  if (*input_line_pointer == ',')
1984
0
    input_line_pointer += 2;
1985
1986
12
  demand_empty_rest_of_line ();
1987
1988
12
  mri_comment_end (stop, stopc);
1989
12
}
1990
1991
void
1992
s_data (int ignore ATTRIBUTE_UNUSED)
1993
1
{
1994
1
  segT section;
1995
1
  int temp;
1996
1997
1
  temp = get_absolute_expression ();
1998
1
  if (flag_readonly_data_in_text)
1999
0
    {
2000
0
      section = text_section;
2001
0
      temp += 1000;
2002
0
    }
2003
1
  else
2004
1
    section = data_section;
2005
2006
1
  subseg_set (section, temp);
2007
2008
1
  demand_empty_rest_of_line ();
2009
1
}
2010
2011
/* Handle the .file pseudo-op.  This default definition may be overridden by
2012
   the object or CPU specific pseudo-ops.  */
2013
2014
void
2015
s_file_string (char *file)
2016
150
{
2017
#ifdef LISTING
2018
  if (listing)
2019
    listing_source_file (file);
2020
#endif
2021
150
  register_dependency (file);
2022
150
#ifdef obj_app_file
2023
150
  obj_app_file (file);
2024
150
#endif
2025
150
}
2026
2027
void
2028
s_file (int ignore ATTRIBUTE_UNUSED)
2029
150
{
2030
150
  char *s;
2031
150
  int length;
2032
2033
  /* Some assemblers tolerate immediately following '"'.  */
2034
150
  if ((s = demand_copy_string (&length)) != 0)
2035
150
    {
2036
150
      new_logical_line_flags (s, -1, 1);
2037
2038
      /* In MRI mode, the preprocessor may have inserted an extraneous
2039
   backquote.  */
2040
150
      if (flag_m68k_mri
2041
0
    && *input_line_pointer == '\''
2042
0
    && is_end_of_stmt (input_line_pointer[1]))
2043
0
  ++input_line_pointer;
2044
2045
150
      demand_empty_rest_of_line ();
2046
150
      s_file_string (s);
2047
150
    }
2048
150
}
2049
2050
static bool
2051
get_linefile_number (int *flag)
2052
305k
{
2053
305k
  offsetT val;
2054
2055
305k
  SKIP_WHITESPACE ();
2056
2057
305k
  if (is_end_of_stmt (*input_line_pointer))
2058
52.5k
    return false;
2059
2060
  /* Don't mistakenly interpret octal numbers as line numbers.  */
2061
253k
  if (*input_line_pointer == '0')
2062
34.4k
    {
2063
34.4k
      *flag = 0;
2064
34.4k
      ++input_line_pointer;
2065
34.4k
      return true;
2066
34.4k
    }
2067
2068
218k
  val = get_single_number ();
2069
  /* Zero was handled above; getting back zero indicates an error.  */
2070
218k
  if (val == 0)
2071
99.6k
    return false;
2072
2073
118k
#if defined (BFD64) || LONG_MAX > INT_MAX
2074
118k
  if (val < INT_MIN || val > INT_MAX)
2075
142
    return false;
2076
118k
#endif
2077
2078
118k
  *flag = val;
2079
2080
118k
  return true;
2081
118k
}
2082
2083
/* Handle the .linefile pseudo-op.  This is automatically generated by
2084
   do_scrub_chars when a preprocessor # line comment is seen.  This
2085
   default definition may be overridden by the object or CPU specific
2086
   pseudo-ops.  */
2087
2088
void
2089
s_linefile (int ignore ATTRIBUTE_UNUSED)
2090
153k
{
2091
153k
  char *file = NULL;
2092
153k
  int linenum, flags = 0;
2093
2094
  /* The given number is that of the next line.  */
2095
153k
  if (!get_linefile_number (&linenum))
2096
139
    {
2097
139
      ignore_rest_of_line ();
2098
139
      return;
2099
139
    }
2100
2101
153k
  if (linenum < 0)
2102
    /* Some of the back ends can't deal with non-positive line numbers.
2103
       Besides, it's silly.  GCC however will generate a line number of
2104
       zero when it is pre-processing builtins for assembler-with-cpp files:
2105
2106
    # 0 "<built-in>"
2107
2108
       We do not want to barf on this, especially since such files are used
2109
       in the GCC and GDB testsuites.  So we check for negative line numbers
2110
       rather than non-positive line numbers.  */
2111
0
    as_warn (_("line numbers must be positive; line number %d rejected"),
2112
0
       linenum);
2113
153k
  else
2114
153k
    {
2115
153k
      int length = 0;
2116
2117
153k
      SKIP_WHITESPACE ();
2118
2119
153k
      if (*input_line_pointer == '"')
2120
152k
  file = demand_copy_string (&length);
2121
789
      else if (*input_line_pointer == '.')
2122
22
  {
2123
    /* buffer_and_nest() may insert this form.  */
2124
22
    ++input_line_pointer;
2125
22
    flags = 1 << 3;
2126
22
  }
2127
2128
153k
      if (file)
2129
152k
  {
2130
152k
    int this_flag;
2131
2132
152k
    while (get_linefile_number (&this_flag))
2133
152
      switch (this_flag)
2134
152
        {
2135
    /* From GCC's cpp documentation:
2136
       1: start of a new file.
2137
       2: returning to a file after having included another file.
2138
       3: following text comes from a system header file.
2139
       4: following text should be treated as extern "C".
2140
2141
       4 is nonsensical for the assembler; 3, we don't care about,
2142
       so we ignore it just in case a system header file is
2143
       included while preprocessing assembly.  So 1 and 2 are all
2144
       we care about, and they are mutually incompatible.
2145
       new_logical_line_flags() demands this.  */
2146
8
        case 1:
2147
8
        case 2:
2148
8
    if (flags && flags != (1 << this_flag))
2149
0
      as_warn (_("incompatible flag %i in line directive"),
2150
0
         this_flag);
2151
8
    else
2152
8
      flags |= 1 << this_flag;
2153
8
    break;
2154
2155
0
        case 3:
2156
0
        case 4:
2157
    /* We ignore these.  */
2158
0
    break;
2159
2160
144
        default:
2161
144
    as_warn (_("unsupported flag %i in line directive"),
2162
144
       this_flag);
2163
144
    break;
2164
152
        }
2165
2166
152k
    if (!is_end_of_stmt (*input_line_pointer))
2167
99.6k
      file = NULL;
2168
152k
        }
2169
2170
153k
      if (file || flags)
2171
52.5k
  {
2172
52.5k
    demand_empty_rest_of_line ();
2173
2174
    /* read_a_source_file() will bump the line number only if the line
2175
       is terminated by '\n'.  */
2176
52.5k
    if (input_line_pointer[-1] == '\n')
2177
45.8k
      linenum--;
2178
2179
52.5k
    new_logical_line_flags (file, linenum, flags);
2180
#ifdef LISTING
2181
    if (listing)
2182
      listing_source_line (linenum);
2183
#endif
2184
52.5k
    return;
2185
52.5k
  }
2186
153k
    }
2187
100k
  ignore_rest_of_line ();
2188
100k
}
2189
2190
/* Handle the .end pseudo-op.  Actually, the real work is done in
2191
   read_a_source_file.  */
2192
2193
void
2194
s_end (int ignore ATTRIBUTE_UNUSED)
2195
3
{
2196
3
  if (flag_mri)
2197
3
    {
2198
      /* The MRI assembler permits the start symbol to follow .end,
2199
   but we don't support that.  */
2200
3
      SKIP_WHITESPACE ();
2201
3
      if (!is_end_of_stmt (*input_line_pointer)
2202
1
    && *input_line_pointer != '*'
2203
1
    && *input_line_pointer != '!')
2204
1
  as_warn (_("start address not supported"));
2205
3
    }
2206
3
}
2207
2208
/* Handle the .err pseudo-op.  */
2209
2210
void
2211
s_err (int ignore ATTRIBUTE_UNUSED)
2212
0
{
2213
0
  as_bad (_(".err encountered"));
2214
0
  demand_empty_rest_of_line ();
2215
0
}
2216
2217
/* Handle the .error and .warning pseudo-ops.  */
2218
2219
void
2220
s_errwarn (int err)
2221
7
{
2222
7
  int len;
2223
  /* The purpose for the conditional assignment is not to
2224
     internationalize the directive itself, but that we need a
2225
     self-contained message, one that can be passed like the
2226
     demand_copy_C_string return value, and with no assumption on the
2227
     location of the name of the directive within the message.  */
2228
7
  const char *msg
2229
7
    = (err ? _(".error directive invoked in source file")
2230
7
       : _(".warning directive invoked in source file"));
2231
2232
7
  if (!is_it_end_of_statement ())
2233
1
    {
2234
1
      if (*input_line_pointer != '\"')
2235
1
  {
2236
1
    as_bad (_("%s argument must be a string"),
2237
1
      err ? ".error" : ".warning");
2238
1
    ignore_rest_of_line ();
2239
1
    return;
2240
1
  }
2241
2242
0
      msg = demand_copy_C_string (&len);
2243
0
      if (msg == NULL)
2244
0
  return;
2245
0
    }
2246
2247
6
  if (err)
2248
6
    as_bad ("%s", msg);
2249
0
  else
2250
0
    as_warn ("%s", msg);
2251
6
  demand_empty_rest_of_line ();
2252
6
}
2253
2254
/* Handle the .errif and .warnif pseudo-ops.  */
2255
2256
static struct deferred_diag {
2257
  struct deferred_diag *next;
2258
  const char *file;
2259
  unsigned int lineno;
2260
  bool err;
2261
  expressionS exp;
2262
} *deferred_diag_head, **deferred_diag_tail = &deferred_diag_head;
2263
2264
static void
2265
s_errwarn_if (int err)
2266
0
{
2267
0
  struct deferred_diag *diag = XNEW (struct deferred_diag);
2268
0
  int errcnt = had_errors ();
2269
2270
0
  deferred_expression (&diag->exp);
2271
0
  if (errcnt != had_errors ())
2272
0
    {
2273
0
      ignore_rest_of_line ();
2274
0
      free (diag);
2275
0
      return;
2276
0
    }
2277
2278
0
  diag->err = err;
2279
0
  diag->file = as_where (&diag->lineno);
2280
0
  diag->next = NULL;
2281
0
  *deferred_diag_tail = diag;
2282
0
  deferred_diag_tail = &diag->next;
2283
2284
0
  demand_empty_rest_of_line ();
2285
0
}
2286
2287
void
2288
evaluate_deferred_diags (void)
2289
0
{
2290
0
  struct deferred_diag *diag;
2291
2292
0
  while ((diag = deferred_diag_head) != NULL)
2293
0
    {
2294
0
      if (!resolve_expression (&diag->exp) || diag->exp.X_op != O_constant)
2295
0
  as_warn_where (diag->file, diag->lineno,
2296
0
           _("expression does not evaluate to a constant"));
2297
0
      else if (diag->exp.X_add_number == 0)
2298
0
  ;
2299
0
      else if (diag->err)
2300
0
  as_bad_where (diag->file, diag->lineno,
2301
0
          _(".errif expression evaluates to true"));
2302
0
      else
2303
0
  as_warn_where (diag->file, diag->lineno,
2304
0
           _(".warnif expression evaluates to true"));
2305
0
      deferred_diag_head = diag->next;
2306
0
      free (diag);
2307
0
    }
2308
0
  deferred_diag_tail = &deferred_diag_head;
2309
0
}
2310
2311
/* Handle the MRI fail pseudo-op.  */
2312
2313
void
2314
s_fail (int ignore ATTRIBUTE_UNUSED)
2315
12
{
2316
12
  offsetT temp;
2317
12
  char *stop = NULL;
2318
12
  char stopc = 0;
2319
2320
12
  if (flag_mri)
2321
10
    stop = mri_comment_field (&stopc);
2322
2323
12
  temp = get_absolute_expression ();
2324
12
  if (temp >= 500)
2325
7
    as_warn (_(".fail %ld encountered"), (long) temp);
2326
5
  else
2327
5
    as_bad (_(".fail %ld encountered"), (long) temp);
2328
2329
12
  demand_empty_rest_of_line ();
2330
2331
12
  if (flag_mri)
2332
10
    mri_comment_end (stop, stopc);
2333
12
}
2334
2335
void
2336
s_fill (int ignore ATTRIBUTE_UNUSED)
2337
2.91k
{
2338
2.91k
  expressionS rep_exp;
2339
2.91k
  offsetT size = 1;
2340
2.91k
  valueT fill = 0;
2341
2.91k
  char *p;
2342
2343
#ifdef md_flush_pending_output
2344
  md_flush_pending_output ();
2345
#endif
2346
2347
2.91k
#ifdef md_cons_align
2348
2.91k
  md_cons_align (1);
2349
2.91k
#endif
2350
2351
2.91k
  expression (&rep_exp);
2352
2.91k
  if (*input_line_pointer == ',')
2353
2.35k
    {
2354
2.35k
      input_line_pointer++;
2355
2.35k
      size = get_absolute_expression ();
2356
2.35k
      if (*input_line_pointer == ',')
2357
1.79k
  {
2358
1.79k
    input_line_pointer++;
2359
1.79k
    fill = get_absolute_expression ();
2360
1.79k
  }
2361
2.35k
    }
2362
2363
  /* This is to be compatible with BSD 4.2 AS, not for any rational reason.  */
2364
7.08k
#define BSD_FILL_SIZE_CROCK_8 (8)
2365
2.91k
  if (size > BSD_FILL_SIZE_CROCK_8)
2366
2.08k
    {
2367
2.08k
      as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
2368
2.08k
      size = BSD_FILL_SIZE_CROCK_8;
2369
2.08k
    }
2370
2.91k
  if (size < 0)
2371
3
    {
2372
3
      as_warn (_("size negative; .fill ignored"));
2373
3
      size = 0;
2374
3
    }
2375
2.90k
  else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
2376
245
    {
2377
245
      if (rep_exp.X_add_number < 0)
2378
33
  as_warn (_("repeat < 0; .fill ignored"));
2379
245
      size = 0;
2380
245
    }
2381
2.66k
  else if (size && !need_pass_2)
2382
2.40k
    {
2383
2.40k
      if (now_seg == absolute_section && rep_exp.X_op != O_constant)
2384
4
  {
2385
4
    as_bad (_("non-constant fill count for absolute section"));
2386
4
    size = 0;
2387
4
  }
2388
2.39k
      else if (now_seg == absolute_section && fill && rep_exp.X_add_number != 0)
2389
252
  {
2390
252
    as_bad (_("attempt to fill absolute section with non-zero value"));
2391
252
    size = 0;
2392
252
  }
2393
2.14k
      else if (fill
2394
510
         && (rep_exp.X_op != O_constant || rep_exp.X_add_number != 0)
2395
510
         && in_bss ())
2396
0
  {
2397
0
    as_bad (_("attempt to fill section `%s' with non-zero value"),
2398
0
      segment_name (now_seg));
2399
0
    size = 0;
2400
0
  }
2401
2.40k
    }
2402
2403
2.91k
  if (size && !need_pass_2)
2404
2.14k
    {
2405
2.14k
      if (now_seg == absolute_section)
2406
433
  abs_section_offset += (valueT) rep_exp.X_add_number * size;
2407
2408
2.14k
      if (rep_exp.X_op == O_constant)
2409
1.87k
  {
2410
1.87k
    p = frag_var (rs_fill, size, size, 0, NULL,
2411
1.87k
      rep_exp.X_add_number, NULL);
2412
1.87k
  }
2413
266
      else
2414
266
  {
2415
    /* We don't have a constant repeat count, so we can't use
2416
       rs_fill.  We can get the same results out of rs_space,
2417
       but its argument is in bytes, so we must multiply the
2418
       repeat count by size.  */
2419
2420
266
    symbolS *rep_sym;
2421
266
    rep_sym = make_expr_symbol (&rep_exp);
2422
266
    if (size != 1)
2423
258
      {
2424
258
        expressionS size_exp;
2425
258
        size_exp.X_op = O_constant;
2426
258
        size_exp.X_add_number = size;
2427
2428
258
        rep_exp.X_op = O_multiply;
2429
258
        rep_exp.X_add_symbol = rep_sym;
2430
258
        rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
2431
258
        rep_exp.X_add_number = 0;
2432
258
        rep_sym = make_expr_symbol (&rep_exp);
2433
258
      }
2434
2435
266
    p = frag_var (rs_space, size, size, 0, rep_sym, 0, NULL);
2436
266
  }
2437
2438
2.14k
      memset (p, 0, size);
2439
2440
      /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
2441
   flavoured AS.  The following bizarre behaviour is to be
2442
   compatible with above.  I guess they tried to take up to 8
2443
   bytes from a 4-byte expression and they forgot to sign
2444
   extend.  */
2445
3.96k
#define BSD_FILL_SIZE_CROCK_4 (4)
2446
2.14k
      md_number_to_chars (p, fill,
2447
2.14k
        (size > BSD_FILL_SIZE_CROCK_4
2448
2.14k
         ? BSD_FILL_SIZE_CROCK_4
2449
2.14k
         : size));
2450
      /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
2451
   but emits no error message because it seems a legal thing to do.
2452
   It is a degenerate case of .fill but could be emitted by a
2453
   compiler.  */
2454
2.14k
    }
2455
2.91k
  demand_empty_rest_of_line ();
2456
2.91k
}
2457
2458
void
2459
s_globl (int ignore ATTRIBUTE_UNUSED)
2460
40
{
2461
40
  char *name;
2462
40
  int c;
2463
40
  symbolS *symbolP;
2464
40
  char *stop = NULL;
2465
40
  char stopc = 0;
2466
2467
40
  if (flag_mri)
2468
29
    stop = mri_comment_field (&stopc);
2469
2470
40
  do
2471
65
    {
2472
65
      if ((name = read_symbol_name ()) == NULL)
2473
18
  return;
2474
2475
47
      symbolP = symbol_find_or_make (name);
2476
47
      S_SET_EXTERNAL (symbolP);
2477
2478
47
      SKIP_WHITESPACE ();
2479
47
      c = *input_line_pointer;
2480
47
      if (c == ',')
2481
25
  {
2482
25
    input_line_pointer++;
2483
25
    SKIP_WHITESPACE ();
2484
25
    if (is_end_of_stmt (*input_line_pointer))
2485
0
      c = '\n';
2486
25
  }
2487
2488
47
      free (name);
2489
47
    }
2490
47
  while (c == ',');
2491
2492
22
  demand_empty_rest_of_line ();
2493
2494
22
  if (flag_mri)
2495
11
    mri_comment_end (stop, stopc);
2496
22
}
2497
2498
/* Handle the MRI IRP and IRPC pseudo-ops.  */
2499
2500
void
2501
s_irp (int irpc)
2502
321
{
2503
321
  char * eol;
2504
321
  const char * file;
2505
321
  unsigned int line;
2506
321
  sb s;
2507
321
  const char *err;
2508
321
  sb out;
2509
2510
321
  file = as_where (&line);
2511
2512
321
  eol = find_end_of_line (input_line_pointer, 0);
2513
321
  sb_build (&s, eol - input_line_pointer);
2514
321
  sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2515
321
  input_line_pointer = eol;
2516
2517
321
  sb_new (&out);
2518
2519
321
  err = expand_irp (irpc, 0, &s, &out, get_macro_line_sb);
2520
321
  if (err != NULL)
2521
201
    as_bad_where (file, line, "%s", err);
2522
2523
321
  sb_kill (&s);
2524
2525
321
  input_scrub_include_sb (&out, input_line_pointer, expanding_repeat);
2526
321
  sb_kill (&out);
2527
321
  buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2528
321
}
2529
2530
/* Handle the .linkonce pseudo-op.  This tells the assembler to mark
2531
   the section to only be linked once.  However, this is not supported
2532
   by most object file formats.  This takes an optional argument,
2533
   which is what to do about duplicates.  */
2534
2535
void
2536
s_linkonce (int ignore ATTRIBUTE_UNUSED)
2537
20
{
2538
20
  enum linkonce_type type;
2539
2540
20
  SKIP_WHITESPACE ();
2541
2542
20
  type = LINKONCE_DISCARD;
2543
2544
20
  if (!is_end_of_stmt (*input_line_pointer))
2545
4
    {
2546
4
      char *s;
2547
4
      char c;
2548
2549
4
      c = get_symbol_name (& s);
2550
4
      if (strcasecmp (s, "discard") == 0)
2551
0
  type = LINKONCE_DISCARD;
2552
4
      else if (strcasecmp (s, "one_only") == 0)
2553
0
  type = LINKONCE_ONE_ONLY;
2554
4
      else if (strcasecmp (s, "same_size") == 0)
2555
0
  type = LINKONCE_SAME_SIZE;
2556
4
      else if (strcasecmp (s, "same_contents") == 0)
2557
0
  type = LINKONCE_SAME_CONTENTS;
2558
4
      else
2559
4
  as_warn (_("unrecognized .linkonce type `%s'"), s);
2560
2561
4
      (void) restore_line_pointer (c);
2562
4
    }
2563
2564
#ifdef obj_handle_link_once
2565
  obj_handle_link_once (type);
2566
#else /* ! defined (obj_handle_link_once) */
2567
20
  {
2568
20
    flagword flags;
2569
2570
20
    if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
2571
20
      as_warn (_(".linkonce is not supported for this object file format"));
2572
2573
20
    flags = bfd_section_flags (now_seg);
2574
20
    flags |= SEC_LINK_ONCE;
2575
20
    switch (type)
2576
20
      {
2577
0
      default:
2578
0
  abort ();
2579
20
      case LINKONCE_DISCARD:
2580
20
  flags |= SEC_LINK_DUPLICATES_DISCARD;
2581
20
  break;
2582
0
      case LINKONCE_ONE_ONLY:
2583
0
  flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
2584
0
  break;
2585
0
      case LINKONCE_SAME_SIZE:
2586
0
  flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
2587
0
  break;
2588
0
      case LINKONCE_SAME_CONTENTS:
2589
0
  flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
2590
0
  break;
2591
20
      }
2592
20
    if (!bfd_set_section_flags (now_seg, flags))
2593
0
      as_bad (_("bfd_set_section_flags: %s"),
2594
0
        bfd_errmsg (bfd_get_error ()));
2595
20
  }
2596
0
#endif /* ! defined (obj_handle_link_once) */
2597
2598
0
  demand_empty_rest_of_line ();
2599
20
}
2600
2601
void
2602
bss_alloc (symbolS *symbolP, addressT size, unsigned int align)
2603
4
{
2604
4
  char *pfrag;
2605
4
  segT current_seg = now_seg;
2606
4
  subsegT current_subseg = now_subseg;
2607
4
  segT bss_seg = bss_section;
2608
2609
#if defined (TC_MIPS) || defined (TC_ALPHA)
2610
  if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
2611
      || OUTPUT_FLAVOR == bfd_target_elf_flavour)
2612
    {
2613
      /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss.  */
2614
      if (size <= bfd_get_gp_size (stdoutput))
2615
  {
2616
    bss_seg = subseg_new (".sbss", 1);
2617
    seg_info (bss_seg)->bss = 1;
2618
    if (!bfd_set_section_flags (bss_seg, SEC_ALLOC | SEC_SMALL_DATA))
2619
      as_warn (_("error setting flags for \".sbss\": %s"),
2620
         bfd_errmsg (bfd_get_error ()));
2621
  }
2622
    }
2623
#endif
2624
4
  subseg_set (bss_seg, 1);
2625
2626
4
  if (align > OCTETS_PER_BYTE_POWER)
2627
1
    {
2628
1
      record_alignment (bss_seg, align);
2629
1
      frag_align (align, 0, 0);
2630
1
    }
2631
2632
  /* Detach from old frag.  */
2633
4
  if (S_GET_SEGMENT (symbolP) == bss_seg)
2634
0
    symbol_get_frag (symbolP)->fr_symbol = NULL;
2635
2636
4
  symbol_set_frag (symbolP, frag_now);
2637
4
  pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size * OCTETS_PER_BYTE, NULL);
2638
4
  *pfrag = 0;
2639
2640
4
#ifdef S_SET_SIZE
2641
4
  S_SET_SIZE (symbolP, size);
2642
4
#endif
2643
4
  S_SET_SEGMENT (symbolP, bss_seg);
2644
2645
#ifdef OBJ_COFF
2646
  /* The symbol may already have been created with a preceding
2647
     ".globl" directive -- be careful not to step on storage class
2648
     in that case.  Otherwise, set it to static.  */
2649
  if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2650
    S_SET_STORAGE_CLASS (symbolP, C_STAT);
2651
#endif /* OBJ_COFF */
2652
2653
4
  subseg_set (current_seg, current_subseg);
2654
4
}
2655
2656
offsetT
2657
parse_align (int align_bytes)
2658
6
{
2659
6
  expressionS exp;
2660
6
  addressT align;
2661
2662
6
  SKIP_WHITESPACE ();
2663
6
  if (*input_line_pointer != ',')
2664
0
    {
2665
1
    no_align:
2666
1
      as_bad (_("expected alignment after size"));
2667
1
      ignore_rest_of_line ();
2668
1
      return -1;
2669
0
    }
2670
2671
6
  input_line_pointer++;
2672
6
  SKIP_WHITESPACE ();
2673
2674
6
  align = get_absolute_expr (&exp);
2675
6
  if (exp.X_op == O_absent)
2676
1
    goto no_align;
2677
2678
5
  if (!exp.X_unsigned && exp.X_add_number < 0)
2679
0
    {
2680
0
      as_warn (_("alignment negative; 0 assumed"));
2681
0
      align = 0;
2682
0
    }
2683
2684
5
  if (align_bytes && align != 0)
2685
0
    {
2686
      /* convert to a power of 2 alignment */
2687
0
      unsigned int alignp2 = 0;
2688
0
      while ((align & 1) == 0)
2689
0
  align >>= 1, ++alignp2;
2690
0
      if (align != 1)
2691
0
  {
2692
0
    as_bad (_("alignment not a power of 2"));
2693
0
    ignore_rest_of_line ();
2694
0
    return -1;
2695
0
  }
2696
0
      align = alignp2;
2697
0
    }
2698
5
  return align;
2699
5
}
2700
2701
/* Called from s_comm_internal after symbol name and size have been
2702
   parsed.  NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2703
   1 if this was a ".bss" directive which has a 3rd argument
2704
   (alignment as a power of 2), or 2 if this was a ".bss" directive
2705
   with alignment in bytes.  */
2706
2707
symbolS *
2708
s_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
2709
4
{
2710
4
  addressT align = 0;
2711
2712
4
  if (needs_align)
2713
0
    {
2714
0
      align = parse_align (needs_align - 1);
2715
0
      if (align == (addressT) -1)
2716
0
  return NULL;
2717
0
    }
2718
4
  else
2719
    /* Assume some objects may require alignment on some systems.  */
2720
4
    TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
2721
2722
4
  bss_alloc (symbolP, size, align);
2723
4
  return symbolP;
2724
4
}
2725
2726
void
2727
s_lcomm (int needs_align)
2728
0
{
2729
0
  s_comm_internal (needs_align, s_lcomm_internal);
2730
0
}
2731
2732
void
2733
s_lcomm_bytes (int needs_align)
2734
0
{
2735
0
  s_comm_internal (needs_align * 2, s_lcomm_internal);
2736
0
}
2737
2738
void
2739
s_lsym (int ignore ATTRIBUTE_UNUSED)
2740
165
{
2741
165
  char *name;
2742
165
  expressionS exp;
2743
165
  symbolS *symbolP;
2744
2745
  /* We permit ANY defined expression: BSD4.2 demands constants.  */
2746
165
  if ((name = read_symbol_name ()) == NULL)
2747
28
    return;
2748
2749
137
  if (*input_line_pointer != ',')
2750
22
    {
2751
22
      as_bad (_("expected comma after \"%s\""), name);
2752
22
      goto err_out;
2753
22
    }
2754
2755
115
  input_line_pointer++;
2756
115
  expression_and_evaluate (&exp);
2757
2758
115
  if (exp.X_op != O_constant
2759
44
      && exp.X_op != O_register)
2760
44
    {
2761
44
      as_bad (_("bad expression"));
2762
44
      goto err_out;
2763
44
    }
2764
2765
71
  symbolP = symbol_find_or_make (name);
2766
2767
71
  if (S_GET_SEGMENT (symbolP) == undefined_section)
2768
8
    {
2769
      /* The name might be an undefined .global symbol; be sure to
2770
   keep the "external" bit.  */
2771
8
      S_SET_SEGMENT (symbolP,
2772
8
         (exp.X_op == O_constant
2773
8
          ? absolute_section
2774
8
          : reg_section));
2775
8
      S_SET_VALUE (symbolP, exp.X_add_number);
2776
8
    }
2777
63
  else
2778
63
    {
2779
63
      as_bad (_("symbol `%s' is already defined"), name);
2780
63
    }
2781
2782
71
  demand_empty_rest_of_line ();
2783
71
  free (name);
2784
71
  return;
2785
2786
66
 err_out:
2787
66
  ignore_rest_of_line ();
2788
66
  free (name);
2789
66
  return;
2790
115
}
2791
2792
/* Read a line into an sb.  Returns the character that ended the line
2793
   or zero if there are no more lines.  */
2794
2795
static int
2796
get_line_sb (sb *line, int in_macro)
2797
792k
{
2798
792k
  char *eol;
2799
2800
792k
  if (input_line_pointer[-1] == '\n')
2801
787k
    bump_line_counters ();
2802
2803
792k
  if (input_line_pointer >= buffer_limit)
2804
152
    {
2805
152
      buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2806
152
      if (buffer_limit == 0)
2807
7
  return 0;
2808
152
    }
2809
2810
792k
  eol = _find_end_of_line (input_line_pointer, flag_m68k_mri, 0, in_macro);
2811
792k
  sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
2812
792k
  input_line_pointer = eol;
2813
2814
  /* Don't skip multiple end-of-line characters, because that breaks support
2815
     for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2816
     characters but isn't.  Instead just skip one end of line character and
2817
     return the character skipped so that the caller can re-insert it if
2818
     necessary.   */
2819
792k
  return *input_line_pointer++;
2820
792k
}
2821
2822
static size_t
2823
get_non_macro_line_sb (sb *line)
2824
6.99k
{
2825
6.99k
  return get_line_sb (line, 0);
2826
6.99k
}
2827
2828
static size_t
2829
get_macro_line_sb (sb *line)
2830
785k
{
2831
785k
  return get_line_sb (line, 1);
2832
785k
}
2833
2834
/* Define a macro.  This is an interface to macro.c.  */
2835
2836
void
2837
s_macro (int ignore ATTRIBUTE_UNUSED)
2838
705
{
2839
705
  char *eol;
2840
705
  sb s;
2841
705
  macro_entry *macro;
2842
2843
705
  eol = find_end_of_line (input_line_pointer, 0);
2844
705
  sb_build (&s, eol - input_line_pointer);
2845
705
  sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2846
705
  input_line_pointer = eol;
2847
2848
705
  if (line_label != NULL)
2849
683
    {
2850
683
      sb label;
2851
683
      size_t len;
2852
683
      const char *name;
2853
2854
683
      name = S_GET_NAME (line_label);
2855
683
      len = strlen (name);
2856
683
      sb_build (&label, len);
2857
683
      sb_add_buffer (&label, name, len);
2858
683
      macro = define_macro (&s, &label, get_macro_line_sb);
2859
683
      sb_kill (&label);
2860
683
    }
2861
22
  else
2862
22
    macro = define_macro (&s, NULL, get_macro_line_sb);
2863
705
  if (macro != NULL)
2864
354
    {
2865
354
      if (line_label != NULL)
2866
341
  {
2867
341
    S_SET_SEGMENT (line_label, absolute_section);
2868
341
    S_SET_VALUE (line_label, 0);
2869
341
    symbol_set_frag (line_label, &zero_address_frag);
2870
341
  }
2871
2872
354
      if (((NO_PSEUDO_DOT || flag_m68k_mri)
2873
0
     && str_hash_find (po_hash, macro->name) != NULL)
2874
354
    || (!flag_m68k_mri
2875
354
        && macro->name[0] == '.'
2876
342
        && str_hash_find (po_hash, macro->name + 1) != NULL))
2877
338
  {
2878
338
    as_warn_where (macro->file, macro->line,
2879
338
       _("attempt to redefine pseudo-op `%s' ignored"),
2880
338
       macro->name);
2881
338
    str_hash_delete (macro_hash, macro->name);
2882
338
  }
2883
354
    }
2884
2885
705
  sb_kill (&s);
2886
705
}
2887
2888
/* Handle the .mexit pseudo-op, which immediately exits a macro
2889
   expansion.  */
2890
2891
void
2892
s_mexit (int ignore ATTRIBUTE_UNUSED)
2893
17
{
2894
17
  if (macro_nest)
2895
0
    {
2896
0
      cond_exit_macro (macro_nest);
2897
0
      buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2898
0
    }
2899
17
  else
2900
17
    as_warn (_("ignoring macro exit outside a macro definition."));
2901
17
}
2902
2903
/* Switch in and out of MRI mode.  */
2904
2905
void
2906
s_mri (int ignore ATTRIBUTE_UNUSED)
2907
56
{
2908
56
  int on;
2909
#ifdef MRI_MODE_CHANGE
2910
  int old_flag;
2911
#endif
2912
2913
56
  on = get_absolute_expression ();
2914
#ifdef MRI_MODE_CHANGE
2915
  old_flag = flag_mri;
2916
#endif
2917
56
  if (on != 0)
2918
39
    {
2919
39
      flag_mri = 1;
2920
#ifdef TC_M68K
2921
      flag_m68k_mri = 1;
2922
#endif
2923
39
      lex_type['?'] = LEX_BEGIN_NAME | LEX_NAME;
2924
39
    }
2925
17
  else
2926
17
    {
2927
17
      flag_mri = 0;
2928
#ifdef TC_M68K
2929
      flag_m68k_mri = 0;
2930
#endif
2931
17
      lex_type['?'] = LEX_QM;
2932
17
    }
2933
2934
  /* Operator precedence changes in m68k MRI mode, so we need to
2935
     update the operator rankings.  */
2936
56
  expr_set_precedence ();
2937
2938
#ifdef MRI_MODE_CHANGE
2939
  if (on != old_flag)
2940
    MRI_MODE_CHANGE (on);
2941
#endif
2942
2943
56
  demand_empty_rest_of_line ();
2944
56
}
2945
2946
/* Handle changing the location counter.  */
2947
2948
static void
2949
do_org (segT segment, expressionS *exp, int fill)
2950
1.23k
{
2951
1.23k
  if (segment != now_seg
2952
1.09k
      && segment != absolute_section
2953
0
      && segment != expr_section)
2954
0
    as_bad (_("invalid segment \"%s\""), segment_name (segment));
2955
2956
1.23k
  if (now_seg == absolute_section)
2957
131
    {
2958
131
      if (fill != 0)
2959
0
  as_warn (_("ignoring fill value in absolute section"));
2960
131
      if (exp->X_op != O_constant)
2961
2
  {
2962
2
    as_bad (_("only constant offsets supported in absolute section"));
2963
2
    exp->X_add_number = 0;
2964
2
  }
2965
131
      abs_section_offset = exp->X_add_number;
2966
131
    }
2967
1.10k
  else
2968
1.10k
    {
2969
1.10k
      char *p;
2970
1.10k
      symbolS *sym = exp->X_add_symbol;
2971
1.10k
      offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
2972
2973
1.10k
      if (fill && in_bss ())
2974
0
  as_warn (_("ignoring fill value in section `%s'"),
2975
0
     segment_name (now_seg));
2976
2977
1.10k
      if (exp->X_op != O_constant && exp->X_op != O_symbol)
2978
146
  {
2979
    /* Handle complex expressions.  */
2980
146
    sym = make_expr_symbol (exp);
2981
146
    off = 0;
2982
146
  }
2983
2984
1.10k
      p = frag_var (rs_org, 1, 1, 0, sym, off, NULL);
2985
1.10k
      *p = fill;
2986
1.10k
    }
2987
1.23k
}
2988
2989
void
2990
s_org (int ignore ATTRIBUTE_UNUSED)
2991
767
{
2992
767
  segT segment;
2993
767
  expressionS exp;
2994
767
  long temp_fill;
2995
2996
#ifdef md_flush_pending_output
2997
  md_flush_pending_output ();
2998
#endif
2999
3000
  /* The m68k MRI assembler has a different meaning for .org.  It
3001
     means to create an absolute section at a given address.  We can't
3002
     support that--use a linker script instead.  */
3003
767
  if (flag_m68k_mri)
3004
0
    {
3005
0
      as_bad (_("MRI style ORG pseudo-op not supported"));
3006
0
      ignore_rest_of_line ();
3007
0
      return;
3008
0
    }
3009
3010
  /* Don't believe the documentation of BSD 4.2 AS.  There is no such
3011
     thing as a sub-segment-relative origin.  Any absolute origin is
3012
     given a warning, then assumed to be segment-relative.  Any
3013
     segmented origin expression ("foo+42") had better be in the right
3014
     segment or the .org is ignored.
3015
3016
     BSD 4.2 AS warns if you try to .org backwards. We cannot because
3017
     we never know sub-segment sizes when we are reading code.  BSD
3018
     will crash trying to emit negative numbers of filler bytes in
3019
     certain .orgs. We don't crash, but see as-write for that code.
3020
3021
     Don't make frag if need_pass_2==1.  */
3022
767
  segment = get_known_segmented_expression (&exp);
3023
767
  if (*input_line_pointer == ',')
3024
494
    {
3025
494
      input_line_pointer++;
3026
494
      temp_fill = get_absolute_expression ();
3027
494
    }
3028
273
  else
3029
273
    temp_fill = 0;
3030
3031
767
  if (!need_pass_2)
3032
767
    do_org (segment, &exp, temp_fill);
3033
3034
767
  demand_empty_rest_of_line ();
3035
767
}
3036
3037
/* Handle parsing for the MRI SECT/SECTION pseudo-op.  This should be
3038
   called by the obj-format routine which handles section changing
3039
   when in MRI mode.  It will create a new section, and return it.  It
3040
   will set *TYPE to the section type: one of 'C' (code), 'D' (data),
3041
   'M' (mixed), or 'R' (romable).  The flags will be set in the section.  */
3042
3043
void
3044
s_mri_sect (char *type ATTRIBUTE_UNUSED)
3045
3.95k
{
3046
#ifdef TC_M68K
3047
3048
  char *name;
3049
  char c;
3050
  segT seg;
3051
3052
  SKIP_WHITESPACE ();
3053
3054
  name = input_line_pointer;
3055
  if (!ISDIGIT (*name))
3056
    c = get_symbol_name (& name);
3057
  else
3058
    {
3059
      do
3060
  {
3061
    ++input_line_pointer;
3062
  }
3063
      while (ISDIGIT (*input_line_pointer));
3064
3065
      c = *input_line_pointer;
3066
      *input_line_pointer = '\0';
3067
    }
3068
3069
  name = xstrdup (name);
3070
3071
  c = restore_line_pointer (c);
3072
3073
  seg = subseg_new (name, 0);
3074
3075
  if (c == ',')
3076
    {
3077
      unsigned int align;
3078
3079
      ++input_line_pointer;
3080
      align = get_absolute_expression ();
3081
      record_alignment (seg, align);
3082
    }
3083
3084
  *type = 'C';
3085
  if (*input_line_pointer == ',')
3086
    {
3087
      c = *++input_line_pointer;
3088
      c = TOUPPER (c);
3089
      if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
3090
  *type = c;
3091
      else
3092
  as_bad (_("unrecognized section type"));
3093
      ++input_line_pointer;
3094
3095
      {
3096
  flagword flags;
3097
3098
  flags = SEC_NO_FLAGS;
3099
  if (*type == 'C')
3100
    flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
3101
  else if (*type == 'D' || *type == 'M')
3102
    flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
3103
  else if (*type == 'R')
3104
    flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
3105
  if (flags != SEC_NO_FLAGS)
3106
    {
3107
      if (!bfd_set_section_flags (seg, flags))
3108
        as_warn (_("error setting flags for \"%s\": %s"),
3109
           bfd_section_name (seg),
3110
           bfd_errmsg (bfd_get_error ()));
3111
    }
3112
      }
3113
    }
3114
3115
  /* Ignore the HP type.  */
3116
  if (*input_line_pointer == ',')
3117
    input_line_pointer += 2;
3118
3119
  demand_empty_rest_of_line ();
3120
3121
#else /* ! TC_M68K */
3122
  /* The MRI assembler seems to use different forms of .sect for
3123
     different targets.  */
3124
3.95k
  as_bad ("MRI mode not supported for this target");
3125
3.95k
  ignore_rest_of_line ();
3126
3.95k
#endif /* ! TC_M68K */
3127
3.95k
}
3128
3129
/* Handle the .print pseudo-op.  */
3130
3131
void
3132
s_print (int ignore ATTRIBUTE_UNUSED)
3133
9
{
3134
9
  char *s;
3135
9
  int len;
3136
3137
9
  s = demand_copy_C_string (&len);
3138
9
  if (s != NULL)
3139
9
    printf ("%s\n", s);
3140
9
  demand_empty_rest_of_line ();
3141
9
}
3142
3143
/* Handle the .purgem pseudo-op.  */
3144
3145
void
3146
s_purgem (int ignore ATTRIBUTE_UNUSED)
3147
4
{
3148
4
  if (is_it_end_of_statement ())
3149
0
    {
3150
0
      demand_empty_rest_of_line ();
3151
0
      return;
3152
0
    }
3153
3154
4
  do
3155
4
    {
3156
4
      char *name;
3157
4
      char c;
3158
3159
4
      SKIP_WHITESPACE ();
3160
4
      c = get_symbol_name (& name);
3161
4
      delete_macro (name);
3162
4
      restore_line_pointer (c);
3163
4
      SKIP_WHITESPACE ();
3164
4
    }
3165
4
  while (*input_line_pointer++ == ',');
3166
3167
4
  --input_line_pointer;
3168
4
  demand_empty_rest_of_line ();
3169
4
}
3170
3171
/* Handle the .endm/.endr pseudo-ops.  */
3172
3173
static void
3174
s_bad_end (int endr)
3175
355
{
3176
355
  as_warn (_(".end%c encountered without preceding %s"),
3177
355
     endr ? 'r' : 'm',
3178
355
     endr ? ".rept, .irp, or .irpc" : ".macro");
3179
355
  demand_empty_rest_of_line ();
3180
355
}
3181
3182
/* Handle the .rept pseudo-op.  */
3183
3184
void
3185
s_rept (int expand_count)
3186
1.01k
{
3187
1.01k
  size_t count;
3188
3189
1.01k
  count = get_absolute_expression ();
3190
3191
1.01k
  do_repeat (count, "REPT", "ENDR", expand_count ? "" : NULL);
3192
1.01k
}
3193
3194
/* This function provides a generic repeat block implementation.   It allows
3195
   different directives to be used as the start/end keys.  Any text matching
3196
   the optional EXPANDER in the block is replaced by the remaining iteration
3197
   count.  Except when EXPANDER is the empty string, in which case \+ will
3198
   be looked for (as also recognized in macros as well as .irp and .irpc),
3199
   where the replacement will be the number of iterations done so far.  */
3200
3201
void
3202
do_repeat (size_t count, const char *start, const char *end,
3203
     const char *expander)
3204
1.01k
{
3205
1.01k
  sb one;
3206
1.01k
  sb many;
3207
1.01k
  size_t total, limit;
3208
1.01k
  unsigned int line;
3209
1.01k
  const char *file = as_where_top (&line);
3210
3211
1.01k
  demand_empty_rest_of_line ();
3212
1.01k
  --input_line_pointer;
3213
3214
1.01k
  sb_new (&one);
3215
1.01k
  if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
3216
89
    {
3217
89
      as_bad (_("%s without %s"), start, end);
3218
89
      sb_kill (&one);
3219
89
      return;
3220
89
    }
3221
3222
922
  sb_terminate (&one);
3223
3224
922
  limit = (size_t) LONG_MAX < 0xffffffff ? (size_t) LONG_MAX : 0xffffffff;
3225
922
  if (gas_mul_overflow (count, one.len, &total) || total > limit)
3226
0
    {
3227
0
      as_bad_where (file, line,
3228
0
        _("excessive count %zu for %s - ignored"), count, start);
3229
0
      count = 1;
3230
0
    }
3231
3232
922
  if (expander != NULL && !*expander && strstr (one.ptr, "\\+") != NULL)
3233
4
    {
3234
      /* The 3 here and below are arbitrary, added in an attempt to limit
3235
   re-allocation needs in sb_add_...() for moderate repeat counts.  */
3236
4
      sb_build (&many, count * (one.len + 3));
3237
3238
4
      for (size_t done = 0; count-- > 0; ++done)
3239
0
  {
3240
0
    const char *ptr, *bs;
3241
0
    sb processed;
3242
3243
0
    sb_build (&processed, one.len + 3);
3244
3245
0
    for (ptr = one.ptr; (bs = strchr (ptr, '\\')) != NULL; )
3246
0
      {
3247
0
        sb_add_buffer (&processed, ptr, bs - ptr);
3248
0
        switch (bs[1])
3249
0
    {
3250
0
      char scratch[24];
3251
3252
0
    default:
3253
0
      sb_add_char (&processed, '\\');
3254
0
      sb_add_char (&processed, bs[1]);
3255
0
      ptr = bs + 2;
3256
0
      break;
3257
3258
0
    case '\0':
3259
0
      as_warn (_("`\\' at end of line/statement; ignored"));
3260
0
      ptr = bs + 1;
3261
0
      break;
3262
3263
0
    case '\\':
3264
0
      sb_add_char (&processed, '\\');
3265
0
      ptr = bs + 2;
3266
0
      break;
3267
3268
0
    case '+':
3269
0
      snprintf (scratch, ARRAY_SIZE (scratch), "%zu", done);
3270
0
      sb_add_string (&processed, scratch);
3271
0
      ptr = bs + 2;
3272
0
      break;
3273
0
    }
3274
0
      }
3275
3276
0
    sb_add_string (&processed, ptr);
3277
3278
0
    sb_add_sb (&many, &processed);
3279
0
    sb_kill (&processed);
3280
0
  }
3281
4
    }
3282
918
  else if (expander == NULL || !*expander || strstr (one.ptr, expander) == NULL)
3283
918
    {
3284
918
      sb_build (&many, count * one.len);
3285
113k
      while (count-- > 0)
3286
112k
  sb_add_sb (&many, &one);
3287
918
    }
3288
0
  else
3289
0
    {
3290
0
      sb_new (&many);
3291
3292
0
      while (count -- > 0)
3293
0
  {
3294
0
    int len;
3295
0
    char * sub;
3296
0
    sb processed;
3297
3298
0
    sb_build (& processed, one.len);
3299
0
    sb_add_sb (& processed, & one);
3300
0
    sub = strstr (processed.ptr, expander);
3301
0
    len = sprintf (sub, "%lu", (unsigned long) count);
3302
0
    gas_assert (len < 8);
3303
0
    memmove (sub + len, sub + 8,
3304
0
       processed.ptr + processed.len - (sub + 8));
3305
0
    processed.len -= (8 - len);
3306
0
    sb_add_sb (& many, & processed);
3307
0
    sb_kill (& processed);
3308
0
  }
3309
0
    }
3310
3311
922
  sb_kill (&one);
3312
3313
922
  input_scrub_include_sb (&many, input_line_pointer, expanding_repeat);
3314
922
  sb_kill (&many);
3315
922
  buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3316
922
}
3317
3318
/* Skip to end of current repeat loop; EXTRA indicates how many additional
3319
   input buffers to skip.  Assumes that conditionals preceding the loop end
3320
   are properly nested.
3321
3322
   This function makes it easier to implement a premature "break" out of the
3323
   loop.  The EXTRA arg accounts for other buffers we might have inserted,
3324
   such as line substitutions.  */
3325
3326
void
3327
end_repeat (int extra)
3328
0
{
3329
0
  cond_exit_macro (macro_nest);
3330
0
  while (extra-- >= 0)
3331
0
    buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3332
0
}
3333
3334
static void
3335
assign_symbol (char *name, int mode)
3336
22.2k
{
3337
22.2k
  symbolS *symbolP;
3338
3339
22.2k
  if (name[0] == '.' && name[1] == '\0')
3340
472
    {
3341
      /* Turn '. = mumble' into a .org mumble.  */
3342
472
      segT segment;
3343
472
      expressionS exp;
3344
3345
472
      segment = get_known_segmented_expression (&exp);
3346
3347
472
      if (!need_pass_2)
3348
472
  do_org (segment, &exp, 0);
3349
3350
472
      return;
3351
472
    }
3352
3353
21.8k
  if ((symbolP = symbol_find (name)) == NULL
3354
524
      && (symbolP = md_undefined_symbol (name)) == NULL)
3355
524
    {
3356
524
      symbolP = symbol_find_or_make (name);
3357
524
#ifndef NO_LISTING
3358
      /* When doing symbol listings, play games with dummy fragments living
3359
   outside the normal fragment chain to record the file and line info
3360
   for this symbol.  */
3361
524
      if (listing & LISTING_SYMBOLS)
3362
0
  {
3363
0
    fragS *dummy_frag = notes_calloc (1, sizeof (*dummy_frag));
3364
0
    dummy_frag->line = listing_tail;
3365
0
    dummy_frag->fr_symbol = symbolP;
3366
0
    symbol_set_frag (symbolP, dummy_frag);
3367
0
  }
3368
524
#endif
3369
#ifdef obj_assign_symbol
3370
      obj_assign_symbol (symbolP);
3371
#endif
3372
524
    }
3373
3374
21.8k
  if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3375
20.6k
    {
3376
20.6k
      if ((mode != 0 || !S_IS_VOLATILE (symbolP))
3377
7.53k
    && !S_CAN_BE_REDEFINED (symbolP))
3378
7.53k
  {
3379
7.53k
    as_bad (_("symbol `%s' is already defined"), name);
3380
7.53k
    ignore_rest_of_line ();
3381
7.53k
    input_line_pointer--;
3382
7.53k
    return;
3383
7.53k
  }
3384
      /* If the symbol is volatile, copy the symbol and replace the
3385
   original with the copy, so that previous uses of the symbol will
3386
   retain the value of the symbol at the point of use.  */
3387
13.1k
      else if (S_IS_VOLATILE (symbolP))
3388
13.1k
  symbolP = symbol_clone (symbolP, 1);
3389
13.1k
      S_CLEAR_WEAKREFR (symbolP);
3390
13.1k
    }
3391
3392
14.2k
  if (mode == 0)
3393
14.1k
    S_SET_VOLATILE (symbolP);
3394
124
  else if (mode < 0)
3395
124
    S_SET_FORWARD_REF (symbolP);
3396
3397
14.2k
  pseudo_set (symbolP);
3398
14.2k
}
3399
3400
/* Handle the .equ, .equiv, .eqv, and .set directives.  If EQUIV is 1,
3401
   then this is .equiv, and it is an error if the symbol is already
3402
   defined.  If EQUIV is -1, the symbol additionally is a forward
3403
   reference.  */
3404
3405
void
3406
s_set (int equiv)
3407
1
{
3408
1
  char *name;
3409
3410
  /* Especial apologies for the random logic:
3411
     this just grew, and could be parsed much more simply!
3412
     Dean in haste.  */
3413
1
  if ((name = read_symbol_name ()) == NULL)
3414
1
    return;
3415
3416
0
  if (*input_line_pointer != ',')
3417
0
    {
3418
0
      as_bad (_("expected comma after \"%s\""), name);
3419
0
      ignore_rest_of_line ();
3420
0
      free (name);
3421
0
      return;
3422
0
    }
3423
3424
0
  input_line_pointer++;
3425
0
  assign_symbol (name, equiv);
3426
0
  demand_empty_rest_of_line ();
3427
0
  free (name);
3428
0
}
3429
3430
void
3431
s_space (int mult)
3432
1.84k
{
3433
1.84k
  expressionS exp;
3434
1.84k
  expressionS val;
3435
1.84k
  char *p = 0;
3436
1.84k
  char *stop = NULL;
3437
1.84k
  char stopc = 0;
3438
1.84k
  int bytes;
3439
3440
#ifdef md_flush_pending_output
3441
  md_flush_pending_output ();
3442
#endif
3443
3444
1.84k
  switch (mult)
3445
1.84k
    {
3446
233
    case 'x':
3447
233
#ifdef X_PRECISION
3448
233
# ifndef P_PRECISION
3449
233
#  define P_PRECISION     X_PRECISION
3450
233
#  define P_PRECISION_PAD X_PRECISION_PAD
3451
233
# endif
3452
233
      mult = (X_PRECISION + X_PRECISION_PAD) * sizeof (LITTLENUM_TYPE);
3453
233
      if (!mult)
3454
0
#endif
3455
0
  mult = 12;
3456
233
      break;
3457
3458
8
    case 'p':
3459
8
#ifdef P_PRECISION
3460
8
      mult = (P_PRECISION + P_PRECISION_PAD) * sizeof (LITTLENUM_TYPE);
3461
8
      if (!mult)
3462
0
#endif
3463
0
  mult = 12;
3464
8
      break;
3465
1.84k
    }
3466
3467
1.84k
#ifdef md_cons_align
3468
1.84k
  md_cons_align (1);
3469
1.84k
#endif
3470
3471
1.84k
  if (flag_mri)
3472
420
    stop = mri_comment_field (&stopc);
3473
3474
  /* In m68k MRI mode, we need to align to a word boundary, unless
3475
     this is ds.b.  */
3476
1.84k
  if (flag_m68k_mri && mult > 1)
3477
0
    {
3478
0
      if (now_seg == absolute_section)
3479
0
  {
3480
0
    abs_section_offset += abs_section_offset & 1;
3481
0
    if (line_label != NULL)
3482
0
      S_SET_VALUE (line_label, abs_section_offset);
3483
0
  }
3484
0
      else if (mri_common_symbol != NULL)
3485
0
  {
3486
0
    valueT mri_val;
3487
3488
0
    mri_val = S_GET_VALUE (mri_common_symbol);
3489
0
    if ((mri_val & 1) != 0)
3490
0
      {
3491
0
        S_SET_VALUE (mri_common_symbol, mri_val + 1);
3492
0
        if (line_label != NULL)
3493
0
    {
3494
0
      expressionS *symexp;
3495
3496
0
      symexp = symbol_get_value_expression (line_label);
3497
0
      know (symexp->X_op == O_symbol);
3498
0
      know (symexp->X_add_symbol == mri_common_symbol);
3499
0
      symexp->X_add_number += 1;
3500
0
    }
3501
0
      }
3502
0
  }
3503
0
      else
3504
0
  {
3505
0
    do_align (1, NULL, 0, 0);
3506
0
    if (line_label != NULL)
3507
0
      {
3508
0
        symbol_set_frag (line_label, frag_now);
3509
0
        S_SET_VALUE (line_label, frag_now_fix ());
3510
0
      }
3511
0
  }
3512
0
    }
3513
3514
1.84k
  bytes = mult;
3515
3516
1.84k
  expression (&exp);
3517
3518
1.84k
  SKIP_WHITESPACE ();
3519
1.84k
  if (*input_line_pointer == ',')
3520
106
    {
3521
106
      ++input_line_pointer;
3522
106
      expression (&val);
3523
106
    }
3524
1.73k
  else
3525
1.73k
    {
3526
1.73k
      val.X_op = O_constant;
3527
1.73k
      val.X_add_number = 0;
3528
1.73k
    }
3529
3530
1.84k
  if ((val.X_op != O_constant
3531
1.78k
       || val.X_add_number < - 0x80
3532
1.76k
       || val.X_add_number > 0xff
3533
1.75k
       || (mult != 0 && mult != 1 && val.X_add_number != 0))
3534
92
      && (now_seg != absolute_section && !in_bss ()))
3535
38
    {
3536
38
      resolve_expression (&exp);
3537
38
      if (exp.X_op != O_constant)
3538
3
  as_bad (_("unsupported variable size or fill value"));
3539
35
      else
3540
35
  {
3541
35
    offsetT i;
3542
3543
    /* PR 20901: Check for excessive values.
3544
       FIXME: 1<<10 is an arbitrary limit.  Maybe use maxpagesize instead ?  */
3545
35
    if (exp.X_add_number < 0 || exp.X_add_number > (1 << 10))
3546
1
      as_bad (_("size value for space directive too large: %lx"),
3547
1
        (long) exp.X_add_number);
3548
34
    else
3549
34
      {
3550
34
        if (mult == 0)
3551
28
    mult = 1;
3552
34
        bytes = mult * exp.X_add_number;
3553
3554
457
        for (i = 0; i < exp.X_add_number; i++)
3555
423
    emit_expr (&val, mult);
3556
34
      }
3557
35
  }
3558
38
    }
3559
1.80k
  else
3560
1.80k
    {
3561
1.80k
      if (now_seg == absolute_section || mri_common_symbol != NULL)
3562
47
  resolve_expression (&exp);
3563
3564
1.80k
      if (exp.X_op == O_constant)
3565
109
  {
3566
109
    addressT repeat = exp.X_add_number;
3567
109
    addressT total;
3568
3569
109
    bytes = 0;
3570
109
    if ((offsetT) repeat < 0)
3571
9
      {
3572
9
        as_warn (_(".space repeat count is negative, ignored"));
3573
9
        goto getout;
3574
9
      }
3575
100
    if (repeat == 0)
3576
37
      {
3577
37
        if (!flag_mri)
3578
6
    as_warn (_(".space repeat count is zero, ignored"));
3579
37
        goto getout;
3580
37
      }
3581
63
    if ((unsigned int) mult <= 1)
3582
54
      total = repeat;
3583
9
    else if (gas_mul_overflow (repeat, mult, &total)
3584
9
       || (offsetT) total < 0)
3585
1
      {
3586
1
        as_warn (_(".space repeat count overflow, ignored"));
3587
1
        goto getout;
3588
1
      }
3589
62
    bytes = total;
3590
3591
    /* If we are in the absolute section, just bump the offset.  */
3592
62
    if (now_seg == absolute_section)
3593
36
      {
3594
36
        if (val.X_op != O_constant || val.X_add_number != 0)
3595
21
    as_warn (_("ignoring fill value in absolute section"));
3596
36
        abs_section_offset += total;
3597
36
        goto getout;
3598
36
      }
3599
3600
    /* If we are secretly in an MRI common section, then
3601
       creating space just increases the size of the common
3602
       symbol.  */
3603
26
    if (mri_common_symbol != NULL)
3604
0
      {
3605
0
        S_SET_VALUE (mri_common_symbol,
3606
0
         S_GET_VALUE (mri_common_symbol) + total);
3607
0
        goto getout;
3608
0
      }
3609
3610
26
    if (!need_pass_2)
3611
26
      p = frag_var (rs_fill, 1, 1, 0, NULL, total, NULL);
3612
26
  }
3613
1.69k
      else
3614
1.69k
  {
3615
1.69k
    if (now_seg == absolute_section)
3616
2
      {
3617
2
        as_bad (_("space allocation too complex in absolute section"));
3618
2
        subseg_set (text_section, 0);
3619
2
      }
3620
3621
1.69k
    if (mri_common_symbol != NULL)
3622
1
      {
3623
1
        as_bad (_("space allocation too complex in common section"));
3624
1
        mri_common_symbol = NULL;
3625
1
      }
3626
3627
1.69k
    if (!need_pass_2)
3628
1.69k
      p = frag_var (rs_space, 1, 1, 0, make_expr_symbol (&exp), 0, NULL);
3629
1.69k
  }
3630
3631
1.72k
      if ((val.X_op != O_constant || val.X_add_number != 0) && in_bss ())
3632
39
  as_warn (_("ignoring fill value in section `%s'"),
3633
39
     segment_name (now_seg));
3634
1.68k
      else if (p)
3635
1.68k
  *p = val.X_add_number;
3636
1.72k
    }
3637
3638
1.84k
 getout:
3639
3640
  /* In MRI mode, after an odd number of bytes, we must align to an
3641
     even word boundary, unless the next instruction is a dc.b, ds.b
3642
     or dcb.b.  */
3643
1.84k
  if (flag_mri && (bytes & 1) != 0)
3644
46
    mri_pending_align = 1;
3645
3646
1.84k
  demand_empty_rest_of_line ();
3647
3648
1.84k
  if (flag_mri)
3649
420
    mri_comment_end (stop, stopc);
3650
1.84k
}
3651
3652
void
3653
s_nop (int ignore ATTRIBUTE_UNUSED)
3654
215
{
3655
215
  expressionS exp;
3656
215
  fragS *start;
3657
215
  addressT start_off;
3658
215
  offsetT frag_off;
3659
3660
#ifdef md_flush_pending_output
3661
  md_flush_pending_output ();
3662
#endif
3663
3664
215
  SKIP_WHITESPACE ();
3665
215
  expression (&exp);
3666
215
  demand_empty_rest_of_line ();
3667
3668
215
  start = frag_now;
3669
215
  start_off = frag_now_fix ();
3670
215
  do
3671
815
    {
3672
#ifdef md_emit_single_noop
3673
      md_emit_single_noop;
3674
#else
3675
815
      char *nop;
3676
3677
815
#ifndef md_single_noop_insn
3678
815
#define md_single_noop_insn "nop"
3679
815
#endif
3680
      /* md_assemble might modify its argument, so
3681
   we must pass it a string that is writable.  */
3682
815
      nop = xasprintf ("%s", md_single_noop_insn);
3683
3684
      /* Some targets assume that they can update input_line_pointer
3685
   inside md_assemble, and, worse, that they can leave it
3686
   assigned to the string pointer that was provided as an
3687
   argument.  So preserve ilp here.  */
3688
815
      char *saved_ilp = input_line_pointer;
3689
815
      md_assemble (nop);
3690
815
      input_line_pointer = saved_ilp;
3691
815
      free (nop);
3692
815
#endif
3693
#ifdef md_flush_pending_output
3694
      md_flush_pending_output ();
3695
#endif
3696
815
    } while (exp.X_op == O_constant
3697
629
       && exp.X_add_number > 0
3698
625
       && frag_offset_ignore_align_p (start, frag_now, &frag_off)
3699
625
       && frag_off + frag_now_fix () < start_off + exp.X_add_number);
3700
215
}
3701
3702
/* Use this to specify the amount of memory allocated for representing
3703
   the nops.  Needs to be large enough to hold any fixed size prologue
3704
   plus the replicating portion.  */
3705
#ifndef MAX_MEM_FOR_RS_SPACE_NOP
3706
# define MAX_MEM_FOR_RS_SPACE_NOP 1
3707
#endif
3708
3709
void
3710
s_nops (int ignore ATTRIBUTE_UNUSED)
3711
63
{
3712
63
  expressionS exp;
3713
63
  expressionS val;
3714
3715
#ifdef md_flush_pending_output
3716
  md_flush_pending_output ();
3717
#endif
3718
3719
63
  SKIP_WHITESPACE ();
3720
63
  expression (&exp);
3721
  /* Note - this expression is tested for an absolute value in
3722
     write.c:relax_segment().  */
3723
3724
63
  SKIP_WHITESPACE ();
3725
63
  if (*input_line_pointer == ',')
3726
42
    {
3727
42
      ++input_line_pointer;
3728
42
      expression (&val);
3729
42
    }
3730
21
  else
3731
21
    {
3732
21
      val.X_op = O_constant;
3733
21
      val.X_add_number = 0;
3734
21
    }
3735
3736
63
  if (val.X_op != O_constant)
3737
7
    {
3738
7
      as_bad (_("unsupported variable nop control in .nops directive"));
3739
7
      val.X_op = O_constant;
3740
7
      val.X_add_number = 0;
3741
7
    }
3742
56
  else if (val.X_add_number < 0)
3743
17
    {
3744
17
      as_warn (_("negative nop control byte, ignored"));
3745
17
      val.X_add_number = 0;
3746
17
    }
3747
3748
63
  demand_empty_rest_of_line ();
3749
3750
63
  if (need_pass_2)
3751
    /* Ignore this directive if we are going to perform a second pass.  */
3752
0
    return;
3753
3754
  /* Store the no-op instruction control byte in the first byte of frag.  */
3755
63
  char *p;
3756
63
  symbolS *sym = make_expr_symbol (&exp);
3757
63
  p = frag_var (rs_space_nop, MAX_MEM_FOR_RS_SPACE_NOP, 1, 0, sym, 0, NULL);
3758
63
  *p = val.X_add_number;
3759
63
}
3760
3761
/* Obtain the size of a floating point number, given a type.  */
3762
3763
static int
3764
float_length (int float_type, int *pad_p)
3765
56
{
3766
56
  int length, pad = 0;
3767
3768
56
  switch (float_type)
3769
56
    {
3770
2
    case 'b':
3771
2
    case 'B':
3772
2
    case 'h':
3773
2
    case 'H':
3774
2
      length = 2;
3775
2
      break;
3776
3777
52
    case 'f':
3778
52
    case 'F':
3779
52
    case 's':
3780
52
    case 'S':
3781
52
      length = 4;
3782
52
      break;
3783
3784
0
    case 'd':
3785
0
    case 'D':
3786
0
    case 'r':
3787
0
    case 'R':
3788
0
      length = 8;
3789
0
      break;
3790
3791
2
    case 'x':
3792
2
    case 'X':
3793
2
#ifdef X_PRECISION
3794
2
      length = X_PRECISION * sizeof (LITTLENUM_TYPE);
3795
2
      pad = X_PRECISION_PAD * sizeof (LITTLENUM_TYPE);
3796
2
      if (!length)
3797
0
#endif
3798
0
  length = 12;
3799
2
      break;
3800
3801
0
    case 'p':
3802
0
    case 'P':
3803
0
#ifdef P_PRECISION
3804
0
      length = P_PRECISION * sizeof (LITTLENUM_TYPE);
3805
0
      pad = P_PRECISION_PAD * sizeof (LITTLENUM_TYPE);
3806
0
      if (!length)
3807
0
#endif
3808
0
  length = 12;
3809
0
      break;
3810
3811
0
    default:
3812
0
      as_bad (_("unknown floating type '%c'"), float_type);
3813
0
      length = -1;
3814
0
      break;
3815
56
    }
3816
3817
56
  if (pad_p)
3818
56
    *pad_p = pad;
3819
3820
56
  return length;
3821
56
}
3822
3823
static int
3824
parse_one_float (int float_type, char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT])
3825
1.63k
{
3826
1.63k
  int length;
3827
3828
1.63k
  SKIP_WHITESPACE ();
3829
3830
  /* Skip any 0{letter} that may be present.  Don't even check if the
3831
     letter is legal.  Someone may invent a "z" format and this routine
3832
     has no use for such information. Lusers beware: you get
3833
     diagnostics if your input is ill-conditioned.  */
3834
1.63k
  if (input_line_pointer[0] == '0'
3835
4
      && ISALPHA (input_line_pointer[1]))
3836
0
    input_line_pointer += 2;
3837
3838
  /* Accept :xxxx, where the x's are hex digits, for a floating point
3839
     with the exact digits specified.  */
3840
1.63k
  if (input_line_pointer[0] == ':')
3841
37
    {
3842
37
      ++input_line_pointer;
3843
37
      length = hex_float (float_type, temp);
3844
37
      if (length < 0)
3845
31
  {
3846
31
    ignore_rest_of_line ();
3847
31
    return length;
3848
31
  }
3849
37
    }
3850
1.59k
  else
3851
1.59k
    {
3852
1.59k
      const char *err;
3853
3854
1.59k
      err = md_atof (float_type, temp, &length);
3855
1.59k
      know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3856
1.59k
      know (err != NULL || length > 0);
3857
1.59k
      if (err)
3858
0
  {
3859
0
    as_bad (_("bad floating literal: %s"), err);
3860
0
    ignore_rest_of_line ();
3861
0
    return -1;
3862
0
  }
3863
1.59k
    }
3864
3865
1.60k
  return length;
3866
1.63k
}
3867
3868
/* This is like s_space, but the value is a floating point number with
3869
   the given precision.  This is for the MRI dcb.s pseudo-op and
3870
   friends.  */
3871
3872
void
3873
s_float_space (int float_type)
3874
821
{
3875
821
  offsetT count;
3876
821
  int flen;
3877
821
  char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3878
821
  char *stop = NULL;
3879
821
  char stopc = 0;
3880
821
  char *p;
3881
3882
821
#ifdef md_cons_align
3883
821
  md_cons_align (1);
3884
821
#endif
3885
3886
821
  if (flag_mri)
3887
812
    stop = mri_comment_field (&stopc);
3888
3889
821
  count = get_absolute_expression ();
3890
3891
821
  SKIP_WHITESPACE ();
3892
821
  if (*input_line_pointer != ',')
3893
19
    {
3894
19
      int pad;
3895
3896
19
      flen = float_length (float_type, &pad);
3897
19
      if (flen >= 0)
3898
19
  memset (temp, 0, flen += pad);
3899
19
    }
3900
802
  else
3901
802
    {
3902
802
      ++input_line_pointer;
3903
3904
802
      flen = parse_one_float (float_type, temp);
3905
802
    }
3906
3907
821
  if (flen < 0)
3908
31
    {
3909
31
      if (flag_mri)
3910
31
  mri_comment_end (stop, stopc);
3911
31
      return;
3912
31
    }
3913
3914
790
  if (count == 1)
3915
8
    p = frag_more (flen);
3916
782
  else
3917
782
    p = frag_var (rs_fill, flen, flen, 0, NULL, count, NULL);
3918
790
  memcpy (p, temp, flen);
3919
3920
790
  demand_empty_rest_of_line ();
3921
3922
790
  if (flag_mri)
3923
781
    mri_comment_end (stop, stopc);
3924
790
}
3925
3926
/* Handle the .struct pseudo-op, as found in MIPS assemblers.  */
3927
3928
void
3929
s_struct (int ignore ATTRIBUTE_UNUSED)
3930
232
{
3931
232
  char *stop = NULL;
3932
232
  char stopc = 0;
3933
3934
232
  if (flag_mri)
3935
78
    stop = mri_comment_field (&stopc);
3936
232
  abs_section_offset = get_absolute_expression ();
3937
232
#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3938
  /* The ELF backend needs to know that we are changing sections, so
3939
     that .previous works correctly. */
3940
232
  if (IS_ELF)
3941
232
    obj_elf_section_change_hook ();
3942
232
#endif
3943
232
  subseg_set (absolute_section, 0);
3944
232
  demand_empty_rest_of_line ();
3945
232
  if (flag_mri)
3946
78
    mri_comment_end (stop, stopc);
3947
232
}
3948
3949
void
3950
s_text (int ignore ATTRIBUTE_UNUSED)
3951
381
{
3952
381
  int temp;
3953
3954
381
  temp = get_absolute_expression ();
3955
381
  subseg_set (text_section, temp);
3956
381
  demand_empty_rest_of_line ();
3957
381
}
3958
3959
/* .weakref x, y sets x as an alias to y that, as long as y is not
3960
   referenced directly, will cause y to become a weak symbol.  */
3961
void
3962
s_weakref (int ignore ATTRIBUTE_UNUSED)
3963
78
{
3964
78
  char *name;
3965
78
  symbolS *symbolP;
3966
78
  symbolS *symbolP2;
3967
78
  expressionS exp;
3968
3969
78
  if ((name = read_symbol_name ()) == NULL)
3970
1
    return;
3971
3972
77
  symbolP = symbol_find_or_make (name);
3973
3974
77
  if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3975
18
    {
3976
18
      if (!S_IS_VOLATILE (symbolP))
3977
17
  {
3978
17
    as_bad (_("symbol `%s' is already defined"), name);
3979
17
    goto err_out;
3980
17
  }
3981
1
      symbolP = symbol_clone (symbolP, 1);
3982
1
      S_CLEAR_VOLATILE (symbolP);
3983
1
    }
3984
3985
60
  SKIP_WHITESPACE ();
3986
3987
60
  if (*input_line_pointer != ',')
3988
22
    {
3989
22
      as_bad (_("expected comma after \"%s\""), name);
3990
22
      goto err_out;
3991
22
    }
3992
3993
38
  input_line_pointer++;
3994
3995
38
  SKIP_WHITESPACE ();
3996
38
  free (name);
3997
3998
38
  if ((name = read_symbol_name ()) == NULL)
3999
28
    return;
4000
4001
10
  if ((symbolP2 = symbol_find_noref (name, 1)) == NULL
4002
3
      && (symbolP2 = md_undefined_symbol (name)) == NULL)
4003
3
    {
4004
3
      symbolP2 = symbol_find_or_make (name);
4005
3
      S_SET_WEAKREFD (symbolP2);
4006
3
    }
4007
7
  else
4008
7
    {
4009
7
      symbolS *symp = symbolP2;
4010
4011
7
      while (S_IS_WEAKREFR (symp) && symp != symbolP)
4012
0
  {
4013
0
    expressionS *expP = symbol_get_value_expression (symp);
4014
4015
0
    gas_assert (expP->X_op == O_symbol
4016
0
      && expP->X_add_number == 0);
4017
0
    symp = expP->X_add_symbol;
4018
0
  }
4019
7
      if (symp == symbolP)
4020
5
  {
4021
5
    char *loop;
4022
4023
5
    loop = concat (S_GET_NAME (symbolP),
4024
5
       " => ", S_GET_NAME (symbolP2), (const char *) NULL);
4025
4026
5
    symp = symbolP2;
4027
5
    while (symp != symbolP)
4028
0
      {
4029
0
        char *old_loop = loop;
4030
4031
0
        symp = symbol_get_value_expression (symp)->X_add_symbol;
4032
0
        loop = concat (loop, " => ", S_GET_NAME (symp),
4033
0
           (const char *) NULL);
4034
0
        free (old_loop);
4035
0
      }
4036
4037
5
    as_bad (_("%s: would close weakref loop: %s"),
4038
5
      S_GET_NAME (symbolP), loop);
4039
4040
5
    free (loop);
4041
5
    free (name);
4042
5
    ignore_rest_of_line ();
4043
5
    return;
4044
5
  }
4045
4046
      /* Short-circuiting instead of just checking here might speed
4047
   things up a tiny little bit, but loop error messages would
4048
   miss intermediate links.  */
4049
      /* symbolP2 = symp; */
4050
7
    }
4051
4052
5
  memset (&exp, 0, sizeof (exp));
4053
5
  exp.X_op = O_symbol;
4054
5
  exp.X_add_symbol = symbolP2;
4055
4056
5
  S_SET_SEGMENT (symbolP, undefined_section);
4057
5
  symbol_set_value_expression (symbolP, &exp);
4058
5
  symbol_set_frag (symbolP, &zero_address_frag);
4059
5
  S_SET_WEAKREFR (symbolP);
4060
4061
5
  demand_empty_rest_of_line ();
4062
5
  free (name);
4063
5
  return;
4064
4065
39
 err_out:
4066
39
  ignore_rest_of_line ();
4067
39
  free (name);
4068
39
  return;
4069
10
}
4070

4071
4072
/* Verify that we are at the end of a line.  If not, issue an error and
4073
   skip to EOL.  This function may leave input_line_pointer one past
4074
   buffer_limit, so should not be called from places that may
4075
   dereference input_line_pointer unconditionally.  Note that when the
4076
   gas parser is switched to handling a string (where buffer_limit
4077
   should be the size of the string excluding the NUL terminator) this
4078
   will be one past the NUL; is_end_of_line(0) returns true.  */
4079
4080
void
4081
demand_empty_rest_of_line (void)
4082
147k
{
4083
147k
  SKIP_WHITESPACE ();
4084
147k
  if (input_line_pointer > buffer_limit)
4085
0
    return;
4086
147k
  if (is_end_of_stmt (*input_line_pointer))
4087
85.8k
    input_line_pointer++;
4088
62.0k
  else
4089
62.0k
    {
4090
62.0k
      if (ISPRINT (*input_line_pointer))
4091
51.3k
  as_bad (_("junk at end of line, first unrecognized character is `%c'"),
4092
51.3k
     *input_line_pointer);
4093
10.7k
      else
4094
10.7k
  as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
4095
10.7k
     *input_line_pointer);
4096
62.0k
      ignore_rest_of_line ();
4097
62.0k
    }
4098
  /* Return pointing just after end-of-line.  */
4099
147k
}
4100
4101
/* Silently advance to the end of a statement.  Use this after already having
4102
   issued an error about something bad.  Like demand_empty_rest_of_line,
4103
   this function may leave input_line_pointer one after buffer_limit;
4104
   Don't call it from within expression parsing code in an attempt to
4105
   silence further errors.  */
4106
4107
void
4108
ignore_rest_of_line (void)
4109
225k
{
4110
4.06M
  while (input_line_pointer <= buffer_limit)
4111
4.06M
    if (is_end_of_stmt (*input_line_pointer++))
4112
225k
      break;
4113
  /* Return pointing just after end-of-statement.  */
4114
225k
}
4115
4116
/* Sets frag for given symbol to zero_address_frag, except when the
4117
   symbol frag is already set to a dummy listing frag.  */
4118
4119
static void
4120
set_zero_frag (symbolS *symbolP)
4121
14.1k
{
4122
14.1k
  if (symbol_get_frag (symbolP)->fr_type != rs_dummy)
4123
14.1k
    symbol_set_frag (symbolP, &zero_address_frag);
4124
14.1k
}
4125
4126
/* In:  Pointer to a symbol.
4127
  Input_line_pointer->expression.
4128
4129
   Out: Input_line_pointer->just after any whitespace after expression.
4130
  Tried to set symbol to value of expression.
4131
  Will change symbols type, value, and frag;  */
4132
4133
void
4134
pseudo_set (symbolS *symbolP)
4135
14.2k
{
4136
14.2k
  expressionS exp;
4137
14.2k
  segT seg;
4138
4139
14.2k
  know (symbolP);   /* NULL pointer is logic error.  */
4140
4141
#ifdef md_expr_init_rest
4142
  md_expr_init_rest (&exp);
4143
#endif
4144
14.2k
  if (!S_IS_FORWARD_REF (symbolP))
4145
14.1k
    (void) expression (&exp);
4146
124
  else
4147
124
    (void) expr (0, &exp, expr_defer_incl_dot);
4148
4149
14.2k
  if (exp.X_op == O_illegal)
4150
0
    as_bad (_("illegal expression"));
4151
14.2k
  else if (exp.X_op == O_absent)
4152
1.70k
    as_bad (_("missing expression"));
4153
12.5k
  else if (exp.X_op == O_big)
4154
94
    {
4155
94
      if (exp.X_add_number > 0)
4156
60
  as_bad (_("bignum invalid"));
4157
34
      else
4158
34
  as_bad (_("floating point number invalid"));
4159
94
    }
4160
12.4k
  else if (exp.X_op == O_subtract
4161
2.66k
     && !S_IS_FORWARD_REF (symbolP)
4162
2.66k
     && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
4163
7
     && (symbol_get_frag (exp.X_add_symbol)
4164
7
         == symbol_get_frag (exp.X_op_symbol)))
4165
7
    {
4166
7
      exp.X_op = O_constant;
4167
7
      exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
4168
7
        - S_GET_VALUE (exp.X_op_symbol));
4169
7
    }
4170
4171
14.2k
  if (symbol_section_p (symbolP))
4172
0
    {
4173
0
      as_bad ("attempt to set value of section symbol");
4174
0
      return;
4175
0
    }
4176
4177
14.2k
  switch (exp.X_op)
4178
14.2k
    {
4179
0
    case O_illegal:
4180
1.70k
    case O_absent:
4181
1.80k
    case O_big:
4182
1.80k
      exp.X_add_number = 0;
4183
      /* Fall through.  */
4184
4.78k
    case O_constant:
4185
4.78k
      S_SET_SEGMENT (symbolP, absolute_section);
4186
4.78k
      S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
4187
4.78k
      set_zero_frag (symbolP);
4188
4.78k
      break;
4189
4190
119
    case O_register:
4191
119
#ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
4192
119
      if (S_IS_EXTERNAL (symbolP))
4193
0
  {
4194
0
    as_bad ("can't equate global symbol `%s' with register name",
4195
0
      S_GET_NAME (symbolP));
4196
0
    return;
4197
0
  }
4198
119
#endif
4199
      /* Make sure symbol_equated_p() recognizes the symbol as an equate.  */
4200
119
      exp.X_add_symbol = make_expr_symbol (&exp);
4201
119
      exp.X_add_number = 0;
4202
119
      exp.X_op = O_symbol;
4203
119
      symbol_set_value_expression (symbolP, &exp);
4204
119
      S_SET_SEGMENT (symbolP, reg_section);
4205
119
      set_zero_frag (symbolP);
4206
119
      break;
4207
4208
3.95k
    case O_symbol:
4209
3.95k
      seg = S_GET_SEGMENT (exp.X_add_symbol);
4210
3.95k
      if (seg == expr_section)
4211
10
  goto expr;
4212
      /* For x=undef+const, create an expression symbol.
4213
   For x=x+const, just update x except when x is an undefined symbol
4214
   For x=defined+const, evaluate x.  */
4215
3.94k
      if (symbolP == exp.X_add_symbol
4216
24
    && (seg != undefined_section
4217
24
        || !symbol_constant_p (symbolP)))
4218
16
  {
4219
16
    *symbol_X_add_number (symbolP) += exp.X_add_number;
4220
16
    break;
4221
16
  }
4222
3.92k
      else if (!S_IS_FORWARD_REF (symbolP) && seg != undefined_section)
4223
145
  {
4224
145
    symbolS *s = exp.X_add_symbol;
4225
4226
145
    if (S_IS_COMMON (s))
4227
0
      as_bad (_("`%s' can't be equated to common symbol `%s'"),
4228
0
        S_GET_NAME (symbolP), S_GET_NAME (s));
4229
4230
145
    S_SET_SEGMENT (symbolP, seg);
4231
145
    S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (s));
4232
145
    symbol_set_frag (symbolP, symbol_get_frag (s));
4233
145
    copy_symbol_attributes (symbolP, s);
4234
145
    break;
4235
145
  }
4236
3.77k
      S_SET_SEGMENT (symbolP, undefined_section);
4237
3.77k
      symbol_set_value_expression (symbolP, &exp);
4238
3.77k
      copy_symbol_attributes (symbolP, exp.X_add_symbol);
4239
3.77k
      set_zero_frag (symbolP);
4240
3.77k
      break;
4241
4242
5.43k
    default:
4243
5.44k
    expr:
4244
      /* The value is some complex expression.  */
4245
5.44k
      S_SET_SEGMENT (symbolP, expr_section);
4246
5.44k
      symbol_set_value_expression (symbolP, &exp);
4247
5.44k
      set_zero_frag (symbolP);
4248
5.44k
      break;
4249
14.2k
    }
4250
14.2k
}
4251

4252
/*      cons()
4253
4254
   CONStruct more frag of .bytes, or .words etc.
4255
   Should need_pass_2 be 1 then emit no frag(s).
4256
   This understands EXPRESSIONS.
4257
4258
   Bug (?)
4259
4260
   This has a split personality. We use expression() to read the
4261
   value. We can detect if the value won't fit in a byte or word.
4262
   But we can't detect if expression() discarded significant digits
4263
   in the case of a long. Not worth the crocks required to fix it.  */
4264
4265
/* Select a parser for cons expressions.  */
4266
4267
/* Some targets need to parse the expression in various fancy ways.
4268
   You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
4269
   (for example, the HPPA does this).  Otherwise, you can define
4270
   REPEAT_CONS_EXPRESSIONS to permit repeat counts.  If none of these
4271
   are defined, which is the normal case, then only simple expressions
4272
   are permitted.  */
4273
4274
#ifdef TC_M68K
4275
static void
4276
parse_mri_cons (expressionS *exp, unsigned int nbytes);
4277
#endif
4278
4279
/* This function is used by .cfi_* directive handling, and hence must not
4280
   invoke parse_repeat_cons().  */
4281
4282
TC_PARSE_CONS_RETURN_TYPE
4283
do_parse_cons_expression (expressionS *exp,
4284
        int nbytes ATTRIBUTE_UNUSED)
4285
411
{
4286
411
#ifdef TC_PARSE_CONS_EXPRESSION
4287
411
  return TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4288
#else
4289
  expression (exp);
4290
  return TC_PARSE_CONS_RETURN_NONE;
4291
#endif
4292
411
}
4293
4294
#ifndef TC_PARSE_CONS_EXPRESSION
4295
#ifdef REPEAT_CONS_EXPRESSIONS
4296
#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
4297
  (parse_repeat_cons (EXP, NBYTES), TC_PARSE_CONS_RETURN_NONE)
4298
static void
4299
parse_repeat_cons (expressionS *exp, unsigned int nbytes);
4300
#endif
4301
4302
/* If we haven't gotten one yet, just call expression.  */
4303
#ifndef TC_PARSE_CONS_EXPRESSION
4304
#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
4305
  (expression (EXP), TC_PARSE_CONS_RETURN_NONE)
4306
#endif
4307
#endif
4308
4309
/* Worker to do .byte etc statements.
4310
   Clobbers input_line_pointer and checks end-of-line.  */
4311
4312
static void
4313
cons_worker (int nbytes,  /* 1=.byte, 2=.word, 4=.long.  */
4314
       int rva)
4315
440
{
4316
440
  int c;
4317
440
  expressionS exp;
4318
440
  char *stop = NULL;
4319
440
  char stopc = 0;
4320
4321
#ifdef md_flush_pending_output
4322
  md_flush_pending_output ();
4323
#endif
4324
4325
440
  if (flag_mri)
4326
347
    stop = mri_comment_field (&stopc);
4327
4328
440
  if (is_it_end_of_statement ())
4329
20
    {
4330
20
      demand_empty_rest_of_line ();
4331
20
      if (flag_mri)
4332
13
  mri_comment_end (stop, stopc);
4333
20
      return;
4334
20
    }
4335
4336
420
  if (nbytes == 0)
4337
1
    nbytes = TC_ADDRESS_BYTES ();
4338
4339
420
#ifdef md_cons_align
4340
420
  md_cons_align (nbytes);
4341
420
#endif
4342
4343
420
  c = 0;
4344
420
  do
4345
809
    {
4346
809
      TC_PARSE_CONS_RETURN_TYPE ret = TC_PARSE_CONS_RETURN_NONE;
4347
#ifdef TC_CONS_FIX_CHECK
4348
      fixS **cur_fix = &frchain_now->fix_tail;
4349
4350
      if (*cur_fix != NULL)
4351
  cur_fix = &(*cur_fix)->fx_next;
4352
#endif
4353
4354
#ifdef TC_M68K
4355
      if (flag_m68k_mri)
4356
  parse_mri_cons (&exp, nbytes);
4357
      else
4358
#endif
4359
809
  {
4360
#if 0
4361
    if (*input_line_pointer == '"')
4362
      {
4363
        as_bad (_("unexpected `\"' in expression"));
4364
        ignore_rest_of_line ();
4365
        return;
4366
      }
4367
#endif
4368
809
    ret = TC_PARSE_CONS_EXPRESSION (&exp, nbytes);
4369
809
  }
4370
4371
809
      if (rva)
4372
0
  {
4373
0
    if (exp.X_op == O_symbol)
4374
0
      exp.X_op = O_symbol_rva;
4375
0
    else
4376
0
      as_fatal (_("rva without symbol"));
4377
0
  }
4378
809
      emit_expr_with_reloc (&exp, nbytes, ret);
4379
#ifdef TC_CONS_FIX_CHECK
4380
      TC_CONS_FIX_CHECK (&exp, nbytes, *cur_fix);
4381
#endif
4382
809
      ++c;
4383
809
    }
4384
809
  while (*input_line_pointer++ == ',');
4385
4386
  /* In MRI mode, after an odd number of bytes, we must align to an
4387
     even word boundary, unless the next instruction is a dc.b, ds.b
4388
     or dcb.b.  */
4389
420
  if (flag_mri && nbytes == 1 && (c & 1) != 0)
4390
8
    mri_pending_align = 1;
4391
4392
420
  input_line_pointer--;   /* Put terminator back into stream.  */
4393
4394
420
  demand_empty_rest_of_line ();
4395
4396
420
  if (flag_mri)
4397
334
    mri_comment_end (stop, stopc);
4398
4399
  /* Disallow hand-crafting instructions using .byte.  FIXME - what about
4400
     .word, .long etc ?  */
4401
420
  if (flag_synth_cfi && frchain_now && frchain_now->frch_ginsn_data
4402
0
      && nbytes == 1)
4403
0
    as_bad (_("SCFI: hand-crafting instructions not supported"));
4404
420
}
4405
4406
void
4407
cons (int size)
4408
427
{
4409
427
  cons_worker (size, 0);
4410
427
}
4411
4412
void
4413
s_rva (int size)
4414
13
{
4415
13
  cons_worker (size, 1);
4416
13
}
4417
4418
/* .reloc offset, reloc_name, symbol+addend.  */
4419
4420
static void
4421
s_reloc (int ignore ATTRIBUTE_UNUSED)
4422
724
{
4423
724
  char *stop = NULL;
4424
724
  char stopc = 0;
4425
724
  expressionS exp;
4426
724
  char *r_name;
4427
724
  int c;
4428
724
  struct reloc_list *reloc;
4429
724
  struct _bfd_rel { const char * name; bfd_reloc_code_real_type code; };
4430
724
  static const struct _bfd_rel bfd_relocs[] =
4431
724
  {
4432
724
    { "NONE", BFD_RELOC_NONE },
4433
724
    { "8",  BFD_RELOC_8 },
4434
724
    { "16", BFD_RELOC_16 },
4435
724
    { "32", BFD_RELOC_32 },
4436
724
    { "64", BFD_RELOC_64 }
4437
724
  };
4438
4439
724
  reloc = notes_alloc (sizeof (*reloc));
4440
4441
724
  if (flag_mri)
4442
715
    stop = mri_comment_field (&stopc);
4443
4444
724
  expression (&exp);
4445
724
  switch (exp.X_op)
4446
724
    {
4447
0
    case O_illegal:
4448
0
    case O_absent:
4449
0
    case O_big:
4450
0
    case O_register:
4451
0
      as_bad (_("missing or bad offset expression"));
4452
0
      goto err_out;
4453
566
    case O_constant:
4454
566
      exp.X_add_symbol = section_symbol (now_seg);
4455
      /* Mark the section symbol used in relocation so that it will be
4456
   included in the symbol table.  */
4457
566
      symbol_mark_used_in_reloc (exp.X_add_symbol);
4458
566
      exp.X_op = O_symbol;
4459
      /* Fallthru */
4460
712
    case O_symbol:
4461
712
      if (exp.X_add_number == 0)
4462
710
  {
4463
710
    reloc->u.a.offset_sym = exp.X_add_symbol;
4464
710
    break;
4465
710
  }
4466
      /* Fallthru */
4467
14
    default:
4468
14
      reloc->u.a.offset_sym = make_expr_symbol (&exp);
4469
14
      break;
4470
724
    }
4471
4472
724
  SKIP_WHITESPACE ();
4473
724
  if (*input_line_pointer != ',')
4474
158
    {
4475
158
      as_bad (_("missing reloc type"));
4476
158
      goto err_out;
4477
158
    }
4478
4479
566
  ++input_line_pointer;
4480
566
  SKIP_WHITESPACE ();
4481
566
  c = get_symbol_name (& r_name);
4482
566
  if (strncasecmp (r_name, "BFD_RELOC_", 10) == 0)
4483
0
    {
4484
0
      unsigned int i;
4485
4486
0
      for (reloc->u.a.howto = NULL, i = 0; i < ARRAY_SIZE (bfd_relocs); i++)
4487
0
  if (strcasecmp (r_name + 10, bfd_relocs[i].name) == 0)
4488
0
    {
4489
0
      reloc->u.a.howto = bfd_reloc_type_lookup (stdoutput,
4490
0
                  bfd_relocs[i].code);
4491
0
      break;
4492
0
    }
4493
0
    }
4494
566
  else
4495
566
    reloc->u.a.howto = bfd_reloc_name_lookup (stdoutput, r_name);
4496
566
  restore_line_pointer (c);
4497
566
  if (reloc->u.a.howto == NULL)
4498
141
    {
4499
141
      as_bad (_("unrecognized reloc type"));
4500
141
      goto err_out;
4501
141
    }
4502
4503
425
  exp.X_op = O_absent;
4504
425
  SKIP_WHITESPACE ();
4505
425
  if (*input_line_pointer == ',')
4506
425
    {
4507
425
      ++input_line_pointer;
4508
425
      expression (&exp);
4509
425
    }
4510
425
  switch (exp.X_op)
4511
425
    {
4512
0
    case O_illegal:
4513
280
    case O_big:
4514
280
    case O_register:
4515
280
      as_bad (_("bad reloc expression"));
4516
579
    err_out:
4517
579
      ignore_rest_of_line ();
4518
579
      if (flag_mri)
4519
570
  mri_comment_end (stop, stopc);
4520
579
      return;
4521
0
    case O_absent:
4522
0
      reloc->u.a.sym = NULL;
4523
0
      reloc->u.a.addend = 0;
4524
0
      break;
4525
140
    case O_constant:
4526
140
      reloc->u.a.sym = NULL;
4527
140
      reloc->u.a.addend = exp.X_add_number;
4528
140
      break;
4529
5
    case O_symbol:
4530
5
      reloc->u.a.sym = exp.X_add_symbol;
4531
5
      reloc->u.a.addend = exp.X_add_number;
4532
5
      break;
4533
0
    default:
4534
0
      reloc->u.a.sym = make_expr_symbol (&exp);
4535
0
      reloc->u.a.addend = 0;
4536
0
      break;
4537
425
    }
4538
4539
145
  reloc->file = as_where (&reloc->line);
4540
145
  reloc->next = reloc_list;
4541
145
  reloc_list = reloc;
4542
4543
145
  demand_empty_rest_of_line ();
4544
145
  if (flag_mri)
4545
145
    mri_comment_end (stop, stopc);
4546
145
}
4547
4548
/* Put the contents of expression EXP into the object file using
4549
   NBYTES bytes.  If need_pass_2 is 1, this does nothing.  */
4550
4551
void
4552
emit_expr (expressionS *exp, unsigned int nbytes)
4553
1.48k
{
4554
1.48k
  emit_expr_with_reloc (exp, nbytes, TC_PARSE_CONS_RETURN_NONE);
4555
1.48k
}
4556
4557
void
4558
emit_expr_with_reloc (expressionS *exp,
4559
          unsigned int nbytes,
4560
          TC_PARSE_CONS_RETURN_TYPE reloc)
4561
2.69k
{
4562
2.69k
  operatorT op;
4563
2.69k
  char *p;
4564
2.69k
  valueT extra_digit = 0;
4565
4566
  /* Don't do anything if we are going to make another pass.  */
4567
2.69k
  if (need_pass_2)
4568
0
    return;
4569
4570
2.69k
  frag_grow (nbytes);
4571
2.69k
  symbol_set_value_now (&dot_symbol);
4572
4573
2.69k
#ifndef NO_LISTING
4574
2.69k
#ifdef OBJ_ELF
4575
  /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
4576
     appear as a four byte positive constant in the .line section,
4577
     followed by a 2 byte 0xffff.  Look for that case here.  */
4578
2.69k
  if (strcmp (segment_name (now_seg), ".line") != 0)
4579
2.53k
    dwarf_line = -1;
4580
153
  else if (dwarf_line >= 0
4581
1
     && nbytes == 2
4582
0
     && exp->X_op == O_constant
4583
0
     && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
4584
0
    listing_source_line (dwarf_line);
4585
153
  else if (nbytes == 4
4586
22
     && exp->X_op == O_constant
4587
9
     && exp->X_add_number >= 0)
4588
1
    dwarf_line = exp->X_add_number;
4589
152
  else
4590
152
    dwarf_line = -1;
4591
4592
  /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
4593
     appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
4594
     AT_sibling (0x12) followed by a four byte address of the sibling
4595
     followed by a 2 byte AT_name (0x38) followed by the name of the
4596
     file.  We look for that case here.  */
4597
2.69k
  if (strcmp (segment_name (now_seg), ".debug") != 0)
4598
2.68k
    dwarf_file = 0;
4599
4
  else if (dwarf_file == 0
4600
4
     && nbytes == 2
4601
4
     && exp->X_op == O_constant
4602
3
     && exp->X_add_number == 0x11)
4603
0
    dwarf_file = 1;
4604
4
  else if (dwarf_file == 1
4605
0
     && nbytes == 2
4606
0
     && exp->X_op == O_constant
4607
0
     && exp->X_add_number == 0x12)
4608
0
    dwarf_file = 2;
4609
4
  else if (dwarf_file == 2
4610
0
     && nbytes == 4)
4611
0
    dwarf_file = 3;
4612
4
  else if (dwarf_file == 3
4613
0
     && nbytes == 2
4614
0
     && exp->X_op == O_constant
4615
0
     && exp->X_add_number == 0x38)
4616
0
    dwarf_file = 4;
4617
4
  else
4618
4
    dwarf_file = 0;
4619
4620
  /* The variable dwarf_file_string tells stringer that the string
4621
     may be the name of the source file.  */
4622
2.69k
  if (dwarf_file == 4)
4623
0
    dwarf_file_string = 1;
4624
2.69k
  else
4625
2.69k
    dwarf_file_string = 0;
4626
2.69k
#endif
4627
2.69k
#endif
4628
4629
2.69k
  if (check_eh_frame (exp, &nbytes))
4630
0
    return;
4631
4632
2.69k
  op = exp->X_op;
4633
4634
  /* Handle a negative bignum.  */
4635
2.69k
  if (op == O_uminus
4636
0
      && exp->X_add_number == 0
4637
0
      && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
4638
0
      && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
4639
0
    {
4640
0
      int i;
4641
0
      unsigned long carry;
4642
4643
0
      exp = symbol_get_value_expression (exp->X_add_symbol);
4644
4645
      /* Negate the bignum: one's complement each digit and add 1.  */
4646
0
      carry = 1;
4647
0
      for (i = 0; i < exp->X_add_number; i++)
4648
0
  {
4649
0
    unsigned long next;
4650
4651
0
    next = (((~(generic_bignum[i] & LITTLENUM_MASK))
4652
0
       & LITTLENUM_MASK)
4653
0
      + carry);
4654
0
    generic_bignum[i] = next & LITTLENUM_MASK;
4655
0
    carry = next >> LITTLENUM_NUMBER_OF_BITS;
4656
0
  }
4657
4658
      /* We can ignore any carry out, because it will be handled by
4659
   extra_digit if it is needed.  */
4660
4661
0
      extra_digit = -1;
4662
0
      op = O_big;
4663
0
    }
4664
4665
2.69k
  if (op == O_absent || op == O_illegal)
4666
170
    {
4667
170
      as_warn (_("zero assumed for missing expression"));
4668
170
      exp->X_add_number = 0;
4669
170
      op = O_constant;
4670
170
    }
4671
2.52k
  else if (op == O_big && exp->X_add_number <= 0)
4672
6
    {
4673
6
      as_bad (_("floating point number invalid"));
4674
6
      exp->X_add_number = 0;
4675
6
      op = O_constant;
4676
6
    }
4677
2.51k
  else if (op == O_register)
4678
0
    {
4679
0
      as_warn (_("register value used as expression"));
4680
0
      op = O_constant;
4681
0
    }
4682
4683
  /* Allow `.word 0' in the absolute section.  */
4684
2.69k
  if (now_seg == absolute_section)
4685
66
    {
4686
66
      if (op != O_constant || exp->X_add_number != 0)
4687
21
  as_bad (_("attempt to store value in absolute section"));
4688
66
      abs_section_offset += nbytes;
4689
66
      return;
4690
66
    }
4691
4692
  /* Allow `.word 0' in BSS style sections.  */
4693
2.62k
  if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
4694
5
    as_bad (_("attempt to store non-zero value in section `%s'"),
4695
5
      segment_name (now_seg));
4696
4697
2.62k
  p = frag_more (nbytes);
4698
4699
2.62k
  if (reloc != TC_PARSE_CONS_RETURN_NONE)
4700
67
    {
4701
67
      emit_expr_fix (exp, nbytes, frag_now, p, reloc);
4702
67
      return;
4703
67
    }
4704
4705
#ifndef WORKING_DOT_WORD
4706
  /* If we have the difference of two symbols in a word, save it on
4707
     the broken_words list.  See the code in write.c.  */
4708
  if (op == O_subtract && nbytes == 2)
4709
    {
4710
      struct broken_word *x;
4711
4712
      x = XNEW (struct broken_word);
4713
      x->next_broken_word = broken_words;
4714
      broken_words = x;
4715
      x->seg = now_seg;
4716
      x->subseg = now_subseg;
4717
      x->frag = frag_now;
4718
      x->word_goes_here = p;
4719
      x->dispfrag = 0;
4720
      x->add = exp->X_add_symbol;
4721
      x->sub = exp->X_op_symbol;
4722
      x->addnum = exp->X_add_number;
4723
      x->added = 0;
4724
      x->use_jump = 0;
4725
      new_broken_words++;
4726
      return;
4727
    }
4728
#endif
4729
4730
  /* If we have an integer, but the number of bytes is too large to
4731
     pass to md_number_to_chars, handle it as a bignum.  */
4732
2.55k
  if (op == O_constant && nbytes > sizeof (valueT))
4733
22
    {
4734
22
      extra_digit = -convert_to_bignum (exp);
4735
22
      op = O_big;
4736
22
    }
4737
4738
2.55k
  if (op == O_constant)
4739
491
    {
4740
491
      valueT get;
4741
491
      valueT use;
4742
491
      valueT mask;
4743
491
      valueT unmask;
4744
4745
      /* JF << of >= number of bits in the object is undefined.  In
4746
   particular SPARC (Sun 4) has problems.  */
4747
491
      if (nbytes >= sizeof (valueT))
4748
21
  {
4749
21
    know (nbytes == sizeof (valueT));
4750
21
    mask = 0;
4751
21
  }
4752
470
      else
4753
470
  {
4754
    /* Don't store these bits.  */
4755
470
    mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
4756
470
  }
4757
4758
491
      unmask = ~mask;   /* Do store these bits.  */
4759
4760
#ifdef NEVER
4761
      "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
4762
      mask = ~(unmask >> 1);  /* Includes sign bit now.  */
4763
#endif
4764
4765
491
      get = exp->X_add_number;
4766
491
      use = get & unmask;
4767
491
      if ((get & mask) != 0 && (-get & mask) != 0)
4768
45
  {
4769
    /* Leading bits contain both 0s & 1s.  */
4770
45
    as_warn (_("value 0x%" PRIx64 " truncated to 0x%" PRIx64),
4771
45
       (uint64_t) get, (uint64_t) use);
4772
45
  }
4773
      /* Put bytes in right order.  */
4774
491
      md_number_to_chars (p, use, nbytes);
4775
491
    }
4776
2.06k
  else if (op == O_big)
4777
238
    {
4778
238
      unsigned int size;
4779
238
      LITTLENUM_TYPE *nums;
4780
4781
238
      size = exp->X_add_number * CHARS_PER_LITTLENUM;
4782
238
      if (nbytes < size)
4783
0
  {
4784
0
    int i = nbytes / CHARS_PER_LITTLENUM;
4785
4786
0
    if (i != 0)
4787
0
      {
4788
0
        LITTLENUM_TYPE sign = 0;
4789
0
        if ((generic_bignum[--i]
4790
0
       & (1 << (LITTLENUM_NUMBER_OF_BITS - 1))) != 0)
4791
0
    sign = ~(LITTLENUM_TYPE) 0;
4792
4793
0
        while (++i < exp->X_add_number)
4794
0
    if (generic_bignum[i] != sign)
4795
0
      break;
4796
0
      }
4797
0
    else if (nbytes == 1)
4798
0
      {
4799
        /* We have nbytes == 1 and CHARS_PER_LITTLENUM == 2 (probably).
4800
     Check that bits 8.. of generic_bignum[0] match bit 7
4801
     and that they match all of generic_bignum[1..exp->X_add_number].  */
4802
0
        LITTLENUM_TYPE sign = (generic_bignum[0] & (1 << 7)) ? -1 : 0;
4803
0
        LITTLENUM_TYPE himask = LITTLENUM_MASK & ~ 0xFF;
4804
4805
0
        if ((generic_bignum[0] & himask) == (sign & himask))
4806
0
    {
4807
0
      while (++i < exp->X_add_number)
4808
0
        if (generic_bignum[i] != sign)
4809
0
          break;
4810
0
    }
4811
0
      }
4812
4813
0
    if (i < exp->X_add_number)
4814
0
      as_warn (ngettext ("bignum truncated to %d byte",
4815
0
             "bignum truncated to %d bytes",
4816
0
             nbytes),
4817
0
         nbytes);
4818
0
    size = nbytes;
4819
0
  }
4820
4821
238
      if (nbytes == 1)
4822
0
  {
4823
0
    md_number_to_chars (p, generic_bignum[0], 1);
4824
0
    return;
4825
0
  }
4826
238
      know (nbytes % CHARS_PER_LITTLENUM == 0);
4827
4828
238
      if (target_big_endian)
4829
0
  {
4830
0
    while (nbytes > size)
4831
0
      {
4832
0
        md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4833
0
        nbytes -= CHARS_PER_LITTLENUM;
4834
0
        p += CHARS_PER_LITTLENUM;
4835
0
      }
4836
4837
0
    nums = generic_bignum + size / CHARS_PER_LITTLENUM;
4838
0
    while (size >= CHARS_PER_LITTLENUM)
4839
0
      {
4840
0
        --nums;
4841
0
        md_number_to_chars (p, *nums, CHARS_PER_LITTLENUM);
4842
0
        size -= CHARS_PER_LITTLENUM;
4843
0
        p += CHARS_PER_LITTLENUM;
4844
0
      }
4845
0
  }
4846
238
      else
4847
238
  {
4848
238
    nums = generic_bignum;
4849
1.19k
    while (size >= CHARS_PER_LITTLENUM)
4850
956
      {
4851
956
        md_number_to_chars (p, *nums, CHARS_PER_LITTLENUM);
4852
956
        ++nums;
4853
956
        size -= CHARS_PER_LITTLENUM;
4854
956
        p += CHARS_PER_LITTLENUM;
4855
956
        nbytes -= CHARS_PER_LITTLENUM;
4856
956
      }
4857
4858
526
    while (nbytes >= CHARS_PER_LITTLENUM)
4859
288
      {
4860
288
        md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4861
288
        nbytes -= CHARS_PER_LITTLENUM;
4862
288
        p += CHARS_PER_LITTLENUM;
4863
288
      }
4864
238
  }
4865
238
    }
4866
1.82k
  else
4867
1.82k
    emit_expr_fix (exp, nbytes, frag_now, p, TC_PARSE_CONS_RETURN_NONE);
4868
2.55k
}
4869
4870
void
4871
emit_expr_fix (expressionS *exp, unsigned int nbytes, fragS *frag, char *p,
4872
         TC_PARSE_CONS_RETURN_TYPE r ATTRIBUTE_UNUSED)
4873
1.89k
{
4874
1.89k
  int offset = 0;
4875
1.89k
  unsigned int size = nbytes;
4876
4877
1.89k
  memset (p, 0, size);
4878
4879
  /* Generate a fixS to record the symbol value.  */
4880
4881
1.89k
#ifdef TC_CONS_FIX_NEW
4882
1.89k
  TC_CONS_FIX_NEW (frag, p - frag->fr_literal + offset, size, exp, r);
4883
#else
4884
  if (r != TC_PARSE_CONS_RETURN_NONE)
4885
    {
4886
      reloc_howto_type *reloc_howto;
4887
4888
      reloc_howto = bfd_reloc_type_lookup (stdoutput, r);
4889
      size = bfd_get_reloc_size (reloc_howto);
4890
4891
      if (size > nbytes)
4892
  {
4893
    as_bad (ngettext ("%s relocations do not fit in %u byte",
4894
          "%s relocations do not fit in %u bytes",
4895
          nbytes),
4896
      reloc_howto->name, nbytes);
4897
    return;
4898
  }
4899
      else if (target_big_endian)
4900
  offset = nbytes - size;
4901
    }
4902
  else
4903
    switch (size)
4904
      {
4905
      case 1:
4906
  r = BFD_RELOC_8;
4907
  break;
4908
      case 2:
4909
  r = BFD_RELOC_16;
4910
  break;
4911
      case 3:
4912
  r = BFD_RELOC_24;
4913
  break;
4914
      case 4:
4915
  r = BFD_RELOC_32;
4916
  break;
4917
      case 8:
4918
  r = BFD_RELOC_64;
4919
  break;
4920
      default:
4921
  as_bad (_("unsupported BFD relocation size %u"), size);
4922
  return;
4923
      }
4924
  fix_new_exp (frag, p - frag->fr_literal + offset, size,
4925
         exp, 0, r);
4926
#endif
4927
1.89k
}
4928

4929
/* Handle an MRI style string expression.  */
4930
4931
#ifdef TC_M68K
4932
static void
4933
parse_mri_cons (expressionS *exp, unsigned int nbytes)
4934
{
4935
  if (*input_line_pointer != '\''
4936
      && (input_line_pointer[1] != '\''
4937
    || (*input_line_pointer != 'A'
4938
        && *input_line_pointer != 'E')))
4939
    (void) TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4940
  else
4941
    {
4942
      unsigned int scan;
4943
      unsigned int result = 0;
4944
4945
      /* An MRI style string.  Cut into as many bytes as will fit into
4946
   a nbyte chunk, left justify if necessary, and separate with
4947
   commas so we can try again later.  */
4948
      if (*input_line_pointer == 'A')
4949
  ++input_line_pointer;
4950
      else if (*input_line_pointer == 'E')
4951
  {
4952
    as_bad (_("EBCDIC constants are not supported"));
4953
    ++input_line_pointer;
4954
  }
4955
4956
      input_line_pointer++;
4957
      for (scan = 0; scan < nbytes; scan++)
4958
  {
4959
    if (*input_line_pointer == '\'')
4960
      {
4961
        if (input_line_pointer[1] == '\'')
4962
    {
4963
      input_line_pointer++;
4964
    }
4965
        else
4966
    break;
4967
      }
4968
    result = (result << 8) | (*input_line_pointer++);
4969
  }
4970
4971
      /* Left justify.  */
4972
      while (scan < nbytes)
4973
  {
4974
    result <<= 8;
4975
    scan++;
4976
  }
4977
4978
      /* Create correct expression.  */
4979
      exp->X_op = O_constant;
4980
      exp->X_add_number = result;
4981
4982
      /* Fake it so that we can read the next char too.  */
4983
      if (input_line_pointer[0] != '\'' ||
4984
    (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
4985
  {
4986
    input_line_pointer -= 2;
4987
    input_line_pointer[0] = ',';
4988
    input_line_pointer[1] = '\'';
4989
  }
4990
      else
4991
  input_line_pointer++;
4992
    }
4993
}
4994
#endif /* TC_M68K */
4995

4996
#ifdef REPEAT_CONS_EXPRESSIONS
4997
4998
/* Parse a repeat expression for cons.  This is used by the MIPS
4999
   assembler.  The format is NUMBER:COUNT; NUMBER appears in the
5000
   object file COUNT times.
5001
5002
   To use this for a target, define REPEAT_CONS_EXPRESSIONS.  */
5003
5004
static void
5005
parse_repeat_cons (expressionS *exp, unsigned int nbytes)
5006
{
5007
  expressionS count;
5008
  int i;
5009
5010
  expression (exp);
5011
5012
  if (*input_line_pointer != ':')
5013
    {
5014
      /* No repeat count.  */
5015
      return;
5016
    }
5017
5018
  ++input_line_pointer;
5019
  expression (&count);
5020
  if (count.X_op != O_constant
5021
      || count.X_add_number <= 0)
5022
    {
5023
      as_warn (_("unresolvable or nonpositive repeat count; using 1"));
5024
      return;
5025
    }
5026
5027
  /* The cons function is going to output this expression once.  So we
5028
     output it count - 1 times.  */
5029
  for (i = count.X_add_number - 1; i > 0; i--)
5030
    emit_expr (exp, nbytes);
5031
}
5032
5033
#endif /* REPEAT_CONS_EXPRESSIONS */
5034

5035
/* Parse a floating point number represented as a hex constant.  This
5036
   permits users to specify the exact bits they want in the floating
5037
   point number.  */
5038
5039
static int
5040
hex_float (int float_type, char *bytes)
5041
37
{
5042
37
  int pad, length = float_length (float_type, &pad);
5043
37
  int i;
5044
5045
37
  if (length < 0)
5046
0
    return length;
5047
5048
  /* It would be nice if we could go through expression to parse the
5049
     hex constant, but if we get a bignum it's a pain to sort it into
5050
     the buffer correctly.  */
5051
37
  i = 0;
5052
167
  while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
5053
161
    {
5054
161
      int d;
5055
5056
      /* The MRI assembler accepts arbitrary underscores strewn about
5057
   through the hex constant, so we ignore them as well.  */
5058
161
      if (*input_line_pointer == '_')
5059
0
  {
5060
0
    ++input_line_pointer;
5061
0
    continue;
5062
0
  }
5063
5064
161
      if (i >= length)
5065
31
  {
5066
31
    as_warn (_("floating point constant too large"));
5067
31
    return -1;
5068
31
  }
5069
130
      d = hex_value (*input_line_pointer) << 4;
5070
130
      ++input_line_pointer;
5071
130
      while (*input_line_pointer == '_')
5072
0
  ++input_line_pointer;
5073
130
      if (hex_p (*input_line_pointer))
5074
128
  {
5075
128
    d += hex_value (*input_line_pointer);
5076
128
    ++input_line_pointer;
5077
128
  }
5078
130
      if (target_big_endian)
5079
0
  bytes[i] = d;
5080
130
      else
5081
130
  bytes[length - i - 1] = d;
5082
130
      ++i;
5083
130
    }
5084
5085
6
  if (i < length)
5086
6
    {
5087
6
      if (target_big_endian)
5088
0
  memset (bytes + i, 0, length - i);
5089
6
      else
5090
6
  memset (bytes, 0, length - i);
5091
6
    }
5092
5093
6
  memset (bytes + length, 0, pad);
5094
5095
6
  return length + pad;
5096
37
}
5097
5098
/*      float_cons()
5099
5100
   CONStruct some more frag chars of .floats .ffloats etc.
5101
   Makes 0 or more new frags.
5102
   If need_pass_2 == 1, no frags are emitted.
5103
   This understands only floating literals, not expressions. Sorry.
5104
5105
   A floating constant is defined by atof_generic(), except it is preceded
5106
   by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
5107
   reading, I decided to be incompatible. This always tries to give you
5108
   rounded bits to the precision of the pseudo-op. Former AS did premature
5109
   truncation, restored noisy bits instead of trailing 0s AND gave you
5110
   a choice of 2 flavours of noise according to which of 2 floating-point
5111
   scanners you directed AS to use.
5112
5113
   In:  input_line_pointer->whitespace before, or '0' of flonum.  */
5114
5115
void
5116
float_cons (/* Clobbers input_line-pointer, checks end-of-line.  */
5117
      int float_type  /* 'f':.ffloat ... 'F':.float ...  */)
5118
1.67k
{
5119
1.67k
  char *p;
5120
1.67k
  int length;     /* Number of chars in an object.  */
5121
1.67k
  char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
5122
5123
1.67k
  if (is_it_end_of_statement ())
5124
924
    {
5125
924
      demand_empty_rest_of_line ();
5126
924
      return;
5127
924
    }
5128
5129
755
  if (now_seg == absolute_section)
5130
1
    {
5131
1
      as_bad (_("attempt to store float in absolute section"));
5132
1
      ignore_rest_of_line ();
5133
1
      return;
5134
1
    }
5135
5136
754
  if (in_bss ())
5137
0
    {
5138
0
      as_bad (_("attempt to store float in section `%s'"),
5139
0
        segment_name (now_seg));
5140
0
      ignore_rest_of_line ();
5141
0
      return;
5142
0
    }
5143
5144
#ifdef md_flush_pending_output
5145
  md_flush_pending_output ();
5146
#endif
5147
5148
754
#ifdef md_cons_align
5149
754
  md_cons_align (1);
5150
754
#endif
5151
5152
754
  do
5153
833
    {
5154
833
      length = parse_one_float (float_type, temp);
5155
833
      if (length < 0)
5156
0
  return;
5157
5158
833
      if (!need_pass_2)
5159
833
  {
5160
833
    int count;
5161
5162
833
    count = 1;
5163
5164
#ifdef REPEAT_CONS_EXPRESSIONS
5165
    if (*input_line_pointer == ':')
5166
      {
5167
        expressionS count_exp;
5168
5169
        ++input_line_pointer;
5170
        expression (&count_exp);
5171
5172
        if (count_exp.X_op != O_constant
5173
      || count_exp.X_add_number <= 0)
5174
    as_warn (_("unresolvable or nonpositive repeat count; using 1"));
5175
        else
5176
    count = count_exp.X_add_number;
5177
      }
5178
#endif
5179
833
    if (count == 1)
5180
833
      p = frag_more (length);
5181
0
    else
5182
0
      p = frag_var (rs_fill, length, length, 0, NULL, count, NULL);
5183
833
    memcpy (p, temp, length);
5184
833
  }
5185
833
      SKIP_WHITESPACE ();
5186
833
    }
5187
833
  while (*input_line_pointer++ == ',');
5188
5189
  /* Put terminator back into stream.  */
5190
754
  --input_line_pointer;
5191
754
  demand_empty_rest_of_line ();
5192
754
}
5193

5194
/* LEB128 Encoding.
5195
5196
   Note - we are using the DWARF standard's definition of LEB128 encoding
5197
   where each 7-bit value is a stored in a byte, *not* an octet.  This
5198
   means that on targets where a byte contains multiple octets there is
5199
   a *huge waste of space*.  (This also means that we do not have to
5200
   have special versions of these functions for when OCTETS_PER_BYTE_POWER
5201
   is non-zero).
5202
5203
   If the 7-bit values were to be packed into N-bit bytes (where N > 8)
5204
   we would then have to consider whether multiple, successive LEB128
5205
   values should be packed into the bytes without padding (bad idea) or
5206
   whether each LEB128 number is padded out to a whole number of bytes.
5207
   Plus you have to decide on the endianness of packing octets into a
5208
   byte.  */
5209
5210
/* Return the size of a LEB128 value in bytes.  */
5211
5212
static inline unsigned int
5213
sizeof_sleb128 (offsetT value)
5214
5.19k
{
5215
5.19k
  int size = 0;
5216
5.19k
  unsigned byte;
5217
5218
5.19k
  do
5219
11.7k
    {
5220
11.7k
      byte = (value & 0x7f);
5221
      /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5222
   Fortunately, we can structure things so that the extra work reduces
5223
   to a noop on systems that do things "properly".  */
5224
11.7k
      value = (value >> 7) | ~(-(offsetT)1 >> 7);
5225
11.7k
      size += 1;
5226
11.7k
    }
5227
11.7k
  while (!(((value == 0) && ((byte & 0x40) == 0))
5228
8.89k
     || ((value == -1) && ((byte & 0x40) != 0))));
5229
5230
5.19k
  return size;
5231
5.19k
}
5232
5233
static inline unsigned int
5234
sizeof_uleb128 (valueT value)
5235
5.06k
{
5236
5.06k
  int size = 0;
5237
5238
5.06k
  do
5239
27.4k
    {
5240
27.4k
      value >>= 7;
5241
27.4k
      size += 1;
5242
27.4k
    }
5243
27.4k
  while (value != 0);
5244
5245
5.06k
  return size;
5246
5.06k
}
5247
5248
unsigned int
5249
sizeof_leb128 (valueT value, int sign)
5250
8.27k
{
5251
8.27k
  if (sign)
5252
5.19k
    return sizeof_sleb128 (value);
5253
3.08k
  else
5254
3.08k
    return sizeof_uleb128 (value);
5255
8.27k
}
5256
5257
/* Output a LEB128 value.  Returns the number of bytes used.  */
5258
5259
static inline unsigned int
5260
output_sleb128 (char *p, offsetT value)
5261
4.87k
{
5262
4.87k
  char *orig = p;
5263
4.87k
  int more;
5264
5265
4.87k
  do
5266
11.0k
    {
5267
11.0k
      unsigned byte = (value & 0x7f);
5268
5269
      /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5270
   Fortunately, we can structure things so that the extra work reduces
5271
   to a noop on systems that do things "properly".  */
5272
11.0k
      value = (value >> 7) | ~(-(offsetT)1 >> 7);
5273
5274
11.0k
      more = !((((value == 0) && ((byte & 0x40) == 0))
5275
8.24k
    || ((value == -1) && ((byte & 0x40) != 0))));
5276
11.0k
      if (more)
5277
6.21k
  byte |= 0x80;
5278
5279
11.0k
      *p++ = byte;
5280
11.0k
    }
5281
11.0k
  while (more);
5282
5283
4.87k
  return p - orig;
5284
4.87k
}
5285
5286
static inline unsigned int
5287
output_uleb128 (char *p, valueT value)
5288
2.60k
{
5289
2.60k
  char *orig = p;
5290
5291
2.60k
  do
5292
2.90k
    {
5293
2.90k
      unsigned byte = (value & 0x7f);
5294
5295
2.90k
      value >>= 7;
5296
2.90k
      if (value != 0)
5297
  /* More bytes to follow.  */
5298
294
  byte |= 0x80;
5299
5300
2.90k
      *p++ = byte;
5301
2.90k
    }
5302
2.90k
  while (value != 0);
5303
5304
2.60k
  return p - orig;
5305
2.60k
}
5306
5307
unsigned int
5308
output_leb128 (char *p, valueT value, int sign)
5309
7.47k
{
5310
7.47k
  if (sign)
5311
4.87k
    return output_sleb128 (p, value);
5312
2.60k
  else
5313
2.60k
    return output_uleb128 (p, value);
5314
7.47k
}
5315
5316
/* Do the same for bignums.  We combine sizeof with output here in that
5317
   we don't output for NULL values of P.  It isn't really as critical as
5318
   for "normal" values that this be streamlined.  Returns the number of
5319
   bytes used.  */
5320
5321
static inline unsigned int
5322
output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size)
5323
608
{
5324
608
  char *orig = p;
5325
608
  valueT val = 0;
5326
608
  int loaded = 0;
5327
608
  unsigned byte;
5328
5329
  /* Strip leading sign extensions off the bignum.  */
5330
1.65k
  while (size > 1
5331
1.65k
   && bignum[size - 1] == LITTLENUM_MASK
5332
1.53k
   && bignum[size - 2] > LITTLENUM_MASK / 2)
5333
1.04k
    size--;
5334
5335
608
  do
5336
3.34k
    {
5337
      /* OR in the next part of the littlenum.  */
5338
3.34k
      val |= (*bignum << loaded);
5339
3.34k
      loaded += LITTLENUM_NUMBER_OF_BITS;
5340
3.34k
      size--;
5341
3.34k
      bignum++;
5342
5343
      /* Add bytes until there are less than 7 bits left in VAL
5344
   or until every non-sign bit has been written.  */
5345
3.34k
      do
5346
6.81k
  {
5347
6.81k
    byte = val & 0x7f;
5348
6.81k
    loaded -= 7;
5349
6.81k
    val >>= 7;
5350
6.81k
    if (size > 0
5351
660
        || val != ((byte & 0x40) == 0 ? 0 : ((valueT) 1 << loaded) - 1))
5352
6.25k
      byte |= 0x80;
5353
5354
6.81k
    if (orig)
5355
3.40k
      *p = byte;
5356
6.81k
    p++;
5357
6.81k
  }
5358
6.81k
      while ((byte & 0x80) != 0 && loaded >= 7);
5359
3.34k
    }
5360
3.34k
  while (size > 0);
5361
5362
  /* Mop up any left-over bits (of which there will be less than 7).  */
5363
608
  if ((byte & 0x80) != 0)
5364
50
    {
5365
      /* Sign-extend VAL.  */
5366
50
      if (val & (1 << (loaded - 1)))
5367
36
  val |= ~0U << loaded;
5368
50
      if (orig)
5369
25
  *p = val & 0x7f;
5370
50
      p++;
5371
50
    }
5372
5373
608
  return p - orig;
5374
608
}
5375
5376
static inline unsigned int
5377
output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size)
5378
12
{
5379
12
  char *orig = p;
5380
12
  valueT val = 0;
5381
12
  int loaded = 0;
5382
12
  unsigned byte;
5383
5384
  /* Strip leading zeros off the bignum.  */
5385
  /* XXX: Is this needed?  */
5386
172
  while (size > 0 && bignum[size - 1] == 0)
5387
160
    size--;
5388
5389
12
  do
5390
192
    {
5391
192
      if (loaded < 7 && size > 0)
5392
80
  {
5393
80
    val |= (*bignum << loaded);
5394
80
    loaded += 8 * CHARS_PER_LITTLENUM;
5395
80
    size--;
5396
80
    bignum++;
5397
80
  }
5398
5399
192
      byte = val & 0x7f;
5400
192
      loaded -= 7;
5401
192
      val >>= 7;
5402
5403
192
      if (size > 0 || val)
5404
180
  byte |= 0x80;
5405
5406
192
      if (orig)
5407
96
  *p = byte;
5408
192
      p++;
5409
192
    }
5410
192
  while (byte & 0x80);
5411
5412
12
  return p - orig;
5413
12
}
5414
5415
static unsigned int
5416
output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size, int sign)
5417
620
{
5418
620
  if (sign)
5419
608
    return output_big_sleb128 (p, bignum, size);
5420
12
  else
5421
12
    return output_big_uleb128 (p, bignum, size);
5422
620
}
5423
5424
/* Generate the appropriate fragments for a given expression to emit a
5425
   leb128 value.  SIGN is 1 for sleb, 0 for uleb.  */
5426
5427
void
5428
emit_leb128_expr (expressionS *exp, int sign)
5429
6.89k
{
5430
6.89k
  operatorT op = exp->X_op;
5431
6.89k
  unsigned int nbytes;
5432
5433
6.89k
  if (op == O_absent || op == O_illegal)
5434
2.77k
    {
5435
2.77k
      as_warn (_("zero assumed for missing expression"));
5436
2.77k
      exp->X_add_number = 0;
5437
2.77k
      op = O_constant;
5438
2.77k
    }
5439
4.12k
  else if (op == O_big && exp->X_add_number <= 0)
5440
0
    {
5441
0
      as_bad (_("floating point number invalid"));
5442
0
      exp->X_add_number = 0;
5443
0
      op = O_constant;
5444
0
    }
5445
4.12k
  else if (op == O_register)
5446
0
    {
5447
0
      as_warn (_("register value used as expression"));
5448
0
      op = O_constant;
5449
0
    }
5450
4.12k
  else if (op == O_constant
5451
2.08k
     && sign
5452
2.06k
     && (exp->X_unsigned
5453
2.06k
         ? exp->X_add_number < 0
5454
2.06k
         : (exp->X_add_number < 0) != exp->X_extrabit))
5455
256
    {
5456
      /* We're outputting a signed leb128 and the sign of X_add_number
5457
   doesn't reflect the sign of the original value.  Convert EXP
5458
   to a correctly-extended bignum instead.  */
5459
256
      convert_to_bignum (exp);
5460
256
      op = O_big;
5461
256
    }
5462
5463
6.89k
  if (now_seg == absolute_section)
5464
5
    {
5465
5
      if (op != O_constant || exp->X_add_number != 0)
5466
4
  as_bad (_("attempt to store value in absolute section"));
5467
5
      abs_section_offset++;
5468
5
      return;
5469
5
    }
5470
5471
6.88k
  if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
5472
80
    as_bad (_("attempt to store non-zero value in section `%s'"),
5473
80
      segment_name (now_seg));
5474
5475
  /* Let check_eh_frame know that data is being emitted.  nbytes == -1 is
5476
     a signal that this is leb128 data.  It shouldn't optimize this away.  */
5477
6.88k
  nbytes = -1u;
5478
6.88k
  if (check_eh_frame (exp, &nbytes))
5479
0
    abort ();
5480
5481
  /* Let the backend know that subsequent data may be byte aligned.  */
5482
6.88k
#ifdef md_cons_align
5483
6.88k
  md_cons_align (1);
5484
6.88k
#endif
5485
5486
6.88k
  if (op == O_constant)
5487
4.59k
    {
5488
      /* If we've got a constant, emit the thing directly right now.  */
5489
5490
4.59k
      valueT value = exp->X_add_number;
5491
4.59k
      unsigned int size;
5492
4.59k
      char *p;
5493
5494
4.59k
      size = sizeof_leb128 (value, sign);
5495
4.59k
      p = frag_more (size);
5496
4.59k
      if (output_leb128 (p, value, sign) > size)
5497
0
  abort ();
5498
4.59k
    }
5499
2.29k
  else if (op == O_big)
5500
310
    {
5501
      /* O_big is a different sort of constant.  */
5502
310
      int nbr_digits = exp->X_add_number;
5503
310
      unsigned int size;
5504
310
      char *p;
5505
5506
      /* If the leading littenum is 0xffff, prepend a 0 to avoid confusion with
5507
   a signed number.  Unary operators like - or ~ always extend the
5508
   bignum to its largest size.  */
5509
310
      if (exp->X_unsigned
5510
28
    && nbr_digits < SIZE_OF_LARGE_NUMBER
5511
17
    && generic_bignum[nbr_digits - 1] == LITTLENUM_MASK)
5512
4
  generic_bignum[nbr_digits++] = 0;
5513
5514
310
      size = output_big_leb128 (NULL, generic_bignum, nbr_digits, sign);
5515
310
      p = frag_more (size);
5516
310
      if (output_big_leb128 (p, generic_bignum, nbr_digits, sign) > size)
5517
0
  abort ();
5518
310
    }
5519
1.98k
  else
5520
1.98k
    {
5521
      /* Otherwise, we have to create a variable sized fragment and
5522
   resolve things later.  */
5523
5524
1.98k
      frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
5525
1.98k
    make_expr_symbol (exp), 0, NULL);
5526
1.98k
    }
5527
6.88k
}
5528
5529
/* Parse the .sleb128 and .uleb128 pseudos.  */
5530
5531
void
5532
s_leb128 (int sign)
5533
2.31k
{
5534
2.31k
  expressionS exp;
5535
5536
#ifdef md_flush_pending_output
5537
  md_flush_pending_output ();
5538
#endif
5539
5540
2.31k
  do
5541
6.85k
    {
5542
6.85k
      expression (&exp);
5543
6.85k
      emit_leb128_expr (&exp, sign);
5544
6.85k
    }
5545
6.85k
  while (*input_line_pointer++ == ',');
5546
5547
2.31k
  input_line_pointer--;
5548
2.31k
  demand_empty_rest_of_line ();
5549
2.31k
}
5550

5551
#if defined (TE_PE) && defined (O_secrel)
5552
5553
/* Generate the appropriate fragments for a given expression to emit a
5554
   cv_comp value.  SIGN is 1 for cv_scomp, 0 for cv_ucomp.  */
5555
5556
static void
5557
emit_cv_comp_expr (expressionS *exp, int sign)
5558
{
5559
  operatorT op = exp->X_op;
5560
5561
  if (op == O_absent || op == O_illegal)
5562
    {
5563
      as_warn (_("zero assumed for missing expression"));
5564
      exp->X_add_number = 0;
5565
      op = O_constant;
5566
    }
5567
  else if (op == O_big)
5568
    {
5569
      as_bad (_("number invalid"));
5570
      exp->X_add_number = 0;
5571
      op = O_constant;
5572
    }
5573
  else if (op == O_register)
5574
    {
5575
      as_warn (_("register value used as expression"));
5576
      op = O_constant;
5577
    }
5578
5579
  if (now_seg == absolute_section)
5580
    {
5581
      if (op != O_constant || exp->X_add_number != 0)
5582
  as_bad (_("attempt to store value in absolute section"));
5583
      abs_section_offset++;
5584
      return;
5585
    }
5586
5587
  if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
5588
    as_bad (_("attempt to store non-zero value in section `%s'"),
5589
      segment_name (now_seg));
5590
5591
  /* Let the backend know that subsequent data may be byte aligned.  */
5592
#ifdef md_cons_align
5593
  md_cons_align (1);
5594
#endif
5595
5596
  if (op == O_constant)
5597
    {
5598
      offsetT value = exp->X_add_number;
5599
      unsigned int size;
5600
      char *p;
5601
5602
      /* If we've got a constant, emit the thing directly right now.  */
5603
5604
      size = sizeof_cv_comp (value, sign);
5605
      p = frag_more (size);
5606
      if (output_cv_comp (p, value, sign) > size)
5607
  abort ();
5608
    }
5609
  else
5610
    {
5611
      /* Otherwise, we have to create a variable sized fragment and
5612
   resolve things later.  */
5613
5614
      frag_var (rs_cv_comp, 4, 0, sign, make_expr_symbol (exp), 0, NULL);
5615
    }
5616
}
5617
5618
/* Parse the .cv_ucomp and .cv_scomp pseudos.  */
5619
5620
static void
5621
s_cv_comp (int sign)
5622
{
5623
  expressionS exp;
5624
5625
#ifdef md_flush_pending_output
5626
  md_flush_pending_output ();
5627
#endif
5628
5629
  do
5630
    {
5631
      expression (&exp);
5632
      emit_cv_comp_expr (&exp, sign);
5633
    }
5634
  while (*input_line_pointer++ == ',');
5635
5636
  input_line_pointer--;
5637
  demand_empty_rest_of_line ();
5638
}
5639
5640
#endif /* TE_PE && O_secrel */
5641
5642
/* Code for handling base64 encoded strings.
5643
   Based upon code in sharutils' lib/base64.c source file, written by
5644
   Simon Josefsson.  Which was partially adapted from GNU MailUtils
5645
   (mailbox/filter_trans.c, as of 2004-11-28) and improved by review
5646
   from Paul Eggert, Bruno Haible, and Stepan Kasal.  */
5647
5648
#define B64(_)           \
5649
  (  (_) == 'A' ? 0      \
5650
   : (_) == 'B' ? 1      \
5651
   : (_) == 'C' ? 2      \
5652
   : (_) == 'D' ? 3      \
5653
   : (_) == 'E' ? 4      \
5654
   : (_) == 'F' ? 5      \
5655
   : (_) == 'G' ? 6      \
5656
   : (_) == 'H' ? 7      \
5657
   : (_) == 'I' ? 8      \
5658
   : (_) == 'J' ? 9      \
5659
   : (_) == 'K' ? 10     \
5660
   : (_) == 'L' ? 11     \
5661
   : (_) == 'M' ? 12     \
5662
   : (_) == 'N' ? 13     \
5663
   : (_) == 'O' ? 14     \
5664
   : (_) == 'P' ? 15     \
5665
   : (_) == 'Q' ? 16     \
5666
   : (_) == 'R' ? 17     \
5667
   : (_) == 'S' ? 18     \
5668
   : (_) == 'T' ? 19     \
5669
   : (_) == 'U' ? 20     \
5670
   : (_) == 'V' ? 21     \
5671
   : (_) == 'W' ? 22     \
5672
   : (_) == 'X' ? 23     \
5673
   : (_) == 'Y' ? 24     \
5674
   : (_) == 'Z' ? 25     \
5675
   : (_) == 'a' ? 26     \
5676
   : (_) == 'b' ? 27     \
5677
   : (_) == 'c' ? 28     \
5678
   : (_) == 'd' ? 29     \
5679
   : (_) == 'e' ? 30     \
5680
   : (_) == 'f' ? 31     \
5681
   : (_) == 'g' ? 32     \
5682
   : (_) == 'h' ? 33     \
5683
   : (_) == 'i' ? 34     \
5684
   : (_) == 'j' ? 35     \
5685
   : (_) == 'k' ? 36     \
5686
   : (_) == 'l' ? 37     \
5687
   : (_) == 'm' ? 38     \
5688
   : (_) == 'n' ? 39     \
5689
   : (_) == 'o' ? 40     \
5690
   : (_) == 'p' ? 41     \
5691
   : (_) == 'q' ? 42     \
5692
   : (_) == 'r' ? 43     \
5693
   : (_) == 's' ? 44     \
5694
   : (_) == 't' ? 45     \
5695
   : (_) == 'u' ? 46     \
5696
   : (_) == 'v' ? 47     \
5697
   : (_) == 'w' ? 48     \
5698
   : (_) == 'x' ? 49     \
5699
   : (_) == 'y' ? 50     \
5700
   : (_) == 'z' ? 51     \
5701
   : (_) == '0' ? 52     \
5702
   : (_) == '1' ? 53     \
5703
   : (_) == '2' ? 54     \
5704
   : (_) == '3' ? 55     \
5705
   : (_) == '4' ? 56     \
5706
   : (_) == '5' ? 57     \
5707
   : (_) == '6' ? 58     \
5708
   : (_) == '7' ? 59     \
5709
   : (_) == '8' ? 60     \
5710
   : (_) == '9' ? 61     \
5711
   : (_) == '+' ? 62     \
5712
   : (_) == '/' ? 63     \
5713
   : -1)
5714
5715
static const signed char b64[0x100] =
5716
{
5717
  B64 (0),   B64 (1),   B64 (2),   B64 (3),
5718
  B64 (4),   B64 (5),   B64 (6),   B64 (7),
5719
  B64 (8),   B64 (9),   B64 (10),  B64 (11),
5720
  B64 (12),  B64 (13),  B64 (14),  B64 (15),
5721
  B64 (16),  B64 (17),  B64 (18),  B64 (19),
5722
  B64 (20),  B64 (21),  B64 (22),  B64 (23),
5723
  B64 (24),  B64 (25),  B64 (26),  B64 (27),
5724
  B64 (28),  B64 (29),  B64 (30),  B64 (31),
5725
  B64 (32),  B64 (33),  B64 (34),  B64 (35),
5726
  B64 (36),  B64 (37),  B64 (38),  B64 (39),
5727
  B64 (40),  B64 (41),  B64 (42),  B64 (43),
5728
  B64 (44),  B64 (45),  B64 (46),  B64 (47),
5729
  B64 (48),  B64 (49),  B64 (50),  B64 (51),
5730
  B64 (52),  B64 (53),  B64 (54),  B64 (55),
5731
  B64 (56),  B64 (57),  B64 (58),  B64 (59),
5732
  B64 (60),  B64 (61),  B64 (62),  B64 (63),
5733
  B64 (64),  B64 (65),  B64 (66),  B64 (67),
5734
  B64 (68),  B64 (69),  B64 (70),  B64 (71),
5735
  B64 (72),  B64 (73),  B64 (74),  B64 (75),
5736
  B64 (76),  B64 (77),  B64 (78),  B64 (79),
5737
  B64 (80),  B64 (81),  B64 (82),  B64 (83),
5738
  B64 (84),  B64 (85),  B64 (86),  B64 (87),
5739
  B64 (88),  B64 (89),  B64 (90),  B64 (91),
5740
  B64 (92),  B64 (93),  B64 (94),  B64 (95),
5741
  B64 (96),  B64 (97),  B64 (98),  B64 (99),
5742
  B64 (100), B64 (101), B64 (102), B64 (103),
5743
  B64 (104), B64 (105), B64 (106), B64 (107),
5744
  B64 (108), B64 (109), B64 (110), B64 (111),
5745
  B64 (112), B64 (113), B64 (114), B64 (115),
5746
  B64 (116), B64 (117), B64 (118), B64 (119),
5747
  B64 (120), B64 (121), B64 (122), B64 (123),
5748
  B64 (124), B64 (125), B64 (126), B64 (127),
5749
  B64 (128), B64 (129), B64 (130), B64 (131),
5750
  B64 (132), B64 (133), B64 (134), B64 (135),
5751
  B64 (136), B64 (137), B64 (138), B64 (139),
5752
  B64 (140), B64 (141), B64 (142), B64 (143),
5753
  B64 (144), B64 (145), B64 (146), B64 (147),
5754
  B64 (148), B64 (149), B64 (150), B64 (151),
5755
  B64 (152), B64 (153), B64 (154), B64 (155),
5756
  B64 (156), B64 (157), B64 (158), B64 (159),
5757
  B64 (160), B64 (161), B64 (162), B64 (163),
5758
  B64 (164), B64 (165), B64 (166), B64 (167),
5759
  B64 (168), B64 (169), B64 (170), B64 (171),
5760
  B64 (172), B64 (173), B64 (174), B64 (175),
5761
  B64 (176), B64 (177), B64 (178), B64 (179),
5762
  B64 (180), B64 (181), B64 (182), B64 (183),
5763
  B64 (184), B64 (185), B64 (186), B64 (187),
5764
  B64 (188), B64 (189), B64 (190), B64 (191),
5765
  B64 (192), B64 (193), B64 (194), B64 (195),
5766
  B64 (196), B64 (197), B64 (198), B64 (199),
5767
  B64 (200), B64 (201), B64 (202), B64 (203),
5768
  B64 (204), B64 (205), B64 (206), B64 (207),
5769
  B64 (208), B64 (209), B64 (210), B64 (211),
5770
  B64 (212), B64 (213), B64 (214), B64 (215),
5771
  B64 (216), B64 (217), B64 (218), B64 (219),
5772
  B64 (220), B64 (221), B64 (222), B64 (223),
5773
  B64 (224), B64 (225), B64 (226), B64 (227),
5774
  B64 (228), B64 (229), B64 (230), B64 (231),
5775
  B64 (232), B64 (233), B64 (234), B64 (235),
5776
  B64 (236), B64 (237), B64 (238), B64 (239),
5777
  B64 (240), B64 (241), B64 (242), B64 (243),
5778
  B64 (244), B64 (245), B64 (246), B64 (247),
5779
  B64 (248), B64 (249), B64 (250), B64 (251),
5780
  B64 (252), B64 (253), B64 (254), B64 (255)
5781
};
5782
5783
static bool
5784
is_base64_char (unsigned int c)
5785
428
{
5786
428
  return (c < 0x100) && (b64[c] != -1);
5787
428
}
5788
5789
static void
5790
decode_base64_and_append (unsigned int b[4], int len)
5791
86
{
5792
86
  gas_assert (len > 1);
5793
5794
86
  FRAG_APPEND_1_CHAR ((b64[b[0]] << 2) | (b64[b[1]] >> 4));
5795
5796
86
  if (len == 2)
5797
0
    return; /* FIXME: Check for unused bits in b[1] ?  */
5798
5799
86
  FRAG_APPEND_1_CHAR (((b64[b[1]] << 4) & 0xf0) | (b64[b[2]] >> 2));
5800
5801
86
  if (len == 3)
5802
12
    return; /* FIXME: Check for unused bits in b[2] ?  */
5803
5804
74
  FRAG_APPEND_1_CHAR (((b64[b[2]] << 6) & 0xc0) | b64[b[3]]);
5805
74
}
5806
5807
/* Accept one or more comma separated, base64 encoded strings.  Decode them
5808
   and store them at the current point in the current section.  The strings
5809
   must be enclosed in double quotes.  Line breaks, quoted characters and
5810
   escaped characters are not allowed.  Only the characters "A-Za-z0-9+/" are
5811
   accepted inside the string.  The string must be a multiple of four
5812
   characters in length.  If the encoded string does not fit this requirement
5813
   it may use one or more '=' characters at the end as padding.  */
5814
5815
void
5816
s_base64 (int dummy ATTRIBUTE_UNUSED)
5817
43
{
5818
43
  unsigned int c;
5819
43
  unsigned long num_octets = 0;
5820
5821
  /* If we have been switched into the abs_section then we
5822
     will not have an obstack onto which we can hang strings.  */
5823
43
  if (now_seg == absolute_section)
5824
10
    {
5825
10
      as_bad (_("base64 strings must be placed into a section"));
5826
10
      ignore_rest_of_line ();
5827
10
      return;
5828
10
    }
5829
5830
33
  if (is_it_end_of_statement ())
5831
0
    {
5832
0
      as_bad (_("a string must follow the .base64 pseudo-op"));
5833
0
      return;
5834
0
    }
5835
5836
#ifdef md_flush_pending_output
5837
  md_flush_pending_output ();
5838
#endif
5839
5840
33
#ifdef md_cons_align
5841
33
  md_cons_align (1);
5842
33
#endif
5843
5844
33
  do
5845
33
    {
5846
33
      SKIP_ALL_WHITESPACE ();
5847
5848
33
      c = * input_line_pointer ++;
5849
5850
33
      if (c != '"')
5851
0
  {
5852
0
    as_bad (_("expected double quote enclosed string as argument to .base64 pseudo-op"));
5853
0
    ignore_rest_of_line ();
5854
0
    return;
5855
0
  }
5856
5857
      /* Read a block of four base64 encoded characters.  */
5858
33
      int i;
5859
33
      unsigned int b[4];
5860
33
      bool seen_equals = false;
5861
5862
105
    loop:
5863
457
      for (i = 0; i < 4; i++)
5864
372
        {
5865
372
    c = * input_line_pointer ++;
5866
5867
372
    if (c >= 256 || is_end_of_stmt (c))
5868
8
      {
5869
8
        as_bad (_("end of line encountered inside .base64 string"));
5870
8
        ignore_rest_of_line ();
5871
8
        return;
5872
8
      }
5873
5874
364
    if (c == '"')
5875
11
      {
5876
        /* We allow this.  But only if there were enough
5877
     characters to form a valid base64 encoding.  */
5878
11
        if (i > 1)
5879
1
    {
5880
1
      as_warn (_(".base64 string terminated early"));
5881
1
      -- input_line_pointer;
5882
1
      break;
5883
1
    }
5884
5885
10
        as_bad (_(".base64 string terminated unexpectedly"));
5886
10
        ignore_rest_of_line ();
5887
10
        return;
5888
11
      }
5889
5890
353
    if (seen_equals && c != '=')
5891
0
      {
5892
0
        as_bad (_("equals character only allowed at end of .base64 string"));
5893
0
        ignore_rest_of_line ();
5894
0
        return;
5895
0
      }
5896
5897
353
    if (c == '=')
5898
11
      {
5899
11
        if (i == 0)
5900
0
    {
5901
0
      as_bad (_("the equals character cannot start a block of four base64 encoded bytes"));
5902
0
      ignore_rest_of_line ();
5903
0
      return;
5904
0
    }
5905
11
        else if (i == 1)
5906
0
    {
5907
0
      as_bad (_("the equals character cannot be the second character in a block of four base64 encoded bytes"));
5908
0
      ignore_rest_of_line ();
5909
0
      return;
5910
0
    }
5911
5912
11
        seen_equals = true;
5913
11
      }
5914
342
    else if (! is_base64_char (c))
5915
1
      {
5916
1
        if (ISPRINT (c))
5917
1
    as_bad (_("invalid character '%c' found inside .base64 string"), c);
5918
0
        else
5919
0
    as_bad (_("invalid character %#x found inside .base64 string"), c);
5920
1
        ignore_rest_of_line ();
5921
1
        return;
5922
1
      }
5923
5924
352
    b[i] = c;
5925
352
  }
5926
5927
86
      if (seen_equals && i == 4)
5928
11
  {
5929
11
    -- i;
5930
11
    if (b[2] == '=')
5931
0
      -- i;
5932
11
  }
5933
5934
      /* We have a block of up to four valid base64 encoded bytes.  */
5935
86
      decode_base64_and_append (b, i);
5936
86
      num_octets += (i - 1);
5937
5938
      /* Check the next character.  */
5939
86
      c = * input_line_pointer ++;
5940
5941
86
      if (is_base64_char (c))
5942
72
  {
5943
72
    if (seen_equals)
5944
0
      {
5945
0
        as_bad (_("no base64 characters expected after '=' padding characters"));
5946
0
        ignore_rest_of_line ();
5947
0
        return;
5948
0
      }
5949
5950
72
    -- input_line_pointer;
5951
72
    goto loop;
5952
72
  }
5953
14
      else if (c != '"')
5954
13
  {
5955
13
    as_bad (_(".base64 string must have a terminating double quote character"));
5956
13
    ignore_rest_of_line ();
5957
13
    return;
5958
13
  }
5959
5960
1
      SKIP_ALL_WHITESPACE ();
5961
      
5962
1
      c = * input_line_pointer ++;
5963
1
    }
5964
33
  while (c == ',');
5965
5966
  /* Make sure that we have not skipped the EOL marker.  */
5967
1
  -- input_line_pointer;
5968
5969
1
  while (num_octets % OCTETS_PER_BYTE)
5970
0
    {
5971
      /* We have finished emiting the octets for this .base64 pseudo-op, but
5972
   we have not filled up enough bytes for the target architecture.  So
5973
   we emit padding octets here.  This is done after all of the arguments
5974
   to the pseudo-op have been processed, rather than at the end of each
5975
   argument, as it is likely that the user wants the arguments to be
5976
   contiguous.  */
5977
0
      FRAG_APPEND_1_CHAR (0);
5978
0
      ++ num_octets;
5979
0
    }
5980
5981
1
  demand_empty_rest_of_line ();
5982
1
}
5983
5984
static void
5985
stringer_append_char (int c, int bitsize)
5986
5.70k
{
5987
5.70k
  if (c && in_bss ())
5988
0
    as_bad (_("attempt to store non-empty string in section `%s'"),
5989
0
      segment_name (now_seg));
5990
5991
5.70k
  if (!target_big_endian)
5992
5.70k
    FRAG_APPEND_1_CHAR (c);
5993
5994
5.70k
  switch (bitsize)
5995
5.70k
    {
5996
227
    case 64:
5997
227
      FRAG_APPEND_1_CHAR (0);
5998
227
      FRAG_APPEND_1_CHAR (0);
5999
227
      FRAG_APPEND_1_CHAR (0);
6000
227
      FRAG_APPEND_1_CHAR (0);
6001
      /* Fall through.  */
6002
227
    case 32:
6003
227
      FRAG_APPEND_1_CHAR (0);
6004
227
      FRAG_APPEND_1_CHAR (0);
6005
      /* Fall through.  */
6006
229
    case 16:
6007
229
      FRAG_APPEND_1_CHAR (0);
6008
      /* Fall through.  */
6009
5.70k
    case 8:
6010
5.70k
      break;
6011
0
    default:
6012
      /* Called with invalid bitsize argument.  */
6013
0
      abort ();
6014
0
      break;
6015
5.70k
    }
6016
5.70k
  if (target_big_endian)
6017
0
    FRAG_APPEND_1_CHAR (c);
6018
5.70k
}
6019
6020
/* Worker to do .ascii etc statements.
6021
   Reads 0 or more ',' separated, double-quoted strings.
6022
   Caller should have checked need_pass_2 is FALSE because we don't
6023
   check it.
6024
   Checks for end-of-line.
6025
   BITS_APPENDZERO says how many bits are in a target char.
6026
   The bottom bit is set if a NUL char should be appended to the strings.  */
6027
6028
void
6029
stringer (int bits_appendzero)
6030
2.02k
{
6031
2.02k
  const int bitsize = bits_appendzero & ~7;
6032
2.02k
  const int append_zero = bits_appendzero & 1;
6033
2.02k
  unsigned int c;
6034
2.02k
#if !defined(NO_LISTING) && defined (OBJ_ELF)
6035
2.02k
  char *start;
6036
2.02k
#endif
6037
6038
#ifdef md_flush_pending_output
6039
  md_flush_pending_output ();
6040
#endif
6041
6042
2.02k
#ifdef md_cons_align
6043
2.02k
  md_cons_align (1);
6044
2.02k
#endif
6045
6046
  /* If we have been switched into the abs_section then we
6047
     will not have an obstack onto which we can hang strings.  */
6048
2.02k
  if (now_seg == absolute_section)
6049
269
    {
6050
269
      as_bad (_("strings must be placed into a section"));
6051
269
      ignore_rest_of_line ();
6052
269
      return;
6053
269
    }
6054
6055
  /* The following awkward logic is to parse ZERO or more strings,
6056
     comma separated. Recall a string expression includes spaces
6057
     before the opening '\"' and spaces after the closing '\"'.
6058
     We fake a leading ',' if there is (supposed to be)
6059
     a 1st, expression. We keep demanding expressions for each ','.  */
6060
1.75k
  if (is_it_end_of_statement ())
6061
0
    {
6062
0
      c = 0;      /* Skip loop.  */
6063
0
      ++input_line_pointer; /* Compensate for end of loop.  */
6064
0
    }
6065
1.75k
  else
6066
1.75k
    {
6067
1.75k
      c = ',';      /* Do loop.  */
6068
1.75k
    }
6069
6070
3.29k
  while (c == ',' || c == '<' || c == '"')
6071
2.95k
    {
6072
2.95k
      SKIP_WHITESPACE ();
6073
2.95k
      switch (*input_line_pointer)
6074
2.95k
  {
6075
76
  case '\"':
6076
76
    ++input_line_pointer; /*->1st char of string.  */
6077
76
#if !defined(NO_LISTING) && defined (OBJ_ELF)
6078
76
    start = input_line_pointer;
6079
76
#endif
6080
6081
4.29k
    while (is_a_char (c = next_char_of_string ()))
6082
4.22k
      stringer_append_char (c, bitsize);
6083
6084
    /* Treat "a" "b" as "ab".  Even if we are appending zeros.  */
6085
76
    SKIP_ALL_WHITESPACE ();
6086
76
    if (*input_line_pointer == '"')
6087
0
      break;
6088
6089
76
    if (append_zero)
6090
76
      stringer_append_char (0, bitsize);
6091
6092
76
#if !defined(NO_LISTING) && defined (OBJ_ELF)
6093
    /* In ELF, when gcc is emitting DWARF 1 debugging output, it
6094
       will emit .string with a filename in the .debug section
6095
       after a sequence of constants.  See the comment in
6096
       emit_expr for the sequence.  emit_expr will set
6097
       dwarf_file_string to non-zero if this string might be a
6098
       source file name.  */
6099
76
    if (strcmp (segment_name (now_seg), ".debug") != 0)
6100
76
      dwarf_file_string = 0;
6101
0
    else if (dwarf_file_string)
6102
0
      {
6103
0
        c = input_line_pointer[-1];
6104
0
        input_line_pointer[-1] = '\0';
6105
0
        listing_source_file (start);
6106
0
        input_line_pointer[-1] = c;
6107
0
      }
6108
76
#endif
6109
6110
76
    break;
6111
1.41k
  case '<':
6112
1.41k
    input_line_pointer++;
6113
1.41k
    offsetT n = get_single_number ();
6114
1.41k
    if (n != (unsigned char) n)
6115
5
      {
6116
5
        as_bad (_("<nn> out of range"));
6117
5
        ignore_rest_of_line ();
6118
5
        return;
6119
5
      }
6120
1.41k
    stringer_append_char (n, bitsize);
6121
1.41k
    if (*input_line_pointer != '>')
6122
1.41k
      {
6123
1.41k
        as_bad (_("expected <nn>"));
6124
1.41k
        ignore_rest_of_line ();
6125
1.41k
        return;
6126
1.41k
      }
6127
0
    input_line_pointer++;
6128
0
    break;
6129
1.21k
  case ',':
6130
1.21k
    input_line_pointer++;
6131
1.21k
    break;
6132
2.95k
  }
6133
1.54k
      SKIP_WHITESPACE ();
6134
1.54k
      c = *input_line_pointer;
6135
1.54k
    }
6136
6137
337
  demand_empty_rest_of_line ();
6138
337
}
6139

6140
/* FIXME-SOMEDAY: I had trouble here on characters with the
6141
    high bits set.  We'll probably also have trouble with
6142
    multibyte chars, wide chars, etc.  Also be careful about
6143
    returning values bigger than 1 byte.  xoxorich.  */
6144
6145
unsigned int
6146
next_char_of_string (void)
6147
50.6M
{
6148
50.6M
  unsigned int c;
6149
6150
50.6M
  c = *input_line_pointer++ & CHAR_MASK;
6151
50.6M
  switch (c)
6152
50.6M
    {
6153
336
    case 0:
6154
      /* PR 20902: Do not advance past the end of the buffer.  */
6155
336
      -- input_line_pointer;
6156
336
      c = NOT_A_CHAR;
6157
336
      break;
6158
6159
161k
    case '\"':
6160
161k
      c = NOT_A_CHAR;
6161
161k
      break;
6162
6163
177k
    case '\n':
6164
177k
      as_warn (_("unterminated string; newline inserted"));
6165
177k
      bump_line_counters ();
6166
177k
      break;
6167
6168
12.0M
    case '\\':
6169
12.0M
      if (!TC_STRING_ESCAPES)
6170
0
  break;
6171
12.0M
      switch (c = *input_line_pointer++ & CHAR_MASK)
6172
12.0M
  {
6173
11
  case 'b':
6174
11
    c = '\b';
6175
11
    break;
6176
6177
0
  case 'f':
6178
0
    c = '\f';
6179
0
    break;
6180
6181
0
  case 'n':
6182
0
    c = '\n';
6183
0
    break;
6184
6185
1
  case 'r':
6186
1
    c = '\r';
6187
1
    break;
6188
6189
0
  case 't':
6190
0
    c = '\t';
6191
0
    break;
6192
6193
0
  case 'v':
6194
0
    c = '\013';
6195
0
    break;
6196
6197
1.96M
  case '\\':
6198
1.96M
  case '"':
6199
1.96M
    break;    /* As itself.  */
6200
6201
0
  case '0':
6202
1
  case '1':
6203
1
  case '2':
6204
3
  case '3':
6205
3
  case '4':
6206
3
  case '5':
6207
5
  case '6':
6208
5
  case '7':
6209
7
  case '8':
6210
7
  case '9':
6211
7
    {
6212
7
      unsigned number;
6213
7
      int i;
6214
6215
7
      for (i = 0, number = 0;
6216
20
     ISDIGIT (c) && i < 3;
6217
13
     c = *input_line_pointer++, i++)
6218
13
        {
6219
13
    number = number * 8 + c - '0';
6220
13
        }
6221
6222
7
      c = number & CHAR_MASK;
6223
7
    }
6224
7
    --input_line_pointer;
6225
7
    break;
6226
6227
0
  case 'x':
6228
4
  case 'X':
6229
4
    {
6230
4
      unsigned number;
6231
6232
4
      number = 0;
6233
4
      c = *input_line_pointer++;
6234
4
      while (ISXDIGIT (c))
6235
0
        {
6236
0
    if (ISDIGIT (c))
6237
0
      number = number * 16 + c - '0';
6238
0
    else if (ISUPPER (c))
6239
0
      number = number * 16 + c - 'A' + 10;
6240
0
    else
6241
0
      number = number * 16 + c - 'a' + 10;
6242
0
    c = *input_line_pointer++;
6243
0
        }
6244
4
      c = number & CHAR_MASK;
6245
4
      --input_line_pointer;
6246
4
    }
6247
4
    break;
6248
6249
0
  case '\n':
6250
    /* To be compatible with BSD 4.2 as: give the luser a linefeed!!  */
6251
0
    as_warn (_("unterminated string; newline inserted"));
6252
0
    c = '\n';
6253
0
    bump_line_counters ();
6254
0
    break;
6255
6256
0
  case 0:
6257
    /* Do not advance past the end of the buffer.  */
6258
0
    -- input_line_pointer;
6259
0
    c = NOT_A_CHAR;
6260
0
    break;
6261
6262
10.0M
  default:
6263
6264
#ifdef ONLY_STANDARD_ESCAPES
6265
    as_bad (_("bad escaped character in string"));
6266
    c = '?';
6267
#endif /* ONLY_STANDARD_ESCAPES */
6268
6269
10.0M
    break;
6270
12.0M
  }
6271
12.0M
      break;
6272
6273
38.2M
    default:
6274
38.2M
      break;
6275
50.6M
    }
6276
50.6M
  return (c);
6277
50.6M
}
6278

6279
static segT
6280
get_segmented_expression (expressionS *expP)
6281
1.23k
{
6282
1.23k
  segT retval;
6283
6284
1.23k
  retval = expression (expP);
6285
1.23k
  if (expP->X_op == O_illegal
6286
1.23k
      || expP->X_op == O_absent
6287
1.08k
      || expP->X_op == O_big)
6288
336
    {
6289
336
      as_bad (_("expected address expression"));
6290
336
      expP->X_op = O_constant;
6291
336
      expP->X_add_number = 0;
6292
336
      retval = absolute_section;
6293
336
    }
6294
1.23k
  return retval;
6295
1.23k
}
6296
6297
static segT
6298
get_known_segmented_expression (expressionS *expP)
6299
1.23k
{
6300
1.23k
  segT retval = get_segmented_expression (expP);
6301
6302
1.23k
  if (retval == undefined_section)
6303
574
    {
6304
      /* There is no easy way to extract the undefined symbol from the
6305
   expression.  */
6306
574
      if (expP->X_add_symbol != NULL
6307
574
    && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
6308
565
  as_warn (_("symbol \"%s\" undefined; zero assumed"),
6309
565
     S_GET_NAME (expP->X_add_symbol));
6310
9
      else
6311
9
  as_warn (_("some symbol undefined; zero assumed"));
6312
574
      retval = absolute_section;
6313
574
      expP->X_op = O_constant;
6314
574
      expP->X_add_number = 0;
6315
574
    }
6316
1.23k
  return retval;
6317
1.23k
}
6318
6319
char        /* Return terminator.  */
6320
get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression.  */)
6321
0
{
6322
  /* FIXME: val_pointer should probably be offsetT *.  */
6323
0
  *val_pointer = get_absolute_expression ();
6324
0
  return (*input_line_pointer++);
6325
0
}
6326

6327
/* Like demand_copy_string, but return NULL if the string contains any '\0's.
6328
   Give a warning if that happens.  */
6329
6330
char *
6331
demand_copy_C_string (int *len_pointer)
6332
9.29k
{
6333
9.29k
  char *s;
6334
6335
9.29k
  if ((s = demand_copy_string (len_pointer)) != 0)
6336
9.09k
    {
6337
9.09k
      int len;
6338
6339
519k
      for (len = *len_pointer; len > 0; len--)
6340
510k
  {
6341
510k
    if (s[len - 1] == 0)
6342
4
      {
6343
4
        s = 0;
6344
4
        *len_pointer = 0;
6345
4
        as_bad (_("this string may not contain \'\\0\'"));
6346
4
        break;
6347
4
      }
6348
510k
  }
6349
9.09k
    }
6350
6351
9.29k
  return s;
6352
9.29k
}
6353

6354
/* Demand string, but return a safe (=private) copy of the string.
6355
   Return NULL if we can't read a string here.  */
6356
6357
char *
6358
demand_copy_string (int *lenP)
6359
161k
{
6360
161k
  unsigned int c;
6361
161k
  int len;
6362
161k
  char *retval;
6363
6364
161k
  len = 0;
6365
161k
  SKIP_WHITESPACE ();
6366
161k
  if (*input_line_pointer == '\"')
6367
161k
    {
6368
161k
      input_line_pointer++; /* Skip opening quote.  */
6369
6370
50.6M
      while (is_a_char (c = next_char_of_string ()))
6371
50.4M
  {
6372
50.4M
    obstack_1grow (&notes, c);
6373
50.4M
    len++;
6374
50.4M
  }
6375
      /* JF this next line is so demand_copy_C_string will return a
6376
   null terminated string.  */
6377
161k
      obstack_1grow (&notes, '\0');
6378
161k
      retval = obstack_finish (&notes);
6379
161k
    }
6380
205
  else
6381
205
    {
6382
205
      as_bad (_("missing string"));
6383
205
      retval = NULL;
6384
205
      ignore_rest_of_line ();
6385
205
    }
6386
161k
  *lenP = len;
6387
161k
  return retval;
6388
161k
}
6389

6390
/* In:  Input_line_pointer->next character.
6391
6392
   Do:  Skip input_line_pointer over all whitespace.
6393
6394
   Out: 1 if input_line_pointer->end-of-line.  */
6395
6396
int
6397
is_it_end_of_statement (void)
6398
3.96k
{
6399
3.96k
  SKIP_WHITESPACE ();
6400
3.96k
  return is_end_of_stmt (*input_line_pointer);
6401
3.96k
}
6402
6403
void
6404
equals (char *sym_name, int reassign)
6405
22.2k
{
6406
22.2k
  char *stop = NULL;
6407
22.2k
  char stopc = 0;
6408
6409
22.2k
  input_line_pointer++;
6410
22.2k
  if (*input_line_pointer == '=')
6411
9.13k
    input_line_pointer++;
6412
22.2k
  if (reassign < 0 && *input_line_pointer == '=')
6413
7.27k
    input_line_pointer++;
6414
6415
22.3k
  while (is_whitespace (*input_line_pointer))
6416
14
    input_line_pointer++;
6417
6418
22.2k
  if (flag_mri)
6419
11.0k
    stop = mri_comment_field (&stopc);
6420
6421
22.2k
  assign_symbol (sym_name, reassign >= 0 ? !reassign : reassign);
6422
6423
22.2k
  if (flag_mri)
6424
11.0k
    {
6425
11.0k
      demand_empty_rest_of_line ();
6426
11.0k
      mri_comment_end (stop, stopc);
6427
11.0k
    }
6428
22.2k
}
6429
6430
/* Open FILENAME, first trying the unadorned file name, then if that
6431
   fails and the file name is not an absolute path, attempt to open
6432
   the file in current -I include paths.  PATH is a preallocated
6433
   buffer which will be set to the file opened, or FILENAME if no file
6434
   is found.  */
6435
6436
FILE *
6437
search_and_open (const char *filename, char *path)
6438
101
{
6439
101
  FILE *f = fopen (filename, FOPEN_RB);
6440
101
  if (f == NULL && !IS_ABSOLUTE_PATH (filename))
6441
27
    {
6442
54
      for (size_t i = 0; i < include_dir_count; i++)
6443
27
  {
6444
27
    sprintf (path, "%s/%s", include_dirs[i], filename);
6445
27
    f = fopen (path, FOPEN_RB);
6446
27
    if (f != NULL)
6447
0
      return f;
6448
27
  }
6449
27
    }
6450
101
  strcpy (path, filename);
6451
101
  return f;
6452
101
}
6453
6454
/* .incbin -- include a file verbatim at the current location.  */
6455
6456
void
6457
s_incbin (int x ATTRIBUTE_UNUSED)
6458
0
{
6459
0
  FILE * binfile;
6460
0
  char * path;
6461
0
  char * filename;
6462
0
  char * binfrag;
6463
0
  long   skip = 0;
6464
0
  long   count = 0;
6465
0
  long   bytes;
6466
0
  int    len;
6467
6468
#ifdef md_flush_pending_output
6469
  md_flush_pending_output ();
6470
#endif
6471
6472
0
#ifdef md_cons_align
6473
0
  md_cons_align (1);
6474
0
#endif
6475
6476
0
  SKIP_WHITESPACE ();
6477
0
  filename = demand_copy_string (& len);
6478
0
  if (filename == NULL)
6479
0
    return;
6480
6481
0
  SKIP_WHITESPACE ();
6482
6483
  /* Look for optional skip and count.  */
6484
0
  if (* input_line_pointer == ',')
6485
0
    {
6486
0
      ++ input_line_pointer;
6487
0
      skip = get_absolute_expression ();
6488
6489
0
      SKIP_WHITESPACE ();
6490
6491
0
      if (* input_line_pointer == ',')
6492
0
  {
6493
0
    ++ input_line_pointer;
6494
6495
0
    count = get_absolute_expression ();
6496
0
    if (count == 0)
6497
0
      as_warn (_(".incbin count zero, ignoring `%s'"), filename);
6498
6499
0
    SKIP_WHITESPACE ();
6500
0
  }
6501
0
    }
6502
6503
0
  demand_empty_rest_of_line ();
6504
6505
0
  path = XNEWVEC (char, len + include_dir_maxlen + 2);
6506
0
  binfile = search_and_open (filename, path);
6507
6508
0
  if (binfile == NULL)
6509
0
    as_bad (_("file not found: %s"), filename);
6510
0
  else
6511
0
    {
6512
0
      long   file_len;
6513
0
      struct stat filestat;
6514
6515
0
      if (fstat (fileno (binfile), &filestat) != 0
6516
0
    || ! S_ISREG (filestat.st_mode)
6517
0
    || S_ISDIR (filestat.st_mode))
6518
0
  {
6519
0
    as_bad (_("unable to include `%s'"), path);
6520
0
    goto done;
6521
0
  }
6522
      
6523
0
      register_dependency (path);
6524
6525
      /* Compute the length of the file.  */
6526
0
      if (fseek (binfile, 0, SEEK_END) != 0)
6527
0
  {
6528
0
    as_bad (_("seek to end of .incbin file failed `%s'"), path);
6529
0
    goto done;
6530
0
  }
6531
0
      file_len = ftell (binfile);
6532
6533
      /* If a count was not specified use the remainder of the file.  */
6534
0
      if (count == 0)
6535
0
  count = file_len - skip;
6536
6537
0
      if (skip < 0 || count < 0 || file_len < 0 || skip + count > file_len)
6538
0
  {
6539
0
    as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
6540
0
      skip, count, file_len);
6541
0
    goto done;
6542
0
  }
6543
6544
0
      if (fseek (binfile, skip, SEEK_SET) != 0)
6545
0
  {
6546
0
    as_bad (_("could not skip to %ld in file `%s'"), skip, path);
6547
0
    goto done;
6548
0
  }
6549
6550
      /* Allocate frag space and store file contents in it.  */
6551
0
      binfrag = frag_more (count);
6552
6553
0
      bytes = fread (binfrag, 1, count, binfile);
6554
0
      if (bytes < count)
6555
0
  as_warn (_("truncated file `%s', %ld of %ld bytes read"),
6556
0
     path, bytes, count);
6557
0
    }
6558
0
 done:
6559
0
  if (binfile != NULL)
6560
0
    fclose (binfile);
6561
0
  free (path);
6562
0
}
6563
6564
/* .include -- include a file at this point.  */
6565
6566
void
6567
s_include (int arg ATTRIBUTE_UNUSED)
6568
109
{
6569
109
  char *filename;
6570
109
  int i;
6571
109
  FILE *try_file;
6572
109
  char *path;
6573
6574
109
  if (!flag_m68k_mri)
6575
109
    {
6576
109
      filename = demand_copy_string (&i);
6577
109
      if (filename == NULL)
6578
8
  {
6579
    /* demand_copy_string has already printed an error and
6580
       called ignore_rest_of_line.  */
6581
8
    return;
6582
8
  }
6583
109
    }
6584
0
  else
6585
0
    {
6586
0
      SKIP_WHITESPACE ();
6587
0
      i = 0;
6588
0
      while (!is_end_of_stmt (*input_line_pointer)
6589
0
       && !is_whitespace (*input_line_pointer))
6590
0
  {
6591
0
    obstack_1grow (&notes, *input_line_pointer);
6592
0
    ++input_line_pointer;
6593
0
    ++i;
6594
0
  }
6595
6596
0
      obstack_1grow (&notes, '\0');
6597
0
      filename = obstack_finish (&notes);
6598
0
      while (!is_end_of_stmt (*input_line_pointer))
6599
0
  ++input_line_pointer;
6600
0
    }
6601
6602
101
  demand_empty_rest_of_line ();
6603
6604
101
  path = notes_alloc (i + include_dir_maxlen + 2);
6605
101
  try_file = search_and_open (filename, path);
6606
101
  if (try_file)
6607
74
    fclose (try_file);
6608
6609
101
  register_dependency (path);
6610
101
  input_scrub_insert_file (path);
6611
101
}
6612
6613
void
6614
init_include_dir (void)
6615
567
{
6616
567
  include_dirs = XNEWVEC (const char *, 1);
6617
567
  include_dirs[0] = ".";  /* Current dir.  */
6618
567
  include_dir_count = 1;
6619
567
  include_dir_maxlen = 1;
6620
567
}
6621
6622
void
6623
add_include_dir (char *path)
6624
0
{
6625
0
  include_dir_count++;
6626
0
  include_dirs = XRESIZEVEC (const char *, include_dirs, include_dir_count);
6627
0
  include_dirs[include_dir_count - 1] = path; /* New one.  */
6628
6629
0
  size_t i = strlen (path);
6630
0
  if (i > include_dir_maxlen)
6631
0
    include_dir_maxlen = i;
6632
0
}
6633

6634
/* Output debugging information to denote the source file.  */
6635
6636
static void
6637
generate_file_debug (void)
6638
567
{
6639
567
  if (debug_type == DEBUG_STABS)
6640
0
    stabs_generate_asm_file ();
6641
567
}
6642
6643
/* Output line number debugging information for the current source line.  */
6644
6645
void
6646
generate_lineno_debug (void)
6647
78.2k
{
6648
78.2k
  switch (debug_type)
6649
78.2k
    {
6650
5
    case DEBUG_UNSPECIFIED:
6651
78.2k
    case DEBUG_NONE:
6652
78.2k
    case DEBUG_DWARF:
6653
78.2k
      break;
6654
0
    case DEBUG_STABS:
6655
0
      stabs_generate_asm_lineno ();
6656
0
      break;
6657
0
    case DEBUG_ECOFF:
6658
0
      ecoff_generate_asm_lineno ();
6659
0
      break;
6660
0
    case DEBUG_DWARF2:
6661
      /* ??? We could here indicate to dwarf2dbg.c that something
6662
   has changed.  However, since there is additional backend
6663
   support that is required (calling dwarf2_emit_insn), we
6664
   let dwarf2dbg.c call as_where on its own.  */
6665
0
      break;
6666
0
    case DEBUG_CODEVIEW:
6667
0
      codeview_generate_asm_lineno ();
6668
0
      break;
6669
78.2k
    }
6670
78.2k
}
6671
6672
/* Output debugging information to mark a function entry point or end point.
6673
   END_P is zero for .func, and non-zero for .endfunc.  */
6674
6675
void
6676
s_func (int end_p)
6677
38
{
6678
38
  do_s_func (end_p, NULL);
6679
38
}
6680
6681
/* Subroutine of s_func so targets can choose a different default prefix.
6682
   If DEFAULT_PREFIX is NULL, use the target's "leading char".  */
6683
6684
static void
6685
do_s_func (int end_p, const char *default_prefix)
6686
38
{
6687
38
  if (end_p)
6688
14
    {
6689
14
      if (current_name == NULL)
6690
2
  {
6691
2
    as_bad (_("missing .func"));
6692
2
    ignore_rest_of_line ();
6693
2
    return;
6694
2
  }
6695
6696
12
      if (debug_type == DEBUG_STABS)
6697
0
  stabs_generate_asm_endfunc (current_name, current_label);
6698
6699
12
      free (current_name);
6700
12
      free (current_label);
6701
12
      current_name = current_label = NULL;
6702
12
    }
6703
24
  else /* ! end_p */
6704
24
    {
6705
24
      char *name, *label;
6706
24
      char delim1, delim2;
6707
6708
24
      if (current_name != NULL)
6709
5
  {
6710
5
    as_bad (_(".endfunc missing for previous .func"));
6711
5
    ignore_rest_of_line ();
6712
5
    return;
6713
5
  }
6714
6715
19
      delim1 = get_symbol_name (& name);
6716
19
      name = xstrdup (name);
6717
19
      restore_line_pointer (delim1);
6718
19
      SKIP_WHITESPACE ();
6719
19
      if (*input_line_pointer != ',')
6720
11
  {
6721
11
    if (default_prefix)
6722
0
      label = xasprintf ("%s%s", default_prefix, name);
6723
11
    else
6724
11
      {
6725
11
        char leading_char = bfd_get_symbol_leading_char (stdoutput);
6726
        /* Missing entry point, use function's name with the leading
6727
     char prepended.  */
6728
11
        if (leading_char)
6729
0
    label = xasprintf ("%c%s", leading_char, name);
6730
11
        else
6731
11
    label = xstrdup (name);
6732
11
      }
6733
11
  }
6734
8
      else
6735
8
  {
6736
8
    ++input_line_pointer;
6737
8
    SKIP_WHITESPACE ();
6738
8
    delim2 = get_symbol_name (& label);
6739
8
    label = xstrdup (label);
6740
8
    restore_line_pointer (delim2);
6741
8
  }
6742
6743
19
      if (debug_type == DEBUG_STABS)
6744
0
  stabs_generate_asm_func (name, label);
6745
6746
19
      current_name = name;
6747
19
      current_label = label;
6748
19
    }
6749
6750
31
  demand_empty_rest_of_line ();
6751
31
}
6752

6753
#ifdef HANDLE_BUNDLE
6754
6755
void
6756
s_bundle_align_mode (int arg ATTRIBUTE_UNUSED)
6757
23
{
6758
23
  unsigned int align = get_absolute_expression ();
6759
23
  SKIP_WHITESPACE ();
6760
23
  demand_empty_rest_of_line ();
6761
6762
23
  if (align > (unsigned int) TC_ALIGN_LIMIT)
6763
0
    as_fatal (_(".bundle_align_mode alignment too large (maximum %u)"),
6764
0
        (unsigned int) TC_ALIGN_LIMIT);
6765
6766
23
  if (bundle_lock_frag != NULL)
6767
0
    {
6768
0
      as_bad (_("cannot change .bundle_align_mode inside .bundle_lock"));
6769
0
      return;
6770
0
    }
6771
6772
23
  bundle_align_p2 = align;
6773
23
}
6774
6775
void
6776
s_bundle_lock (int arg ATTRIBUTE_UNUSED)
6777
39
{
6778
39
  demand_empty_rest_of_line ();
6779
6780
39
  if (bundle_align_p2 == 0)
6781
35
    {
6782
35
      as_bad (_(".bundle_lock is meaningless without .bundle_align_mode"));
6783
35
      return;
6784
35
    }
6785
6786
4
  if (bundle_lock_depth == 0)
6787
3
    {
6788
3
      bundle_lock_frchain = frchain_now;
6789
3
      bundle_lock_frag = start_bundle ();
6790
3
    }
6791
4
  ++bundle_lock_depth;
6792
4
}
6793
6794
void
6795
s_bundle_unlock (int arg ATTRIBUTE_UNUSED)
6796
16
{
6797
16
  valueT size;
6798
6799
16
  demand_empty_rest_of_line ();
6800
6801
16
  if (bundle_lock_frag == NULL)
6802
16
    {
6803
16
      as_bad (_(".bundle_unlock without preceding .bundle_lock"));
6804
16
      return;
6805
16
    }
6806
6807
0
  gas_assert (bundle_align_p2 > 0);
6808
6809
0
  gas_assert (bundle_lock_depth > 0);
6810
0
  if (--bundle_lock_depth > 0)
6811
0
    return;
6812
6813
0
  size = pending_bundle_size (bundle_lock_frag);
6814
6815
0
  if (size > (valueT) 1 << bundle_align_p2)
6816
0
    as_bad (_(".bundle_lock sequence is %" PRIu64 " bytes, "
6817
0
        "but bundle size is only %" PRIu64 " bytes"),
6818
0
      (uint64_t) size, (uint64_t) 1 << bundle_align_p2);
6819
0
  else
6820
0
    finish_bundle (bundle_lock_frag, size);
6821
6822
0
  bundle_lock_frag = NULL;
6823
0
  bundle_lock_frchain = NULL;
6824
0
}
6825
6826
#endif  /* HANDLE_BUNDLE */
6827

6828
void
6829
s_ignore (int arg ATTRIBUTE_UNUSED)
6830
45.8k
{
6831
45.8k
  ignore_rest_of_line ();
6832
45.8k
}
6833
6834
void
6835
read_print_statistics (FILE *file)
6836
0
{
6837
0
  htab_print_statistics (file, "pseudo-op table", po_hash);
6838
0
}
6839
6840
/* Inserts the given line into the input stream.
6841
6842
   This call avoids macro/conditionals nesting checking, since the contents of
6843
   the line are assumed to replace the contents of a line already scanned.
6844
6845
   An appropriate use of this function would be substitution of input lines when
6846
   called by md_start_line_hook().  The given line is assumed to already be
6847
   properly scrubbed.  */
6848
6849
void
6850
input_scrub_insert_line (const char *line)
6851
0
{
6852
0
  sb newline;
6853
0
  size_t len = strlen (line);
6854
0
  sb_build (&newline, len);
6855
0
  sb_add_buffer (&newline, line, len);
6856
0
  input_scrub_include_sb (&newline, input_line_pointer, expanding_none);
6857
0
  sb_kill (&newline);
6858
0
  buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6859
0
}
6860
6861
/* Insert a file into the input stream; the path must resolve to an actual
6862
   file; no include path searching or dependency registering is performed.  */
6863
6864
void
6865
input_scrub_insert_file (char *path)
6866
101
{
6867
101
  input_scrub_include_file (path, input_line_pointer);
6868
101
  buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6869
101
}
6870
6871
/* Find the end of a line, considering quotation and escaping of quotes.  */
6872
6873
#if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
6874
# define TC_SINGLE_QUOTE_STRINGS 1
6875
#endif
6876
6877
static char *
6878
_find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED,
6879
       int in_macro)
6880
873k
{
6881
873k
  char inquote = '\0';
6882
873k
  int inescape = 0;
6883
6884
21.9M
  while (!is_end_of_stmt (*s)
6885
874k
   || (inquote && !ISCNTRL (*s))
6886
873k
   || (inquote == '\'' && flag_mri)
6887
#ifdef TC_EOL_IN_INSN
6888
   || (insn && TC_EOL_IN_INSN (s))
6889
#endif
6890
   /* PR 6926:  When we are parsing the body of a macro the sequence
6891
      \@ is special - it refers to the invocation count.  If the @
6892
      character happens to be registered as a line-separator character
6893
      by the target, then the is_end_of_stmt() test above will have
6894
      returned true, but we need to ignore the line separating
6895
      semantics in this particular case.  */
6896
873k
   || (in_macro && inescape && *s == '@')
6897
873k
  )
6898
21.0M
    {
6899
21.0M
      if (mri_string && *s == '\'')
6900
0
  inquote ^= *s;
6901
21.0M
      else if (inescape)
6902
303k
  inescape = 0;
6903
20.7M
      else if (*s == '\\')
6904
303k
  inescape = 1;
6905
20.4M
      else if (!inquote
6906
20.4M
         ? *s == '"'
6907
#ifdef TC_SINGLE_QUOTE_STRINGS
6908
     || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
6909
#endif
6910
20.4M
         : *s == inquote)
6911
651k
  inquote ^= *s;
6912
21.0M
      ++s;
6913
21.0M
    }
6914
873k
  if (inquote)
6915
235k
    as_warn (_("missing closing `%c'"), inquote);
6916
873k
  if (inescape && !ignore_input ())
6917
20
    as_warn (_("stray `\\'"));
6918
873k
  return s;
6919
873k
}
6920
6921
char *
6922
find_end_of_line (char *s, int mri_string)
6923
2.89k
{
6924
2.89k
  return _find_end_of_line (s, mri_string, 0, 0);
6925
2.89k
}
6926
6927
static char *saved_ilp;
6928
static char *saved_limit;
6929
6930
/* Use BUF as a temporary input pointer for calling other functions in this
6931
   file.  BUF must be a C string, so that its end can be found by strlen.
6932
   Also sets the buffer_limit variable (local to this file) so that buffer
6933
   overruns should not occur.  Saves the current input line pointer so that
6934
   it can be restored by calling restore_ilp().
6935
6936
   Does not support recursion.  */
6937
6938
void
6939
temp_ilp (char *buf)
6940
323
{
6941
323
  gas_assert (saved_ilp == NULL);
6942
323
  gas_assert (buf != NULL);
6943
6944
323
  saved_ilp = input_line_pointer;
6945
323
  saved_limit = buffer_limit;
6946
  /* Prevent the assert in restore_ilp from triggering if
6947
     the input_line_pointer has not yet been initialised.  */
6948
323
  if (saved_ilp == NULL)
6949
0
    saved_limit = saved_ilp = (char *) "";
6950
6951
323
  input_line_pointer = buf;
6952
323
  buffer_limit = buf + strlen (buf);
6953
323
  input_from_string = true;
6954
323
}
6955
6956
/* Restore a saved input line pointer.  */
6957
6958
void
6959
restore_ilp (void)
6960
323
{
6961
323
  gas_assert (saved_ilp != NULL);
6962
6963
323
  input_line_pointer = saved_ilp;
6964
323
  buffer_limit = saved_limit;
6965
323
  input_from_string = false;
6966
6967
  saved_ilp = NULL;
6968
323
}