1 # This shell script emits a C file. -*- C -*-
2 # Copyright (C) 2011-2022 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 # This file is sourced from elf.em, and defines extra C6X DSBT specific
27 #include "elf32-tic6x.h"
29 static struct elf32_tic6x_params params =
34 static int merge_exidx_entries = -1;
37 is_tic6x_target (void)
39 extern const bfd_target tic6x_elf32_le_vec;
40 extern const bfd_target tic6x_elf32_be_vec;
41 extern const bfd_target tic6x_elf32_linux_le_vec;
42 extern const bfd_target tic6x_elf32_linux_be_vec;
43 extern const bfd_target tic6x_elf32_c6000_le_vec;
44 extern const bfd_target tic6x_elf32_c6000_be_vec;
46 return (link_info.output_bfd->xvec == &tic6x_elf32_le_vec
47 || link_info.output_bfd->xvec == &tic6x_elf32_be_vec
48 || link_info.output_bfd->xvec == &tic6x_elf32_linux_le_vec
49 || link_info.output_bfd->xvec == &tic6x_elf32_linux_be_vec
50 || link_info.output_bfd->xvec == &tic6x_elf32_c6000_le_vec
51 || link_info.output_bfd->xvec == &tic6x_elf32_c6000_be_vec);
54 /* Pass params to backend. */
57 tic6x_after_open (void)
59 if (is_tic6x_target ())
61 if (params.dsbt_index >= params.dsbt_size)
63 einfo (_("%F%P: invalid --dsbt-index %d, outside DSBT size\n"),
66 elf32_tic6x_setup (&link_info, ¶ms);
69 gld${EMULATION_NAME}_after_open ();
73 compare_output_sec_vma (const void *a, const void *b)
75 asection *asec = *(asection **) a, *bsec = *(asection **) b;
76 asection *aout = asec->output_section, *bout = bsec->output_section;
79 /* If there's no output section for some reason, compare equal. */
83 avma = aout->vma + asec->output_offset;
84 bvma = bout->vma + bsec->output_offset;
95 gld${EMULATION_NAME}_after_allocation (void)
97 int layout_changed = 0;
100 if (!bfd_link_relocatable (&link_info))
102 /* Build a sorted list of input text sections, then use that to process
103 the unwind table index. */
104 unsigned int list_size = 10;
105 asection **sec_list = (asection **)
106 xmalloc (list_size * sizeof (asection *));
107 unsigned int sec_count = 0;
109 LANG_FOR_EACH_INPUT_STATEMENT (is)
111 bfd *abfd = is->the_bfd;
114 if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
117 for (sec = abfd->sections; sec != NULL; sec = sec->next)
119 asection *out_sec = sec->output_section;
122 && elf_section_data (sec)
123 && elf_section_type (sec) == SHT_PROGBITS
124 && (elf_section_flags (sec) & SHF_EXECINSTR) != 0
125 && (sec->flags & SEC_EXCLUDE) == 0
126 && sec->sec_info_type != SEC_INFO_TYPE_JUST_SYMS
127 && out_sec != bfd_abs_section_ptr)
129 if (sec_count == list_size)
132 sec_list = (asection **)
133 xrealloc (sec_list, list_size * sizeof (asection *));
136 sec_list[sec_count++] = sec;
141 qsort (sec_list, sec_count, sizeof (asection *), &compare_output_sec_vma);
143 if (elf32_tic6x_fix_exidx_coverage (sec_list, sec_count, &link_info,
144 merge_exidx_entries))
150 /* bfd_elf32_discard_info just plays with debugging sections,
151 ie. doesn't affect any code, so we can delay resizing the
153 ret = bfd_elf_discard_info (link_info.output_bfd, & link_info);
156 einfo (_("%X%P: .eh_frame/.stab edit: %E\n"));
162 ldelf_map_segments (layout_changed);
166 # This code gets inserted into the generic elf32.sc linker script
167 # and allows us to define our own command line switches.
168 PARSE_AND_LIST_PROLOGUE='
169 #define OPTION_DSBT_INDEX 300
170 #define OPTION_DSBT_SIZE 301
171 #define OPTION_NO_MERGE_EXIDX_ENTRIES 302
174 PARSE_AND_LIST_LONGOPTS='
175 {"dsbt-index", required_argument, NULL, OPTION_DSBT_INDEX},
176 {"dsbt-size", required_argument, NULL, OPTION_DSBT_SIZE},
177 { "no-merge-exidx-entries", no_argument, NULL, OPTION_NO_MERGE_EXIDX_ENTRIES },
180 PARSE_AND_LIST_OPTIONS='
181 fprintf (file, _(" --dsbt-index <index> Use this as the DSBT index for the output object\n"));
182 fprintf (file, _(" --dsbt-size <index> Use this as the number of entries in the DSBT table\n"));
183 fprintf (file, _(" --no-merge-exidx-entries\n"));
184 fprintf (file, _(" Disable merging exidx entries\n"));
187 PARSE_AND_LIST_ARGS_CASES='
188 case OPTION_DSBT_INDEX:
191 params.dsbt_index = strtol (optarg, &end, 0);
193 && params.dsbt_index >= 0 && params.dsbt_index < 0x7fff)
195 einfo (_("%F%P: invalid --dsbt-index %s\n"), optarg);
198 case OPTION_DSBT_SIZE:
201 params.dsbt_size = strtol (optarg, &end, 0);
203 && params.dsbt_size >= 0 && params.dsbt_size < 0x7fff)
205 einfo (_("%F%P: invalid --dsbt-size %s\n"), optarg);
208 case OPTION_NO_MERGE_EXIDX_ENTRIES:
209 merge_exidx_entries = 0;
212 LDEMUL_AFTER_OPEN=tic6x_after_open
213 LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation