Coverage Report

Created: 2026-07-25 10:20

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