elf32-m68hc1x.c revision 1.1.1.3 1 1.1 christos /* Motorola 68HC11/HC12-specific support for 32-bit ELF
2 1.1 christos Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3 1.1.1.2 christos 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 1.1 christos Contributed by Stephane Carrez (stcarrez (at) nerim.fr)
5 1.1 christos
6 1.1 christos This file is part of BFD, the Binary File Descriptor library.
7 1.1 christos
8 1.1 christos This program is free software; you can redistribute it and/or modify
9 1.1 christos it under the terms of the GNU General Public License as published by
10 1.1 christos the Free Software Foundation; either version 3 of the License, or
11 1.1 christos (at your option) any later version.
12 1.1 christos
13 1.1 christos This program is distributed in the hope that it will be useful,
14 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
15 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 1.1 christos GNU General Public License for more details.
17 1.1 christos
18 1.1 christos You should have received a copy of the GNU General Public License
19 1.1 christos along with this program; if not, write to the Free Software
20 1.1 christos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 1.1 christos MA 02110-1301, USA. */
22 1.1 christos
23 1.1 christos #include "sysdep.h"
24 1.1.1.2 christos #include "alloca-conf.h"
25 1.1 christos #include "bfd.h"
26 1.1 christos #include "bfdlink.h"
27 1.1 christos #include "libbfd.h"
28 1.1 christos #include "elf-bfd.h"
29 1.1 christos #include "elf32-m68hc1x.h"
30 1.1 christos #include "elf/m68hc11.h"
31 1.1 christos #include "opcode/m68hc11.h"
32 1.1 christos
33 1.1 christos
34 1.1 christos #define m68hc12_stub_hash_lookup(table, string, create, copy) \
35 1.1 christos ((struct elf32_m68hc11_stub_hash_entry *) \
36 1.1 christos bfd_hash_lookup ((table), (string), (create), (copy)))
37 1.1 christos
38 1.1 christos static struct elf32_m68hc11_stub_hash_entry* m68hc12_add_stub
39 1.1 christos (const char *stub_name,
40 1.1 christos asection *section,
41 1.1 christos struct m68hc11_elf_link_hash_table *htab);
42 1.1 christos
43 1.1 christos static struct bfd_hash_entry *stub_hash_newfunc
44 1.1 christos (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
45 1.1 christos
46 1.1 christos static void m68hc11_elf_set_symbol (bfd* abfd, struct bfd_link_info *info,
47 1.1 christos const char* name, bfd_vma value,
48 1.1 christos asection* sec);
49 1.1 christos
50 1.1 christos static bfd_boolean m68hc11_elf_export_one_stub
51 1.1 christos (struct bfd_hash_entry *gen_entry, void *in_arg);
52 1.1 christos
53 1.1.1.2 christos static void scan_sections_for_abi (bfd*, asection*, void *);
54 1.1 christos
55 1.1 christos struct m68hc11_scan_param
56 1.1 christos {
57 1.1 christos struct m68hc11_page_info* pinfo;
58 1.1 christos bfd_boolean use_memory_banks;
59 1.1 christos };
60 1.1 christos
61 1.1 christos
62 1.1 christos /* Create a 68HC11/68HC12 ELF linker hash table. */
63 1.1 christos
64 1.1 christos struct m68hc11_elf_link_hash_table*
65 1.1 christos m68hc11_elf_hash_table_create (bfd *abfd)
66 1.1 christos {
67 1.1 christos struct m68hc11_elf_link_hash_table *ret;
68 1.1 christos bfd_size_type amt = sizeof (struct m68hc11_elf_link_hash_table);
69 1.1 christos
70 1.1.1.2 christos ret = (struct m68hc11_elf_link_hash_table *) bfd_zmalloc (amt);
71 1.1 christos if (ret == (struct m68hc11_elf_link_hash_table *) NULL)
72 1.1 christos return NULL;
73 1.1 christos
74 1.1 christos if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
75 1.1 christos _bfd_elf_link_hash_newfunc,
76 1.1 christos sizeof (struct elf_link_hash_entry),
77 1.1 christos M68HC11_ELF_DATA))
78 1.1 christos {
79 1.1 christos free (ret);
80 1.1 christos return NULL;
81 1.1 christos }
82 1.1 christos
83 1.1 christos /* Init the stub hash table too. */
84 1.1 christos amt = sizeof (struct bfd_hash_table);
85 1.1 christos ret->stub_hash_table = (struct bfd_hash_table*) bfd_malloc (amt);
86 1.1 christos if (ret->stub_hash_table == NULL)
87 1.1 christos {
88 1.1 christos free (ret);
89 1.1 christos return NULL;
90 1.1 christos }
91 1.1 christos if (!bfd_hash_table_init (ret->stub_hash_table, stub_hash_newfunc,
92 1.1 christos sizeof (struct elf32_m68hc11_stub_hash_entry)))
93 1.1 christos return NULL;
94 1.1 christos
95 1.1 christos return ret;
96 1.1 christos }
97 1.1 christos
98 1.1 christos /* Free the derived linker hash table. */
99 1.1 christos
100 1.1 christos void
101 1.1 christos m68hc11_elf_bfd_link_hash_table_free (struct bfd_link_hash_table *hash)
102 1.1 christos {
103 1.1 christos struct m68hc11_elf_link_hash_table *ret
104 1.1 christos = (struct m68hc11_elf_link_hash_table *) hash;
105 1.1 christos
106 1.1 christos bfd_hash_table_free (ret->stub_hash_table);
107 1.1 christos free (ret->stub_hash_table);
108 1.1.1.2 christos _bfd_elf_link_hash_table_free (hash);
109 1.1 christos }
110 1.1 christos
111 1.1 christos /* Assorted hash table functions. */
112 1.1 christos
113 1.1 christos /* Initialize an entry in the stub hash table. */
114 1.1 christos
115 1.1 christos static struct bfd_hash_entry *
116 1.1 christos stub_hash_newfunc (struct bfd_hash_entry *entry, struct bfd_hash_table *table,
117 1.1 christos const char *string)
118 1.1 christos {
119 1.1 christos /* Allocate the structure if it has not already been allocated by a
120 1.1 christos subclass. */
121 1.1 christos if (entry == NULL)
122 1.1 christos {
123 1.1 christos entry = bfd_hash_allocate (table,
124 1.1 christos sizeof (struct elf32_m68hc11_stub_hash_entry));
125 1.1 christos if (entry == NULL)
126 1.1 christos return entry;
127 1.1 christos }
128 1.1 christos
129 1.1 christos /* Call the allocation method of the superclass. */
130 1.1 christos entry = bfd_hash_newfunc (entry, table, string);
131 1.1 christos if (entry != NULL)
132 1.1 christos {
133 1.1 christos struct elf32_m68hc11_stub_hash_entry *eh;
134 1.1 christos
135 1.1 christos /* Initialize the local fields. */
136 1.1 christos eh = (struct elf32_m68hc11_stub_hash_entry *) entry;
137 1.1 christos eh->stub_sec = NULL;
138 1.1 christos eh->stub_offset = 0;
139 1.1 christos eh->target_value = 0;
140 1.1 christos eh->target_section = NULL;
141 1.1 christos }
142 1.1 christos
143 1.1 christos return entry;
144 1.1 christos }
145 1.1 christos
146 1.1 christos /* Add a new stub entry to the stub hash. Not all fields of the new
147 1.1 christos stub entry are initialised. */
148 1.1 christos
149 1.1 christos static struct elf32_m68hc11_stub_hash_entry *
150 1.1 christos m68hc12_add_stub (const char *stub_name, asection *section,
151 1.1 christos struct m68hc11_elf_link_hash_table *htab)
152 1.1 christos {
153 1.1 christos struct elf32_m68hc11_stub_hash_entry *stub_entry;
154 1.1 christos
155 1.1 christos /* Enter this entry into the linker stub hash table. */
156 1.1 christos stub_entry = m68hc12_stub_hash_lookup (htab->stub_hash_table, stub_name,
157 1.1 christos TRUE, FALSE);
158 1.1 christos if (stub_entry == NULL)
159 1.1 christos {
160 1.1 christos (*_bfd_error_handler) (_("%B: cannot create stub entry %s"),
161 1.1 christos section->owner, stub_name);
162 1.1 christos return NULL;
163 1.1 christos }
164 1.1 christos
165 1.1 christos if (htab->stub_section == 0)
166 1.1 christos {
167 1.1 christos htab->stub_section = (*htab->add_stub_section) (".tramp",
168 1.1 christos htab->tramp_section);
169 1.1 christos }
170 1.1 christos
171 1.1 christos stub_entry->stub_sec = htab->stub_section;
172 1.1 christos stub_entry->stub_offset = 0;
173 1.1 christos return stub_entry;
174 1.1 christos }
175 1.1 christos
176 1.1 christos /* Hook called by the linker routine which adds symbols from an object
177 1.1 christos file. We use it for identify far symbols and force a loading of
178 1.1 christos the trampoline handler. */
179 1.1 christos
180 1.1 christos bfd_boolean
181 1.1 christos elf32_m68hc11_add_symbol_hook (bfd *abfd, struct bfd_link_info *info,
182 1.1 christos Elf_Internal_Sym *sym,
183 1.1 christos const char **namep ATTRIBUTE_UNUSED,
184 1.1 christos flagword *flagsp ATTRIBUTE_UNUSED,
185 1.1 christos asection **secp ATTRIBUTE_UNUSED,
186 1.1 christos bfd_vma *valp ATTRIBUTE_UNUSED)
187 1.1 christos {
188 1.1 christos if (sym->st_other & STO_M68HC12_FAR)
189 1.1 christos {
190 1.1 christos struct elf_link_hash_entry *h;
191 1.1 christos
192 1.1 christos h = (struct elf_link_hash_entry *)
193 1.1 christos bfd_link_hash_lookup (info->hash, "__far_trampoline",
194 1.1 christos FALSE, FALSE, FALSE);
195 1.1 christos if (h == NULL)
196 1.1 christos {
197 1.1 christos struct bfd_link_hash_entry* entry = NULL;
198 1.1 christos
199 1.1 christos _bfd_generic_link_add_one_symbol (info, abfd,
200 1.1 christos "__far_trampoline",
201 1.1 christos BSF_GLOBAL,
202 1.1 christos bfd_und_section_ptr,
203 1.1 christos (bfd_vma) 0, (const char*) NULL,
204 1.1 christos FALSE, FALSE, &entry);
205 1.1 christos }
206 1.1 christos
207 1.1 christos }
208 1.1 christos return TRUE;
209 1.1 christos }
210 1.1 christos
211 1.1.1.2 christos /* Merge non-visibility st_other attributes, STO_M68HC12_FAR and
212 1.1.1.2 christos STO_M68HC12_INTERRUPT. */
213 1.1.1.2 christos
214 1.1.1.2 christos void
215 1.1.1.2 christos elf32_m68hc11_merge_symbol_attribute (struct elf_link_hash_entry *h,
216 1.1.1.2 christos const Elf_Internal_Sym *isym,
217 1.1.1.2 christos bfd_boolean definition,
218 1.1.1.2 christos bfd_boolean dynamic ATTRIBUTE_UNUSED)
219 1.1.1.2 christos {
220 1.1.1.2 christos if (definition)
221 1.1.1.2 christos h->other = ((isym->st_other & ~ELF_ST_VISIBILITY (-1))
222 1.1.1.2 christos | ELF_ST_VISIBILITY (h->other));
223 1.1.1.2 christos }
224 1.1.1.2 christos
225 1.1 christos /* External entry points for sizing and building linker stubs. */
226 1.1 christos
227 1.1 christos /* Set up various things so that we can make a list of input sections
228 1.1 christos for each output section included in the link. Returns -1 on error,
229 1.1 christos 0 when no stubs will be needed, and 1 on success. */
230 1.1 christos
231 1.1 christos int
232 1.1 christos elf32_m68hc11_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info)
233 1.1 christos {
234 1.1 christos bfd *input_bfd;
235 1.1 christos unsigned int bfd_count;
236 1.1 christos int top_id, top_index;
237 1.1 christos asection *section;
238 1.1 christos asection **input_list, **list;
239 1.1 christos bfd_size_type amt;
240 1.1 christos asection *text_section;
241 1.1 christos struct m68hc11_elf_link_hash_table *htab;
242 1.1 christos
243 1.1 christos htab = m68hc11_elf_hash_table (info);
244 1.1 christos if (htab == NULL)
245 1.1 christos return -1;
246 1.1 christos
247 1.1 christos if (bfd_get_flavour (info->output_bfd) != bfd_target_elf_flavour)
248 1.1 christos return 0;
249 1.1 christos
250 1.1 christos /* Count the number of input BFDs and find the top input section id.
251 1.1 christos Also search for an existing ".tramp" section so that we know
252 1.1 christos where generated trampolines must go. Default to ".text" if we
253 1.1 christos can't find it. */
254 1.1 christos htab->tramp_section = 0;
255 1.1 christos text_section = 0;
256 1.1 christos for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
257 1.1 christos input_bfd != NULL;
258 1.1 christos input_bfd = input_bfd->link_next)
259 1.1 christos {
260 1.1 christos bfd_count += 1;
261 1.1 christos for (section = input_bfd->sections;
262 1.1 christos section != NULL;
263 1.1 christos section = section->next)
264 1.1 christos {
265 1.1 christos const char* name = bfd_get_section_name (input_bfd, section);
266 1.1 christos
267 1.1 christos if (!strcmp (name, ".tramp"))
268 1.1 christos htab->tramp_section = section;
269 1.1 christos
270 1.1 christos if (!strcmp (name, ".text"))
271 1.1 christos text_section = section;
272 1.1 christos
273 1.1 christos if (top_id < section->id)
274 1.1 christos top_id = section->id;
275 1.1 christos }
276 1.1 christos }
277 1.1 christos htab->bfd_count = bfd_count;
278 1.1 christos if (htab->tramp_section == 0)
279 1.1 christos htab->tramp_section = text_section;
280 1.1 christos
281 1.1 christos /* We can't use output_bfd->section_count here to find the top output
282 1.1 christos section index as some sections may have been removed, and
283 1.1 christos strip_excluded_output_sections doesn't renumber the indices. */
284 1.1 christos for (section = output_bfd->sections, top_index = 0;
285 1.1 christos section != NULL;
286 1.1 christos section = section->next)
287 1.1 christos {
288 1.1 christos if (top_index < section->index)
289 1.1 christos top_index = section->index;
290 1.1 christos }
291 1.1 christos
292 1.1 christos htab->top_index = top_index;
293 1.1 christos amt = sizeof (asection *) * (top_index + 1);
294 1.1 christos input_list = (asection **) bfd_malloc (amt);
295 1.1 christos htab->input_list = input_list;
296 1.1 christos if (input_list == NULL)
297 1.1 christos return -1;
298 1.1 christos
299 1.1 christos /* For sections we aren't interested in, mark their entries with a
300 1.1 christos value we can check later. */
301 1.1 christos list = input_list + top_index;
302 1.1 christos do
303 1.1 christos *list = bfd_abs_section_ptr;
304 1.1 christos while (list-- != input_list);
305 1.1 christos
306 1.1 christos for (section = output_bfd->sections;
307 1.1 christos section != NULL;
308 1.1 christos section = section->next)
309 1.1 christos {
310 1.1 christos if ((section->flags & SEC_CODE) != 0)
311 1.1 christos input_list[section->index] = NULL;
312 1.1 christos }
313 1.1 christos
314 1.1 christos return 1;
315 1.1 christos }
316 1.1 christos
317 1.1 christos /* Determine and set the size of the stub section for a final link.
318 1.1 christos
319 1.1 christos The basic idea here is to examine all the relocations looking for
320 1.1 christos PC-relative calls to a target that is unreachable with a "bl"
321 1.1 christos instruction. */
322 1.1 christos
323 1.1 christos bfd_boolean
324 1.1 christos elf32_m68hc11_size_stubs (bfd *output_bfd, bfd *stub_bfd,
325 1.1 christos struct bfd_link_info *info,
326 1.1 christos asection * (*add_stub_section) (const char*, asection*))
327 1.1 christos {
328 1.1 christos bfd *input_bfd;
329 1.1 christos asection *section;
330 1.1 christos Elf_Internal_Sym *local_syms, **all_local_syms;
331 1.1 christos unsigned int bfd_indx, bfd_count;
332 1.1 christos bfd_size_type amt;
333 1.1 christos asection *stub_sec;
334 1.1 christos struct m68hc11_elf_link_hash_table *htab = m68hc11_elf_hash_table (info);
335 1.1 christos
336 1.1 christos if (htab == NULL)
337 1.1 christos return FALSE;
338 1.1 christos
339 1.1 christos /* Stash our params away. */
340 1.1 christos htab->stub_bfd = stub_bfd;
341 1.1 christos htab->add_stub_section = add_stub_section;
342 1.1 christos
343 1.1 christos /* Count the number of input BFDs and find the top input section id. */
344 1.1 christos for (input_bfd = info->input_bfds, bfd_count = 0;
345 1.1 christos input_bfd != NULL;
346 1.1 christos input_bfd = input_bfd->link_next)
347 1.1 christos bfd_count += 1;
348 1.1 christos
349 1.1 christos /* We want to read in symbol extension records only once. To do this
350 1.1 christos we need to read in the local symbols in parallel and save them for
351 1.1 christos later use; so hold pointers to the local symbols in an array. */
352 1.1 christos amt = sizeof (Elf_Internal_Sym *) * bfd_count;
353 1.1 christos all_local_syms = (Elf_Internal_Sym **) bfd_zmalloc (amt);
354 1.1 christos if (all_local_syms == NULL)
355 1.1 christos return FALSE;
356 1.1 christos
357 1.1 christos /* Walk over all the input BFDs, swapping in local symbols. */
358 1.1 christos for (input_bfd = info->input_bfds, bfd_indx = 0;
359 1.1 christos input_bfd != NULL;
360 1.1 christos input_bfd = input_bfd->link_next, bfd_indx++)
361 1.1 christos {
362 1.1 christos Elf_Internal_Shdr *symtab_hdr;
363 1.1 christos
364 1.1 christos /* We'll need the symbol table in a second. */
365 1.1 christos symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
366 1.1 christos if (symtab_hdr->sh_info == 0)
367 1.1 christos continue;
368 1.1 christos
369 1.1 christos /* We need an array of the local symbols attached to the input bfd. */
370 1.1 christos local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
371 1.1 christos if (local_syms == NULL)
372 1.1 christos {
373 1.1 christos local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
374 1.1 christos symtab_hdr->sh_info, 0,
375 1.1 christos NULL, NULL, NULL);
376 1.1 christos /* Cache them for elf_link_input_bfd. */
377 1.1 christos symtab_hdr->contents = (unsigned char *) local_syms;
378 1.1 christos }
379 1.1 christos if (local_syms == NULL)
380 1.1 christos {
381 1.1 christos free (all_local_syms);
382 1.1 christos return FALSE;
383 1.1 christos }
384 1.1 christos
385 1.1 christos all_local_syms[bfd_indx] = local_syms;
386 1.1 christos }
387 1.1 christos
388 1.1 christos for (input_bfd = info->input_bfds, bfd_indx = 0;
389 1.1 christos input_bfd != NULL;
390 1.1 christos input_bfd = input_bfd->link_next, bfd_indx++)
391 1.1 christos {
392 1.1 christos Elf_Internal_Shdr *symtab_hdr;
393 1.1 christos struct elf_link_hash_entry ** sym_hashes;
394 1.1 christos
395 1.1 christos sym_hashes = elf_sym_hashes (input_bfd);
396 1.1 christos
397 1.1 christos /* We'll need the symbol table in a second. */
398 1.1 christos symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
399 1.1 christos if (symtab_hdr->sh_info == 0)
400 1.1 christos continue;
401 1.1 christos
402 1.1 christos local_syms = all_local_syms[bfd_indx];
403 1.1 christos
404 1.1 christos /* Walk over each section attached to the input bfd. */
405 1.1 christos for (section = input_bfd->sections;
406 1.1 christos section != NULL;
407 1.1 christos section = section->next)
408 1.1 christos {
409 1.1 christos Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
410 1.1 christos
411 1.1 christos /* If there aren't any relocs, then there's nothing more
412 1.1 christos to do. */
413 1.1 christos if ((section->flags & SEC_RELOC) == 0
414 1.1 christos || section->reloc_count == 0)
415 1.1 christos continue;
416 1.1 christos
417 1.1 christos /* If this section is a link-once section that will be
418 1.1 christos discarded, then don't create any stubs. */
419 1.1 christos if (section->output_section == NULL
420 1.1 christos || section->output_section->owner != output_bfd)
421 1.1 christos continue;
422 1.1 christos
423 1.1 christos /* Get the relocs. */
424 1.1 christos internal_relocs
425 1.1 christos = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
426 1.1 christos (Elf_Internal_Rela *) NULL,
427 1.1 christos info->keep_memory);
428 1.1 christos if (internal_relocs == NULL)
429 1.1 christos goto error_ret_free_local;
430 1.1 christos
431 1.1 christos /* Now examine each relocation. */
432 1.1 christos irela = internal_relocs;
433 1.1 christos irelaend = irela + section->reloc_count;
434 1.1 christos for (; irela < irelaend; irela++)
435 1.1 christos {
436 1.1 christos unsigned int r_type, r_indx;
437 1.1 christos struct elf32_m68hc11_stub_hash_entry *stub_entry;
438 1.1 christos asection *sym_sec;
439 1.1 christos bfd_vma sym_value;
440 1.1 christos struct elf_link_hash_entry *hash;
441 1.1 christos const char *stub_name;
442 1.1 christos Elf_Internal_Sym *sym;
443 1.1 christos
444 1.1 christos r_type = ELF32_R_TYPE (irela->r_info);
445 1.1 christos
446 1.1 christos /* Only look at 16-bit relocs. */
447 1.1 christos if (r_type != (unsigned int) R_M68HC11_16)
448 1.1 christos continue;
449 1.1 christos
450 1.1 christos /* Now determine the call target, its name, value,
451 1.1 christos section. */
452 1.1 christos r_indx = ELF32_R_SYM (irela->r_info);
453 1.1 christos if (r_indx < symtab_hdr->sh_info)
454 1.1 christos {
455 1.1 christos /* It's a local symbol. */
456 1.1 christos Elf_Internal_Shdr *hdr;
457 1.1 christos bfd_boolean is_far;
458 1.1 christos
459 1.1 christos sym = local_syms + r_indx;
460 1.1 christos is_far = (sym && (sym->st_other & STO_M68HC12_FAR));
461 1.1 christos if (!is_far)
462 1.1 christos continue;
463 1.1 christos
464 1.1 christos if (sym->st_shndx >= elf_numsections (input_bfd))
465 1.1 christos sym_sec = NULL;
466 1.1 christos else
467 1.1 christos {
468 1.1 christos hdr = elf_elfsections (input_bfd)[sym->st_shndx];
469 1.1 christos sym_sec = hdr->bfd_section;
470 1.1 christos }
471 1.1 christos stub_name = (bfd_elf_string_from_elf_section
472 1.1 christos (input_bfd, symtab_hdr->sh_link,
473 1.1 christos sym->st_name));
474 1.1 christos sym_value = sym->st_value;
475 1.1 christos hash = NULL;
476 1.1 christos }
477 1.1 christos else
478 1.1 christos {
479 1.1 christos /* It's an external symbol. */
480 1.1 christos int e_indx;
481 1.1 christos
482 1.1 christos e_indx = r_indx - symtab_hdr->sh_info;
483 1.1 christos hash = (struct elf_link_hash_entry *)
484 1.1 christos (sym_hashes[e_indx]);
485 1.1 christos
486 1.1 christos while (hash->root.type == bfd_link_hash_indirect
487 1.1 christos || hash->root.type == bfd_link_hash_warning)
488 1.1 christos hash = ((struct elf_link_hash_entry *)
489 1.1 christos hash->root.u.i.link);
490 1.1 christos
491 1.1 christos if (hash->root.type == bfd_link_hash_defined
492 1.1 christos || hash->root.type == bfd_link_hash_defweak
493 1.1 christos || hash->root.type == bfd_link_hash_new)
494 1.1 christos {
495 1.1 christos if (!(hash->other & STO_M68HC12_FAR))
496 1.1 christos continue;
497 1.1 christos }
498 1.1 christos else if (hash->root.type == bfd_link_hash_undefweak)
499 1.1 christos {
500 1.1 christos continue;
501 1.1 christos }
502 1.1 christos else if (hash->root.type == bfd_link_hash_undefined)
503 1.1 christos {
504 1.1 christos continue;
505 1.1 christos }
506 1.1 christos else
507 1.1 christos {
508 1.1 christos bfd_set_error (bfd_error_bad_value);
509 1.1 christos goto error_ret_free_internal;
510 1.1 christos }
511 1.1 christos sym_sec = hash->root.u.def.section;
512 1.1 christos sym_value = hash->root.u.def.value;
513 1.1 christos stub_name = hash->root.root.string;
514 1.1 christos }
515 1.1 christos
516 1.1 christos if (!stub_name)
517 1.1 christos goto error_ret_free_internal;
518 1.1 christos
519 1.1 christos stub_entry = m68hc12_stub_hash_lookup
520 1.1 christos (htab->stub_hash_table,
521 1.1 christos stub_name,
522 1.1 christos FALSE, FALSE);
523 1.1 christos if (stub_entry == NULL)
524 1.1 christos {
525 1.1 christos if (add_stub_section == 0)
526 1.1 christos continue;
527 1.1 christos
528 1.1 christos stub_entry = m68hc12_add_stub (stub_name, section, htab);
529 1.1 christos if (stub_entry == NULL)
530 1.1 christos {
531 1.1 christos error_ret_free_internal:
532 1.1 christos if (elf_section_data (section)->relocs == NULL)
533 1.1 christos free (internal_relocs);
534 1.1 christos goto error_ret_free_local;
535 1.1 christos }
536 1.1 christos }
537 1.1 christos
538 1.1 christos stub_entry->target_value = sym_value;
539 1.1 christos stub_entry->target_section = sym_sec;
540 1.1 christos }
541 1.1 christos
542 1.1 christos /* We're done with the internal relocs, free them. */
543 1.1 christos if (elf_section_data (section)->relocs == NULL)
544 1.1 christos free (internal_relocs);
545 1.1 christos }
546 1.1 christos }
547 1.1 christos
548 1.1 christos if (add_stub_section)
549 1.1 christos {
550 1.1 christos /* OK, we've added some stubs. Find out the new size of the
551 1.1 christos stub sections. */
552 1.1 christos for (stub_sec = htab->stub_bfd->sections;
553 1.1 christos stub_sec != NULL;
554 1.1 christos stub_sec = stub_sec->next)
555 1.1 christos {
556 1.1 christos stub_sec->size = 0;
557 1.1 christos }
558 1.1 christos
559 1.1 christos bfd_hash_traverse (htab->stub_hash_table, htab->size_one_stub, htab);
560 1.1 christos }
561 1.1 christos free (all_local_syms);
562 1.1 christos return TRUE;
563 1.1 christos
564 1.1 christos error_ret_free_local:
565 1.1 christos free (all_local_syms);
566 1.1 christos return FALSE;
567 1.1 christos }
568 1.1 christos
569 1.1 christos /* Export the trampoline addresses in the symbol table. */
570 1.1 christos static bfd_boolean
571 1.1 christos m68hc11_elf_export_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
572 1.1 christos {
573 1.1 christos struct bfd_link_info *info;
574 1.1 christos struct m68hc11_elf_link_hash_table *htab;
575 1.1 christos struct elf32_m68hc11_stub_hash_entry *stub_entry;
576 1.1 christos char* name;
577 1.1 christos bfd_boolean result;
578 1.1 christos
579 1.1 christos info = (struct bfd_link_info *) in_arg;
580 1.1 christos htab = m68hc11_elf_hash_table (info);
581 1.1 christos if (htab == NULL)
582 1.1 christos return FALSE;
583 1.1 christos
584 1.1 christos /* Massage our args to the form they really have. */
585 1.1 christos stub_entry = (struct elf32_m68hc11_stub_hash_entry *) gen_entry;
586 1.1 christos
587 1.1 christos /* Generate the trampoline according to HC11 or HC12. */
588 1.1 christos result = (* htab->build_one_stub) (gen_entry, in_arg);
589 1.1 christos
590 1.1 christos /* Make a printable name that does not conflict with the real function. */
591 1.1 christos name = alloca (strlen (stub_entry->root.string) + 16);
592 1.1 christos sprintf (name, "tramp.%s", stub_entry->root.string);
593 1.1 christos
594 1.1 christos /* Export the symbol for debugging/disassembling. */
595 1.1 christos m68hc11_elf_set_symbol (htab->stub_bfd, info, name,
596 1.1 christos stub_entry->stub_offset,
597 1.1 christos stub_entry->stub_sec);
598 1.1 christos return result;
599 1.1 christos }
600 1.1 christos
601 1.1 christos /* Export a symbol or set its value and section. */
602 1.1 christos static void
603 1.1 christos m68hc11_elf_set_symbol (bfd *abfd, struct bfd_link_info *info,
604 1.1 christos const char *name, bfd_vma value, asection *sec)
605 1.1 christos {
606 1.1 christos struct elf_link_hash_entry *h;
607 1.1 christos
608 1.1 christos h = (struct elf_link_hash_entry *)
609 1.1 christos bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, FALSE);
610 1.1 christos if (h == NULL)
611 1.1 christos {
612 1.1 christos _bfd_generic_link_add_one_symbol (info, abfd,
613 1.1 christos name,
614 1.1 christos BSF_GLOBAL,
615 1.1 christos sec,
616 1.1 christos value,
617 1.1 christos (const char*) NULL,
618 1.1 christos TRUE, FALSE, NULL);
619 1.1 christos }
620 1.1 christos else
621 1.1 christos {
622 1.1 christos h->root.type = bfd_link_hash_defined;
623 1.1 christos h->root.u.def.value = value;
624 1.1 christos h->root.u.def.section = sec;
625 1.1 christos }
626 1.1 christos }
627 1.1 christos
628 1.1 christos
629 1.1 christos /* Build all the stubs associated with the current output file. The
630 1.1 christos stubs are kept in a hash table attached to the main linker hash
631 1.1 christos table. This function is called via m68hc12elf_finish in the
632 1.1 christos linker. */
633 1.1 christos
634 1.1 christos bfd_boolean
635 1.1 christos elf32_m68hc11_build_stubs (bfd *abfd, struct bfd_link_info *info)
636 1.1 christos {
637 1.1 christos asection *stub_sec;
638 1.1 christos struct bfd_hash_table *table;
639 1.1 christos struct m68hc11_elf_link_hash_table *htab;
640 1.1 christos struct m68hc11_scan_param param;
641 1.1 christos
642 1.1 christos m68hc11_elf_get_bank_parameters (info);
643 1.1 christos htab = m68hc11_elf_hash_table (info);
644 1.1 christos if (htab == NULL)
645 1.1 christos return FALSE;
646 1.1 christos
647 1.1 christos for (stub_sec = htab->stub_bfd->sections;
648 1.1 christos stub_sec != NULL;
649 1.1 christos stub_sec = stub_sec->next)
650 1.1 christos {
651 1.1 christos bfd_size_type size;
652 1.1 christos
653 1.1 christos /* Allocate memory to hold the linker stubs. */
654 1.1 christos size = stub_sec->size;
655 1.1 christos stub_sec->contents = (unsigned char *) bfd_zalloc (htab->stub_bfd, size);
656 1.1 christos if (stub_sec->contents == NULL && size != 0)
657 1.1 christos return FALSE;
658 1.1 christos stub_sec->size = 0;
659 1.1 christos }
660 1.1 christos
661 1.1 christos /* Build the stubs as directed by the stub hash table. */
662 1.1 christos table = htab->stub_hash_table;
663 1.1 christos bfd_hash_traverse (table, m68hc11_elf_export_one_stub, info);
664 1.1.1.2 christos
665 1.1 christos /* Scan the output sections to see if we use the memory banks.
666 1.1 christos If so, export the symbols that define how the memory banks
667 1.1 christos are mapped. This is used by gdb and the simulator to obtain
668 1.1 christos the information. It can be used by programs to burn the eprom
669 1.1 christos at the good addresses. */
670 1.1 christos param.use_memory_banks = FALSE;
671 1.1 christos param.pinfo = &htab->pinfo;
672 1.1 christos bfd_map_over_sections (abfd, scan_sections_for_abi, ¶m);
673 1.1 christos if (param.use_memory_banks)
674 1.1 christos {
675 1.1 christos m68hc11_elf_set_symbol (abfd, info, BFD_M68HC11_BANK_START_NAME,
676 1.1 christos htab->pinfo.bank_physical,
677 1.1 christos bfd_abs_section_ptr);
678 1.1 christos m68hc11_elf_set_symbol (abfd, info, BFD_M68HC11_BANK_VIRTUAL_NAME,
679 1.1 christos htab->pinfo.bank_virtual,
680 1.1 christos bfd_abs_section_ptr);
681 1.1 christos m68hc11_elf_set_symbol (abfd, info, BFD_M68HC11_BANK_SIZE_NAME,
682 1.1 christos htab->pinfo.bank_size,
683 1.1 christos bfd_abs_section_ptr);
684 1.1 christos }
685 1.1 christos
686 1.1 christos return TRUE;
687 1.1 christos }
688 1.1 christos
689 1.1 christos void
690 1.1 christos m68hc11_elf_get_bank_parameters (struct bfd_link_info *info)
691 1.1 christos {
692 1.1 christos unsigned i;
693 1.1 christos struct m68hc11_page_info *pinfo;
694 1.1 christos struct bfd_link_hash_entry *h;
695 1.1 christos struct m68hc11_elf_link_hash_table *htab;
696 1.1 christos
697 1.1 christos htab = m68hc11_elf_hash_table (info);
698 1.1 christos if (htab == NULL)
699 1.1 christos return;
700 1.1 christos
701 1.1 christos pinfo = & htab->pinfo;
702 1.1 christos if (pinfo->bank_param_initialized)
703 1.1 christos return;
704 1.1 christos
705 1.1 christos pinfo->bank_virtual = M68HC12_BANK_VIRT;
706 1.1 christos pinfo->bank_mask = M68HC12_BANK_MASK;
707 1.1 christos pinfo->bank_physical = M68HC12_BANK_BASE;
708 1.1 christos pinfo->bank_shift = M68HC12_BANK_SHIFT;
709 1.1 christos pinfo->bank_size = 1 << M68HC12_BANK_SHIFT;
710 1.1 christos
711 1.1 christos h = bfd_link_hash_lookup (info->hash, BFD_M68HC11_BANK_START_NAME,
712 1.1 christos FALSE, FALSE, TRUE);
713 1.1 christos if (h != (struct bfd_link_hash_entry*) NULL
714 1.1 christos && h->type == bfd_link_hash_defined)
715 1.1 christos pinfo->bank_physical = (h->u.def.value
716 1.1 christos + h->u.def.section->output_section->vma
717 1.1 christos + h->u.def.section->output_offset);
718 1.1 christos
719 1.1 christos h = bfd_link_hash_lookup (info->hash, BFD_M68HC11_BANK_VIRTUAL_NAME,
720 1.1 christos FALSE, FALSE, TRUE);
721 1.1 christos if (h != (struct bfd_link_hash_entry*) NULL
722 1.1 christos && h->type == bfd_link_hash_defined)
723 1.1 christos pinfo->bank_virtual = (h->u.def.value
724 1.1 christos + h->u.def.section->output_section->vma
725 1.1 christos + h->u.def.section->output_offset);
726 1.1 christos
727 1.1 christos h = bfd_link_hash_lookup (info->hash, BFD_M68HC11_BANK_SIZE_NAME,
728 1.1 christos FALSE, FALSE, TRUE);
729 1.1 christos if (h != (struct bfd_link_hash_entry*) NULL
730 1.1 christos && h->type == bfd_link_hash_defined)
731 1.1 christos pinfo->bank_size = (h->u.def.value
732 1.1 christos + h->u.def.section->output_section->vma
733 1.1 christos + h->u.def.section->output_offset);
734 1.1 christos
735 1.1 christos pinfo->bank_shift = 0;
736 1.1 christos for (i = pinfo->bank_size; i != 0; i >>= 1)
737 1.1 christos pinfo->bank_shift++;
738 1.1 christos pinfo->bank_shift--;
739 1.1 christos pinfo->bank_mask = (1 << pinfo->bank_shift) - 1;
740 1.1 christos pinfo->bank_physical_end = pinfo->bank_physical + pinfo->bank_size;
741 1.1 christos pinfo->bank_param_initialized = 1;
742 1.1 christos
743 1.1 christos h = bfd_link_hash_lookup (info->hash, "__far_trampoline", FALSE,
744 1.1 christos FALSE, TRUE);
745 1.1 christos if (h != (struct bfd_link_hash_entry*) NULL
746 1.1 christos && h->type == bfd_link_hash_defined)
747 1.1 christos pinfo->trampoline_addr = (h->u.def.value
748 1.1 christos + h->u.def.section->output_section->vma
749 1.1 christos + h->u.def.section->output_offset);
750 1.1 christos }
751 1.1 christos
752 1.1 christos /* Return 1 if the address is in banked memory.
753 1.1 christos This can be applied to a virtual address and to a physical address. */
754 1.1 christos int
755 1.1 christos m68hc11_addr_is_banked (struct m68hc11_page_info *pinfo, bfd_vma addr)
756 1.1 christos {
757 1.1 christos if (addr >= pinfo->bank_virtual)
758 1.1 christos return 1;
759 1.1 christos
760 1.1 christos if (addr >= pinfo->bank_physical && addr <= pinfo->bank_physical_end)
761 1.1 christos return 1;
762 1.1 christos
763 1.1 christos return 0;
764 1.1 christos }
765 1.1 christos
766 1.1 christos /* Return the physical address seen by the processor, taking
767 1.1 christos into account banked memory. */
768 1.1 christos bfd_vma
769 1.1 christos m68hc11_phys_addr (struct m68hc11_page_info *pinfo, bfd_vma addr)
770 1.1 christos {
771 1.1 christos if (addr < pinfo->bank_virtual)
772 1.1 christos return addr;
773 1.1 christos
774 1.1 christos /* Map the address to the memory bank. */
775 1.1 christos addr -= pinfo->bank_virtual;
776 1.1 christos addr &= pinfo->bank_mask;
777 1.1 christos addr += pinfo->bank_physical;
778 1.1 christos return addr;
779 1.1 christos }
780 1.1 christos
781 1.1 christos /* Return the page number corresponding to an address in banked memory. */
782 1.1 christos bfd_vma
783 1.1 christos m68hc11_phys_page (struct m68hc11_page_info *pinfo, bfd_vma addr)
784 1.1 christos {
785 1.1 christos if (addr < pinfo->bank_virtual)
786 1.1 christos return 0;
787 1.1 christos
788 1.1 christos /* Map the address to the memory bank. */
789 1.1 christos addr -= pinfo->bank_virtual;
790 1.1 christos addr >>= pinfo->bank_shift;
791 1.1 christos addr &= 0x0ff;
792 1.1 christos return addr;
793 1.1 christos }
794 1.1 christos
795 1.1 christos /* This function is used for relocs which are only used for relaxing,
796 1.1 christos which the linker should otherwise ignore. */
797 1.1 christos
798 1.1 christos bfd_reloc_status_type
799 1.1 christos m68hc11_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED,
800 1.1 christos arelent *reloc_entry,
801 1.1 christos asymbol *symbol ATTRIBUTE_UNUSED,
802 1.1 christos void *data ATTRIBUTE_UNUSED,
803 1.1 christos asection *input_section,
804 1.1 christos bfd *output_bfd,
805 1.1 christos char **error_message ATTRIBUTE_UNUSED)
806 1.1 christos {
807 1.1 christos if (output_bfd != NULL)
808 1.1 christos reloc_entry->address += input_section->output_offset;
809 1.1 christos return bfd_reloc_ok;
810 1.1 christos }
811 1.1 christos
812 1.1 christos bfd_reloc_status_type
813 1.1 christos m68hc11_elf_special_reloc (bfd *abfd ATTRIBUTE_UNUSED,
814 1.1 christos arelent *reloc_entry,
815 1.1 christos asymbol *symbol,
816 1.1 christos void *data ATTRIBUTE_UNUSED,
817 1.1 christos asection *input_section,
818 1.1 christos bfd *output_bfd,
819 1.1 christos char **error_message ATTRIBUTE_UNUSED)
820 1.1 christos {
821 1.1 christos if (output_bfd != (bfd *) NULL
822 1.1 christos && (symbol->flags & BSF_SECTION_SYM) == 0
823 1.1 christos && (! reloc_entry->howto->partial_inplace
824 1.1 christos || reloc_entry->addend == 0))
825 1.1 christos {
826 1.1 christos reloc_entry->address += input_section->output_offset;
827 1.1 christos return bfd_reloc_ok;
828 1.1 christos }
829 1.1 christos
830 1.1 christos if (output_bfd != NULL)
831 1.1 christos return bfd_reloc_continue;
832 1.1 christos
833 1.1 christos if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
834 1.1 christos return bfd_reloc_outofrange;
835 1.1 christos
836 1.1 christos abort();
837 1.1 christos }
838 1.1 christos
839 1.1 christos /* Look through the relocs for a section during the first phase.
840 1.1 christos Since we don't do .gots or .plts, we just need to consider the
841 1.1 christos virtual table relocs for gc. */
842 1.1 christos
843 1.1 christos bfd_boolean
844 1.1 christos elf32_m68hc11_check_relocs (bfd *abfd, struct bfd_link_info *info,
845 1.1 christos asection *sec, const Elf_Internal_Rela *relocs)
846 1.1 christos {
847 1.1 christos Elf_Internal_Shdr * symtab_hdr;
848 1.1 christos struct elf_link_hash_entry ** sym_hashes;
849 1.1 christos const Elf_Internal_Rela * rel;
850 1.1 christos const Elf_Internal_Rela * rel_end;
851 1.1 christos
852 1.1 christos if (info->relocatable)
853 1.1 christos return TRUE;
854 1.1 christos
855 1.1 christos symtab_hdr = & elf_tdata (abfd)->symtab_hdr;
856 1.1 christos sym_hashes = elf_sym_hashes (abfd);
857 1.1 christos rel_end = relocs + sec->reloc_count;
858 1.1 christos
859 1.1 christos for (rel = relocs; rel < rel_end; rel++)
860 1.1 christos {
861 1.1 christos struct elf_link_hash_entry * h;
862 1.1 christos unsigned long r_symndx;
863 1.1 christos
864 1.1 christos r_symndx = ELF32_R_SYM (rel->r_info);
865 1.1 christos
866 1.1 christos if (r_symndx < symtab_hdr->sh_info)
867 1.1 christos h = NULL;
868 1.1 christos else
869 1.1 christos {
870 1.1 christos h = sym_hashes [r_symndx - symtab_hdr->sh_info];
871 1.1 christos while (h->root.type == bfd_link_hash_indirect
872 1.1 christos || h->root.type == bfd_link_hash_warning)
873 1.1 christos h = (struct elf_link_hash_entry *) h->root.u.i.link;
874 1.1.1.3 christos
875 1.1.1.3 christos /* PR15323, ref flags aren't set for references in the same
876 1.1.1.3 christos object. */
877 1.1.1.3 christos h->root.non_ir_ref = 1;
878 1.1 christos }
879 1.1 christos
880 1.1 christos switch (ELF32_R_TYPE (rel->r_info))
881 1.1 christos {
882 1.1 christos /* This relocation describes the C++ object vtable hierarchy.
883 1.1 christos Reconstruct it for later use during GC. */
884 1.1 christos case R_M68HC11_GNU_VTINHERIT:
885 1.1 christos if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
886 1.1 christos return FALSE;
887 1.1 christos break;
888 1.1 christos
889 1.1 christos /* This relocation describes which C++ vtable entries are actually
890 1.1 christos used. Record for later use during GC. */
891 1.1 christos case R_M68HC11_GNU_VTENTRY:
892 1.1 christos BFD_ASSERT (h != NULL);
893 1.1 christos if (h != NULL
894 1.1 christos && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
895 1.1 christos return FALSE;
896 1.1 christos break;
897 1.1 christos }
898 1.1 christos }
899 1.1 christos
900 1.1 christos return TRUE;
901 1.1 christos }
902 1.1 christos
903 1.1 christos /* Relocate a 68hc11/68hc12 ELF section. */
904 1.1 christos bfd_boolean
905 1.1 christos elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
906 1.1 christos struct bfd_link_info *info,
907 1.1 christos bfd *input_bfd, asection *input_section,
908 1.1 christos bfd_byte *contents, Elf_Internal_Rela *relocs,
909 1.1 christos Elf_Internal_Sym *local_syms,
910 1.1 christos asection **local_sections)
911 1.1 christos {
912 1.1 christos Elf_Internal_Shdr *symtab_hdr;
913 1.1 christos struct elf_link_hash_entry **sym_hashes;
914 1.1 christos Elf_Internal_Rela *rel, *relend;
915 1.1 christos const char *name = NULL;
916 1.1 christos struct m68hc11_page_info *pinfo;
917 1.1 christos const struct elf_backend_data * const ebd = get_elf_backend_data (input_bfd);
918 1.1 christos struct m68hc11_elf_link_hash_table *htab;
919 1.1.1.2 christos unsigned long e_flags;
920 1.1 christos
921 1.1 christos symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
922 1.1 christos sym_hashes = elf_sym_hashes (input_bfd);
923 1.1.1.2 christos e_flags = elf_elfheader (input_bfd)->e_flags;
924 1.1 christos
925 1.1 christos htab = m68hc11_elf_hash_table (info);
926 1.1 christos if (htab == NULL)
927 1.1 christos return FALSE;
928 1.1 christos
929 1.1 christos /* Get memory bank parameters. */
930 1.1 christos m68hc11_elf_get_bank_parameters (info);
931 1.1 christos
932 1.1 christos pinfo = & htab->pinfo;
933 1.1 christos rel = relocs;
934 1.1 christos relend = relocs + input_section->reloc_count;
935 1.1 christos
936 1.1 christos for (; rel < relend; rel++)
937 1.1 christos {
938 1.1 christos int r_type;
939 1.1 christos arelent arel;
940 1.1 christos reloc_howto_type *howto;
941 1.1 christos unsigned long r_symndx;
942 1.1 christos Elf_Internal_Sym *sym;
943 1.1 christos asection *sec;
944 1.1 christos bfd_vma relocation = 0;
945 1.1 christos bfd_reloc_status_type r = bfd_reloc_undefined;
946 1.1 christos bfd_vma phys_page;
947 1.1 christos bfd_vma phys_addr;
948 1.1 christos bfd_vma insn_addr;
949 1.1 christos bfd_vma insn_page;
950 1.1 christos bfd_boolean is_far = FALSE;
951 1.1.1.2 christos bfd_boolean is_xgate_symbol = FALSE;
952 1.1.1.2 christos bfd_boolean is_section_symbol = FALSE;
953 1.1 christos struct elf_link_hash_entry *h;
954 1.1.1.2 christos bfd_vma val;
955 1.1 christos
956 1.1 christos r_symndx = ELF32_R_SYM (rel->r_info);
957 1.1 christos r_type = ELF32_R_TYPE (rel->r_info);
958 1.1 christos
959 1.1 christos if (r_type == R_M68HC11_GNU_VTENTRY
960 1.1.1.2 christos || r_type == R_M68HC11_GNU_VTINHERIT)
961 1.1 christos continue;
962 1.1 christos
963 1.1 christos (*ebd->elf_info_to_howto_rel) (input_bfd, &arel, rel);
964 1.1 christos howto = arel.howto;
965 1.1 christos
966 1.1 christos h = NULL;
967 1.1 christos sym = NULL;
968 1.1 christos sec = NULL;
969 1.1 christos if (r_symndx < symtab_hdr->sh_info)
970 1.1 christos {
971 1.1 christos sym = local_syms + r_symndx;
972 1.1 christos sec = local_sections[r_symndx];
973 1.1 christos relocation = (sec->output_section->vma
974 1.1 christos + sec->output_offset
975 1.1 christos + sym->st_value);
976 1.1 christos is_far = (sym && (sym->st_other & STO_M68HC12_FAR));
977 1.1.1.2 christos is_xgate_symbol = (sym && (sym->st_target_internal));
978 1.1.1.2 christos is_section_symbol = ELF_ST_TYPE (sym->st_info) & STT_SECTION;
979 1.1 christos }
980 1.1 christos else
981 1.1 christos {
982 1.1.1.3 christos bfd_boolean unresolved_reloc, warned, ignored;
983 1.1 christos
984 1.1 christos RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
985 1.1 christos r_symndx, symtab_hdr, sym_hashes,
986 1.1 christos h, sec, relocation, unresolved_reloc,
987 1.1.1.3 christos warned, ignored);
988 1.1 christos
989 1.1 christos is_far = (h && (h->other & STO_M68HC12_FAR));
990 1.1.1.2 christos is_xgate_symbol = (h && (h->target_internal));
991 1.1 christos }
992 1.1 christos
993 1.1.1.2 christos if (sec != NULL && discarded_section (sec))
994 1.1 christos RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
995 1.1.1.2 christos rel, 1, relend, howto, 0, contents);
996 1.1 christos
997 1.1 christos if (info->relocatable)
998 1.1 christos {
999 1.1 christos /* This is a relocatable link. We don't have to change
1000 1.1 christos anything, unless the reloc is against a section symbol,
1001 1.1 christos in which case we have to adjust according to where the
1002 1.1 christos section symbol winds up in the output section. */
1003 1.1 christos if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1004 1.1 christos rel->r_addend += sec->output_offset;
1005 1.1 christos continue;
1006 1.1 christos }
1007 1.1 christos
1008 1.1 christos if (h != NULL)
1009 1.1 christos name = h->root.root.string;
1010 1.1 christos else
1011 1.1 christos {
1012 1.1 christos name = (bfd_elf_string_from_elf_section
1013 1.1 christos (input_bfd, symtab_hdr->sh_link, sym->st_name));
1014 1.1 christos if (name == NULL || *name == '\0')
1015 1.1 christos name = bfd_section_name (input_bfd, sec);
1016 1.1 christos }
1017 1.1 christos
1018 1.1 christos if (is_far && ELF32_R_TYPE (rel->r_info) == R_M68HC11_16)
1019 1.1 christos {
1020 1.1 christos struct elf32_m68hc11_stub_hash_entry* stub;
1021 1.1 christos
1022 1.1 christos stub = m68hc12_stub_hash_lookup (htab->stub_hash_table,
1023 1.1 christos name, FALSE, FALSE);
1024 1.1 christos if (stub)
1025 1.1 christos {
1026 1.1 christos relocation = stub->stub_offset
1027 1.1 christos + stub->stub_sec->output_section->vma
1028 1.1 christos + stub->stub_sec->output_offset;
1029 1.1 christos is_far = FALSE;
1030 1.1 christos }
1031 1.1 christos }
1032 1.1 christos
1033 1.1 christos /* Do the memory bank mapping. */
1034 1.1 christos phys_addr = m68hc11_phys_addr (pinfo, relocation + rel->r_addend);
1035 1.1 christos phys_page = m68hc11_phys_page (pinfo, relocation + rel->r_addend);
1036 1.1 christos switch (r_type)
1037 1.1 christos {
1038 1.1.1.2 christos case R_M68HC12_LO8XG:
1039 1.1.1.2 christos /* This relocation is specific to XGATE IMM16 calls and will precede
1040 1.1.1.2 christos a HI8. tc-m68hc11 only generates them in pairs.
1041 1.1.1.2 christos Leave the relocation to the HI8XG step. */
1042 1.1.1.2 christos r = bfd_reloc_ok;
1043 1.1.1.2 christos r_type = R_M68HC11_NONE;
1044 1.1.1.2 christos break;
1045 1.1.1.2 christos
1046 1.1.1.2 christos case R_M68HC12_HI8XG:
1047 1.1.1.2 christos /* This relocation is specific to XGATE IMM16 calls and must follow
1048 1.1.1.2 christos a LO8XG. Does not actually check that it was a LO8XG.
1049 1.1.1.2 christos Adjusts high and low bytes. */
1050 1.1.1.2 christos relocation = phys_addr;
1051 1.1.1.2 christos if ((e_flags & E_M68HC11_XGATE_RAMOFFSET)
1052 1.1.1.2 christos && (relocation >= 0x2000))
1053 1.1.1.2 christos relocation += 0xc000; /* HARDCODED RAM offset for XGATE. */
1054 1.1.1.2 christos
1055 1.1.1.2 christos /* Fetch 16 bit value including low byte in previous insn. */
1056 1.1.1.2 christos val = (bfd_get_8 (input_bfd, (bfd_byte*) contents + rel->r_offset) << 8)
1057 1.1.1.2 christos | bfd_get_8 (input_bfd, (bfd_byte*) contents + rel->r_offset - 2);
1058 1.1.1.2 christos
1059 1.1.1.2 christos /* Add on value to preserve carry, then write zero to high byte. */
1060 1.1.1.2 christos relocation += val;
1061 1.1.1.2 christos
1062 1.1.1.2 christos /* Write out top byte. */
1063 1.1.1.2 christos bfd_put_8 (input_bfd, (relocation >> 8) & 0xff,
1064 1.1.1.2 christos (bfd_byte*) contents + rel->r_offset);
1065 1.1.1.2 christos
1066 1.1.1.2 christos /* Write out low byte to previous instruction. */
1067 1.1.1.2 christos bfd_put_8 (input_bfd, relocation & 0xff,
1068 1.1.1.2 christos (bfd_byte*) contents + rel->r_offset - 2);
1069 1.1.1.2 christos
1070 1.1.1.2 christos /* Mark as relocation completed. */
1071 1.1.1.2 christos r = bfd_reloc_ok;
1072 1.1.1.2 christos r_type = R_M68HC11_NONE;
1073 1.1.1.2 christos break;
1074 1.1.1.2 christos
1075 1.1.1.2 christos /* The HI8 and LO8 relocs are generated by %hi(expr) %lo(expr)
1076 1.1.1.2 christos assembler directives. %hi does not support carry. */
1077 1.1.1.2 christos case R_M68HC11_HI8:
1078 1.1.1.2 christos case R_M68HC11_LO8:
1079 1.1.1.2 christos relocation = phys_addr;
1080 1.1.1.2 christos break;
1081 1.1.1.2 christos
1082 1.1 christos case R_M68HC11_24:
1083 1.1 christos /* Reloc used by 68HC12 call instruction. */
1084 1.1 christos bfd_put_16 (input_bfd, phys_addr,
1085 1.1 christos (bfd_byte*) contents + rel->r_offset);
1086 1.1 christos bfd_put_8 (input_bfd, phys_page,
1087 1.1 christos (bfd_byte*) contents + rel->r_offset + 2);
1088 1.1 christos r = bfd_reloc_ok;
1089 1.1 christos r_type = R_M68HC11_NONE;
1090 1.1 christos break;
1091 1.1 christos
1092 1.1 christos case R_M68HC11_NONE:
1093 1.1 christos r = bfd_reloc_ok;
1094 1.1 christos break;
1095 1.1 christos
1096 1.1 christos case R_M68HC11_LO16:
1097 1.1 christos /* Reloc generated by %addr(expr) gas to obtain the
1098 1.1 christos address as mapped in the memory bank window. */
1099 1.1 christos relocation = phys_addr;
1100 1.1 christos break;
1101 1.1 christos
1102 1.1 christos case R_M68HC11_PAGE:
1103 1.1 christos /* Reloc generated by %page(expr) gas to obtain the
1104 1.1 christos page number associated with the address. */
1105 1.1 christos relocation = phys_page;
1106 1.1 christos break;
1107 1.1 christos
1108 1.1 christos case R_M68HC11_16:
1109 1.1 christos /* Get virtual address of instruction having the relocation. */
1110 1.1 christos if (is_far)
1111 1.1 christos {
1112 1.1 christos const char* msg;
1113 1.1 christos char* buf;
1114 1.1 christos msg = _("Reference to the far symbol `%s' using a wrong "
1115 1.1 christos "relocation may result in incorrect execution");
1116 1.1 christos buf = alloca (strlen (msg) + strlen (name) + 10);
1117 1.1 christos sprintf (buf, msg, name);
1118 1.1.1.2 christos
1119 1.1 christos (* info->callbacks->warning)
1120 1.1 christos (info, buf, name, input_bfd, NULL, rel->r_offset);
1121 1.1 christos }
1122 1.1 christos
1123 1.1 christos /* Get virtual address of instruction having the relocation. */
1124 1.1 christos insn_addr = input_section->output_section->vma
1125 1.1 christos + input_section->output_offset
1126 1.1 christos + rel->r_offset;
1127 1.1 christos
1128 1.1 christos insn_page = m68hc11_phys_page (pinfo, insn_addr);
1129 1.1 christos
1130 1.1.1.2 christos /* If we are linking an S12 instruction against an XGATE symbol, we
1131 1.1.1.2 christos need to change the offset of the symbol value so that it's correct
1132 1.1.1.2 christos from the S12's perspective. */
1133 1.1.1.2 christos if (is_xgate_symbol)
1134 1.1.1.2 christos {
1135 1.1.1.2 christos /* The ram in the global space is mapped to 0x2000 in the 16-bit
1136 1.1.1.2 christos address space for S12 and 0xE000 in the 16-bit address space
1137 1.1.1.2 christos for XGATE. */
1138 1.1.1.2 christos if (relocation >= 0xE000)
1139 1.1.1.2 christos {
1140 1.1.1.2 christos /* We offset the address by the difference
1141 1.1.1.2 christos between these two mappings. */
1142 1.1.1.2 christos relocation -= 0xC000;
1143 1.1.1.2 christos break;
1144 1.1.1.2 christos }
1145 1.1.1.2 christos else
1146 1.1.1.2 christos {
1147 1.1.1.2 christos const char * msg;
1148 1.1.1.2 christos char * buf;
1149 1.1.1.2 christos
1150 1.1.1.2 christos msg = _("XGATE address (%lx) is not within shared RAM"
1151 1.1.1.2 christos "(0xE000-0xFFFF), therefore you must manually offset "
1152 1.1.1.2 christos "the address, and possibly manage the page, in your "
1153 1.1.1.2 christos "code.");
1154 1.1.1.2 christos buf = alloca (strlen (msg) + 128);
1155 1.1.1.2 christos sprintf (buf, msg, phys_addr);
1156 1.1.1.2 christos if (!((*info->callbacks->warning) (info, buf, name, input_bfd,
1157 1.1.1.2 christos input_section, insn_addr)))
1158 1.1.1.2 christos return FALSE;
1159 1.1.1.2 christos break;
1160 1.1.1.2 christos }
1161 1.1.1.2 christos }
1162 1.1.1.2 christos
1163 1.1 christos if (m68hc11_addr_is_banked (pinfo, relocation + rel->r_addend)
1164 1.1 christos && m68hc11_addr_is_banked (pinfo, insn_addr)
1165 1.1.1.2 christos && phys_page != insn_page && !(e_flags & E_M68HC11_NO_BANK_WARNING))
1166 1.1 christos {
1167 1.1.1.2 christos const char * msg;
1168 1.1.1.2 christos char * buf;
1169 1.1 christos
1170 1.1 christos msg = _("banked address [%lx:%04lx] (%lx) is not in the same bank "
1171 1.1 christos "as current banked address [%lx:%04lx] (%lx)");
1172 1.1 christos
1173 1.1 christos buf = alloca (strlen (msg) + 128);
1174 1.1 christos sprintf (buf, msg, phys_page, phys_addr,
1175 1.1 christos (long) (relocation + rel->r_addend),
1176 1.1 christos insn_page, m68hc11_phys_addr (pinfo, insn_addr),
1177 1.1 christos (long) (insn_addr));
1178 1.1 christos if (!((*info->callbacks->warning)
1179 1.1 christos (info, buf, name, input_bfd, input_section,
1180 1.1 christos rel->r_offset)))
1181 1.1 christos return FALSE;
1182 1.1 christos break;
1183 1.1 christos }
1184 1.1.1.2 christos
1185 1.1 christos if (phys_page != 0 && insn_page == 0)
1186 1.1 christos {
1187 1.1.1.2 christos const char * msg;
1188 1.1.1.2 christos char * buf;
1189 1.1 christos
1190 1.1 christos msg = _("reference to a banked address [%lx:%04lx] in the "
1191 1.1 christos "normal address space at %04lx");
1192 1.1 christos
1193 1.1 christos buf = alloca (strlen (msg) + 128);
1194 1.1 christos sprintf (buf, msg, phys_page, phys_addr, insn_addr);
1195 1.1 christos if (!((*info->callbacks->warning)
1196 1.1 christos (info, buf, name, input_bfd, input_section,
1197 1.1 christos insn_addr)))
1198 1.1 christos return FALSE;
1199 1.1 christos
1200 1.1 christos relocation = phys_addr;
1201 1.1 christos break;
1202 1.1 christos }
1203 1.1 christos
1204 1.1 christos /* If this is a banked address use the phys_addr so that
1205 1.1 christos we stay in the banked window. */
1206 1.1 christos if (m68hc11_addr_is_banked (pinfo, relocation + rel->r_addend))
1207 1.1 christos relocation = phys_addr;
1208 1.1 christos break;
1209 1.1 christos }
1210 1.1.1.2 christos
1211 1.1.1.2 christos /* If we are linking an XGATE instruction against an S12 symbol, we
1212 1.1.1.2 christos need to change the offset of the symbol value so that it's correct
1213 1.1.1.2 christos from the XGATE's perspective. */
1214 1.1.1.2 christos if (!strcmp (howto->name, "R_XGATE_IMM8_LO")
1215 1.1.1.2 christos || !strcmp (howto->name, "R_XGATE_IMM8_HI"))
1216 1.1.1.2 christos {
1217 1.1.1.2 christos /* We can only offset S12 addresses that lie within the non-paged
1218 1.1.1.2 christos area of RAM. */
1219 1.1.1.2 christos if (!is_xgate_symbol && !is_section_symbol)
1220 1.1.1.2 christos {
1221 1.1.1.2 christos /* The ram in the global space is mapped to 0x2000 and stops at
1222 1.1.1.2 christos 0x4000 in the 16-bit address space for S12 and 0xE000 in the
1223 1.1.1.2 christos 16-bit address space for XGATE. */
1224 1.1.1.2 christos if (relocation >= 0x2000 && relocation < 0x4000)
1225 1.1.1.2 christos /* We offset the address by the difference
1226 1.1.1.2 christos between these two mappings. */
1227 1.1.1.2 christos relocation += 0xC000;
1228 1.1.1.2 christos else
1229 1.1.1.2 christos {
1230 1.1.1.2 christos const char * msg;
1231 1.1.1.2 christos char * buf;
1232 1.1.1.2 christos
1233 1.1.1.2 christos /* Get virtual address of instruction having the relocation. */
1234 1.1.1.2 christos insn_addr = input_section->output_section->vma
1235 1.1.1.2 christos + input_section->output_offset + rel->r_offset;
1236 1.1.1.2 christos
1237 1.1.1.2 christos msg = _("S12 address (%lx) is not within shared RAM"
1238 1.1.1.2 christos "(0x2000-0x4000), therefore you must manually "
1239 1.1.1.2 christos "offset the address in your code");
1240 1.1.1.2 christos buf = alloca (strlen (msg) + 128);
1241 1.1.1.2 christos sprintf (buf, msg, phys_addr);
1242 1.1.1.2 christos if (!((*info->callbacks->warning) (info, buf, name, input_bfd,
1243 1.1.1.2 christos input_section, insn_addr)))
1244 1.1.1.2 christos return FALSE;
1245 1.1.1.2 christos break;
1246 1.1.1.2 christos }
1247 1.1.1.2 christos }
1248 1.1.1.2 christos }
1249 1.1.1.2 christos
1250 1.1 christos if (r_type != R_M68HC11_NONE)
1251 1.1.1.2 christos {
1252 1.1.1.2 christos if ((r_type == R_M68HC12_PCREL_9) || (r_type == R_M68HC12_PCREL_10))
1253 1.1.1.2 christos r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1254 1.1 christos contents, rel->r_offset,
1255 1.1.1.2 christos relocation - 2, rel->r_addend);
1256 1.1.1.2 christos else
1257 1.1.1.2 christos r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1258 1.1.1.2 christos contents, rel->r_offset,
1259 1.1.1.2 christos relocation, rel->r_addend);
1260 1.1.1.2 christos }
1261 1.1 christos
1262 1.1 christos if (r != bfd_reloc_ok)
1263 1.1 christos {
1264 1.1 christos const char * msg = (const char *) 0;
1265 1.1 christos
1266 1.1 christos switch (r)
1267 1.1 christos {
1268 1.1 christos case bfd_reloc_overflow:
1269 1.1 christos if (!((*info->callbacks->reloc_overflow)
1270 1.1 christos (info, NULL, name, howto->name, (bfd_vma) 0,
1271 1.1 christos input_bfd, input_section, rel->r_offset)))
1272 1.1 christos return FALSE;
1273 1.1 christos break;
1274 1.1 christos
1275 1.1 christos case bfd_reloc_undefined:
1276 1.1 christos if (!((*info->callbacks->undefined_symbol)
1277 1.1 christos (info, name, input_bfd, input_section,
1278 1.1 christos rel->r_offset, TRUE)))
1279 1.1 christos return FALSE;
1280 1.1 christos break;
1281 1.1 christos
1282 1.1 christos case bfd_reloc_outofrange:
1283 1.1 christos msg = _ ("internal error: out of range error");
1284 1.1 christos goto common_error;
1285 1.1 christos
1286 1.1 christos case bfd_reloc_notsupported:
1287 1.1 christos msg = _ ("internal error: unsupported relocation error");
1288 1.1 christos goto common_error;
1289 1.1 christos
1290 1.1 christos case bfd_reloc_dangerous:
1291 1.1 christos msg = _ ("internal error: dangerous error");
1292 1.1 christos goto common_error;
1293 1.1 christos
1294 1.1 christos default:
1295 1.1 christos msg = _ ("internal error: unknown error");
1296 1.1 christos /* fall through */
1297 1.1 christos
1298 1.1 christos common_error:
1299 1.1 christos if (!((*info->callbacks->warning)
1300 1.1 christos (info, msg, name, input_bfd, input_section,
1301 1.1 christos rel->r_offset)))
1302 1.1 christos return FALSE;
1303 1.1 christos break;
1304 1.1 christos }
1305 1.1 christos }
1306 1.1 christos }
1307 1.1 christos
1308 1.1 christos return TRUE;
1309 1.1 christos }
1310 1.1 christos
1311 1.1 christos
1312 1.1 christos
1313 1.1 christos /* Set and control ELF flags in ELF header. */
1315 1.1 christos
1316 1.1 christos bfd_boolean
1317 1.1 christos _bfd_m68hc11_elf_set_private_flags (bfd *abfd, flagword flags)
1318 1.1 christos {
1319 1.1 christos BFD_ASSERT (!elf_flags_init (abfd)
1320 1.1 christos || elf_elfheader (abfd)->e_flags == flags);
1321 1.1 christos
1322 1.1 christos elf_elfheader (abfd)->e_flags = flags;
1323 1.1 christos elf_flags_init (abfd) = TRUE;
1324 1.1 christos return TRUE;
1325 1.1 christos }
1326 1.1 christos
1327 1.1 christos /* Merge backend specific data from an object file to the output
1328 1.1 christos object file when linking. */
1329 1.1 christos
1330 1.1 christos bfd_boolean
1331 1.1 christos _bfd_m68hc11_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
1332 1.1 christos {
1333 1.1 christos flagword old_flags;
1334 1.1 christos flagword new_flags;
1335 1.1 christos bfd_boolean ok = TRUE;
1336 1.1.1.2 christos
1337 1.1 christos /* Check if we have the same endianness */
1338 1.1 christos if (!_bfd_generic_verify_endian_match (ibfd, obfd))
1339 1.1 christos return FALSE;
1340 1.1 christos
1341 1.1 christos if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1342 1.1 christos || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1343 1.1 christos return TRUE;
1344 1.1 christos
1345 1.1 christos new_flags = elf_elfheader (ibfd)->e_flags;
1346 1.1 christos elf_elfheader (obfd)->e_flags |= new_flags & EF_M68HC11_ABI;
1347 1.1 christos old_flags = elf_elfheader (obfd)->e_flags;
1348 1.1 christos
1349 1.1 christos if (! elf_flags_init (obfd))
1350 1.1 christos {
1351 1.1 christos elf_flags_init (obfd) = TRUE;
1352 1.1 christos elf_elfheader (obfd)->e_flags = new_flags;
1353 1.1 christos elf_elfheader (obfd)->e_ident[EI_CLASS]
1354 1.1 christos = elf_elfheader (ibfd)->e_ident[EI_CLASS];
1355 1.1 christos
1356 1.1 christos if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
1357 1.1 christos && bfd_get_arch_info (obfd)->the_default)
1358 1.1 christos {
1359 1.1 christos if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
1360 1.1 christos bfd_get_mach (ibfd)))
1361 1.1 christos return FALSE;
1362 1.1 christos }
1363 1.1 christos
1364 1.1 christos return TRUE;
1365 1.1 christos }
1366 1.1 christos
1367 1.1 christos /* Check ABI compatibility. */
1368 1.1 christos if ((new_flags & E_M68HC11_I32) != (old_flags & E_M68HC11_I32))
1369 1.1 christos {
1370 1.1 christos (*_bfd_error_handler)
1371 1.1 christos (_("%B: linking files compiled for 16-bit integers (-mshort) "
1372 1.1 christos "and others for 32-bit integers"), ibfd);
1373 1.1 christos ok = FALSE;
1374 1.1 christos }
1375 1.1 christos if ((new_flags & E_M68HC11_F64) != (old_flags & E_M68HC11_F64))
1376 1.1 christos {
1377 1.1 christos (*_bfd_error_handler)
1378 1.1 christos (_("%B: linking files compiled for 32-bit double (-fshort-double) "
1379 1.1 christos "and others for 64-bit double"), ibfd);
1380 1.1 christos ok = FALSE;
1381 1.1 christos }
1382 1.1 christos
1383 1.1 christos /* Processor compatibility. */
1384 1.1 christos if (!EF_M68HC11_CAN_MERGE_MACH (new_flags, old_flags))
1385 1.1 christos {
1386 1.1 christos (*_bfd_error_handler)
1387 1.1 christos (_("%B: linking files compiled for HCS12 with "
1388 1.1 christos "others compiled for HC12"), ibfd);
1389 1.1 christos ok = FALSE;
1390 1.1 christos }
1391 1.1 christos new_flags = ((new_flags & ~EF_M68HC11_MACH_MASK)
1392 1.1 christos | (EF_M68HC11_MERGE_MACH (new_flags, old_flags)));
1393 1.1 christos
1394 1.1 christos elf_elfheader (obfd)->e_flags = new_flags;
1395 1.1 christos
1396 1.1 christos new_flags &= ~(EF_M68HC11_ABI | EF_M68HC11_MACH_MASK);
1397 1.1 christos old_flags &= ~(EF_M68HC11_ABI | EF_M68HC11_MACH_MASK);
1398 1.1 christos
1399 1.1 christos /* Warn about any other mismatches */
1400 1.1 christos if (new_flags != old_flags)
1401 1.1 christos {
1402 1.1 christos (*_bfd_error_handler)
1403 1.1 christos (_("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1404 1.1 christos ibfd, (unsigned long) new_flags, (unsigned long) old_flags);
1405 1.1 christos ok = FALSE;
1406 1.1 christos }
1407 1.1 christos
1408 1.1 christos if (! ok)
1409 1.1 christos {
1410 1.1 christos bfd_set_error (bfd_error_bad_value);
1411 1.1 christos return FALSE;
1412 1.1 christos }
1413 1.1 christos
1414 1.1 christos return TRUE;
1415 1.1 christos }
1416 1.1 christos
1417 1.1 christos bfd_boolean
1418 1.1 christos _bfd_m68hc11_elf_print_private_bfd_data (bfd *abfd, void *ptr)
1419 1.1 christos {
1420 1.1 christos FILE *file = (FILE *) ptr;
1421 1.1 christos
1422 1.1 christos BFD_ASSERT (abfd != NULL && ptr != NULL);
1423 1.1 christos
1424 1.1 christos /* Print normal ELF private data. */
1425 1.1 christos _bfd_elf_print_private_bfd_data (abfd, ptr);
1426 1.1 christos
1427 1.1 christos /* xgettext:c-format */
1428 1.1 christos fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
1429 1.1 christos
1430 1.1 christos if (elf_elfheader (abfd)->e_flags & E_M68HC11_I32)
1431 1.1 christos fprintf (file, _("[abi=32-bit int, "));
1432 1.1 christos else
1433 1.1 christos fprintf (file, _("[abi=16-bit int, "));
1434 1.1 christos
1435 1.1 christos if (elf_elfheader (abfd)->e_flags & E_M68HC11_F64)
1436 1.1 christos fprintf (file, _("64-bit double, "));
1437 1.1 christos else
1438 1.1 christos fprintf (file, _("32-bit double, "));
1439 1.1 christos
1440 1.1 christos if (strcmp (bfd_get_target (abfd), "elf32-m68hc11") == 0)
1441 1.1 christos fprintf (file, _("cpu=HC11]"));
1442 1.1 christos else if (elf_elfheader (abfd)->e_flags & EF_M68HCS12_MACH)
1443 1.1 christos fprintf (file, _("cpu=HCS12]"));
1444 1.1.1.2 christos else
1445 1.1 christos fprintf (file, _("cpu=HC12]"));
1446 1.1 christos
1447 1.1 christos if (elf_elfheader (abfd)->e_flags & E_M68HC12_BANKS)
1448 1.1 christos fprintf (file, _(" [memory=bank-model]"));
1449 1.1 christos else
1450 1.1 christos fprintf (file, _(" [memory=flat]"));
1451 1.1.1.2 christos
1452 1.1.1.2 christos if (elf_elfheader (abfd)->e_flags & E_M68HC11_XGATE_RAMOFFSET)
1453 1.1.1.2 christos fprintf (file, _(" [XGATE RAM offsetting]"));
1454 1.1 christos
1455 1.1 christos fputc ('\n', file);
1456 1.1 christos
1457 1.1 christos return TRUE;
1458 1.1 christos }
1459 1.1 christos
1460 1.1 christos static void scan_sections_for_abi (bfd *abfd ATTRIBUTE_UNUSED,
1461 1.1 christos asection *asect, void *arg)
1462 1.1 christos {
1463 1.1 christos struct m68hc11_scan_param* p = (struct m68hc11_scan_param*) arg;
1464 1.1 christos
1465 1.1 christos if (asect->vma >= p->pinfo->bank_virtual)
1466 1.1 christos p->use_memory_banks = TRUE;
1467 1.1.1.2 christos }
1468 1.1 christos
1469 1.1 christos /* Tweak the OSABI field of the elf header. */
1470 1.1 christos
1471 1.1 christos void
1472 1.1 christos elf32_m68hc11_post_process_headers (bfd *abfd, struct bfd_link_info *link_info)
1473 1.1 christos {
1474 1.1 christos struct m68hc11_scan_param param;
1475 1.1 christos struct m68hc11_elf_link_hash_table *htab;
1476 1.1 christos
1477 1.1 christos if (link_info == NULL)
1478 1.1 christos return;
1479 1.1 christos
1480 1.1 christos htab = m68hc11_elf_hash_table (link_info);
1481 1.1 christos if (htab == NULL)
1482 1.1 christos return;
1483 1.1 christos
1484 1.1 christos m68hc11_elf_get_bank_parameters (link_info);
1485 1.1 christos
1486 1.1 christos param.use_memory_banks = FALSE;
1487 1.1 christos param.pinfo = & htab->pinfo;
1488 1.1 christos
1489 1.1 christos bfd_map_over_sections (abfd, scan_sections_for_abi, ¶m);
1490 1.1 christos
1491 1.1 christos if (param.use_memory_banks)
1492 1.1 christos {
1493 1.1 christos Elf_Internal_Ehdr * i_ehdrp;
1494 1.1 christos
1495 1.1 christos i_ehdrp = elf_elfheader (abfd);
1496 1.1 christos i_ehdrp->e_flags |= E_M68HC12_BANKS;
1497 1.1 christos }
1498 }
1499