Coverage Report

Created: 2026-07-12 09:22

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