Coverage Report

Created: 2024-05-21 06:29

/src/binutils-gdb/gas/read.c
Line
Count
Source (jump to first uncovered line)
1
/* read.c - read a source file -
2
   Copyright (C) 1986-2024 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
2.23M
#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
13
  do                \
57
13
    {               \
58
13
      if ((SIZE) >= 8)           \
59
13
  (P2VAR) = 3;           \
60
13
      else if ((SIZE) >= 4)         \
61
10
  (P2VAR) = 2;           \
62
10
      else if ((SIZE) >= 2)         \
63
10
  (P2VAR) = 1;           \
64
10
      else              \
65
10
  (P2VAR) = 0;           \
66
13
    }               \
67
13
  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 LEX_AT
80
#define LEX_AT 0
81
#endif
82
83
#ifndef LEX_BR
84
/* The RS/6000 assembler uses {,},[,] as parts of symbol names.  */
85
#define LEX_BR 0
86
#endif
87
88
#ifndef LEX_PCT
89
/* The Delta 68k assembler permits % inside label names.  */
90
#define LEX_PCT 0
91
#endif
92
93
#ifndef LEX_QM
94
/* The PowerPC Windows NT assemblers permits ? inside label names.  */
95
#define LEX_QM 0
96
#endif
97
98
#ifndef LEX_HASH
99
/* The IA-64 assembler uses # as a suffix designating a symbol.  We include
100
   it in the symbol and strip it out in tc_canonicalize_symbol_name.  */
101
#define LEX_HASH 0
102
#endif
103
104
#ifndef LEX_DOLLAR
105
#define LEX_DOLLAR 3
106
#endif
107
108
#ifndef LEX_TILDE
109
/* The Delta 68k assembler permits ~ at start of label names.  */
110
#define LEX_TILDE 0
111
#endif
112
113
/* Used by is_... macros. our ctype[].  */
114
char lex_type[256] = {
115
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
116
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
117
  0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
118
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM,  /* 0123456789:;<=>? */
119
  LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,  /* @ABCDEFGHIJKLMNO */
120
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
121
  0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
122
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~.  */
123
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
124
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
125
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
126
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
127
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
128
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
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
};
132
133
/* In: a character.
134
   Out: 1 if this character ends a line.
135
  2 if this character is a line separator.  */
136
char is_end_of_line[256] = {
137
#ifdef CR_EOL
138
  1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, /* @abcdefghijklmno */
139
#else
140
  1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, /* @abcdefghijklmno */
141
#endif
142
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
143
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* _!"#$%&'()*+,-./ */
144
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
145
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
146
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
147
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
148
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
149
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
150
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
151
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
152
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
153
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
154
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
155
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */
156
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0  /* */
157
};
158
159
#ifndef TC_CASE_SENSITIVE
160
char original_case_string[128];
161
#endif
162
163
/* Functions private to this file.  */
164
165
static char *buffer;  /* 1st char of each buffer of lines is here.  */
166
static char *buffer_limit;  /*->1 + last char in buffer.  */
167
168
/* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
169
   in the tc-<CPU>.h file.  See the "Porting GAS" section of the
170
   internals manual.  */
171
int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
172
173
/* Variables for handling include file directory table.  */
174
175
/* Table of pointers to directories to search for .include's.  */
176
const char **include_dirs;
177
178
/* How many are in the table.  */
179
size_t include_dir_count;
180
181
/* Length of longest in table.  */
182
size_t include_dir_maxlen;
183
184
#ifndef WORKING_DOT_WORD
185
struct broken_word *broken_words;
186
int new_broken_words;
187
#endif
188
189
/* The current offset into the absolute section.  We don't try to
190
   build frags in the absolute section, since no data can be stored
191
   there.  We just keep track of the current offset.  */
192
addressT abs_section_offset;
193
194
/* If this line had an MRI style label, it is stored in this variable.
195
   This is used by some of the MRI pseudo-ops.  */
196
symbolS *line_label;
197
198
/* This global variable is used to support MRI common sections.  We
199
   translate such sections into a common symbol.  This variable is
200
   non-NULL when we are in an MRI common section.  */
201
symbolS *mri_common_symbol;
202
203
/* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
204
   need to align to an even byte boundary unless the next pseudo-op is
205
   dc.b, ds.b, or dcb.b.  This variable is set to 1 if an alignment
206
   may be needed.  */
207
static int mri_pending_align;
208
209
/* Record the current function so that we can issue an error message for
210
   misplaced .func,.endfunc, and also so that .endfunc needs no
211
   arguments.  */
212
static char *current_name;
213
static char *current_label;
214
215
#ifndef NO_LISTING
216
#ifdef OBJ_ELF
217
static int dwarf_file;
218
static int dwarf_line;
219
220
/* This variable is set to be non-zero if the next string we see might
221
   be the name of the source file in DWARF debugging information.  See
222
   the comment in emit_expr for the format we look for.  */
223
static int dwarf_file_string;
224
#endif
225
#endif
226
227
/* If the target defines the md_frag_max_var hook then we know
228
   enough to implement the .bundle_align_mode features.  */
229
#ifdef md_frag_max_var
230
# define HANDLE_BUNDLE
231
#endif
232
233
#ifdef HANDLE_BUNDLE
234
/* .bundle_align_mode sets this.  Normally it's zero.  When nonzero,
235
   it's the exponent of the bundle size, and aligned instruction bundle
236
   mode is in effect.  */
237
static unsigned int bundle_align_p2;
238
239
/* These are set by .bundle_lock and .bundle_unlock.  .bundle_lock sets
240
   bundle_lock_frag to frag_now and then starts a new frag with
241
   frag_align_code.  At the same time, bundle_lock_frain gets frchain_now,
242
   so that .bundle_unlock can verify that we didn't change segments.
243
   .bundle_unlock resets both to NULL.  If we detect a bundling violation,
244
   then we reset bundle_lock_frchain to NULL as an indicator that we've
245
   already diagnosed the error with as_bad and don't need a cascade of
246
   redundant errors, but bundle_lock_frag remains set to indicate that
247
   we are expecting to see .bundle_unlock.  */
248
static fragS *bundle_lock_frag;
249
static frchainS *bundle_lock_frchain;
250
251
/* This is incremented by .bundle_lock and decremented by .bundle_unlock,
252
   to allow nesting.  */
253
static unsigned int bundle_lock_depth;
254
#endif
255
256
static void do_s_func (int end_p, const char *default_prefix);
257
static void s_align (int, int);
258
static void s_altmacro (int);
259
static void s_bad_end (int);
260
static void s_reloc (int);
261
static int hex_float (int, char *);
262
static segT get_known_segmented_expression (expressionS * expP);
263
static void pobegin (void);
264
static void poend (void);
265
static size_t get_non_macro_line_sb (sb *);
266
static void generate_file_debug (void);
267
static char *_find_end_of_line (char *, int, int, int);
268

269
void
270
read_begin (void)
271
736
{
272
736
  const char *p;
273
274
736
  pobegin ();
275
736
  obj_read_begin_hook ();
276
277
736
  obstack_begin (&cond_obstack, chunksize);
278
279
736
#ifndef tc_line_separator_chars
280
736
#define tc_line_separator_chars line_separator_chars
281
736
#endif
282
  /* Use machine dependent syntax.  */
283
1.47k
  for (p = tc_line_separator_chars; *p; p++)
284
736
    is_end_of_line[(unsigned char) *p] = 2;
285
  /* Use more.  FIXME-SOMEDAY.  */
286
287
736
  if (flag_mri)
288
119
    lex_type['?'] = 3;
289
736
  stabs_begin ();
290
291
#ifndef WORKING_DOT_WORD
292
  broken_words = NULL;
293
  new_broken_words = 0;
294
#endif
295
296
736
  abs_section_offset = 0;
297
298
736
  line_label = NULL;
299
736
  mri_common_symbol = NULL;
300
736
  mri_pending_align = 0;
301
302
736
  current_name = NULL;
303
736
  current_label = NULL;
304
305
736
#ifndef NO_LISTING
306
736
#ifdef OBJ_ELF
307
736
  dwarf_file = 0;
308
736
  dwarf_line = -1;
309
736
  dwarf_file_string = 0;
310
736
#endif
311
736
#endif
312
313
736
#ifdef HANDLE_BUNDLE
314
736
  bundle_align_p2 = 0;
315
736
  bundle_lock_frag = NULL;
316
736
  bundle_lock_frchain = NULL;
317
736
  bundle_lock_depth = 0;
318
736
#endif
319
736
}
320
321
void
322
read_end (void)
323
736
{
324
736
  stabs_end ();
325
736
  poend ();
326
736
  _obstack_free (&cond_obstack, NULL);
327
736
  free (current_name);
328
736
  free (current_label);
329
736
}
330

