xref: /netbsd-src/external/gpl3/binutils/dist/gas/write.h (revision d16b7486a53dcb8072b60ec6fcb4373a2d0c27b7)
1 /* write.h
2    Copyright (C) 1987-2022 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 #ifndef __write_h__
22 #define __write_h__
23 
24 /* This is the name of a fake symbol which will never appear in the
25    assembler output.  S_IS_LOCAL detects it because of the \001.  */
26 #ifndef FAKE_LABEL_NAME
27 #define FAKE_LABEL_NAME "L0\001"
28 #endif
29 
30 /* This is a special character that is used to indicate a fake label.
31    It must be present in FAKE_LABEL_NAME, although it does not have to
32    be the first character.  It must not be a character that would be
33    found in a valid symbol name.
34 
35    Also be aware that the function _bfd_elf_is_local_label_name in
36    bfd/elf.c has an implicit assumption that FAKE_LABEL_CHAR is '\001'.
37    If this is not the case then FAKE_LABEL_NAME must start with ".L" in
38    order for the function to continue working.  */
39 #ifndef FAKE_LABEL_CHAR
40 #define FAKE_LABEL_CHAR '\001'
41 #endif
42 
43 /*
44  * FixSs may be built up in any order.
45  */
46 
47 struct fix
48 {
49   /* Next fixS in linked list, or NULL.  */
50   struct fix *fx_next;
51 
52   /* These small fields are grouped together for compactness of
53      this structure, and efficiency of access on some architectures.  */
54 
55   /* pc-relative offset adjust (only used by some CPU specific code).
56      A 4-bit field would be sufficient for most uses, except for ppc
57      which pokes an operand table index here.  Bits may be stolen
58      from here should that be necessary, provided PPC_OPINDEX_MAX is
59      adjusted suitably.  */
60   int fx_pcrel_adjust : 16;
61 
62   /* How many bytes are involved? */
63   unsigned fx_size : 8;
64 
65   /* Is this a pc-relative relocation?  */
66   unsigned fx_pcrel : 1;
67 
68   /* Has this relocation already been applied?  */
69   unsigned fx_done : 1;
70 
71   /* Suppress overflow complaints on large addends.  This is used
72      in the PowerPC ELF config to allow large addends on the
73      BFD_RELOC_{LO16,HI16,HI16_S} relocations.
74 
75      @@ Can this be determined from BFD?  */
76   unsigned fx_no_overflow : 1;
77 
78   /* The value is signed when checking for overflow.  */
79   unsigned fx_signed : 1;
80 
81   /* Some bits for the CPU specific code.  */
82   unsigned fx_tcbit : 1;
83   unsigned fx_tcbit2 : 1;
84 
85   /* Spare bits.  */
86   unsigned fx_unused : 2;
87 
88   bfd_reloc_code_real_type fx_r_type;
89 
90   /* Which frag does this fix apply to?  */
91   fragS *fx_frag;
92 
93   /* The location within the frag where the fixup occurs.  */
94   unsigned long fx_where;
95 
96   /* NULL or Symbol whose value we add in.  */
97   symbolS *fx_addsy;
98 
99   /* NULL or Symbol whose value we subtract.  */
100   symbolS *fx_subsy;
101 
102   /* Absolute number we add in.  */
103   valueT fx_offset;
104 
105   /* The value of dot when the fixup expression was parsed.  */
106   addressT fx_dot_value;
107 
108   /* The frag fx_dot_value is based on.  */
109   fragS *fx_dot_frag;
110 
111   /* This field is sort of misnamed.  It appears to be a sort of random
112      scratch field, for use by the back ends.  The main gas code doesn't
113      do anything but initialize it to zero.  The use of it does need to
114      be coordinated between the cpu and format files, though.  E.g., some
115      coff targets pass the `addend' field from the cpu file via this
116      field.  I don't know why the `fx_offset' field above can't be used
117      for that; investigate later and document. KR  */
118   valueT fx_addnumber;
119 
120   /* The location of the instruction which created the reloc, used
121      in error messages.  */
122   const char *fx_file;
123   unsigned fx_line;
124 
125 #ifdef USING_CGEN
126   struct {
127     /* CGEN_INSN entry for this instruction.  */
128     const struct cgen_insn *insn;
129     /* Target specific data, usually reloc number.  */
130     int opinfo;
131     /* Which ifield this fixup applies to. */
132     struct cgen_maybe_multi_ifield * field;
133     /* is this field is the MSB field in a set? */
134     int msb_field_p;
135   } fx_cgen;
136 #endif
137 
138 #ifdef TC_FIX_TYPE
139   /* Location where a backend can attach additional data
140      needed to perform fixups.  */
141   TC_FIX_TYPE tc_fix_data;
142 #endif
143 };
144 
145 typedef struct fix fixS;
146 
147 struct reloc_list
148 {
149   struct reloc_list *next;
150   union
151   {
152     struct
153     {
154       symbolS *offset_sym;
155       reloc_howto_type *howto;
156       symbolS *sym;
157       bfd_vma addend;
158     } a;
159     struct
160     {
161       asection *sec;
162       asymbol *s;
163       arelent r;
164     } b;
165   } u;
166   const char *file;
167   unsigned int line;
168 };
169 
170 extern int finalize_syms;
171 extern symbolS *abs_section_sym;
172 extern addressT dot_value;
173 extern fragS *dot_frag;
174 extern struct reloc_list* reloc_list;
175 
176 extern void append (char **, char *, unsigned long);
177 extern void record_alignment (segT, unsigned);
178 extern int get_recorded_alignment (segT);
179 extern void write_object_file (void);
180 extern long relax_frag (segT, fragS *, long);
181 extern int relax_segment (struct frag *, segT, int);
182 extern void number_to_chars_littleendian (char *, valueT, int);
183 extern void number_to_chars_bigendian (char *, valueT, int);
184 extern fixS *fix_new (fragS *, unsigned long, unsigned long, symbolS *,
185 		      offsetT, int, bfd_reloc_code_real_type);
186 extern fixS *fix_at_start (fragS *, unsigned long, symbolS *,
187 			   offsetT, int, bfd_reloc_code_real_type);
188 extern fixS *fix_new_exp (fragS *, unsigned long, unsigned long,
189 			  expressionS *, int, bfd_reloc_code_real_type);
190 extern void write_print_statistics (FILE *);
191 extern void as_bad_subtract (fixS *);
192 
193 #endif /* __write_h__ */
194