Coverage Report

Created: 2026-10-02 09:53

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
3
  do                \
57
3
    {               \
58
3
      if ((SIZE) >= 8)           \
59
3
  (P2VAR) = 3;           \
60
3
      else if ((SIZE) >= 4)         \
61
2
  (P2VAR) = 2;           \
62
2
      else if ((SIZE) >= 2)         \
63
1
  (P2VAR) = 1;           \
64
1
      else              \
65
1
  (P2VAR) = 0;           \
66
3
    }               \
67
3
  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
10
#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
281
{
255
281
  const char *p;
256
257
281
  pobegin ();
258
281
  obj_read_begin_hook ();
259
260
281
  obstack_begin (&cond_obstack, chunksize);
261
262
281
#ifndef tc_line_separator_chars
263
281
#define tc_line_separator_chars line_separator_chars
264
281
#endif
265
  /* Use machine dependent syntax.  */
266
562
  for (p = tc_line_separator_chars; *p; p++)
267
281
    lex_type[(unsigned char) *p] = LEX_EOS;
268
269
281
  if (flag_mri)
270
39
    lex_type['?'] = LEX_BEGIN_NAME | LEX_NAME;
271
272
281
  stabs_begin ();
273
274
#ifndef WORKING_DOT_WORD
275
  broken_words = NULL;
276
  new_broken_words = 0;
277
#endif
278
279
281
  abs_section_offset = 0;
280
281
281
  line_label = NULL;
282
281
  mri_common_symbol = NULL;
283
281
  mri_pending_align = 0;
284
285
281
  current_name = NULL;
286
281
  current_label = NULL;
287
288
281
#ifndef NO_LISTING
289
281
#ifdef OBJ_ELF
290
281
  dwarf_file = 0;
291
281
  dwarf_line = -1;
292
281
  dwarf_file_string = 0;
293
281
#endif
294
281
#endif
295
296
281
#ifdef HANDLE_BUNDLE
297
281
  bundle_align_p2 = 0;
298
281
  bundle_lock_frag = NULL;
299
281
  bundle_lock_frchain = NULL;
300
281
  bundle_lock_depth = 0;
301
281
#endif
302
281
}
303
304
void
305
read_end (void)
306
281
{
307
281
  if (!ENABLE_LEAK_CHECK)
308
0
    return;
309
281
  stabs_end ();
310
281
  poend ();
311
281
  _obstack_free (&cond_obstack, NULL);
312
281
  free (current_name);
313
281
  free (current_label);
314
281
  free (include_dirs);
315
281
}
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
42.8k
{
536
42.8k
  expression_and_evaluate (exp);
537
538
42.8k
  if (exp->X_op != O_constant)
539
29.4k
    {
540
29.4k
      if (exp->X_op != O_absent)
541
28.0k
  as_bad (_("bad or irreducible absolute expression"));
542
29.4k
      exp->X_add_number = 0;
543
29.4k
    }
544
42.8k
  return exp->X_add_number;
545
42.8k
}
546
547
offsetT
548
get_absolute_expression (void)
549
42.1k
{
550
42.1k
  expressionS exp;
551
552
42.1k
  return get_absolute_expr (&exp);
553
42.1k
}
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.12k
{
561
1.12k
  const pseudo_typeS *pop;
562
71.3k
  for (pop = table; pop->poc_name; pop++)
563
70.2k
    {
564
70.2k
      if (str_hash_insert (po_hash, pop->poc_name, pop, 0) != NULL)
565
2.52k
  {
566
2.52k
    if (!pop_override_ok)
567
0
      as_fatal (_("error constructing %s pseudo-op table"),
568
0
          pop_table_name);
569
2.52k
  }
570
70.2k
    }
571
1.12k
}
572
573
#ifndef md_pop_insert
574
281
#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
281
#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
281
{
592
281
  po_hash = str_htab_create ();
593
594
  /* Do the target-specific pseudo ops.  */
595
281
  pop_table_name = "md";
596
281
  pop_override_ok = 0;
597
281
  md_pop_insert ();
598
599
  /* Now object specific.  Skip any that were in the target table.  */
600
281
  pop_table_name = "obj";
601
281
  pop_override_ok = 1;
602
281
  obj_pop_insert ();
603
604
  /* Now portable ones.  Skip any that we've seen already.  */
605
281
  pop_table_name = "standard";
606
281
  pop_insert (potable);
607
608
  /* Now CFI ones.  */
609
281
#if defined (TARGET_USE_SCFI) && defined (TARGET_USE_GINSN)
610
281
  if (flag_synth_cfi)
611
0
    {
612
0
      pop_table_name = "scfi";
613
0
      scfi_pop_insert ();
614
0
    }
615
281
  else
616
281
#endif
617
281
    {
618
281
      pop_table_name = "cfi";
619
281
      cfi_pop_insert ();
620
281
    }
621
281
}
622
623
static void
624
poend (void)
625
281
{
626
281
  if (ENABLE_LEAK_CHECK)
627
281
    htab_delete (po_hash);
628
281
}
629

630
#define HANDLE_CONDITIONAL_ASSEMBLY(num_read)       \
631
254k
  if (ignore_input ())             \
632
254k
    {                 \
633
75
      char *eol = find_end_of_line (input_line_pointer - (num_read),  \
634
75
            flag_m68k_mri);      \
635
75
      input_line_pointer = (input_line_pointer <= buffer_limit    \
636
75
          && eol >= buffer_limit)     \
637
75
         ? buffer_limit        \
638
75
         : eol + 1;         \
639
75
      continue;               \
640
75
    }
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
686
{
646
686
  sb out;
647
686
  const char *err;
648
686
  macro_entry *macro;
649
650
686
  if (check_macro (line, &out, &err, &macro))
651
46
    {
652
46
      if (err != NULL)
653
5
  as_bad ("%s", err);
654
46
      *input_line_pointer++ = term;
655
46
      input_scrub_include_sb (&out,
656
46
            input_line_pointer, expanding_macro);
657
46
      sb_kill (&out);
658
46
      buffer_limit =
659
46
  input_scrub_next_buffer (&input_line_pointer);
660
#ifdef md_macro_info
661
      md_macro_info (macro);
662
#endif
663
46
      return 1;
664
46
    }
665
640
  return 0;
666
686
}
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
251
{
674
251
  fragS *frag = frag_now;
675
676
251
  frag_align_code (bundle_align_p2, 0);
677
678
251
  while (frag->fr_type != rs_align_code)
679
0
    frag = frag->fr_next;
680
681
251
  gas_assert (frag != frag_now);
682
683
  /* Set initial alignment to zero.  */
684
251
  frag->fr_offset = 0;
685
686
251
  return frag;
687
251
}
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
257
{
694
257
  valueT offset = frag->fr_fix;
695
257
  valueT size = 0;
696
697
257
  gas_assert (frag != frag_now);
698
257
  gas_assert (frag->fr_type == rs_align_code);
699
700
514
  while (frag != frag_now)
701
257
    {
702
      /* This should only happen in what will later become an error case.  */
703
257
      if (frag == NULL)
704
0
  return 0;
705
706
257
      size += frag->fr_fix;
707
257
      if (frag->fr_type == rs_machine_dependent)
708
0
  size += md_frag_max_var (frag);
709
710
257
      frag = frag->fr_next;
711
257
    }
712
713
257
  gas_assert (frag == frag_now);
714
257
  size += frag_now_fix ();
715
257
  if (frag->fr_type == rs_machine_dependent)
716
0
    size += md_frag_max_var (frag);
717
718
257
  gas_assert (size >= offset || now_seg == absolute_section);
719
720
257
  return size - offset;
721
257
}
722
723
/* Finish off the frag created to ensure bundle alignment.  */
724
static void
725
finish_bundle (fragS *frag, valueT size)
726
251
{
727
251
  gas_assert (bundle_align_p2 > 0);
728
251
  gas_assert (frag->fr_type == rs_align_code);
729
730
251
  if (size > 1)
731
188
    {
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
188
      frag->fr_offset = bundle_align_p2;
736
188
      frag->fr_subtype = size - 1;
737
188
    }
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
251
  if (bundle_align_p2 > OCTETS_PER_BYTE_POWER)
743
251
    record_alignment (now_seg, bundle_align_p2 - OCTETS_PER_BYTE_POWER);
744
251
}
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
41.6k
{
751
41.6k
  fragS *insn_start_frag = NULL;
752
753
41.6k
  if (bundle_lock_frchain != NULL && bundle_lock_frchain != frchain_now)
754
0
    {
755
0
      as_bad (_("cannot change section or subsection inside .bundle_lock"));
756
      /* Clearing this serves as a marker that we have already complained.  */
757
0
      bundle_lock_frchain = NULL;
758
0
    }
759
760
41.6k
  if (bundle_lock_frchain == NULL && bundle_align_p2 > 0)
761
249
    insn_start_frag = start_bundle ();
762
763
41.6k
  md_assemble (line);
764
765
41.6k
  if (bundle_lock_frchain != NULL)
766
6
    {
767
      /* Make sure this hasn't pushed the locked sequence
768
   past the bundle size.  */
769
6
      valueT bundle_size = pending_bundle_size (bundle_lock_frag);
770
6
      if (bundle_size > (valueT) 1 << bundle_align_p2)
771
0
  as_bad (_ (".bundle_lock sequence at %" PRIu64 " bytes, "
772
0
       "but .bundle_align_mode limit is %" PRIu64 " bytes"),
773
0
    (uint64_t) bundle_size, (uint64_t) 1 << bundle_align_p2);
774
6
    }
775
41.6k
  else if (bundle_align_p2 > 0)
776
249
    {
777
249
      valueT insn_size = pending_bundle_size (insn_start_frag);
778
779
249
      if (insn_size > (valueT) 1 << bundle_align_p2)
780
184
  as_bad (_("single instruction is %" PRIu64 " bytes long, "
781
184
      "but .bundle_align_mode limit is %" PRIu64 " bytes"),
782
184
    (uint64_t) insn_size, (uint64_t) 1 << bundle_align_p2);
783
784
249
      finish_bundle (insn_start_frag, insn_size);
785
249
    }
786
41.6k
}
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
9.67k
{
797
9.67k
  flagword flags = bfd_section_flags (now_seg);
798
799
9.67k
  return (flags & SEC_ALLOC) && !(flags & (SEC_LOAD | SEC_HAS_CONTENTS));
800
9.67k
}
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.16k
{
814
1.16k
  if (now_seg == absolute_section || in_bss ())
815
289
    {
816
289
      if (fill != NULL)
817
37
  while (len-- > 0)
818
30
    if (*fill++ != '\0')
819
23
      {
820
23
        if (now_seg == absolute_section)
821
23
    as_warn (_("ignoring fill value in absolute section"));
822
0
        else
823
0
    as_warn (_("ignoring fill value in section `%s'"),
824
0
       segment_name (now_seg));
825
23
        break;
826
23
      }
827
289
      fill = NULL;
828
289
      len = 0;
829
289
    }
830
831
#ifdef md_flush_pending_output
832
  md_flush_pending_output ();
833
#endif
834
835
1.16k
#ifdef md_do_align
836
1.16k
  md_do_align (n, fill, len, max, just_record_alignment);
837
1.12k
#endif
838
839
  /* Only make a frag if we HAVE to...  */
840
1.12k
  if ((n > OCTETS_PER_BYTE_POWER) && !need_pass_2)
841
48
    {
842
48
      if (fill == NULL)
843
30
  {
844
30
    if (subseg_text_p (now_seg))
845
0
      frag_align_code (n, max);
846
30
    else
847
30
      frag_align (n, 0, max);
848
30
  }
849
18
      else if (len <= 1)
850
14
  frag_align (n, *fill, max);
851
4
      else
852
4
  frag_align_pattern (n, fill, len, max);
853
48
    }
854
855
1.12k
#ifdef md_do_align
856
1.16k
 just_record_alignment: ATTRIBUTE_UNUSED_LABEL
857
1.16k
#endif
858
859
1.16k
  if (n > OCTETS_PER_BYTE_POWER)
860
91
    record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
861
1.16k
}
862
863
/* Find first <eol><next_char>NO_APP<eol>, if any, in the supplied buffer.
864
   Return NULL if there's none, or else the position of <next_char>.
865
   
866
   Note: the S parameter to this function is typed as CHAR* rather than
867
   CONST CHAR* because if it is const then the strstr() function will return
868
   a const pointer, which in turn means that the END local would need to be
869
   const, which would mean that the function itself would have to return a
870
   const pointer, which means that input_line_pointer would have to become
871
   const, which would break lots of things.  (See PR 33696).  */
872
873
static char *
874
find_no_app (char *s, char next_char)
875
17
{
876
17
  const char *start = s;
877
17
  const char srch[] = { next_char, 'N', 'O', '_', 'A', 'P', 'P', '\0' };
878
879
17
  for (;;)
880
17
    {
881
17
      char * ends = strstr (s, srch);
882
883
17
      if (ends == NULL)
884
16
  break;
885
1
      if (is_end_of_line (ends[sizeof (srch) - 1])
886
1
    && (ends == start || is_end_of_line (ends[-1])))
887
1
  return ends;
888
0
      s = ends + sizeof (srch) - 1;
889
0
    }
890
891
16
  return NULL;
892
17
}
893
894
/* We read the file, putting things into a web that represents what we
895
   have been reading.  */
896
void
897
read_a_source_file (const char *name)
898
281
{
899
281
  char nul_char;
900
281
  char next_char;
901
281
  char *s;    /* String of symbol, '\0' appended.  */
902
281
  long temp;
903
281
  const pseudo_typeS *pop;
904
905
#ifdef WARN_COMMENTS
906
  found_comment = 0;
907
#endif
908
909
281
  set_identify_name (name);
910
911
281
  buffer = input_scrub_new_file (name);
912
913
281
  listing_file (name);
914
281
  listing_newline (NULL);
915
281
  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
281
  generate_file_debug ();
921
922
1.27k
  while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
923
999
    {       /* We have another line to parse.  */
924
999
#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
999
      char *last_eol = NULL;
928
929
999
#endif
930
301k
      while (input_line_pointer < buffer_limit)
931
300k
  {
932
300k
    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
300k
    was_new_line = lex_type[(unsigned char) input_line_pointer[-1]]
939
300k
       & (LEX_EOL | LEX_EOS);
940
300k
    if (was_new_line)
941
274k
      {
942
274k
        symbol_set_value_now (&dot_symbol);
943
274k
#ifdef md_start_line_hook
944
274k
        md_start_line_hook ();
945
274k
#endif
946
274k
        if (input_line_pointer[-1] == '\n')
947
211k
    bump_line_counters ();
948
274k
      }
949
950
300k
#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
300k
    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
300k
#endif
986
987
300k
    next_char = *input_line_pointer;
988
300k
    if ((was_new_line & LEX_EOL)
989
231k
             && (strchr (line_comment_chars, '#')
990
231k
      ? next_char == '#'
991
231k
      : next_char && strchr (line_comment_chars, next_char)))
992
794
      {
993
        /* Its a comment.  Check for APP followed by NO_APP.  */
994
794
        sb sbuf;
995
794
        char *ends;
996
794
        size_t len;
997
998
794
        s = input_line_pointer + 1;
999
794
        if (!startswith (s, "APP") || !is_end_of_line (s[3]))
1000
788
    {
1001
      /* We ignore it.  Note: Not ignore_rest_of_line ()!  */
1002
7.07k
      while (s <= buffer_limit)
1003
7.07k
        if (is_end_of_line (*s++))
1004
788
          break;
1005
788
      input_line_pointer = s;
1006
788
      continue;
1007
788
    }
1008
6
        s += 4;
1009
1010
6
        ends = find_no_app (s, next_char);
1011
6
        len = ends ? ends - s : buffer_limit - s;
1012
1013
6
        sb_build (&sbuf, len + 100);
1014
6
        sb_add_buffer (&sbuf, s, len);
1015
6
        if (!ends)
1016
5
    {
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
5
      do
1022
16
        {
1023
16
          buffer_limit = input_scrub_next_buffer (&buffer);
1024
16
          if (!buffer_limit)
1025
5
      break;
1026
11
          ends = find_no_app (buffer, next_char);
1027
11
          len = ends ? ends - buffer : buffer_limit - buffer;
1028
11
          sb_add_buffer (&sbuf, buffer, len);
1029
11
        }
1030
11
      while (!ends);
1031
5
    }
1032
6
        sb_add_char (&sbuf, '\n');
1033
1034
6
        input_line_pointer = ends ? ends + 8 : NULL;
1035
6
        input_scrub_include_sb (&sbuf, input_line_pointer, expanding_app);
1036
6
        sb_kill (&sbuf);
1037
6
        buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1038
6
        continue;
1039
794
      }
1040
1041
299k
    if (was_new_line)
1042
273k
      {
1043
273k
        line_label = NULL;
1044
1045
273k
        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
273k
      }
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
299k
    do
1116
362k
      nul_char = next_char = *input_line_pointer++;
1117
362k
    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
299k
    if (is_name_beginner (next_char) || next_char == '"')
1122
206k
      {
1123
206k
        char *rest;
1124
1125
        /* Want user-defined label or pseudo/opcode.  */
1126
206k
        HANDLE_CONDITIONAL_ASSEMBLY (1);
1127
1128
206k
        --input_line_pointer;
1129
206k
        nul_char = get_symbol_name (& s); /* name's delimiter.  */
1130
206k
        next_char = (nul_char == '"' ? input_line_pointer[1] : nul_char);
1131
206k
        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
206k
        if (TC_START_LABEL (s, nul_char, next_char))
1139
7.81k
    {
1140
7.81k
      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
7.81k
      line_label = colon (s); /* User-defined label.  */
1160
7.81k
      restore_line_pointer (nul_char);
1161
7.81k
      ++ input_line_pointer;
1162
#ifdef tc_check_label
1163
      tc_check_label (line_label);
1164
#endif
1165
      /* Input_line_pointer->after ':'.  */
1166
7.81k
      SKIP_WHITESPACE ();
1167
7.81k
    }
1168
198k
        else if ((next_char == '=' && *rest == '=')
1169
198k
           || (is_whitespace (next_char)
1170
110k
         && rest[0] == '='
1171
1.93k
         && rest[1] == '='))
1172
525
    {
1173
525
      equals (s, -1);
1174
525
      demand_empty_rest_of_line ();
1175
525
    }
1176
198k
        else if ((next_char == '='
1177
191k
           || (is_whitespace (next_char)
1178
110k
          && *rest == '='))
1179
#ifdef TC_EQUAL_IN_INSN
1180
         && !TC_EQUAL_IN_INSN (next_char, s)
1181
#endif
1182
198k
         )
1183
8.41k
    {
1184
8.41k
      equals (s, 1);
1185
8.41k
      demand_empty_rest_of_line ();
1186
8.41k
    }
1187
189k
        else
1188
189k
    {
1189
      /* Expect pseudo-op or machine instruction.  */
1190
189k
      pop = NULL;
1191
1192
189k
#ifndef TC_CASE_SENSITIVE
1193
189k
      {
1194
189k
        char *s2 = s;
1195
1196
189k
        strncpy (original_case_string, s2,
1197
189k
           sizeof (original_case_string) - 1);
1198
189k
        original_case_string[sizeof (original_case_string) - 1] = 0;
1199
1200
1.39M
        while (*s2)
1201
1.20M
          {
1202
1.20M
      *s2 = TOLOWER (*s2);
1203
1.20M
      s2++;
1204
1.20M
          }
1205
189k
      }
1206
189k
#endif
1207
189k
      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
189k
      if (pop != NULL
1217
189k
          || (!flag_m68k_mri && *s == '.'))
1218
148k
        {
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
148k
          if (pop == NULL)
1226
148k
      pop = str_hash_find (po_hash, s + 1);
1227
148k
          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
148k
          if (mri_pending_align
1234
13
        && (pop == NULL
1235
12
            || !((pop->poc_handler == cons
1236
0
            && pop->poc_val == 1)
1237
12
           || (pop->poc_handler == s_space
1238
0
               && pop->poc_val == 1)
1239
#ifdef tc_conditional_pseudoop
1240
           || tc_conditional_pseudoop (pop)
1241
#endif
1242
12
           || pop->poc_handler == s_if
1243
12
           || pop->poc_handler == s_ifdef
1244
12
           || pop->poc_handler == s_ifc
1245
12
           || pop->poc_handler == s_ifeqs
1246
12
           || pop->poc_handler == s_else
1247
12
           || pop->poc_handler == s_endif
1248
11
           || pop->poc_handler == s_globl
1249
11
           || pop->poc_handler == s_ignore)))
1250
12
      {
1251
12
        do_align (1, NULL, 0, 0);
1252
12
        mri_pending_align = 0;
1253
1254
12
        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
12
      }
1260
1261
          /* Print the error msg now, while we still can.  */
1262
148k
          if (pop == NULL)
1263
31.7k
      {
1264
31.7k
        char *end = input_line_pointer;
1265
1266
31.7k
        (void) restore_line_pointer (nul_char);
1267
31.7k
        s_ignore (0);
1268
31.7k
        nul_char = next_char = *--input_line_pointer;
1269
31.7k
        *input_line_pointer = '\0';
1270
31.7k
        if (! macro_defined || ! try_macro (next_char, s))
1271
31.7k
          {
1272
31.7k
            *end = '\0';
1273
31.7k
            as_bad (_("unknown pseudo-op: `%s'"), s);
1274
31.7k
            *input_line_pointer++ = nul_char;
1275
31.7k
          }
1276
31.7k
        continue;
1277
31.7k
      }
1278
1279
          /* Put it back for error messages etc.  */
1280
116k
          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
116k
          if (is_whitespace (next_char))
1285
84.4k
      input_line_pointer++;
1286
1287
          /* Input_line is restored.
1288
       Input_line_pointer->1st non-blank char
1289
       after pseudo-operation.  */
1290
116k
          (*pop->poc_handler) (pop->poc_val);
1291
1292
          /* If that was .end, just get out now.  */
1293
116k
          if (pop->poc_handler == s_end)
1294
3
      goto quit;
1295
116k
        }
1296
41.6k
      else
1297
41.6k
        {
1298
          /* WARNING: next_char may be end-of-line.  */
1299
          /* Also: input_line_pointer->`\0` where nul_char was.  */
1300
41.6k
          (void) restore_line_pointer (nul_char);
1301
41.6k
          input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1, 0);
1302
41.6k
          next_char = nul_char = *input_line_pointer;
1303
41.6k
          *input_line_pointer = '\0';
1304
1305
41.6k
          generate_lineno_debug ();
1306
1307
41.6k
          if (macro_defined && try_macro (next_char, s))
1308
46
      continue;
1309
1310
41.6k
          if (mri_pending_align)
1311
5
      {
1312
5
        do_align (1, NULL, 0, 0);
1313
5
        mri_pending_align = 0;
1314
5
        if (line_label != NULL)
1315
0
          {
1316
0
            symbol_set_frag (line_label, frag_now);
1317
0
            S_SET_VALUE (line_label, frag_now_fix ());
1318
0
          }
1319
5
      }
1320
1321
41.6k
          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
41.6k
          if (input_line_pointer == NULL)
1326
0
      as_fatal (_("unable to continue with assembly."));
1327
 
1328
41.6k
          *input_line_pointer++ = nul_char;
1329
1330
          /* We resume loop AFTER the end-of-line from
1331
       this instruction.  */
1332
41.6k
        }
1333
189k
    }
1334
174k
        continue;
1335
206k
      }
1336
1337
    /* Empty statement?  */
1338
92.9k
    if (is_end_of_stmt (next_char))
1339
56.3k
      continue;
1340
1341
36.6k
    if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (next_char))
1342
19.4k
      {
1343
        /* local label  ("4:")  */
1344
19.4k
        char *backup = input_line_pointer;
1345
1346
19.4k
        HANDLE_CONDITIONAL_ASSEMBLY (1);
1347
1348
19.4k
        temp = next_char - '0';
1349
1350
        /* Read the whole number.  */
1351
19.4k
        while (ISDIGIT (*input_line_pointer))
1352
9.42k
    {
1353
9.42k
      const long digit = *input_line_pointer - '0';
1354
1355
      /* Don't accept labels which look like octal numbers.  */
1356
9.42k
      if (temp == 0)
1357
1.79k
        break;
1358
7.62k
      if (temp > (INT_MAX - digit) / 10)
1359
18
        {
1360
18
          as_bad (_("local label too large near %s"), backup);
1361
18
          temp = -1;
1362
18
          break;
1363
18
        }
1364
7.60k
      temp = temp * 10 + digit;
1365
7.60k
      ++input_line_pointer;
1366
7.60k
    }
1367
1368
        /* Overflow: stop processing the label.  */
1369
19.4k
        if (temp == -1)
1370
18
    {
1371
18
      ignore_rest_of_line ();
1372
18
      continue;
1373
18
    }
1374
1375
19.4k
        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
19.4k
        if (LOCAL_LABELS_FB
1392
19.4k
      && *input_line_pointer++ == ':')
1393
8.26k
    {
1394
8.26k
      fb_label_instance_inc (temp);
1395
8.26k
      colon (fb_label_name (temp, 0));
1396
8.26k
      continue;
1397
8.26k
    }
1398
1399
11.1k
        input_line_pointer = backup;
1400
11.1k
      }
1401
1402
28.3k
    if (next_char && strchr (line_comment_chars, next_char))
1403
42
      {
1404
        /* Its a comment, ignore it.  Note: Not ignore_rest_of_line ()!  */
1405
42
        s = input_line_pointer;
1406
287
        while (s <= buffer_limit)
1407
287
    if (is_end_of_line (*s++))
1408
42
      break;
1409
42
        input_line_pointer = s;
1410
42
        continue;
1411
42
      }
1412
1413
28.2k
    HANDLE_CONDITIONAL_ASSEMBLY (1);
1414
1415
28.2k
#ifdef tc_unrecognized_line
1416
28.2k
    if (tc_unrecognized_line (next_char))
1417
1.80k
      continue;
1418
26.4k
#endif
1419
26.4k
    input_line_pointer--;
1420
    /* Report unknown char as error.  */
1421
26.4k
    demand_empty_rest_of_line ();
1422
26.4k
  }
