/src/binutils-gdb/bfd/coff-tic30.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* BFD back-end for TMS320C30 coff binaries. |
2 | | Copyright (C) 1998-2025 Free Software Foundation, Inc. |
3 | | Contributed by Steven Haworth (steve@pm.cse.rmit.edu.au) |
4 | | |
5 | | This file is part of BFD, the Binary File Descriptor library. |
6 | | |
7 | | This program is free software; you can redistribute it and/or modify |
8 | | it under the terms of the GNU General Public License as published by |
9 | | the Free Software Foundation; either version 3 of the License, or |
10 | | (at your option) any later version. |
11 | | |
12 | | This program is distributed in the hope that it will be useful, |
13 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | GNU General Public License for more details. |
16 | | |
17 | | You should have received a copy of the GNU General Public License |
18 | | along with this program; if not, write to the Free Software |
19 | | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA |
20 | | 02110-1301, USA. */ |
21 | | |
22 | | #include "sysdep.h" |
23 | | #include "bfd.h" |
24 | | #include "libbfd.h" |
25 | | #include "bfdlink.h" |
26 | | #include "coff/tic30.h" |
27 | | #include "coff/internal.h" |
28 | | #include "libcoff.h" |
29 | | |
30 | 25.5M | #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (1) |
31 | | |
32 | | reloc_howto_type tic30_coff_howto_table[] = |
33 | | { |
34 | | HOWTO (R_TIC30_ABS16, 2, 2, 16, false, 0, 0, NULL, |
35 | | "16", false, 0x0000FFFF, 0x0000FFFF, false), |
36 | | HOWTO (R_TIC30_ABS24, 2, 4, 24, false, 8, complain_overflow_bitfield, NULL, |
37 | | "24", false, 0xFFFFFF00, 0xFFFFFF00, false), |
38 | | HOWTO (R_TIC30_LDP, 18, 1, 24, false, 0, complain_overflow_bitfield, NULL, |
39 | | "LDP", false, 0x00FF0000, 0x000000FF, false), |
40 | | HOWTO (R_TIC30_ABS32, 2, 4, 32, false, 0, complain_overflow_bitfield, NULL, |
41 | | "32", false, 0xFFFFFFFF, 0xFFFFFFFF, false), |
42 | | HOWTO (R_TIC30_PC16, 2, 2, 16, true, 0, complain_overflow_signed, NULL, |
43 | | "PCREL", false, 0x0000FFFF, 0x0000FFFF, false), |
44 | | EMPTY_HOWTO (-1) |
45 | | }; |
46 | | |
47 | | #ifndef coff_bfd_reloc_type_lookup |
48 | | #define coff_bfd_reloc_type_lookup tic30_coff_reloc_type_lookup |
49 | | #define coff_bfd_reloc_name_lookup tic30_coff_reloc_name_lookup |
50 | | |
51 | | /* For the case statement use the code values used in tc_gen_reloc to |
52 | | map to the howto table entries that match those in both the aout |
53 | | and coff implementations. */ |
54 | | |
55 | | static reloc_howto_type * |
56 | | tic30_coff_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
57 | | bfd_reloc_code_real_type code) |
58 | 0 | { |
59 | 0 | switch (code) |
60 | 0 | { |
61 | 0 | case BFD_RELOC_8: |
62 | 0 | case BFD_RELOC_TIC30_LDP: |
63 | 0 | return &tic30_coff_howto_table[2]; |
64 | 0 | case BFD_RELOC_16: |
65 | 0 | return &tic30_coff_howto_table[0]; |
66 | 0 | case BFD_RELOC_24: |
67 | 0 | return &tic30_coff_howto_table[1]; |
68 | 0 | case BFD_RELOC_16_PCREL: |
69 | 0 | return &tic30_coff_howto_table[4]; |
70 | 0 | case BFD_RELOC_32: |
71 | 0 | return &tic30_coff_howto_table[3]; |
72 | 0 | default: |
73 | 0 | return (reloc_howto_type *) NULL; |
74 | 0 | } |
75 | 0 | } |
76 | | |
77 | | static reloc_howto_type * |
78 | | tic30_coff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
79 | | const char *r_name) |
80 | 0 | { |
81 | 0 | unsigned int i; |
82 | |
|
83 | 0 | for (i = 0; |
84 | 0 | i < (sizeof (tic30_coff_howto_table) |
85 | 0 | / sizeof (tic30_coff_howto_table[0])); |
86 | 0 | i++) |
87 | 0 | if (tic30_coff_howto_table[i].name != NULL |
88 | 0 | && strcasecmp (tic30_coff_howto_table[i].name, r_name) == 0) |
89 | 0 | return &tic30_coff_howto_table[i]; |
90 | | |
91 | 0 | return NULL; |
92 | 0 | } |
93 | | |
94 | | #endif |
95 | | |
96 | | /* Turn a howto into a reloc number. */ |
97 | | |
98 | | static int |
99 | | coff_tic30_select_reloc (reloc_howto_type *howto) |
100 | 0 | { |
101 | 0 | return howto->type; |
102 | 0 | } |
103 | | |
104 | 0 | #define SELECT_RELOC(x,howto) x.r_type = coff_tic30_select_reloc(howto) |
105 | | |
106 | 3.35M | #define BADMAG(x) TIC30BADMAG(x) |
107 | | #define TIC30 1 /* Customize coffcode.h */ |
108 | | #define __A_MAGIC_SET__ |
109 | | |
110 | | /* Code to swap in the reloc */ |
111 | 2.31k | #define SWAP_IN_RELOC_OFFSET H_GET_32 |
112 | 0 | #define SWAP_OUT_RELOC_OFFSET H_PUT_32 |
113 | 0 | #define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) dst->r_stuff[0] = 'S'; \ |
114 | 0 | dst->r_stuff[1] = 'C'; |
115 | | |
116 | | /* Code to turn a r_type into a howto ptr, uses the above howto table. */ |
117 | | |
118 | | static void |
119 | | rtype2howto (arelent *internal, struct internal_reloc *dst) |
120 | 2.31k | { |
121 | 2.31k | switch (dst->r_type) |
122 | 2.31k | { |
123 | 29 | case R_TIC30_ABS16: |
124 | 29 | internal->howto = &tic30_coff_howto_table[0]; |
125 | 29 | break; |
126 | 156 | case R_TIC30_ABS24: |
127 | 156 | internal->howto = &tic30_coff_howto_table[1]; |
128 | 156 | break; |
129 | 4 | case R_TIC30_ABS32: |
130 | 4 | internal->howto = &tic30_coff_howto_table[3]; |
131 | 4 | break; |
132 | 3 | case R_TIC30_LDP: |
133 | 3 | internal->howto = &tic30_coff_howto_table[2]; |
134 | 3 | break; |
135 | 1 | case R_TIC30_PC16: |
136 | 1 | internal->howto = &tic30_coff_howto_table[4]; |
137 | 1 | break; |
138 | 2.12k | default: |
139 | 2.12k | internal->howto = NULL; |
140 | 2.12k | break; |
141 | 2.31k | } |
142 | 2.31k | } |
143 | | |
144 | 0 | #define RTYPE2HOWTO(internal, relocentry) rtype2howto (internal, relocentry) |
145 | | |
146 | | /* Perform any necessary magic to the addend in a reloc entry */ |
147 | | |
148 | | #define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \ |
149 | | cache_ptr->addend = ext_reloc.r_offset; |
150 | | |
151 | | #define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \ |
152 | 2.31k | reloc_processing(relent, reloc, symbols, abfd, section) |
153 | | |
154 | | static void |
155 | | reloc_processing (arelent *relent, |
156 | | struct internal_reloc *reloc, |
157 | | asymbol **symbols, |
158 | | bfd *abfd, |
159 | | asection *section) |
160 | 2.31k | { |
161 | 2.31k | relent->address = reloc->r_vaddr; |
162 | 2.31k | rtype2howto (relent, reloc); |
163 | | |
164 | 2.31k | if (reloc->r_symndx == -1 || symbols == NULL) |
165 | 2.01k | relent->sym_ptr_ptr = &bfd_abs_section_ptr->symbol; |
166 | 299 | else if (reloc->r_symndx >= 0 && reloc->r_symndx < obj_conv_table_size (abfd)) |
167 | 106 | relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx]; |
168 | 193 | else |
169 | 193 | { |
170 | 193 | _bfd_error_handler |
171 | | /* xgettext:c-format */ |
172 | 193 | (_("%pB: warning: illegal symbol index %ld in relocs"), |
173 | 193 | abfd, reloc->r_symndx); |
174 | 193 | relent->sym_ptr_ptr = &bfd_abs_section_ptr->symbol; |
175 | 193 | } |
176 | 2.31k | relent->addend = reloc->r_offset; |
177 | 2.31k | relent->address -= section->vma; |
178 | 2.31k | } |
179 | | |
180 | | #ifndef bfd_pe_print_pdata |
181 | | #define bfd_pe_print_pdata NULL |
182 | | #endif |
183 | | |
184 | | #include "coffcode.h" |
185 | | |
186 | | const bfd_target tic30_coff_vec = |
187 | | { |
188 | | "coff-tic30", /* name */ |
189 | | bfd_target_coff_flavour, |
190 | | BFD_ENDIAN_BIG, /* data byte order is big */ |
191 | | BFD_ENDIAN_LITTLE, /* header byte order is little */ |
192 | | |
193 | | (HAS_RELOC | EXEC_P /* object flags */ |
194 | | | HAS_LINENO | HAS_DEBUG |
195 | | | HAS_SYMS | HAS_LOCALS | WP_TEXT), |
196 | | |
197 | | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ |
198 | | '_', /* leading symbol underscore */ |
199 | | '/', /* ar_pad_char */ |
200 | | 15, /* ar_max_namelen */ |
201 | | 0, /* match priority. */ |
202 | | TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */ |
203 | | bfd_getb64, bfd_getb_signed_64, bfd_putb64, |
204 | | bfd_getb32, bfd_getb_signed_32, bfd_putb32, |
205 | | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */ |
206 | | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
207 | | bfd_getl32, bfd_getl_signed_32, bfd_putl32, |
208 | | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */ |
209 | | |
210 | | { /* bfd_check_format */ |
211 | | _bfd_dummy_target, |
212 | | coff_object_p, |
213 | | bfd_generic_archive_p, |
214 | | _bfd_dummy_target |
215 | | }, |
216 | | { /* bfd_set_format */ |
217 | | _bfd_bool_bfd_false_error, |
218 | | coff_mkobject, |
219 | | _bfd_generic_mkarchive, |
220 | | _bfd_bool_bfd_false_error |
221 | | }, |
222 | | { /* bfd_write_contents */ |
223 | | _bfd_bool_bfd_false_error, |
224 | | coff_write_object_contents, |
225 | | _bfd_write_archive_contents, |
226 | | _bfd_bool_bfd_false_error |
227 | | }, |
228 | | |
229 | | BFD_JUMP_TABLE_GENERIC (coff), |
230 | | BFD_JUMP_TABLE_COPY (coff), |
231 | | BFD_JUMP_TABLE_CORE (_bfd_nocore), |
232 | | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), |
233 | | BFD_JUMP_TABLE_SYMBOLS (coff), |
234 | | BFD_JUMP_TABLE_RELOCS (coff), |
235 | | BFD_JUMP_TABLE_WRITE (coff), |
236 | | BFD_JUMP_TABLE_LINK (coff), |
237 | | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), |
238 | | |
239 | | NULL, |
240 | | |
241 | | COFF_SWAP_TABLE |
242 | | }; |