1 /* BFD back-end for TMS320C30 a.out binaries.
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
4 Contributed by Steven Haworth (steve@pm.cse.rmit.edu.au)
6 This file is part of BFD, the Binary File Descriptor library.
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
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
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.
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
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 #define TARGET_IS_BIG_ENDIAN_P
24 #define N_HEADER_IN_TEXT(x) 1
25 #define TEXT_START_ADDR 1024
26 #define TARGET_PAGE_SIZE 128
27 #define SEGMENT_SIZE TARGET_PAGE_SIZE
28 #define DEFAULT_ARCH bfd_arch_tic30
31 /* Do not "beautify" the CONCAT* macro args. Traditional C will not
32 remove whitespace added here, and thus will fail to concatenate
34 #define MY(OP) CONCAT2 (tic30_aout_,OP)
35 #define TARGETNAME "a.out-tic30"
36 #define NAME(x,y) CONCAT3 (tic30_aout,_32_,y)
42 #include "aout/aout64.h"
43 #include "aout/stab_gnu.h"
46 static bfd_reloc_status_type tic30_aout_fix_16
47 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
48 static bfd_reloc_status_type tic30_aout_fix_32
49 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
50 static bfd_reloc_status_type tic30_aout_fix_pcrel_16
51 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
52 static reloc_howto_type *tic30_aout_reloc_howto
53 PARAMS ((bfd *, struct reloc_std_external *, int *, int *, int *));
54 static bfd_reloc_status_type tic30_aout_relocate_contents
55 PARAMS ((reloc_howto_type *, bfd *, bfd_vma, bfd_byte *));
56 static bfd_reloc_status_type tic30_aout_final_link_relocate
57 PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *, bfd_vma,
59 static const bfd_target *tic30_aout_object_p
61 static bfd_boolean tic30_aout_write_object_contents
63 static bfd_boolean tic30_aout_set_sizes
65 static const bfd_target * tic30_aout_callback
67 static bfd_boolean MY_bfd_copy_private_section_data
68 PARAMS ((bfd *, asection *, bfd *, asection *));
69 static bfd_boolean MY_bfd_final_link
70 PARAMS ((bfd *, struct bfd_link_info *));
71 reloc_howto_type * tic30_aout_reloc_type_lookup
72 PARAMS ((bfd *, bfd_reloc_code_real_type));
73 enum machine_type tic30_aout_machine_type
74 PARAMS ((enum bfd_architecture, unsigned long, bfd_boolean *));
75 bfd_boolean tic30_aout_set_arch_mach
76 PARAMS ((bfd *, enum bfd_architecture, unsigned long));
78 #define MY_reloc_howto(BFD, REL, IN, EX, PC) \
79 tic30_aout_reloc_howto(BFD, REL, &IN, &EX, &PC)
80 #define MY_final_link_relocate tic30_aout_final_link_relocate
81 #define MY_object_p tic30_aout_object_p
82 #define MY_mkobject NAME(aout,mkobject)
83 #define MY_write_object_contents tic30_aout_write_object_contents
84 #define MY_set_sizes tic30_aout_set_sizes
86 #ifndef MY_exec_hdr_flags
87 #define MY_exec_hdr_flags 1
90 #ifndef MY_backend_data
92 #ifndef MY_zmagic_contiguous
93 #define MY_zmagic_contiguous 0
95 #ifndef MY_text_includes_header
96 #define MY_text_includes_header 0
98 #ifndef MY_entry_is_text_address
99 #define MY_entry_is_text_address 0
101 #ifndef MY_exec_header_not_counted
102 #define MY_exec_header_not_counted 1
104 #ifndef MY_add_dynamic_symbols
105 #define MY_add_dynamic_symbols 0
107 #ifndef MY_add_one_symbol
108 #define MY_add_one_symbol 0
110 #ifndef MY_link_dynamic_object
111 #define MY_link_dynamic_object 0
113 #ifndef MY_write_dynamic_symbol
114 #define MY_write_dynamic_symbol 0
116 #ifndef MY_check_dynamic_reloc
117 #define MY_check_dynamic_reloc 0
119 #ifndef MY_finish_dynamic_link
120 #define MY_finish_dynamic_link 0
123 static const struct aout_backend_data tic30_aout_backend_data =
125 MY_zmagic_contiguous,
126 MY_text_includes_header,
127 MY_entry_is_text_address,
131 MY_exec_header_not_counted,
132 MY_add_dynamic_symbols,
134 MY_link_dynamic_object,
135 MY_write_dynamic_symbol,
136 MY_check_dynamic_reloc,
137 MY_finish_dynamic_link
139 #define MY_backend_data &tic30_aout_backend_data
142 /* FIXME: This is wrong. aoutx.h should really only be included by
147 /* This table lists the relocation types for the TMS320C30. There are
148 only a few relocations required, and all must be divided by 4 (>>
149 2) to get the 32-bit addresses in the format the TMS320C30 likes
151 reloc_howto_type tic30_aout_howto_table[] =
154 HOWTO (1, 2, 1, 16, FALSE, 0, 0, tic30_aout_fix_16,
155 "16", FALSE, 0x0000FFFF, 0x0000FFFF, FALSE),
156 HOWTO (2, 2, 2, 24, FALSE, 0, complain_overflow_bitfield, NULL,
157 "24", FALSE, 0x00FFFFFF, 0x00FFFFFF, FALSE),
158 HOWTO (3, 18, 3, 24, FALSE, 0, complain_overflow_bitfield, NULL,
159 "LDP", FALSE, 0x00FF0000, 0x000000FF, FALSE),
160 HOWTO (4, 2, 4, 32, FALSE, 0, complain_overflow_bitfield, tic30_aout_fix_32,
161 "32", FALSE, 0xFFFFFFFF, 0xFFFFFFFF, FALSE),
162 HOWTO (5, 2, 1, 16, TRUE, 0, complain_overflow_signed,
163 tic30_aout_fix_pcrel_16, "PCREL", TRUE, 0x0000FFFF, 0x0000FFFF, TRUE),
171 extern reloc_howto_type *NAME (aout, reloc_type_lookup)
172 PARAMS ((bfd *, bfd_reloc_code_real_type));
175 tic30_aout_reloc_type_lookup (abfd, code)
176 bfd *abfd ATTRIBUTE_UNUSED;
177 bfd_reloc_code_real_type code;
182 case BFD_RELOC_TIC30_LDP:
183 return &tic30_aout_howto_table[3];
185 return &tic30_aout_howto_table[1];
187 return &tic30_aout_howto_table[2];
188 case BFD_RELOC_16_PCREL:
189 return &tic30_aout_howto_table[5];
191 return &tic30_aout_howto_table[4];
193 return (reloc_howto_type *) NULL;
197 static reloc_howto_type *
198 tic30_aout_reloc_howto (abfd, relocs, r_index, r_extern, r_pcrel)
200 struct reloc_std_external *relocs;
205 unsigned int r_length;
206 unsigned int r_pcrel_done;
210 if (bfd_header_big_endian (abfd))
212 *r_index = ((relocs->r_index[0] << 16) | (relocs->r_index[1] << 8) | relocs->r_index[2]);
213 *r_extern = (0 != (relocs->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));
214 r_pcrel_done = (0 != (relocs->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
215 r_length = ((relocs->r_type[0] & RELOC_STD_BITS_LENGTH_BIG) >> RELOC_STD_BITS_LENGTH_SH_BIG);
219 *r_index = ((relocs->r_index[2] << 16) | (relocs->r_index[1] << 8) | relocs->r_index[0]);
220 *r_extern = (0 != (relocs->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));
221 r_pcrel_done = (0 != (relocs->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
222 r_length = ((relocs->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE) >> RELOC_STD_BITS_LENGTH_SH_LITTLE);
224 index = r_length + 4 * r_pcrel_done;
225 return tic30_aout_howto_table + index;
228 /* This function is used as a callback for 16-bit relocs. This is
229 required for relocations between segments. A line in aoutx.h
230 requires that any relocations for the data section should point to
231 the end of the aligned text section, plus an offset. By default,
232 this does not happen, therefore this function takes care of
235 static bfd_reloc_status_type
236 tic30_aout_fix_16 (abfd, reloc_entry, symbol, data, input_section, output_bfd, error_message)
238 arelent *reloc_entry;
241 asection *input_section ATTRIBUTE_UNUSED;
243 char **error_message ATTRIBUTE_UNUSED;
247 /* Make sure that the symbol's section is defined. */
248 if (symbol->section == &bfd_und_section && (symbol->flags & BSF_WEAK) == 0)
249 return output_bfd ? bfd_reloc_ok : bfd_reloc_undefined;
250 /* Get the size of the input section and turn it into the TMS320C30
251 32-bit address format. */
252 relocation = (symbol->section->vma >> 2);
253 relocation += bfd_get_16 (abfd, (bfd_byte *) data + reloc_entry->address);
254 bfd_put_16 (abfd, relocation, (bfd_byte *) data + reloc_entry->address);
258 /* This function does the same thing as tic30_aout_fix_16 except for 32
261 static bfd_reloc_status_type
262 tic30_aout_fix_32 (abfd, reloc_entry, symbol, data, input_section,
263 output_bfd, error_message)
265 arelent *reloc_entry;
268 asection *input_section ATTRIBUTE_UNUSED;
270 char **error_message ATTRIBUTE_UNUSED;
274 /* Make sure that the symbol's section is defined. */
275 if (symbol->section == &bfd_und_section && (symbol->flags & BSF_WEAK) == 0)
276 return output_bfd ? bfd_reloc_ok : bfd_reloc_undefined;
277 /* Get the size of the input section and turn it into the TMS320C30
278 32-bit address format. */
279 relocation = (symbol->section->vma >> 2);
280 relocation += bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
281 bfd_put_32 (abfd, relocation, (bfd_byte *) data + reloc_entry->address);
285 /* This function is used to work out pc-relative offsets for the
286 TMS320C30. The data already placed by md_pcrel_from within gas is
287 useless for a relocation, so we just get the offset value and place
288 a version of this within the object code.
289 tic30_aout_final_link_relocate will then calculate the required
290 relocation to add on to the value in the object code. */
292 static bfd_reloc_status_type
293 tic30_aout_fix_pcrel_16 (abfd, reloc_entry, symbol, data, input_section,
294 output_bfd, error_message)
296 arelent *reloc_entry;
297 asymbol *symbol ATTRIBUTE_UNUSED;
299 asection *input_section ATTRIBUTE_UNUSED;
300 bfd *output_bfd ATTRIBUTE_UNUSED;
301 char **error_message ATTRIBUTE_UNUSED;
303 bfd_vma relocation = 1;
304 bfd_byte offset_data = bfd_get_8 (abfd, (bfd_byte *) data + reloc_entry->address - 1);
306 /* The byte before the location of the fix contains bits 23-16 of
307 the pcrel instruction. Bit 21 is set for a delayed instruction
308 which requires on offset of 3 instead of 1. */
309 if (offset_data & 0x20)
313 bfd_put_16 (abfd, relocation, (bfd_byte *) data + reloc_entry->address);
317 /* These macros will get 24-bit values from the bfd definition.
319 #define bfd_getb_24(BFD,ADDR) \
320 (bfd_get_8 (BFD, ADDR ) << 16) | \
321 (bfd_get_8 (BFD, ADDR + 1) << 8) | \
322 (bfd_get_8 (BFD, ADDR + 2) )
324 #define bfd_putb_24(BFD,DATA,ADDR) \
325 bfd_put_8 (BFD, (bfd_byte) ((DATA >> 16) & 0xFF), ADDR ); \
326 bfd_put_8 (BFD, (bfd_byte) ((DATA >> 8) & 0xFF), ADDR + 1); \
327 bfd_put_8 (BFD, (bfd_byte) ( DATA & 0xFF), ADDR + 2)
329 /* Set parameters about this a.out file that are machine-dependent.
330 This routine is called from some_aout_object_p just before it returns. */
332 static const bfd_target *
333 tic30_aout_callback (abfd)
336 struct internal_exec *execp = exec_hdr (abfd);
337 unsigned int arch_align_power;
338 unsigned long arch_align;
340 /* Calculate the file positions of the parts of a newly read aout header. */
341 obj_textsec (abfd)->size = N_TXTSIZE (*execp);
343 /* The virtual memory addresses of the sections. */
344 obj_textsec (abfd)->vma = N_TXTADDR (*execp);
345 obj_datasec (abfd)->vma = N_DATADDR (*execp);
346 obj_bsssec (abfd)->vma = N_BSSADDR (*execp);
348 obj_textsec (abfd)->lma = obj_textsec (abfd)->vma;
349 obj_datasec (abfd)->lma = obj_datasec (abfd)->vma;
350 obj_bsssec (abfd)->lma = obj_bsssec (abfd)->vma;
352 /* The file offsets of the sections. */
353 obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
354 obj_datasec (abfd)->filepos = N_DATOFF (*execp);
356 /* The file offsets of the relocation info. */
357 obj_textsec (abfd)->rel_filepos = N_TRELOFF (*execp);
358 obj_datasec (abfd)->rel_filepos = N_DRELOFF (*execp);
360 /* The file offsets of the string table and symbol table. */
361 obj_sym_filepos (abfd) = N_SYMOFF (*execp);
362 obj_str_filepos (abfd) = N_STROFF (*execp);
364 /* Determine the architecture and machine type of the object file. */
366 SET_ARCH_MACH (abfd, *execp);
368 bfd_default_set_arch_mach (abfd, DEFAULT_ARCH, 0L);
371 /* Now that we know the architecture, set the alignments of the
372 sections. This is normally done by NAME(aout,new_section_hook),
373 but when the initial sections were created the architecture had
374 not yet been set. However, for backward compatibility, we don't
375 set the alignment power any higher than as required by the size
377 arch_align_power = bfd_get_arch_info (abfd)->section_align_power;
378 arch_align = 1 << arch_align_power;
379 if ((BFD_ALIGN (obj_textsec (abfd)->size, arch_align)
380 == obj_textsec (abfd)->size)
381 && (BFD_ALIGN (obj_datasec (abfd)->size, arch_align)
382 == obj_datasec (abfd)->size)
383 && (BFD_ALIGN (obj_bsssec (abfd)->size, arch_align)
384 == obj_bsssec (abfd)->size))
386 obj_textsec (abfd)->alignment_power = arch_align_power;
387 obj_datasec (abfd)->alignment_power = arch_align_power;
388 obj_bsssec (abfd)->alignment_power = arch_align_power;
393 static bfd_reloc_status_type
394 tic30_aout_final_link_relocate (howto, input_bfd, input_section, contents,
395 address, value, addend)
396 reloc_howto_type *howto;
398 asection *input_section;
407 sz = input_section->rawsize ? input_section->rawsize : input_section->size;
409 return bfd_reloc_outofrange;
411 relocation = value + addend;
412 if (howto->pc_relative)
414 relocation -= (input_section->output_section->vma + input_section->output_offset);
415 if (howto->pcrel_offset)
416 relocation -= address;
418 return tic30_aout_relocate_contents (howto, input_bfd, relocation,
422 bfd_reloc_status_type
423 tic30_aout_relocate_contents (howto, input_bfd, relocation, location)
424 reloc_howto_type *howto;
430 bfd_boolean overflow;
433 relocation = -relocation;
442 x = bfd_get_16 (input_bfd, location);
445 x = bfd_getb_24 (input_bfd, location);
448 x = bfd_get_8 (input_bfd, location);
451 x = bfd_get_32 (input_bfd, location);
457 if (howto->complain_on_overflow != complain_overflow_dont)
460 bfd_signed_vma signed_check;
462 bfd_signed_vma signed_add;
464 if (howto->rightshift == 0)
467 signed_check = (bfd_signed_vma) relocation;
471 check = relocation >> howto->rightshift;
472 if ((bfd_signed_vma) relocation >= 0)
473 signed_check = check;
475 signed_check = (check | ((bfd_vma) - 1 & ~((bfd_vma) - 1 >> howto->rightshift)));
477 add = x & howto->src_mask;
479 if ((add & (((~howto->src_mask) >> 1) & howto->src_mask)) != 0)
480 signed_add -= (((~howto->src_mask) >> 1) & howto->src_mask) << 1;
481 if (howto->bitpos == 0)
484 signed_check += signed_add;
488 check += add >> howto->bitpos;
490 signed_check += add >> howto->bitpos;
492 signed_check += ((add >> howto->bitpos) | ((bfd_vma) - 1 & ~((bfd_vma) - 1 >> howto->bitpos)));
494 switch (howto->complain_on_overflow)
496 case complain_overflow_signed:
498 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
499 bfd_signed_vma reloc_signed_min = ~reloc_signed_max;
500 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
504 case complain_overflow_unsigned:
506 bfd_vma reloc_unsigned_max = (((1 << (howto->bitsize - 1)) - 1) << 1) | 1;
507 if (check > reloc_unsigned_max)
511 case complain_overflow_bitfield:
513 bfd_vma reloc_bits = (((1 << (howto->bitsize - 1)) - 1) << 1) | 1;
514 if ((check & ~reloc_bits) != 0
515 && (((bfd_vma) signed_check & ~reloc_bits)
516 != ((bfd_vma) -1 & ~reloc_bits)))
524 relocation >>= (bfd_vma) howto->rightshift;
525 relocation <<= (bfd_vma) howto->bitpos;
526 x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + relocation) & howto->dst_mask));
534 bfd_put_16 (input_bfd, x, location);
537 bfd_putb_24 (input_bfd, x, location);
540 bfd_put_8 (input_bfd, x, location);
543 bfd_put_32 (input_bfd, x, location);
546 return overflow ? bfd_reloc_overflow : bfd_reloc_ok;
549 /* Finish up the reading of an a.out file header. */
551 static const bfd_target *
552 tic30_aout_object_p (abfd)
555 struct external_exec exec_bytes; /* Raw exec header from file. */
556 struct internal_exec exec; /* Cleaned-up exec header. */
557 const bfd_target *target;
558 bfd_size_type amt = EXEC_BYTES_SIZE;
560 if (bfd_bread ((PTR) &exec_bytes, amt, abfd) != amt)
562 if (bfd_get_error () != bfd_error_system_call)
563 bfd_set_error (bfd_error_wrong_format);
568 exec.a_info = SWAP_MAGIC (exec_bytes.e_info);
570 exec.a_info = H_GET_32 (abfd, exec_bytes.e_info);
571 #endif /* SWAP_MAGIC */
576 if (!(MACHTYPE_OK (N_MACHTYPE (exec))))
580 NAME (aout, swap_exec_header_in) (abfd, &exec_bytes, &exec);
583 /* swap_exec_header_in read in a_info with the wrong byte order */
584 exec.a_info = SWAP_MAGIC (exec_bytes.e_info);
585 #endif /* SWAP_MAGIC */
587 target = NAME (aout, some_aout_object_p) (abfd, &exec, tic30_aout_callback);
589 #ifdef ENTRY_CAN_BE_ZERO
590 /* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
591 means that it isn't obvious if EXEC_P should be set.
592 All of the following must be true for an executable:
593 There must be no relocations, the bfd can be neither an
594 archive nor an archive element, and the file must be executable. */
596 if (exec.a_trsize + exec.a_drsize == 0
597 && bfd_get_format (abfd) == bfd_object && abfd->my_archive == NULL)
601 #define S_IXUSR 0100 /* Execute by owner. */
603 if (stat (abfd->filename, &buf) == 0 && (buf.st_mode & S_IXUSR))
604 abfd->flags |= EXEC_P;
606 #endif /* ENTRY_CAN_BE_ZERO */
611 /* Copy private section data. This actually does nothing with the
612 sections. It copies the subformat field. We copy it here, because
613 we need to know whether this is a QMAGIC file before we set the
614 section contents, and copy_private_bfd_data is not called until
615 after the section contents have been set. */
618 MY_bfd_copy_private_section_data (ibfd, isec, obfd, osec)
620 asection *isec ATTRIBUTE_UNUSED;
622 asection *osec ATTRIBUTE_UNUSED;
624 if (bfd_get_flavour (obfd) == bfd_target_aout_flavour)
625 obj_aout_subformat (obfd) = obj_aout_subformat (ibfd);
629 /* Write an object file.
630 Section contents have already been written. We write the
631 file header, symbols, and relocation. */
634 tic30_aout_write_object_contents (abfd)
637 struct external_exec exec_bytes;
638 struct internal_exec *execp = exec_hdr (abfd);
640 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
643 bfd_size_type text_size; /* Dummy vars. */
646 if (adata (abfd).magic == undecided_magic)
647 NAME (aout, adjust_sizes_and_vmas) (abfd, &text_size, &text_end);
649 execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE;
650 execp->a_entry = bfd_get_start_address (abfd);
652 execp->a_trsize = ((obj_textsec (abfd)->reloc_count) * obj_reloc_entry_size (abfd));
653 execp->a_drsize = ((obj_datasec (abfd)->reloc_count) * obj_reloc_entry_size (abfd));
654 NAME (aout, swap_exec_header_out) (abfd, execp, &exec_bytes);
656 if (adata (abfd).exec_bytes_size > 0)
659 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
661 amt = adata (abfd).exec_bytes_size;
662 if (bfd_bwrite ((PTR) &exec_bytes, amt, abfd) != amt)
666 /* Now write out reloc info, followed by syms and strings. */
667 if (bfd_get_outsymbols (abfd) != (asymbol **) NULL
668 && bfd_get_symcount (abfd) != 0)
670 if (bfd_seek (abfd, (file_ptr) (N_SYMOFF (*execp)), SEEK_SET) != 0)
673 if (!NAME (aout, write_syms) (abfd))
677 if (bfd_seek (abfd, (file_ptr) (N_TRELOFF (*execp)), SEEK_SET) != 0)
679 if (!NAME (aout, squirt_out_relocs) (abfd, obj_textsec (abfd)))
682 if (bfd_seek (abfd, (file_ptr) (N_DRELOFF (*execp)), SEEK_SET) != 0)
684 if (!NAME (aout, squirt_out_relocs) (abfd, obj_datasec (abfd)))
692 tic30_aout_set_sizes (abfd)
695 adata (abfd).page_size = TARGET_PAGE_SIZE;
698 adata (abfd).segment_size = SEGMENT_SIZE;
700 adata (abfd).segment_size = TARGET_PAGE_SIZE;
703 #ifdef ZMAGIC_DISK_BLOCK_SIZE
704 adata (abfd).zmagic_disk_block_size = ZMAGIC_DISK_BLOCK_SIZE;
706 adata (abfd).zmagic_disk_block_size = TARGET_PAGE_SIZE;
709 adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
714 #ifndef MY_final_link_callback
716 /* Callback for the final_link routine to set the section offsets. */
718 static void MY_final_link_callback
719 PARAMS ((bfd *, file_ptr *, file_ptr *, file_ptr *));
722 MY_final_link_callback (abfd, ptreloff, pdreloff, psymoff)
728 struct internal_exec *execp = exec_hdr (abfd);
730 *ptreloff = obj_datasec (abfd)->filepos + execp->a_data;
731 *pdreloff = *ptreloff + execp->a_trsize;
732 *psymoff = *pdreloff + execp->a_drsize;;
737 #ifndef MY_bfd_final_link
739 /* Final link routine. We need to use a call back to get the correct
740 offsets in the output file. */
743 MY_bfd_final_link (abfd, info)
745 struct bfd_link_info *info;
747 struct internal_exec *execp = exec_hdr (abfd);
752 /* Set the executable header size to 0, as we don't want one for an
754 adata (abfd).exec_bytes_size = 0;
755 pos = adata (abfd).exec_bytes_size;
757 vma = info->create_object_symbols_section->vma;
759 obj_textsec (abfd)->filepos = pos;
760 obj_textsec (abfd)->vma = vma;
761 obj_textsec (abfd)->user_set_vma = 1;
762 pos += obj_textsec (abfd)->size;
763 vma += obj_textsec (abfd)->size;
766 if (abfd->flags & D_PAGED)
768 if (info->create_object_symbols_section->next->vma > 0)
769 obj_datasec (abfd)->vma = info->create_object_symbols_section->next->vma;
771 obj_datasec (abfd)->vma = BFD_ALIGN (vma, adata (abfd).segment_size);
775 obj_datasec (abfd)->vma = BFD_ALIGN (vma, 4);
778 if (obj_datasec (abfd)->vma < vma)
779 obj_datasec (abfd)->vma = BFD_ALIGN (vma, 4);
781 obj_datasec (abfd)->user_set_vma = 1;
782 vma = obj_datasec (abfd)->vma;
783 obj_datasec (abfd)->filepos = vma + adata (abfd).exec_bytes_size;
784 execp->a_text = vma - obj_textsec (abfd)->vma;
785 obj_textsec (abfd)->size = execp->a_text;
787 /* Since BSS follows data immediately, see if it needs alignment. */
788 vma += obj_datasec (abfd)->size;
789 pad = align_power (vma, obj_bsssec (abfd)->alignment_power) - vma;
790 obj_datasec (abfd)->size += pad;
791 pos += obj_datasec (abfd)->size;
792 execp->a_data = obj_datasec (abfd)->size;
795 obj_bsssec (abfd)->vma = vma;
796 obj_bsssec (abfd)->user_set_vma = 1;
798 /* We are fully resized, so don't readjust in final_link. */
799 adata (abfd).magic = z_magic;
801 return NAME (aout, final_link) (abfd, info, MY_final_link_callback);
807 tic30_aout_machine_type (arch, machine, unknown)
808 enum bfd_architecture arch;
809 unsigned long machine ATTRIBUTE_UNUSED;
810 bfd_boolean *unknown;
812 enum machine_type arch_flags;
814 arch_flags = M_UNKNOWN;
823 arch_flags = M_UNKNOWN;
825 if (arch_flags != M_UNKNOWN)
831 tic30_aout_set_arch_mach (abfd, arch, machine)
833 enum bfd_architecture arch;
834 unsigned long machine;
836 if (!bfd_default_set_arch_mach (abfd, arch, machine))
838 if (arch != bfd_arch_unknown)
841 tic30_aout_machine_type (arch, machine, &unknown);
845 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
846 return (*aout_backend_info (abfd)->set_sizes) (abfd);
849 /* We assume BFD generic archive files. */
850 #ifndef MY_openr_next_archived_file
851 #define MY_openr_next_archived_file bfd_generic_openr_next_archived_file
853 #ifndef MY_get_elt_at_index
854 #define MY_get_elt_at_index _bfd_generic_get_elt_at_index
856 #ifndef MY_generic_stat_arch_elt
857 #define MY_generic_stat_arch_elt bfd_generic_stat_arch_elt
859 #ifndef MY_slurp_armap
860 #define MY_slurp_armap bfd_slurp_bsd_armap
862 #ifndef MY_slurp_extended_name_table
863 #define MY_slurp_extended_name_table _bfd_slurp_extended_name_table
865 #ifndef MY_construct_extended_name_table
866 #define MY_construct_extended_name_table \
867 _bfd_archive_bsd_construct_extended_name_table
869 #ifndef MY_write_armap
870 #define MY_write_armap bsd_write_armap
872 #ifndef MY_read_ar_hdr
873 #define MY_read_ar_hdr _bfd_generic_read_ar_hdr
875 #ifndef MY_truncate_arname
876 #define MY_truncate_arname bfd_bsd_truncate_arname
878 #ifndef MY_update_armap_timestamp
879 #define MY_update_armap_timestamp _bfd_archive_bsd_update_armap_timestamp
882 /* No core file defined here -- configure in trad-core.c separately. */
883 #ifndef MY_core_file_failing_command
884 #define MY_core_file_failing_command _bfd_nocore_core_file_failing_command
886 #ifndef MY_core_file_failing_signal
887 #define MY_core_file_failing_signal _bfd_nocore_core_file_failing_signal
889 #ifndef MY_core_file_matches_executable_p
890 #define MY_core_file_matches_executable_p \
891 _bfd_nocore_core_file_matches_executable_p
893 #ifndef MY_core_file_p
894 #define MY_core_file_p _bfd_dummy_target
897 #ifndef MY_bfd_debug_info_start
898 #define MY_bfd_debug_info_start bfd_void
900 #ifndef MY_bfd_debug_info_end
901 #define MY_bfd_debug_info_end bfd_void
903 #ifndef MY_bfd_debug_info_accumulate
904 #define MY_bfd_debug_info_accumulate \
905 (void (*) PARAMS ((bfd*, struct bfd_section *))) bfd_void
908 #ifndef MY_core_file_failing_command
909 #define MY_core_file_failing_command NAME(aout,core_file_failing_command)
911 #ifndef MY_core_file_failing_signal
912 #define MY_core_file_failing_signal NAME(aout,core_file_failing_signal)
914 #ifndef MY_core_file_matches_executable_p
915 #define MY_core_file_matches_executable_p NAME(aout,core_file_matches_executable_p)
917 #ifndef MY_set_section_contents
918 #define MY_set_section_contents NAME(aout,set_section_contents)
920 #ifndef MY_get_section_contents
921 #define MY_get_section_contents aout_32_get_section_contents
923 #ifndef MY_get_section_contents_in_window
924 #define MY_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
926 #ifndef MY_new_section_hook
927 #define MY_new_section_hook NAME(aout,new_section_hook)
929 #ifndef MY_get_symtab_upper_bound
930 #define MY_get_symtab_upper_bound NAME(aout,get_symtab_upper_bound)
932 #ifndef MY_canonicalize_symtab
933 #define MY_canonicalize_symtab NAME(aout,canonicalize_symtab)
935 #ifndef MY_get_reloc_upper_bound
936 #define MY_get_reloc_upper_bound NAME(aout,get_reloc_upper_bound)
938 #ifndef MY_canonicalize_reloc
939 #define MY_canonicalize_reloc NAME(aout,canonicalize_reloc)
941 #ifndef MY_make_empty_symbol
942 #define MY_make_empty_symbol NAME(aout,make_empty_symbol)
944 #ifndef MY_print_symbol
945 #define MY_print_symbol NAME(aout,print_symbol)
947 #ifndef MY_get_symbol_info
948 #define MY_get_symbol_info NAME(aout,get_symbol_info)
950 #ifndef MY_get_lineno
951 #define MY_get_lineno NAME(aout,get_lineno)
953 #ifndef MY_set_arch_mach
954 #define MY_set_arch_mach tic30_aout_set_arch_mach
956 #ifndef MY_find_nearest_line
957 #define MY_find_nearest_line NAME(aout,find_nearest_line)
959 #ifndef MY_sizeof_headers
960 #define MY_sizeof_headers NAME(aout,sizeof_headers)
962 #ifndef MY_bfd_get_relocated_section_contents
963 #define MY_bfd_get_relocated_section_contents \
964 bfd_generic_get_relocated_section_contents
966 #ifndef MY_bfd_relax_section
967 #define MY_bfd_relax_section bfd_generic_relax_section
969 #ifndef MY_bfd_gc_sections
970 #define MY_bfd_gc_sections bfd_generic_gc_sections
972 #ifndef MY_bfd_merge_sections
973 #define MY_bfd_merge_sections bfd_generic_merge_sections
975 #ifndef MY_bfd_is_group_section
976 #define MY_bfd_is_group_section bfd_generic_is_group_section
978 #ifndef MY_bfd_discard_group
979 #define MY_bfd_discard_group bfd_generic_discard_group
981 #ifndef MY_bfd_reloc_type_lookup
982 #define MY_bfd_reloc_type_lookup tic30_aout_reloc_type_lookup
984 #ifndef MY_bfd_make_debug_symbol
985 #define MY_bfd_make_debug_symbol 0
987 #ifndef MY_read_minisymbols
988 #define MY_read_minisymbols NAME(aout,read_minisymbols)
990 #ifndef MY_minisymbol_to_symbol
991 #define MY_minisymbol_to_symbol NAME(aout,minisymbol_to_symbol)
993 #ifndef MY_bfd_link_hash_table_create
994 #define MY_bfd_link_hash_table_create NAME(aout,link_hash_table_create)
996 #ifndef MY_bfd_link_hash_table_free
997 #define MY_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
999 #ifndef MY_bfd_link_add_symbols
1000 #define MY_bfd_link_add_symbols NAME(aout,link_add_symbols)
1002 #ifndef MY_bfd_link_just_syms
1003 #define MY_bfd_link_just_syms _bfd_generic_link_just_syms
1005 #ifndef MY_bfd_link_split_section
1006 #define MY_bfd_link_split_section _bfd_generic_link_split_section
1009 #ifndef MY_bfd_copy_private_bfd_data
1010 #define MY_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
1013 #ifndef MY_bfd_merge_private_bfd_data
1014 #define MY_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
1017 #ifndef MY_bfd_copy_private_symbol_data
1018 #define MY_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
1021 #ifndef MY_bfd_copy_private_header_data
1022 #define MY_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
1025 #ifndef MY_bfd_print_private_bfd_data
1026 #define MY_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
1029 #ifndef MY_bfd_set_private_flags
1030 #define MY_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
1033 #ifndef MY_bfd_is_local_label_name
1034 #define MY_bfd_is_local_label_name bfd_generic_is_local_label_name
1037 #ifndef MY_bfd_free_cached_info
1038 #define MY_bfd_free_cached_info NAME(aout,bfd_free_cached_info)
1041 #ifndef MY_close_and_cleanup
1042 #define MY_close_and_cleanup MY_bfd_free_cached_info
1045 #ifndef MY_get_dynamic_symtab_upper_bound
1046 #define MY_get_dynamic_symtab_upper_bound \
1047 _bfd_nodynamic_get_dynamic_symtab_upper_bound
1049 #ifndef MY_canonicalize_dynamic_symtab
1050 #define MY_canonicalize_dynamic_symtab \
1051 _bfd_nodynamic_canonicalize_dynamic_symtab
1053 #ifndef MY_get_synthetic_symtab
1054 #define MY_get_synthetic_symtab \
1055 _bfd_nodynamic_get_synthetic_symtab
1057 #ifndef MY_get_dynamic_reloc_upper_bound
1058 #define MY_get_dynamic_reloc_upper_bound \
1059 _bfd_nodynamic_get_dynamic_reloc_upper_bound
1061 #ifndef MY_canonicalize_dynamic_reloc
1062 #define MY_canonicalize_dynamic_reloc \
1063 _bfd_nodynamic_canonicalize_dynamic_reloc
1066 /* Aout symbols normally have leading underscores */
1067 #ifndef MY_symbol_leading_char
1068 #define MY_symbol_leading_char '_'
1071 /* Aout archives normally use spaces for padding */
1073 #define AR_PAD_CHAR ' '
1076 #ifndef MY_BFD_TARGET
1077 const bfd_target tic30_aout_vec =
1079 TARGETNAME, /* name */
1080 bfd_target_aout_flavour,
1081 BFD_ENDIAN_BIG, /* target byte order (big) */
1082 BFD_ENDIAN_BIG, /* target headers byte order (big) */
1083 (HAS_RELOC | /* object flags */
1084 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
1085 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
1086 MY_symbol_leading_char,
1087 AR_PAD_CHAR, /* ar_pad_char */
1088 15, /* ar_max_namelen */
1089 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1090 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1091 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
1092 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1093 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1094 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
1095 {_bfd_dummy_target, MY_object_p, /* bfd_check_format */
1096 bfd_generic_archive_p, MY_core_file_p},
1097 {bfd_false, MY_mkobject, /* bfd_set_format */
1098 _bfd_generic_mkarchive, bfd_false},
1099 {bfd_false, MY_write_object_contents, /* bfd_write_contents */
1100 _bfd_write_archive_contents, bfd_false},
1102 BFD_JUMP_TABLE_GENERIC (MY),
1103 BFD_JUMP_TABLE_COPY (MY),
1104 BFD_JUMP_TABLE_CORE (MY),
1105 BFD_JUMP_TABLE_ARCHIVE (MY),
1106 BFD_JUMP_TABLE_SYMBOLS (MY),
1107 BFD_JUMP_TABLE_RELOCS (MY),
1108 BFD_JUMP_TABLE_WRITE (MY),
1109 BFD_JUMP_TABLE_LINK (MY),
1110 BFD_JUMP_TABLE_DYNAMIC (MY),
1114 (PTR) MY_backend_data
1116 #endif /* MY_BFD_TARGET */