gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / bfd / aout-cris.c
CommitLineData
06c15ad7 1/* BFD backend for CRIS a.out binaries.
b3adc24a 2 Copyright (C) 2000-2020 Free Software Foundation, Inc.
06c15ad7
HPN
3 Contributed by Axis Communications AB.
4 Written by Hans-Peter Nilsson.
5
7920ce38 6 This file is part of BFD, the Binary File Descriptor library.
06c15ad7 7
7920ce38
NC
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
cd123cb7 10 the Free Software Foundation; either version 3 of the License, or
7920ce38 11 (at your option) any later version.
06c15ad7 12
7920ce38
NC
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
06c15ad7 17
7920ce38
NC
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
cd123cb7
NC
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
06c15ad7
HPN
22
23/* See info in the file PORTING for documentation of these macros and
24 functions. Beware; some of the information there is outdated. */
25
26#define N_HEADER_IN_TEXT(x) 0
07d6d2b8 27#define N_TXTOFF(x) 32
06c15ad7 28#define ENTRY_CAN_BE_ZERO
7920ce38 29#define TEXT_START_ADDR 0
06c15ad7 30
b16885a1
HPN
31/* Without reading symbols to get the text start symbol, there is no way
32 to know where the text segment starts in an a.out file. Defaulting to
33 anything as constant as TEXT_START_ADDR is bad. But we can guess from
34 the entry point, which is usually within the first 64k of the text
35 segment. We also assume here that the text segment is 64k-aligned.
36 FIXME: It is also wrong to assume that data and bss follow immediately
37 after text, but with those, we don't have any choice besides reading
38 symbol info, and luckily there's no pressing need for correctness for
39 those vma:s at this time. */
bbb1afc8 40#define N_TXTADDR(x) ((x)->a_entry & ~(bfd_vma) 0xffff)
b16885a1 41
06c15ad7
HPN
42/* If you change this to 4, you can not link to an address N*4+2. */
43#define SEGMENT_SIZE 2
44
45/* For some reason, if the a.out file has Z_MAGIC, then
46 adata(abfd).exec_bytes_size is not used, but rather
47 adata(abfd).zmagic_disk_block_size, even though the exec_header is
48 *not* included in the text segment. A simple workaround is to
49 #define ZMAGIC_DISK_BLOCK_SIZE, which is used if defined; otherwise
c4dfa77f 50 TARGET_PAGE_SIZE is used. */
7920ce38 51#define ZMAGIC_DISK_BLOCK_SIZE N_TXTOFF (0)
06c15ad7
HPN
52
53/* It seems odd at first to set a page-size this low, but gives greater
54 freedom in where things can be linked. The drawback is that you have
55 to set alignment and padding in linker scripts. */
56#define TARGET_PAGE_SIZE SEGMENT_SIZE
57#define TARGETNAME "a.out-cris"
58
e43d48cc
AM
59/* Do not "beautify" the CONCAT* macro args. Traditional C will not
60 remove whitespace added here, and thus will fail to concatenate
61 the tokens. */
62#define MY(OP) CONCAT2 (cris_aout_,OP)
63#define NAME(x, y) CONCAT3 (cris_aout,_32_,y)
06c15ad7 64
691bf19c 65#include "sysdep.h"
06c15ad7
HPN
66#include "bfd.h"
67
68/* Version 1 of the header. */
69#define MY_exec_hdr_flags 1
70
7920ce38
NC
71#define MY_write_object_contents MY (write_object_contents)
72static bfd_boolean MY (write_object_contents) (bfd *);
06c15ad7
HPN
73
74/* Forward this, so we can use a pointer to it in PARAMS. */
75struct reloc_ext_external;
76
7920ce38
NC
77#define MY_swap_ext_reloc_out MY (swap_ext_reloc_out)
78static void MY (swap_ext_reloc_out) (bfd *, arelent *, struct reloc_ext_external *);
06c15ad7 79
7920ce38
NC
80#define MY_swap_ext_reloc_in MY (swap_ext_reloc_in)
81static void MY (swap_ext_reloc_in) (bfd *, struct reloc_ext_external *,
82 arelent *, asymbol **, bfd_size_type);
06c15ad7 83
7920ce38
NC
84#define MY_set_sizes MY (set_sizes)
85static bfd_boolean MY (set_sizes) (bfd *);
06c15ad7 86
7920ce38 87/* To set back reloc_size to ext, we make MY (set_sizes) be called
06c15ad7
HPN
88 through this construct. Note that MY_set_arch_mach is only called
89 through SET_ARCH_MACH. The default bfd_default_set_arch_mach will
90 not call set_sizes. */
91
bbb1afc8 92#define SET_ARCH_MACH(BFD, EXECP) \
7242fa8a 93 bfd_set_arch_mach (BFD, bfd_arch_cris, N_MACHTYPE (EXECP))
06c15ad7
HPN
94
95/* These macros describe the binary layout of the reloc information we
96 use in a file. */
7920ce38
NC
97#define RELOC_EXT_BITS_EXTERN_LITTLE 0x80
98#define RELOC_EXT_BITS_TYPE_LITTLE 3
06c15ad7
HPN
99#define RELOC_EXT_BITS_TYPE_SH_LITTLE 0
100
101#ifndef MY_get_section_contents
102#define MY_get_section_contents aout_32_get_section_contents
103#endif
104
15103188
L
105#define MACHTYPE_OK(mtype) ((mtype) == M_CRIS)
106
06c15ad7
HPN
107/* Include generic functions (some are overridden above). */
108#include "aout32.c"
109#include "aout-target.h"
110
06c15ad7
HPN
111/* We need our own version to set header flags. */
112
b34976b6 113static bfd_boolean
7920ce38 114MY (write_object_contents) (bfd *abfd)
06c15ad7
HPN
115{
116 struct external_exec exec_bytes;
117 struct internal_exec *execp = exec_hdr (abfd);
118
119 /* We set the reloc type to RELOC_EXT_SIZE, although setting it at all
120 seems unnecessary when inspecting as and ld behavior (not an
121 exhaustive inspection). The default write_object_contents
122 definition sets RELOC_EXT_SIZE, so we follow suite and set it too. */
123 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
124
125 /* Setting N_SET_MACHTYPE and using N_SET_FLAGS is not performed by
126 the default definition. */
7920ce38 127 if (bfd_get_arch (abfd) == bfd_arch_cris)
bbb1afc8 128 N_SET_MACHTYPE (execp, M_CRIS);
06c15ad7 129
bbb1afc8 130 N_SET_FLAGS (execp, aout_backend_info (abfd)->exec_hdr_flags);
06c15ad7
HPN
131
132 WRITE_HEADERS (abfd, execp);
133
b34976b6 134 return TRUE;
06c15ad7
HPN
135}
136
06c15ad7 137/* We need our own for these reasons:
c4dfa77f
KH
138 - Assert that a normal 8, 16 or 32 reloc is output.
139 - Fix what seems to be a weak-bug (perhaps there for valid reasons). */
06c15ad7
HPN
140
141static void
7920ce38
NC
142MY (swap_ext_reloc_out) (bfd *abfd,
143 arelent *g,
144 struct reloc_ext_external *natptr)
06c15ad7
HPN
145{
146 int r_index;
147 int r_extern;
148 unsigned int r_type;
dc810e39 149 bfd_vma r_addend;
06c15ad7
HPN
150 asymbol *sym = *(g->sym_ptr_ptr);
151 asection *output_section = sym->section->output_section;
152
153 PUT_WORD (abfd, g->address, natptr->r_address);
154
155 r_type = (unsigned int) g->howto->type;
156
157 r_addend = g->addend;
158 if ((sym->flags & BSF_SECTION_SYM) != 0)
159 r_addend += (*(g->sym_ptr_ptr))->section->output_section->vma;
160
161 /* If this relocation is relative to a symbol then set the
162 r_index to the symbols index, and the r_extern bit.
163
164 Absolute symbols can come in in two ways, either as an offset
165 from the abs section, or as a symbol which has an abs value.
166 check for that here. */
167
e6f7f6d1 168 if (bfd_is_abs_section (bfd_asymbol_section (sym)))
06c15ad7
HPN
169 {
170 r_extern = 0;
171 r_index = N_ABS;
172 }
173 else if ((sym->flags & BSF_SECTION_SYM) == 0)
174 {
e6f7f6d1 175 if (bfd_is_und_section (bfd_asymbol_section (sym))
06c15ad7
HPN
176 /* Remember to check for weak symbols; they count as global. */
177 || (sym->flags & (BSF_GLOBAL | BSF_WEAK)) != 0)
178 r_extern = 1;
179 else
180 r_extern = 0;
181 r_index = (*(g->sym_ptr_ptr))->KEEPIT;
182 }
183 else
184 {
185 /* Just an ordinary section. */
186 r_extern = 0;
187 r_index = output_section->target_index;
188 }
189
190 /* The relocation type is the same as the canonical ones, but only
191 the first 3 are used: RELOC_8, RELOC_16, RELOC_32.
192 We may change this later, but assert this for the moment. */
193 if (r_type > 2)
194 {
695344c0 195 /* xgettext:c-format */
e8f5af78 196 _bfd_error_handler (_("%pB: unsupported relocation type exported: %#x"),
dae82561 197 abfd, r_type);
c4dfa77f 198
06c15ad7
HPN
199 bfd_set_error (bfd_error_wrong_format);
200 }
201
202 /* Now the fun stuff. */
203 natptr->r_index[2] = r_index >> 16;
204 natptr->r_index[1] = r_index >> 8;
205 natptr->r_index[0] = r_index;
206 natptr->r_type[0] =
207 (r_extern ? RELOC_EXT_BITS_EXTERN_LITTLE : 0)
208 | (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE);
209
210 PUT_WORD (abfd, r_addend, natptr->r_addend);
211}
212
06c15ad7
HPN
213/* We need our own to assert that a normal 8, 16 or 32 reloc is input. */
214
215static void
7920ce38
NC
216MY (swap_ext_reloc_in) (bfd *abfd,
217 struct reloc_ext_external *bytes,
218 arelent *cache_ptr,
219 asymbol **symbols,
220 bfd_size_type symcount)
06c15ad7
HPN
221{
222 unsigned int r_index;
223 int r_extern;
224 unsigned int r_type;
225 struct aoutdata *su = &(abfd->tdata.aout_data->a);
226
227 cache_ptr->address = (GET_SWORD (abfd, bytes->r_address));
228
229 /* Now the fun stuff. */
7242fa8a
GN
230 r_index = (((unsigned int) bytes->r_index[2] << 16)
231 | ((unsigned int) bytes->r_index[1] << 8)
232 | bytes->r_index[0]);
233
06c15ad7 234 r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
7242fa8a
GN
235
236 r_type = ((bytes->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
237 >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
06c15ad7
HPN
238
239 if (r_type > 2)
240 {
695344c0 241 /* xgettext:c-format */
e8f5af78 242 _bfd_error_handler (_("%pB: unsupported relocation type imported: %#x"),
4eca0228 243 abfd, r_type);
c4dfa77f 244
d003868e 245 bfd_set_error (bfd_error_wrong_format);
06c15ad7 246 }
c4dfa77f 247
06c15ad7
HPN
248 cache_ptr->howto = howto_table_ext + r_type;
249
250 if (r_extern && r_index > symcount)
251 {
4eca0228 252 _bfd_error_handler
695344c0 253 /* xgettext:c-format */
59d08d6c 254 (_("%pB: bad relocation record imported: %d"), abfd, r_index);
c4dfa77f 255
06c15ad7
HPN
256 bfd_set_error (bfd_error_wrong_format);
257
258 /* We continue, so we can catch further errors. */
259 r_extern = 0;
260 r_index = N_ABS;
261 }
262
263 /* Magically uses r_extern, symbols etc. Ugly, but it's what's in the
264 default. */
265 MOVE_ADDRESS (GET_SWORD (abfd, bytes->r_addend));
266}
267
06c15ad7
HPN
268/* We use the same as the default, except that we also set
269 "obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;", to avoid changing
270 NAME (aout, set_arch_mach) in aoutx. */
271
b34976b6 272static bfd_boolean
7920ce38 273MY (set_sizes) (bfd *abfd)
06c15ad7
HPN
274{
275 /* Just as the default in aout-target.h (with some #ifdefs folded)... */
276
7920ce38
NC
277 adata (abfd).page_size = TARGET_PAGE_SIZE;
278 adata (abfd).segment_size = SEGMENT_SIZE;
279 adata (abfd).zmagic_disk_block_size = ZMAGIC_DISK_BLOCK_SIZE;
280 adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
06c15ad7
HPN
281
282 /* ... except for that we have the extended reloc. The alternative
283 would be to add a check on bfd_arch_cris in NAME (aout,
284 set_arch_mach) in aoutx.h, but I don't want to do that since
285 target-specific things should not be added there. */
286
287 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
c4dfa77f 288
b34976b6 289 return TRUE;
06c15ad7 290}
This page took 0.861174 seconds and 4 git commands to generate.