331
#ifndef TC_ADDRESS_BYTES
332
#define TC_ADDRESS_BYTES address_bytes
333
334
static inline int
335
address_bytes (void)
336
{
337
  /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
338
     contain an address.  */
339
  int n = (stdoutput->arch_info->bits_per_address - 1) / 8;
340
  n |= n >> 1;
341
  n |= n >> 2;
342
  n += 1;
343
  return n;
344
}
345
#endif
346
347
/* Set up pseudo-op tables.  */
348
349
static htab_t po_hash;
350
351
static const pseudo_typeS potable[] = {
352
  {"abort", s_abort, 0},
353
  {"align", s_align_ptwo, 0},
354
  {"altmacro", s_altmacro, 1},
355
  {"ascii", stringer, 8+0},
356
  {"asciz", stringer, 8+1},
357
  {"balign", s_align_bytes, 0},
358
  {"balignw", s_align_bytes, -2},
359
  {"balignl", s_align_bytes, -4},
360
/* block  */
361
#ifdef HANDLE_BUNDLE
362
  {"bundle_align_mode", s_bundle_align_mode, 0},
363
  {"bundle_lock", s_bundle_lock, 0},
364
  {"bundle_unlock", s_bundle_unlock, 0},
365
#endif
366
  {"byte", cons, 1},
367
  {"comm", s_comm, 0},
368
  {"common", s_mri_common, 0},
369
  {"common.s", s_mri_common, 1},
370
  {"data", s_data, 0},
371
  {"dc", cons, 2},
372
  {"dc.a", cons, 0},
373
  {"dc.b", cons, 1},
374
  {"dc.d", float_cons, 'd'},
375
  {"dc.l", cons, 4},
376
  {"dc.s", float_cons, 'f'},
377
  {"dc.w", cons, 2},
378
  {"dc.x", float_cons, 'x'},
379
  {"dcb", s_space, 2},
380
  {"dcb.b", s_space, 1},
381
  {"dcb.d", s_float_space, 'd'},
382
  {"dcb.l", s_space, 4},
383
  {"dcb.s", s_float_space, 'f'},
384
  {"dcb.w", s_space, 2},
385
  {"dcb.x", s_float_space, 'x'},
386
  {"ds", s_space, 2},
387
  {"ds.b", s_space, 1},
388
  {"ds.d", s_space, 8},
389
  {"ds.l", s_space, 4},
390
  {"ds.p", s_space, 'p'},
391
  {"ds.s", s_space, 4},
392
  {"ds.w", s_space, 2},
393
  {"ds.x", s_space, 'x'},
394
  {"debug", s_ignore, 0},
395
#ifdef S_SET_DESC
396
  {"desc", s_desc, 0},
397
#endif
398
/* dim  */
399
  {"double", float_cons, 'd'},
400
/* dsect  */
401
  {"eject", listing_eject, 0},  /* Formfeed listing.  */
402
  {"else", s_else, 0},
403
  {"elsec", s_else, 0},
404
  {"elseif", s_elseif, (int) O_ne},
405
  {"end", s_end, 0},
406
  {"endc", s_endif, 0},
407
  {"endfunc", s_func, 1},
408
  {"endif", s_endif, 0},
409
  {"endm", s_bad_end, 0},
410
  {"endr", s_bad_end, 1},
411
/* endef  */
412
  {"equ", s_set, 0},
413
  {"equiv", s_set, 1},
414
  {"eqv", s_set, -1},
415
  {"err", s_err, 0},
416
  {"error", s_errwarn, 1},
417
  {"exitm", s_mexit, 0},
418
/* extend  */
419
  {"extern", s_ignore, 0},  /* We treat all undef as ext.  */
420
  {"fail", s_fail, 0},
421
  {"file", s_file, 0},
422
  {"fill", s_fill, 0},
423
  {"float", float_cons, 'f'},
424
  {"format", s_ignore, 0},
425
  {"func", s_func, 0},
426
  {"global", s_globl, 0},
427
  {"globl", s_globl, 0},
428
  {"hword", cons, 2},
429
  {"if", s_if, (int) O_ne},
430
  {"ifb", s_ifb, 1},
431
  {"ifc", s_ifc, 0},
432
  {"ifdef", s_ifdef, 0},
433
  {"ifeq", s_if, (int) O_eq},
434
  {"ifeqs", s_ifeqs, 0},
435
  {"ifge", s_if, (int) O_ge},
436
  {"ifgt", s_if, (int) O_gt},
437
  {"ifle", s_if, (int) O_le},
438
  {"iflt", s_if, (int) O_lt},
439
  {"ifnb", s_ifb, 0},
440
  {"ifnc", s_ifc, 1},
441
  {"ifndef", s_ifdef, 1},
442
  {"ifne", s_if, (int) O_ne},
443
  {"ifnes", s_ifeqs, 1},
444
  {"ifnotdef", s_ifdef, 1},
445
  {"incbin", s_incbin, 0},
446
  {"include", s_include, 0},
447
  {"int", cons, 4},
448
  {"irp", s_irp, 0},
449
  {"irep", s_irp, 0},
450
  {"irpc", s_irp, 1},
451
  {"irepc", s_irp, 1},
452
  {"lcomm", s_lcomm, 0},
453
  {"lflags", s_ignore, 0},  /* Listing flags.  */
454
  {"linefile", s_linefile, 0},
455
  {"linkonce", s_linkonce, 0},
456
  {"list", listing_list, 1},  /* Turn listing on.  */
457
  {"llen", listing_psize, 1},
458
  {"long", cons, 4},
459
  {"lsym", s_lsym, 0},
460
  {"macro", s_macro, 0},
461
  {"mexit", s_mexit, 0},
462
  {"mri", s_mri, 0},
463
  {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode.  */
464
  {"name", s_ignore, 0},
465
  {"noaltmacro", s_altmacro, 0},
466
  {"noformat", s_ignore, 0},
467
  {"nolist", listing_list, 0},  /* Turn listing off.  */
468
  {"nopage", listing_nopage, 0},
469
  {"nop", s_nop, 0},
470
  {"nops", s_nops, 0},
471
  {"octa", cons, 16},
472
  {"offset", s_struct, 0},
473
  {"org", s_org, 0},
474
  {"p2align", s_align_ptwo, 0},
475
  {"p2alignw", s_align_ptwo, -2},
476
  {"p2alignl", s_align_ptwo, -4},
477
  {"page", listing_eject, 0},
478
  {"plen", listing_psize, 0},
479
  {"print", s_print, 0},
480
  {"psize", listing_psize, 0},  /* Set paper size.  */
481
  {"purgem", s_purgem, 0},
482
  {"quad", cons, 8},
483
  {"reloc", s_reloc, 0},
484
  {"rep", s_rept, 0},
485
  {"rept", s_rept, 0},
486
  {"rva", s_rva, 4},
487
  {"sbttl", listing_title, 1},  /* Subtitle of listing.  */
488
/* scl  */
489
/* sect  */
490
  {"set", s_set, 0},
491
  {"short", cons, 2},
492
  {"single", float_cons, 'f'},
493
/* size  */
494
  {"space", s_space, 0},
495
  {"skip", s_space, 0},
496
  {"sleb128", s_leb128, 1},
497
  {"spc", s_ignore, 0},
498
  {"stabd", s_stab, 'd'},
499
  {"stabn", s_stab, 'n'},
500
  {"stabs", s_stab, 's'},
501
  {"string", stringer, 8+1},
502
  {"string8", stringer, 8+1},
503
  {"string16", stringer, 16+1},
504
  {"string32", stringer, 32+1},
505
  {"string64", stringer, 64+1},
506
  {"struct", s_struct, 0},
507
/* tag  */
508
  {"text", s_text, 0},
509
510
  /* This is for gcc to use.  It's only just been added (2/94), so gcc
511
     won't be able to use it for a while -- probably a year or more.
512
     But once this has been released, check with gcc maintainers
513
     before deleting it or even changing the spelling.  */
514
  {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
515
  /* If we're folding case -- done for some targets, not necessarily
516
     all -- the above string in an input file will be converted to
517
     this one.  Match it either way...  */
518
  {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
519
520
  {"title", listing_title, 0},  /* Listing title.  */
521
  {"ttl", listing_title, 0},
522
/* type  */
523
  {"uleb128", s_leb128, 0},
524
/* use  */
525
/* val  */
526
  {"xcom", s_comm, 0},
527
  {"xdef", s_globl, 0},
528
  {"xref", s_ignore, 0},
529
  {"xstabs", s_xstab, 's'},
530
  {"warning", s_errwarn, 0},
531
  {"weakref", s_weakref, 0},
532
  {"word", cons, 2},
533
  {"zero", s_space, 0},
534
  {"2byte", cons, 2},
535
  {"4byte", cons, 4},
536
  {"8byte", cons, 8},
537
  {NULL, NULL, 0}     /* End sentinel.  */
538
};
539
540
static offsetT
541
get_absolute_expr (expressionS *exp)
542
134k
{
543
134k
  expression_and_evaluate (exp);
544
545
134k
  if (exp->X_op != O_constant)
546
53.3k
    {
547
53.3k
      if (exp->X_op != O_absent)
548
41.7k
  as_bad (_("bad or irreducible absolute expression"));
549
53.3k
      exp->X_add_number = 0;
550
53.3k
    }
551
134k
  return exp->X_add_number;
552
134k
}
553
554
offsetT
555
get_absolute_expression (void)
556
106k
{
557
106k
  expressionS exp;
558
559
106k
  return get_absolute_expr (&exp);
560
106k
}
561
562
static int pop_override_ok;
563
static const char *pop_table_name;
564
565
void
566
pop_insert (const pseudo_typeS *table)
567
2.94k
{
568
2.94k
  const pseudo_typeS *pop;
569
184k
  for (pop = table; pop->poc_name; pop++)
570
181k
    {
571
181k
      if (str_hash_insert (po_hash, pop->poc_name, pop, 0) != NULL)
572
6.62k
  {
573
6.62k
    if (!pop_override_ok)
574
0
      as_fatal (_("error constructing %s pseudo-op table"),
575
0
          pop_table_name);
576
6.62k
  }
577
181k
    }
578
2.94k
}
579
580
#ifndef md_pop_insert
581
736
#define md_pop_insert()   pop_insert(md_pseudo_table)
582
#endif
583
584
#ifndef obj_pop_insert
585
#define obj_pop_insert()  pop_insert(obj_pseudo_table)
586
#endif
587
588
#ifndef cfi_pop_insert
589
736
#define cfi_pop_insert()  pop_insert(cfi_pseudo_table)
590
#endif
591
592
#ifndef scfi_pop_insert
593
0
#define scfi_pop_insert() pop_insert(scfi_pseudo_table)
594
#endif
595
596
static void
597
pobegin (void)
598
736
{
599
736
  po_hash = str_htab_create ();
600
601
  /* Do the target-specific pseudo ops.  */
602
736
  pop_table_name = "md";
603
736
  pop_override_ok = 0;
604
736
  md_pop_insert ();
605
606
  /* Now object specific.  Skip any that were in the target table.  */
607
736
  pop_table_name = "obj";
608
736
  pop_override_ok = 1;
609
736
  obj_pop_insert ();
610
611
  /* Now portable ones.  Skip any that we've seen already.  */
612
736
  pop_table_name = "standard";
613
736
  pop_insert (potable);
614
615
  /* Now CFI ones.  */
616
736
#if defined (TARGET_USE_SCFI) && defined (TARGET_USE_GINSN)
617
736
  if (flag_synth_cfi)
618
0
    {
619
0
      pop_table_name = "scfi";
620
0
      scfi_pop_insert ();
621
0
    }
622
736
  else
623
736
#endif
624
736
    {
625
736
      pop_table_name = "cfi";
626
736
      cfi_pop_insert ();
627
736
    }
628
736
}
629
630
static void
631
poend (void)
632
736
{
633
736
  htab_delete (po_hash);
634
736
}
635

636
#define HANDLE_CONDITIONAL_ASSEMBLY(num_read)       \
637
3.73M
  if (ignore_input ())             \
638
3.73M
    {                 \
639
26.0k
      char *eol = find_end_of_line (input_line_pointer - (num_read),  \
640
26.0k
            flag_m68k_mri);      \
641
26.0k
      input_line_pointer = (input_line_pointer <= buffer_limit    \
642
26.0k
          && eol >= buffer_limit)     \
643
26.0k
         ? buffer_limit        \
644
26.0k
         : eol + 1;         \
645
26.0k
      continue;               \
646
26.0k
    }
647
648
/* Helper function of read_a_source_file, which tries to expand a macro.  */
649
static int
650
try_macro (char term, const char *line)
651
340k
{
652
340k
  sb out;
653
340k
  const char *err;
654
340k
  macro_entry *macro;
655
656
340k
  if (check_macro (line, &out, &err, &macro))
657
14.4k
    {
658
14.4k
      if (err != NULL)
659
8.92k
  as_bad ("%s", err);
660
14.4k
      *input_line_pointer++ = term;
661
14.4k
      input_scrub_include_sb (&out,
662
14.4k
            input_line_pointer, expanding_macro);
663
14.4k
      sb_kill (&out);
664
14.4k
      buffer_limit =
665
14.4k
  input_scrub_next_buffer (&input_line_pointer);
666
#ifdef md_macro_info
667
      md_macro_info (macro);
668
#endif
669
14.4k
      return 1;
670
14.4k
    }
671
326k
  return 0;
672
340k
}
673
674
#ifdef HANDLE_BUNDLE
675
/* Start a new instruction bundle.  Returns the rs_align_code frag that
676
   will be used to align the new bundle.  */
677
static fragS *
678
start_bundle (void)
679
0
{
680
0
  fragS *frag = frag_now;
681
682
0
  frag_align_code (0, 0);
683
684
0
  while (frag->fr_type != rs_align_code)
685
0
    frag = frag->fr_next;
686
687
0
  gas_assert (frag != frag_now);
688
689
0
  return frag;
690
0
}
691
692
/* Calculate the maximum size after relaxation of the region starting
693
   at the given frag and extending through frag_now (which is unfinished).  */
694
static unsigned int
695
pending_bundle_size (fragS *frag)
696
0
{
697
0
  unsigned int offset = frag->fr_fix;
698
0
  unsigned int size = 0;
699
700
0
  gas_assert (frag != frag_now);
701
0
  gas_assert (frag->fr_type == rs_align_code);
702
703
0
  while (frag != frag_now)
704
0
    {
705
      /* This should only happen in what will later become an error case.  */
706
0
      if (frag == NULL)
707
0
  return 0;
708
709
0
      size += frag->fr_fix;
710
0
      if (frag->fr_type == rs_machine_dependent)
711
0
  size += md_frag_max_var (frag);
712
713
0
      frag = frag->fr_next;
714
0
    }
715
716
0
  gas_assert (frag == frag_now);
717
0
  size += frag_now_fix ();
718
0
  if (frag->fr_type == rs_machine_dependent)
719
0
    size += md_frag_max_var (frag);
720
721
0
  gas_assert (size >= offset);
722
723
0
  return size - offset;
724
0
}
725
726
/* Finish off the frag created to ensure bundle alignment.  */
727
static void
728
finish_bundle (fragS *frag, unsigned int size)
729
0
{
730
0
  gas_assert (bundle_align_p2 > 0);
731
0
  gas_assert (frag->fr_type == rs_align_code);
732
733
0
  if (size > 1)
734
0
    {
735
      /* If there is more than a single byte, then we need to set up the
736
   alignment frag.  Otherwise we leave it at its initial state from
737
   calling frag_align_code (0, 0), so that it does nothing.  */
738
0
      frag->fr_offset = bundle_align_p2;
739
0
      frag->fr_subtype = size - 1;
740
0
    }
741
742
  /* We do this every time rather than just in s_bundle_align_mode
743
     so that we catch any affected section without needing hooks all
744
     over for all paths that do section changes.  It's cheap enough.  */
745
0
  if (bundle_align_p2 > OCTETS_PER_BYTE_POWER)
746
0
    record_alignment (now_seg, bundle_align_p2 - OCTETS_PER_BYTE_POWER);
747
0
}
748
749
/* Assemble one instruction.  This takes care of the bundle features
750
   around calling md_assemble.  */
751
static void
752
assemble_one (char *line)
753
1.27M
{
754
1.27M
  fragS *insn_start_frag = NULL;
755
756
1.27M
  if (bundle_lock_frchain != NULL && bundle_lock_frchain != frchain_now)
757
0
    {
758
0
      as_bad (_("cannot change section or subsection inside .bundle_lock"));
759
      /* Clearing this serves as a marker that we have already complained.  */
760
0
      bundle_lock_frchain = NULL;
761
0
    }
762
763
1.27M
  if (bundle_lock_frchain == NULL && bundle_align_p2 > 0)
764
0
    insn_start_frag = start_bundle ();
765
766
1.27M
  md_assemble (line);
767
768
1.27M
  if (bundle_lock_frchain != NULL)
769
0
    {
770
      /* Make sure this hasn't pushed the locked sequence
771
   past the bundle size.  */
772
0
      unsigned int bundle_size = pending_bundle_size (bundle_lock_frag);
773
0
      if (bundle_size > 1U << bundle_align_p2)
774
0
  as_bad (_ (".bundle_lock sequence at %u bytes, "
775
0
       "but .bundle_align_mode limit is %u bytes"),
776
0
    bundle_size, 1U << bundle_align_p2);
777
0
    }
778
1.27M
  else if (bundle_align_p2 > 0)
779
0
    {
780
0
      unsigned int insn_size = pending_bundle_size (insn_start_frag);
781
782
0
      if (insn_size > 1U << bundle_align_p2)
783
0
  as_bad (_("single instruction is %u bytes long, "
784
0
      "but .bundle_align_mode limit is %u bytes"),
785
0
    insn_size, 1U << bundle_align_p2);
786
787
0
      finish_bundle (insn_start_frag, insn_size);
788
0
    }
789
1.27M
}
790
791
#else  /* !HANDLE_BUNDLE */
792
793
# define assemble_one(line) md_assemble(line)
794
795
#endif  /* HANDLE_BUNDLE */
796
797
static bool
798
in_bss (void)
799
1.20M
{
800
1.20M
  flagword flags = bfd_section_flags (now_seg);
801
802
1.20M
  return (flags & SEC_ALLOC) && !(flags & (SEC_LOAD | SEC_HAS_CONTENTS));
803
1.20M
}
804
805
/* Guts of .align directive:
806
   N is the power of two to which to align.  A value of zero is accepted but
807
    ignored: the default alignment of the section will be at least this.
808
   FILL may be NULL, or it may point to the bytes of the fill pattern.
809
   LEN is the length of whatever FILL points to, if anything.  If LEN is zero
810
    but FILL is not NULL then LEN is treated as if it were one.
811
   MAX is the maximum number of characters to skip when doing the alignment,
812
    or 0 if there is no maximum.  */
813
814
void
815
do_align (unsigned int n, char *fill, unsigned int len, unsigned int max)
816
13.5k
{
817
13.5k
  if (now_seg == absolute_section || in_bss ())
818
11.3k
    {
819
11.3k
      if (fill != NULL)
820
5.33k
  while (len-- > 0)
821
5.03k
    if (*fill++ != '\0')
822
4.74k
      {
823
4.74k
        if (now_seg == absolute_section)
824
4.71k
    as_warn (_("ignoring fill value in absolute section"));
825
22
        else
826
22
    as_warn (_("ignoring fill value in section `%s'"),
827
22
       segment_name (now_seg));
828
4.74k
        break;
829
4.74k
      }
830
11.3k
      fill = NULL;
831
11.3k
      len = 0;
832
11.3k
    }
833
834
#ifdef md_flush_pending_output
835
  md_flush_pending_output ();
836
#endif
837
838
13.5k
#ifdef md_do_align
839
13.5k
  md_do_align (n, fill, len, max, just_record_alignment);
840
13.1k
#endif
841
842
  /* Only make a frag if we HAVE to...  */
843
13.1k
  if ((n > OCTETS_PER_BYTE_POWER) && !need_pass_2)
844
6.54k
    {
845
6.54k
      if (fill == NULL)
846
6.37k
  {
847
6.37k
    if (subseg_text_p (now_seg))
848
0
      frag_align_code (n, max);
849
6.37k
    else
850
6.37k
      frag_align (n, 0, max);
851
6.37k
  }
852
173
      else if (len <= 1)
853
173
  frag_align (n, *fill, max);
854
0
      else
855
0
  frag_align_pattern (n, fill, len, max);
856
6.54k
    }
857
858
13.1k
#ifdef md_do_align
859
13.5k
 just_record_alignment: ATTRIBUTE_UNUSED_LABEL
860
13.5k
#endif
861
862
13.5k
  if (n > OCTETS_PER_BYTE_POWER)
863
6.87k
    record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
864
13.5k
}
865
866
/* We read the file, putting things into a web that represents what we
867
   have been reading.  */
868
void
869
read_a_source_file (const char *name)
870
736
{
871
736
  char nul_char;
872
736
  char next_char;
873
736
  char *s;    /* String of symbol, '\0' appended.  */
874
736
  long temp;
875
736
  const pseudo_typeS *pop;
876
877
#ifdef WARN_COMMENTS
878
  found_comment = 0;
879
#endif
880
881
736
  buffer = input_scrub_new_file (name);
882
883
736
  listing_file (name);
884
736
  listing_newline (NULL);
885
736
  register_dependency (name);
886
887
  /* Generate debugging information before we've read anything in to denote
888
     this file as the "main" source file and not a subordinate one
889
     (e.g. N_SO vs N_SOL in stabs).  */
890
736
  generate_file_debug ();
891
892
10.2k
  while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
893
9.56k
    {       /* We have another line to parse.  */
894
9.56k
#ifndef NO_LISTING
895
      /* In order to avoid listing macro expansion lines with labels
896
   multiple times, keep track of which line was last issued.  */
897
9.56k
      char *last_eol = NULL;
898
899
9.56k
#endif
900
18.6M
      while (input_line_pointer < buffer_limit)
901
18.6M
  {
902
18.6M
    bool was_new_line;
903
    /* We have more of this buffer to parse.  */
904
905
    /* We now have input_line_pointer->1st char of next line.
906
       If input_line_pointer [-1] == '\n' then we just
907
       scanned another line: so bump line counters.  */
908
18.6M
    was_new_line = is_end_of_line[(unsigned char) input_line_pointer[-1]];
909
18.6M
    if (was_new_line)
910
18.4M
      {
911
18.4M
        symbol_set_value_now (&dot_symbol);
912
#ifdef md_start_line_hook
913
        md_start_line_hook ();
914
#endif
915
18.4M
        if (input_line_pointer[-1] == '\n')
916
6.79M
    bump_line_counters ();
917
18.4M
      }
918
919
18.6M
#ifndef NO_LISTING
920
    /* If listing is on, and we are expanding a macro, then give
921
       the listing code the contents of the expanded line.  */
922
18.6M
    if (listing)
923
0
      {
924
0
        if ((listing & LISTING_MACEXP) && macro_nest > 0)
925
0
    {
926
      /* Find the end of the current expanded macro line.  */
927
0
      s = find_end_of_line (input_line_pointer, flag_m68k_mri);
928
929
0
      if (s != last_eol
930
0
          && !startswith (input_line_pointer,
931
0
              !flag_m68k_mri ? " .linefile "
932
0
                 : " linefile "))
933
0
        {
934
0
          char *copy;
935
0
          size_t len;
936
937
0
          last_eol = s;
938
          /* Copy it for safe keeping.  Also give an indication of
939
       how much macro nesting is involved at this point.  */
940
0
          len = s - input_line_pointer;
941
0
          copy = XNEWVEC (char, len + macro_nest + 2);
942
0
          memset (copy, '>', macro_nest);
943
0
          copy[macro_nest] = ' ';
944
0
          memcpy (copy + macro_nest + 1, input_line_pointer, len);
945
0
          copy[macro_nest + 1 + len] = '\0';
946
947
          /* Install the line with the listing facility.  */
948
0
          listing_newline (copy);
949
0
        }
950
0
    }
951
0
        else
952
0
    listing_newline (NULL);
953
0
      }
954
18.6M
#endif
955
18.6M
    if (was_new_line)
956
18.4M
      {
957
18.4M
        line_label = NULL;
958
959
18.4M
        if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
960
0
    {
961
0
      next_char = * input_line_pointer;
962
      /* Text at the start of a line must be a label, we
963
         run down and stick a colon in.  */
964
0
      if (is_name_beginner (next_char) || next_char == '"')
965
0
        {
966
0
          char *line_start;
967
0
          int mri_line_macro;
968
969
0
          HANDLE_CONDITIONAL_ASSEMBLY (0);
970
971
0
          nul_char = get_symbol_name (& line_start);
972
0
          next_char = (nul_char == '"' ? input_line_pointer[1] : nul_char);
973
974
          /* In MRI mode, the EQU and MACRO pseudoops must
975
       be handled specially.  */
976
0
          mri_line_macro = 0;
977
0
          if (flag_m68k_mri)
978
0
      {
979
0
        char *rest = input_line_pointer + 1;
980
981
0
        if (*rest == ':')
982
0
          ++rest;
983
0
        if (*rest == ' ' || *rest == '\t')
984
0
          ++rest;
985
0
        if ((strncasecmp (rest, "EQU", 3) == 0
986
0
             || strncasecmp (rest, "SET", 3) == 0)
987
0
            && (rest[3] == ' ' || rest[3] == '\t'))
988
0
          {
989
0
            input_line_pointer = rest + 3;
990
0
            equals (line_start,
991
0
              strncasecmp (rest, "SET", 3) == 0);
992
0
            continue;
993
0
          }
994
0
        if (strncasecmp (rest, "MACRO", 5) == 0
995
0
            && (rest[5] == ' '
996
0
          || rest[5] == '\t'
997
0
          || is_end_of_line[(unsigned char) rest[5]]))
998
0
          mri_line_macro = 1;
999
0
      }
1000
1001
          /* In MRI mode, we need to handle the MACRO
1002
       pseudo-op specially: we don't want to put the
1003
       symbol in the symbol table.  */
1004
0
          if (!mri_line_macro
1005
#ifdef TC_START_LABEL_WITHOUT_COLON
1006
        && TC_START_LABEL_WITHOUT_COLON (nul_char, next_char)
1007
#endif
1008
0
        )
1009
0
      line_label = colon (line_start);
1010
0
          else
1011
0
      line_label = symbol_create (line_start,
1012
0
                absolute_section,
1013
0
                &zero_address_frag, 0);
1014
1015
0
          next_char = restore_line_pointer (nul_char);
1016
0
          if (next_char == ':')
1017
0
      input_line_pointer++;
1018
0
        }
1019
0
    }
1020
18.4M
      }
1021
1022
    /* We are at the beginning of a line, or similar place.
1023
       We expect a well-formed assembler statement.
1024
       A "symbol-name:" is a statement.
1025
1026
       Depending on what compiler is used, the order of these tests
1027
       may vary to catch most common case 1st.
1028
       Each test is independent of all other tests at the (top)
1029
       level.  */
1030
18.6M
    do
1031
19.0M
      nul_char = next_char = *input_line_pointer++;
1032
19.0M
    while (next_char == '\t' || next_char == ' ' || next_char == '\f');
1033
1034
    /* C is the 1st significant character.
1035
       Input_line_pointer points after that character.  */
1036
18.6M
    if (is_name_beginner (next_char) || next_char == '"')
1037
2.25M
      {
1038
2.25M
        char *rest;
1039
1040
        /* Want user-defined label or pseudo/opcode.  */
1041
2.25M
        HANDLE_CONDITIONAL_ASSEMBLY (1);
1042
1043
2.23M
        --input_line_pointer;
1044
2.23M
        nul_char = get_symbol_name (& s); /* name's delimiter.  */
1045
2.23M
        next_char = (nul_char == '"' ? input_line_pointer[1] : nul_char);
1046
2.23M
        rest = input_line_pointer + (nul_char == '"' ? 2 : 1);
1047
1048
        /* NEXT_CHAR is character after symbol.
1049
     The end of symbol in the input line is now '\0'.
1050
     S points to the beginning of the symbol.
1051
       [In case of pseudo-op, s->'.'.]
1052
     Input_line_pointer->'\0' where NUL_CHAR was.  */
1053
2.23M
        if (TC_START_LABEL (s, nul_char, next_char))
1054
69.8k
    {
1055
69.8k
      if (flag_m68k_mri)
1056
0
        {
1057
          /* In MRI mode, \tsym: set 0 is permitted.  */
1058
0
          if (*rest == ':')
1059
0
      ++rest;
1060
1061
0
          if (*rest == ' ' || *rest == '\t')
1062
0
      ++rest;
1063
1064
0
          if ((strncasecmp (rest, "EQU", 3) == 0
1065
0
         || strncasecmp (rest, "SET", 3) == 0)
1066
0
        && (rest[3] == ' ' || rest[3] == '\t'))
1067
0
      {
1068
0
        input_line_pointer = rest + 3;
1069
0
        equals (s, 1);
1070
0
        continue;
1071
0
      }
1072
0
        }
1073
1074
69.8k
      line_label = colon (s); /* User-defined label.  */
1075
69.8k
      restore_line_pointer (nul_char);
1076
69.8k
      ++ input_line_pointer;
1077
#ifdef tc_check_label
1078
      tc_check_label (line_label);
1079
#endif
1080
      /* Input_line_pointer->after ':'.  */
1081
69.8k
      SKIP_WHITESPACE ();
1082
69.8k
    }
1083
2.16M
        else if ((next_char == '=' && *rest == '=')
1084
2.16M
           || ((next_char == ' ' || next_char == '\t')
1085
2.13M
         && rest[0] == '='
1086
2.13M
         && rest[1] == '='))
1087
29.0k
    {
1088
29.0k
      equals (s, -1);
1089
29.0k
      demand_empty_rest_of_line ();
1090
29.0k
    }
1091
2.13M
        else if ((next_char == '='
1092
2.13M
           || ((next_char == ' ' || next_char == '\t')
1093
2.00M
          && *rest == '='))
1094
#ifdef TC_EQUAL_IN_INSN
1095
         && !TC_EQUAL_IN_INSN (next_char, s)
1096
#endif
1097
2.13M
         )
1098
138k
    {
1099
138k
      equals (s, 1);
1100
138k
      demand_empty_rest_of_line ();
1101
138k
    }
1102
1.99M
        else
1103
1.99M
    {
1104
      /* Expect pseudo-op or machine instruction.  */
1105
1.99M
      pop = NULL;
1106
1107
1.99M
#ifndef TC_CASE_SENSITIVE
1108
1.99M
      {
1109
1.99M
        char *s2 = s;
1110
1111
1.99M
        strncpy (original_case_string, s2,
1112
1.99M
           sizeof (original_case_string) - 1);
1113
1.99M
        original_case_string[sizeof (original_case_string) - 1] = 0;
1114
1115
15.8M
        while (*s2)
1116
13.8M
          {
1117
13.8M
      *s2 = TOLOWER (*s2);
1118
13.8M
      s2++;
1119
13.8M
          }
1120
1.99M
      }
1121
1.99M
#endif
1122
1.99M
      if (NO_PSEUDO_DOT || flag_m68k_mri)
1123
0
        {
1124
          /* The MRI assembler uses pseudo-ops without
1125
       a period.  */
1126
0
          pop = str_hash_find (po_hash, s);
1127
0
          if (pop != NULL && pop->poc_handler == NULL)
1128
0
      pop = NULL;
1129
0
        }
1130
1131
1.99M
      if (pop != NULL
1132
1.99M
          || (!flag_m68k_mri && *s == '.'))
1133
715k
        {
1134
          /* PSEUDO - OP.
1135
1136
       WARNING: next_char may be end-of-line.
1137
       We lookup the pseudo-op table with s+1 because we
1138
       already know that the pseudo-op begins with a '.'.  */
1139
1140
715k
          if (pop == NULL)
1141
715k
      pop = str_hash_find (po_hash, s + 1);
1142
715k
          if (pop && !pop->poc_handler)
1143
0
      pop = NULL;
1144
1145
          /* In MRI mode, we may need to insert an
1146
       automatic alignment directive.  What a hack
1147
       this is.  */
1148
715k
          if (mri_pending_align
1149
715k
        && (pop == NULL
1150
113
            || !((pop->poc_handler == cons
1151
110
            && pop->poc_val == 1)
1152
110
           || (pop->poc_handler == s_space
1153
110
               && pop->poc_val == 1)
1154
#ifdef tc_conditional_pseudoop
1155
           || tc_conditional_pseudoop (pop)
1156
#endif
1157
110
           || pop->poc_handler == s_if
1158
110
           || pop->poc_handler == s_ifdef
1159
110
           || pop->poc_handler == s_ifc
1160
110
           || pop->poc_handler == s_ifeqs
1161
110
           || pop->poc_handler == s_else
1162
110
           || pop->poc_handler == s_endif
1163
110
           || pop->poc_handler == s_globl
1164
110
           || pop->poc_handler == s_ignore)))
1165
111
      {
1166
111
        do_align (1, (char *) NULL, 0, 0);
1167
111
        mri_pending_align = 0;
1168
1169
111
        if (line_label != NULL)
1170
0
          {
1171
0
            symbol_set_frag (line_label, frag_now);
1172
0
            S_SET_VALUE (line_label, frag_now_fix ());
1173
0
          }
1174
111
      }
1175
1176
          /* Print the error msg now, while we still can.  */
1177
715k
          if (pop == NULL)
1178
232k
      {
1179
232k
        char *end = input_line_pointer;
1180
1181
232k
        (void) restore_line_pointer (nul_char);
1182
232k
        s_ignore (0);
1183
232k
        nul_char = next_char = *--input_line_pointer;
1184
232k
        *input_line_pointer = '\0';
1185
232k
        if (! macro_defined || ! try_macro (next_char, s))
1186
231k
          {
1187
231k
            *end = '\0';
1188
231k
            as_bad (_("unknown pseudo-op: `%s'"), s);
1189
231k
            *input_line_pointer++ = nul_char;
1190
231k
          }
1191
232k
        continue;
1192
232k
      }
1193
1194
          /* Put it back for error messages etc.  */
1195
482k
          next_char = restore_line_pointer (nul_char);
1196
          /* The following skip of whitespace is compulsory.
1197
       A well shaped space is sometimes all that separates
1198
       keyword from operands.  */
1199
482k
          if (next_char == ' ' || next_char == '\t')
1200
250k
      input_line_pointer++;
1201
1202
          /* Input_line is restored.
1203
       Input_line_pointer->1st non-blank char
1204
       after pseudo-operation.  */
1205
482k
          (*pop->poc_handler) (pop->poc_val);
1206
1207
          /* If that was .end, just get out now.  */
1208
482k
          if (pop->poc_handler == s_end)
1209
7
      goto quit;
1210
482k
        }
1211
1.28M
      else
1212
1.28M
        {
1213
          /* WARNING: next_char may be end-of-line.  */
1214
          /* Also: input_line_pointer->`\0` where nul_char was.  */
1215
1.28M
          (void) restore_line_pointer (nul_char);
1216
1.28M
          input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1, 0);
1217
1.28M
          next_char = nul_char = *input_line_pointer;
1218
1.28M
          *input_line_pointer = '\0';
1219
1220
1.28M
          generate_lineno_debug ();
1221
1222
1.28M
          if (macro_defined && try_macro (next_char, s))
1223
13.0k
      continue;
1224
1225
1.27M
          if (mri_pending_align)
1226
6
      {
1227
6
        do_align (1, (char *) NULL, 0, 0);
1228
6
        mri_pending_align = 0;
1229
6
        if (line_label != NULL)
1230
0
          {
1231
0
            symbol_set_frag (line_label, frag_now);
1232
0
            S_SET_VALUE (line_label, frag_now_fix ());
1233
0
          }
1234
6
      }
1235
1236
1.27M
          assemble_one (s); /* Assemble 1 instruction.  */
1237
1238
          /* PR 19630: The backend may have set ilp to NULL
1239
       if it encountered a catastrophic failure.  */
1240
1.27M
          if (input_line_pointer == NULL)
1241
0
      as_fatal (_("unable to continue with assembly."));
1242
 
1243
1.27M
          *input_line_pointer++ = nul_char;
1244
1245
          /* We resume loop AFTER the end-of-line from
1246
       this instruction.  */
1247
1.27M
        }
1248
1.99M
    }
1249
1.99M
        continue;
1250
2.23M
      }
1251
1252
    /* Empty statement?  */
1253
16.3M
    if (is_end_of_line[(unsigned char) next_char])
1254
15.0M
      continue;
1255
1256
1.25M
    if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (next_char))
1257
313k
      {
1258
        /* local label  ("4:")  */
1259
313k
        char *backup = input_line_pointer;
1260
1261
313k
        HANDLE_CONDITIONAL_ASSEMBLY (1);
1262
1263
312k
        temp = next_char - '0';
1264
1265
        /* Read the whole number.  */
1266
312k
        while (ISDIGIT (*input_line_pointer))
1267
266k
    {
1268
266k
      const long digit = *input_line_pointer - '0';
1269
1270
      /* Don't accept labels which look like octal numbers.  */
1271
266k
      if (temp == 0)
1272
7.57k
        break;
1273
258k
      if (temp > (INT_MAX - digit) / 10)
1274
10.3k
        {
1275
10.3k
          as_bad (_("local label too large near %s"), backup);
1276
10.3k
          temp = -1;
1277
10.3k
          break;
1278
10.3k
        }
1279
248k
      temp = temp * 10 + digit;
1280
248k
      ++input_line_pointer;
1281
248k
    }
1282
1283
        /* Overflow: stop processing the label.  */
1284
312k
        if (temp == -1)
1285
10.3k
    {
1286
10.3k
      ignore_rest_of_line ();
1287
10.3k
      continue;
1288
10.3k
    }
1289
1290
301k
        if (LOCAL_LABELS_DOLLAR
1291
301k
      && *input_line_pointer == '$'
1292
301k
      && *(input_line_pointer + 1) == ':')
1293
0
    {
1294
0
      input_line_pointer += 2;
1295
1296
0
      if (dollar_label_defined (temp))
1297
0
        {
1298
0
          as_fatal (_("label \"%ld$\" redefined"), temp);
1299
0
        }
1300
1301
0
      define_dollar_label (temp);
1302
0
      colon (dollar_label_name (temp, 0));
1303
0
      continue;
1304
0
    }
1305
1306
301k
        if (LOCAL_LABELS_FB
1307
301k
      && *input_line_pointer++ == ':')
1308
19.1k
    {
1309
19.1k
      fb_label_instance_inc (temp);
1310
19.1k
      colon (fb_label_name (temp, 0));
1311
19.1k
      continue;
1312
19.1k
    }
1313
1314
282k
        input_line_pointer = backup;
1315
282k
      }
1316
1317
1.22M
    if (next_char && strchr (line_comment_chars, next_char))
1318
52.0k
      {     /* Its a comment.  Better say APP or NO_APP.  */
1319
52.0k
        sb sbuf;
1320
52.0k
        char *ends;
1321
52.0k
        size_t len;
1322
1323
52.0k
        s = input_line_pointer;
1324
52.0k
        if (!startswith (s, "APP\n"))
1325
51.2k
    {
1326
      /* We ignore it.  */
1327
51.2k
      ignore_rest_of_line ();
1328
51.2k
      continue;
1329
51.2k
    }
1330
818
        bump_line_counters ();
1331
818
        s += 4;
1332
1333
818
        ends = strstr (s, "#NO_APP\n");
1334
818
        len = ends ? ends - s : buffer_limit - s;
1335
1336
818
        sb_build (&sbuf, len + 100);
1337
818
        sb_add_buffer (&sbuf, s, len);
1338
818
        if (!ends)
1339
396
    {
1340
      /* The end of the #APP wasn't in this buffer.  We
1341
         keep reading in buffers until we find the #NO_APP
1342
         that goes with this #APP  There is one.  The specs
1343
         guarantee it...  */
1344
396
      do
1345
648
        {
1346
648
          buffer_limit = input_scrub_next_buffer (&buffer);
1347
648
          if (!buffer_limit)
1348
387
      break;
1349
261
          ends = strstr (buffer, "#NO_APP\n");
1350
261
          len = ends ? ends - buffer : buffer_limit - buffer;
1351
261
          sb_add_buffer (&sbuf, buffer, len);
1352
261
        }
1353
396
      while (!ends);
1354
396
    }
1355
1356
818
        input_line_pointer = ends ? ends + 8 : NULL;
1357
818
        input_scrub_include_sb (&sbuf, input_line_pointer, expanding_none);
1358
818
        sb_kill (&sbuf);
1359
818
        buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1360
818
        continue;
1361
52.0k
      }
1362
1363
1.16M
    HANDLE_CONDITIONAL_ASSEMBLY (1);
1364
1365
#ifdef tc_unrecognized_line
1366
    if (tc_unrecognized_line (next_char))
1367
      continue;
1368
#endif
1369
1.16M
    input_line_pointer--;
1370
    /* Report unknown char as error.  */
1371
1.16M
    demand_empty_rest_of_line ();
1372
1.16M
  }
1373
9.56k
    }
1374
1375
736
 quit:
1376
736
  symbol_set_value_now (&dot_symbol);
1377
1378
736
#ifdef HANDLE_BUNDLE
1379
736
  if (bundle_lock_frag != NULL)
1380
0
    {
1381
0
      as_bad_where (bundle_lock_frag->fr_file, bundle_lock_frag->fr_line,
1382
0
        _(".bundle_lock with no matching .bundle_unlock"));
1383
0
      bundle_lock_frag = NULL;
1384
0
      bundle_lock_frchain = NULL;
1385
0
      bundle_lock_depth = 0;
1386
0
    }
1387
736
#endif
1388
1389
736
  if (flag_synth_cfi)
1390
0
    ginsn_data_end (symbol_temp_new_now ());
1391
1392
736
#ifdef md_cleanup
1393
736
  md_cleanup ();
1394
736
#endif
1395
  /* Close the input file.  */
1396
736
  input_scrub_close ();
1397
#ifdef WARN_COMMENTS
1398
  {
1399
    if (warn_comment && found_comment)
1400
      as_warn_where (found_comment_file, found_comment,
1401
         "first comment found here");
1402
  }
1403
#endif
1404
736
}
1405
1406
/* Convert O_constant expression EXP into the equivalent O_big representation.
1407
   Take the sign of the number from SIGN rather than X_add_number.  */
1408
1409
static void
1410
convert_to_bignum (expressionS *exp, int sign)
1411
52
{
1412
52
  valueT value;
1413
52
  unsigned int i;
1414
1415
52
  value = exp->X_add_number;
1416
260
  for (i = 0; i < sizeof (exp->X_add_number) / CHARS_PER_LITTLENUM; i++)
1417
208
    {
1418
208
      generic_bignum[i] = value & LITTLENUM_MASK;
1419
208
      value >>= LITTLENUM_NUMBER_OF_BITS;
1420
208
    }
1421
  /* Add a sequence of sign bits if the top bit of X_add_number is not
1422
     the sign of the original value.  */
1423
52
  if ((exp->X_add_number < 0) == !sign)
1424
37
    generic_bignum[i++] = sign ? LITTLENUM_MASK : 0;
1425
52
  exp->X_op = O_big;
1426
52
  exp->X_add_number = i;
1427
52
}
1428
1429
/* For most MRI pseudo-ops, the line actually ends at the first
1430
   nonquoted space.  This function looks for that point, stuffs a null
1431
   in, and sets *STOPCP to the character that used to be there, and
1432
   returns the location.
1433
1434
   Until I hear otherwise, I am going to assume that this is only true
1435
   for the m68k MRI assembler.  */
1436
1437
char *
1438
mri_comment_field (char *stopcp)
1439
33.0k
{
1440
33.0k
  char *s;
1441
#ifdef TC_M68K
1442
  int inquote = 0;
1443
1444
  know (flag_m68k_mri);
1445
1446
  for (s = input_line_pointer;
1447
       ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1448
  || inquote);
1449
       s++)
1450
    {
1451
      if (*s == '\'')
1452
  inquote = !inquote;
1453
    }
1454
#else
1455
33.0k
  for (s = input_line_pointer;
1456
1.48M
       !is_end_of_line[(unsigned char) *s];
1457
1.45M
       s++)
1458
1.45M
    ;
1459
33.0k
#endif
1460
33.0k
  *stopcp = *s;
1461
33.0k
  *s = '\0';
1462
1463
33.0k
  return s;
1464
33.0k
}
1465
1466
/* Skip to the end of an MRI comment field.  */
1467
1468
void
1469
mri_comment_end (char *stop, int stopc)
1470
33.0k
{
1471
33.0k
  know (flag_mri);
1472
1473
33.0k
  input_line_pointer = stop;
1474
33.0k
  *stop = stopc;
1475
33.0k
  while (!is_end_of_line[(unsigned char) *input_line_pointer])
1476
0
    ++input_line_pointer;
1477
33.0k
}
1478
1479
void
1480
s_abort (int ignore ATTRIBUTE_UNUSED)
1481
0
{
1482
0
  as_fatal (_(".abort detected.  Abandoning ship."));
1483
0
}
1484
1485
/* Handle the .align pseudo-op.  A positive ARG is a default alignment
1486
   (in bytes).  A negative ARG is the negative of the length of the
1487
   fill pattern.  BYTES_P is non-zero if the alignment value should be
1488
   interpreted as the byte boundary, rather than the power of 2.  */
1489
#ifndef TC_ALIGN_LIMIT
1490
13.4k
#define TC_ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1491
#endif
1492
1493
static void
1494
s_align (signed int arg, int bytes_p)
1495
13.4k
{
1496
13.4k
  unsigned int align_limit = TC_ALIGN_LIMIT;
1497
13.4k
  addressT align;
1498
13.4k
  char *stop = NULL;
1499
13.4k
  char stopc = 0;
1500
13.4k
  offsetT fill = 0;
1501
13.4k
  unsigned int max;
1502
13.4k
  int fill_p;
1503
1504
13.4k
  if (flag_mri)
1505
3.20k
    stop = mri_comment_field (&stopc);
1506
1507
13.4k
  if (is_end_of_line[(unsigned char) *input_line_pointer])
1508
4.44k
    {
1509
4.44k
      if (arg < 0)
1510
0
  align = 0;
1511
4.44k
      else
1512
4.44k
  align = arg; /* Default value from pseudo-op table.  */
1513
4.44k
    }
1514
8.96k
  else
1515
8.96k
    {
1516
8.96k
      align = get_absolute_expression ();
1517
8.96k
      SKIP_WHITESPACE ();
1518
1519
#ifdef TC_ALIGN_ZERO_IS_DEFAULT
1520
      if (arg > 0 && align == 0)
1521
  align = arg;
1522
#endif
1523
8.96k
    }
1524
1525
13.4k
  if (bytes_p)
1526
13.4k
    {
1527
      /* Convert to a power of 2.  */
1528
13.4k
      if (align != 0)
1529
7.22k
  {
1530
7.22k
    unsigned int i;
1531
1532
19.5k
    for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1533
12.3k
      ;
1534
7.22k
    if (align != 1)
1535
1.31k
      as_bad (_("alignment not a power of 2"));
1536
1537
7.22k
    align = i;
1538
7.22k
  }
1539
13.4k
    }
1540
1541
13.4k
  if (align > align_limit)
1542
0
    {
1543
0
      align = align_limit;
1544
0
      as_warn (_("alignment too large: %u assumed"), align_limit);
1545
0
    }
1546
1547
13.4k
  if (*input_line_pointer != ',')
1548
7.66k
    {
1549
7.66k
      fill_p = 0;
1550
7.66k
      max = 0;
1551
7.66k
    }
1552
5.74k
  else
1553
5.74k
    {
1554
5.74k
      ++input_line_pointer;
1555
5.74k
      if (*input_line_pointer == ',')
1556
460
  fill_p = 0;
1557
5.28k
      else
1558
5.28k
  {
1559
5.28k
    fill = get_absolute_expression ();
1560
5.28k
    SKIP_WHITESPACE ();
1561
5.28k
    fill_p = 1;
1562
5.28k
  }
1563
1564
5.74k
      if (*input_line_pointer != ',')
1565
5.20k
  max = 0;
1566
536
      else
1567
536
  {
1568
536
    ++input_line_pointer;
1569
536
    max = get_absolute_expression ();
1570
536
  }
1571
5.74k
    }
1572
1573
13.4k
  if (!fill_p)
1574
8.12k
    {
1575
8.12k
      if (arg < 0)
1576
4
  as_warn (_("expected fill pattern missing"));
1577
8.12k
      do_align (align, (char *) NULL, 0, max);
1578
8.12k
    }
1579
5.28k
  else
1580
5.28k
    {
1581
5.28k
      unsigned int fill_len;
1582
1583
5.28k
      if (arg >= 0)
1584
5.27k
  fill_len = 1;
1585
6
      else
1586
6
  fill_len = -arg;
1587
1588
5.28k
      if (fill_len <= 1)
1589
5.27k
  {
1590
5.27k
    char fill_char = 0;
1591
1592
5.27k
    fill_char = fill;
1593
5.27k
    do_align (align, &fill_char, fill_len, max);
1594
5.27k
  }
1595
6
      else
1596
6
  {
1597
6
    char ab[16];
1598
1599
6
    if ((size_t) fill_len > sizeof ab)
1600
0
      {
1601
0
        as_warn (_("fill pattern too long, truncating to %u"),
1602
0
           (unsigned) sizeof ab);
1603
0
        fill_len = sizeof ab;
1604
0
      }
1605
1606
6
    md_number_to_chars (ab, fill, fill_len);
1607
6
    do_align (align, ab, fill_len, max);
1608
6
  }
1609
5.28k
    }
1610
1611
13.4k
  demand_empty_rest_of_line ();
1612
1613
13.4k
  if (flag_mri)
1614
3.20k
    mri_comment_end (stop, stopc);
1615
13.4k
}
1616
1617
/* Handle the .align pseudo-op on machines where ".align 4" means
1618
   align to a 4 byte boundary.  */