1423
999
    }
1424
1425
281
 quit:
1426
281
  symbol_set_value_now (&dot_symbol);
1427
1428
281
#ifdef HANDLE_BUNDLE
1429
281
  if (bundle_lock_frag != NULL)
1430
0
    {
1431
0
      as_bad_where (bundle_lock_frag->fr_file, bundle_lock_frag->fr_line,
1432
0
        _(".bundle_lock with no matching .bundle_unlock"));
1433
0
      bundle_lock_frag = NULL;
1434
0
      bundle_lock_frchain = NULL;
1435
0
      bundle_lock_depth = 0;
1436
0
    }
1437
281
#endif
1438
1439
281
  if (flag_synth_cfi)
1440
0
    ginsn_data_end (symbol_temp_new_now ());
1441
1442
281
#ifdef md_cleanup
1443
281
  md_cleanup ();
1444
281
#endif
1445
  /* Close the input file.  */
1446
281
  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
281
}
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
3
{
1462
3
  valueT value;
1463
3
  unsigned int i;
1464
3
  bool sign = !exp->X_unsigned && exp->X_extrabit;
1465
1466
3
  value = exp->X_add_number;
1467
15
  for (i = 0; i < sizeof (exp->X_add_number) / CHARS_PER_LITTLENUM; i++)
1468
12
    {
1469
12
      generic_bignum[i] = value & LITTLENUM_MASK;
1470
12
      value >>= LITTLENUM_NUMBER_OF_BITS;
1471
12
    }
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
3
  if ((exp->X_add_number < 0) == !sign)
1475
2
    generic_bignum[i++] = sign ? LITTLENUM_MASK : 0;
1476
3
  exp->X_op = O_big;
1477
3
  exp->X_add_number = i;
1478
3
  exp->X_unsigned = !sign;
1479
1480
3
  return sign;
1481
3
}
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
3.58k
{
1494
3.58k
  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
3.58k
  for (s = input_line_pointer;
1510
165k
       !is_end_of_stmt (*s);
1511
161k
       s++)
1512
161k
    ;
1513
3.58k
#endif
1514
3.58k
  *stopcp = *s;
1515
3.58k
  *s = '\0';
1516
1517
3.58k
  return s;
1518
3.58k
}
1519
1520
/* Skip to the end of an MRI comment field.  */
1521
1522
void
1523
mri_comment_end (char *stop, int stopc)
1524
3.58k
{
1525
3.58k
  know (flag_mri);
1526
1527
3.58k
  input_line_pointer = stop;
1528
3.58k
  *stop = stopc;
1529
3.58k
  while (!is_end_of_stmt (*input_line_pointer))
1530
0
    ++input_line_pointer;
1531
3.58k
}
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.18k
#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.15k
{
1551
1.15k
  unsigned int align_limit = TC_ALIGN_LIMIT;
1552
1.15k
  addressT align;
1553
1.15k
  char *stop = NULL;
1554
1.15k
  char stopc = 0;
1555
1.15k
  offsetT fill = 0;
1556
1.15k
  unsigned int max;
1557
1.15k
  int fill_p;
1558
1559
1.15k
  if (flag_mri)
1560
17
    stop = mri_comment_field (&stopc);
1561
1562
1.15k
  if (is_end_of_stmt (*input_line_pointer))
1563
8
    {
1564
8
      if (arg < 0)
1565
8
  align = 0;
1566
0
      else
1567
0
  align = arg; /* Default value from pseudo-op table.  */
1568
8
    }
1569
1.14k
  else
1570
1.14k
    {
1571
1.14k
      align = get_absolute_expression ();
1572
1.14k
      SKIP_WHITESPACE ();
1573
1574
#ifdef TC_ALIGN_ZERO_IS_DEFAULT
1575
      if (arg > 0 && align == 0)
1576
  align = arg;
1577
#endif
1578
1.14k
    }
1579
1580
1.15k
  if (bytes_p)
1581
1.14k
    {
1582
      /* Convert to a power of 2.  */
1583
1.14k
      if (align != 0)
1584
97
  {
1585
97
    unsigned int i;
1586
1587
315
    for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1588
218
      ;
1589
97
    if (align != 1)
1590
57
      as_bad (_("alignment not a power of 2"));
1591
1592
97
    align = i;
1593
97
  }
1594
1.14k
    }
1595
1596
1.15k
  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.15k
  if (*input_line_pointer != ',')
1604
818
    {
1605
818
      fill_p = 0;
1606
818
      max = 0;
1607
818
    }
1608
332
  else
1609
332
    {
1610
332
      ++input_line_pointer;
1611
332
      if (*input_line_pointer == ',')
1612
262
  fill_p = 0;
1613
70
      else
1614
70
  {
1615
70
    fill = get_absolute_expression ();
1616
70
    SKIP_WHITESPACE ();
1617
70
    fill_p = 1;
1618
70
  }
1619
1620
332
      if (*input_line_pointer != ',')
1621
50
  max = 0;
1622
282
      else
1623
282
  {
1624
282
    ++input_line_pointer;
1625
282
    offsetT val = get_absolute_expression ();
1626
282
    max = val;
1627
282
    if (val < 0 || max != (valueT) val)
1628
257
      {
1629
257
        as_warn (_("ignoring out of range alignment maximum"));
1630
257
        max = 0;
1631
257
      }
1632
282
  }
1633
332
    }
1634
1635
1.15k
  if (!fill_p)
1636
1.08k
    {
1637
1.08k
      if (arg < 0)
1638
14
  as_warn (_("expected fill pattern missing"));
1639
1.08k
      do_align (align, NULL, 0, max);
1640
1.08k
    }
1641
70
  else
1642
70
    {
1643
70
      unsigned int fill_len;
1644
1645
70
      if (arg >= 0)
1646
61
  fill_len = 1;
1647
9
      else
1648
9
  fill_len = -arg;
1649
1650
70
      if (fill_len <= 1)
1651
61
  {
1652
61
    char fill_char = 0;
1653
1654
61
    fill_char = fill;
1655
61
    do_align (align, &fill_char, fill_len, max);
1656
61
  }
1657
9
      else
1658
9
  {
1659
9
    char ab[16];
1660
1661
9
    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
9
    md_number_to_chars (ab, fill, fill_len);
1669
9
    do_align (align, ab, fill_len, max);
1670
9
  }
1671
70
    }
1672
1673
1.15k
  demand_empty_rest_of_line ();
1674
1675
1.15k
  if (flag_mri)
1676
17
    mri_comment_end (stop, stopc);
1677
1.15k
}
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.14k
{
1685
1.14k
  s_align (arg, 1);
1686
1.14k
}
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
2
{
1694
2
  s_align (arg, 0);
1695
2
}
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.10k
{
1723
1.10k
  char * name;
1724
1.10k
  char * start;
1725
1.10k
  char c;
1726
1727
1.10k
  c = *input_line_pointer++;
1728
1729
1.10k
  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.10k
  else if (is_name_beginner (c) || (input_from_string && c == FAKE_LABEL_CHAR))
1767
947
    {
1768
947
      ptrdiff_t len;
1769
1770
947
      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
4.32k
      while (is_part_of_name (c = *input_line_pointer++)
1775
947
       || (input_from_string && c == FAKE_LABEL_CHAR))
1776
3.38k
  ;
1777
1778
947
      len = (input_line_pointer - name) - 1;
1779
947
      start = XNEWVEC (char, len + 1);
1780
1781
947
      memcpy (start, name, len);
1782
947
      start[len] = 0;
1783
1784
      /* Skip a name ender char if one is present.  */
1785
947
      if (! is_name_ender (c))
1786
947
  --input_line_pointer;
1787
947
    }
1788
156
  else
1789
156
    name = start = NULL;
1790
1791
1.10k
  if (name == start)
1792
156
    {
1793
156
      as_bad (_("expected symbol name"));
1794
156
      ignore_rest_of_line ();
1795
156
      free (start);
1796
156
      return NULL;
1797
156
    }
1798
1799
947
  SKIP_WHITESPACE ();
1800
1801
947
  return start;
1802
1.10k
}
1803
1804
1805
symbolS *
1806
s_comm_internal (int param,
1807
     symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
1808
658
{
1809
658
  char *name;
1810
658
  offsetT temp, size;
1811
658
  symbolS *symbolP = NULL;
1812
658
  char *stop = NULL;
1813
658
  char stopc = 0;
1814
658
  expressionS exp;
1815
1816
658
  if (flag_mri)
1817
10
    stop = mri_comment_field (&stopc);
1818
1819
658
  if ((name = read_symbol_name ()) == NULL)
1820
105
    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
553
  if (*input_line_pointer == ',')
1825
270
    input_line_pointer++;
1826
1827
553
  temp = get_absolute_expr (&exp);
1828
553
  size = temp;
1829
553
  size &= ((addressT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
1830
553
  if (exp.X_op == O_absent)
1831
1
    {
1832
1
      as_bad (_("missing size expression"));
1833
1
      ignore_rest_of_line ();
1834
1
      goto out;
1835
1
    }
1836
552
  else if (temp != size || (!exp.X_unsigned && exp.X_add_number < 0))
1837
0
    {
1838
0
      as_warn (_("size (%ld) out of range, ignored"), (long) temp);
1839
0
      ignore_rest_of_line ();
1840
0
      goto out;
1841
0
    }
1842
1843
552
  symbolP = symbol_find_or_make (name);
1844
552
  if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
1845
517
      && !S_IS_COMMON (symbolP))
1846
125
    {
1847
125
      if (!S_IS_VOLATILE (symbolP))
1848
125
  {
1849
125
    symbolP = NULL;
1850
125
    as_bad (_("symbol `%s' is already defined"), name);
1851
125
    ignore_rest_of_line ();
1852
125
    goto out;
1853
125
  }
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
427
  size = S_GET_VALUE (symbolP);
1862
427
  if (size == 0)
1863
292
    size = temp;
1864
135
  else if (size != temp)
1865
1
    as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1866
1
       name, (long) size, (long) temp);
1867
1868
427
  if (comm_parse_extra != NULL)
1869
417
    symbolP = (*comm_parse_extra) (param, symbolP, size);
1870
10
  else
1871
10
    {
1872
10
      S_SET_VALUE (symbolP, size);
1873
10
      S_SET_EXTERNAL (symbolP);
1874
10
      S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
1875
10
    }
1876
1877
427
  demand_empty_rest_of_line ();
1878
658
 out:
1879
658
  if (flag_mri)
1880
10
    mri_comment_end (stop, stopc);
1881
658
  free (name);
1882
658
  return symbolP;
1883
427
}
1884
1885
void
1886
s_comm (int ignore)
1887
15
{
1888
15
  s_comm_internal (ignore, NULL);
1889
15
}
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
16
{
1898
16
  char *name;
1899
16
  char c;
1900
16
  char *alc = NULL;
1901
16
  symbolS *sym;
1902
16
  offsetT align;
1903
16
  char *stop = NULL;
1904
16
  char stopc = 0;
1905
1906
16
  if (!flag_mri)
1907
15
    {
1908
15
      s_comm (0);
1909
15
      return;
1910
15
    }
1911
1912
1
  stop = mri_comment_field (&stopc);
1913
1914
1
  SKIP_WHITESPACE ();
1915
1916
1
  name = input_line_pointer;
1917
1
  if (!ISDIGIT (*name))
1918
1
    c = get_symbol_name (& name);
1919
0
  else
1920
0
    {
1921
0
      do
1922
0
  {
1923
0
    ++input_line_pointer;
1924
0
  }
1925
0
      while (ISDIGIT (*input_line_pointer));
1926
1927
0
      c = *input_line_pointer;
1928
0
      *input_line_pointer = '\0';
1929
1930
0
      if (line_label != NULL)
1931
0
  {
1932
0
    alc = XNEWVEC (char, strlen (S_GET_NAME (line_label))
1933
0
       + (input_line_pointer - name) + 1);
1934
0
    sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1935
0
    name = alc;
1936
0
  }
1937
0
    }
1938
1939
1
  sym = symbol_find_or_make (name);
1940
1
  c = restore_line_pointer (c);
1941
1
  free (alc);
1942
1943
1
  if (*input_line_pointer != ',')
1944
1
    align = 0;
1945
0
  else
1946
0
    {
1947
0
      ++input_line_pointer;
1948
0
      align = get_absolute_expression ();
1949
0
    }
1950
1951
1
  if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1952
0
    {
1953
0
      as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
1954
0
      mri_comment_end (stop, stopc);
1955
0
      return;
1956
0
    }
1957
1958
1
  S_SET_EXTERNAL (sym);
1959
1
  S_SET_SEGMENT (sym, bfd_com_section_ptr);
1960
1
  mri_common_symbol = sym;
1961
1962
1
#ifdef S_SET_ALIGN
1963
1
  if (align != 0)
1964
0
    S_SET_ALIGN (sym, align);
1965
#else
1966
  (void) align;
1967
#endif
1968
1969
1
  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
1
  if (*input_line_pointer == ',')
1982
0
    input_line_pointer += 2;
1983
1
  if (*input_line_pointer == ',')
1984
0
    input_line_pointer += 2;
1985
1986
1
  demand_empty_rest_of_line ();
1987
1988
1
  mri_comment_end (stop, stopc);
1989
1
}
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
157
{
2017
#ifdef LISTING
2018
  if (listing)
2019
    listing_source_file (file);
2020
#endif
2021
157
  register_dependency (file);
2022
157
#ifdef obj_app_file
2023
157
  obj_app_file (file);
2024
157
#endif
2025
157
}
2026
2027
void
2028
s_file (int ignore ATTRIBUTE_UNUSED)
2029
157
{
2030
157
  char *s;
2031
157
  int length;
2032
2033
  /* Some assemblers tolerate immediately following '"'.  */
2034
157
  if ((s = demand_copy_string (&length)) != 0)
2035
157
    {
2036
157
      new_logical_line_flags (s, -1, 1);
2037
2038
      /* In MRI mode, the preprocessor may have inserted an extraneous
2039
   backquote.  */
2040
157
      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
157
      demand_empty_rest_of_line ();
2046
157
      s_file_string (s);
2047
157
    }
2048
0
  else
2049
0
    ignore_rest_of_line ();
2050
157
}
2051
2052
static bool
2053
get_linefile_number (int *flag)
2054
73.7k
{
2055
73.7k
  offsetT val;
2056
2057
73.7k
  SKIP_WHITESPACE ();
2058
2059
73.7k
  if (is_end_of_stmt (*input_line_pointer))
2060
35.0k
    return false;
2061
2062
  /* Don't mistakenly interpret octal numbers as line numbers.  */
2063
38.6k
  if (*input_line_pointer == '0')
2064
1.17k
    {
2065
1.17k
      *flag = 0;
2066
1.17k
      ++input_line_pointer;
2067
1.17k
      return true;
2068
1.17k
    }
2069
2070
37.4k
  val = get_single_number ();
2071
  /* Zero was handled above; getting back zero indicates an error.  */
2072
37.4k
  if (val == 0)
2073
1.16k
    return false;
2074
2075
36.2k
#if defined (BFD64) || LONG_MAX > INT_MAX
2076
36.2k
  if (val < INT_MIN || val > INT_MAX)
2077
0
    return false;
2078
36.2k
#endif
2079
2080
36.2k
  *flag = val;
2081
2082
36.2k
  return true;
2083
36.2k
}
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
36.2k
{
2093
36.2k
  char *file = NULL;
2094
36.2k
  int linenum, flags = 0;
2095
2096
  /* The given number is that of the next line.  */
2097
36.2k
  if (!get_linefile_number (&linenum))
2098
1
    {
2099
1
      ignore_rest_of_line ();
2100
1
      return;
2101
1
    }
2102
2103
36.2k
  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
36.2k
  SKIP_WHITESPACE ();
2121
2122
36.2k
  if (*input_line_pointer == '"')
2123
36.2k
    {
2124
36.2k
      int this_flag;
2125
36.2k
      int length = 0;
2126
36.2k
      file = demand_copy_string (&length);
2127
36.2k
      if (file == NULL)
2128
0
  {
2129
0
    ignore_rest_of_line ();
2130
0
    return;
2131
0
  }
2132
2133
37.4k
      while (get_linefile_number (&this_flag))
2134
1.16k
  switch (this_flag)
2135
1.16k
    {
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
1.16k
    case 4:
2158
      /* We ignore these.  */
2159
1.16k
      break;
2160
2161
0
    default:
2162
0
      as_warn (_("unsupported flag %i in line directive"),
2163
0
         this_flag);
2164
0
      break;
2165
1.16k
    }
2166
2167
36.2k
      if (!is_end_of_stmt (*input_line_pointer))
2168
1.16k
  file = NULL;
2169
36.2k
    }
2170
5
  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
36.2k
  if (file || flags)
2178
35.1k
    {
2179
35.1k
      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
35.1k
      if (input_line_pointer[-1] == '\n')
2184
30.9k
  linenum--;
2185
2186
35.1k
      new_logical_line_flags (file, linenum, flags);
2187
#ifdef LISTING
2188
      if (listing)
2189
  listing_source_line (linenum);
2190
#endif
2191
35.1k
      return;
2192
35.1k
    }
2193
1.17k
  ignore_rest_of_line ();
2194
1.17k
}
2195
2196
/* Handle the .end pseudo-op.  Actually, the real work is done in
2197
   read_a_source_file.  */
2198
2199
void
2200
s_end (int ignore ATTRIBUTE_UNUSED)
2201
3
{
2202
3
  if (flag_mri)
2203
1
    {
2204
      /* The MRI assembler permits the start symbol to follow .end,
2205
   but we don't support that.  */
2206
1
      SKIP_WHITESPACE ();
2207
1
      if (!is_end_of_stmt (*input_line_pointer)
2208
0
    && *input_line_pointer != '*'
2209
0
    && *input_line_pointer != '!')
2210
0
  as_warn (_("start address not supported"));
2211
1
    }
2212
3
}
2213
2214
/* Handle the .err pseudo-op.  */
2215
2216
void
2217
s_err (int ignore ATTRIBUTE_UNUSED)
2218
0
{
2219
0
  as_bad (_(".err encountered"));
2220
0
  demand_empty_rest_of_line ();
2221
0
}
2222
2223
/* Handle the .error and .warning pseudo-ops.  */
2224
2225
void
2226
s_errwarn (int err)
2227
0
{
2228
0
  int len;
2229
  /* The purpose for the conditional assignment is not to
2230
     internationalize the directive itself, but that we need a
2231
     self-contained message, one that can be passed like the
2232
     demand_copy_C_string return value, and with no assumption on the
2233
     location of the name of the directive within the message.  */
2234
0
  const char *msg
2235
0
    = (err ? _(".error directive invoked in source file")
2236
0
       : _(".warning directive invoked in source file"));
2237
2238
0
  if (!is_it_end_of_statement ())
2239
0
    {
2240
0
      if (*input_line_pointer != '\"')
2241
0
  {
2242
0
    as_bad (_("%s argument must be a string"),
2243
0
      err ? ".error" : ".warning");
2244
0
    ignore_rest_of_line ();
2245
0
    return;
2246
0
  }
2247
2248
0
      msg = demand_copy_C_string (&len);
2249
0
      if (msg == NULL)
2250
0
  {
2251
0
    ignore_rest_of_line ();
2252
0
    return;
2253
0
  }
2254
0
    }
2255
2256
0
  if (err)
2257
0
    as_bad ("%s", msg);
2258
0
  else
2259
0
    as_warn ("%s", msg);
2260
0
  demand_empty_rest_of_line ();
2261
0
}
2262
2263
/* Handle the .errif and .warnif pseudo-ops.  */
2264
2265
static struct deferred_diag {
2266
  struct deferred_diag *next;
2267
  const char *file;
2268
  unsigned int lineno;
2269
  bool err;
2270
  expressionS exp;
2271
} *deferred_diag_head, **deferred_diag_tail = &deferred_diag_head;
2272
2273
static void
2274
s_errwarn_if (int err)
2275
0
{
2276
0
  struct deferred_diag *diag = XNEW (struct deferred_diag);
2277
0
  int errcnt = had_errors ();
2278
2279
0
  deferred_expression (&diag->exp);
2280
0
  if (errcnt != had_errors ())
2281
0
    {
2282
0
      ignore_rest_of_line ();
2283
0
      free (diag);
2284
0
      return;
2285
0
    }
2286
2287
0
  diag->err = err;
2288
0
  diag->file = as_where (&diag->lineno);
2289
0
  diag->next = NULL;
2290
0
  *deferred_diag_tail = diag;
2291
0
  deferred_diag_tail = &diag->next;
2292
2293
0
  demand_empty_rest_of_line ();
2294
0
}
2295
2296
void
2297
evaluate_deferred_diags (void)
2298
0
{
2299
0
  struct deferred_diag *diag;
2300
2301
0
  while ((diag = deferred_diag_head) != NULL)
2302
0
    {
2303
0
      if (!resolve_expression (&diag->exp) || diag->exp.X_op != O_constant)
2304
0
  as_warn_where (diag->file, diag->lineno,
2305
0
           _("expression does not evaluate to a constant"));
2306
0
      else if (diag->exp.X_add_number == 0)
2307
0
  ;
2308
0
      else if (diag->err)
2309
0
  as_bad_where (diag->file, diag->lineno,
2310
0
          _(".errif expression evaluates to true"));
2311
0
      else
2312
0
  as_warn_where (diag->file, diag->lineno,
2313
0
           _(".warnif expression evaluates to true"));
2314
0
      deferred_diag_head = diag->next;
2315
0
      free (diag);
2316
0
    }
2317
0
  deferred_diag_tail = &deferred_diag_head;
2318
0
}
2319
2320
/* Handle the MRI fail pseudo-op.  */
2321
2322
void
2323
s_fail (int ignore ATTRIBUTE_UNUSED)
2324
14.8k
{
2325
14.8k
  offsetT temp;
2326
14.8k
  char *stop = NULL;
2327
14.8k
  char stopc = 0;
2328
2329
14.8k
  if (flag_mri)
2330
304
    stop = mri_comment_field (&stopc);
2331
2332
14.8k
  temp = get_absolute_expression ();
2333
14.8k
  if (temp >= 500)
2334
304
    as_warn (_(".fail %ld encountered"), (long) temp);
2335
14.5k
  else
2336
14.5k
    as_bad (_(".fail %ld encountered"), (long) temp);
2337
2338
14.8k
  demand_empty_rest_of_line ();
2339
2340
14.8k
  if (flag_mri)
2341
304
    mri_comment_end (stop, stopc);
2342
14.8k
}
2343
2344
void
2345
s_fill (int ignore ATTRIBUTE_UNUSED)
2346
692
{
2347
692
  expressionS rep_exp;
2348
692
  offsetT size = 1;
2349
692
  valueT fill = 0;
2350
692
  char *p;
2351
2352
#ifdef md_flush_pending_output
2353
  md_flush_pending_output ();
2354
#endif
2355
2356
692
#ifdef md_cons_align
2357
692
  md_cons_align (1);
2358
692
#endif
2359
2360
692
  expression (&rep_exp);
2361
692
  if (*input_line_pointer == ',')
2362
29
    {
2363
29
      input_line_pointer++;
2364
29
      size = get_absolute_expression ();
2365
29
      if (*input_line_pointer == ',')
2366
16
  {
2367
16
    input_line_pointer++;
2368
16
    fill = get_absolute_expression ();
2369
16
  }
2370
29
    }
2371
2372
  /* This is to be compatible with BSD 4.2 AS, not for any rational reason.  */
2373
736
#define BSD_FILL_SIZE_CROCK_8 (8)
2374
692
  if (size > BSD_FILL_SIZE_CROCK_8)
2375
22
    {
2376
22
      as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
2377
22
      size = BSD_FILL_SIZE_CROCK_8;
2378
22
    }
2379
692
  if (size < 0)
2380
0
    {
2381
0
      as_warn (_("size negative; .fill ignored"));
2382
0
      size = 0;
2383
0
    }
2384
692
  else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
2385
627
    {
2386
627
      if (rep_exp.X_add_number < 0)
2387
8
  as_warn (_("repeat < 0; .fill ignored"));
2388
627
      size = 0;
2389
627
    }
2390
65
  else if (size && !need_pass_2)
2391
61
    {
2392
61
      if (now_seg == absolute_section && rep_exp.X_op != O_constant)
2393
1
  {
2394
1
    as_bad (_("non-constant fill count for absolute section"));
2395
1
    size = 0;
2396
1
  }
2397
60
      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
58
      else if (fill
2403
11
         && (rep_exp.X_op != O_constant || rep_exp.X_add_number != 0)
2404
11
         && in_bss ())
2405
6
  {
2406
6
    as_bad (_("attempt to fill section `%s' with non-zero value"),
2407
6
      segment_name (now_seg));
2408
6
    size = 0;
2409
6
  }
2410
61
    }
2411
2412
692
  if (size && !need_pass_2)
2413
52
    {
2414
52
      if (now_seg == absolute_section)
2415
5
  abs_section_offset += (valueT) rep_exp.X_add_number * size;
2416
2417
52
      if (rep_exp.X_op == O_constant)
2418
18
  {
2419
18
    p = frag_var (rs_fill, size, size, 0, NULL,
2420
18
      rep_exp.X_add_number, NULL);
2421
18
  }
2422
34
      else
2423
34
  {
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
34
    symbolS *rep_sym;
2430
34
    rep_sym = make_expr_symbol (&rep_exp);
2431
34
    if (size != 1)
2432
2
      {
2433
2
        expressionS size_exp;
2434
2
        size_exp.X_op = O_constant;
2435
2
        size_exp.X_add_number = size;
2436
2437
2
        rep_exp.X_op = O_multiply;
2438
2
        rep_exp.X_add_symbol = rep_sym;
2439
2
        rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
2440
2
        rep_exp.X_add_number = 0;
2441
2
        rep_sym = make_expr_symbol (&rep_exp);
2442
2
      }
2443
2444
34
    p = frag_var (rs_space, size, size, 0, rep_sym, 0, NULL);
2445
34
  }
2446
2447
52
      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
63
#define BSD_FILL_SIZE_CROCK_4 (4)
2455
52
      md_number_to_chars (p, fill,
2456
52
        (size > BSD_FILL_SIZE_CROCK_4
2457
52
         ? BSD_FILL_SIZE_CROCK_4
2458
52
         : 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
52
    }
2464
692
  demand_empty_rest_of_line ();
2465
692
}
2466
2467
void
2468
s_globl (int ignore ATTRIBUTE_UNUSED)
2469
5
{
2470
5
  char *name;
2471
5
  int c;
2472
5
  symbolS *symbolP;
2473
5
  char *stop = NULL;
2474
5
  char stopc = 0;
2475
2476
5
  if (flag_mri)
2477
2
    stop = mri_comment_field (&stopc);
2478
2479
5
  do
2480
5
    {
2481
5
      if ((name = read_symbol_name ()) == NULL)
2482
1
  return;
2483
2484
4
      symbolP = symbol_find_or_make (name);
2485
4
      S_SET_EXTERNAL (symbolP);
2486
2487
4
      SKIP_WHITESPACE ();
2488
4
      c = *input_line_pointer;
2489
4
      if (c == ',')
2490
0
  {
2491
0
    input_line_pointer++;
2492
0
    SKIP_WHITESPACE ();
2493
0
    if (is_end_of_stmt (*input_line_pointer))
2494
0
      c = '\n';
2495
0
  }
2496
2497
4
      free (name);
2498
4
    }
2499
5
  while (c == ',');
2500
2501
4
  demand_empty_rest_of_line ();
2502
2503
4
  if (flag_mri)
2504
1
    mri_comment_end (stop, stopc);
2505
4
}
2506
2507
/* Handle the MRI IRP and IRPC pseudo-ops.  */
2508
2509
void
2510
s_irp (int irpc)
2511
641
{
2512
641
  char * eol;
2513
641
  const char * file;
2514
641
  unsigned int line;
2515
641
  sb s;
2516
641
  const char *err;
2517
641
  sb out;
2518
2519
641
  file = as_where (&line);
2520
2521
641
  eol = find_end_of_line (input_line_pointer, 0);
2522
641
  sb_build (&s, eol - input_line_pointer);
2523
641
  sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2524
641
  input_line_pointer = eol;
2525
2526
641
  sb_new (&out);
2527
2528
641
  err = expand_irp (irpc, 0, &s, &out, get_macro_line_sb);
2529
641
  if (err != NULL)
2530
41
    as_bad_where (file, line, "%s", err);
2531
2532
641
  sb_kill (&s);
2533
2534
641
  input_scrub_include_sb (&out, input_line_pointer, expanding_repeat);
2535
641
  sb_kill (&out);
2536
641
  buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2537
641
}
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
12
{
2547
12
  enum linkonce_type type;
2548
2549
12
  SKIP_WHITESPACE ();
2550
2551
12
  type = LINKONCE_DISCARD;
2552
2553
12
  if (!is_end_of_stmt (*input_line_pointer))
2554
12
    {
2555
12
      char *s;
2556
12
      char c;
2557
2558
12
      c = get_symbol_name (& s);
2559
12
      if (strcasecmp (s, "discard") == 0)
2560
0
  type = LINKONCE_DISCARD;
2561
12
      else if (strcasecmp (s, "one_only") == 0)
2562
0
  type = LINKONCE_ONE_ONLY;
2563
12
      else if (strcasecmp (s, "same_size") == 0)
2564
0
  type = LINKONCE_SAME_SIZE;
2565
12
      else if (strcasecmp (s, "same_contents") == 0)
2566
9
  type = LINKONCE_SAME_CONTENTS;
2567
3
      else
2568
3
  as_warn (_("unrecognized .linkonce type `%s'"), s);
2569
2570
12
      (void) restore_line_pointer (c);
2571
12
    }
2572
2573
#ifdef obj_handle_link_once
2574
  obj_handle_link_once (type);
2575
#else /* ! defined (obj_handle_link_once) */
2576
12
  {
2577
12
    flagword flags;
2578
2579
12
    if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
2580
12
      as_warn (_(".linkonce is not supported for this object file format"));
2581
2582
12
    flags = bfd_section_flags (now_seg);
2583
12
    flags |= SEC_LINK_ONCE;
2584
12
    switch (type)
2585
12
      {
2586
0
      default:
2587
0
  abort ();
2588
3
      case LINKONCE_DISCARD:
2589
3
  flags |= SEC_LINK_DUPLICATES_DISCARD;
2590
3
  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
9
      case LINKONCE_SAME_CONTENTS:
2598
9
  flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
2599
9
  break;
2600
12
      }
2601
12
    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
12
  }
2605
0
#endif /* ! defined (obj_handle_link_once) */
2606
2607
0
  demand_empty_rest_of_line ();
2608
12
}
2609
2610
void
2611
bss_alloc (symbolS *symbolP, addressT size, unsigned int align)
2612
4
{
2613
4
  char *pfrag;
2614
4
  segT current_seg = now_seg;
2615
4
  subsegT current_subseg = now_subseg;
2616
4
  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
4
  subseg_set (bss_seg, 1);
2634
2635
4
  if (align > OCTETS_PER_BYTE_POWER)
2636
2
    {
2637
2
      record_alignment (bss_seg, align);
2638
2
      frag_align (align, 0, 0);
2639
2
    }
2640
2641
  /* Detach from old frag.  */
2642
4
  if (S_GET_SEGMENT (symbolP) == bss_seg)
2643
0
    symbol_get_frag (symbolP)->fr_symbol = NULL;
2644
2645
4
  symbol_set_frag (symbolP, frag_now);
2646
4
  pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size * OCTETS_PER_BYTE, NULL);
2647
4
  *pfrag = 0;
2648
2649
4
#ifdef S_SET_SIZE
2650
4
  S_SET_SIZE (symbolP, size);
2651
4
#endif
2652
4
  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
4
  subseg_set (current_seg, current_subseg);
2663
4
}
2664
2665
offsetT
2666
parse_align (int align_bytes)
2667
139
{
2668
139
  expressionS exp;
2669
139
  addressT align;
2670
2671
139
  SKIP_WHITESPACE ();
2672
139
  if (*input_line_pointer != ',')
2673
0
    {
2674
3
    no_align:
2675
3
      as_bad (_("expected alignment after size"));
2676
3
      ignore_rest_of_line ();
2677
3
      return -1;
2678
0
    }
2679
2680
139
  input_line_pointer++;
2681
139
  SKIP_WHITESPACE ();
2682
2683
139
  align = get_absolute_expr (&exp);
2684
139
  if (exp.X_op == O_absent)
2685
3
    goto no_align;
2686
2687
136
  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
136
  if (align_bytes && align != 0)
2694
8
    {
2695
      /* convert to a power of 2 alignment */
2696
8
      unsigned int alignp2 = 0;
2697
16
      while ((align & 1) == 0)
2698
8
  align >>= 1, ++alignp2;
2699
8
      if (align != 1)
2700
8
  {
2701
8
    as_bad (_("alignment not a power of 2"));
2702
8
    ignore_rest_of_line ();
2703
8
    return -1;
2704
8
  }
2705
0
      align = alignp2;
2706
0
    }
2707
128
  return align;
2708
136
}
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
3
{
2719
3
  addressT align = 0;
2720
2721
3
  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
3
  else
2728
    /* Assume some objects may require alignment on some systems.  */
2729
3
    TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
2730
2731
3
  bss_alloc (symbolP, size, align);
2732
3
  return symbolP;
2733
3
}
2734
2735
void
2736
s_lcomm (int needs_align)
2737
0
{
2738
0
  s_comm_internal (needs_align, s_lcomm_internal);
2739
0
}
2740
2741
void
2742
s_lcomm_bytes (int needs_align)
2743
0
{
2744
0
  s_comm_internal (needs_align * 2, s_lcomm_internal);
2745
0
}
2746
2747
void
2748
s_lsym (int ignore ATTRIBUTE_UNUSED)
2749
76
{
2750
76
  char *name;
2751
76
  expressionS exp;
2752
76
  symbolS *symbolP;
2753
2754
  /* We permit ANY defined expression: BSD4.2 demands constants.  */
2755
76
  if ((name = read_symbol_name ()) == NULL)
2756
12
    return;
2757
2758
64
  if (*input_line_pointer != ',')
2759
7
    {
2760
7
      as_bad (_("expected comma after \"%s\""), name);
2761
7
      goto err_out;
2762
7
    }
2763
2764
57
  input_line_pointer++;
2765
57
  expression_and_evaluate (&exp);
2766
2767
57
  if (exp.X_op != O_constant
2768
16
      && exp.X_op != O_register)
2769
0
    {
2770
0
      as_bad (_("bad expression"));
2771
0
      goto err_out;
2772
0
    }
2773
2774
57
  symbolP = symbol_find_or_make (name);
2775
2776
57
  if (S_GET_SEGMENT (symbolP) == undefined_section)
2777
3
    {
2778
      /* The name might be an undefined .global symbol; be sure to
2779
   keep the "external" bit.  */
2780
3
      S_SET_SEGMENT (symbolP,
2781
3
         (exp.X_op == O_constant
2782
3
          ? absolute_section
2783
3
          : reg_section));
2784
3
      S_SET_VALUE (symbolP, exp.X_add_number);
2785
3
    }
2786
54
  else
2787
54
    {
2788
54
      as_bad (_("symbol `%s' is already defined"), name);
2789
54
    }
2790
2791
57
  demand_empty_rest_of_line ();
2792
57
  free (name);
2793
57
  return;
2794
2795
7
 err_out:
2796
7
  ignore_rest_of_line ();
2797
7
  free (name);
2798
7
  return;
2799
57
}
2800
2801
/* Read a line into an sb.  Returns the character that ended the line
2802
   or zero if there are no more lines.  */
2803
2804
static int
2805
get_line_sb (sb *line, int in_macro)
2806
6.13k
{
2807
6.13k
  char *eol;
2808
2809
6.13k
  if (input_line_pointer[-1] == '\n')
2810
4.30k
    bump_line_counters ();
2811
2812
6.13k
  if (input_line_pointer >= buffer_limit)
2813
3
    {
2814
3
      buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2815
3
      if (buffer_limit == 0)
2816
3
  return 0;
2817
3
    }
2818
2819
6.12k
  eol = _find_end_of_line (input_line_pointer, flag_m68k_mri, 0, in_macro);
2820
6.12k
  sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
2821
6.12k
  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
6.12k
  return *input_line_pointer++;
2829
6.13k
}
2830
2831
static size_t
2832
get_non_macro_line_sb (sb *line)
2833
944
{
2834
944
  return get_line_sb (line, 0);
2835
944
}
2836
2837
static size_t
2838
get_macro_line_sb (sb *line)
2839
5.18k
{
2840
5.18k
  return get_line_sb (line, 1);
2841
5.18k
}
2842
2843
/* Define a macro.  This is an interface to macro.c.  */
2844
2845
void
2846
s_macro (int ignore ATTRIBUTE_UNUSED)
2847
22
{
2848
22
  char *eol;
2849
22
  sb s;
2850
22
  macro_entry *macro;
2851
2852
22
  eol = find_end_of_line (input_line_pointer, 0);
2853
22
  sb_build (&s, eol - input_line_pointer);
2854
22
  sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2855
22
  input_line_pointer = eol;
2856
2857
22
  if (line_label != NULL)
2858
0
    {
2859
0
      sb label;
2860
0
      size_t len;
2861
0
      const char *name;
2862
2863
0
      name = S_GET_NAME (line_label);
2864
0
      len = strlen (name);
2865
0
      sb_build (&label, len);
2866
0
      sb_add_buffer (&label, name, len);
2867
0
      macro = define_macro (&s, &label, get_macro_line_sb);
2868
0
      sb_kill (&label);
2869
0
    }
2870
22
  else
2871
22
    macro = define_macro (&s, NULL, get_macro_line_sb);
2872
22
  if (macro != NULL)
2873
14
    {
2874
14
      if (line_label != NULL)
2875
0
  {
2876
0
    S_SET_SEGMENT (line_label, absolute_section);
2877
0
    S_SET_VALUE (line_label, 0);
2878
0
    symbol_set_frag (line_label, &zero_address_frag);
2879
0
  }
2880
2881
14
      if (((NO_PSEUDO_DOT || flag_m68k_mri)
2882
0
     && str_hash_find (po_hash, macro->name) != NULL)
2883
14
    || (!flag_m68k_mri
2884
14
        && macro->name[0] == '.'
2885
0
        && str_hash_find (po_hash, macro->name + 1) != NULL))
2886
0
  {
2887
0
    as_warn_where (macro->file, macro->line,
2888
0
       _("attempt to redefine pseudo-op `%s' ignored"),
2889
0
       macro->name);
2890
0
    str_hash_delete (macro_hash, macro->name);
2891
0
  }
2892
14
    }
2893
2894
22
  sb_kill (&s);
2895
22
}
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
19
{
2917
19
  int on;
2918
#ifdef MRI_MODE_CHANGE
2919
  int old_flag;
2920
#endif
2921
2922
19
  on = get_absolute_expression ();
2923
#ifdef MRI_MODE_CHANGE
2924
  old_flag = flag_mri;
2925
#endif
2926
19
  if (on != 0)
2927
9
    {
2928
9
      flag_mri = 1;
2929
#ifdef TC_M68K
2930
      flag_m68k_mri = 1;
2931
#endif
2932
9
      lex_type['?'] = LEX_BEGIN_NAME | LEX_NAME;
2933
9
    }
2934
10
  else
2935
10
    {
2936
10
      flag_mri = 0;
2937
#ifdef TC_M68K
2938
      flag_m68k_mri = 0;
2939
#endif
2940
10
      lex_type['?'] = LEX_QM;
2941
10
    }
2942
2943
  /* Operator precedence changes in m68k MRI mode, so we need to
2944
     update the operator rankings.  */
2945
19
  expr_set_precedence ();
2946
2947
#ifdef MRI_MODE_CHANGE
2948
  if (on != old_flag)
2949
    MRI_MODE_CHANGE (on);
2950
#endif
2951
2952
19
  demand_empty_rest_of_line ();
2953
19
}
2954
2955
/* Handle changing the location counter.  */
2956
2957
static void
2958
do_org (segT segment, expressionS *exp, int fill)
2959
669
{
2960
669
  if (segment != now_seg
2961
531
      && segment != absolute_section
2962
0
      && segment != expr_section)
2963
0
    as_bad (_("invalid segment \"%s\""), segment_name (segment));
2964
2965
669
  if (now_seg == absolute_section)
2966
137
    {
2967
137
      if (fill != 0)
2968
0
  as_warn (_("ignoring fill value in absolute section"));
2969
137
      if (exp->X_op != O_constant)
2970
0
  {
2971
0
    as_bad (_("only constant offsets supported in absolute section"));
2972
0
    exp->X_add_number = 0;
2973
0
  }
2974
137
      abs_section_offset = exp->X_add_number;
2975
137
    }
2976
532
  else
2977
532
    {
2978
532
      char *p;
2979
532
      symbolS *sym = exp->X_add_symbol;
2980
532
      offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
2981
2982
532
      if (fill && in_bss ())
2983
0
  as_warn (_("ignoring fill value in section `%s'"),
2984
0
     segment_name (now_seg));
2985
2986
532
      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
532
      p = frag_var (rs_org, 1, 1, 0, sym, off, NULL);
2994
532
      *p = fill;
2995
532
    }
2996
669
}
2997
2998
void
2999
s_org (int ignore ATTRIBUTE_UNUSED)
3000
128
{
3001
128
  segT segment;
3002
128
  expressionS exp;
3003
128
  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
128
  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
128
  segment = get_known_segmented_expression (&exp);
3032
128
  if (*input_line_pointer == ',')
3033
2
    {
3034
2
      input_line_pointer++;
3035
2
      temp_fill = get_absolute_expression ();
3036
2
    }
3037
126
  else
3038
126
    temp_fill = 0;
3039
3040
128
  if (!need_pass_2)
3041
128
    do_org (segment, &exp, temp_fill);
3042
3043
128
  demand_empty_rest_of_line ();
3044
128
}
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
666
{
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
666
  as_bad ("MRI mode not supported for this target");
3134
666
  ignore_rest_of_line ();
3135
666
#endif /* ! TC_M68K */
3136
666
}
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
523
{
3189
523
  as_warn (_(".end%c encountered without preceding %s"),
3190
523
     endr ? 'r' : 'm',
3191
523
     endr ? ".rept, .irp, or .irpc" : ".macro");
3192
523
  demand_empty_rest_of_line ();
3193
523
}
3194
3195
/* Handle the .rept pseudo-op.  */
3196
3197
void
3198
s_rept (int expand_count)
3199
87
{
3200
87
  size_t count;
3201
3202
87
  count = get_absolute_expression ();
3203
3204
87
  do_repeat (count, "REPT", "ENDR", expand_count ? "" : NULL);
3205
87
}
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
87
{
3218
87
  sb one;
3219
87
  sb many;
3220
87
  size_t total, limit;
3221
87
  unsigned int line;
3222
87
  const char *file = as_where_top (&line);
3223
3224
87
  demand_empty_rest_of_line ();
3225
87
  --input_line_pointer;
3226
3227
87
  sb_new (&one);
3228
87
  if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
3229
28
    {
3230
28
      as_bad (_("%s without %s"), start, end);
3231
28
      sb_kill (&one);
3232
28
      return;
3233
28
    }
3234
3235
59
  sb_terminate (&one);
3236
3237
59
  limit = (size_t) LONG_MAX < 0xffffffff ? (size_t) LONG_MAX : 0xffffffff;
3238
59
  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
59
  if (expander != NULL && !*expander && strstr (one.ptr, "\\+") != NULL)
3246
4
    {
3247
      /* The 3 here and below are arbitrary, added in an attempt to limit
3248
   re-allocation needs in sb_add_...() for moderate repeat counts.  */
3249
4
      sb_build (&many, count * (one.len + 3));
3250
3251
4
      for (size_t done = 0; count-- > 0; ++done)
3252
0
  {
3253
0
    const char *ptr, *bs;
3254
0
    sb processed;
3255
3256
0
    sb_build (&processed, one.len + 3);
3257
3258
0
    for (ptr = one.ptr; (bs = strchr (ptr, '\\')) != NULL; )
3259
0
      {
3260
0
        sb_add_buffer (&processed, ptr, bs - ptr);
3261
0
        switch (bs[1])
3262
0
    {
3263
0
      char scratch[24];
3264
3265
0
    default:
3266
0
      sb_add_char (&processed, '\\');
3267
0
      sb_add_char (&processed, bs[1]);
3268
0
      ptr = bs + 2;
3269
0
      break;
3270
3271
0
    case '\0':
3272
0
      as_warn (_("`\\' at end of line/statement; ignored"));
3273
0
      ptr = bs + 1;
3274
0
      break;
3275
3276
0
    case '\\':
3277
0
      sb_add_char (&processed, '\\');
3278
0
      ptr = bs + 2;
3279
0
      break;
3280
3281
0
    case '+':
3282
0
      snprintf (scratch, ARRAY_SIZE (scratch), "%zu", done);
3283
0
      sb_add_string (&processed, scratch);
3284
0
      ptr = bs + 2;
3285
0
      break;
3286
0
    }
3287
0
      }
3288
3289
0
    sb_add_string (&processed, ptr);
3290
3291
0
    sb_add_sb (&many, &processed);
3292
0
    sb_kill (&processed);
3293
0
  }
3294
4
    }
3295
55
  else if (expander == NULL || !*expander || strstr (one.ptr, expander) == NULL)
3296
55
    {
3297
55
      sb_build (&many, count * one.len);
3298
7.45k
      while (count-- > 0)
3299
7.39k
  sb_add_sb (&many, &one);
3300
55
    }
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
59
  sb_kill (&one);
3325
3326
59
  input_scrub_include_sb (&many, input_line_pointer, expanding_repeat);
3327
59
  sb_kill (&many);
3328
59
  buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3329
59
}
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
8.95k
{
3350
8.95k
  symbolS *symbolP;
3351
3352
8.95k
  if (name[0] == '.' && name[1] == '\0')
3353
541
    {
3354
      /* Turn '. = mumble' into a .org mumble.  */
3355
541
      segT segment;
3356
541
      expressionS exp;
3357
3358
541
      segment = get_known_segmented_expression (&exp);
3359
3360
541
      if (!need_pass_2)
3361
541
  do_org (segment, &exp, 0);
3362
3363
541
      return;
3364
541
    }
3365
3366
8.41k
  if ((symbolP = symbol_find (name)) == NULL
3367
248
      && (symbolP = md_undefined_symbol (name)) == NULL)
3368
248
    {
3369
248
      symbolP = symbol_find_or_make (name);
3370
248
#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
248
      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
248
#endif
3382
#ifdef obj_assign_symbol
3383
      obj_assign_symbol (symbolP);
3384
#endif
3385
248
    }
3386
3387
8.41k
  if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3388
8.15k
    {
3389
8.15k
      if ((mode != 0 || !S_IS_VOLATILE (symbolP))
3390
483
    && !S_CAN_BE_REDEFINED (symbolP))
3391
483
  {
3392
483
    as_bad (_("symbol `%s' is already defined"), name);
3393
483
    ignore_rest_of_line ();
3394
483
    input_line_pointer--;
3395
483
    return;
3396
483
  }
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
7.67k
      else if (S_IS_VOLATILE (symbolP))
3401
7.67k
  symbolP = symbol_clone (symbolP, 1);
3402
7.67k
      S_CLEAR_WEAKREFR (symbolP);
3403
7.67k
    }
3404
3405
7.92k
  if (mode == 0)
3406
7.89k
    S_SET_VOLATILE (symbolP);
3407
33
  else if (mode < 0)
3408
32
    S_SET_FORWARD_REF (symbolP);
3409
3410
7.92k
  pseudo_set (symbolP);
3411
7.92k
}
3412
3413
/* Handle the .equ, .equiv, .eqv, and .set directives.  If EQUIV is 1,
3414
   then this is .equiv, and it is an error if the symbol is already
3415
   defined.  If EQUIV is -1, the symbol additionally is a forward
3416
   reference.  */
3417
3418
void
3419
s_set (int equiv)
3420
13
{
3421
13
  char *name;
3422
3423
  /* Especial apologies for the random logic:
3424
     this just grew, and could be parsed much more simply!
3425
     Dean in haste.  */
3426
13
  if ((name = read_symbol_name ()) == NULL)
3427
0
    return;
3428
3429
13
  if (*input_line_pointer != ',')
3430
2
    {
3431
2
      as_bad (_("expected comma after \"%s\""), name);
3432
2
      ignore_rest_of_line ();
3433
2
      free (name);
3434
2
      return;
3435
2
    }
3436
3437
11
  input_line_pointer++;
3438
11
  assign_symbol (name, equiv);
3439
11
  demand_empty_rest_of_line ();
3440
11
  free (name);
3441
11
}
3442
3443
void
3444
s_space (int mult)
3445
74
{
3446
74
  expressionS exp;
3447
74
  expressionS val;
3448
74
  char *p = 0;
3449
74
  char *stop = NULL;
3450
74
  char stopc = 0;
3451
74
  int bytes;
3452
3453
#ifdef md_flush_pending_output
3454
  md_flush_pending_output ();
3455
#endif
3456
3457
74
  switch (mult)
3458
74
    {
3459
5
    case 'x':
3460
5
#ifdef X_PRECISION
3461
5
# ifndef P_PRECISION
3462
5
#  define P_PRECISION     X_PRECISION
3463
5
#  define P_PRECISION_PAD X_PRECISION_PAD
3464
5
# endif
3465
5
      mult = (X_PRECISION + X_PRECISION_PAD) * sizeof (LITTLENUM_TYPE);
3466
5
      if (!mult)
3467
0
#endif
3468
0
  mult = 12;
3469
5
      break;
3470
3471
0
    case 'p':
3472
0
#ifdef P_PRECISION
3473
0
      mult = (P_PRECISION + P_PRECISION_PAD) * sizeof (LITTLENUM_TYPE);
3474
0
      if (!mult)
3475
0
#endif
3476
0
  mult = 12;
3477
0
      break;
3478
74
    }
3479
3480
74
#ifdef md_cons_align
3481
74
  md_cons_align (1);
3482
74
#endif
3483
3484
74
  if (flag_mri)
3485
28
    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
74
  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
74
  bytes = mult;
3528
3529
74
  expression (&exp);
3530
3531
74
  SKIP_WHITESPACE ();
3532
74
  if (*input_line_pointer == ',')
3533
47
    {
3534
47
      ++input_line_pointer;
3535
47
      expression (&val);
3536
47
    }
3537
27
  else
3538
27
    {
3539
27
      val.X_op = O_constant;
3540
27
      val.X_add_number = 0;
3541
27
    }
3542
3543
74
  if ((val.X_op != O_constant
3544
61
       || val.X_add_number < - 0x80
3545
54
       || val.X_add_number > 0xff
3546
51
       || (mult != 0 && mult != 1 && val.X_add_number != 0))
3547
26
      && (now_seg != absolute_section && !in_bss ()))
3548
20
    {
3549
20
      resolve_expression (&exp);
3550
20
      if (exp.X_op != O_constant)
3551
0
  as_bad (_("unsupported variable size or fill value"));
3552
20
      else
3553
20
  {
3554
20
    offsetT i;
3555
3556
    /* PR 20901: Check for excessive values.
3557
       FIXME: 1<<10 is an arbitrary limit.  Maybe use maxpagesize instead ?  */
3558
20
    if (exp.X_add_number < 0 || exp.X_add_number > (1 << 10))
3559
1
      as_bad (_("size value for space directive too large: %lx"),
3560
1
        (long) exp.X_add_number);
3561
19
    else
3562
19
      {
3563
19
        if (mult == 0)
3564
13
    mult = 1;
3565
19
        bytes = mult * exp.X_add_number;
3566
3567
1.01k
        for (i = 0; i < exp.X_add_number; i++)
3568
993
    emit_expr (&val, mult);
3569
19
      }
3570
20
  }
3571
20
    }
3572
54
  else
3573
54
    {
3574
54
      if (now_seg == absolute_section || mri_common_symbol != NULL)
3575
13
  resolve_expression (&exp);
3576
3577
54
      if (exp.X_op == O_constant)
3578
51
  {
3579
51
    addressT repeat = exp.X_add_number;
3580
51
    addressT total;
3581
3582
51
    bytes = 0;
3583
51
    if ((offsetT) repeat < 0)
3584
7
      {
3585
7
        as_warn (_(".space repeat count is negative, ignored"));
3586
7
        goto getout;
3587
7
      }
3588
44
    if (repeat == 0)
3589
4
      {
3590
4
        if (!flag_mri)
3591
2
    as_warn (_(".space repeat count is zero, ignored"));
3592
4
        goto getout;
3593
4
      }
3594
40
    if ((unsigned int) mult <= 1)
3595
38
      total = repeat;
3596
2
    else if (_bfd_mul_overflow (repeat, mult, &total)
3597
2
       || (offsetT) total < 0)
3598
0
      {
3599
0
        as_warn (_(".space repeat count overflow, ignored"));
3600
0
        goto getout;
3601
0
      }
3602
40
    bytes = total;
3603
3604
    /* If we are in the absolute section, just bump the offset.  */
3605
40
    if (now_seg == absolute_section)
3606
5
      {
3607
5
        if (val.X_op != O_constant || val.X_add_number != 0)
3608
4
    as_warn (_("ignoring fill value in absolute section"));
3609
5
        abs_section_offset += total;
3610
5
        goto getout;
3611
5
      }
3612
3613
    /* If we are secretly in an MRI common section, then
3614
       creating space just increases the size of the common
3615
       symbol.  */
3616
35
    if (mri_common_symbol != NULL)
3617
2
      {
3618
2
        S_SET_VALUE (mri_common_symbol,
3619
2
         S_GET_VALUE (mri_common_symbol) + total);
3620
2
        goto getout;
3621
2
      }
3622
3623
33
    if (!need_pass_2)
3624
33
      p = frag_var (rs_fill, 1, 1, 0, NULL, total, NULL);
3625
33
  }
3626
3
      else
3627
3
  {
3628
3
    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
3
    if (mri_common_symbol != NULL)
3635
0
      {
3636
0
        as_bad (_("space allocation too complex in common section"));
3637
0
        mri_common_symbol = NULL;
3638
0
      }
3639
3640
3
    if (!need_pass_2)
3641
3
      p = frag_var (rs_space, 1, 1, 0, make_expr_symbol (&exp), 0, NULL);
3642
3
  }
3643
3644
36
      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
36
      else if (p)
3648
36
  *p = val.X_add_number;
3649
36
    }
3650
3651
74
 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
74
  if (flag_mri && (bytes & 1) != 0)
3657
14
    mri_pending_align = 1;
3658
3659
74
  demand_empty_rest_of_line ();
3660
3661
74
  if (flag_mri)
3662
28
    mri_comment_end (stop, stopc);
3663
74
}
3664
3665
void
3666
s_nop (int ignore ATTRIBUTE_UNUSED)
3667
3
{
3668
3
  expressionS exp;
3669
3
  fragS *start;
3670
3
  addressT start_off;
3671
3
  offsetT frag_off;
3672
3673
#ifdef md_flush_pending_output
3674
  md_flush_pending_output ();
3675
#endif
3676
3677
3
  SKIP_WHITESPACE ();
3678
3
  expression (&exp);
3679
3
  demand_empty_rest_of_line ();
3680
3681
3
  start = frag_now;
3682
3
  start_off = frag_now_fix ();
3683
3
  do
3684
3
    {
3685
#ifdef md_emit_single_noop
3686
      md_emit_single_noop;
3687
#else
3688
3
      char *nop;
3689
3690
3
#ifndef md_single_noop_insn
3691
3
#define md_single_noop_insn "nop"
3692
3
#endif
3693
      /* md_assemble might modify its argument, so
3694
   we must pass it a string that is writable.  */
3695
3
      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
3
      char *saved_ilp = input_line_pointer;
3702
3
      md_assemble (nop);
3703
3
      input_line_pointer = saved_ilp;
3704
3
      free (nop);
3705
3
#endif
3706
#ifdef md_flush_pending_output
3707
      md_flush_pending_output ();
3708
#endif
3709
3
    } while (exp.X_op == O_constant
3710
1
       && 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
3
}
3714
3715
/* Use this to specify the amount of memory allocated for representing
3716
   the nops.  Needs to be large enough to hold any fixed size prologue
3717
   plus the replicating portion.  */
3718
#ifndef MAX_MEM_FOR_RS_SPACE_NOP
3719
# define MAX_MEM_FOR_RS_SPACE_NOP 1
3720
#endif
3721
3722
void
3723
s_nops (int ignore ATTRIBUTE_UNUSED)
3724
20
{
3725
20
  expressionS exp;
3726
20
  expressionS val;
3727
3728
#ifdef md_flush_pending_output
3729
  md_flush_pending_output ();
3730
#endif
3731
3732
20
  SKIP_WHITESPACE ();
3733
20
  expression (&exp);
3734
  /* Note - this expression is tested for an absolute value in
3735
     write.c:relax_segment().  */
3736
3737
20
  SKIP_WHITESPACE ();
3738
20
  if (*input_line_pointer == ',')
3739
1
    {
3740
1
      ++input_line_pointer;
3741
1
      expression (&val);
3742
1
    }
3743
19
  else
3744
19
    {
3745
19
      val.X_op = O_constant;
3746
19
      val.X_add_number = 0;
3747
19
    }
3748
3749
20
  if (val.X_op != O_constant)
3750
0
    {
3751
0
      as_bad (_("unsupported variable nop control in .nops directive"));
3752
0
      val.X_op = O_constant;
3753
0
      val.X_add_number = 0;
3754
0
    }
3755
20
  else if (val.X_add_number < 0)
3756
1
    {
3757
1
      as_warn (_("negative nop control byte, ignored"));
3758
1
      val.X_add_number = 0;
3759
1
    }
3760
3761
20
  demand_empty_rest_of_line ();
3762
3763
20
  if (need_pass_2)
3764
    /* Ignore this directive if we are going to perform a second pass.  */
3765
0
    return;
3766
3767
  /* Store the no-op instruction control byte in the first byte of frag.  */
3768
20
  char *p;
3769
20
  symbolS *sym = make_expr_symbol (&exp);
3770
20
  p = frag_var (rs_space_nop, MAX_MEM_FOR_RS_SPACE_NOP, 1, 0, sym, 0, NULL);
3771
20
  *p = val.X_add_number;
3772
20
}
3773
3774
/* Obtain the size of a floating point number, given a type.  */
3775
3776
static int
3777
float_length (int float_type, int *pad_p)
3778
4
{
3779
4
  int length, pad = 0;
3780
3781
4
  switch (float_type)
3782
4
    {
3783
0
    case 'b':
3784
0
    case 'B':
3785
0
    case 'h':
3786
0
    case 'H':
3787
0
      length = 2;
3788
0
      break;
3789
3790
4
    case 'f':
3791
4
    case 'F':
3792
4
    case 's':
3793
4
    case 'S':
3794
4
      length = 4;
3795
4
      break;
3796
3797
0
    case 'd':
3798
0
    case 'D':
3799
0
    case 'r':
3800
0
    case 'R':
3801
0
      length = 8;
3802
0
      break;
3803
3804
0
    case 'x':
3805
0
    case 'X':
3806
0
#ifdef X_PRECISION
3807
0
      length = X_PRECISION * sizeof (LITTLENUM_TYPE);
3808
0
      pad = X_PRECISION_PAD * sizeof (LITTLENUM_TYPE);
3809
0
      if (!length)
3810
0
#endif
3811
0
  length = 12;
3812
0
      break;
3813
3814
0
    case 'p':
3815
0
    case 'P':
3816
0
#ifdef P_PRECISION
3817
0
      length = P_PRECISION * sizeof (LITTLENUM_TYPE);
3818
0
      pad = P_PRECISION_PAD * sizeof (LITTLENUM_TYPE);
3819
0
      if (!length)
3820
0
#endif
3821
0
  length = 12;
3822
0
      break;
3823
3824
0
    default:
3825
0
      as_bad (_("unknown floating type '%c'"), float_type);
3826
0
      length = -1;
3827
0
      break;
3828
4
    }
3829
3830
4
  if (pad_p)
3831
4
    *pad_p = pad;
3832
3833
4
  return length;
3834
4
}
3835
3836
static int
3837
parse_one_float (int float_type, char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT])
3838
362
{
3839
362
  int length;
3840
3841
362
  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
362
  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
362
  if (input_line_pointer[0] == ':')
3854
0
    {
3855
0
      ++input_line_pointer;
3856
0
      length = hex_float (float_type, temp);
3857
0
      if (length < 0)
3858
0
  {
3859
0
    ignore_rest_of_line ();
3860
0
    return length;
3861
0
  }
3862
0
    }
3863
362
  else
3864
362
    {
3865
362
      const char *err;
3866
3867
362
      err = md_atof (float_type, temp, &length);
3868
362
      know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3869
362
      know (err != NULL || length > 0);
3870
362
      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
362
    }
3877
3878
362
  return length;
3879
362
}
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
6
{
3888
6
  offsetT count;
3889
6
  int flen;
3890
6
  char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3891
6
  char *stop = NULL;
3892
6
  char stopc = 0;
3893
6
  char *p;
3894
3895
6
#ifdef md_cons_align
3896
6
  md_cons_align (1);
3897
6
#endif
3898
3899
6
  if (flag_mri)
3900
1
    stop = mri_comment_field (&stopc);
3901
3902
6
  count = get_absolute_expression ();
3903
3904
6
  SKIP_WHITESPACE ();
3905
6
  if (*input_line_pointer != ',')
3906
4
    {
3907
4
      int pad;
3908
3909
4
      flen = float_length (float_type, &pad);
3910
4
      if (flen >= 0)
3911
4
  memset (temp, 0, flen += pad);
3912
4
    }
3913
2
  else
3914
2
    {
3915
2
      ++input_line_pointer;
3916
3917
2
      flen = parse_one_float (float_type, temp);
3918
2
    }
3919
3920
6
  if (flen < 0)
3921
0
    {
3922
0
      if (flag_mri)
3923
0
  mri_comment_end (stop, stopc);
3924
0
      return;
3925
0
    }
3926
3927
6
  if (count == 1)
3928
0
    p = frag_more (flen);
3929
6
  else
3930
6
    p = frag_var (rs_fill, flen, flen, 0, NULL, count, NULL);
3931
6
  memcpy (p, temp, flen);
3932
3933
6
  demand_empty_rest_of_line ();
3934
3935
6
  if (flag_mri)
3936
1
    mri_comment_end (stop, stopc);
3937
6
}
3938
3939
/* Handle the .struct pseudo-op, as found in MIPS assemblers.  */
3940
3941
void
3942
s_struct (int ignore ATTRIBUTE_UNUSED)
3943
442
{
3944
442
  char *stop = NULL;
3945
442
  char stopc = 0;
3946
3947
442
  if (flag_mri)
3948
143
    stop = mri_comment_field (&stopc);
3949
442
  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
442
#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3953
442
  if (IS_ELF)
3954
442
    obj_elf_section_change_hook ();
3955
442
#endif
3956
#if defined (OBJ_COFF)
3957
  obj_coff_section_change_hook ();
3958
#endif
3959
442
  subseg_set (absolute_section, 0);
3960
442
  demand_empty_rest_of_line ();
3961
442
  if (flag_mri)
3962
143
    mri_comment_end (stop, stopc);
3963
442
}
3964
3965
void
3966
s_text (int ignore ATTRIBUTE_UNUSED)
3967
26
{
3968
26
  int temp;
3969
3970
26
  temp = get_absolute_expression ();
3971
26
  subseg_set (text_section, temp);
3972
26
  demand_empty_rest_of_line ();
3973
26
}
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
65
{
3980
65
  char *name;
3981
65
  symbolS *symbolP;
3982
65
  symbolS *symbolP2;
3983
65
  expressionS exp;
3984
3985
65
  if ((name = read_symbol_name ()) == NULL)
3986
34
    return;
3987
3988
31
  symbolP = symbol_find_or_make (name);
3989
3990
31
  if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3991
18
    {
3992
18
      if (!S_IS_VOLATILE (symbolP))
3993
14
  {
3994
14
    as_bad (_("symbol `%s' is already defined"), name);
3995
14
    goto err_out;
3996
14
  }
3997
4
      symbolP = symbol_clone (symbolP, 1);
3998
4
      S_CLEAR_VOLATILE (symbolP);
3999
4
    }
4000
4001
17
  SKIP_WHITESPACE ();
4002
4003
17
  if (*input_line_pointer != ',')
4004
10
    {
4005
10
      as_bad (_("expected comma after \"%s\""), name);
4006
10
      goto err_out;
4007
10
    }
4008
4009
7
  input_line_pointer++;
4010
4011
7
  SKIP_WHITESPACE ();
4012
7
  free (name);
4013
4014
7
  if ((name = read_symbol_name ()) == NULL)
4015
4
    return;
4016
4017
3
  if ((symbolP2 = symbol_find_noref (name, 1)) == NULL
4018
1
      && (symbolP2 = md_undefined_symbol (name)) == NULL)
4019
1
    {
4020
1
      symbolP2 = symbol_find_or_make (name);
4021
1
      S_SET_WEAKREFD (symbolP2);
4022
1
    }
4023
2
  else
4024
2
    {
4025
2
      symbolS *symp = symbolP2;
4026
4027
2
      while (S_IS_WEAKREFR (symp) && symp != symbolP)
4028
0
  {
4029
0
    expressionS *expP = symbol_get_value_expression (symp);
4030
4031
0
    gas_assert (expP->X_op == O_symbol
4032
0
      && expP->X_add_number == 0);
4033
0
    symp = expP->X_add_symbol;
4034
0
  }
4035
2
      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
2
    }
4067
4068
2
  memset (&exp, 0, sizeof (exp));
4069
2
  exp.X_op = O_symbol;
4070
2
  exp.X_add_symbol = symbolP2;
4071
4072
2
  S_SET_SEGMENT (symbolP, undefined_section);
4073
2
  symbol_set_value_expression (symbolP, &exp);
4074
2
  symbol_set_frag (symbolP, &zero_address_frag);
4075
2
  S_SET_WEAKREFR (symbolP);
4076
4077
2
  demand_empty_rest_of_line ();
4078
2
  free (name);
4079
2
  return;
4080
4081
24
 err_out:
4082
24
  ignore_rest_of_line ();
4083
24
  free (name);
4084
24
  return;
4085
3
}
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
132k
{
4099
132k
  SKIP_WHITESPACE ();
4100
132k
  if (input_line_pointer > buffer_limit)
4101
0
    return;
4102
132k
  if (is_end_of_stmt (*input_line_pointer))
4103
50.3k
    input_line_pointer++;
4104
82.5k
  else
4105
82.5k
    {
4106
82.5k
      if (ISPRINT (*input_line_pointer))
4107
51.7k
  as_bad (_("junk at end of line, first unrecognized character is `%c'"),
4108
51.7k
     *input_line_pointer);
4109
30.7k
      else
4110
30.7k
  as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
4111
30.7k
     *input_line_pointer);
4112
82.5k
      ignore_rest_of_line ();
4113
82.5k
    }
4114
  /* Return pointing just after end-of-line.  */
4115
132k
}
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
128k
{
4128
2.79M
  while (input_line_pointer <= buffer_limit)
4129
2.79M
    if (is_end_of_stmt (*input_line_pointer++))
4130
128k
      break;
4131
  /* Return pointing just after end-of-statement.  */
4132
128k
}
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
7.91k
{
4140
7.91k
  if (symbol_get_frag (symbolP)->fr_type != rs_dummy)
4141
7.91k
    symbol_set_frag (symbolP, &zero_address_frag);
4142
7.91k
}
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
7.92k
{
4154
7.92k
  expressionS exp;
4155
7.92k
  segT seg;
4156
4157
7.92k
  know (symbolP);   /* NULL pointer is logic error.  */
4158
4159
#ifdef md_expr_init_rest
4160
  md_expr_init_rest (&exp);
4161
#endif
4162
7.92k
  if (!S_IS_FORWARD_REF (symbolP))
4163
7.89k
    (void) expression (&exp);
4164
32
  else
4165
32
    (void) expr (0, &exp, expr_defer_incl_dot);
4166
4167
7.92k
  if (exp.X_op == O_illegal)
4168
0
    as_bad (_("illegal expression"));
4169
7.92k
  else if (exp.X_op == O_absent)
4170
327
    as_bad (_("missing expression"));
4171
7.60k
  else if (exp.X_op == O_big)
4172
8
    {
4173
8
      if (exp.X_add_number > 0)
4174
5
  as_bad (_("bignum invalid"));
4175
3
      else
4176
3
  as_bad (_("floating point number invalid"));
4177
8
    }
4178
7.59k
  else if (exp.X_op == O_subtract
4179
1.23k
     && !S_IS_FORWARD_REF (symbolP)
4180
1.23k
     && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
4181
828
     && (symbol_get_frag (exp.X_add_symbol)
4182
828
         == symbol_get_frag (exp.X_op_symbol)))
4183
0
    {
4184
0
      exp.X_op = O_constant;
4185
0
      exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
4186
0
        - S_GET_VALUE (exp.X_op_symbol));
4187
0
    }
4188
4189
7.92k
  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
7.92k
  switch (exp.X_op)
4196
7.92k
    {
4197
0
    case O_illegal:
4198
327
    case O_absent:
4199
335
    case O_big:
4200
335
      exp.X_add_number = 0;
4201
      /* Fall through.  */
4202
476
    case O_constant:
4203
476
      S_SET_SEGMENT (symbolP, absolute_section);
4204
476
      S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
4205
476
      set_zero_frag (symbolP);
4206
476
      break;
4207
4208
15
    case O_register:
4209
15
#ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
4210
15
      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
15
#endif
4217
      /* Make sure symbol_equated_p() recognizes the symbol as an equate.  */
4218
15
      exp.X_add_symbol = make_expr_symbol (&exp);
4219
15
      exp.X_add_number = 0;
4220
15
      exp.X_op = O_symbol;
4221
15
      symbol_set_value_expression (symbolP, &exp);
4222
15
      S_SET_SEGMENT (symbolP, reg_section);
4223
15
      set_zero_frag (symbolP);
4224
15
      break;
4225
4226
4.00k
    case O_symbol:
4227
4.00k
      seg = S_GET_SEGMENT (exp.X_add_symbol);
4228
4.00k
      if (seg == expr_section)
4229
0
  goto expr;
4230
      /* For x=undef+const, create an expression symbol.
4231
   For x=x+const, just update x except when x is an undefined symbol
4232
   For x=defined+const, evaluate x.  */
4233
4.00k
      if (symbolP == exp.X_add_symbol
4234
3
    && (seg != undefined_section
4235
3
        || !symbol_constant_p (symbolP)))
4236
0
  {
4237
0
    *symbol_X_add_number (symbolP) += exp.X_add_number;
4238
0
    break;
4239
0
  }
4240
4.00k
      else if (!S_IS_FORWARD_REF (symbolP) && seg != undefined_section)
4241
13
  {
4242
13
    symbolS *s = exp.X_add_symbol;
4243
4244
13
    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
13
    S_SET_SEGMENT (symbolP, seg);
4249
13
    S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (s));
4250
13
    symbol_set_frag (symbolP, symbol_get_frag (s));
4251
13
    copy_symbol_attributes (symbolP, s);
4252
13
    break;
4253
13
  }
4254
3.98k
      S_SET_SEGMENT (symbolP, undefined_section);
4255
3.98k
      symbol_set_value_expression (symbolP, &exp);
4256
3.98k
      copy_symbol_attributes (symbolP, exp.X_add_symbol);
4257
3.98k
      set_zero_frag (symbolP);
4258
3.98k
      break;
4259
4260
3.43k
    default:
4261
3.43k
    expr:
4262
      /* The value is some complex expression.  */
4263
3.43k
      S_SET_SEGMENT (symbolP, expr_section);
4264
3.43k
      symbol_set_value_expression (symbolP, &exp);
4265
3.43k
      set_zero_frag (symbolP);
4266
3.43k
      break;
4267
7.92k
    }
4268
7.92k
}
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
123
{
4304
123
#ifdef TC_PARSE_CONS_EXPRESSION
4305
123
  return TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4306
#else
4307
  expression (exp);
4308
  return TC_PARSE_CONS_RETURN_NONE;
4309
#endif
4310
123
}
4311
4312
#ifndef TC_PARSE_CONS_EXPRESSION
4313
#ifdef REPEAT_CONS_EXPRESSIONS
4314
#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
4315
  (parse_repeat_cons (EXP, NBYTES), TC_PARSE_CONS_RETURN_NONE)
