Coverage Report

Created: 2025-07-08 11:15

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