1619
1620
void
1621
s_align_bytes (int arg)
1622
13.4k
{
1623
13.4k
  s_align (arg, 1);
1624
13.4k
}
1625
1626
/* Handle the .align pseudo-op on machines where ".align 4" means align
1627
   to a 2**4 boundary.  */
1628
1629
void
1630
s_align_ptwo (int arg)
1631
0
{
1632
0
  s_align (arg, 0);
1633
0
}
1634
1635
/* Switch in and out of alternate macro mode.  */
1636
1637
static void
1638
s_altmacro (int on)
1639
0
{
1640
0
  demand_empty_rest_of_line ();
1641
0
  flag_macro_alternate = on;
1642
0
}
1643
1644
/* Read a symbol name from input_line_pointer.
1645
1646
   Stores the symbol name in a buffer and returns a pointer to this buffer.
1647
   The buffer is xalloc'ed.  It is the caller's responsibility to free
1648
   this buffer.
1649
1650
   The name is not left in the i_l_p buffer as it may need processing
1651
   to handle escape characters.
1652
1653
   Advances i_l_p to the next non-whitespace character.
1654
1655
   If a symbol name could not be read, the routine issues an error
1656
   messages, skips to the end of the line and returns NULL.  */
1657
1658
char *
1659
read_symbol_name (void)
1660
28.0k
{
1661
28.0k
  char * name;
1662
28.0k
  char * start;
1663
28.0k
  char c;
1664
1665
28.0k
  c = *input_line_pointer++;
1666
1667
28.0k
  if (c == '"')
1668
6
    {
1669
12
#define SYM_NAME_CHUNK_LEN 128
1670
6
      ptrdiff_t len = SYM_NAME_CHUNK_LEN;
1671
6
      char * name_end;
1672
6
      unsigned int C;
1673
1674
6
      start = name = XNEWVEC (char, len + 1);
1675
1676
6
      name_end = name + SYM_NAME_CHUNK_LEN;
1677
1678
126
      while (is_a_char (C = next_char_of_string ()))
1679
120
  {
1680
120
    if (name >= name_end)
1681
0
      {
1682
0
        ptrdiff_t sofar;
1683
1684
0
        sofar = name - start;
1685
0
        len += SYM_NAME_CHUNK_LEN;
1686
0
        start = XRESIZEVEC (char, start, len + 1);
1687
0
        name_end = start + len;
1688
0
        name = start + sofar;
1689
0
      }
1690
1691
120
    *name++ = (char) C;
1692
120
  }
1693
6
      *name = 0;
1694
1695
      /* Since quoted symbol names can contain non-ASCII characters,
1696
   check the string and warn if it cannot be recognised by the
1697
   current character set.  */
1698
      /* PR 29447: mbstowcs ignores the third (length) parameter when
1699
   the first (destination) parameter is NULL.  For clarity sake
1700
   therefore we pass 0 rather than 'len' as the third parameter.  */
1701
6
      if (mbstowcs (NULL, name, 0) == (size_t) -1)
1702
0
  as_warn (_("symbol name not recognised in the current locale"));
1703
6
    }
1704
28.0k
  else if (is_name_beginner (c) || (input_from_string && c == FAKE_LABEL_CHAR))
1705
22.1k
    {
1706
22.1k
      ptrdiff_t len;
1707
1708
22.1k
      name = input_line_pointer - 1;
1709
1710
      /* We accept FAKE_LABEL_CHAR in a name in case this is
1711
   being called with a constructed string.  */
1712
41.8k
      while (is_part_of_name (c = *input_line_pointer++)
1713
41.8k
       || (input_from_string && c == FAKE_LABEL_CHAR))
1714
19.6k
  ;
1715
1716
22.1k
      len = (input_line_pointer - name) - 1;
1717
22.1k
      start = XNEWVEC (char, len + 1);
1718
1719
22.1k
      memcpy (start, name, len);
1720
22.1k
      start[len] = 0;
1721
1722
      /* Skip a name ender char if one is present.  */
1723
22.1k
      if (! is_name_ender (c))
1724
22.1k
  --input_line_pointer;
1725
22.1k
    }
1726
5.81k
  else
1727
5.81k
    name = start = NULL;
1728
1729
28.0k
  if (name == start)
1730
5.81k
    {
1731
5.81k
      as_bad (_("expected symbol name"));
1732
5.81k
      ignore_rest_of_line ();
1733
5.81k
      free (start);
1734
5.81k
      return NULL;
1735
5.81k
    }
1736
1737
22.1k
  SKIP_WHITESPACE ();
1738
1739
22.1k
  return start;
1740
28.0k
}
1741
1742
1743
symbolS *
1744
s_comm_internal (int param,
1745
     symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
1746
22.4k
{
1747
22.4k
  char *name;
1748
22.4k
  offsetT temp, size;
1749
22.4k
  symbolS *symbolP = NULL;
1750
22.4k
  char *stop = NULL;
1751
22.4k
  char stopc = 0;
1752
22.4k
  expressionS exp;
1753
1754
22.4k
  if (flag_mri)
1755
4.00k
    stop = mri_comment_field (&stopc);
1756
1757
22.4k
  if ((name = read_symbol_name ()) == NULL)
1758
664
    goto out;
1759
1760
  /* Accept an optional comma after the name.  The comma used to be
1761
     required, but Irix 5 cc does not generate it for .lcomm.  */
1762
21.7k
  if (*input_line_pointer == ',')
1763
17.2k
    input_line_pointer++;
1764
1765
21.7k
  temp = get_absolute_expr (&exp);
1766
21.7k
  size = temp;
1767
21.7k
  size &= ((addressT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
1768
21.7k
  if (exp.X_op == O_absent)
1769
102
    {
1770
102
      as_bad (_("missing size expression"));
1771
102
      ignore_rest_of_line ();
1772
102
      goto out;
1773
102
    }
1774
21.6k
  else if (temp != size || (!exp.X_unsigned && exp.X_add_number < 0))
1775
15
    {
1776
15
      as_warn (_("size (%ld) out of range, ignored"), (long) temp);
1777
15
      ignore_rest_of_line ();
1778
15
      goto out;
1779
15
    }
1780
1781
21.6k
  symbolP = symbol_find_or_make (name);
1782
21.6k
  if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
1783
21.6k
      && !S_IS_COMMON (symbolP))
1784
76
    {
1785
76
      if (!S_IS_VOLATILE (symbolP))
1786
72
  {
1787
72
    symbolP = NULL;
1788
72
    as_bad (_("symbol `%s' is already defined"), name);
1789
72
    ignore_rest_of_line ();
1790
72
    goto out;
1791
72
  }
1792
4
      symbolP = symbol_clone (symbolP, 1);
1793
4
      S_SET_SEGMENT (symbolP, undefined_section);
1794
4
      S_SET_VALUE (symbolP, 0);
1795
4
      symbol_set_frag (symbolP, &zero_address_frag);
1796
4
      S_CLEAR_VOLATILE (symbolP);
1797
4
    }
1798
1799
21.5k
  size = S_GET_VALUE (symbolP);
1800
21.5k
  if (size == 0)
1801
12.0k
    size = temp;
1802
9.50k
  else if (size != temp)
1803
4.26k
    as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1804
4.26k
       name, (long) size, (long) temp);
1805
1806
21.5k
  if (comm_parse_extra != NULL)
1807
21.5k
    symbolP = (*comm_parse_extra) (param, symbolP, size);
1808
0
  else
1809
0
    {
1810
0
      S_SET_VALUE (symbolP, (valueT) size);
1811
0
      S_SET_EXTERNAL (symbolP);
1812
0
      S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
1813
0
    }
1814
1815
21.5k
  demand_empty_rest_of_line ();
1816
22.4k
 out:
1817
22.4k
  if (flag_mri)
1818
4.00k
    mri_comment_end (stop, stopc);
1819
22.4k
  free (name);
1820
22.4k
  return symbolP;
1821
21.5k
}
1822
1823
void
1824
s_comm (int ignore)
1825
0
{
1826
0
  s_comm_internal (ignore, NULL);
1827
0
}
1828
1829
/* The MRI COMMON pseudo-op.  We handle this by creating a common
1830
   symbol with the appropriate name.  We make s_space do the right
1831
   thing by increasing the size.  */
1832
1833
void
1834
s_mri_common (int small ATTRIBUTE_UNUSED)
1835
0
{
1836
0
  char *name;
1837
0
  char c;
1838
0
  char *alc = NULL;
1839
0
  symbolS *sym;
1840
0
  offsetT align;
1841
0
  char *stop = NULL;
1842
0
  char stopc = 0;
1843
1844
0
  if (!flag_mri)
1845
0
    {
1846
0
      s_comm (0);
1847
0
      return;
1848
0
    }
1849
1850
0
  stop = mri_comment_field (&stopc);
1851
1852
0
  SKIP_WHITESPACE ();
1853
1854
0
  name = input_line_pointer;
1855
0
  if (!ISDIGIT (*name))
1856
0
    c = get_symbol_name (& name);
1857
0
  else
1858
0
    {
1859
0
      do
1860
0
  {
1861
0
    ++input_line_pointer;
1862
0
  }
1863
0
      while (ISDIGIT (*input_line_pointer));
1864
1865
0
      c = *input_line_pointer;
1866
0
      *input_line_pointer = '\0';
1867
1868
0
      if (line_label != NULL)
1869
0
  {
1870
0
    alc = XNEWVEC (char, strlen (S_GET_NAME (line_label))
1871
0
       + (input_line_pointer - name) + 1);
1872
0
    sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1873
0
    name = alc;
1874
0
  }
1875
0
    }
1876
1877
0
  sym = symbol_find_or_make (name);
1878
0
  c = restore_line_pointer (c);
1879
0
  free (alc);
1880
1881
0
  if (*input_line_pointer != ',')
1882
0
    align = 0;
1883
0
  else
1884
0
    {
1885
0
      ++input_line_pointer;
1886
0
      align = get_absolute_expression ();
1887
0
    }
1888
1889
0
  if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1890
0
    {
1891
0
      as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
1892
0
      mri_comment_end (stop, stopc);
1893
0
      return;
1894
0
    }
1895
1896
0
  S_SET_EXTERNAL (sym);
1897
0
  S_SET_SEGMENT (sym, bfd_com_section_ptr);
1898
0
  mri_common_symbol = sym;
1899
1900
0
#ifdef S_SET_ALIGN
1901
0
  if (align != 0)
1902
0
    S_SET_ALIGN (sym, align);
1903
#else
1904
  (void) align;
1905
#endif
1906
1907
0
  if (line_label != NULL)
1908
0
    {
1909
0
      expressionS exp;
1910
0
      exp.X_op = O_symbol;
1911
0
      exp.X_add_symbol = sym;
1912
0
      exp.X_add_number = 0;
1913
0
      symbol_set_value_expression (line_label, &exp);
1914
0
      symbol_set_frag (line_label, &zero_address_frag);
1915
0
      S_SET_SEGMENT (line_label, expr_section);
1916
0
    }
1917
1918
  /* FIXME: We just ignore the small argument, which distinguishes
1919
     COMMON and COMMON.S.  I don't know what we can do about it.  */
1920
1921
  /* Ignore the type and hptype.  */
1922
0
  if (*input_line_pointer == ',')
1923
0
    input_line_pointer += 2;
1924
0
  if (*input_line_pointer == ',')
1925
0
    input_line_pointer += 2;
1926
1927
0
  demand_empty_rest_of_line ();
1928
1929
0
  mri_comment_end (stop, stopc);
1930
0
}
1931
1932
void
1933
s_data (int ignore ATTRIBUTE_UNUSED)
1934
111
{
1935
111
  segT section;
1936
111
  int temp;
1937
1938
111
  temp = get_absolute_expression ();
1939
111
  if (flag_readonly_data_in_text)
1940
0
    {
1941
0
      section = text_section;
1942
0
      temp += 1000;
1943
0
    }
1944
111
  else
1945
111
    section = data_section;
1946
1947
111
  subseg_set (section, (subsegT) temp);
1948
1949
111
  demand_empty_rest_of_line ();
1950
111
}
1951
1952
/* Handle the .file pseudo-op.  This default definition may be overridden by
1953
   the object or CPU specific pseudo-ops.  */
1954
1955
void
1956
s_file_string (char *file)
1957
656
{
1958
#ifdef LISTING
1959
  if (listing)
1960
    listing_source_file (file);
1961
#endif
1962
656
  register_dependency (file);
1963
656
#ifdef obj_app_file
1964
656
  obj_app_file (file);
1965
656
#endif
1966
656
}
1967
1968
void
1969
s_file (int ignore ATTRIBUTE_UNUSED)
1970
656
{
1971
656
  char *s;
1972
656
  int length;
1973
1974
  /* Some assemblers tolerate immediately following '"'.  */
1975
656
  if ((s = demand_copy_string (&length)) != 0)
1976
656
    {
1977
656
      new_logical_line_flags (s, -1, 1);
1978
1979
      /* In MRI mode, the preprocessor may have inserted an extraneous
1980
   backquote.  */
1981
656
      if (flag_m68k_mri
1982
656
    && *input_line_pointer == '\''
1983
656
    && is_end_of_line[(unsigned char) input_line_pointer[1]])
1984
0
  ++input_line_pointer;
1985
1986
656
      demand_empty_rest_of_line ();
1987
656
      s_file_string (s);
1988
656
    }
1989
656
}
1990
1991
static bool
1992
get_linefile_number (int *flag)
1993
226k
{
1994
226k
  expressionS exp;
1995
1996
226k
  SKIP_WHITESPACE ();
1997
1998
226k
  if (*input_line_pointer < '0' || *input_line_pointer > '9')
1999
42.3k
    return false;
2000
2001
  /* Don't mistakenly interpret octal numbers as line numbers.  */
2002
184k
  if (*input_line_pointer == '0')
2003
42.6k
    {
2004
42.6k
      *flag = 0;
2005
42.6k
      ++input_line_pointer;
2006
42.6k
      return true;
2007
42.6k
    }
2008
2009
141k
  expression_and_evaluate (&exp);
2010
141k
  if (exp.X_op != O_constant)
2011
875
    return false;
2012
2013
140k
#if defined (BFD64) || LONG_MAX > INT_MAX
2014
140k
  if (exp.X_add_number < INT_MIN || exp.X_add_number > INT_MAX)
2015
2.17k
    return false;
2016
138k
#endif
2017
2018
138k
  *flag = exp.X_add_number;
2019
2020
138k
  return true;
2021
140k
}
2022
2023
/* Handle the .linefile pseudo-op.  This is automatically generated by
2024
   do_scrub_chars when a preprocessor # line comment is seen.  This
2025
   default definition may be overridden by the object or CPU specific
2026
   pseudo-ops.  */
2027
2028
void
2029
s_linefile (int ignore ATTRIBUTE_UNUSED)
2030
149k
{
2031
149k
  char *file = NULL;
2032
149k
  int linenum, flags = 0;
2033
2034
  /* The given number is that of the next line.  */
2035
149k
  if (!get_linefile_number (&linenum))
2036
6
    {
2037
6
      ignore_rest_of_line ();
2038
6
      return;
2039
6
    }
2040
2041
149k
  if (linenum < 0)
2042
    /* Some of the back ends can't deal with non-positive line numbers.
2043
       Besides, it's silly.  GCC however will generate a line number of
2044
       zero when it is pre-processing builtins for assembler-with-cpp files:
2045
2046
    # 0 "<built-in>"
2047
2048
       We do not want to barf on this, especially since such files are used
2049
       in the GCC and GDB testsuites.  So we check for negative line numbers
2050
       rather than non-positive line numbers.  */
2051
4
    as_warn (_("line numbers must be positive; line number %d rejected"),
2052
4
       linenum);
2053
149k
  else
2054
149k
    {
2055
149k
      int length = 0;
2056
2057
149k
      SKIP_WHITESPACE ();
2058
2059
149k
      if (*input_line_pointer == '"')
2060
45.4k
  file = demand_copy_string (&length);
2061
103k
      else if (*input_line_pointer == '.')
2062
86.3k
  {
2063
    /* buffer_and_nest() may insert this form.  */
2064
86.3k
    ++input_line_pointer;
2065
86.3k
    flags = 1 << 3;
2066
86.3k
  }
2067
2068
149k
      if (file)
2069
45.4k
  {
2070
45.4k
    int this_flag;
2071
2072
77.1k
    while (get_linefile_number (&this_flag))
2073
31.6k
      switch (this_flag)
2074
31.6k
        {
2075
    /* From GCC's cpp documentation:
2076
       1: start of a new file.
2077
       2: returning to a file after having included another file.
2078
       3: following text comes from a system header file.
2079
       4: following text should be treated as extern "C".
2080
2081
       4 is nonsensical for the assembler; 3, we don't care about,
2082
       so we ignore it just in case a system header file is
2083
       included while preprocessing assembly.  So 1 and 2 are all
2084
       we care about, and they are mutually incompatible.
2085
       new_logical_line_flags() demands this.  */
2086
518
        case 1:
2087
566
        case 2:
2088
566
    if (flags && flags != (1 << this_flag))
2089
0
      as_warn (_("incompatible flag %i in line directive"),
2090
0
         this_flag);
2091
566
    else
2092
566
      flags |= 1 << this_flag;
2093
566
    break;
2094
2095
448
        case 3:
2096
449
        case 4:
2097
    /* We ignore these.  */
2098
449
    break;
2099
2100
30.6k
        default:
2101
30.6k
    as_warn (_("unsupported flag %i in line directive"),
2102
30.6k
       this_flag);
2103
30.6k
    break;
2104
31.6k
        }
2105
2106
45.4k
    if (!is_end_of_line[(unsigned char)*input_line_pointer])
2107
6.63k
      file = NULL;
2108
45.4k
        }
2109
2110
149k
      if (file || flags)
2111
125k
  {
2112
125k
    demand_empty_rest_of_line ();
2113
2114
    /* read_a_source_file() will bump the line number only if the line
2115
       is terminated by '\n'.  */
2116
125k
    if (input_line_pointer[-1] == '\n')
2117
108k
      linenum--;
2118
2119
125k
    new_logical_line_flags (file, linenum, flags);
2120
#ifdef LISTING
2121
    if (listing)
2122
      listing_source_line (linenum);
2123
#endif
2124
125k
    return;
2125
125k
  }
2126
149k
    }
2127
23.6k
  ignore_rest_of_line ();
2128
23.6k
}
2129
2130
/* Handle the .end pseudo-op.  Actually, the real work is done in
2131
   read_a_source_file.  */
2132
2133
void
2134
s_end (int ignore ATTRIBUTE_UNUSED)
2135
7
{
2136
7
  if (flag_mri)
2137
2
    {
2138
      /* The MRI assembler permits the start symbol to follow .end,
2139
   but we don't support that.  */
2140
2
      SKIP_WHITESPACE ();
2141
2
      if (!is_end_of_line[(unsigned char) *input_line_pointer]
2142
2
    && *input_line_pointer != '*'
2143
2
    && *input_line_pointer != '!')
2144
0
  as_warn (_("start address not supported"));
2145
2
    }
2146
7
}
2147
2148
/* Handle the .err pseudo-op.  */
2149
2150
void
2151
s_err (int ignore ATTRIBUTE_UNUSED)
2152
609
{
2153
609
  as_bad (_(".err encountered"));
2154
609
  demand_empty_rest_of_line ();
2155
609
}
2156
2157
/* Handle the .error and .warning pseudo-ops.  */
2158
2159
void
2160
s_errwarn (int err)
2161
212
{
2162
212
  int len;
2163
  /* The purpose for the conditional assignment is not to
2164
     internationalize the directive itself, but that we need a
2165
     self-contained message, one that can be passed like the
2166
     demand_copy_C_string return value, and with no assumption on the
2167
     location of the name of the directive within the message.  */
2168
212
  const char *msg
2169
212
    = (err ? _(".error directive invoked in source file")
2170
212
       : _(".warning directive invoked in source file"));
2171
2172
212
  if (!is_it_end_of_statement ())
2173
209
    {
2174
209
      if (*input_line_pointer != '\"')
2175
209
  {
2176
209
    as_bad (_("%s argument must be a string"),
2177
209
      err ? ".error" : ".warning");
2178
209
    ignore_rest_of_line ();
2179
209
    return;
2180
209
  }
2181
2182
0
      msg = demand_copy_C_string (&len);
2183
0
      if (msg == NULL)
2184
0
  return;
2185
0
    }
2186
2187
3
  if (err)
2188
3
    as_bad ("%s", msg);
2189
0
  else
2190
0
    as_warn ("%s", msg);
2191
3
  demand_empty_rest_of_line ();
2192
3
}
2193
2194
/* Handle the MRI fail pseudo-op.  */
2195
2196
void
2197
s_fail (int ignore ATTRIBUTE_UNUSED)
2198
1.13k
{
2199
1.13k
  offsetT temp;
2200
1.13k
  char *stop = NULL;
2201
1.13k
  char stopc = 0;
2202
2203
1.13k
  if (flag_mri)
2204
83
    stop = mri_comment_field (&stopc);
2205
2206
1.13k
  temp = get_absolute_expression ();
2207
1.13k
  if (temp >= 500)
2208
82
    as_warn (_(".fail %ld encountered"), (long) temp);
2209
1.04k
  else
2210
1.04k
    as_bad (_(".fail %ld encountered"), (long) temp);
2211
2212
1.13k
  demand_empty_rest_of_line ();
2213
2214
1.13k
  if (flag_mri)
2215
83
    mri_comment_end (stop, stopc);
2216
1.13k
}
2217
2218
void
2219
s_fill (int ignore ATTRIBUTE_UNUSED)
2220
7.72k
{
2221
7.72k
  expressionS rep_exp;
2222
7.72k
  long size = 1;
2223
7.72k
  long fill = 0;
2224
7.72k
  char *p;
2225
2226
#ifdef md_flush_pending_output
2227
  md_flush_pending_output ();
2228
#endif
2229
2230
7.72k
#ifdef md_cons_align
2231
7.72k
  md_cons_align (1);
2232
7.72k
#endif
2233
2234
7.72k
  expression (&rep_exp);
2235
7.72k
  if (*input_line_pointer == ',')
2236
4.84k
    {
2237
4.84k
      input_line_pointer++;
2238
4.84k
      size = get_absolute_expression ();
2239
4.84k
      if (*input_line_pointer == ',')
2240
242
  {
2241
242
    input_line_pointer++;
2242
242
    fill = get_absolute_expression ();
2243
242
  }
2244
4.84k
    }
2245
2246
  /* This is to be compatible with BSD 4.2 AS, not for any rational reason.  */
2247
7.96k
#define BSD_FILL_SIZE_CROCK_8 (8)
2248
7.72k
  if (size > BSD_FILL_SIZE_CROCK_8)
2249
117
    {
2250
117
      as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
2251
117
      size = BSD_FILL_SIZE_CROCK_8;
2252
117
    }
2253
7.72k
  if (size < 0)
2254
1.48k
    {
2255
1.48k
      as_warn (_("size negative; .fill ignored"));
2256
1.48k
      size = 0;
2257
1.48k
    }
2258
6.24k
  else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
2259
387
    {
2260
387
      if (rep_exp.X_add_number < 0)
2261
297
  as_warn (_("repeat < 0; .fill ignored"));
2262
387
      size = 0;
2263
387
    }
2264
5.85k
  else if (size && !need_pass_2)
2265
2.75k
    {
2266
2.75k
      if (now_seg == absolute_section && rep_exp.X_op != O_constant)
2267
143
  {
2268
143
    as_bad (_("non-constant fill count for absolute section"));
2269
143
    size = 0;
2270
143
  }
2271
2.61k
      else if (now_seg == absolute_section && fill && rep_exp.X_add_number != 0)
2272
11
  {
2273
11
    as_bad (_("attempt to fill absolute section with non-zero value"));
2274
11
    size = 0;
2275
11
  }
2276
2.60k
      else if (fill
2277
2.60k
         && (rep_exp.X_op != O_constant || rep_exp.X_add_number != 0)
2278
2.60k
         && in_bss ())
2279
4
  {
2280
4
    as_bad (_("attempt to fill section `%s' with non-zero value"),
2281
4
      segment_name (now_seg));
2282
4
    size = 0;
2283
4
  }
2284
2.75k
    }
2285
2286
7.72k
  if (size && !need_pass_2)
2287
2.59k
    {
2288
2.59k
      if (now_seg == absolute_section)
2289
281
  abs_section_offset += rep_exp.X_add_number * size;
2290
2291
2.59k
      if (rep_exp.X_op == O_constant)
2292
2.33k
  {
2293
2.33k
    p = frag_var (rs_fill, (int) size, (int) size,
2294
2.33k
      (relax_substateT) 0, (symbolS *) 0,
2295
2.33k
      (offsetT) rep_exp.X_add_number,
2296
2.33k
      (char *) 0);
2297
2.33k
  }
2298
267
      else
2299
267
  {
2300
    /* We don't have a constant repeat count, so we can't use
2301
       rs_fill.  We can get the same results out of rs_space,
2302
       but its argument is in bytes, so we must multiply the
2303
       repeat count by size.  */
2304
2305
267
    symbolS *rep_sym;
2306
267
    rep_sym = make_expr_symbol (&rep_exp);
2307
267
    if (size != 1)
2308
2
      {
2309
2
        expressionS size_exp;
2310
2
        size_exp.X_op = O_constant;
2311
2
        size_exp.X_add_number = size;
2312
2313
2
        rep_exp.X_op = O_multiply;
2314
2
        rep_exp.X_add_symbol = rep_sym;
2315
2
        rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
2316
2
        rep_exp.X_add_number = 0;
2317
2
        rep_sym = make_expr_symbol (&rep_exp);
2318
2
      }
2319
2320
267
    p = frag_var (rs_space, (int) size, (int) size,
2321
267
      (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
2322
267
  }
2323
2324
2.59k
      memset (p, 0, (unsigned int) size);
2325
2326
      /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
2327
   flavoured AS.  The following bizarre behaviour is to be
2328
   compatible with above.  I guess they tried to take up to 8
2329
   bytes from a 4-byte expression and they forgot to sign
2330
   extend.  */
2331
2.59k
#define BSD_FILL_SIZE_CROCK_4 (4)
2332
2.59k
      md_number_to_chars (p, (valueT) fill,
2333
2.59k
        (size > BSD_FILL_SIZE_CROCK_4
2334
2.59k
         ? BSD_FILL_SIZE_CROCK_4
2335
2.59k
         : (int) size));
2336
      /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
2337
   but emits no error message because it seems a legal thing to do.
2338
   It is a degenerate case of .fill but could be emitted by a
2339
   compiler.  */
2340
2.59k
    }
2341
7.72k
  demand_empty_rest_of_line ();
2342
7.72k
}
2343
2344
void
2345
s_globl (int ignore ATTRIBUTE_UNUSED)
2346
0
{
2347
0
  char *name;
2348
0
  int c;
2349
0
  symbolS *symbolP;
2350
0
  char *stop = NULL;
2351
0
  char stopc = 0;
2352
2353
0
  if (flag_mri)
2354
0
    stop = mri_comment_field (&stopc);
2355
2356
0
  do
2357
0
    {
2358
0
      if ((name = read_symbol_name ()) == NULL)
2359
0
  return;
2360
2361
0
      symbolP = symbol_find_or_make (name);
2362
0
      S_SET_EXTERNAL (symbolP);
2363
2364
0
      SKIP_WHITESPACE ();
2365
0
      c = *input_line_pointer;
2366
0
      if (c == ',')
2367
0
  {
2368
0
    input_line_pointer++;
2369
0
    SKIP_WHITESPACE ();
2370
0
    if (is_end_of_line[(unsigned char) *input_line_pointer])
2371
0
      c = '\n';
2372
0
  }
2373
2374
0
      free (name);
2375
0
    }
2376
0
  while (c == ',');
2377
2378
0
  demand_empty_rest_of_line ();
2379
2380
0
  if (flag_mri)
2381
0
    mri_comment_end (stop, stopc);
2382
0
}
2383
2384
/* Handle the MRI IRP and IRPC pseudo-ops.  */
2385
2386
void
2387
s_irp (int irpc)
2388
2.90k
{
2389
2.90k
  char * eol;
2390
2.90k
  const char * file;
2391
2.90k
  unsigned int line;
2392
2.90k
  sb s;
2393
2.90k
  const char *err;
2394
2.90k
  sb out;
2395
2396
2.90k
  file = as_where (&line);
2397
2398
2.90k
  eol = find_end_of_line (input_line_pointer, 0);
2399
2.90k
  sb_build (&s, eol - input_line_pointer);
2400
2.90k
  sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2401
2.90k
  input_line_pointer = eol;
2402
2403
2.90k
  sb_new (&out);
2404
2405
2.90k
  err = expand_irp (irpc, 0, &s, &out, get_non_macro_line_sb);
2406
2.90k
  if (err != NULL)
2407
2.12k
    as_bad_where (file, line, "%s", err);
2408
2409
2.90k
  sb_kill (&s);
2410
2411
2.90k
  input_scrub_include_sb (&out, input_line_pointer, expanding_repeat);
2412
2.90k
  sb_kill (&out);
2413
2.90k
  buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2414
2.90k
}
2415
2416
/* Handle the .linkonce pseudo-op.  This tells the assembler to mark
2417
   the section to only be linked once.  However, this is not supported
2418
   by most object file formats.  This takes an optional argument,
2419
   which is what to do about duplicates.  */
2420
2421
void
2422
s_linkonce (int ignore ATTRIBUTE_UNUSED)
2423
0
{
2424
0
  enum linkonce_type type;
2425
2426
0
  SKIP_WHITESPACE ();
2427
2428
0
  type = LINKONCE_DISCARD;
2429
2430
0
  if (!is_end_of_line[(unsigned char) *input_line_pointer])
2431
0
    {
2432
0
      char *s;
2433
0
      char c;
2434
2435
0
      c = get_symbol_name (& s);
2436
0
      if (strcasecmp (s, "discard") == 0)
2437
0
  type = LINKONCE_DISCARD;
2438
0
      else if (strcasecmp (s, "one_only") == 0)
2439
0
  type = LINKONCE_ONE_ONLY;
2440
0
      else if (strcasecmp (s, "same_size") == 0)
2441
0
  type = LINKONCE_SAME_SIZE;
2442
0
      else if (strcasecmp (s, "same_contents") == 0)
2443
0
  type = LINKONCE_SAME_CONTENTS;
2444
0
      else
2445
0
  as_warn (_("unrecognized .linkonce type `%s'"), s);
2446
2447
0
      (void) restore_line_pointer (c);
2448
0
    }
2449
2450
#ifdef obj_handle_link_once
2451
  obj_handle_link_once (type);
2452
#else /* ! defined (obj_handle_link_once) */
2453
0
  {
2454
0
    flagword flags;
2455
2456
0
    if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
2457
0
      as_warn (_(".linkonce is not supported for this object file format"));
2458
2459
0
    flags = bfd_section_flags (now_seg);
2460
0
    flags |= SEC_LINK_ONCE;
2461
0
    switch (type)
2462
0
      {
2463
0
      default:
2464
0
  abort ();
2465
0
      case LINKONCE_DISCARD:
2466
0
  flags |= SEC_LINK_DUPLICATES_DISCARD;
2467
0
  break;
2468
0
      case LINKONCE_ONE_ONLY:
2469
0
  flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
2470
0
  break;
2471
0
      case LINKONCE_SAME_SIZE:
2472
0
  flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
2473
0
  break;
2474
0
      case LINKONCE_SAME_CONTENTS:
2475
0
  flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
2476
0
  break;
2477
0
      }
2478
0
    if (!bfd_set_section_flags (now_seg, flags))
2479
0
      as_bad (_("bfd_set_section_flags: %s"),
2480
0
        bfd_errmsg (bfd_get_error ()));
2481
0
  }
2482
0
#endif /* ! defined (obj_handle_link_once) */
2483
2484
0
  demand_empty_rest_of_line ();
2485
0
}
2486
2487
void
2488
bss_alloc (symbolS *symbolP, addressT size, unsigned int align)
2489
13
{
2490
13
  char *pfrag;
2491
13
  segT current_seg = now_seg;
2492
13
  subsegT current_subseg = now_subseg;
2493
13
  segT bss_seg = bss_section;
2494
2495
#if defined (TC_MIPS) || defined (TC_ALPHA)
2496
  if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
2497
      || OUTPUT_FLAVOR == bfd_target_elf_flavour)
2498
    {
2499
      /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss.  */
2500
      if (size <= bfd_get_gp_size (stdoutput))
2501
  {
2502
    bss_seg = subseg_new (".sbss", 1);
2503
    seg_info (bss_seg)->bss = 1;
2504
    if (!bfd_set_section_flags (bss_seg, SEC_ALLOC | SEC_SMALL_DATA))
2505
      as_warn (_("error setting flags for \".sbss\": %s"),
2506
         bfd_errmsg (bfd_get_error ()));
2507
  }
2508
    }
2509
#endif
2510
13
  subseg_set (bss_seg, 1);
2511
2512
13
  if (align > OCTETS_PER_BYTE_POWER)
2513
4
    {
2514
4
      record_alignment (bss_seg, align);
2515
4
      frag_align (align, 0, 0);
2516
4
    }
2517
2518
  /* Detach from old frag.  */
2519
13
  if (S_GET_SEGMENT (symbolP) == bss_seg)
2520
0
    symbol_get_frag (symbolP)->fr_symbol = NULL;
2521
2522
13
  symbol_set_frag (symbolP, frag_now);
2523
13
  pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size * OCTETS_PER_BYTE, NULL);
2524
13
  *pfrag = 0;
2525
2526
13
#ifdef S_SET_SIZE
2527
13
  S_SET_SIZE (symbolP, size);
2528
13
#endif
2529
13
  S_SET_SEGMENT (symbolP, bss_seg);
2530
2531
#ifdef OBJ_COFF
2532
  /* The symbol may already have been created with a preceding
2533
     ".globl" directive -- be careful not to step on storage class
2534
     in that case.  Otherwise, set it to static.  */
2535
  if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2536
    S_SET_STORAGE_CLASS (symbolP, C_STAT);
2537
#endif /* OBJ_COFF */
2538
2539
13
  subseg_set (current_seg, current_subseg);
2540
13
}
2541
2542
offsetT
2543
parse_align (int align_bytes)
2544
6.11k
{
2545
6.11k
  expressionS exp;
2546
6.11k
  addressT align;
2547
2548
6.11k
  SKIP_WHITESPACE ();
2549
6.11k
  if (*input_line_pointer != ',')
2550
0
    {
2551
3.84k
    no_align:
2552
3.84k
      as_bad (_("expected alignment after size"));
2553
3.84k
      ignore_rest_of_line ();
2554
3.84k
      return -1;
2555
0
    }
2556
2557
6.11k
  input_line_pointer++;
2558
6.11k
  SKIP_WHITESPACE ();
2559
2560
6.11k
  align = get_absolute_expr (&exp);
2561
6.11k
  if (exp.X_op == O_absent)
2562
3.84k
    goto no_align;
2563
2564
2.27k
  if (!exp.X_unsigned && exp.X_add_number < 0)
2565
73
    {
2566
73
      as_warn (_("alignment negative; 0 assumed"));
2567
73
      align = 0;
2568
73
    }
2569
2570
2.27k
  if (align_bytes && align != 0)
2571
0
    {
2572
      /* convert to a power of 2 alignment */
2573
0
      unsigned int alignp2 = 0;
2574
0
      while ((align & 1) == 0)
2575
0
  align >>= 1, ++alignp2;
2576
0
      if (align != 1)
2577
0
  {
2578
0
    as_bad (_("alignment not a power of 2"));
2579
0
    ignore_rest_of_line ();
2580
0
    return -1;
2581
0
  }
2582
0
      align = alignp2;
2583
0
    }
2584
2.27k
  return align;
2585
2.27k
}
2586
2587
/* Called from s_comm_internal after symbol name and size have been
2588
   parsed.  NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2589
   1 if this was a ".bss" directive which has a 3rd argument
2590
   (alignment as a power of 2), or 2 if this was a ".bss" directive
2591
   with alignment in bytes.  */
2592
2593
symbolS *
2594
s_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
2595
13
{
2596
13
  addressT align = 0;
2597
2598
13
  if (needs_align)
2599
0
    {
2600
0
      align = parse_align (needs_align - 1);
2601
0
      if (align == (addressT) -1)
2602
0
  return NULL;
2603
0
    }
2604
13
  else
2605
    /* Assume some objects may require alignment on some systems.  */
2606
13
    TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
2607
2608
13
  bss_alloc (symbolP, size, align);
2609
13
  return symbolP;
2610
13
}
2611
2612
void
2613
s_lcomm (int needs_align)
2614
0
{
2615
0
  s_comm_internal (needs_align, s_lcomm_internal);
2616
0
}
2617
2618
void
2619
s_lcomm_bytes (int needs_align)
2620
0
{
2621
0
  s_comm_internal (needs_align * 2, s_lcomm_internal);
2622
0
}
2623
2624
void
2625
s_lsym (int ignore ATTRIBUTE_UNUSED)
2626
386
{
2627
386
  char *name;
2628
386
  expressionS exp;
2629
386
  symbolS *symbolP;
2630
2631
  /* We permit ANY defined expression: BSD4.2 demands constants.  */
2632
386
  if ((name = read_symbol_name ()) == NULL)
2633
53
    return;
2634
2635
333
  if (*input_line_pointer != ',')
2636
127
    {
2637
127
      as_bad (_("expected comma after \"%s\""), name);
2638
127
      goto err_out;
2639
127
    }
2640
2641
206
  input_line_pointer++;
2642
206
  expression_and_evaluate (&exp);
2643
2644
206
  if (exp.X_op != O_constant
2645
206
      && exp.X_op != O_register)
2646
117
    {
2647
117
      as_bad (_("bad expression"));
2648
117
      goto err_out;
2649
117
    }
2650
2651
89
  symbolP = symbol_find_or_make (name);
2652
2653
89
  if (S_GET_SEGMENT (symbolP) == undefined_section)
2654
38
    {
2655
      /* The name might be an undefined .global symbol; be sure to
2656
   keep the "external" bit.  */
2657
38
      S_SET_SEGMENT (symbolP,
2658
38
         (exp.X_op == O_constant
2659
38
          ? absolute_section
2660
38
          : reg_section));
2661
38
      S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2662
38
    }
2663
51
  else
2664
51
    {
2665
51
      as_bad (_("symbol `%s' is already defined"), name);
2666
51
    }
2667
2668
89
  demand_empty_rest_of_line ();
2669
89
  free (name);
2670
89
  return;
2671
2672
244
 err_out:
2673
244
  ignore_rest_of_line ();
2674
244
  free (name);
2675
244
  return;
2676
206
}
2677
2678
/* Read a line into an sb.  Returns the character that ended the line
2679
   or zero if there are no more lines.  */
2680
2681
static int
2682
get_line_sb (sb *line, int in_macro)
2683
105k
{
2684
105k
  char *eol;
2685
2686
105k
  if (input_line_pointer[-1] == '\n')
2687
71.8k
    bump_line_counters ();
2688
2689
105k
  if (input_line_pointer >= buffer_limit)
2690
80
    {
2691
80
      buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2692
80
      if (buffer_limit == 0)
2693
15
  return 0;
2694
80
    }
2695
2696
105k
  eol = _find_end_of_line (input_line_pointer, flag_m68k_mri, 0, in_macro);
2697
105k
  sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
2698
105k
  input_line_pointer = eol;
2699
2700
  /* Don't skip multiple end-of-line characters, because that breaks support
2701
     for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2702
     characters but isn't.  Instead just skip one end of line character and
2703
     return the character skipped so that the caller can re-insert it if
2704
     necessary.   */
2705
105k
  return *input_line_pointer++;
2706
105k
}
2707
2708
static size_t
2709
get_non_macro_line_sb (sb *line)
2710
76.1k
{
2711
76.1k
  return get_line_sb (line, 0);
2712
76.1k
}
2713
2714
static size_t
2715
get_macro_line_sb (sb *line)
2716
29.3k
{
2717
29.3k
  return get_line_sb (line, 1);
2718
29.3k
}
2719
2720
/* Define a macro.  This is an interface to macro.c.  */
2721
2722
void
2723
s_macro (int ignore ATTRIBUTE_UNUSED)
2724
2.89k
{
2725
2.89k
  char *eol;
2726
2.89k
  sb s;
2727
2.89k
  macro_entry *macro;
2728
2729
2.89k
  eol = find_end_of_line (input_line_pointer, 0);
2730
2.89k
  sb_build (&s, eol - input_line_pointer);
2731
2.89k
  sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2732
2.89k
  input_line_pointer = eol;
2733
2734
2.89k
  if (line_label != NULL)
2735
40
    {
2736
40
      sb label;
2737
40
      size_t len;
2738
40
      const char *name;
2739
2740
40
      name = S_GET_NAME (line_label);
2741
40
      len = strlen (name);
2742
40
      sb_build (&label, len);
2743
40
      sb_add_buffer (&label, name, len);
2744
40
      macro = define_macro (&s, &label, get_macro_line_sb);
2745
40
      sb_kill (&label);
2746
40
    }
2747
2.85k
  else
2748
2.85k
    macro = define_macro (&s, NULL, get_macro_line_sb);
2749
2.89k
  if (macro != NULL)
2750
398
    {
2751
398
      if (line_label != NULL)
2752
0
  {
2753
0
    S_SET_SEGMENT (line_label, absolute_section);
2754
0
    S_SET_VALUE (line_label, 0);
2755
0
    symbol_set_frag (line_label, &zero_address_frag);
2756
0
  }
2757
2758
398
      if (((NO_PSEUDO_DOT || flag_m68k_mri)
2759
398
     && str_hash_find (po_hash, macro->name) != NULL)
2760
398
    || (!flag_m68k_mri
2761
398
        && macro->name[0] == '.'
2762
398
        && str_hash_find (po_hash, macro->name + 1) != NULL))
2763
251
  {
2764
251
    as_warn_where (macro->file, macro->line,
2765
251
       _("attempt to redefine pseudo-op `%s' ignored"),
2766
251
       macro->name);
2767
251
    str_hash_delete (macro_hash, macro->name);
2768
251
  }
2769
398
    }
2770
2771
2.89k
  sb_kill (&s);
2772
2.89k
}
2773
2774
/* Handle the .mexit pseudo-op, which immediately exits a macro
2775
   expansion.  */
2776
2777
void
2778
s_mexit (int ignore ATTRIBUTE_UNUSED)
2779
0
{
2780
0
  if (macro_nest)
2781
0
    {
2782
0
      cond_exit_macro (macro_nest);
2783
0
      buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2784
0
    }
2785
0
  else
2786
0
    as_warn (_("ignoring macro exit outside a macro definition."));
2787
0
}
2788
2789
/* Switch in and out of MRI mode.  */
2790
2791
void
2792
s_mri (int ignore ATTRIBUTE_UNUSED)
2793
16.5k
{
2794
16.5k
  int on;
2795
#ifdef MRI_MODE_CHANGE
2796
  int old_flag;
2797
#endif
2798
2799
16.5k
  on = get_absolute_expression ();
2800
#ifdef MRI_MODE_CHANGE
2801
  old_flag = flag_mri;
2802
#endif
2803
16.5k
  if (on != 0)
2804
502
    {
2805
502
      flag_mri = 1;
2806
#ifdef TC_M68K
2807
      flag_m68k_mri = 1;
2808
#endif
2809
502
    }
2810
16.0k
  else
2811
16.0k
    {
2812
16.0k
      flag_mri = 0;
2813
#ifdef TC_M68K
2814
      flag_m68k_mri = 0;
2815
#endif
2816
16.0k
    }
2817
2818
  /* Operator precedence changes in m68k MRI mode, so we need to
2819
     update the operator rankings.  */
2820
16.5k
  expr_set_precedence ();
2821
2822
#ifdef MRI_MODE_CHANGE
2823
  if (on != old_flag)
2824
    MRI_MODE_CHANGE (on);
2825
#endif
2826
2827
16.5k
  demand_empty_rest_of_line ();
2828
16.5k
}
2829
2830
/* Handle changing the location counter.  */
2831
2832
static void
2833
do_org (segT segment, expressionS *exp, int fill)
2834
81.6k
{
2835
81.6k
  if (segment != now_seg
2836
81.6k
      && segment != absolute_section
2837
81.6k
      && segment != expr_section)
2838
55
    as_bad (_("invalid segment \"%s\""), segment_name (segment));
2839
2840
81.6k
  if (now_seg == absolute_section)
2841
10.5k
    {
2842
10.5k
      if (fill != 0)
2843
32
  as_warn (_("ignoring fill value in absolute section"));
2844
10.5k
      if (exp->X_op != O_constant)
2845
2.28k
  {
2846
2.28k
    as_bad (_("only constant offsets supported in absolute section"));
2847
2.28k
    exp->X_add_number = 0;
2848
2.28k
  }
2849
10.5k
      abs_section_offset = exp->X_add_number;
2850
10.5k
    }
2851
71.1k
  else
2852
71.1k
    {
2853
71.1k
      char *p;
2854
71.1k
      symbolS *sym = exp->X_add_symbol;
2855
71.1k
      offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
2856
2857
71.1k
      if (fill && in_bss ())
2858
3
  as_warn (_("ignoring fill value in section `%s'"),
2859
3
     segment_name (now_seg));
2860
2861
71.1k
      if (exp->X_op != O_constant && exp->X_op != O_symbol)
2862
2.47k
  {
2863
    /* Handle complex expressions.  */
2864
2.47k
    sym = make_expr_symbol (exp);
2865
2.47k
    off = 0;
2866
2.47k
  }
2867
2868
71.1k
      p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
2869
71.1k
      *p = fill;
2870
71.1k
    }
2871
81.6k
}
2872
2873
void
2874
s_org (int ignore ATTRIBUTE_UNUSED)
2875
80.0k
{
2876
80.0k
  segT segment;
2877
80.0k
  expressionS exp;
2878
80.0k
  long temp_fill;
2879
2880
#ifdef md_flush_pending_output
2881
  md_flush_pending_output ();
2882
#endif
2883
2884
  /* The m68k MRI assembler has a different meaning for .org.  It
2885
     means to create an absolute section at a given address.  We can't
2886
     support that--use a linker script instead.  */
2887
80.0k
  if (flag_m68k_mri)
2888
0
    {
2889
0
      as_bad (_("MRI style ORG pseudo-op not supported"));
2890
0
      ignore_rest_of_line ();
2891
0
      return;
2892
0
    }
2893
2894
  /* Don't believe the documentation of BSD 4.2 AS.  There is no such
2895
     thing as a sub-segment-relative origin.  Any absolute origin is
2896
     given a warning, then assumed to be segment-relative.  Any
2897
     segmented origin expression ("foo+42") had better be in the right
2898
     segment or the .org is ignored.
2899
2900
     BSD 4.2 AS warns if you try to .org backwards. We cannot because
2901
     we never know sub-segment sizes when we are reading code.  BSD
2902
     will crash trying to emit negative numbers of filler bytes in
2903
     certain .orgs. We don't crash, but see as-write for that code.
2904
2905
     Don't make frag if need_pass_2==1.  */
2906
80.0k
  segment = get_known_segmented_expression (&exp);
2907
80.0k
  if (*input_line_pointer == ',')
2908
15.0k
    {
2909
15.0k
      input_line_pointer++;
2910
15.0k
      temp_fill = get_absolute_expression ();
2911
15.0k
    }
2912
65.0k
  else
2913
65.0k
    temp_fill = 0;
2914
2915
80.0k
  if (!need_pass_2)
2916
80.0k
    do_org (segment, &exp, temp_fill);
2917
2918
80.0k
  demand_empty_rest_of_line ();
2919
80.0k
}
2920
2921
/* Handle parsing for the MRI SECT/SECTION pseudo-op.  This should be
2922
   called by the obj-format routine which handles section changing
2923
   when in MRI mode.  It will create a new section, and return it.  It
2924
   will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2925
   'M' (mixed), or 'R' (romable).  The flags will be set in the section.  */
2926
2927
void
2928
s_mri_sect (char *type ATTRIBUTE_UNUSED)
2929
108
{
2930
#ifdef TC_M68K
2931
2932
  char *name;
2933
  char c;
2934
  segT seg;
2935
2936
  SKIP_WHITESPACE ();
2937
2938
  name = input_line_pointer;
2939
  if (!ISDIGIT (*name))
2940
    c = get_symbol_name (& name);
2941
  else
2942
    {
2943
      do
2944
  {
2945
    ++input_line_pointer;
2946
  }
2947
      while (ISDIGIT (*input_line_pointer));
2948
2949
      c = *input_line_pointer;
2950
      *input_line_pointer = '\0';
2951
    }
2952
2953
  name = xstrdup (name);
2954
2955
  c = restore_line_pointer (c);
2956
2957
  seg = subseg_new (name, 0);
2958
2959
  if (c == ',')
2960
    {
2961
      unsigned int align;
2962
2963
      ++input_line_pointer;
2964
      align = get_absolute_expression ();
2965
      record_alignment (seg, align);
2966
    }
2967
2968
  *type = 'C';
2969
  if (*input_line_pointer == ',')
2970
    {
2971
      c = *++input_line_pointer;
2972
      c = TOUPPER (c);
2973
      if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2974
  *type = c;
2975
      else
2976
  as_bad (_("unrecognized section type"));
2977
      ++input_line_pointer;
2978
2979
      {
2980
  flagword flags;
2981
2982
  flags = SEC_NO_FLAGS;
2983
  if (*type == 'C')
2984
    flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2985
  else if (*type == 'D' || *type == 'M')
2986
    flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2987
  else if (*type == 'R')
2988
    flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2989
  if (flags != SEC_NO_FLAGS)
2990
    {
2991
      if (!bfd_set_section_flags (seg, flags))
2992
        as_warn (_("error setting flags for \"%s\": %s"),
2993
           bfd_section_name (seg),
2994
           bfd_errmsg (bfd_get_error ()));
2995
    }
2996
      }
2997
    }
2998
2999
  /* Ignore the HP type.  */
3000
  if (*input_line_pointer == ',')
3001
    input_line_pointer += 2;
3002
3003
  demand_empty_rest_of_line ();
3004
3005
#else /* ! TC_M68K */
3006
  /* The MRI assembler seems to use different forms of .sect for
3007
     different targets.  */
3008
108
  as_bad ("MRI mode not supported for this target");
3009
108
  ignore_rest_of_line ();
3010
108
#endif /* ! TC_M68K */
3011
108
}
3012
3013
/* Handle the .print pseudo-op.  */
3014
3015
void
3016
s_print (int ignore ATTRIBUTE_UNUSED)
3017
0
{
3018
0
  char *s;
3019
0
  int len;
3020
3021
0
  s = demand_copy_C_string (&len);
3022
0
  if (s != NULL)
3023
0
    printf ("%s\n", s);
3024
0
  demand_empty_rest_of_line ();
3025
0
}
3026
3027
/* Handle the .purgem pseudo-op.  */
3028
3029
void
3030
s_purgem (int ignore ATTRIBUTE_UNUSED)
3031
4.86k
{
3032
4.86k
  if (is_it_end_of_statement ())
3033
2.60k
    {
3034
2.60k
      demand_empty_rest_of_line ();
3035
2.60k
      return;
3036
2.60k
    }
3037
3038
2.25k
  do
3039
2.61k
    {
3040
2.61k
      char *name;
3041
2.61k
      char c;
3042
3043
2.61k
      SKIP_WHITESPACE ();
3044
2.61k
      c = get_symbol_name (& name);
3045
2.61k
      delete_macro (name);
3046
2.61k
      *input_line_pointer = c;
3047
2.61k
      SKIP_WHITESPACE_AFTER_NAME ();
3048
2.61k
    }
3049
2.61k
  while (*input_line_pointer++ == ',');
3050
3051
2.25k
  --input_line_pointer;
3052
2.25k
  demand_empty_rest_of_line ();
3053
2.25k
}
3054
3055
/* Handle the .endm/.endr pseudo-ops.  */
3056
3057
static void
3058
s_bad_end (int endr)
3059
11.2k
{
3060
11.2k
  as_warn (_(".end%c encountered without preceding %s"),
3061
11.2k
     endr ? 'r' : 'm',
3062
11.2k
     endr ? ".rept, .irp, or .irpc" : ".macro");
3063
11.2k
  demand_empty_rest_of_line ();
3064
11.2k
}
3065
3066
/* Handle the .rept pseudo-op.  */
3067
3068
void
3069
s_rept (int ignore ATTRIBUTE_UNUSED)
3070
2.66k
{
3071
2.66k
  size_t count;
3072
3073
2.66k
  count = (size_t) get_absolute_expression ();
3074
3075
2.66k
  do_repeat (count, "REPT", "ENDR", NULL);
3076
2.66k
}
3077
3078
/* This function provides a generic repeat block implementation.   It allows
3079
   different directives to be used as the start/end keys.  Any text matching
3080
   the optional EXPANDER in the block is replaced by the remaining iteration
3081
   count.  */
3082
3083
void
3084
do_repeat (size_t count, const char *start, const char *end,
3085
     const char *expander)
3086
2.66k
{
3087
2.66k
  sb one;
3088
2.66k
  sb many;
3089
3090
2.66k
  if (((ssize_t) count) < 0)
3091
4
    {
3092
4
      as_bad (_("negative count for %s - ignored"), start);
3093
4
      count = 0;
3094
4
    }
3095
3096
2.66k
  sb_new (&one);
3097
2.66k
  if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
3098
1.92k
    {
3099
1.92k
      as_bad (_("%s without %s"), start, end);
3100
1.92k
      sb_kill (&one);
3101
1.92k
      return;
3102
1.92k
    }
3103
3104
736
  if (expander == NULL || strstr (one.ptr, expander) == NULL)
3105
736
    {
3106
736
      sb_build (&many, count * one.len);
3107
28.4k
      while (count-- > 0)
3108
27.6k
  sb_add_sb (&many, &one);
3109
736
    }
3110
0
  else
3111
0
    {
3112
0
      sb_new (&many);
3113
3114
0
      while (count -- > 0)
3115
0
  {
3116
0
    int len;
3117
0
    char * sub;
3118
0
    sb processed;
3119
3120
0
    sb_build (& processed, one.len);
3121
0
    sb_add_sb (& processed, & one);
3122
0
    sub = strstr (processed.ptr, expander);
3123
0
    len = sprintf (sub, "%lu", (unsigned long) count);
3124
0
    gas_assert (len < 8);
3125
0
    memmove (sub + len, sub + 8,
3126
0
       processed.ptr + processed.len - (sub + 8));
3127
0
    processed.len -= (8 - len);
3128
0
    sb_add_sb (& many, & processed);
3129
0
    sb_kill (& processed);
3130
0
  }
3131
0
    }
3132
3133
736
  sb_kill (&one);
3134
3135
736
  input_scrub_include_sb (&many, input_line_pointer, expanding_repeat);
3136
736
  sb_kill (&many);
3137
736
  buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3138
736
}
3139
3140
/* Skip to end of current repeat loop; EXTRA indicates how many additional
3141
   input buffers to skip.  Assumes that conditionals preceding the loop end
3142
   are properly nested.
3143
3144
   This function makes it easier to implement a premature "break" out of the
3145
   loop.  The EXTRA arg accounts for other buffers we might have inserted,
3146
   such as line substitutions.  */
3147
3148
void
3149
end_repeat (int extra)
3150
0
{
3151
0
  cond_exit_macro (macro_nest);
3152
0
  while (extra-- >= 0)
3153
0
    buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3154
0
}
3155
3156
static void
3157
assign_symbol (char *name, int mode)
3158
167k
{
3159
167k
  symbolS *symbolP;
3160
3161
167k
  if (name[0] == '.' && name[1] == '\0')
3162
1.64k
    {
3163
      /* Turn '. = mumble' into a .org mumble.  */
3164
1.64k
      segT segment;
3165
1.64k
      expressionS exp;
3166
3167
1.64k
      segment = get_known_segmented_expression (&exp);
3168
3169
1.64k
      if (!need_pass_2)
3170
1.64k
  do_org (segment, &exp, 0);
3171
3172
1.64k
      return;
3173
1.64k
    }
3174
3175
165k
  if ((symbolP = symbol_find (name)) == NULL
3176
165k
      && (symbolP = md_undefined_symbol (name)) == NULL)
3177
7.17k
    {
3178
7.17k
      symbolP = symbol_find_or_make (name);
3179
7.17k
#ifndef NO_LISTING
3180
      /* When doing symbol listings, play games with dummy fragments living
3181
   outside the normal fragment chain to record the file and line info
3182
   for this symbol.  */
3183
7.17k
      if (listing & LISTING_SYMBOLS)
3184
0
  {
3185
0
    extern struct list_info_struct *listing_tail;
3186
0
    fragS *dummy_frag = notes_calloc (1, sizeof (*dummy_frag));
3187
0
    dummy_frag->line = listing_tail;
3188
0
    dummy_frag->fr_symbol = symbolP;
3189
0
    symbol_set_frag (symbolP, dummy_frag);
3190
0
  }
3191
7.17k
#endif
3192
#if defined (OBJ_COFF) && !defined (TE_PE)
3193
      /* "set" symbols are local unless otherwise specified.  */
3194
      SF_SET_LOCAL (symbolP);
3195
#endif
3196
7.17k
    }
3197
3198
165k
  if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3199
149k
    {
3200
149k
      if ((mode != 0 || !S_IS_VOLATILE (symbolP))
3201
149k
    && !S_CAN_BE_REDEFINED (symbolP))
3202
23.2k
  {
3203
23.2k
    as_bad (_("symbol `%s' is already defined"), name);
3204
23.2k
    ignore_rest_of_line ();
3205
23.2k
    input_line_pointer--;
3206
23.2k
    return;
3207
23.2k
  }
3208
      /* If the symbol is volatile, copy the symbol and replace the
3209
   original with the copy, so that previous uses of the symbol will
3210
   retain the value of the symbol at the point of use.  */
3211
126k
      else if (S_IS_VOLATILE (symbolP))
3212
126k
  symbolP = symbol_clone (symbolP, 1);
3213
149k
    }
3214
3215
142k
  if (mode == 0)
3216
134k
    S_SET_VOLATILE (symbolP);
3217
8.28k
  else if (mode < 0)
3218
8.28k
    S_SET_FORWARD_REF (symbolP);
3219
3220
142k
  pseudo_set (symbolP);
3221
142k
}
3222
3223
/* Handle the .equ, .equiv, .eqv, and .set directives.  If EQUIV is 1,
3224
   then this is .equiv, and it is an error if the symbol is already
3225
   defined.  If EQUIV is -1, the symbol additionally is a forward
3226
   reference.  */
3227
3228
void
3229
s_set (int equiv)
3230
5.05k
{
3231
5.05k
  char *name;
3232
3233
  /* Especial apologies for the random logic:
3234
     this just grew, and could be parsed much more simply!
3235
     Dean in haste.  */
3236
5.05k
  if ((name = read_symbol_name ()) == NULL)
3237
5.05k
    return;
3238
3239
1
  if (*input_line_pointer != ',')
3240
1
    {
3241
1
      as_bad (_("expected comma after \"%s\""), name);
3242
1
      ignore_rest_of_line ();
3243
1
      free (name);
3244
1
      return;
3245
1
    }
3246
3247
0
  input_line_pointer++;
3248
0
  assign_symbol (name, equiv);
3249
0
  demand_empty_rest_of_line ();
3250
0
  free (name);
3251
0
}
3252
3253
void
3254
s_space (int mult)
3255
3.23k
{
3256
3.23k
  expressionS exp;
3257
3.23k
  expressionS val;
3258
3.23k
  char *p = 0;
3259
3.23k
  char *stop = NULL;
3260
3.23k
  char stopc = 0;
3261
3.23k
  int bytes;
3262
3263
#ifdef md_flush_pending_output
3264
  md_flush_pending_output ();
3265
#endif
3266
3267
3.23k
  switch (mult)
3268
3.23k
    {
3269
0
    case 'x':
3270
0
#ifdef X_PRECISION
3271
0
# ifndef P_PRECISION
3272
0
#  define P_PRECISION     X_PRECISION
3273
0
#  define P_PRECISION_PAD X_PRECISION_PAD
3274
0
# endif
3275
0
      mult = (X_PRECISION + X_PRECISION_PAD) * sizeof (LITTLENUM_TYPE);
3276
0
      if (!mult)
3277
0
#endif
3278
0
  mult = 12;
3279
0
      break;
3280
3281
0
    case 'p':
3282
0
#ifdef P_PRECISION
3283
0
      mult = (P_PRECISION + P_PRECISION_PAD) * sizeof (LITTLENUM_TYPE);
3284
0
      if (!mult)
3285
0
#endif
3286
0
  mult = 12;
3287
0
      break;
3288
3.23k
    }
3289
3290
3.23k
#ifdef md_cons_align
3291
3.23k
  md_cons_align (1);
3292
3.23k
#endif
3293
3294
3.23k
  if (flag_mri)
3295
827
    stop = mri_comment_field (&stopc);
3296
3297
  /* In m68k MRI mode, we need to align to a word boundary, unless
3298
     this is ds.b.  */
3299
3.23k
  if (flag_m68k_mri && mult > 1)
3300
0
    {
3301
0
      if (now_seg == absolute_section)
3302
0
  {
3303
0
    abs_section_offset += abs_section_offset & 1;
3304
0
    if (line_label != NULL)
3305
0
      S_SET_VALUE (line_label, abs_section_offset);
3306
0
  }
3307
0
      else if (mri_common_symbol != NULL)
3308
0
  {
3309
0
    valueT mri_val;
3310
3311
0
    mri_val = S_GET_VALUE (mri_common_symbol);
3312
0
    if ((mri_val & 1) != 0)
3313
0
      {
3314
0
        S_SET_VALUE (mri_common_symbol, mri_val + 1);
3315
0
        if (line_label != NULL)
3316
0
    {
3317
0
      expressionS *symexp;
3318
3319
0
      symexp = symbol_get_value_expression (line_label);
3320
0
      know (symexp->X_op == O_symbol);
3321
0
      know (symexp->X_add_symbol == mri_common_symbol);
3322
0
      symexp->X_add_number += 1;
3323
0
    }
3324
0
      }
3325
0
  }
3326
0
      else
3327
0
  {
3328
0
    do_align (1, (char *) NULL, 0, 0);
3329
0
    if (line_label != NULL)
3330
0
      {
3331
0
        symbol_set_frag (line_label, frag_now);
3332
0
        S_SET_VALUE (line_label, frag_now_fix ());
3333
0
      }
3334
0
  }
3335
0
    }
3336
3337
3.23k
  bytes = mult;
3338
3339
3.23k
  expression (&exp);
3340
3341
3.23k
  SKIP_WHITESPACE ();
3342
3.23k
  if (*input_line_pointer == ',')
3343
898
    {
3344
898
      ++input_line_pointer;
3345
898
      expression (&val);
3346
898
    }
3347
2.33k
  else
3348
2.33k
    {
3349
2.33k
      val.X_op = O_constant;
3350
2.33k
      val.X_add_number = 0;
3351
2.33k
    }
3352
3353
3.23k
  if ((val.X_op != O_constant
3354
3.23k
       || val.X_add_number < - 0x80
3355
3.23k
       || val.X_add_number > 0xff
3356
3.23k
       || (mult != 0 && mult != 1 && val.X_add_number != 0))
3357
3.23k
      && (now_seg != absolute_section && !in_bss ()))
3358
436
    {
3359
436
      resolve_expression (&exp);
3360
436
      if (exp.X_op != O_constant)
3361
51
  as_bad (_("unsupported variable size or fill value"));
3362
385
      else
3363
385
  {
3364
385
    offsetT i;
3365
3366
    /* PR 20901: Check for excessive values.
3367
       FIXME: 1<<10 is an arbitrary limit.  Maybe use maxpagesize instead ?  */
3368
385
    if (exp.X_add_number < 0 || exp.X_add_number > (1 << 10))
3369
4
      as_bad (_("size value for space directive too large: %lx"),
3370
4
        (long) exp.X_add_number);
3371
381
    else
3372
381
      {
3373
381
        if (mult == 0)
3374
251
    mult = 1;
3375
381
        bytes = mult * exp.X_add_number;
3376
3377
929
        for (i = 0; i < exp.X_add_number; i++)
3378
548
    emit_expr (&val, mult);
3379
381
      }
3380
385
  }
3381
436
    }
3382
2.80k
  else
3383
2.80k
    {
3384
2.80k
      if (now_seg == absolute_section || mri_common_symbol != NULL)
3385
1.43k
  resolve_expression (&exp);
3386
3387
2.80k
      if (exp.X_op == O_constant)
3388
2.45k
  {
3389
2.45k
    addressT repeat = exp.X_add_number;
3390
2.45k
    addressT total;
3391
3392
2.45k
    bytes = 0;
3393
2.45k
    if ((offsetT) repeat < 0)
3394
409
      {
3395
409
        as_warn (_(".space repeat count is negative, ignored"));
3396
409
        goto getout;
3397
409
      }
3398
2.04k
    if (repeat == 0)
3399
1.57k
      {
3400
1.57k
        if (!flag_mri)
3401
972
    as_warn (_(".space repeat count is zero, ignored"));
3402
1.57k
        goto getout;
3403
1.57k
      }
3404
465
    if ((unsigned int) mult <= 1)
3405
223
      total = repeat;
3406
242
    else if (gas_mul_overflow (repeat, mult, &total)
3407
242
       || (offsetT) total < 0)
3408
0
      {
3409
0
        as_warn (_(".space repeat count overflow, ignored"));
3410
0
        goto getout;
3411
0
      }
3412
465
    bytes = total;
3413
3414
    /* If we are in the absolute section, just bump the offset.  */
3415
465
    if (now_seg == absolute_section)
3416
307
      {
3417
307
        if (val.X_op != O_constant || val.X_add_number != 0)
3418
110
    as_warn (_("ignoring fill value in absolute section"));
3419
307
        abs_section_offset += total;
3420
307
        goto getout;
3421
307
      }
3422
3423
    /* If we are secretly in an MRI common section, then
3424
       creating space just increases the size of the common
3425
       symbol.  */
3426
158
    if (mri_common_symbol != NULL)
3427
0
      {
3428
0
        S_SET_VALUE (mri_common_symbol,
3429
0
         S_GET_VALUE (mri_common_symbol) + total);
3430
0
        goto getout;
3431
0
      }
3432
3433
158
    if (!need_pass_2)
3434
158
      p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
3435
158
        (offsetT) total, (char *) 0);
3436
158
  }
3437
349
      else
3438
349
  {
3439
349
    if (now_seg == absolute_section)
3440
51
      {
3441
51
        as_bad (_("space allocation too complex in absolute section"));
3442
51
        subseg_set (text_section, 0);
3443
51
      }
3444
3445
349
    if (mri_common_symbol != NULL)
3446
0
      {
3447
0
        as_bad (_("space allocation too complex in common section"));
3448
0
        mri_common_symbol = NULL;
3449
0
      }
3450
3451
349
    if (!need_pass_2)
3452
349
      p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
3453
349
        make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
3454
349
  }
3455
3456
507
      if ((val.X_op != O_constant || val.X_add_number != 0) && in_bss ())
3457
99
  as_warn (_("ignoring fill value in section `%s'"),
3458
99
     segment_name (now_seg));
3459
408
      else if (p)
3460
408
  *p = val.X_add_number;
3461
507
    }
3462
3463
3.23k
 getout:
3464
3465
  /* In MRI mode, after an odd number of bytes, we must align to an
3466
     even word boundary, unless the next instruction is a dc.b, ds.b
3467
     or dcb.b.  */
3468
3.23k
  if (flag_mri && (bytes & 1) != 0)
3469
117
    mri_pending_align = 1;
3470
3471
3.23k
  demand_empty_rest_of_line ();
3472
3473
3.23k
  if (flag_mri)
3474
827
    mri_comment_end (stop, stopc);
3475
3.23k
}
3476
3477
void
3478
s_nop (int ignore ATTRIBUTE_UNUSED)
3479
22.8k
{
3480
22.8k
  expressionS exp;
3481
22.8k
  fragS *start;
3482
22.8k
  addressT start_off;
3483
22.8k
  offsetT frag_off;
3484
3485
#ifdef md_flush_pending_output
3486
  md_flush_pending_output ();
3487
#endif
3488
3489
22.8k
  SKIP_WHITESPACE ();
3490
22.8k
  expression (&exp);
3491
22.8k
  demand_empty_rest_of_line ();
3492
3493
22.8k
  start = frag_now;
3494
22.8k
  start_off = frag_now_fix ();
3495
22.8k
  do
3496
635k
    {
3497
#ifdef md_emit_single_noop
3498
      md_emit_single_noop;
3499
#else
3500
635k
      char *nop;
3501
3502
635k
#ifndef md_single_noop_insn
3503
635k
#define md_single_noop_insn "nop"
3504
635k
#endif
3505
      /* md_assemble might modify its argument, so
3506
   we must pass it a string that is writable.  */
3507
635k
      if (asprintf (&nop, "%s", md_single_noop_insn) < 0)
3508
0
  as_fatal ("%s", xstrerror (errno));
3509
3510
      /* Some targets assume that they can update input_line_pointer
3511
   inside md_assemble, and, worse, that they can leave it
3512
   assigned to the string pointer that was provided as an
3513
   argument.  So preserve ilp here.  */
3514
635k
      char *saved_ilp = input_line_pointer;
3515
635k
      md_assemble (nop);
3516
635k
      input_line_pointer = saved_ilp;
3517
635k
      free (nop);
3518
635k
#endif
3519
#ifdef md_flush_pending_output
3520
      md_flush_pending_output ();
3521
#endif
3522
635k
    } while (exp.X_op == O_constant
3523
635k
       && exp.X_add_number > 0
3524
635k
       && frag_offset_ignore_align_p (start, frag_now, &frag_off)
3525
635k
       && frag_off + frag_now_fix () < start_off + exp.X_add_number);
3526
22.8k
}
3527
3528
void
3529
s_nops (int ignore ATTRIBUTE_UNUSED)
3530
8
{
3531
8
  expressionS exp;
3532
8
  expressionS val;
3533
3534
#ifdef md_flush_pending_output
3535
  md_flush_pending_output ();
3536
#endif
3537
3538
8
  SKIP_WHITESPACE ();
3539
8
  expression (&exp);
3540
  /* Note - this expression is tested for an absolute value in
3541
     write.c:relax_segment().  */
3542
3543
8
  SKIP_WHITESPACE ();
3544
8
  if (*input_line_pointer == ',')
3545
8
    {
3546
8
      ++input_line_pointer;
3547
8
      expression (&val);
3548
8
    }
3549
0
  else
3550
0
    {
3551
0
      val.X_op = O_constant;
3552
0
      val.X_add_number = 0;
3553
0
    }
3554
3555
8
  if (val.X_op != O_constant)
3556
0
    {
3557
0
      as_bad (_("unsupported variable nop control in .nops directive"));
3558
0
      val.X_op = O_constant;
3559
0
      val.X_add_number = 0;
3560
0
    }
3561
8
  else if (val.X_add_number < 0)
3562
0
    {
3563
0
      as_warn (_("negative nop control byte, ignored"));
3564
0
      val.X_add_number = 0;
3565
0
    }
3566
3567
8
  demand_empty_rest_of_line ();
3568
3569
8
  if (need_pass_2)
3570
    /* Ignore this directive if we are going to perform a second pass.  */
3571
0
    return;
3572
3573
  /* Store the no-op instruction control byte in the first byte of frag.  */
3574
8
  char *p;
3575
8
  symbolS *sym = make_expr_symbol (&exp);
3576
8
  p = frag_var (rs_space_nop, 1, 1, (relax_substateT) 0,
3577
8
    sym, (offsetT) 0, (char *) 0);
3578
8
  *p = val.X_add_number;
3579
8
}
3580
3581
/* Obtain the size of a floating point number, given a type.  */
3582
3583
static int
3584
float_length (int float_type, int *pad_p)
3585
595
{
3586
595
  int length, pad = 0;
3587
3588
595
  switch (float_type)
3589
595
    {
3590
0
    case 'b':
3591
0
    case 'B':
3592
0
    case 'h':
3593
0
    case 'H':
3594
0
      length = 2;
3595
0
      break;
3596
3597
446
    case 'f':
3598
446
    case 'F':
3599
446
    case 's':
3600
446
    case 'S':
3601
446
      length = 4;
3602
446
      break;
3603
3604
149
    case 'd':
3605
149
    case 'D':
3606
149
    case 'r':
3607
149
    case 'R':
3608
149
      length = 8;
3609
149
      break;
3610
3611
0
    case 'x':
3612
0
    case 'X':
3613
0
#ifdef X_PRECISION
3614
0
      length = X_PRECISION * sizeof (LITTLENUM_TYPE);
3615
0
      pad = X_PRECISION_PAD * sizeof (LITTLENUM_TYPE);
3616
0
      if (!length)
3617
0
#endif
3618
0
  length = 12;
3619
0
      break;
3620
3621
0
    case 'p':
3622
0
    case 'P':
3623
0
#ifdef P_PRECISION
3624
0
      length = P_PRECISION * sizeof (LITTLENUM_TYPE);
3625
0
      pad = P_PRECISION_PAD * sizeof (LITTLENUM_TYPE);
3626
0
      if (!length)
3627
0
#endif
3628
0
  length = 12;
3629
0
      break;
3630
3631
0
    default:
3632
0
      as_bad (_("unknown floating type '%c'"), float_type);
3633
0
      length = -1;
3634
0
      break;
3635
595
    }
3636
3637
595
  if (pad_p)
3638
595
    *pad_p = pad;
3639
3640
595
  return length;
3641
595
}
3642
3643
static int
3644
parse_one_float (int float_type, char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT])
3645
11.5k
{
3646
11.5k
  int length;
3647
3648
11.5k
  SKIP_WHITESPACE ();
3649
3650
  /* Skip any 0{letter} that may be present.  Don't even check if the
3651
     letter is legal.  Someone may invent a "z" format and this routine
3652
     has no use for such information. Lusers beware: you get
3653
     diagnostics if your input is ill-conditioned.  */
3654
11.5k
  if (input_line_pointer[0] == '0'
3655
11.5k
      && ISALPHA (input_line_pointer[1]))
3656
91
    input_line_pointer += 2;
3657
3658
  /* Accept :xxxx, where the x's are hex digits, for a floating point
3659
     with the exact digits specified.  */
3660
11.5k
  if (input_line_pointer[0] == ':')
3661
595
    {
3662
595
      ++input_line_pointer;
3663
595
      length = hex_float (float_type, temp);
3664
595
      if (length < 0)
3665
155
  {
3666
155
    ignore_rest_of_line ();
3667
155
    return length;
3668
155
  }
3669
595
    }
3670
10.9k
  else
3671
10.9k
    {
3672
10.9k
      const char *err;
3673
3674
10.9k
      err = md_atof (float_type, temp, &length);
3675
10.9k
      know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3676
10.9k
      know (err != NULL || length > 0);
3677
10.9k
      if (err)
3678
0
  {
3679
0
    as_bad (_("bad floating literal: %s"), err);
3680
0
    ignore_rest_of_line ();
3681
0
    return -1;
3682
0
  }
3683
10.9k
    }
3684
3685
11.3k
  return length;
3686
11.5k
}
3687
3688
/* This is like s_space, but the value is a floating point number with
3689
   the given precision.  This is for the MRI dcb.s pseudo-op and
3690
   friends.  */