4316
static void
4317
parse_repeat_cons (expressionS *exp, unsigned int nbytes);
4318
#endif
4319
4320
/* If we haven't gotten one yet, just call expression.  */
4321
#ifndef TC_PARSE_CONS_EXPRESSION
4322
#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
4323
  (expression (EXP), TC_PARSE_CONS_RETURN_NONE)
4324
#endif
4325
#endif
4326
4327
/* Worker to do .byte etc statements.
4328
   Clobbers input_line_pointer and checks end-of-line.  */
4329
4330
static void
4331
cons_worker (int nbytes,  /* 1=.byte, 2=.word, 4=.long.  */
4332
       int rva)
4333
1.14k
{
4334
1.14k
  int c;
4335
1.14k
  expressionS exp;
4336
1.14k
  char *stop = NULL;
4337
1.14k
  char stopc = 0;
4338
4339
#ifdef md_flush_pending_output
4340
  md_flush_pending_output ();
4341
#endif
4342
4343
1.14k
  if (flag_mri)
4344
298
    stop = mri_comment_field (&stopc);
4345
4346
1.14k
  if (is_it_end_of_statement ())
4347
10
    {
4348
10
      demand_empty_rest_of_line ();
4349
10
      if (flag_mri)
4350
0
  mri_comment_end (stop, stopc);
4351
10
      return;
4352
10
    }
4353
4354
1.13k
  if (nbytes == 0)
4355
0
    nbytes = TC_ADDRESS_BYTES ();
4356
4357
1.13k
#ifdef md_cons_align
4358
1.13k
  md_cons_align (nbytes);
4359
1.13k
#endif
4360
4361
1.13k
  c = 0;
4362
1.13k
  do
4363
1.26k
    {
4364
1.26k
      TC_PARSE_CONS_RETURN_TYPE ret = TC_PARSE_CONS_RETURN_NONE;
4365
#ifdef TC_CONS_FIX_CHECK
4366
      fixS **cur_fix = &frchain_now->fix_tail;
4367
4368
      if (*cur_fix != NULL)
4369
  cur_fix = &(*cur_fix)->fx_next;
4370
#endif
4371
4372
#ifdef TC_M68K
4373
      if (flag_m68k_mri)
4374
  parse_mri_cons (&exp, nbytes);
4375
      else
4376
#endif
4377
1.26k
  {
4378
#if 0
4379
    if (*input_line_pointer == '"')
4380
      {
4381
        as_bad (_("unexpected `\"' in expression"));
4382
        ignore_rest_of_line ();
4383
        return;
4384
      }
4385
#endif
4386
1.26k
    ret = TC_PARSE_CONS_EXPRESSION (&exp, nbytes);
4387
1.26k
  }
4388
4389
1.26k
      if (rva)
4390
5
  {
4391
5
    if (exp.X_op == O_symbol)
4392
5
      exp.X_op = O_symbol_rva;
4393
0
    else
4394
0
      as_fatal (_("rva without symbol"));
4395
5
  }
4396
1.26k
      emit_expr_with_reloc (&exp, nbytes, ret);
4397
#ifdef TC_CONS_FIX_CHECK
4398
      TC_CONS_FIX_CHECK (&exp, nbytes, *cur_fix);
4399
#endif
4400
1.26k
      ++c;
4401
1.26k
    }
4402
1.26k
  while (*input_line_pointer++ == ',');
4403
4404
  /* In MRI mode, after an odd number of bytes, we must align to an
4405
     even word boundary, unless the next instruction is a dc.b, ds.b
4406
     or dcb.b.  */
4407
1.13k
  if (flag_mri && nbytes == 1 && (c & 1) != 0)
4408
4
    mri_pending_align = 1;
4409
4410
1.13k
  input_line_pointer--;   /* Put terminator back into stream.  */
4411
4412
1.13k
  demand_empty_rest_of_line ();
4413
4414
1.13k
  if (flag_mri)
4415
298
    mri_comment_end (stop, stopc);
4416
4417
  /* Disallow hand-crafting instructions using .byte.  FIXME - what about
4418
     .word, .long etc ?  */
4419
1.13k
  if (flag_synth_cfi && frchain_now && frchain_now->frch_ginsn_data
4420
0
      && nbytes == 1)
4421
0
    as_bad (_("SCFI: hand-crafting instructions not supported"));
4422
1.13k
}
4423
4424
void
4425
cons (int size)
4426
1.12k
{
4427
1.12k
  cons_worker (size, 0);
4428
1.12k
}
4429
4430
void
4431
s_rva (int size)
4432
13
{
4433
13
  cons_worker (size, 1);
4434
13
}
4435
4436
/* .reloc offset, reloc_name, symbol+addend.  */
4437
4438
static void
4439
s_reloc (int ignore ATTRIBUTE_UNUSED)
4440
30
{
4441
30
  char *stop = NULL;
4442
30
  char stopc = 0;
4443
30
  expressionS exp;
4444
30
  char *r_name;
4445
30
  int c;
4446
30
  struct reloc_list *reloc;
4447
30
  struct _bfd_rel { const char * name; bfd_reloc_code_real_type code; };
4448
30
  static const struct _bfd_rel bfd_relocs[] =
4449
30
  {
4450
30
    { "NONE", BFD_RELOC_NONE },
4451
30
    { "8",  BFD_RELOC_8 },
4452
30
    { "16", BFD_RELOC_16 },
4453
30
    { "32", BFD_RELOC_32 },
4454
30
    { "64", BFD_RELOC_64 }
4455
30
  };
4456
4457
30
  reloc = notes_alloc (sizeof (*reloc));
4458
4459
30
  if (flag_mri)
4460
5
    stop = mri_comment_field (&stopc);
4461
4462
30
  expression (&exp);
4463
30
  switch (exp.X_op)
4464
30
    {
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
28
    case O_constant:
4472
28
      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
28
      symbol_mark_used_in_reloc (exp.X_add_symbol);
4476
28
      exp.X_op = O_symbol;
4477
      /* Fallthru */
4478
30
    case O_symbol:
4479
30
      if (exp.X_add_number == 0)
4480
25
  {
4481
25
    reloc->u.a.offset_sym = exp.X_add_symbol;
4482
25
    break;
4483
25
  }
4484
      /* Fallthru */
4485
5
    default:
4486
5
      reloc->u.a.offset_sym = make_expr_symbol (&exp);
4487
5
      break;
4488
30
    }
4489
4490
30
  SKIP_WHITESPACE ();
4491
30
  if (*input_line_pointer != ',')
4492
6
    {
4493
6
      as_bad (_("missing reloc type"));
4494
6
      goto err_out;
4495
6
    }
4496
4497
24
  ++input_line_pointer;
4498
24
  SKIP_WHITESPACE ();
4499
24
  c = get_symbol_name (& r_name);
4500
24
  if (strncasecmp (r_name, "BFD_RELOC_", 10) == 0)
4501
13
    {
4502
13
      unsigned int i;
4503
4504
65
      for (reloc->u.a.howto = NULL, i = 0; i < ARRAY_SIZE (bfd_relocs); i++)
4505
65
  if (strcasecmp (r_name + 10, bfd_relocs[i].name) == 0)
4506
13
    {
4507
13
      reloc->u.a.howto = bfd_reloc_type_lookup (stdoutput,
4508
13
                  bfd_relocs[i].code);
4509
13
      break;
4510
13
    }
4511
13
    }
4512
11
  else
4513
11
    reloc->u.a.howto = bfd_reloc_name_lookup (stdoutput, r_name);
4514
24
  restore_line_pointer (c);
4515
24
  if (reloc->u.a.howto == NULL)
4516
4
    {
4517
4
      as_bad (_("unrecognized reloc type"));
4518
4
      goto err_out;
4519
4
    }
4520
4521
20
  exp.X_op = O_absent;
4522
20
  SKIP_WHITESPACE ();
4523
20
  if (*input_line_pointer == ',')
4524
6
    {
4525
6
      ++input_line_pointer;
4526
6
      expression (&exp);
4527
6
    }
4528
20
  switch (exp.X_op)
4529
20
    {
4530
0
    case O_illegal:
4531
3
    case O_big:
4532
3
    case O_register:
4533
3
      as_bad (_("bad reloc expression"));
4534
13
    err_out:
4535
13
      ignore_rest_of_line ();
4536
13
      if (flag_mri)
4537
2
  mri_comment_end (stop, stopc);
4538
13
      return;
4539
14
    case O_absent:
4540
14
      reloc->u.a.sym = NULL;
4541
14
      reloc->u.a.addend = 0;
4542
14
      break;
4543
0
    case O_constant:
4544
0
      reloc->u.a.sym = NULL;
4545
0
      reloc->u.a.addend = exp.X_add_number;
4546
0
      break;
4547
1
    case O_symbol:
4548
1
      reloc->u.a.sym = exp.X_add_symbol;
4549
1
      reloc->u.a.addend = exp.X_add_number;
4550
1
      break;
4551
2
    default:
4552
2
      reloc->u.a.sym = make_expr_symbol (&exp);
4553
2
      reloc->u.a.addend = 0;
4554
2
      break;
4555
20
    }
4556
4557
17
  reloc->file = as_where (&reloc->line);
4558
17
  reloc->next = reloc_list;
4559
17
  reloc_list = reloc;
4560
4561
17
  demand_empty_rest_of_line ();
4562
17
  if (flag_mri)
4563
3
    mri_comment_end (stop, stopc);
4564
17
}
4565
4566
/* Put the contents of expression EXP into the object file using
4567
   NBYTES bytes.  If need_pass_2 is 1, this does nothing.  */
