Coverage Report

Created: 2026-11-21 09:00

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