3691
3692
void
3693
s_float_space (int float_type)
3694
0
{
3695
0
  offsetT count;
3696
0
  int flen;
3697
0
  char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3698
0
  char *stop = NULL;
3699
0
  char stopc = 0;
3700
3701
0
#ifdef md_cons_align
3702
0
  md_cons_align (1);
3703
0
#endif
3704
3705
0
  if (flag_mri)
3706
0
    stop = mri_comment_field (&stopc);
3707
3708
0
  count = get_absolute_expression ();
3709
3710
0
  SKIP_WHITESPACE ();
3711
0
  if (*input_line_pointer != ',')
3712
0
    {
3713
0
      int pad;
3714
3715
0
      flen = float_length (float_type, &pad);
3716
0
      if (flen >= 0)
3717
0
  memset (temp, 0, flen += pad);
3718
0
    }
3719
0
  else
3720
0
    {
3721
0
      ++input_line_pointer;
3722
3723
0
      flen = parse_one_float (float_type, temp);
3724
0
    }
3725
3726
0
  if (flen < 0)
3727
0
    {
3728
0
      if (flag_mri)
3729
0
  mri_comment_end (stop, stopc);
3730
0
      return;
3731
0
    }
3732
3733
0
  while (--count >= 0)
3734
0
    {
3735
0
      char *p;
3736
3737
0
      p = frag_more (flen);
3738
0
      memcpy (p, temp, (unsigned int) flen);
3739
0
    }
3740
3741
0
  demand_empty_rest_of_line ();
3742
3743
0
  if (flag_mri)
3744
0
    mri_comment_end (stop, stopc);
3745
0
}
3746
3747
/* Handle the .struct pseudo-op, as found in MIPS assemblers.  */
3748
3749
void
3750
s_struct (int ignore ATTRIBUTE_UNUSED)
3751
3.25k
{
3752
3.25k
  char *stop = NULL;
3753
3.25k
  char stopc = 0;
3754
3755
3.25k
  if (flag_mri)
3756
1.05k
    stop = mri_comment_field (&stopc);
3757
3.25k
  abs_section_offset = get_absolute_expression ();
3758
3.25k
#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3759
  /* The ELF backend needs to know that we are changing sections, so
3760
     that .previous works correctly. */
3761
3.25k
  if (IS_ELF)
3762
3.25k
    obj_elf_section_change_hook ();
3763
3.25k
#endif
3764
3.25k
  subseg_set (absolute_section, 0);
3765
3.25k
  demand_empty_rest_of_line ();
3766
3.25k
  if (flag_mri)
3767
1.05k
    mri_comment_end (stop, stopc);
3768
3.25k
}
3769
3770
void
3771
s_text (int ignore ATTRIBUTE_UNUSED)
3772
1.84k
{
3773
1.84k
  int temp;
3774
3775
1.84k
  temp = get_absolute_expression ();
3776
1.84k
  subseg_set (text_section, (subsegT) temp);
3777
1.84k
  demand_empty_rest_of_line ();
3778
1.84k
}
3779
3780
/* .weakref x, y sets x as an alias to y that, as long as y is not
3781
   referenced directly, will cause y to become a weak symbol.  */