4568
4569
void
4570
emit_expr (expressionS *exp, unsigned int nbytes)
4571
2.88k
{
4572
2.88k
  emit_expr_with_reloc (exp, nbytes, TC_PARSE_CONS_RETURN_NONE);
4573
2.88k
}
4574
4575
void
4576
emit_expr_with_reloc (expressionS *exp,
4577
          unsigned int nbytes,
4578
          TC_PARSE_CONS_RETURN_TYPE reloc)
4579
4.19k
{
4580
4.19k
  operatorT op;
4581
4.19k
  char *p;
4582
4.19k
  valueT extra_digit = 0;
4583
4584
  /* Don't do anything if we are going to make another pass.  */
4585
4.19k
  if (need_pass_2)
4586
0
    return;
4587
4588
4.19k
  frag_grow (nbytes);
4589
4.19k
  symbol_set_value_now (&dot_symbol);
4590
4591
4.19k
#ifndef NO_LISTING
4592
4.19k
#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
4.19k
  if (strcmp (segment_name (now_seg), ".line") != 0)
4597
4.06k
    dwarf_line = -1;
4598
125
  else if (dwarf_line >= 0
4599
7
     && 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
125
  else if (nbytes == 4
4604
96
     && exp->X_op == O_constant
4605
13
     && exp->X_add_number >= 0)
4606
7
    dwarf_line = exp->X_add_number;
4607
118
  else
4608
118
    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
4.19k
  if (strcmp (segment_name (now_seg), ".debug") != 0)
4616
4.19k
    dwarf_file = 0;
4617
0
  else if (dwarf_file == 0
4618
0
     && nbytes == 2
4619
0
     && exp->X_op == O_constant
4620
0
     && exp->X_add_number == 0x11)
4621
0
    dwarf_file = 1;
4622
0
  else if (dwarf_file == 1
4623
0
     && nbytes == 2
4624
0
     && exp->X_op == O_constant
4625
0
     && exp->X_add_number == 0x12)
4626
0
    dwarf_file = 2;
4627
0
  else if (dwarf_file == 2
4628
0
     && nbytes == 4)
4629
0
    dwarf_file = 3;
4630
0
  else if (dwarf_file == 3
4631
0
     && nbytes == 2
4632
0
     && exp->X_op == O_constant
4633
0
     && exp->X_add_number == 0x38)
4634
0
    dwarf_file = 4;
4635
0
  else
4636
0
    dwarf_file = 0;
4637
4638
  /* The variable dwarf_file_string tells stringer that the string
4639
     may be the name of the source file.  */
4640
4.19k
  if (dwarf_file == 4)
4641
0
    dwarf_file_string = 1;
4642
4.19k
  else
4643
4.19k
    dwarf_file_string = 0;
4644
4.19k
#endif
4645
4.19k
#endif
4646
4647
4.19k
  if (check_eh_frame (exp, &nbytes))
4648
0
    return;
4649
4650
4.19k
  op = exp->X_op;
4651
4652
  /* Handle a negative bignum.  */
4653
4.19k
  if (op == O_uminus
4654
666
      && exp->X_add_number == 0
4655
3
      && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
4656
0
      && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
4657
0
    {
4658
0
      int i;
4659
0
      unsigned long carry;
4660
4661
0
      exp = symbol_get_value_expression (exp->X_add_symbol);
4662
4663
      /* Negate the bignum: one's complement each digit and add 1.  */
4664
0
      carry = 1;
4665
0
      for (i = 0; i < exp->X_add_number; i++)
4666
0
  {
4667
0
    unsigned long next;
4668
4669
0
    next = (((~(generic_bignum[i] & LITTLENUM_MASK))
4670
0
       & LITTLENUM_MASK)
4671
0
      + carry);
4672
0
    generic_bignum[i] = next & LITTLENUM_MASK;
4673
0
    carry = next >> LITTLENUM_NUMBER_OF_BITS;
4674
0
  }
4675
4676
      /* We can ignore any carry out, because it will be handled by
4677
   extra_digit if it is needed.  */
4678
4679
0
      extra_digit = -1;
4680
0
      op = O_big;
4681
0
    }
4682
4683
4.19k
  if (op == O_absent || op == O_illegal)
4684
99
    {
4685
99
      as_warn (_("zero assumed for missing expression"));
4686
99
      exp->X_add_number = 0;
4687
99
      op = O_constant;
4688
99
    }
4689
4.09k
  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
4.09k
  else if (op == O_register)
4696
281
    {
4697
281
      as_warn (_("register value used as expression"));
4698
281
      op = O_constant;
4699
281
    }
4700
4701
  /* Allow `.word 0' in the absolute section.  */
4702
4.19k
  if (now_seg == absolute_section)
4703
10
    {
4704
10
      if (op != O_constant || exp->X_add_number != 0)
4705
7
  as_bad (_("attempt to store value in absolute section"));
4706
10
      abs_section_offset += nbytes;
4707
10
      return;
4708
10
    }
4709
4710
  /* Allow `.word 0' in BSS style sections.  */
4711
4.18k
  if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
4712
0
    as_bad (_("attempt to store non-zero value in section `%s'"),
4713
0
      segment_name (now_seg));
4714
4715
4.18k
  p = frag_more (nbytes);
4716
4717
4.18k
  if (reloc != TC_PARSE_CONS_RETURN_NONE)
4718
27
    {
4719
27
      emit_expr_fix (exp, nbytes, frag_now, p, reloc);
4720
27
      return;
4721
27
    }
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
4.15k
  if (op == O_constant && nbytes > sizeof (valueT))
4751
3
    {
4752
3
      extra_digit = -convert_to_bignum (exp);
4753
3
      op = O_big;
4754
3
    }
4755
4756
4.15k
  if (op == O_constant)
4757
713
    {
4758
713
      valueT get;
4759
713
      valueT use;
4760
713
      valueT mask;
4761
713
      valueT unmask;
4762
4763
      /* JF << of >= number of bits in the object is undefined.  In
4764
   particular SPARC (Sun 4) has problems.  */
4765
713
      if (nbytes >= sizeof (valueT))
4766
5
  {
4767
5
    know (nbytes == sizeof (valueT));
4768
5
    mask = 0;
4769
5
  }
4770
708
      else
4771
708
  {
4772
    /* Don't store these bits.  */
4773
708
    mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
4774
708
  }
4775
4776
713
      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
713
      get = exp->X_add_number;
4784
713
      use = get & unmask;
4785
713
      if ((get & mask) != 0 && (-get & mask) != 0)
4786
37
  {
4787
    /* Leading bits contain both 0s & 1s.  */
4788
37
    as_warn (_("value 0x%" PRIx64 " truncated to 0x%" PRIx64),
4789
37
       (uint64_t) get, (uint64_t) use);
4790
37
  }
4791
      /* Put bytes in right order.  */
4792
713
      md_number_to_chars (p, use, nbytes);
4793
713
    }
4794
3.44k
  else if (op == O_big)
4795
277
    {
4796
277
      unsigned int size;
4797
277
      LITTLENUM_TYPE *nums;
4798
4799
277
      size = exp->X_add_number * CHARS_PER_LITTLENUM;
4800
277
      if (nbytes < size)
4801
5
  {
4802
5
    int i = nbytes / CHARS_PER_LITTLENUM;
4803
4804
5
    if (i != 0)
4805
5
      {
4806
5
        LITTLENUM_TYPE sign = 0;
4807
5
        if ((generic_bignum[--i]
4808
5
       & (1 << (LITTLENUM_NUMBER_OF_BITS - 1))) != 0)
4809
0
    sign = ~(LITTLENUM_TYPE) 0;
4810
4811
5
        while (++i < exp->X_add_number)
4812
5
    if (generic_bignum[i] != sign)
4813
5
      break;
4814
5
      }
4815
0
    else if (nbytes == 1)
4816
0
      {
4817
        /* We have nbytes == 1 and CHARS_PER_LITTLENUM == 2 (probably).
4818
     Check that bits 8.. of generic_bignum[0] match bit 7
4819
     and that they match all of generic_bignum[1..exp->X_add_number].  */
4820
0
        LITTLENUM_TYPE sign = (generic_bignum[0] & (1 << 7)) ? -1 : 0;
4821
0
        LITTLENUM_TYPE himask = LITTLENUM_MASK & ~ 0xFF;
4822
4823
0
        if ((generic_bignum[0] & himask) == (sign & himask))
4824
0
    {
4825
0
      while (++i < exp->X_add_number)
4826
0
        if (generic_bignum[i] != sign)
4827
0
          break;
4828
0
    }
4829
0
      }
4830
4831
5
    if (i < exp->X_add_number)
4832
5
      as_warn (ngettext ("bignum truncated to %d byte",
4833
5
             "bignum truncated to %d bytes",
4834
5
             nbytes),
4835
5
         nbytes);
4836
5
    size = nbytes;
4837
5
  }
4838
4839
277
      if (nbytes == 1)
4840
0
  {
4841
0
    md_number_to_chars (p, generic_bignum[0], 1);
4842
0
    return;
4843
0
  }
4844
277
      know (nbytes % CHARS_PER_LITTLENUM == 0);
4845
4846
277
      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
277
      else
4865
277
  {
4866
277
    nums = generic_bignum;
4867
1.38k
    while (size >= CHARS_PER_LITTLENUM)
4868
1.10k
      {
4869
1.10k
        md_number_to_chars (p, *nums, CHARS_PER_LITTLENUM);
4870
1.10k
        ++nums;
4871
1.10k
        size -= CHARS_PER_LITTLENUM;
4872
1.10k
        p += CHARS_PER_LITTLENUM;
4873
1.10k
        nbytes -= CHARS_PER_LITTLENUM;
4874
1.10k
      }
4875
4876
539
    while (nbytes >= CHARS_PER_LITTLENUM)
4877
262
      {
4878
262
        md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4879
262
        nbytes -= CHARS_PER_LITTLENUM;
4880
262
        p += CHARS_PER_LITTLENUM;
4881
262
      }
4882
277
  }
4883
277
    }
4884
3.16k
  else
4885
3.16k
    emit_expr_fix (exp, nbytes, frag_now, p, TC_PARSE_CONS_RETURN_NONE);
4886
4.15k
}
4887
4888
void
4889
emit_expr_fix (expressionS *exp, unsigned int nbytes, fragS *frag, char *p,
4890
         TC_PARSE_CONS_RETURN_TYPE r ATTRIBUTE_UNUSED)
4891
3.19k
{
4892
3.19k
  int offset = 0;
4893
3.19k
  unsigned int size = nbytes;
4894
4895
3.19k
  memset (p, 0, size);
4896
4897
  /* Generate a fixS to record the symbol value.  */
4898
4899
3.19k
#ifdef TC_CONS_FIX_NEW
4900
3.19k
  TC_CONS_FIX_NEW (frag, p - frag->fr_literal + offset, size, exp, r);
4901
#else
4902
  if (r != TC_PARSE_CONS_RETURN_NONE)
4903
    {
4904
      reloc_howto_type *reloc_howto;
4905
4906
      reloc_howto = bfd_reloc_type_lookup (stdoutput, r);
4907
      size = bfd_get_reloc_size (reloc_howto);
4908
4909
      if (size > nbytes)
4910
  {
4911
    as_bad (ngettext ("%s relocations do not fit in %u byte",
4912
          "%s relocations do not fit in %u bytes",
4913
          nbytes),
4914
      reloc_howto->name, nbytes);
4915
    return;
4916
  }
4917
      else if (target_big_endian)
4918
  offset = nbytes - size;
4919
    }
4920
  else
4921
    switch (size)
4922
      {
4923
      case 1:
4924
  r = BFD_RELOC_8;
4925
  break;
4926
      case 2:
4927
  r = BFD_RELOC_16;
4928
  break;
4929
      case 3:
4930
  r = BFD_RELOC_24;
4931
  break;
4932
      case 4:
4933
  r = BFD_RELOC_32;
4934
  break;
4935
      case 8:
4936
  r = BFD_RELOC_64;
4937
  break;
4938
      default:
4939
  as_bad (_("unsupported BFD relocation size %u"), size);
4940
  return;
4941
      }
4942
  fix_new_exp (frag, p - frag->fr_literal + offset, size,
4943
         exp, 0, r);
4944
#endif
4945
3.19k
}
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
0
{
5060
0
  int pad, length = float_length (float_type, &pad);
5061
0
  int i;
5062
5063
0
  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
0
  i = 0;
5070
0
  while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
5071
0
    {
5072
0
      int d;
5073
5074
      /* The MRI assembler accepts arbitrary underscores strewn about
5075
   through the hex constant, so we ignore them as well.  */
5076
0
      if (*input_line_pointer == '_')
5077
0
  {
5078
0
    ++input_line_pointer;
5079
0
    continue;
5080
0
  }
5081
5082
0
      if (i >= length)
5083
0
  {
5084
0
    as_warn (_("floating point constant too large"));
5085
0
    return -1;
5086
0
  }
5087
0
      d = hex_value (*input_line_pointer) << 4;
5088
0
      ++input_line_pointer;
5089
0
      while (*input_line_pointer == '_')
5090
0
  ++input_line_pointer;
5091
0
      if (hex_p (*input_line_pointer))
5092
0
  {
5093
0
    d += hex_value (*input_line_pointer);
5094
0
    ++input_line_pointer;
5095
0
  }
5096
0
      if (target_big_endian)
5097
0
  bytes[i] = d;
5098
0
      else
5099
0
  bytes[length - i - 1] = d;
5100
0
      ++i;
5101
0
    }
5102
5103
0
  if (i < length)
5104
0
    {
5105
0
      if (target_big_endian)
5106
0
  memset (bytes + i, 0, length - i);
5107
0
      else
5108
0
  memset (bytes, 0, length - i);
5109
0
    }
5110
5111
0
  memset (bytes + length, 0, pad);
5112
5113
0
  return length + pad;
5114
0
}
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
236
{
5137
236
  char *p;
5138
236
  int length;     /* Number of chars in an object.  */
5139
236
  char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
5140
5141
236
  if (is_it_end_of_statement ())
5142
0
    {
5143
0
      demand_empty_rest_of_line ();
5144
0
      return;
5145
0
    }
5146
5147
236
  if (now_seg == absolute_section)
5148
7
    {
5149
7
      as_bad (_("attempt to store float in absolute section"));
5150
7
      ignore_rest_of_line ();
5151
7
      return;
5152
7
    }
5153
5154
229
  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
229
#ifdef md_cons_align
5167
229
  md_cons_align (1);
5168
229
#endif
5169
5170
229
  do
5171
360
    {
5172
360
      length = parse_one_float (float_type, temp);
5173
360
      if (length < 0)
5174
0
  return;
5175
5176
360
      if (!need_pass_2)
5177
360
  {
5178
360
    int count;
5179
5180
360
    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
360
    if (count == 1)
5198
360
      p = frag_more (length);
5199
0
    else
5200
0
      p = frag_var (rs_fill, length, length, 0, NULL, count, NULL);
5201
360
    memcpy (p, temp, length);
5202
360
  }
5203
360
      SKIP_WHITESPACE ();
5204
360
    }
5205
360
  while (*input_line_pointer++ == ',');
5206
5207
  /* Put terminator back into stream.  */
5208
229
  --input_line_pointer;
5209
229
  demand_empty_rest_of_line ();
5210
229
}
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
556
{
5233
556
  int size = 0;
5234
556
  unsigned byte;
5235
5236
556
  do
5237
828
    {
5238
828
      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
828
      value = (value >> 7) | ~(-(offsetT)1 >> 7);
5243
828
      size += 1;
5244
828
    }
5245
828
  while (!(((value == 0) && ((byte & 0x40) == 0))
5246
711
     || ((value == -1) && ((byte & 0x40) != 0))));
5247
5248
556
  return size;
5249
556
}
5250
5251
static inline unsigned int
5252
sizeof_uleb128 (valueT value)
5253
2.07k
{
5254
2.07k
  int size = 0;
5255
5256
2.07k
  do
5257
3.59k
    {
5258
3.59k
      value >>= 7;
5259
3.59k
      size += 1;
5260
3.59k
    }
5261
3.59k
  while (value != 0);
5262
5263
2.07k
  return size;
5264
2.07k
}
5265
5266
unsigned int
5267
sizeof_leb128 (valueT value, int sign)
5268
2.60k
{
5269
2.60k
  if (sign)
5270
556
    return sizeof_sleb128 (value);
5271
2.04k
  else
5272
2.04k
    return sizeof_uleb128 (value);
5273
2.60k
}
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
555
{
5280
555
  char *orig = p;
5281
555
  int more;
5282
5283
555
  do
5284
826
    {
5285
826
      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
826
      value = (value >> 7) | ~(-(offsetT)1 >> 7);
5291
5292
826
      more = !((((value == 0) && ((byte & 0x40) == 0))
5293
709
    || ((value == -1) && ((byte & 0x40) != 0))));
5294
826
      if (more)
5295
271
  byte |= 0x80;
5296
5297
826
      *p++ = byte;
5298
826
    }
5299
826
  while (more);
5300
5301
555
  return p - orig;
5302
555
}
5303
5304
static inline unsigned int
5305
output_uleb128 (char *p, valueT value)
5306
1.91k
{
5307
1.91k
  char *orig = p;
5308
5309
1.91k
  do
5310
1.98k
    {
5311
1.98k
      unsigned byte = (value & 0x7f);
5312
5313
1.98k
      value >>= 7;
5314
1.98k
      if (value != 0)
5315
  /* More bytes to follow.  */
5316
65
  byte |= 0x80;
5317
5318
1.98k
      *p++ = byte;
5319
1.98k
    }
5320
1.98k
  while (value != 0);
5321
5322
1.91k
  return p - orig;
5323
1.91k
}
5324
5325
unsigned int
5326
output_leb128 (char *p, valueT value, int sign)
5327
2.47k
{
5328
2.47k
  if (sign)
5329
555
    return output_sleb128 (p, value);
5330
1.91k
  else
5331
1.91k
    return output_uleb128 (p, value);
5332
2.47k
}
5333
5334
/* Do the same for bignums.  We combine sizeof with output here in that
5335
   we don't output for NULL values of P.  It isn't really as critical as
5336
   for "normal" values that this be streamlined.  Returns the number of
5337
   bytes used.  */
5338
5339
static inline unsigned int
5340
output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size)
5341
0
{
5342
0
  char *orig = p;
5343
0
  valueT val = 0;
5344
0
  int loaded = 0;
5345
0
  unsigned byte;
5346
5347
  /* Strip leading sign extensions off the bignum.  */
5348
0
  while (size > 1
5349
0
   && bignum[size - 1] == LITTLENUM_MASK
5350
0
   && bignum[size - 2] > LITTLENUM_MASK / 2)
5351
0
    size--;
5352
5353
0
  do
5354
0
    {
5355
      /* OR in the next part of the littlenum.  */
5356
0
      val |= (*bignum << loaded);
5357
0
      loaded += LITTLENUM_NUMBER_OF_BITS;
5358
0
      size--;
5359
0
      bignum++;
5360
5361
      /* Add bytes until there are less than 7 bits left in VAL
5362
   or until every non-sign bit has been written.  */
5363
0
      do
5364
0
  {
5365
0
    byte = val & 0x7f;
5366
0
    loaded -= 7;
5367
0
    val >>= 7;
5368
0
    if (size > 0
5369
0
        || val != ((byte & 0x40) == 0 ? 0 : ((valueT) 1 << loaded) - 1))
5370
0
      byte |= 0x80;
5371
5372
0
    if (orig)
5373
0
      *p = byte;
5374
0
    p++;
5375
0
  }
5376
0
      while ((byte & 0x80) != 0 && loaded >= 7);
5377
0
    }
5378
0
  while (size > 0);
5379
5380
  /* Mop up any left-over bits (of which there will be less than 7).  */
5381
0
  if ((byte & 0x80) != 0)
5382
0
    {
5383
      /* Sign-extend VAL.  */
5384
0
      if (val & (1 << (loaded - 1)))
5385
0
  val |= ~0U << loaded;
5386
0
      if (orig)
5387
0
  *p = val & 0x7f;
5388
0
      p++;
5389
0
    }
5390
5391
0
  return p - orig;
5392
0
}
5393
5394
static inline unsigned int
5395
output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size)
5396
14
{
5397
14
  char *orig = p;
5398
14
  valueT val = 0;
5399
14
  int loaded = 0;
5400
14
  unsigned byte;
5401
5402
  /* Strip leading zeros off the bignum.  */
5403
  /* XXX: Is this needed?  */
5404
14
  while (size > 0 && bignum[size - 1] == 0)
5405
0
    size--;
5406
5407
14
  do
5408
644
    {
5409
644
      if (loaded < 7 && size > 0)
5410
280
  {
5411
280
    val |= (*bignum << loaded);
5412
280
    loaded += 8 * CHARS_PER_LITTLENUM;
5413
280
    size--;
5414
280
    bignum++;
5415
280
  }
5416
5417
644
      byte = val & 0x7f;
5418
644
      loaded -= 7;
5419
644
      val >>= 7;
5420
5421
644
      if (size > 0 || val)
5422
630
  byte |= 0x80;
5423
5424
644
      if (orig)
5425
322
  *p = byte;
5426
644
      p++;
5427
644
    }
5428
644
  while (byte & 0x80);
5429
5430
14
  return p - orig;
5431
14
}
5432
5433
static unsigned int
5434
output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size, int sign)
5435
14
{
5436
14
  if (sign)
5437
0
    return output_big_sleb128 (p, bignum, size);
5438
14
  else
5439
14
    return output_big_uleb128 (p, bignum, size);
5440
14
}
5441
5442
/* Generate the appropriate fragments for a given expression to emit a
5443
   leb128 value.  SIGN is 1 for sleb, 0 for uleb.  */
