Coverage Report

Created: 2026-05-11 07:54

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