3782
void
3783
s_weakref (int ignore ATTRIBUTE_UNUSED)
3784
75
{
3785
75
  char *name;
3786
75
  symbolS *symbolP;
3787
75
  symbolS *symbolP2;
3788
75
  expressionS exp;
3789
3790
75
  if ((name = read_symbol_name ()) == NULL)
3791
0
    return;
3792
3793
75
  symbolP = symbol_find_or_make (name);
3794
3795
75
  if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3796
0
    {
3797
0
      if (!S_IS_VOLATILE (symbolP))
3798
0
  {
3799
0
    as_bad (_("symbol `%s' is already defined"), name);
3800
0
    goto err_out;
3801
0
  }
3802
0
      symbolP = symbol_clone (symbolP, 1);
3803
0
      S_CLEAR_VOLATILE (symbolP);
3804
0
    }
3805
3806
75
  SKIP_WHITESPACE ();
3807
3808
75
  if (*input_line_pointer != ',')
3809
30
    {
3810
30
      as_bad (_("expected comma after \"%s\""), name);
3811
30
      goto err_out;
3812
30
    }
3813
3814
45
  input_line_pointer++;
3815
3816
45
  SKIP_WHITESPACE ();
3817
45
  free (name);
3818
3819
45
  if ((name = read_symbol_name ()) == NULL)
3820
45
    return;
3821
3822
0
  if ((symbolP2 = symbol_find_noref (name, 1)) == NULL
3823
0
      && (symbolP2 = md_undefined_symbol (name)) == NULL)
3824
0
    {
3825
0
      symbolP2 = symbol_find_or_make (name);
3826
0
      S_SET_WEAKREFD (symbolP2);
3827
0
    }
3828
0
  else
3829
0
    {
3830
0
      symbolS *symp = symbolP2;
3831
3832
0
      while (S_IS_WEAKREFR (symp) && symp != symbolP)
3833
0
  {
3834
0
    expressionS *expP = symbol_get_value_expression (symp);
3835
3836
0
    gas_assert (expP->X_op == O_symbol
3837
0
      && expP->X_add_number == 0);
3838
0
    symp = expP->X_add_symbol;
3839
0
  }
3840
0
      if (symp == symbolP)
3841
0
  {
3842
0
    char *loop;
3843
3844
0
    loop = concat (S_GET_NAME (symbolP),
3845
0
       " => ", S_GET_NAME (symbolP2), (const char *) NULL);
3846
3847
0
    symp = symbolP2;
3848
0
    while (symp != symbolP)
3849
0
      {
3850
0
        char *old_loop = loop;
3851
3852
0
        symp = symbol_get_value_expression (symp)->X_add_symbol;
3853
0
        loop = concat (loop, " => ", S_GET_NAME (symp),
3854
0
           (const char *) NULL);
3855
0
        free (old_loop);
3856
0
      }
3857
3858
0
    as_bad (_("%s: would close weakref loop: %s"),
3859
0
      S_GET_NAME (symbolP), loop);
3860
3861
0
    free (loop);
3862
0
    free (name);
3863
0
    ignore_rest_of_line ();
3864
0
    return;
3865
0
  }
3866
3867
      /* Short-circuiting instead of just checking here might speed
3868
   things up a tiny little bit, but loop error messages would
3869
   miss intermediate links.  */
3870
      /* symbolP2 = symp; */
3871
0
    }
3872
3873
0
  memset (&exp, 0, sizeof (exp));
3874
0
  exp.X_op = O_symbol;
3875
0
  exp.X_add_symbol = symbolP2;
3876
3877
0
  S_SET_SEGMENT (symbolP, undefined_section);
3878
0
  symbol_set_value_expression (symbolP, &exp);
3879
0
  symbol_set_frag (symbolP, &zero_address_frag);
3880
0
  S_SET_WEAKREFR (symbolP);
3881
3882
0
  demand_empty_rest_of_line ();
3883
0
  free (name);
3884
0
  return;
3885
3886
30
 err_out:
3887
30
  ignore_rest_of_line ();
3888
30
  free (name);
3889
30
  return;
3890
0
}
3891

3892
3893
/* Verify that we are at the end of a line.  If not, issue an error and
3894
   skip to EOL.  This function may leave input_line_pointer one past
3895
   buffer_limit, so should not be called from places that may
3896
   dereference input_line_pointer unconditionally.  Note that when the
3897
   gas parser is switched to handling a string (where buffer_limit
3898
   should be the size of the string excluding the NUL terminator) this
3899
   will be one past the NUL; is_end_of_line(0) returns true.  */
3900
3901
void
3902
demand_empty_rest_of_line (void)
3903
1.76M
{
3904
1.76M
  SKIP_WHITESPACE ();
3905
1.76M
  if (input_line_pointer > buffer_limit)
3906
0
    return;
3907
1.76M
  if (is_end_of_line[(unsigned char) *input_line_pointer])
3908
327k
    input_line_pointer++;
3909
1.44M
  else
3910
1.44M
    {
3911
1.44M
      if (ISPRINT (*input_line_pointer))
3912
1.00M
  as_bad (_("junk at end of line, first unrecognized character is `%c'"),
3913
1.00M
     *input_line_pointer);
3914
433k
      else
3915
433k
  as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
3916
433k
     *input_line_pointer);
3917
1.44M
      ignore_rest_of_line ();
3918
1.44M
    }
3919
  /* Return pointing just after end-of-line.  */
3920
1.76M
}
3921
3922
/* Silently advance to the end of line.  Use this after already having
3923
   issued an error about something bad.  Like demand_empty_rest_of_line,
3924
   this function may leave input_line_pointer one after buffer_limit;
3925
   Don't call it from within expression parsing code in an attempt to
3926
   silence further errors.  */
3927
3928
void
3929
ignore_rest_of_line (void)
3930
1.81M
{
3931
28.0M
  while (input_line_pointer <= buffer_limit)
3932
28.0M
    if (is_end_of_line[(unsigned char) *input_line_pointer++])
3933
1.81M
      break;
3934
  /* Return pointing just after end-of-line.  */
3935
1.81M
}
3936
3937
/* Sets frag for given symbol to zero_address_frag, except when the
3938
   symbol frag is already set to a dummy listing frag.  */
3939
3940
static void
3941
set_zero_frag (symbolS *symbolP)
3942
105k
{
3943
105k
  if (symbol_get_frag (symbolP)->fr_type != rs_dummy)
3944
104k
    symbol_set_frag (symbolP, &zero_address_frag);
3945
105k
}
3946
3947
/* In:  Pointer to a symbol.
3948
  Input_line_pointer->expression.
3949
3950
   Out: Input_line_pointer->just after any whitespace after expression.
3951
  Tried to set symbol to value of expression.
3952
  Will change symbols type, value, and frag;  */
3953
3954
void
3955
pseudo_set (symbolS *symbolP)
3956
142k
{
3957
142k
  expressionS exp;
3958
142k
  segT seg;
3959
3960
142k
  know (symbolP);   /* NULL pointer is logic error.  */
3961
3962
142k
  if (!S_IS_FORWARD_REF (symbolP))
3963
132k
    (void) expression (&exp);
3964
9.57k
  else
3965
9.57k
    (void) deferred_expression (&exp);
3966
3967
142k
  if (exp.X_op == O_illegal)
3968
0
    as_bad (_("illegal expression"));
3969
142k
  else if (exp.X_op == O_absent)
3970
2.84k
    as_bad (_("missing expression"));
3971
139k
  else if (exp.X_op == O_big)
3972
5.12k
    {
3973
5.12k
      if (exp.X_add_number > 0)
3974
151
  as_bad (_("bignum invalid"));
3975
4.97k
      else
3976
4.97k
  as_bad (_("floating point number invalid"));
3977
5.12k
    }
3978
134k
  else if (exp.X_op == O_subtract
3979
134k
     && !S_IS_FORWARD_REF (symbolP)
3980
134k
     && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3981
134k
     && (symbol_get_frag (exp.X_add_symbol)
3982
78
         == symbol_get_frag (exp.X_op_symbol)))
3983
10
    {
3984
10
      exp.X_op = O_constant;
3985
10
      exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3986
10
        - S_GET_VALUE (exp.X_op_symbol));
3987
10
    }
3988
3989
142k
  if (symbol_section_p (symbolP))
3990
0
    {
3991
0
      as_bad ("attempt to set value of section symbol");
3992
0
      return;
3993
0
    }
3994
3995
142k
  switch (exp.X_op)