5444
5445
void
5446
emit_leb128_expr (expressionS *exp, int sign)
5447
614
{
5448
614
  operatorT op = exp->X_op;
5449
614
  unsigned int nbytes;
5450
5451
614
  if (op == O_absent || op == O_illegal)
5452
7
    {
5453
7
      as_warn (_("zero assumed for missing expression"));
5454
7
      exp->X_add_number = 0;
5455
7
      op = O_constant;
5456
7
    }
5457
607
  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
607
  else if (op == O_register)
5464
0
    {
5465
0
      as_warn (_("register value used as expression"));
5466
0
      op = O_constant;
5467
0
    }
5468
607
  else if (op == O_constant
5469
570
     && sign
5470
558
     && (exp->X_unsigned
5471
558
         ? exp->X_add_number < 0
5472
558
         : (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
614
  if (now_seg == absolute_section)
5482
286
    {
5483
286
      if (op != O_constant || exp->X_add_number != 0)
5484
282
  as_bad (_("attempt to store value in absolute section"));
5485
286
      abs_section_offset++;
5486
286
      return;
5487
286
    }
5488
5489
328
  if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
5490
0
    as_bad (_("attempt to store non-zero value in section `%s'"),
5491
0
      segment_name (now_seg));
5492
5493
  /* Let check_eh_frame know that data is being emitted.  nbytes == -1 is
5494
     a signal that this is leb128 data.  It shouldn't optimize this away.  */
5495
328
  nbytes = -1u;
5496
328
  if (check_eh_frame (exp, &nbytes))
5497
0
    abort ();
5498
5499
  /* Let the backend know that subsequent data may be byte aligned.  */
5500
328
#ifdef md_cons_align
5501
328
  md_cons_align (1);
5502
328
#endif
5503
5504
328
  if (op == O_constant)
5505
291
    {
5506
      /* If we've got a constant, emit the thing directly right now.  */
5507
5508
291
      valueT value = exp->X_add_number;
5509
291
      unsigned int size;
5510
291
      char *p;
5511
5512
291
      size = sizeof_leb128 (value, sign);
5513
291
      p = frag_more (size);
5514
291
      if (output_leb128 (p, value, sign) > size)
5515
0
  abort ();
5516
291
    }
5517
37
  else if (op == O_big)
5518
7
    {
5519
      /* O_big is a different sort of constant.  */
5520
7
      int nbr_digits = exp->X_add_number;
5521
7
      unsigned int size;
5522
7
      char *p;
5523
5524
      /* If the leading littenum is 0xffff, prepend a 0 to avoid confusion with
5525
   a signed number.  Unary operators like - or ~ always extend the
5526
   bignum to its largest size.  */
5527
7
      if (exp->X_unsigned
5528
6
    && nbr_digits < SIZE_OF_LARGE_NUMBER
5529
0
    && generic_bignum[nbr_digits - 1] == LITTLENUM_MASK)
5530
0
  generic_bignum[nbr_digits++] = 0;
5531
5532
7
      size = output_big_leb128 (NULL, generic_bignum, nbr_digits, sign);
5533
7
      p = frag_more (size);
5534
7
      if (output_big_leb128 (p, generic_bignum, nbr_digits, sign) > size)
5535
0
  abort ();
5536
7
    }
5537
30
  else
5538
30
    {
5539
      /* Otherwise, we have to create a variable sized fragment and
5540
   resolve things later.  */
5541
5542
30
      frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
5543
30
    make_expr_symbol (exp), 0, NULL);
5544
30
    }
5545
328
}
5546
5547
/* Parse the .sleb128 and .uleb128 pseudos.  */
5548
5549
void
5550
s_leb128 (int sign)
5551
559
{
5552
559
  expressionS exp;
5553
5554
#ifdef md_flush_pending_output
5555
  md_flush_pending_output ();
5556
#endif
5557
5558
559
  do
5559
586
    {
5560
586
      expression (&exp);
5561
586
      emit_leb128_expr (&exp, sign);
5562
586
    }
5563
586
  while (*input_line_pointer++ == ',');
5564
5565
559
  input_line_pointer--;
5566
559
  demand_empty_rest_of_line ();
5567
559
}
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
112
{
5804
112
  return (c < 0x100) && (b64[c] != -1);
5805
112
}
5806
5807
static void
5808
decode_base64_and_append (unsigned int b[4], int len)
5809
25
{
5810
25
  gas_assert (len > 1);
5811
5812
25
  FRAG_APPEND_1_CHAR ((b64[b[0]] << 2) | (b64[b[1]] >> 4));
5813
5814
25
  if (len == 2)
5815
1
    return; /* FIXME: Check for unused bits in b[1] ?  */
5816
5817
24
  FRAG_APPEND_1_CHAR (((b64[b[1]] << 4) & 0xf0) | (b64[b[2]] >> 2));
5818
5819
24
  if (len == 3)
5820
16
    return; /* FIXME: Check for unused bits in b[2] ?  */
5821
5822
8
  FRAG_APPEND_1_CHAR (((b64[b[2]] << 6) & 0xc0) | b64[b[3]]);
5823
8
}
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
72
{
5836
72
  unsigned int c;
5837
72
  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
72
  if (now_seg == absolute_section)
5842
0
    {
5843
0
      as_bad (_("base64 strings must be placed into a section"));
5844
0
      ignore_rest_of_line ();
5845
0
      return;
5846
0
    }
5847
5848
72
  if (is_it_end_of_statement ())
5849
21
    {
5850
21
      as_bad (_("a string must follow the .base64 pseudo-op"));
5851
21
      return;
5852
21
    }
5853
5854
#ifdef md_flush_pending_output
5855
  md_flush_pending_output ();
5856
#endif
5857
5858
51
#ifdef md_cons_align
5859
51
  md_cons_align (1);
5860
51
#endif
5861
5862
51
  do
5863
51
    {
5864
51
      SKIP_ALL_WHITESPACE ();
5865
5866
51
      c = * input_line_pointer ++;
5867
5868
51
      if (c != '"')
5869
13
  {
5870
13
    as_bad (_("expected double quote enclosed string as argument to .base64 pseudo-op"));
5871
13
    ignore_rest_of_line ();
5872
13
    return;
5873
13
  }
5874
5875
      /* Read a block of four base64 encoded characters.  */
5876
38
      int i;
5877
38
      unsigned int b[4];
5878
38
      bool seen_equals = false;
5879
5880
45
    loop:
5881
140
      for (i = 0; i < 4; i++)
5882
131
        {
5883
131
    c = * input_line_pointer ++;
5884
5885
131
    if (c >= 256 || is_end_of_stmt (c))
5886
4
      {
5887
4
        as_bad (_("end of line encountered inside .base64 string"));
5888
4
        ignore_rest_of_line ();
5889
4
        return;
5890
4
      }
5891
5892
127
    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
111
    if (seen_equals && c != '=')
5909
0
      {
5910
0
        as_bad (_("equals character only allowed at end of .base64 string"));
5911
0
        ignore_rest_of_line ();
5912
0
        return;
5913
0
      }
5914
5915
111
    if (c == '=')
5916
24
      {
5917
24
        if (i == 0)
5918
6
    {
5919
6
      as_bad (_("the equals character cannot start a block of four base64 encoded bytes"));
5920
6
      ignore_rest_of_line ();
5921
6
      return;
5922
6
    }
5923
18
        else if (i == 1)
5924
0
    {
5925
0
      as_bad (_("the equals character cannot be the second character in a block of four base64 encoded bytes"));
5926
0
      ignore_rest_of_line ();
5927
0
      return;
5928
0
    }
5929
5930
18
        seen_equals = true;
5931
18
      }
5932
87
    else if (! is_base64_char (c))
5933
10
      {
5934
10
        if (ISPRINT (c))
5935
9
    as_bad (_("invalid character '%c' found inside .base64 string"), c);
5936
1
        else
5937
1
    as_bad (_("invalid character %#x found inside .base64 string"), c);
5938
10
        ignore_rest_of_line ();
5939
10
        return;
5940
10
      }
5941
5942
95
    b[i] = c;
5943
95
  }
5944
5945
25
      if (seen_equals && i == 4)
5946
1
  {
5947
1
    -- i;
5948
1
    if (b[2] == '=')
5949
1
      -- i;
5950
1
  }
5951
5952
      /* We have a block of up to four valid base64 encoded bytes.  */
5953
25
      decode_base64_and_append (b, i);
5954
25
      num_octets += (i - 1);
5955
5956
      /* Check the next character.  */
5957
25
      c = * input_line_pointer ++;
5958
5959
25
      if (is_base64_char (c))
5960
8
  {
5961
8
    if (seen_equals)
5962
1
      {
5963
1
        as_bad (_("no base64 characters expected after '=' padding characters"));
5964
1
        ignore_rest_of_line ();
5965
1
        return;
5966
1
      }
5967
5968
7
    -- input_line_pointer;
5969
7
    goto loop;
5970
8
  }
5971
17
      else if (c != '"')
5972
1
  {
5973
1
    as_bad (_(".base64 string must have a terminating double quote character"));
5974
1
    ignore_rest_of_line ();
5975
1
    return;
5976
1
  }
5977
5978
16
      SKIP_ALL_WHITESPACE ();
5979
      
5980
16
      c = * input_line_pointer ++;
5981
16
    }
5982
51
  while (c == ',');
5983
5984
  /* Make sure that we have not skipped the EOL marker.  */
5985
16
  -- input_line_pointer;
5986
5987
16
  while (num_octets % OCTETS_PER_BYTE)
5988
0
    {
5989
      /* We have finished emiting the octets for this .base64 pseudo-op, but
5990
   we have not filled up enough bytes for the target architecture.  So
5991
   we emit padding octets here.  This is done after all of the arguments
5992
   to the pseudo-op have been processed, rather than at the end of each
5993
   argument, as it is likely that the user wants the arguments to be
5994
   contiguous.  */
5995
0
      FRAG_APPEND_1_CHAR (0);
5996
0
      ++ num_octets;
5997
0
    }
5998
5999
16
  demand_empty_rest_of_line ();
6000
16
}
6001
6002
static void
6003
stringer_append_char (int c, int bitsize)
6004
4.56k
{
6005
4.56k
  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
4.56k
  if (!target_big_endian)
6010
4.56k
    FRAG_APPEND_1_CHAR (c);
6011
6012
4.56k
  switch (bitsize)
6013
4.56k
    {
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
4.56k
    case 8:
6028
4.56k
      break;
6029
0
    default:
6030
      /* Called with invalid bitsize argument.  */
6031
0
      abort ();
6032
0
      break;
6033
4.56k
    }
6034
4.56k
  if (target_big_endian)
6035
0
    FRAG_APPEND_1_CHAR (c);
6036
4.56k
}
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
646
{
6049
646
  const int bitsize = bits_appendzero & ~7;
6050
646
  const int append_zero = bits_appendzero & 1;
6051
646
  unsigned int c;
6052
646
#if !defined(NO_LISTING) && defined (OBJ_ELF)
6053
646
  char *start;
6054
646
#endif
6055
6056
#ifdef md_flush_pending_output
6057
  md_flush_pending_output ();
6058
#endif
6059
6060
646
#ifdef md_cons_align
6061
646
  md_cons_align (1);
6062
646
#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
646
  if (now_seg == absolute_section)
6067
1
    {
6068
1
      as_bad (_("strings must be placed into a section"));
6069
1
      ignore_rest_of_line ();
6070
1
      return;
6071
1
    }
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
645
  if (is_it_end_of_statement ())
6079
3
    {
6080
3
      c = 0;      /* Skip loop.  */
6081
3
      ++input_line_pointer; /* Compensate for end of loop.  */
6082
3
    }
6083
642
  else
6084
642
    {
6085
642
      c = ',';      /* Do loop.  */
6086
642
    }
6087
6088
1.48k
  while (c == ',' || c == '<' || c == '"')
6089
1.01k
    {
6090
1.01k
      SKIP_WHITESPACE ();
6091
1.01k
      switch (*input_line_pointer)
6092
1.01k
  {
6093
265
  case '\"':
6094
265
    ++input_line_pointer; /*->1st char of string.  */
6095
265
#if !defined(NO_LISTING) && defined (OBJ_ELF)
6096
265
    start = input_line_pointer;
6097
265
#endif
6098
6099
4.46k
    while (is_a_char (c = next_char_of_string ()))
6100
4.19k
      stringer_append_char (c, bitsize);
6101
6102
    /* Treat "a" "b" as "ab".  Even if we are appending zeros.  */
6103
265
    SKIP_ALL_WHITESPACE ();
6104
265
    if (*input_line_pointer == '"')
6105
0
      break;
6106
6107
265
    if (append_zero)
6108
182
      stringer_append_char (0, bitsize);
6109
6110
265
#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
265
    if (strcmp (segment_name (now_seg), ".debug") != 0)
6118
265
      dwarf_file_string = 0;
6119
0
    else if (dwarf_file_string)
6120
0
      {
6121
0
        c = input_line_pointer[-1];
6122
0
        input_line_pointer[-1] = '\0';
6123
0
        listing_source_file (start);
6124
0
        input_line_pointer[-1] = c;
6125
0
      }
6126
265
#endif
6127
6128
265
    break;
6129
180
  case '<':
6130
180
    input_line_pointer++;
6131
180
    offsetT n = get_single_number ();
6132
180
    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
180
    stringer_append_char (n, bitsize);
6139
180
    if (*input_line_pointer != '>')
6140
179
      {
6141
179
        as_bad (_("expected <nn>"));
6142
179
        ignore_rest_of_line ();
6143
179
        return;
6144
179
      }
6145
1
    input_line_pointer++;
6146
1
    break;
6147
573
  case ',':
6148
573
    input_line_pointer++;
6149
573
    break;
6150
1.01k
  }
6151
839
      SKIP_WHITESPACE ();
6152
839
      c = *input_line_pointer;
6153
839
    }
6154
6155
466
  demand_empty_rest_of_line ();
6156
466
}
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.11M
{
6166
2.11M
  unsigned int c;
6167
6168
2.11M
  c = *input_line_pointer++ & CHAR_MASK;
6169
2.11M
  switch (c)
6170
2.11M
    {
6171
250
    case 0:
6172
      /* PR 20902: Do not advance past the end of the buffer.  */
6173
250
      -- input_line_pointer;
6174
250
      c = NOT_A_CHAR;
6175
250
      break;
6176
6177
70.4k
    case '\"':
6178
70.4k
      c = NOT_A_CHAR;
6179
70.4k
      break;
6180
6181
35.3k
    case '\n':
6182
35.3k
      as_warn (_("unterminated string; newline inserted"));
6183
35.3k
      bump_line_counters ();
6184
35.3k
      break;
6185
6186
1.22k
    case '\\':
6187
1.22k
      if (!TC_STRING_ESCAPES)
6188
0
  break;
6189
1.22k
      switch (c = *input_line_pointer++ & CHAR_MASK)
6190
1.22k
  {
6191
9
  case 'b':
6192
9
    c = '\b';
6193
9
    break;
6194
6195
0
  case 'f':
6196
0
    c = '\f';
6197
0
    break;
6198
6199
0
  case 'n':
6200
0
    c = '\n';
6201
0
    break;
6202
6203
0
  case 'r':
6204
0
    c = '\r';
6205
0
    break;
6206
6207
0
  case 't':
6208
0
    c = '\t';
6209
0
    break;
6210
6211
0
  case 'v':
6212
0
    c = '\013';
6213
0
    break;
6214
6215
794
  case '\\':
6216
794
  case '"':
6217
794
    break;    /* As itself.  */
6218
6219
2
  case '0':
6220
2
  case '1':
6221
2
  case '2':
6222
2
  case '3':
6223
3
  case '4':
6224
3
  case '5':
6225
4
  case '6':
6226
4
  case '7':
6227
4
    {
6228
4
      unsigned number;
6229
4
      int i;
6230
6231
4
      for (i = 0, number = 0;
6232
8
     i < 3 && c >= '0' && c <= '7';
6233
4
     c = *input_line_pointer++, i++)
6234
4
        {
6235
4
    number = number * 8 + c - '0';
6236
4
        }
6237
6238
4
      c = number & CHAR_MASK;
6239
4
    }
6240
4
    --input_line_pointer;
6241
4
    break;
6242
6243
0
  case 'x':
6244
0
  case 'X':
6245
0
    {
6246
0
      unsigned number;
6247
6248
0
      number = 0;
6249
0
      c = *input_line_pointer++;
6250
0
      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
0
      c = number & CHAR_MASK;
6261
0
      --input_line_pointer;
6262
0
    }
6263
0
    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
416
  default:
6279
6280
#ifdef ONLY_STANDARD_ESCAPES
6281
    as_bad (_("bad escaped character in string"));
6282
    c = '?';
6283
#endif /* ONLY_STANDARD_ESCAPES */
6284
6285
416
    break;
6286
1.22k
  }
6287
1.22k
      break;
6288
6289
2.01M
    default:
6290
2.01M
      break;
6291
2.11M
    }
6292
2.11M
  return (c);
6293
2.11M
}
6294

6295
static segT
6296
get_segmented_expression (expressionS *expP)
6297
669
{
6298
669
  segT retval;
6299
6300
669
  retval = expression (expP);
6301
669
  if (expP->X_op == O_illegal
6302
669
      || expP->X_op == O_absent
6303
656
      || expP->X_op == O_big)
6304
51
    {
6305
51
      as_bad (_("expected address expression"));
6306
51
      expP->X_op = O_constant;
6307
51
      expP->X_add_number = 0;
6308
51
      retval = absolute_section;
6309
51
    }
6310
669
  return retval;
6311
669
}
6312
6313
static segT
6314
get_known_segmented_expression (expressionS *expP)
6315
669
{
6316
669
  segT retval = get_segmented_expression (expP);
6317
6318
669
  if (retval == undefined_section)
6319
463
    {
6320
      /* There is no easy way to extract the undefined symbol from the
6321
   expression.  */
6322
463
      if (expP->X_add_symbol != NULL
6323
463
    && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
6324
460
  as_warn (_("symbol \"%s\" undefined; zero assumed"),
6325
460
     S_GET_NAME (expP->X_add_symbol));
6326
3
      else
6327
3
  as_warn (_("some symbol undefined; zero assumed"));
6328
463
      retval = absolute_section;
6329
463
      expP->X_op = O_constant;
6330
463
      expP->X_add_number = 0;
6331
463
    }
6332
669
  return retval;
6333
669
}
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
34.6k
{
6349
34.6k
  char *s;
6350
6351
34.6k
  if ((s = demand_copy_string (len_pointer)) != 0)
6352
33.8k
    {
6353
33.8k
      int len;
6354
6355
1.28M
      for (len = *len_pointer; len > 0; len--)
6356
1.25M
  {
6357
1.25M
    if (s[len - 1] == 0)
6358
2
      {
6359
2
        s = NULL;
6360
2
        as_bad (_("this string may not contain \'\\0\'"));
6361
2
        break;
6362
2
      }
6363
1.25M
  }
6364
33.8k
    }
6365
6366
34.6k
  return s;
6367
34.6k
}
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
71.4k
{
6375
71.4k
  unsigned int c;
6376
71.4k
  int len;
6377
71.4k
  char *retval;
6378
6379
71.4k
  len = 0;
6380
71.4k
  SKIP_WHITESPACE ();
6381
71.4k
  if (*input_line_pointer == '\"')
6382
70.3k
    {
6383
70.3k
      input_line_pointer++; /* Skip opening quote.  */
6384
6385
2.11M
      while (is_a_char (c = next_char_of_string ()))
6386
2.04M
  {
6387
2.04M
    obstack_1grow (&notes, c);
6388
2.04M
    len++;
6389
2.04M
  }
6390
      /* JF this next line is so demand_copy_C_string will return a
6391
   null terminated string.  */
6392
70.3k
      obstack_1grow (&notes, '\0');
6393
70.3k
      retval = obstack_finish (&notes);
6394
70.3k
    }
6395
1.07k
  else
6396
1.07k
    {
6397
1.07k
      as_bad (_("missing string"));
6398
1.07k
      retval = NULL;
6399
1.07k
    }
6400
71.4k
  *lenP = len;
6401
71.4k
  return retval;
6402
71.4k
}
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
2.23k
{
6413
2.23k
  SKIP_WHITESPACE ();
6414
2.23k
  return is_end_of_stmt (*input_line_pointer);
6415
2.23k
}
6416
6417
void
6418
equals (char *sym_name, int reassign)
6419
8.94k
{
6420
8.94k
  char *stop = NULL;
6421
8.94k
  char stopc = 0;
6422
6423
8.94k
  input_line_pointer++;
6424
8.94k
  if (*input_line_pointer == '=')
6425
2.46k
    input_line_pointer++;
6426
8.94k
  if (reassign < 0 && *input_line_pointer == '=')
6427
477
    input_line_pointer++;
6428
6429
10.0k
  while (is_whitespace (*input_line_pointer))
6430
1.13k
    input_line_pointer++;
6431
6432
8.94k
  if (flag_mri)
6433
2.77k
    stop = mri_comment_field (&stopc);
6434
6435
8.94k
  assign_symbol (sym_name, reassign >= 0 ? !reassign : reassign);
6436
6437
8.94k
  if (flag_mri)
6438
2.77k
    {
6439
2.77k
      demand_empty_rest_of_line ();
6440
2.77k
      mri_comment_end (stop, stopc);
6441
2.77k
    }
6442
8.94k
}
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
113
{
6453
113
  FILE *f = fopen (filename, FOPEN_RB);
6454
113
  if (f == NULL && !IS_ABSOLUTE_PATH (filename))
6455
65
    {
6456
92
      for (size_t i = 0; i < include_dir_count; i++)
6457
65
  {
6458
65
    sprintf (path, "%s/%s", include_dirs[i], filename);
6459
65
    f = fopen (path, FOPEN_RB);
6460
65
    if (f != NULL)
6461
38
      return f;
6462
65
  }
6463
65
    }
6464
75
  strcpy (path, filename);
6465
75
  return f;
6466
113
}
6467
6468
/* .incbin -- include a file verbatim at the current location.  */
6469
6470
void
6471
s_incbin (int x ATTRIBUTE_UNUSED)
6472
241
{
6473
241
  FILE * binfile;
6474
241
  char * path;
6475
241
  char * filename;
6476
241
  char * binfrag;
6477
241
  long   skip = 0;
6478
241
  long   count = 0;
6479
241
  long   bytes;
6480
241
  int    len;
6481
6482
#ifdef md_flush_pending_output
6483
  md_flush_pending_output ();
6484
#endif
6485
6486
241
#ifdef md_cons_align
6487
241
  md_cons_align (1);
6488
241
#endif
6489
6490
241
  SKIP_WHITESPACE ();
6491
241
  filename = demand_copy_string (& len);
6492
241
  if (filename == NULL)
6493
197
    {
6494
197
      ignore_rest_of_line ();
6495
197
      return;
6496
197
    }
6497
6498
44
  SKIP_WHITESPACE ();
6499
6500
  /* Look for optional skip and count.  */
6501
44
  if (* input_line_pointer == ',')
6502
8
    {
6503
8
      ++ input_line_pointer;
6504
8
      skip = get_absolute_expression ();
6505
6506
8
      SKIP_WHITESPACE ();
6507
6508
8
      if (* input_line_pointer == ',')
6509
7
  {
6510
7
    ++ input_line_pointer;
6511
6512
7
    count = get_absolute_expression ();
6513
7
    if (count == 0)
6514
0
      as_warn (_(".incbin count zero, ignoring `%s'"), filename);
6515
6516
7
    SKIP_WHITESPACE ();
6517
7
  }
6518
8
    }
6519
6520
44
  demand_empty_rest_of_line ();
6521
6522
44
  path = XNEWVEC (char, len + include_dir_maxlen + 2);
6523
44
  binfile = search_and_open (filename, path);
6524
6525
44
  if (binfile == NULL)
6526
25
    as_bad (_("file not found: %s"), filename);
6527
19
  else
6528
19
    {
6529
19
      long   file_len;
6530
19
      struct stat filestat;
6531
6532
19
      if (fstat (fileno (binfile), &filestat) != 0
6533
19
    || ! S_ISREG (filestat.st_mode)
6534
19
    || S_ISDIR (filestat.st_mode))
6535
18
  {
6536
18
    as_bad (_("unable to include `%s'"), path);
6537
18
    goto done;
6538
18
  }
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
44
 done:
6576
44
  if (binfile != NULL)
6577
19
    fclose (binfile);
6578
44
  free (path);
6579
44
}
6580
6581
/* .include -- include a file at this point.  */
6582
6583
void
6584
s_include (int arg ATTRIBUTE_UNUSED)
6585
72
{
6586
72
  char *filename;
6587
72
  int i;
6588
72
  FILE *try_file;
6589
72
  char *path;
6590
6591
72
  if (!flag_m68k_mri)
6592
72
    {
6593
72
      filename = demand_copy_string (&i);
6594
72
      if (filename == NULL)
6595
3
  {
6596
    /* demand_copy_string has already printed an error.  */
6597
3
    ignore_rest_of_line ();
6598
3
    return;
6599
3
  }
6600
72
    }
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
69
  demand_empty_rest_of_line ();
6620
6621
69
  path = notes_alloc (i + include_dir_maxlen + 2);
6622
69
  try_file = search_and_open (filename, path);
6623
69
  if (try_file)
6624
51
    fclose (try_file);
6625
6626
69
  register_dependency (path);
6627
69
  input_scrub_insert_file (path);
6628
69
}
6629
6630
void
6631
init_include_dir (void)
6632
281
{
6633
281
  include_dirs = XNEWVEC (const char *, 1);
6634
281
  include_dirs[0] = ".";  /* Current dir.  */
6635
281
  include_dir_count = 1;
6636
281
  include_dir_maxlen = 1;
6637
281
}
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
281
{
6656
281
  if (debug_type == DEBUG_STABS)
6657
0
    stabs_generate_asm_file ();
6658
281
}
6659
6660
/* Output line number debugging information for the current source line.  */
6661
6662
void
6663
generate_lineno_debug (void)
6664
41.6k
{
6665
41.6k
  switch (debug_type)
6666
41.6k
    {
6667
1.10k
    case DEBUG_UNSPECIFIED:
6668
41.6k
    case DEBUG_NONE:
6669
41.6k
    case DEBUG_DWARF:
6670
41.6k
      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
41.6k
    }
6687
41.6k
}
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
50
{
6695
50
  do_s_func (end_p, NULL);
6696
50
}
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
50
{
6704
50
  if (end_p)
6705
25
    {
6706
25
      if (current_name == NULL)
6707
2
  {
6708
2
    as_bad (_("missing .func"));
6709
2
    ignore_rest_of_line ();
6710
2
    return;
6711
2
  }
6712
6713
23
      if (debug_type == DEBUG_STABS)
6714
0
  stabs_generate_asm_endfunc (current_name, current_label);
6715
6716
23
      free (current_name);
6717
23
      free (current_label);
6718
23
      current_name = current_label = NULL;
6719
23
    }
6720
25
  else /* ! end_p */
6721
25
    {
6722
25
      char *name, *label;
6723
25
      char delim1, delim2;
6724
6725
25
      if (current_name != NULL)
6726
0
  {
6727
0
    as_bad (_(".endfunc missing for previous .func"));
6728
0
    ignore_rest_of_line ();
6729
0
    return;
6730
0
  }
6731
6732
25
      delim1 = get_symbol_name (& name);
6733
25
      name = xstrdup (name);
6734
25
      restore_line_pointer (delim1);
6735
25
      SKIP_WHITESPACE ();
6736
25
      if (*input_line_pointer != ',')
6737
2
  {
6738
2
    if (default_prefix)
6739
0
      label = xasprintf ("%s%s", default_prefix, name);
6740
2
    else
6741
2
      {
6742
2
        char leading_char = bfd_get_symbol_leading_char (stdoutput);
6743
        /* Missing entry point, use function's name with the leading
6744
     char prepended.  */
6745
2
        if (leading_char)
6746
0
    label = xasprintf ("%c%s", leading_char, name);
6747
2
        else
6748
2
    label = xstrdup (name);
6749
2
      }
6750
2
  }
6751
23
      else
6752
23
  {
6753
23
    ++input_line_pointer;
6754
23
    SKIP_WHITESPACE ();
6755
23
    delim2 = get_symbol_name (& label);
6756
23
    label = xstrdup (label);
6757
23
    restore_line_pointer (delim2);
6758
23
  }
6759
6760
25
      if (debug_type == DEBUG_STABS)
6761
0
  stabs_generate_asm_func (name, label);
6762
6763
25
      current_name = name;
6764
25
      current_label = label;
6765
25
    }
6766
6767
48
  demand_empty_rest_of_line ();
6768
48
}
6769

6770
#ifdef HANDLE_BUNDLE
6771
6772
void
6773
s_bundle_align_mode (int arg ATTRIBUTE_UNUSED)
6774
32
{
6775
32
  unsigned int align = get_absolute_expression ();
6776
32
  SKIP_WHITESPACE ();
6777
32
  demand_empty_rest_of_line ();
6778
6779
32
  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
32
  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
32
  bundle_align_p2 = align;
6790
32
}
6791
6792
void
6793
s_bundle_lock (int arg ATTRIBUTE_UNUSED)
6794
36
{
6795
36
  demand_empty_rest_of_line ();
6796
6797
36
  if (bundle_align_p2 == 0)
6798
34
    {
6799
34
      as_bad (_(".bundle_lock is meaningless without .bundle_align_mode"));
6800
34
      return;
6801
34
    }
6802
6803
2
  if (bundle_lock_depth == 0)
6804
2
    {
6805
2
      bundle_lock_frchain = frchain_now;
6806
2
      bundle_lock_frag = start_bundle ();
6807
2
    }
6808
2
  ++bundle_lock_depth;
6809
2
}
6810
6811
void
6812
s_bundle_unlock (int arg ATTRIBUTE_UNUSED)
6813
2
{
6814
2
  valueT size;
6815
6816
2
  demand_empty_rest_of_line ();
6817
6818
2
  if (bundle_lock_frag == NULL)
6819
0
    {
6820
0
      as_bad (_(".bundle_unlock without preceding .bundle_lock"));
6821
0
      return;
6822
0
    }
6823
6824
2
  gas_assert (bundle_align_p2 > 0);
6825
6826
2
  gas_assert (bundle_lock_depth > 0);
6827
2
  if (--bundle_lock_depth > 0)
6828
0
    return;
6829
6830
2
  size = pending_bundle_size (bundle_lock_frag);
6831
6832
2
  if (size > (valueT) 1 << bundle_align_p2)
6833
0
    as_bad (_(".bundle_lock sequence is %" PRIu64 " bytes, "
6834
0
        "but bundle size is only %" PRIu64 " bytes"),
6835
0
      (uint64_t) size, (uint64_t) 1 << bundle_align_p2);
6836
2
  else
6837
2
    finish_bundle (bundle_lock_frag, size);
6838
6839
2
  bundle_lock_frag = NULL;
6840
2
  bundle_lock_frchain = NULL;
6841
2
}
6842
6843
#endif  /* HANDLE_BUNDLE */
6844

6845
void
6846
s_ignore (int arg ATTRIBUTE_UNUSED)
6847
31.7k
{
6848
31.7k
  ignore_rest_of_line ();
6849
31.7k
}
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
69
{
6884
69
  input_scrub_include_file (path, input_line_pointer);
6885
69
  buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6886
69
}
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
56.0k
{
6898
56.0k
  char inquote = '\0';
6899
56.0k
  int inescape = 0;
6900
6901
1.20M
  while (!is_end_of_stmt (*s)
6902
56.0k
   || (inquote && !ISCNTRL (*s))
6903
56.0k
   || (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
56.0k
   || (in_macro && inescape && *s == '@')
6914
56.0k
  )
6915
1.14M
    {
6916
1.14M
      if (mri_string && *s == '\'')
6917
0
  inquote ^= *s;
6918
1.14M
      else if (inescape)
6919
4.42k
  inescape = 0;
6920
1.13M
      else if (*s == '\\')
6921
4.44k
  inescape = 1;
6922
1.13M
      else if (!inquote
6923
1.13M
         ? *s == '"'
6924
#ifdef TC_SINGLE_QUOTE_STRINGS
6925
     || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
6926
#endif
6927
1.13M
         : *s == inquote)
6928
7.33k
  inquote ^= *s;
6929
1.14M
      ++s;
6930
1.14M
    }
6931
56.0k
  if (inquote)
6932
3.07k
    as_warn (_("missing closing `%c'"), inquote);
6933
56.0k
  if (inescape && !ignore_input ())
6934
18
    as_warn (_("stray `\\'"));
6935
56.0k
  return s;
6936
56.0k
}
6937
6938
char *
6939
find_end_of_line (char *s, int mri_string)
6940
8.23k
{
6941
8.23k
  return _find_end_of_line (s, mri_string, 0, 0);
6942
8.23k
}
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
3
{
6958
3
  gas_assert (saved_ilp == NULL);
6959
3
  gas_assert (buf != NULL);
6960
6961
3
  saved_ilp = input_line_pointer;
6962
3
  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
3
  if (saved_ilp == NULL)
6966
0
    saved_limit = saved_ilp = (char *) "";
6967
6968
3
  input_line_pointer = buf;
6969
3
  buffer_limit = buf + strlen (buf);
6970
3
  input_from_string = true;
6971
3
}
6972
6973
/* Restore a saved input line pointer.  */
6974
6975
void
6976
restore_ilp (void)
6977
3
{
6978
3
  gas_assert (saved_ilp != NULL);
6979
6980
3
  input_line_pointer = saved_ilp;
6981
3
  buffer_limit = saved_limit;
6982
3
  input_from_string = false;
6983
6984
  saved_ilp = NULL;
6985
3
}