Coverage Report

Created: 2026-09-14 08:07

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