3996
142k
    {
3997
0
    case O_illegal:
3998
2.84k
    case O_absent:
3999
7.97k
    case O_big:
4000
7.97k
      exp.X_add_number = 0;
4001
      /* Fall through.  */
4002
57.5k
    case O_constant:
4003
57.5k
      S_SET_SEGMENT (symbolP, absolute_section);
4004
57.5k
      S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
4005
57.5k
      set_zero_frag (symbolP);
4006
57.5k
      break;
4007
4008
899
    case O_register:
4009
899
#ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
4010
899
      if (S_IS_EXTERNAL (symbolP))
4011
0
  {
4012
0
    as_bad ("can't equate global symbol `%s' with register name",
4013
0
      S_GET_NAME (symbolP));
4014
0
    return;
4015
0
  }
4016
899
#endif
4017
      /* Make sure symbol_equated_p() recognizes the symbol as an equate.  */
4018
899
      exp.X_add_symbol = make_expr_symbol (&exp);
4019
899
      exp.X_add_number = 0;
4020
899
      exp.X_op = O_symbol;
4021
899
      symbol_set_value_expression (symbolP, &exp);
4022
899
      S_SET_SEGMENT (symbolP, reg_section);
4023
899
      set_zero_frag (symbolP);
4024
899
      break;
4025
4026
62.5k
    case O_symbol:
4027
62.5k
      seg = S_GET_SEGMENT (exp.X_add_symbol);
4028
      /* For x=undef+const, create an expression symbol.
4029
   For x=x+const, just update x except when x is an undefined symbol
4030
   For x=defined+const, evaluate x.  */
4031
62.5k
      if (symbolP == exp.X_add_symbol
4032
62.5k
    && (seg != undefined_section
4033
6.27k
        || !symbol_constant_p (symbolP)))
4034
6.23k
  {
4035
6.23k
    *symbol_X_add_number (symbolP) += exp.X_add_number;
4036
6.23k
    break;
4037
6.23k
  }
4038
56.3k
      else if (!S_IS_FORWARD_REF (symbolP) && seg != undefined_section)
4039
30.4k
  {
4040
30.4k
    symbolS *s = exp.X_add_symbol;
4041
4042
30.4k
    if (S_IS_COMMON (s))
4043
3.42k
      as_bad (_("`%s' can't be equated to common symbol `%s'"),
4044
3.42k
        S_GET_NAME (symbolP), S_GET_NAME (s));
4045
4046
30.4k
    S_SET_SEGMENT (symbolP, seg);
4047
30.4k
    S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (s));
4048
30.4k
    symbol_set_frag (symbolP, symbol_get_frag (s));
4049
30.4k
    copy_symbol_attributes (symbolP, s);
4050
30.4k
    break;
4051
30.4k
  }
4052
25.8k
      S_SET_SEGMENT (symbolP, undefined_section);
4053
25.8k
      symbol_set_value_expression (symbolP, &exp);
4054
25.8k
      copy_symbol_attributes (symbolP, exp.X_add_symbol);
4055
25.8k
      set_zero_frag (symbolP);
4056
25.8k
      break;
4057
4058
21.4k
    default:
4059
      /* The value is some complex expression.  */
4060
21.4k
      S_SET_SEGMENT (symbolP, expr_section);
4061
21.4k
      symbol_set_value_expression (symbolP, &exp);
4062
21.4k
      set_zero_frag (symbolP);
4063
21.4k
      break;
4064
142k
    }
4065
142k
}
4066

4067
/*      cons()
4068
4069
   CONStruct more frag of .bytes, or .words etc.
4070
   Should need_pass_2 be 1 then emit no frag(s).
4071
   This understands EXPRESSIONS.
4072
4073
   Bug (?)
4074
4075
   This has a split personality. We use expression() to read the
4076
   value. We can detect if the value won't fit in a byte or word.
4077
   But we can't detect if expression() discarded significant digits
4078
   in the case of a long. Not worth the crocks required to fix it.  */
4079
4080
/* Select a parser for cons expressions.  */
4081
4082
/* Some targets need to parse the expression in various fancy ways.
4083
   You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
4084
   (for example, the HPPA does this).  Otherwise, you can define
4085
   REPEAT_CONS_EXPRESSIONS to permit repeat counts.  If none of these
4086
   are defined, which is the normal case, then only simple expressions
4087
   are permitted.  */
4088
4089
#ifdef TC_M68K
4090
static void
4091
parse_mri_cons (expressionS *exp, unsigned int nbytes);
4092
#endif
4093
4094
#ifndef TC_PARSE_CONS_EXPRESSION
4095
#ifdef REPEAT_CONS_EXPRESSIONS
4096
#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
4097
  (parse_repeat_cons (EXP, NBYTES), TC_PARSE_CONS_RETURN_NONE)
4098
static void
4099
parse_repeat_cons (expressionS *exp, unsigned int nbytes);
4100
#endif
4101
4102
/* If we haven't gotten one yet, just call expression.  */
4103
#ifndef TC_PARSE_CONS_EXPRESSION
4104
#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) \
4105
  (expression (EXP), TC_PARSE_CONS_RETURN_NONE)
4106
#endif
4107
#endif
4108
4109
void
4110
do_parse_cons_expression (expressionS *exp,
4111
        int nbytes ATTRIBUTE_UNUSED)
4112
0
{
4113
0
  (void) TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4114
0
}
4115
4116
4117
/* Worker to do .byte etc statements.
4118
   Clobbers input_line_pointer and checks end-of-line.  */
4119
4120
static void
4121
cons_worker (int nbytes,  /* 1=.byte, 2=.word, 4=.long.  */
4122
       int rva)
4123
24.3k
{
4124
24.3k
  int c;
4125
24.3k
  expressionS exp;
4126
24.3k
  char *stop = NULL;
4127
24.3k
  char stopc = 0;
4128
4129
#ifdef md_flush_pending_output
4130
  md_flush_pending_output ();
4131
#endif
4132
4133
24.3k
  if (flag_mri)
4134
3.30k
    stop = mri_comment_field (&stopc);
4135
4136
24.3k
  if (is_it_end_of_statement ())
4137
228
    {
4138
228
      demand_empty_rest_of_line ();
4139
228
      if (flag_mri)
4140
12
  mri_comment_end (stop, stopc);
4141
228
      return;
4142
228
    }
4143
4144
24.1k
  if (nbytes == 0)
4145
0
    nbytes = TC_ADDRESS_BYTES ();
4146
4147
24.1k
#ifdef md_cons_align
4148
24.1k
  md_cons_align (nbytes);
4149
24.1k
#endif
4150
4151
24.1k
  c = 0;
4152
24.1k
  do
4153
66.7k
    {
4154
66.7k
      TC_PARSE_CONS_RETURN_TYPE ret = TC_PARSE_CONS_RETURN_NONE;
4155
#ifdef TC_CONS_FIX_CHECK
4156
      fixS **cur_fix = &frchain_now->fix_tail;
4157
4158
      if (*cur_fix != NULL)
4159
  cur_fix = &(*cur_fix)->fx_next;
4160
#endif
4161
4162
#ifdef TC_M68K
4163
      if (flag_m68k_mri)
4164
  parse_mri_cons (&exp, (unsigned int) nbytes);
4165
      else
4166
#endif
4167
66.7k
  {
4168
#if 0
4169
    if (*input_line_pointer == '"')
4170
      {
4171
        as_bad (_("unexpected `\"' in expression"));
4172
        ignore_rest_of_line ();
4173
        return;
4174
      }
4175
#endif
4176
66.7k
    ret = TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
4177
66.7k
  }
4178
4179
66.7k
      if (rva)
4180
0
  {
4181
0
    if (exp.X_op == O_symbol)
4182
0
      exp.X_op = O_symbol_rva;
4183
0
    else
4184
0
      as_fatal (_("rva without symbol"));
4185
0
  }
4186
66.7k
      emit_expr_with_reloc (&exp, (unsigned int) nbytes, ret);
4187
#ifdef TC_CONS_FIX_CHECK
4188
      TC_CONS_FIX_CHECK (&exp, nbytes, *cur_fix);
4189
#endif
4190
66.7k
      ++c;
4191
66.7k
    }
4192
66.7k
  while (*input_line_pointer++ == ',');
4193
4194
  /* In MRI mode, after an odd number of bytes, we must align to an
4195
     even word boundary, unless the next instruction is a dc.b, ds.b
4196
     or dcb.b.  */
4197
24.1k
  if (flag_mri && nbytes == 1 && (c & 1) != 0)
4198
0
    mri_pending_align = 1;
4199
4200
24.1k
  input_line_pointer--;   /* Put terminator back into stream.  */
4201
4202
24.1k
  demand_empty_rest_of_line ();
4203
4204
24.1k
  if (flag_mri)
4205
3.29k
    mri_comment_end (stop, stopc);
4206
4207
  /* Disallow hand-crafting instructions using .byte.  FIXME - what about
4208
     .word, .long etc ?  */
4209
24.1k
  if (flag_synth_cfi && frchain_now && frchain_now->frch_ginsn_data
4210
24.1k
      && nbytes == 1)
4211
0
    as_bad (_("SCFI: hand-crafting instructions not supported"));
4212
24.1k
}
4213
4214
void
4215
cons (int size)
4216
24.3k
{
4217
24.3k
  cons_worker (size, 0);
4218
24.3k
}
4219
4220
void
4221
s_rva (int size)
4222
0
{
4223
0
  cons_worker (size, 1);
4224
0
}
4225
4226
/* .reloc offset, reloc_name, symbol+addend.  */
4227
4228
static void
4229
s_reloc (int ignore ATTRIBUTE_UNUSED)
4230
76
{
4231
76
  char *stop = NULL;
4232
76
  char stopc = 0;
4233
76
  expressionS exp;
4234
76
  char *r_name;
4235
76
  int c;
4236
76
  struct reloc_list *reloc;
4237
76
  struct _bfd_rel { const char * name; bfd_reloc_code_real_type code; };
4238
76
  static const struct _bfd_rel bfd_relocs[] =
4239
76
  {
4240
76
    { "NONE", BFD_RELOC_NONE },
4241
76
    { "8",  BFD_RELOC_8 },
4242
76
    { "16", BFD_RELOC_16 },
4243
76
    { "32", BFD_RELOC_32 },
4244
76
    { "64", BFD_RELOC_64 }
4245
76
  };
4246
4247
76
  reloc = XNEW (struct reloc_list);
4248
4249
76
  if (flag_mri)
4250
14
    stop = mri_comment_field (&stopc);
4251
4252
76
  expression (&exp);
4253
76
  switch (exp.X_op)
4254
76
    {
4255
0
    case O_illegal:
4256
12
    case O_absent:
4257
12
    case O_big:
4258
12
    case O_register:
4259
12
      as_bad (_("missing or bad offset expression"));
4260
12
      goto err_out;
4261
61
    case O_constant:
4262
61
      exp.X_add_symbol = section_symbol (now_seg);
4263
      /* Mark the section symbol used in relocation so that it will be
4264
   included in the symbol table.  */
4265
61
      symbol_mark_used_in_reloc (exp.X_add_symbol);
4266
61
      exp.X_op = O_symbol;
4267
      /* Fallthru */
4268
64
    case O_symbol:
4269
64
      if (exp.X_add_number == 0)
4270
8
  {
4271
8
    reloc->u.a.offset_sym = exp.X_add_symbol;
4272
8
    break;
4273
8
  }
4274
      /* Fallthru */
4275
56
    default:
4276
56
      reloc->u.a.offset_sym = make_expr_symbol (&exp);
4277
56
      break;
4278
76
    }
4279
4280
64
  SKIP_WHITESPACE ();
4281
64
  if (*input_line_pointer != ',')
4282
56
    {
4283
56
      as_bad (_("missing reloc type"));
4284
56
      goto err_out;
4285
56
    }
4286
4287
8
  ++input_line_pointer;
4288
8
  SKIP_WHITESPACE ();
4289
8
  c = get_symbol_name (& r_name);
4290
8
  if (strncasecmp (r_name, "BFD_RELOC_", 10) == 0)
4291
0
    {
4292
0
      unsigned int i;
4293
4294
0
      for (reloc->u.a.howto = NULL, i = 0; i < ARRAY_SIZE (bfd_relocs); i++)
4295
0
  if (strcasecmp (r_name + 10, bfd_relocs[i].name) == 0)
4296
0
    {
4297
0
      reloc->u.a.howto = bfd_reloc_type_lookup (stdoutput,
4298
0
                  bfd_relocs[i].code);
4299
0
      break;
4300
0
    }
4301
0
    }
4302
8
  else
4303
8
    reloc->u.a.howto = bfd_reloc_name_lookup (stdoutput, r_name);
4304
8
  *input_line_pointer = c;
4305
8
  if (reloc->u.a.howto == NULL)
4306
8
    {
4307
8
      as_bad (_("unrecognized reloc type"));
4308
8
      goto err_out;
4309
8
    }
4310
4311
0
  exp.X_op = O_absent;
4312
0
  SKIP_WHITESPACE_AFTER_NAME ();
4313
0
  if (*input_line_pointer == ',')
4314
0
    {
4315
0
      ++input_line_pointer;
4316
0
      expression (&exp);
4317
0
    }
4318
0
  switch (exp.X_op)
4319
0
    {
4320
0
    case O_illegal:
4321
0
    case O_big:
4322
0
    case O_register:
4323
0
      as_bad (_("bad reloc expression"));
4324
76
    err_out:
4325
76
      ignore_rest_of_line ();
4326
76
      free (reloc);
4327
76
      if (flag_mri)
4328
14
  mri_comment_end (stop, stopc);
4329
76
      return;
4330
0
    case O_absent:
4331
0
      reloc->u.a.sym = NULL;
4332
0
      reloc->u.a.addend = 0;
4333
0
      break;
4334
0
    case O_constant:
4335
0
      reloc->u.a.sym = NULL;
4336
0
      reloc->u.a.addend = exp.X_add_number;
4337
0
      break;
4338
0
    case O_symbol:
4339
0
      reloc->u.a.sym = exp.X_add_symbol;
4340
0
      reloc->u.a.addend = exp.X_add_number;
4341
0
      break;
4342
0
    default:
4343
0
      reloc->u.a.sym = make_expr_symbol (&exp);
4344
0
      reloc->u.a.addend = 0;
4345
0
      break;
4346
0
    }
4347
4348
0
  reloc->file = as_where (&reloc->line);
4349
0
  reloc->next = reloc_list;
4350
0
  reloc_list = reloc;
4351
4352
0
  demand_empty_rest_of_line ();
4353
0
  if (flag_mri)
4354
0
    mri_comment_end (stop, stopc);
4355
0
}
4356
4357
/* Put the contents of expression EXP into the object file using
4358
   NBYTES bytes.  If need_pass_2 is 1, this does nothing.  */
4359
4360
void
4361
emit_expr (expressionS *exp, unsigned int nbytes)
4362
110k
{
4363
110k
  emit_expr_with_reloc (exp, nbytes, TC_PARSE_CONS_RETURN_NONE);
4364
110k
}
4365
4366
void
4367
emit_expr_with_reloc (expressionS *exp,
4368
          unsigned int nbytes,
4369
          TC_PARSE_CONS_RETURN_TYPE reloc)
4370
177k
{
4371
177k
  operatorT op;
4372
177k
  char *p;
4373
177k
  valueT extra_digit = 0;
4374
4375
  /* Don't do anything if we are going to make another pass.  */
4376
177k
  if (need_pass_2)
4377
0
    return;
4378
4379
177k
  frag_grow (nbytes);
4380
177k
  dot_value = frag_now_fix ();
4381
177k
  dot_frag = frag_now;
4382
4383
177k
#ifndef NO_LISTING
4384
177k
#ifdef OBJ_ELF
4385
  /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
4386
     appear as a four byte positive constant in the .line section,
4387
     followed by a 2 byte 0xffff.  Look for that case here.  */
4388
177k
  if (strcmp (segment_name (now_seg), ".line") != 0)
4389
177k
    dwarf_line = -1;
4390
0
  else if (dwarf_line >= 0
4391
0
     && nbytes == 2
4392
0
     && exp->X_op == O_constant
4393
0
     && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
4394
0
    listing_source_line ((unsigned int) dwarf_line);
4395
0
  else if (nbytes == 4
4396
0
     && exp->X_op == O_constant
4397
0
     && exp->X_add_number >= 0)
4398
0
    dwarf_line = exp->X_add_number;
4399
0
  else
4400
0
    dwarf_line = -1;
4401
4402
  /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
4403
     appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
4404
     AT_sibling (0x12) followed by a four byte address of the sibling
4405
     followed by a 2 byte AT_name (0x38) followed by the name of the
4406
     file.  We look for that case here.  */
4407
177k
  if (strcmp (segment_name (now_seg), ".debug") != 0)
4408
177k
    dwarf_file = 0;
4409
0
  else if (dwarf_file == 0
4410
0
     && nbytes == 2
4411
0
     && exp->X_op == O_constant
4412
0
     && exp->X_add_number == 0x11)
4413
0
    dwarf_file = 1;
4414
0
  else if (dwarf_file == 1
4415
0
     && nbytes == 2
4416
0
     && exp->X_op == O_constant
4417
0
     && exp->X_add_number == 0x12)
4418
0
    dwarf_file = 2;
4419
0
  else if (dwarf_file == 2
4420
0
     && nbytes == 4)
4421
0
    dwarf_file = 3;
4422
0
  else if (dwarf_file == 3
4423
0
     && nbytes == 2
4424
0
     && exp->X_op == O_constant
4425
0
     && exp->X_add_number == 0x38)
4426
0
    dwarf_file = 4;
4427
0
  else
4428
0
    dwarf_file = 0;
4429
4430
  /* The variable dwarf_file_string tells stringer that the string
4431
     may be the name of the source file.  */
4432
177k
  if (dwarf_file == 4)
4433
0
    dwarf_file_string = 1;
4434
177k
  else
4435
177k
    dwarf_file_string = 0;
4436
177k
#endif
4437
177k
#endif
4438
4439
177k
  if (check_eh_frame (exp, &nbytes))
4440
0
    return;
4441
4442
177k
  op = exp->X_op;
4443
4444
  /* Handle a negative bignum.  */
4445
177k
  if (op == O_uminus
4446
177k
      && exp->X_add_number == 0
4447
177k
      && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
4448
177k
      && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
4449
0
    {
4450
0
      int i;
4451
0
      unsigned long carry;
4452
4453
0
      exp = symbol_get_value_expression (exp->X_add_symbol);
4454
4455
      /* Negate the bignum: one's complement each digit and add 1.  */
4456
0
      carry = 1;
4457
0
      for (i = 0; i < exp->X_add_number; i++)
4458
0
  {
4459
0
    unsigned long next;
4460
4461
0
    next = (((~(generic_bignum[i] & LITTLENUM_MASK))
4462
0
       & LITTLENUM_MASK)
4463
0
      + carry);
4464
0
    generic_bignum[i] = next & LITTLENUM_MASK;
4465
0
    carry = next >> LITTLENUM_NUMBER_OF_BITS;
4466
0
  }
4467
4468
      /* We can ignore any carry out, because it will be handled by
4469
   extra_digit if it is needed.  */
4470
4471
0
      extra_digit = (valueT) -1;
4472
0
      op = O_big;
4473
0
    }
4474
4475
177k
  if (op == O_absent || op == O_illegal)
4476
619
    {
4477
619
      as_warn (_("zero assumed for missing expression"));
4478
619
      exp->X_add_number = 0;
4479
619
      op = O_constant;
4480
619
    }
4481
176k
  else if (op == O_big && exp->X_add_number <= 0)
4482
56
    {
4483
56
      as_bad (_("floating point number invalid"));
4484
56
      exp->X_add_number = 0;
4485
56
      op = O_constant;
4486
56
    }
4487
176k
  else if (op == O_register)
4488
0
    {
4489
0
      as_warn (_("register value used as expression"));
4490
0
      op = O_constant;
4491
0
    }
4492
4493
  /* Allow `.word 0' in the absolute section.  */
4494
177k
  if (now_seg == absolute_section)
4495
24.3k
    {
4496
24.3k
      if (op != O_constant || exp->X_add_number != 0)
4497
23.5k
  as_bad (_("attempt to store value in absolute section"));
4498
24.3k
      abs_section_offset += nbytes;
4499
24.3k
      return;
4500
24.3k
    }
4501
4502
  /* Allow `.word 0' in BSS style sections.  */
4503
152k
  if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
4504
1.62k
    as_bad (_("attempt to store non-zero value in section `%s'"),
4505
1.62k
      segment_name (now_seg));
4506
4507
152k
  p = frag_more ((int) nbytes);
4508
4509
152k
  if (reloc != TC_PARSE_CONS_RETURN_NONE)
4510
1.84k
    {
4511
1.84k
      emit_expr_fix (exp, nbytes, frag_now, p, reloc);
4512
1.84k
      return;
4513
1.84k
    }
4514
4515
#ifndef WORKING_DOT_WORD
4516
  /* If we have the difference of two symbols in a word, save it on
4517
     the broken_words list.  See the code in write.c.  */
4518
  if (op == O_subtract && nbytes == 2)
4519
    {
4520
      struct broken_word *x;
4521
4522
      x = XNEW (struct broken_word);
4523
      x->next_broken_word = broken_words;
4524
      broken_words = x;
4525
      x->seg = now_seg;
4526
      x->subseg = now_subseg;
4527
      x->frag = frag_now;
4528
      x->word_goes_here = p;
4529
      x->dispfrag = 0;
4530
      x->add = exp->X_add_symbol;
4531
      x->sub = exp->X_op_symbol;
4532
      x->addnum = exp->X_add_number;
4533
      x->added = 0;
4534
      x->use_jump = 0;
4535
      new_broken_words++;
4536
      return;
4537
    }
4538
#endif
4539
4540
  /* If we have an integer, but the number of bytes is too large to
4541
     pass to md_number_to_chars, handle it as a bignum.  */
4542
150k
  if (op == O_constant && nbytes > sizeof (valueT))
4543
52
    {
4544
52
      extra_digit = exp->X_unsigned ? 0 : -1;
4545
52
      convert_to_bignum (exp, !exp->X_unsigned);
4546
52
      op = O_big;
4547
52
    }
4548
4549
150k
  if (op == O_constant)
4550
4.35k
    {
4551
4.35k
      valueT get;
4552
4.35k
      valueT use;
4553
4.35k
      valueT mask;
4554
4.35k
      valueT unmask;
4555
4556
      /* JF << of >= number of bits in the object is undefined.  In
4557
   particular SPARC (Sun 4) has problems.  */
4558
4.35k
      if (nbytes >= sizeof (valueT))
4559
0
  {
4560
0
    know (nbytes == sizeof (valueT));
4561
0
    mask = 0;
4562
0
  }
4563
4.35k
      else
4564
4.35k
  {
4565
    /* Don't store these bits.  */
4566
4.35k
    mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
4567
4.35k
  }
4568
4569
4.35k
      unmask = ~mask;   /* Do store these bits.  */
4570
4571
#ifdef NEVER
4572
      "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
4573
      mask = ~(unmask >> 1);  /* Includes sign bit now.  */
4574
#endif
4575
4576
4.35k
      get = exp->X_add_number;
4577
4.35k
      use = get & unmask;
4578
4.35k
      if ((get & mask) != 0 && (-get & mask) != 0)
4579
1.06k
  {
4580
    /* Leading bits contain both 0s & 1s.  */
4581
1.06k
    as_warn (_("value 0x%" PRIx64 " truncated to 0x%" PRIx64),
4582
1.06k
       (uint64_t) get, (uint64_t) use);
4583
1.06k
  }
4584
      /* Put bytes in right order.  */
4585
4.35k
      md_number_to_chars (p, use, (int) nbytes);
4586
4.35k
    }
4587
146k
  else if (op == O_big)
4588
439
    {
4589
439
      unsigned int size;
4590
439
      LITTLENUM_TYPE *nums;
4591
4592
439
      size = exp->X_add_number * CHARS_PER_LITTLENUM;
4593
439
      if (nbytes < size)
4594
385
  {
4595
385
    int i = nbytes / CHARS_PER_LITTLENUM;
4596
4597
385
    if (i != 0)
4598
379
      {
4599
379
        LITTLENUM_TYPE sign = 0;
4600
379
        if ((generic_bignum[--i]
4601
379
       & (1 << (LITTLENUM_NUMBER_OF_BITS - 1))) != 0)
4602
342
    sign = ~(LITTLENUM_TYPE) 0;
4603
4604
400
        while (++i < exp->X_add_number)
4605
399
    if (generic_bignum[i] != sign)
4606
378
      break;
4607
379
      }
4608
6
    else if (nbytes == 1)
4609
6
      {
4610
        /* We have nbytes == 1 and CHARS_PER_LITTLENUM == 2 (probably).
4611
     Check that bits 8.. of generic_bignum[0] match bit 7
4612
     and that they match all of generic_bignum[1..exp->X_add_number].  */
4613
6
        LITTLENUM_TYPE sign = (generic_bignum[0] & (1 << 7)) ? -1 : 0;
4614
6
        LITTLENUM_TYPE himask = LITTLENUM_MASK & ~ 0xFF;
4615
4616
6
        if ((generic_bignum[0] & himask) == (sign & himask))
4617
3
    {
4618
3
      while (++i < exp->X_add_number)
4619
3
        if (generic_bignum[i] != sign)
4620
3
          break;
4621
3
    }
4622
6
      }
4623
4624
385
    if (i < exp->X_add_number)
4625
384
      as_warn (ngettext ("bignum truncated to %d byte",
4626
384
             "bignum truncated to %d bytes",
4627
384
             nbytes),
4628
384
         nbytes);
4629
385
    size = nbytes;
4630
385
  }
4631
4632
439
      if (nbytes == 1)
4633
6
  {
4634
6
    md_number_to_chars (p, (valueT) generic_bignum[0], 1);
4635
6
    return;
4636
6
  }
4637
433
      know (nbytes % CHARS_PER_LITTLENUM == 0);
4638
4639
433
      if (target_big_endian)
4640
0
  {
4641
0
    while (nbytes > size)
4642
0
      {
4643
0
        md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4644
0
        nbytes -= CHARS_PER_LITTLENUM;
4645
0
        p += CHARS_PER_LITTLENUM;
4646
0
      }
4647
4648
0
    nums = generic_bignum + size / CHARS_PER_LITTLENUM;
4649
0
    while (size >= CHARS_PER_LITTLENUM)
4650
0
      {
4651
0
        --nums;
4652
0
        md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
4653
0
        size -= CHARS_PER_LITTLENUM;
4654
0
        p += CHARS_PER_LITTLENUM;
4655
0
      }
4656
0
  }
4657
433
      else
4658
433
  {
4659
433
    nums = generic_bignum;
4660
1.44k
    while (size >= CHARS_PER_LITTLENUM)
4661
1.01k
      {
4662
1.01k
        md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
4663
1.01k
        ++nums;
4664
1.01k
        size -= CHARS_PER_LITTLENUM;
4665
1.01k
        p += CHARS_PER_LITTLENUM;
4666
1.01k
        nbytes -= CHARS_PER_LITTLENUM;
4667
1.01k
      }
4668
4669
608
    while (nbytes >= CHARS_PER_LITTLENUM)
4670
175
      {
4671
175
        md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4672
175
        nbytes -= CHARS_PER_LITTLENUM;
4673
175
        p += CHARS_PER_LITTLENUM;
4674
175
      }
4675
433
  }
4676
433
    }
4677
146k
  else
4678
146k
    emit_expr_fix (exp, nbytes, frag_now, p, TC_PARSE_CONS_RETURN_NONE);
4679
150k
}
4680
4681
void
4682
emit_expr_fix (expressionS *exp, unsigned int nbytes, fragS *frag, char *p,
4683
         TC_PARSE_CONS_RETURN_TYPE r ATTRIBUTE_UNUSED)
4684
147k
{
4685
147k
  int offset = 0;
4686
147k
  unsigned int size = nbytes;
4687
4688
147k
  memset (p, 0, size);
4689
4690
  /* Generate a fixS to record the symbol value.  */
4691
4692
147k
#ifdef TC_CONS_FIX_NEW
4693
147k
  TC_CONS_FIX_NEW (frag, p - frag->fr_literal + offset, size, exp, r);
4694
#else
4695
  if (r != TC_PARSE_CONS_RETURN_NONE)
4696
    {
4697
      reloc_howto_type *reloc_howto;
4698
4699
      reloc_howto = bfd_reloc_type_lookup (stdoutput, r);
4700
      size = bfd_get_reloc_size (reloc_howto);
4701
4702
      if (size > nbytes)
4703
  {
4704
    as_bad (ngettext ("%s relocations do not fit in %u byte",
4705
          "%s relocations do not fit in %u bytes",
4706
          nbytes),
4707
      reloc_howto->name, nbytes);
4708
    return;
4709
  }
4710
      else if (target_big_endian)
4711
  offset = nbytes - size;
4712
    }
4713
  else
4714
    switch (size)
4715
      {
4716
      case 1:
4717
  r = BFD_RELOC_8;
4718
  break;
4719
      case 2:
4720
  r = BFD_RELOC_16;
4721
  break;
4722
      case 3:
4723
  r = BFD_RELOC_24;
4724
  break;
4725
      case 4:
4726
  r = BFD_RELOC_32;
4727
  break;
4728
      case 8:
4729
  r = BFD_RELOC_64;
4730
  break;
4731
      default:
4732
  as_bad (_("unsupported BFD relocation size %u"), size);
4733
  return;
4734
      }
4735
  fix_new_exp (frag, p - frag->fr_literal + offset, size,
4736
         exp, 0, r);
4737
#endif
4738
147k
}
4739

4740
/* Handle an MRI style string expression.  */
4741
4742
#ifdef TC_M68K
4743
static void
4744
parse_mri_cons (expressionS *exp, unsigned int nbytes)
4745
{
4746
  if (*input_line_pointer != '\''
4747
      && (input_line_pointer[1] != '\''
4748
    || (*input_line_pointer != 'A'
4749
        && *input_line_pointer != 'E')))
4750
    (void) TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4751
  else
4752
    {
4753
      unsigned int scan;
4754
      unsigned int result = 0;
4755
4756
      /* An MRI style string.  Cut into as many bytes as will fit into
4757
   a nbyte chunk, left justify if necessary, and separate with
4758
   commas so we can try again later.  */
4759
      if (*input_line_pointer == 'A')
4760
  ++input_line_pointer;
4761
      else if (*input_line_pointer == 'E')
4762
  {
4763
    as_bad (_("EBCDIC constants are not supported"));
4764
    ++input_line_pointer;
4765
  }
4766
4767
      input_line_pointer++;
4768
      for (scan = 0; scan < nbytes; scan++)
4769
  {
4770
    if (*input_line_pointer == '\'')
4771
      {
4772
        if (input_line_pointer[1] == '\'')
4773
    {
4774
      input_line_pointer++;
4775
    }
4776
        else
4777
    break;
4778
      }
4779
    result = (result << 8) | (*input_line_pointer++);
4780
  }
4781
4782
      /* Left justify.  */
4783
      while (scan < nbytes)
4784
  {
4785
    result <<= 8;
4786
    scan++;
4787
  }
4788
4789
      /* Create correct expression.  */
4790
      exp->X_op = O_constant;
4791
      exp->X_add_number = result;
4792
4793
      /* Fake it so that we can read the next char too.  */
4794
      if (input_line_pointer[0] != '\'' ||
4795
    (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
4796
  {
4797
    input_line_pointer -= 2;
4798
    input_line_pointer[0] = ',';
4799
    input_line_pointer[1] = '\'';
4800
  }
4801
      else
4802
  input_line_pointer++;
4803
    }
4804
}
4805
#endif /* TC_M68K */
4806

4807
#ifdef REPEAT_CONS_EXPRESSIONS
4808
4809
/* Parse a repeat expression for cons.  This is used by the MIPS
4810
   assembler.  The format is NUMBER:COUNT; NUMBER appears in the
4811
   object file COUNT times.
4812
4813
   To use this for a target, define REPEAT_CONS_EXPRESSIONS.  */
4814
4815
static void
4816
parse_repeat_cons (expressionS *exp, unsigned int nbytes)
4817
{
4818
  expressionS count;
4819
  int i;
4820
4821
  expression (exp);
4822
4823
  if (*input_line_pointer != ':')
4824
    {
4825
      /* No repeat count.  */
4826
      return;
4827
    }
4828
4829
  ++input_line_pointer;
4830
  expression (&count);
4831
  if (count.X_op != O_constant
4832
      || count.X_add_number <= 0)
4833
    {
4834
      as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4835
      return;
4836
    }
4837
4838
  /* The cons function is going to output this expression once.  So we
4839
     output it count - 1 times.  */
4840
  for (i = count.X_add_number - 1; i > 0; i--)
4841
    emit_expr (exp, nbytes);
4842
}
4843
4844
#endif /* REPEAT_CONS_EXPRESSIONS */
4845

4846
/* Parse a floating point number represented as a hex constant.  This
4847
   permits users to specify the exact bits they want in the floating
4848
   point number.  */
4849
4850
static int
4851
hex_float (int float_type, char *bytes)
4852
595
{
4853
595
  int pad, length = float_length (float_type, &pad);
4854
595
  int i;
4855
4856
595
  if (length < 0)
4857
0
    return length;
4858
4859
  /* It would be nice if we could go through expression to parse the
4860
     hex constant, but if we get a bignum it's a pain to sort it into
4861
     the buffer correctly.  */
4862
595
  i = 0;
4863
1.90k
  while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
4864
1.46k
    {
4865
1.46k
      int d;
4866
4867
      /* The MRI assembler accepts arbitrary underscores strewn about
4868
   through the hex constant, so we ignore them as well.  */
4869
1.46k
      if (*input_line_pointer == '_')
4870
3
  {
4871
3
    ++input_line_pointer;
4872
3
    continue;
4873
3
  }
4874
4875
1.46k
      if (i >= length)
4876
155
  {
4877
155
    as_warn (_("floating point constant too large"));
4878
155
    return -1;
4879
155
  }
4880
1.30k
      d = hex_value (*input_line_pointer) << 4;
4881
1.30k
      ++input_line_pointer;
4882
1.30k
      while (*input_line_pointer == '_')
4883
0
  ++input_line_pointer;
4884
1.30k
      if (hex_p (*input_line_pointer))
4885
1.25k
  {
4886
1.25k
    d += hex_value (*input_line_pointer);
4887
1.25k
    ++input_line_pointer;
4888
1.25k
  }
4889
1.30k
      if (target_big_endian)
4890
0
  bytes[i] = d;
4891
1.30k
      else
4892
1.30k
  bytes[length - i - 1] = d;
4893
1.30k
      ++i;
4894
1.30k
    }
4895
4896
440
  if (i < length)
4897
400
    {
4898
400
      if (target_big_endian)
4899
0
  memset (bytes + i, 0, length - i);
4900
400
      else
4901
400
  memset (bytes, 0, length - i);
4902
400
    }
4903
4904
440
  memset (bytes + length, 0, pad);
4905
4906
440
  return length + pad;
4907
595
}
4908
4909
/*      float_cons()
4910
4911
   CONStruct some more frag chars of .floats .ffloats etc.
4912
   Makes 0 or more new frags.
4913
   If need_pass_2 == 1, no frags are emitted.
4914
   This understands only floating literals, not expressions. Sorry.
4915
4916
   A floating constant is defined by atof_generic(), except it is preceded
4917
   by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4918
   reading, I decided to be incompatible. This always tries to give you
4919
   rounded bits to the precision of the pseudo-op. Former AS did premature
4920
   truncation, restored noisy bits instead of trailing 0s AND gave you
4921
   a choice of 2 flavours of noise according to which of 2 floating-point
4922
   scanners you directed AS to use.
4923
4924
   In:  input_line_pointer->whitespace before, or '0' of flonum.  */
4925
4926
void
4927
float_cons (/* Clobbers input_line-pointer, checks end-of-line.  */
4928
      int float_type  /* 'f':.ffloat ... 'F':.float ...  */)
4929
20.2k
{
4930
20.2k
  char *p;
4931
20.2k
  int length;     /* Number of chars in an object.  */
4932
20.2k
  char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4933
4934
20.2k
  if (is_it_end_of_statement ())
4935
9.32k
    {
4936
9.32k
      demand_empty_rest_of_line ();
4937
9.32k
      return;
4938
9.32k
    }
4939
4940
10.9k
  if (now_seg == absolute_section)
4941
2.69k
    {
4942
2.69k
      as_bad (_("attempt to store float in absolute section"));
4943
2.69k
      ignore_rest_of_line ();
4944
2.69k
      return;
4945
2.69k
    }
4946
4947
8.25k
  if (in_bss ())
4948
433
    {
4949
433
      as_bad (_("attempt to store float in section `%s'"),
4950
433
        segment_name (now_seg));
4951
433
      ignore_rest_of_line ();
4952
433
      return;
4953
433
    }
4954
4955
#ifdef md_flush_pending_output
4956
  md_flush_pending_output ();
4957
#endif
4958
4959
7.82k
#ifdef md_cons_align
4960
7.82k
  md_cons_align (1);
4961
7.82k
#endif
4962
4963
7.82k
  do
4964
11.5k
    {
4965
11.5k
      length = parse_one_float (float_type, temp);
4966
11.5k
      if (length < 0)
4967
155
  return;
4968
4969
11.3k
      if (!need_pass_2)
4970
11.3k
  {
4971
11.3k
    int count;
4972
4973
11.3k
    count = 1;
4974
4975
#ifdef REPEAT_CONS_EXPRESSIONS
4976
    if (*input_line_pointer == ':')
4977
      {
4978
        expressionS count_exp;
4979
4980
        ++input_line_pointer;
4981
        expression (&count_exp);
4982
4983
        if (count_exp.X_op != O_constant
4984
      || count_exp.X_add_number <= 0)
4985
    as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4986
        else
4987
    count = count_exp.X_add_number;
4988
      }
4989
#endif
4990
4991
22.7k
    while (--count >= 0)
4992
11.3k
      {
4993
11.3k
        p = frag_more (length);
4994
11.3k
        memcpy (p, temp, (unsigned int) length);
4995
11.3k
      }
4996
11.3k
  }
4997
11.3k
      SKIP_WHITESPACE ();
4998
11.3k
    }
4999
11.3k
  while (*input_line_pointer++ == ',');
5000
5001
  /* Put terminator back into stream.  */
5002
7.66k
  --input_line_pointer;
5003
7.66k
  demand_empty_rest_of_line ();
5004
7.66k
}
5005

5006
/* LEB128 Encoding.
5007
5008
   Note - we are using the DWARF standard's definition of LEB128 encoding
5009
   where each 7-bit value is a stored in a byte, *not* an octet.  This
5010
   means that on targets where a byte contains multiple octets there is
5011
   a *huge waste of space*.  (This also means that we do not have to
5012
   have special versions of these functions for when OCTETS_PER_BYTE_POWER
5013
   is non-zero).
5014
5015
   If the 7-bit values were to be packed into N-bit bytes (where N > 8)
5016
   we would then have to consider whether multiple, successive LEB128
5017
   values should be packed into the bytes without padding (bad idea) or
5018
   whether each LEB128 number is padded out to a whole number of bytes.
5019
   Plus you have to decide on the endianness of packing octets into a
5020
   byte.  */
5021
5022
/* Return the size of a LEB128 value in bytes.  */
5023
5024
static inline unsigned int
5025
sizeof_sleb128 (offsetT value)
5026
3.21k
{
5027
3.21k
  int size = 0;
5028
3.21k
  unsigned byte;
5029
5030
3.21k
  do
5031
3.53k
    {
5032
3.53k
      byte = (value & 0x7f);
5033
      /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5034
   Fortunately, we can structure things so that the extra work reduces
5035
   to a noop on systems that do things "properly".  */
5036
3.53k
      value = (value >> 7) | ~(-(offsetT)1 >> 7);
5037
3.53k
      size += 1;
5038
3.53k
    }
5039
3.53k
  while (!(((value == 0) && ((byte & 0x40) == 0))
5040
3.53k
     || ((value == -1) && ((byte & 0x40) != 0))));
5041
5042
3.21k
  return size;
5043
3.21k
}
5044
5045
static inline unsigned int
5046
sizeof_uleb128 (valueT value)
5047
35.5k
{
5048
35.5k
  int size = 0;
5049
5050
35.5k
  do
5051
49.4k
    {
5052
49.4k
      value >>= 7;
5053
49.4k
      size += 1;
5054
49.4k
    }
5055
49.4k
  while (value != 0);
5056
5057
35.5k
  return size;
5058
35.5k
}
5059
5060
unsigned int
5061
sizeof_leb128 (valueT value, int sign)
5062
38.6k
{
5063
38.6k
  if (sign)
5064
3.21k
    return sizeof_sleb128 ((offsetT) value);
5065
35.3k
  else
5066
35.3k
    return sizeof_uleb128 (value);
5067
38.6k
}
5068
5069
/* Output a LEB128 value.  Returns the number of bytes used.  */
5070
5071
static inline unsigned int
5072
output_sleb128 (char *p, offsetT value)
5073
2.06k
{
5074
2.06k
  char *orig = p;
5075
2.06k
  int more;
5076
5077
2.06k
  do
5078
2.33k
    {
5079
2.33k
      unsigned byte = (value & 0x7f);
5080
5081
      /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5082
   Fortunately, we can structure things so that the extra work reduces
5083
   to a noop on systems that do things "properly".  */
5084
2.33k
      value = (value >> 7) | ~(-(offsetT)1 >> 7);
5085
5086
2.33k
      more = !((((value == 0) && ((byte & 0x40) == 0))
5087
2.33k
    || ((value == -1) && ((byte & 0x40) != 0))));
5088
2.33k
      if (more)
5089
272
  byte |= 0x80;
5090
5091
2.33k
      *p++ = byte;
5092
2.33k
    }
5093
2.33k
  while (more);
5094
5095
2.06k
  return p - orig;
5096
2.06k
}
5097
5098
static inline unsigned int
5099
output_uleb128 (char *p, valueT value)
5100
34.0k
{
5101
34.0k
  char *orig = p;
5102
5103
34.0k
  do
5104
34.4k
    {
5105
34.4k
      unsigned byte = (value & 0x7f);
5106
5107
34.4k
      value >>= 7;
5108
34.4k
      if (value != 0)
5109
  /* More bytes to follow.  */
5110
376
  byte |= 0x80;
5111
5112
34.4k
      *p++ = byte;
5113
34.4k
    }
5114
34.4k
  while (value != 0);
5115
5116
34.0k
  return p - orig;
5117
34.0k
}
5118
5119
unsigned int
5120
output_leb128 (char *p, valueT value, int sign)
5121
36.0k
{
5122
36.0k
  if (sign)
5123
2.06k
    return output_sleb128 (p, (offsetT) value);
5124
34.0k
  else
5125
34.0k
    return output_uleb128 (p, value);
5126
36.0k
}
5127
5128
/* Do the same for bignums.  We combine sizeof with output here in that
5129
   we don't output for NULL values of P.  It isn't really as critical as
5130
   for "normal" values that this be streamlined.  Returns the number of
5131
   bytes used.  */
5132
5133
static inline unsigned int
5134
output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size)
5135
0
{
5136
0
  char *orig = p;
5137
0
  valueT val = 0;
5138
0
  int loaded = 0;
5139
0
  unsigned byte;
5140
5141
  /* Strip leading sign extensions off the bignum.  */
5142
0
  while (size > 1
5143
0
   && bignum[size - 1] == LITTLENUM_MASK
5144
0
   && bignum[size - 2] > LITTLENUM_MASK / 2)
5145
0
    size--;
5146
5147
0
  do
5148
0
    {
5149
      /* OR in the next part of the littlenum.  */
5150
0
      val |= (*bignum << loaded);
5151
0
      loaded += LITTLENUM_NUMBER_OF_BITS;
5152
0
      size--;
5153
0
      bignum++;
5154
5155
      /* Add bytes until there are less than 7 bits left in VAL
5156
   or until every non-sign bit has been written.  */
5157
0
      do
5158
0
  {
5159
0
    byte = val & 0x7f;
5160
0
    loaded -= 7;
5161
0
    val >>= 7;
5162
0
    if (size > 0
5163
0
        || val != ((byte & 0x40) == 0 ? 0 : ((valueT) 1 << loaded) - 1))
5164
0
      byte |= 0x80;
5165
5166
0
    if (orig)
5167
0
      *p = byte;
5168
0
    p++;
5169
0
  }
5170
0
      while ((byte & 0x80) != 0 && loaded >= 7);
5171
0
    }
5172
0
  while (size > 0);
5173
5174
  /* Mop up any left-over bits (of which there will be less than 7).  */
5175
0
  if ((byte & 0x80) != 0)
5176
0
    {
5177
      /* Sign-extend VAL.  */
5178
0
      if (val & (1 << (loaded - 1)))
5179
0
  val |= ~0U << loaded;
5180
0
      if (orig)
5181
0
  *p = val & 0x7f;
5182
0
      p++;
5183
0
    }
5184
5185
0
  return p - orig;
5186
0
}
5187
5188
static inline unsigned int
5189
output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size)
5190
0
{
5191
0
  char *orig = p;
5192
0
  valueT val = 0;
5193
0
  int loaded = 0;
5194
0
  unsigned byte;
5195
5196
  /* Strip leading zeros off the bignum.  */
5197
  /* XXX: Is this needed?  */
5198
0
  while (size > 0 && bignum[size - 1] == 0)
5199
0
    size--;
5200
5201
0
  do
5202
0
    {
5203
0
      if (loaded < 7 && size > 0)
5204
0
  {
5205
0
    val |= (*bignum << loaded);
5206
0
    loaded += 8 * CHARS_PER_LITTLENUM;
5207
0
    size--;
5208
0
    bignum++;
5209
0
  }
5210
5211
0
      byte = val & 0x7f;
5212
0
      loaded -= 7;
5213
0
      val >>= 7;
5214
5215
0
      if (size > 0 || val)
5216
0
  byte |= 0x80;
5217
5218
0
      if (orig)
5219
0
  *p = byte;
5220
0
      p++;
5221
0
    }
5222
0
  while (byte & 0x80);
5223
5224
0
  return p - orig;
5225
0
}
5226
5227
static unsigned int
5228
output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size, int sign)
5229
0
{
5230
0
  if (sign)
5231
0
    return output_big_sleb128 (p, bignum, size);
5232
0
  else
5233
0
    return output_big_uleb128 (p, bignum, size);
5234
0
}
5235
5236
/* Generate the appropriate fragments for a given expression to emit a
5237
   leb128 value.  SIGN is 1 for sleb, 0 for uleb.  */
5238
5239
void
5240
emit_leb128_expr (expressionS *exp, int sign)
5241
1.06k
{
5242
1.06k
  operatorT op = exp->X_op;
5243
1.06k
  unsigned int nbytes;
5244
5245
1.06k
  if (op == O_absent || op == O_illegal)
5246
480
    {
5247
480
      as_warn (_("zero assumed for missing expression"));
5248
480
      exp->X_add_number = 0;
5249
480
      op = O_constant;
5250
480
    }
5251
586
  else if (op == O_big && exp->X_add_number <= 0)
5252
0
    {
5253
0
      as_bad (_("floating point number invalid"));
5254
0
      exp->X_add_number = 0;
5255
0
      op = O_constant;
5256
0
    }
5257
586
  else if (op == O_register)
5258
0
    {
5259
0
      as_warn (_("register value used as expression"));
5260
0
      op = O_constant;
5261
0
    }
5262
586
  else if (op == O_constant
5263
586
     && sign
5264
586
     && (exp->X_add_number < 0) == !exp->X_extrabit)
5265
0
    {
5266
      /* We're outputting a signed leb128 and the sign of X_add_number
5267
   doesn't reflect the sign of the original value.  Convert EXP
5268
   to a correctly-extended bignum instead.  */
5269
0
      convert_to_bignum (exp, exp->X_extrabit);
5270
0
      op = O_big;
5271
0
    }
5272
5273
1.06k
  if (now_seg == absolute_section)
5274
884
    {
5275
884
      if (op != O_constant || exp->X_add_number != 0)
5276
438
  as_bad (_("attempt to store value in absolute section"));
5277
884
      abs_section_offset++;
5278
884
      return;
5279
884
    }
5280
5281
182
  if ((op != O_constant || exp->X_add_number != 0) && in_bss ())
5282
4
    as_bad (_("attempt to store non-zero value in section `%s'"),
5283
4
      segment_name (now_seg));
5284
5285
  /* Let check_eh_frame know that data is being emitted.  nbytes == -1 is
5286
     a signal that this is leb128 data.  It shouldn't optimize this away.  */
5287
182
  nbytes = (unsigned int) -1;
5288
182
  if (check_eh_frame (exp, &nbytes))
5289
0
    abort ();
5290
5291
  /* Let the backend know that subsequent data may be byte aligned.  */
5292
182
#ifdef md_cons_align
5293
182
  md_cons_align (1);
5294
182
#endif
5295
5296
182
  if (op == O_constant)
5297
46
    {
5298
      /* If we've got a constant, emit the thing directly right now.  */
5299
5300
46
      valueT value = exp->X_add_number;
5301
46
      unsigned int size;
5302
46
      char *p;
5303
5304
46
      size = sizeof_leb128 (value, sign);
5305
46
      p = frag_more (size);
5306
46
      if (output_leb128 (p, value, sign) > size)
5307
0
  abort ();
5308
46
    }
5309
136
  else if (op == O_big)
5310
0
    {
5311
      /* O_big is a different sort of constant.  */
5312
0
      int nbr_digits = exp->X_add_number;
5313
0
      unsigned int size;
5314
0
      char *p;
5315
5316
      /* If the leading littenum is 0xffff, prepend a 0 to avoid confusion with
5317
   a signed number.  Unary operators like - or ~ always extend the
5318
   bignum to its largest size.  */
5319
0
      if (exp->X_unsigned
5320
0
    && nbr_digits < SIZE_OF_LARGE_NUMBER
5321
0
    && generic_bignum[nbr_digits - 1] == LITTLENUM_MASK)
5322
0
  generic_bignum[nbr_digits++] = 0;
5323
5324
0
      size = output_big_leb128 (NULL, generic_bignum, nbr_digits, sign);
5325
0
      p = frag_more (size);
5326
0
      if (output_big_leb128 (p, generic_bignum, nbr_digits, sign) > size)
5327
0
  abort ();
5328
0
    }
5329
136
  else
5330
136
    {
5331
      /* Otherwise, we have to create a variable sized fragment and
5332
   resolve things later.  */
5333
5334
136
      frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
5335
136
    make_expr_symbol (exp), 0, (char *) NULL);
5336
136
    }
5337
182
}
5338
5339
/* Parse the .sleb128 and .uleb128 pseudos.  */
5340
5341
void
5342
s_leb128 (int sign)
5343
450
{
5344
450
  expressionS exp;
5345
5346
#ifdef md_flush_pending_output
5347
  md_flush_pending_output ();
5348
#endif
5349
5350
450
  do
5351
966
    {
5352
966
      expression (&exp);
5353
966
      emit_leb128_expr (&exp, sign);
5354
966
    }
5355
966
  while (*input_line_pointer++ == ',');
5356
5357
450
  input_line_pointer--;
5358
450
  demand_empty_rest_of_line ();
5359
450
}
5360

5361
static void
5362
stringer_append_char (int c, int bitsize)
5363
1.04M
{
5364
1.04M
  if (c && in_bss ())
5365
131
    as_bad (_("attempt to store non-empty string in section `%s'"),
5366
131
      segment_name (now_seg));
5367
5368
1.04M
  if (!target_big_endian)
5369
1.04M
    FRAG_APPEND_1_CHAR (c);
5370
5371
1.04M
  switch (bitsize)
5372
1.04M
    {
5373
0
    case 64:
5374
0
      FRAG_APPEND_1_CHAR (0);
5375
0
      FRAG_APPEND_1_CHAR (0);
5376
0
      FRAG_APPEND_1_CHAR (0);
5377
0
      FRAG_APPEND_1_CHAR (0);
5378
      /* Fall through.  */
5379
0
    case 32:
5380
0
      FRAG_APPEND_1_CHAR (0);
5381
0
      FRAG_APPEND_1_CHAR (0);
5382
      /* Fall through.  */
5383
0
    case 16:
5384
0
      FRAG_APPEND_1_CHAR (0);
5385
      /* Fall through.  */
5386
1.04M
    case 8:
5387
1.04M
      break;
5388
0
    default:
5389
      /* Called with invalid bitsize argument.  */
5390
0
      abort ();
5391
0
      break;
5392
1.04M
    }
5393
1.04M
  if (target_big_endian)
5394
0
    FRAG_APPEND_1_CHAR (c);
5395
1.04M
}
5396
5397
/* Worker to do .ascii etc statements.
5398
   Reads 0 or more ',' separated, double-quoted strings.
5399
   Caller should have checked need_pass_2 is FALSE because we don't
5400
   check it.
5401
   Checks for end-of-line.
5402
   BITS_APPENDZERO says how many bits are in a target char.
5403
   The bottom bit is set if a NUL char should be appended to the strings.  */
5404
5405
void
5406
stringer (int bits_appendzero)
5407
5.74k
{
5408
5.74k
  const int bitsize = bits_appendzero & ~7;
5409
5.74k
  const int append_zero = bits_appendzero & 1;
5410
5.74k
  unsigned int c;
5411
5.74k
#if !defined(NO_LISTING) && defined (OBJ_ELF)
5412
5.74k
  char *start;
5413
5.74k
#endif
5414
5415
#ifdef md_flush_pending_output
5416
  md_flush_pending_output ();
5417
#endif
5418
5419
5.74k
#ifdef md_cons_align
5420
5.74k
  md_cons_align (1);
5421
5.74k
#endif
5422
5423
  /* If we have been switched into the abs_section then we
5424
     will not have an obstack onto which we can hang strings.  */
5425
5.74k
  if (now_seg == absolute_section)
5426
2.27k
    {
5427
2.27k
      as_bad (_("strings must be placed into a section"));
5428
2.27k
      ignore_rest_of_line ();
5429
2.27k
      return;
5430
2.27k
    }
5431
5432
  /* The following awkward logic is to parse ZERO or more strings,
5433
     comma separated. Recall a string expression includes spaces
5434
     before the opening '\"' and spaces after the closing '\"'.
5435
     We fake a leading ',' if there is (supposed to be)
5436
     a 1st, expression. We keep demanding expressions for each ','.  */
5437
3.46k
  if (is_it_end_of_statement ())
5438
6
    {
5439
6
      c = 0;      /* Skip loop.  */
5440
6
      ++input_line_pointer; /* Compensate for end of loop.  */
5441
6
    }
5442
3.45k
  else
5443
3.45k
    {
5444
3.45k
      c = ',';      /* Do loop.  */
5445
3.45k
    }
5446
5447
19.9k
  while (c == ',' || c == '<' || c == '"')
5448
16.5k
    {
5449
16.5k
      SKIP_WHITESPACE ();
5450
16.5k
      switch (*input_line_pointer)
5451
16.5k
  {
5452
16.1k
  case '\"':
5453
16.1k
    ++input_line_pointer; /*->1st char of string.  */
5454
16.1k
#if !defined(NO_LISTING) && defined (OBJ_ELF)
5455
16.1k
    start = input_line_pointer;
5456
16.1k
#endif
5457
5458
1.05M
    while (is_a_char (c = next_char_of_string ()))
5459
1.04M
      stringer_append_char (c, bitsize);
5460
5461
    /* Treat "a" "b" as "ab".  Even if we are appending zeros.  */
5462
16.1k
    SKIP_ALL_WHITESPACE ();
5463
16.1k
    if (*input_line_pointer == '"')
5464
13.0k
      break;
5465
5466
3.04k
    if (append_zero)
5467
3.04k
      stringer_append_char (0, bitsize);
5468
5469
3.04k
#if !defined(NO_LISTING) && defined (OBJ_ELF)
5470
    /* In ELF, when gcc is emitting DWARF 1 debugging output, it
5471
       will emit .string with a filename in the .debug section
5472
       after a sequence of constants.  See the comment in
5473
       emit_expr for the sequence.  emit_expr will set
5474
       dwarf_file_string to non-zero if this string might be a
5475
       source file name.  */
5476
3.04k
    if (strcmp (segment_name (now_seg), ".debug") != 0)
5477
3.04k
      dwarf_file_string = 0;
5478
0
    else if (dwarf_file_string)
5479
0
      {
5480
0
        c = input_line_pointer[-1];
5481
0
        input_line_pointer[-1] = '\0';
5482
0
        listing_source_file (start);
5483
0
        input_line_pointer[-1] = c;
5484
0
      }
5485
3.04k
#endif
5486
5487
3.04k
    break;
5488
0
  case '<':
5489
0
    input_line_pointer++;
5490
0
    c = get_single_number ();
5491
0
    stringer_append_char (c, bitsize);
5492
0
    if (*input_line_pointer != '>')
5493
0
      {
5494
0
        as_bad (_("expected <nn>"));
5495
0
        ignore_rest_of_line ();
5496
0
        return;
5497
0
      }
5498
0
    input_line_pointer++;
5499
0
    break;
5500
41
  case ',':
5501
41
    input_line_pointer++;
5502
41
    break;
5503
16.5k
  }
5504
16.5k
      SKIP_WHITESPACE ();
5505
16.5k
      c = *input_line_pointer;
5506
16.5k
    }
5507
5508
3.46k
  demand_empty_rest_of_line ();
5509
3.46k
}
5510

5511
/* FIXME-SOMEDAY: I had trouble here on characters with the
5512
    high bits set.  We'll probably also have trouble with
5513
    multibyte chars, wide chars, etc.  Also be careful about
5514
    returning values bigger than 1 byte.  xoxorich.  */
5515
5516
unsigned int
5517
next_char_of_string (void)
5518
10.2M
{
5519
10.2M
  unsigned int c;
5520
5521
10.2M
  c = *input_line_pointer++ & CHAR_MASK;
5522
10.2M
  switch (c)
5523
10.2M
    {
5524
16.7k
    case 0:
5525
      /* PR 20902: Do not advance past the end of the buffer.  */
5526
16.7k
      -- input_line_pointer;
5527
16.7k
      c = NOT_A_CHAR;
5528
16.7k
      break;
5529
5530
60.7k
    case '\"':
5531
60.7k
      c = NOT_A_CHAR;
5532
60.7k
      break;
5533
5534
193k
    case '\n':
5535
193k
      as_warn (_("unterminated string; newline inserted"));
5536
193k
      bump_line_counters ();
5537
193k
      break;
5538
5539
116k
    case '\\':
5540
116k
      if (!TC_STRING_ESCAPES)
5541
0
  break;
5542
116k
      switch (c = *input_line_pointer++ & CHAR_MASK)
5543
116k
  {
5544
0
  case 'b':
5545
0
    c = '\b';
5546
0
    break;
5547
5548
1.31k
  case 'f':
5549
1.31k
    c = '\f';
5550
1.31k
    break;
5551
5552
2.91k
  case 'n':
5553
2.91k
    c = '\n';
5554
2.91k
    break;
5555
5556
25.1k
  case 'r':
5557
25.1k
    c = '\r';
5558
25.1k
    break;
5559
5560
16.1k
  case 't':
5561
16.1k
    c = '\t';
5562
16.1k
    break;
5563
5564
230
  case 'v':
5565
230
    c = '\013';
5566
230
    break;
5567
5568
5.54k
  case '\\':
5569
5.96k
  case '"':
5570
5.96k
    break;    /* As itself.  */
5571
5572
1.83k
  case '0':
5573
1.98k
  case '1':
5574
2.75k
  case '2':
5575
3.07k
  case '3':
5576
3.45k
  case '4':
5577
3.59k
  case '5':
5578
3.61k
  case '6':
5579
3.64k
  case '7':
5580
3.74k
  case '8':
5581
4.15k
  case '9':
5582
4.15k
    {
5583
4.15k
      unsigned number;
5584
4.15k
      int i;
5585
5586
4.15k
      for (i = 0, number = 0;
5587
9.77k
     ISDIGIT (c) && i < 3;
5588
5.61k
     c = *input_line_pointer++, i++)
5589
5.61k
        {
5590
5.61k
    number = number * 8 + c - '0';
5591
5.61k
        }
5592
5593
4.15k
      c = number & CHAR_MASK;
5594
4.15k
    }
5595
4.15k
    --input_line_pointer;
5596
4.15k
    break;
5597
5598
120
  case 'x':
5599
554
  case 'X':
5600
554
    {
5601
554
      unsigned number;
5602
5603
554
      number = 0;
5604
554
      c = *input_line_pointer++;
5605
554
      while (ISXDIGIT (c))
5606
573
        {
5607
573
    if (ISDIGIT (c))
5608
501
      number = number * 16 + c - '0';
5609
72
    else if (ISUPPER (c))
5610
30
      number = number * 16 + c - 'A' + 10;
5611
42
    else
5612
42
      number = number * 16 + c - 'a' + 10;
5613
573
    c = *input_line_pointer++;
5614
573
        }
5615
554
      c = number & CHAR_MASK;
5616
554
      --input_line_pointer;
5617
554
    }
5618
554
    break;
5619
5620
28
  case '\n':
5621
    /* To be compatible with BSD 4.2 as: give the luser a linefeed!!  */
5622
28
    as_warn (_("unterminated string; newline inserted"));
5623
28
    c = '\n';
5624
28
    bump_line_counters ();
5625
28
    break;
5626
5627
105
  case 0:
5628
    /* Do not advance past the end of the buffer.  */
5629
105
    -- input_line_pointer;
5630
105
    c = NOT_A_CHAR;
5631
105
    break;
5632
5633
59.6k
  default:
5634
5635
#ifdef ONLY_STANDARD_ESCAPES
5636
    as_bad (_("bad escaped character in string"));
5637
    c = '?';
5638
#endif /* ONLY_STANDARD_ESCAPES */
5639
5640
59.6k
    break;
5641
116k
  }
5642
116k
      break;
5643
5644
9.90M
    default:
5645
9.90M
      break;
5646
10.2M
    }
5647
10.2M
  return (c);
5648
10.2M
}
5649

5650
static segT
5651
get_segmented_expression (expressionS *expP)
5652
81.6k
{
5653
81.6k
  segT retval;
5654
5655
81.6k
  retval = expression (expP);
5656
81.6k
  if (expP->X_op == O_illegal
5657
81.6k
      || expP->X_op == O_absent
5658
81.6k
      || expP->X_op == O_big)
5659
72
    {
5660
72
      as_bad (_("expected address expression"));
5661
72
      expP->X_op = O_constant;
5662
72
      expP->X_add_number = 0;
5663
72
      retval = absolute_section;
5664
72
    }
5665
81.6k
  return retval;
5666
81.6k
}
5667
5668
static segT
5669
get_known_segmented_expression (expressionS *expP)
5670
81.6k
{
5671
81.6k
  segT retval = get_segmented_expression (expP);
5672
5673
81.6k
  if (retval == undefined_section)
5674
73.1k
    {
5675
      /* There is no easy way to extract the undefined symbol from the
5676
   expression.  */
5677
73.1k
      if (expP->X_add_symbol != NULL
5678
73.1k
    && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
5679
70.0k
  as_warn (_("symbol \"%s\" undefined; zero assumed"),
5680
70.0k
     S_GET_NAME (expP->X_add_symbol));
5681
3.17k
      else
5682
3.17k
  as_warn (_("some symbol undefined; zero assumed"));
5683
73.1k
      retval = absolute_section;
5684
73.1k
      expP->X_op = O_constant;
5685
73.1k
      expP->X_add_number = 0;
5686
73.1k
    }
5687
81.6k
  return retval;
5688
81.6k
}
5689
5690
char        /* Return terminator.  */
5691
get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression.  */)
5692
0
{
5693
  /* FIXME: val_pointer should probably be offsetT *.  */
5694
0
  *val_pointer = (long) get_absolute_expression ();
5695
0
  return (*input_line_pointer++);
5696
0
}
5697

5698
/* Like demand_copy_string, but return NULL if the string contains any '\0's.
5699
   Give a warning if that happens.  */
5700
5701
char *
5702
demand_copy_C_string (int *len_pointer)
5703
26.2k
{
5704
26.2k
  char *s;
5705
5706
26.2k
  if ((s = demand_copy_string (len_pointer)) != 0)
5707
15.3k
    {
5708
15.3k
      int len;
5709
5710
3.90M
      for (len = *len_pointer; len > 0; len--)
5711
3.88M
  {
5712
3.88M
    if (s[len - 1] == 0)
5713
557
      {
5714
557
        s = 0;
5715
557
        *len_pointer = 0;
5716
557
        as_bad (_("this string may not contain \'\\0\'"));
5717
557
        break;
5718
557
      }
5719
3.88M
  }
5720
15.3k
    }
5721
5722
26.2k
  return s;
5723
26.2k
}
5724

5725
/* Demand string, but return a safe (=private) copy of the string.
5726
   Return NULL if we can't read a string here.  */
5727
5728
char *
5729
demand_copy_string (int *lenP)
5730
72.2k
{
5731
72.2k
  unsigned int c;
5732
72.2k
  int len;
5733
72.2k
  char *retval;
5734
5735
72.2k
  len = 0;
5736
72.2k
  SKIP_WHITESPACE ();
5737
72.2k
  if (*input_line_pointer == '\"')
5738
61.4k
    {
5739
61.4k
      input_line_pointer++; /* Skip opening quote.  */
5740
5741
9.22M
      while (is_a_char (c = next_char_of_string ()))
5742
9.16M
  {
5743
9.16M
    obstack_1grow (&notes, c);
5744
9.16M
    len++;
5745
9.16M
  }
5746
      /* JF this next line is so demand_copy_C_string will return a
5747
   null terminated string.  */
5748
61.4k
      obstack_1grow (&notes, '\0');
5749
61.4k
      retval = (char *) obstack_finish (&notes);
5750
61.4k
    }
5751
10.8k
  else
5752
10.8k
    {
5753
10.8k
      as_bad (_("missing string"));
5754
10.8k
      retval = NULL;
5755
10.8k
      ignore_rest_of_line ();
5756
10.8k
    }
5757
72.2k
  *lenP = len;
5758
72.2k
  return (retval);
5759
72.2k
}
5760

5761
/* In:  Input_line_pointer->next character.
5762
5763
   Do:  Skip input_line_pointer over all whitespace.
5764
5765
   Out: 1 if input_line_pointer->end-of-line.  */
5766
5767
int
5768
is_it_end_of_statement (void)
5769
53.1k
{
5770
53.1k
  SKIP_WHITESPACE ();
5771
53.1k
  return (is_end_of_line[(unsigned char) *input_line_pointer]);
5772
53.1k
}
5773
5774
void
5775
equals (char *sym_name, int reassign)
5776
167k
{
5777
167k
  char *stop = NULL;
5778
167k
  char stopc = 0;
5779
5780
167k
  input_line_pointer++;
5781
167k
  if (*input_line_pointer == '=')
5782
39.1k
    input_line_pointer++;
5783
167k
  if (reassign < 0 && *input_line_pointer == '=')
5784
971
    input_line_pointer++;
5785
5786
171k
  while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
5787
4.10k
    input_line_pointer++;
5788
5789
167k
  if (flag_mri)
5790
18.4k
    stop = mri_comment_field (&stopc);
5791
5792
167k
  assign_symbol (sym_name, reassign >= 0 ? !reassign : reassign);
5793
5794
167k
  if (flag_mri)
5795
18.4k
    {
5796
18.4k
      demand_empty_rest_of_line ();
5797
18.4k
      mri_comment_end (stop, stopc);
5798
18.4k
    }
5799
167k
}
5800
5801
/* Open FILENAME, first trying the unadorned file name, then if that
5802
   fails and the file name is not an absolute path, attempt to open
5803
   the file in current -I include paths.  PATH is a preallocated
5804
   buffer which will be set to the file opened, or FILENAME if no file
5805
   is found.  */
5806
5807
FILE *
5808
search_and_open (const char *filename, char *path)
5809
0
{
5810
0
  FILE *f = fopen (filename, FOPEN_RB);
5811
0
  if (f == NULL && !IS_ABSOLUTE_PATH (filename))
5812
0
    {
5813
0
      for (size_t i = 0; i < include_dir_count; i++)
5814
0
  {
5815
0
    sprintf (path, "%s/%s", include_dirs[i], filename);
5816
0
    f = fopen (path, FOPEN_RB);
5817
0
    if (f != NULL)
5818
0
      return f;
5819
0
  }
5820
0
    }
5821
0
  strcpy (path, filename);
5822
0
  return f;
5823
0
}
5824
5825
/* .incbin -- include a file verbatim at the current location.  */
5826
5827
void
5828
s_incbin (int x ATTRIBUTE_UNUSED)
5829
0
{
5830
0
  FILE * binfile;
5831
0
  char * path;
5832
0
  char * filename;
5833
0
  char * binfrag;
5834
0
  long   skip = 0;
5835
0
  long   count = 0;
5836
0
  long   bytes;
5837
0
  int    len;
5838
5839
#ifdef md_flush_pending_output
5840
  md_flush_pending_output ();
5841
#endif
5842
5843
0
#ifdef md_cons_align
5844
0
  md_cons_align (1);
5845
0
#endif
5846
5847
0
  SKIP_WHITESPACE ();
5848
0
  filename = demand_copy_string (& len);
5849
0
  if (filename == NULL)
5850
0
    return;
5851
5852
0
  SKIP_WHITESPACE ();
5853
5854
  /* Look for optional skip and count.  */
5855
0
  if (* input_line_pointer == ',')
5856
0
    {
5857
0
      ++ input_line_pointer;
5858
0
      skip = get_absolute_expression ();
5859
5860
0
      SKIP_WHITESPACE ();
5861
5862
0
      if (* input_line_pointer == ',')
5863
0
  {
5864
0
    ++ input_line_pointer;
5865
5866
0
    count = get_absolute_expression ();
5867
0
    if (count == 0)
5868
0
      as_warn (_(".incbin count zero, ignoring `%s'"), filename);
5869
5870
0
    SKIP_WHITESPACE ();
5871
0
  }
5872
0
    }
5873
5874
0
  demand_empty_rest_of_line ();
5875
5876
0
  path = XNEWVEC (char, len + include_dir_maxlen + 2);
5877
0
  binfile = search_and_open (filename, path);
5878
5879
0
  if (binfile == NULL)
5880
0
    as_bad (_("file not found: %s"), filename);
5881
0
  else
5882
0
    {
5883
0
      long   file_len;
5884
0
      struct stat filestat;
5885
5886
0
      if (fstat (fileno (binfile), &filestat) != 0
5887
0
    || ! S_ISREG (filestat.st_mode)
5888
0
    || S_ISDIR (filestat.st_mode))
5889
0
  {
5890
0
    as_bad (_("unable to include `%s'"), path);
5891
0
    goto done;
5892
0
  }
5893
      
5894
0
      register_dependency (path);
5895
5896
      /* Compute the length of the file.  */
5897
0
      if (fseek (binfile, 0, SEEK_END) != 0)
5898
0
  {
5899
0
    as_bad (_("seek to end of .incbin file failed `%s'"), path);
5900
0
    goto done;
5901
0
  }
5902
0
      file_len = ftell (binfile);
5903
5904
      /* If a count was not specified use the remainder of the file.  */
5905
0
      if (count == 0)
5906
0
  count = file_len - skip;
5907
5908
0
      if (skip < 0 || count < 0 || file_len < 0 || skip + count > file_len)
5909
0
  {
5910
0
    as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
5911
0
      skip, count, file_len);
5912
0
    goto done;
5913
0
  }
5914
5915
0
      if (fseek (binfile, skip, SEEK_SET) != 0)
5916
0
  {
5917
0
    as_bad (_("could not skip to %ld in file `%s'"), skip, path);
5918
0
    goto done;
5919
0
  }
5920
5921
      /* Allocate frag space and store file contents in it.  */
5922
0
      binfrag = frag_more (count);
5923
5924
0
      bytes = fread (binfrag, 1, count, binfile);
5925
0
      if (bytes < count)
5926
0
  as_warn (_("truncated file `%s', %ld of %ld bytes read"),
5927
0
     path, bytes, count);
5928
0
    }
5929
0
 done:
5930
0
  if (binfile != NULL)
5931
0
    fclose (binfile);
5932
0
  free (path);
5933
0
}
5934
5935
/* .include -- include a file at this point.  */
5936
5937
void
5938
s_include (int arg ATTRIBUTE_UNUSED)
5939
0
{
5940
0
  char *filename;
5941
0
  int i;
5942
0
  FILE *try_file;
5943
0
  char *path;
5944
5945
0
  if (!flag_m68k_mri)
5946
0
    {
5947
0
      filename = demand_copy_string (&i);
5948
0
      if (filename == NULL)
5949
0
  {
5950
    /* demand_copy_string has already printed an error and
5951
       called ignore_rest_of_line.  */
5952
0
    return;
5953
0
  }
5954
0
    }
5955
0
  else
5956
0
    {
5957
0
      SKIP_WHITESPACE ();
5958
0
      i = 0;
5959
0
      while (!is_end_of_line[(unsigned char) *input_line_pointer]
5960
0
       && *input_line_pointer != ' '
5961
0
       && *input_line_pointer != '\t')
5962
0
  {
5963
0
    obstack_1grow (&notes, *input_line_pointer);
5964
0
    ++input_line_pointer;
5965
0
    ++i;
5966
0
  }
5967
5968
0
      obstack_1grow (&notes, '\0');
5969
0
      filename = (char *) obstack_finish (&notes);
5970
0
      while (!is_end_of_line[(unsigned char) *input_line_pointer])
5971
0
  ++input_line_pointer;
5972
0
    }
5973
5974
0
  demand_empty_rest_of_line ();
5975
5976
0
  path = notes_alloc (i + include_dir_maxlen + 2);
5977
0
  try_file = search_and_open (filename, path);
5978
0
  if (try_file)
5979
0
    fclose (try_file);
5980
5981
0
  register_dependency (path);
5982
0
  input_scrub_insert_file (path);
5983
0
}
5984
5985
void
5986
init_include_dir (void)
5987
736
{
5988
736
  include_dirs = XNEWVEC (const char *, 1);
5989
736
  include_dirs[0] = ".";  /* Current dir.  */
5990
736
  include_dir_count = 1;
5991
736
  include_dir_maxlen = 1;
5992
736
}
5993
5994
void
5995
add_include_dir (char *path)
5996
0
{
5997
0
  include_dir_count++;
5998
0
  include_dirs = XRESIZEVEC (const char *, include_dirs, include_dir_count);
5999
0
  include_dirs[include_dir_count - 1] = path; /* New one.  */
6000
6001
0
  size_t i = strlen (path);
6002
0
  if (i > include_dir_maxlen)
6003
0
    include_dir_maxlen = i;
6004
0
}
6005

6006
/* Output debugging information to denote the source file.  */
6007
6008
static void
6009
generate_file_debug (void)
6010
736
{
6011
736
  if (debug_type == DEBUG_STABS)
6012
0
    stabs_generate_asm_file ();
6013
736
}
6014
6015
/* Output line number debugging information for the current source line.  */
6016
6017
void
6018
generate_lineno_debug (void)
6019
1.28M
{
6020
1.28M
  switch (debug_type)
6021
1.28M
    {
6022
115
    case DEBUG_UNSPECIFIED:
6023
1.28M
    case DEBUG_NONE:
6024
1.28M
    case DEBUG_DWARF:
6025
1.28M
      break;
6026
0
    case DEBUG_STABS:
6027
0
      stabs_generate_asm_lineno ();
6028
0
      break;
6029
0
    case DEBUG_ECOFF:
6030
0
      ecoff_generate_asm_lineno ();
6031
0
      break;
6032
0
    case DEBUG_DWARF2:
6033
      /* ??? We could here indicate to dwarf2dbg.c that something
6034
   has changed.  However, since there is additional backend
6035
   support that is required (calling dwarf2_emit_insn), we
6036
   let dwarf2dbg.c call as_where on its own.  */
6037
0
      break;
6038
0
    case DEBUG_CODEVIEW:
6039
0
      codeview_generate_asm_lineno ();
6040
0
      break;
6041
1.28M
    }
6042
1.28M
}
6043
6044
/* Output debugging information to mark a function entry point or end point.
6045
   END_P is zero for .func, and non-zero for .endfunc.  */
6046
6047
void
6048
s_func (int end_p)
6049
0
{
6050
0
  do_s_func (end_p, NULL);
6051
0
}
6052
6053
/* Subroutine of s_func so targets can choose a different default prefix.
6054
   If DEFAULT_PREFIX is NULL, use the target's "leading char".  */
6055
6056
static void
6057
do_s_func (int end_p, const char *default_prefix)
6058
0
{
6059
0
  if (end_p)
6060
0
    {
6061
0
      if (current_name == NULL)
6062
0
  {
6063
0
    as_bad (_("missing .func"));
6064
0
    ignore_rest_of_line ();
6065
0
    return;
6066
0
  }
6067
6068
0
      if (debug_type == DEBUG_STABS)
6069
0
  stabs_generate_asm_endfunc (current_name, current_label);
6070
6071
0
      free (current_name);
6072
0
      free (current_label);
6073
0
      current_name = current_label = NULL;
6074
0
    }
6075
0
  else /* ! end_p */
6076
0
    {
6077
0
      char *name, *label;
6078
0
      char delim1, delim2;
6079
6080
0
      if (current_name != NULL)
6081
0
  {
6082
0
    as_bad (_(".endfunc missing for previous .func"));
6083
0
    ignore_rest_of_line ();
6084
0
    return;
6085
0
  }
6086
6087
0
      delim1 = get_symbol_name (& name);
6088
0
      name = xstrdup (name);
6089
0
      *input_line_pointer = delim1;
6090
0
      SKIP_WHITESPACE_AFTER_NAME ();
6091
0
      if (*input_line_pointer != ',')
6092
0
  {
6093
0
    if (default_prefix)
6094
0
      {
6095
0
        if (asprintf (&label, "%s%s", default_prefix, name) == -1)
6096
0
    as_fatal ("%s", xstrerror (errno));
6097
0
      }
6098
0
    else
6099
0
      {
6100
0
        char leading_char = bfd_get_symbol_leading_char (stdoutput);
6101
        /* Missing entry point, use function's name with the leading
6102
     char prepended.  */
6103
0
        if (leading_char)
6104
0
    {
6105
0
      if (asprintf (&label, "%c%s", leading_char, name) == -1)
6106
0
        as_fatal ("%s", xstrerror (errno));
6107
0
    }
6108
0
        else
6109
0
    label = xstrdup (name);
6110
0
      }
6111
0
  }
6112
0
      else
6113
0
  {
6114
0
    ++input_line_pointer;
6115
0
    SKIP_WHITESPACE ();
6116
0
    delim2 = get_symbol_name (& label);
6117
0
    label = xstrdup (label);
6118
0
    restore_line_pointer (delim2);
6119
0
  }
6120
6121
0
      if (debug_type == DEBUG_STABS)
6122
0
  stabs_generate_asm_func (name, label);
6123
6124
0
      current_name = name;
6125
0
      current_label = label;
6126
0
    }
6127
6128
0
  demand_empty_rest_of_line ();
6129
0
}
6130

6131
#ifdef HANDLE_BUNDLE
6132
6133
void
6134
s_bundle_align_mode (int arg ATTRIBUTE_UNUSED)
6135
0
{
6136
0
  unsigned int align = get_absolute_expression ();
6137
0
  SKIP_WHITESPACE ();
6138
0
  demand_empty_rest_of_line ();
6139
6140
0
  if (align > (unsigned int) TC_ALIGN_LIMIT)
6141
0
    as_fatal (_(".bundle_align_mode alignment too large (maximum %u)"),
6142
0
        (unsigned int) TC_ALIGN_LIMIT);
6143
6144
0
  if (bundle_lock_frag != NULL)
6145
0
    {
6146
0
      as_bad (_("cannot change .bundle_align_mode inside .bundle_lock"));
6147
0
      return;
6148
0
    }
6149
6150
0
  bundle_align_p2 = align;
6151
0
}
6152
6153
void
6154
s_bundle_lock (int arg ATTRIBUTE_UNUSED)
6155
0
{
6156
0
  demand_empty_rest_of_line ();
6157
6158
0
  if (bundle_align_p2 == 0)
6159
0
    {
6160
0
      as_bad (_(".bundle_lock is meaningless without .bundle_align_mode"));
6161
0
      return;
6162
0
    }
6163
6164
0
  if (bundle_lock_depth == 0)
6165
0
    {
6166
0
      bundle_lock_frchain = frchain_now;
6167
0
      bundle_lock_frag = start_bundle ();
6168
0
    }
6169
0
  ++bundle_lock_depth;
6170
0
}
6171
6172
void
6173
s_bundle_unlock (int arg ATTRIBUTE_UNUSED)
6174
0
{
6175
0
  unsigned int size;
6176
6177
0
  demand_empty_rest_of_line ();
6178
6179
0
  if (bundle_lock_frag == NULL)
6180
0
    {
6181
0
      as_bad (_(".bundle_unlock without preceding .bundle_lock"));
6182
0
      return;
6183
0
    }
6184
6185
0
  gas_assert (bundle_align_p2 > 0);
6186
6187
0
  gas_assert (bundle_lock_depth > 0);
6188
0
  if (--bundle_lock_depth > 0)
6189
0
    return;
6190
6191
0
  size = pending_bundle_size (bundle_lock_frag);
6192
6193
0
  if (size > 1U << bundle_align_p2)
6194
0
    as_bad (_(".bundle_lock sequence is %u bytes, "
6195
0
        "but bundle size is only %u bytes"),
6196
0
      size, 1u << bundle_align_p2);
6197
0
  else
6198
0
    finish_bundle (bundle_lock_frag, size);
6199
6200
0
  bundle_lock_frag = NULL;
6201
0
  bundle_lock_frchain = NULL;
6202
0
}
6203
6204
#endif  /* HANDLE_BUNDLE */
6205

6206
void
6207
s_ignore (int arg ATTRIBUTE_UNUSED)
6208
232k
{
6209
232k
  ignore_rest_of_line ();
6210
232k
}
6211
6212
void
6213
read_print_statistics (FILE *file)
6214
0
{
6215
0
  htab_print_statistics (file, "pseudo-op table", po_hash);
6216
0
}
6217
6218
/* Inserts the given line into the input stream.
6219
6220
   This call avoids macro/conditionals nesting checking, since the contents of
6221
   the line are assumed to replace the contents of a line already scanned.
6222
6223
   An appropriate use of this function would be substitution of input lines when
6224
   called by md_start_line_hook().  The given line is assumed to already be
6225
   properly scrubbed.  */
6226
6227
void
6228
input_scrub_insert_line (const char *line)
6229
0
{
6230
0
  sb newline;
6231
0
  size_t len = strlen (line);
6232
0
  sb_build (&newline, len);
6233
0
  sb_add_buffer (&newline, line, len);
6234
0
  input_scrub_include_sb (&newline, input_line_pointer, expanding_none);
6235
0
  sb_kill (&newline);
6236
0
  buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6237
0
}
6238
6239
/* Insert a file into the input stream; the path must resolve to an actual
6240
   file; no include path searching or dependency registering is performed.  */
6241
6242
void
6243
input_scrub_insert_file (char *path)
6244
0
{
6245
0
  input_scrub_include_file (path, input_line_pointer);
6246
0
  buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6247
0
}
6248
6249
/* Find the end of a line, considering quotation and escaping of quotes.  */
6250
6251
#if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
6252
# define TC_SINGLE_QUOTE_STRINGS 1
6253
#endif
6254
6255
static char *
6256
_find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED,
6257
       int in_macro)
6258
1.42M
{
6259
1.42M
  char inquote = '\0';
6260
1.42M
  int inescape = 0;
6261
6262
26.4M
  while (!is_end_of_line[(unsigned char) *s]
6263
26.4M
   || (inquote && !ISCNTRL (*s))
6264
26.4M
   || (inquote == '\'' && flag_mri)
6265
#ifdef TC_EOL_IN_INSN
6266
   || (insn && TC_EOL_IN_INSN (s))
6267
#endif
6268
   /* PR 6926:  When we are parsing the body of a macro the sequence
6269
      \@ is special - it refers to the invocation count.  If the @
6270
      character happens to be registered as a line-separator character
6271
      by the target, then the is_end_of_line[] test above will have
6272
      returned true, but we need to ignore the line separating
6273
      semantics in this particular case.  */
6274
26.4M
   || (in_macro && inescape && *s == '@')
6275
1.42M
  )
6276
25.0M
    {
6277
25.0M
      if (mri_string && *s == '\'')
6278
0
  inquote ^= *s;
6279
25.0M
      else if (inescape)
6280
342k
  inescape = 0;
6281
24.6M
      else if (*s == '\\')
6282
344k
  inescape = 1;
6283
24.3M
      else if (!inquote
6284
24.3M
         ? *s == '"'
6285
#ifdef TC_SINGLE_QUOTE_STRINGS
6286
     || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
6287
#endif
6288
24.3M
         : *s == inquote)
6289
786k
  inquote ^= *s;
6290
25.0M
      ++s;
6291
25.0M
    }
6292
1.42M
  if (inquote)
6293
34.7k
    as_warn (_("missing closing `%c'"), inquote);
6294
1.42M
  if (inescape && !ignore_input ())
6295
2.17k
    as_warn (_("stray `\\'"));
6296
1.42M
  return s;
6297
1.42M
}
6298
6299
char *
6300
find_end_of_line (char *s, int mri_string)
6301
31.9k
{
6302
31.9k
  return _find_end_of_line (s, mri_string, 0, 0);
6303
31.9k
}
6304
6305
static char *saved_ilp;
6306
static char *saved_limit;
6307
6308
/* Use BUF as a temporary input pointer for calling other functions in this
6309
   file.  BUF must be a C string, so that its end can be found by strlen.
6310
   Also sets the buffer_limit variable (local to this file) so that buffer
6311
   overruns should not occur.  Saves the current input line pointer so that
6312
   it can be restored by calling restore_ilp().
6313
6314
   Does not support recursion.  */
6315
6316
void
6317
temp_ilp (char *buf)
6318
61
{
6319
61
  gas_assert (saved_ilp == NULL);
6320
61
  gas_assert (buf != NULL);
6321
6322
61
  saved_ilp = input_line_pointer;
6323
61
  saved_limit = buffer_limit;
6324
  /* Prevent the assert in restore_ilp from triggering if
6325
     the input_line_pointer has not yet been initialised.  */
6326
61
  if (saved_ilp == NULL)
6327
0
    saved_limit = saved_ilp = (char *) "";
6328
6329
61
  input_line_pointer = buf;
6330
61
  buffer_limit = buf + strlen (buf);
6331
61
  input_from_string = true;
6332
61
}
6333
6334
/* Restore a saved input line pointer.  */
6335
6336
void
6337
restore_ilp (void)
6338
61
{
6339
61
  gas_assert (saved_ilp != NULL);
6340
6341
61
  input_line_pointer = saved_ilp;
6342
61
  buffer_limit = saved_limit;
6343
61
  input_from_string = false;
6344
6345
61
  saved_ilp = NULL;
6346
61
}