1 # This shell script emits a C file. -*- C -*-
2 # Copyright (C) 2003-2023 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 xtensa-elf
27 #include <xtensa-dynconfig.h>
28 #include "../bfd/elf-bfd.h"
29 #include "elf/xtensa.h"
32 /* Provide default values for new configuration settings. */
33 #ifndef XTHAL_ABI_UNDEFINED
34 #define XTHAL_ABI_UNDEFINED -1
37 static void xtensa_wild_group_interleave (lang_statement_union_type *);
38 static void xtensa_colocate_output_literals (lang_statement_union_type *);
39 static void xtensa_strip_inconsistent_linkonce_sections
40 (lang_statement_list_type *);
43 /* This number is irrelevant until we turn on use_literal_pages */
44 static bfd_vma xtensa_page_power = 12; /* 4K pages. */
46 /* To force a page break between literals and text, change
47 xtensa_use_literal_pages to "true". */
48 static bool xtensa_use_literal_pages = false;
50 #define EXTRA_VALIDATION 0
53 This option is defined in BDF library. */
54 extern int elf32xtensa_abi;
58 elf_xtensa_choose_target (int argc ATTRIBUTE_UNUSED,
59 char **argv ATTRIBUTE_UNUSED)
62 return "${BIG_OUTPUT_FORMAT}";
64 return "${LITTLE_OUTPUT_FORMAT}";
69 elf_xtensa_before_parse (void)
71 /* Just call the default hook.... Tensilica's version of this function
72 does some other work that isn't relevant here. */
73 gld${EMULATION_NAME}_before_parse ();
78 remove_section (bfd *abfd, asection *os)
81 for (spp = &abfd->sections; *spp; spp = &(*spp)->next)
85 os->owner->section_count--;
92 replace_insn_sec_with_prop_sec (bfd *abfd,
93 const char *insn_sec_name,
94 const char *prop_sec_name,
99 bfd_byte *prop_contents = NULL;
100 bfd_byte *insn_contents = NULL;
101 unsigned entry_count;
103 Elf_Internal_Shdr *rel_hdr;
104 Elf_Internal_Rela *internal_relocs = NULL;
105 unsigned reloc_count;
108 insn_sec = bfd_get_section_by_name (abfd, insn_sec_name);
109 if (insn_sec == NULL)
111 entry_count = insn_sec->size / 8;
113 prop_sec = bfd_get_section_by_name (abfd, prop_sec_name);
114 if (prop_sec != NULL && insn_sec != NULL)
116 *error_message = _("file already has property tables");
120 if (insn_sec->size != 0)
122 insn_contents = (bfd_byte *) xmalloc (insn_sec->size);
123 if (! bfd_get_section_contents (abfd, insn_sec, insn_contents,
124 (file_ptr) 0, insn_sec->size))
126 *error_message = _("failed to read section contents");
131 /* Create a property table section for it. */
132 prop_sec_name = strdup (prop_sec_name);
133 prop_sec = bfd_make_section_with_flags
134 (abfd, prop_sec_name, bfd_section_flags (insn_sec));
136 || !bfd_set_section_alignment (prop_sec, 2))
138 *error_message = _("could not create new section");
142 prop_sec->size = entry_count * 12;
143 prop_contents = (bfd_byte *) bfd_zalloc (abfd, prop_sec->size);
144 elf_section_data (prop_sec)->this_hdr.contents = prop_contents;
146 /* The entry size and size must be set to allow the linker to compute
147 the number of relocations since it does not use reloc_count. */
148 rel_hdr = _bfd_elf_single_rel_hdr (prop_sec);
149 rel_hdr->sh_entsize = sizeof (Elf32_External_Rela);
150 rel_hdr->sh_size = _bfd_elf_single_rel_hdr (insn_sec)->sh_size;
152 if (prop_contents == NULL && prop_sec->size != 0)
154 *error_message = _("could not allocate section contents");
158 /* Read the relocations. */
159 reloc_count = insn_sec->reloc_count;
160 if (reloc_count != 0)
162 /* If there is already an internal_reloc, then save it so that the
163 read_relocs function freshly allocates a copy. */
164 Elf_Internal_Rela *saved_relocs = elf_section_data (insn_sec)->relocs;
166 elf_section_data (insn_sec)->relocs = NULL;
168 _bfd_elf_link_read_relocs (abfd, insn_sec, NULL, NULL, false);
169 elf_section_data (insn_sec)->relocs = saved_relocs;
171 if (internal_relocs == NULL)
173 *error_message = _("out of memory");
178 /* Create a relocation section for the property section. */
179 if (internal_relocs != NULL)
181 elf_section_data (prop_sec)->relocs = internal_relocs;
182 prop_sec->reloc_count = reloc_count;
185 /* Now copy each insn table entry to the prop table entry with
186 appropriate flags. */
187 for (entry = 0; entry < entry_count; ++entry)
190 unsigned flags = (XTENSA_PROP_INSN | XTENSA_PROP_NO_TRANSFORM
191 | XTENSA_PROP_INSN_NO_REORDER);
192 value = bfd_get_32 (abfd, insn_contents + entry * 8 + 0);
193 bfd_put_32 (abfd, value, prop_contents + entry * 12 + 0);
194 value = bfd_get_32 (abfd, insn_contents + entry * 8 + 4);
195 bfd_put_32 (abfd, value, prop_contents + entry * 12 + 4);
196 bfd_put_32 (abfd, flags, prop_contents + entry * 12 + 8);
199 /* Now copy all of the relocations. Change offsets for the
200 instruction table section to offsets in the property table
206 for (i = 0; i < reloc_count; i++)
208 Elf_Internal_Rela *rela;
211 rela = &internal_relocs[i];
213 /* If this relocation is to the .xt.insn section,
214 change the section number and the offset. */
215 r_offset = rela->r_offset;
216 r_offset += 4 * (r_offset / 8);
217 rela->r_offset = r_offset;
221 remove_section (abfd, insn_sec);
223 free (insn_contents);
228 if (prop_sec && prop_sec->owner)
229 remove_section (abfd, prop_sec);
230 free (insn_contents);
231 free (internal_relocs);
237 #define PROP_SEC_BASE_NAME ".xt.prop"
238 #define INSN_SEC_BASE_NAME ".xt.insn"
239 #define LINKONCE_SEC_OLD_TEXT_BASE_NAME ".gnu.linkonce.x."
243 replace_instruction_table_sections (bfd *abfd, asection *sec)
246 const char *insn_sec_name = NULL;
247 char *prop_sec_name = NULL;
248 char *owned_prop_sec_name = NULL;
249 const char *sec_name;
251 sec_name = bfd_section_name (sec);
252 if (strcmp (sec_name, INSN_SEC_BASE_NAME) == 0)
254 insn_sec_name = INSN_SEC_BASE_NAME;
255 prop_sec_name = PROP_SEC_BASE_NAME;
257 else if (startswith (sec_name, LINKONCE_SEC_OLD_TEXT_BASE_NAME))
259 insn_sec_name = sec_name;
260 owned_prop_sec_name = (char *) xmalloc (strlen (sec_name) + 20);
261 prop_sec_name = owned_prop_sec_name;
262 strcpy (prop_sec_name, ".gnu.linkonce.prop.t.");
263 strcat (prop_sec_name,
264 sec_name + strlen (LINKONCE_SEC_OLD_TEXT_BASE_NAME));
266 if (insn_sec_name != NULL)
268 if (! replace_insn_sec_with_prop_sec (abfd, insn_sec_name, prop_sec_name,
271 einfo (_("%P: warning: failed to convert %s table in %pB (%s); subsequent disassembly may be incomplete\n"),
272 insn_sec_name, abfd, message);
275 free (owned_prop_sec_name);
279 /* This is called after all input sections have been opened to convert
280 instruction tables (.xt.insn, gnu.linkonce.x.*) tables into property
281 tables (.xt.prop) before any section placement. */
284 elf_xtensa_after_open (void)
286 /* First call the ELF version. */
287 gld${EMULATION_NAME}_after_open ();
289 /* Now search the input files looking for instruction table sections. */
290 LANG_FOR_EACH_INPUT_STATEMENT (f)
292 asection *sec = f->the_bfd->sections;
295 /* Do not use bfd_map_over_sections here since we are removing
296 sections as we iterate. */
299 next_sec = sec->next;
300 replace_instruction_table_sections (f->the_bfd, sec);
308 xt_config_info_unpack_and_check (char *data,
325 /* Overwrite the equal sign. */
328 /* Check if this is a quoted string or a number. */
331 /* No string values are currently checked by LD;
332 just skip over the quotes. */
337 /* Overwrite the trailing quote. */
344 num = strtoul (d, &d, 0);
346 if (! strcmp (key, "ABI"))
348 if (elf32xtensa_abi == XTHAL_ABI_UNDEFINED)
350 elf32xtensa_abi = num;
352 else if (num != elf32xtensa_abi)
355 *pmsg = "ABI does not match";
358 else if (! strcmp (key, "USE_ABSOLUTE_LITERALS"))
360 if (num != XSHAL_USE_ABSOLUTE_LITERALS)
363 *pmsg = "incompatible use of the Extended L32R option";
379 #define XTINFO_NAME "Xtensa_Info"
380 #define XTINFO_NAMESZ 12
381 #define XTINFO_TYPE 1
384 check_xtensa_info (bfd *abfd, asection *info_sec)
386 char *data, *errmsg = "";
389 data = xmalloc (info_sec->size);
390 if (! bfd_get_section_contents (abfd, info_sec, data, 0, info_sec->size))
391 einfo (_("%F%P: %pB: cannot read contents of section %pA\n"), abfd, info_sec);
393 if (info_sec->size > 24
394 && info_sec->size >= 24 + bfd_get_32 (abfd, data + 4)
395 && bfd_get_32 (abfd, data + 0) == XTINFO_NAMESZ
396 && bfd_get_32 (abfd, data + 8) == XTINFO_TYPE
397 && strcmp (data + 12, XTINFO_NAME) == 0
398 && xt_config_info_unpack_and_check (data + 12 + XTINFO_NAMESZ,
402 einfo (_("%P: %pB: warning: incompatible Xtensa configuration (%s)\n"),
406 einfo (_("%P: %pB: warning: cannot parse .xtensa.info section\n"), abfd);
412 /* This is called after the sections have been attached to output
413 sections, but before any sizes or addresses have been set. */
416 elf_xtensa_before_allocation (void)
418 asection *info_sec, *first_info_sec;
420 bool is_big_endian = XCHAL_HAVE_BE;
422 /* Check that the output endianness matches the Xtensa
423 configuration. The BFD library always includes both big and
424 little endian target vectors for Xtensa, but it only supports the
425 detailed instruction encode/decode operations (such as are
426 required to process relocations) for the selected Xtensa
430 && link_info.output_bfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
432 einfo (_("%F%P: little endian output does not match "
433 "Xtensa configuration\n"));
436 && link_info.output_bfd->xvec->byteorder == BFD_ENDIAN_BIG)
438 einfo (_("%F%P: big endian output does not match "
439 "Xtensa configuration\n"));
442 /* Keep track of the first input .xtensa.info section, and as a fallback,
443 the first input bfd where a .xtensa.info section could be created.
444 After the input .xtensa.info has been checked, the contents of the
445 first one will be replaced with the output .xtensa.info table. */
449 LANG_FOR_EACH_INPUT_STATEMENT (f)
451 /* Check that the endianness for each input file matches the output.
452 The merge_private_bfd_data hook has already reported any mismatches
453 as errors, but those errors are not fatal. At this point, we
454 cannot go any further if there are any mismatches. */
455 if ((is_big_endian && f->the_bfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
456 || (!is_big_endian && f->the_bfd->xvec->byteorder == BFD_ENDIAN_BIG))
457 einfo (_("%F%P: cross-endian linking for %pB not supported\n"),
461 first_bfd = f->the_bfd;
463 info_sec = bfd_get_section_by_name (f->the_bfd, ".xtensa.info");
467 if (! first_info_sec)
468 first_info_sec = info_sec;
470 /* Unpack the .xtensa.info section and check it against the current
471 Xtensa configuration. */
472 check_xtensa_info (f->the_bfd, info_sec);
474 /* Do not include this copy of .xtensa.info in the output. */
476 info_sec->flags |= SEC_EXCLUDE;
479 /* Reuse the first .xtensa.info input section to hold the output
480 .xtensa.info; or, if none were found, create a new section in the
481 first input bfd (assuming there is one). */
482 info_sec = first_info_sec;
483 if (! info_sec && first_bfd)
485 info_sec = bfd_make_section_with_flags (first_bfd, ".xtensa.info",
486 SEC_HAS_CONTENTS | SEC_READONLY);
488 einfo (_("%F%P: failed to create .xtensa.info section\n"));
492 int xtensa_info_size;
495 info_sec->flags &= ~SEC_EXCLUDE;
496 info_sec->flags |= SEC_IN_MEMORY;
499 = 1 + sprintf (data, "USE_ABSOLUTE_LITERALS=%d\nABI=%d\n",
500 XSHAL_USE_ABSOLUTE_LITERALS, xtensa_abi_choice ());
502 /* Add enough null terminators to pad to a word boundary. */
504 data[xtensa_info_size++] = 0;
505 while ((xtensa_info_size & 3) != 0);
507 info_sec->size = 12 + XTINFO_NAMESZ + xtensa_info_size;
508 info_sec->contents = xmalloc (info_sec->size);
509 bfd_put_32 (info_sec->owner, XTINFO_NAMESZ, info_sec->contents + 0);
510 bfd_put_32 (info_sec->owner, xtensa_info_size, info_sec->contents + 4);
511 bfd_put_32 (info_sec->owner, XTINFO_TYPE, info_sec->contents + 8);
512 memcpy (info_sec->contents + 12, XTINFO_NAME, XTINFO_NAMESZ);
513 memcpy (info_sec->contents + 12 + XTINFO_NAMESZ, data, xtensa_info_size);
516 /* Enable relaxation by default if the "--no-relax" option was not
517 specified. This is done here instead of in the before_parse hook
518 because there is a check in main() to prohibit use of --relax and
519 -r together and that combination should be allowed for Xtensa. */
520 if (RELAXATION_DISABLED_BY_DEFAULT)
523 xtensa_strip_inconsistent_linkonce_sections (stat_ptr);
525 gld${EMULATION_NAME}_before_allocation ();
527 xtensa_wild_group_interleave (stat_ptr->head);
529 if (RELAXATION_ENABLED)
530 xtensa_colocate_output_literals (stat_ptr->head);
532 /* TBD: We need to force the page alignments to here and only do
533 them as needed for the entire output section. Finally, if this
534 is a relocatable link then we need to add alignment notes so
535 that the literals can be separated later. */
539 typedef struct wildcard_list section_name_list;
541 typedef struct reloc_deps_e_t reloc_deps_e;
542 typedef struct reloc_deps_section_t reloc_deps_section;
543 typedef struct reloc_deps_graph_t reloc_deps_graph;
546 struct reloc_deps_e_t
548 asection *src; /* Contains l32rs. */
549 asection *tgt; /* Contains literals. */
553 /* Place these in the userdata field. */
554 struct reloc_deps_section_t
558 bool is_only_literal;
562 struct reloc_deps_graph_t
569 static void xtensa_layout_wild
570 (const reloc_deps_graph *, lang_wild_statement_type *);
572 typedef void (*deps_callback_t) (asection *, /* src_sec */
573 bfd_vma, /* src_offset */
574 asection *, /* target_sec */
575 bfd_vma, /* target_offset */
576 void *); /* closure */
578 extern bool xtensa_callback_required_dependence
579 (bfd *, asection *, struct bfd_link_info *, deps_callback_t, void *);
580 static void xtensa_ldlang_clear_addresses (lang_statement_union_type *);
581 static bool ld_local_file_relocations_fit
582 (lang_statement_union_type *, const reloc_deps_graph *);
583 static bfd_vma ld_assign_relative_paged_dot
584 (bfd_vma, lang_statement_union_type *, const reloc_deps_graph *,
586 static bfd_vma ld_xtensa_insert_page_offsets
587 (bfd_vma, lang_statement_union_type *, reloc_deps_graph *, bool);
589 static size_t ld_count_children (lang_statement_union_type *);
592 extern lang_statement_list_type constructor_list;
594 static reloc_deps_section *
595 xtensa_get_section_deps (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
598 /* We have a separate function for this so that
599 we could in the future keep a completely independent
600 structure that maps a section to its dependence edges.
601 For now, we place these in the sec->userdata field.
602 This doesn't clash with ldlang.c use of userdata for output
603 sections, and during map output for input sections, since the
604 xtensa use is only for input sections and only extant in
605 before_allocation. */
606 reloc_deps_section *sec_deps = bfd_section_userdata (sec);
611 xtensa_set_section_deps (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
613 reloc_deps_section *deps_section)
615 bfd_set_section_userdata (sec, deps_section);
619 /* This is used to keep a list of all of the sections participating in
620 the graph so we can clean them up quickly. */
623 xtensa_append_section_deps (reloc_deps_graph *deps, asection *sec)
625 if (deps->size <= deps->count)
627 asection **new_sections;
631 new_size = deps->size * 2;
635 new_sections = xmalloc (sizeof (asection *) * new_size);
636 memset (new_sections, 0, sizeof (asection *) * new_size);
637 for (i = 0; i < deps->count; i++)
639 new_sections[i] = deps->sections[i];
641 free (deps->sections);
642 deps->sections = new_sections;
643 deps->size = new_size;
645 deps->sections[deps->count] = sec;
651 free_reloc_deps_graph (reloc_deps_graph *deps)
654 for (i = 0; i < deps->count; i++)
656 asection *sec = deps->sections[i];
657 reloc_deps_section *sec_deps;
658 sec_deps = xtensa_get_section_deps (deps, sec);
662 while (sec_deps->succs != NULL)
664 next = sec_deps->succs->next;
665 free (sec_deps->succs);
666 sec_deps->succs = next;
669 while (sec_deps->preds != NULL)
671 next = sec_deps->preds->next;
672 free (sec_deps->preds);
673 sec_deps->preds = next;
677 xtensa_set_section_deps (deps, sec, NULL);
679 free (deps->sections);
685 section_is_source (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
686 lang_statement_union_type *s)
689 const reloc_deps_section *sec_deps;
691 if (s->header.type != lang_input_section_enum)
693 sec = s->input_section.section;
695 sec_deps = xtensa_get_section_deps (deps, sec);
696 return sec_deps && sec_deps->succs != NULL;
701 section_is_target (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
702 lang_statement_union_type *s)
705 const reloc_deps_section *sec_deps;
707 if (s->header.type != lang_input_section_enum)
709 sec = s->input_section.section;
711 sec_deps = xtensa_get_section_deps (deps, sec);
712 return sec_deps && sec_deps->preds != NULL;
717 section_is_source_or_target (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
718 lang_statement_union_type *s)
720 return (section_is_source (deps, s)
721 || section_is_target (deps, s));
725 typedef struct xtensa_ld_iter_stack_t xtensa_ld_iter_stack;
726 typedef struct xtensa_ld_iter_t xtensa_ld_iter;
728 struct xtensa_ld_iter_t
730 lang_statement_union_type *parent; /* Parent of the list. */
731 lang_statement_list_type *l; /* List that holds it. */
732 lang_statement_union_type **loc; /* Place in the list. */
735 struct xtensa_ld_iter_stack_t
737 xtensa_ld_iter iterloc; /* List that hold it. */
739 xtensa_ld_iter_stack *next; /* Next in the stack. */
740 xtensa_ld_iter_stack *prev; /* Back pointer for stack. */
745 ld_xtensa_move_section_after (xtensa_ld_iter *to, xtensa_ld_iter *current)
747 lang_statement_union_type *to_next;
748 lang_statement_union_type *current_next;
749 lang_statement_union_type **e;
752 size_t old_to_count, new_to_count;
753 size_t old_current_count, new_current_count;
760 old_to_count = ld_count_children (to->parent);
761 old_current_count = ld_count_children (current->parent);
764 to_next = *(to->loc);
765 current_next = (*current->loc)->header.next;
767 *(to->loc) = *(current->loc);
769 *(current->loc) = current_next;
770 (*(to->loc))->header.next = to_next;
772 /* reset "to" list tail */
773 for (e = &to->l->head; *e != NULL; e = &(*e)->header.next)
777 /* reset "current" list tail */
778 for (e = ¤t->l->head; *e != NULL; e = &(*e)->header.next)
780 current->l->tail = e;
783 new_to_count = ld_count_children (to->parent);
784 new_current_count = ld_count_children (current->parent);
786 ASSERT ((old_to_count + old_current_count)
787 == (new_to_count + new_current_count));
792 /* Can only be called with lang_statements that have lists. Returns
793 FALSE if the list is empty. */
796 iter_stack_empty (xtensa_ld_iter_stack **stack_p)
798 return *stack_p == NULL;
803 iter_stack_push (xtensa_ld_iter_stack **stack_p,
804 lang_statement_union_type *parent)
806 xtensa_ld_iter_stack *stack;
807 lang_statement_list_type *l = NULL;
809 switch (parent->header.type)
811 case lang_output_section_statement_enum:
812 l = &parent->output_section_statement.children;
814 case lang_wild_statement_enum:
815 l = &parent->wild_statement.children;
817 case lang_group_statement_enum:
818 l = &parent->group_statement.children;
825 /* Empty. do not push. */
826 if (l->tail == &l->head)
829 stack = xmalloc (sizeof (xtensa_ld_iter_stack));
830 memset (stack, 0, sizeof (xtensa_ld_iter_stack));
831 stack->iterloc.parent = parent;
832 stack->iterloc.l = l;
833 stack->iterloc.loc = &l->head;
835 stack->next = *stack_p;
837 if (*stack_p != NULL)
838 (*stack_p)->prev = stack;
845 iter_stack_pop (xtensa_ld_iter_stack **stack_p)
847 xtensa_ld_iter_stack *stack;
853 ASSERT (stack != NULL);
857 if (stack->next != NULL)
858 stack->next->prev = NULL;
860 *stack_p = stack->next;
865 /* This MUST be called if, during iteration, the user changes the
866 underlying structure. It will check for a NULL current and advance
870 iter_stack_update (xtensa_ld_iter_stack **stack_p)
872 if (!iter_stack_empty (stack_p)
873 && (*(*stack_p)->iterloc.loc) == NULL)
875 iter_stack_pop (stack_p);
877 while (!iter_stack_empty (stack_p)
878 && ((*(*stack_p)->iterloc.loc)->header.next == NULL))
880 iter_stack_pop (stack_p);
882 if (!iter_stack_empty (stack_p))
883 (*stack_p)->iterloc.loc = &(*(*stack_p)->iterloc.loc)->header.next;
889 iter_stack_next (xtensa_ld_iter_stack **stack_p)
891 xtensa_ld_iter_stack *stack;
892 lang_statement_union_type *current;
895 current = *stack->iterloc.loc;
896 /* If we are on the first element. */
899 switch (current->header.type)
901 case lang_output_section_statement_enum:
902 case lang_wild_statement_enum:
903 case lang_group_statement_enum:
904 /* If the list if not empty, we are done. */
905 if (iter_stack_push (stack_p, *stack->iterloc.loc))
907 /* Otherwise increment the pointer as normal. */
914 while (!iter_stack_empty (stack_p)
915 && ((*(*stack_p)->iterloc.loc)->header.next == NULL))
917 iter_stack_pop (stack_p);
919 if (!iter_stack_empty (stack_p))
920 (*stack_p)->iterloc.loc = &(*(*stack_p)->iterloc.loc)->header.next;
924 static lang_statement_union_type *
925 iter_stack_current (xtensa_ld_iter_stack **stack_p)
927 return *((*stack_p)->iterloc.loc);
931 /* The iter stack is a preorder. */
934 iter_stack_create (xtensa_ld_iter_stack **stack_p,
935 lang_statement_union_type *parent)
937 iter_stack_push (stack_p, parent);
942 iter_stack_copy_current (xtensa_ld_iter_stack **stack_p, xtensa_ld_iter *front)
944 *front = (*stack_p)->iterloc;
949 xtensa_colocate_literals (reloc_deps_graph *deps,
950 lang_statement_union_type *statement)
952 /* Keep a stack of pointers to control iteration through the contours. */
953 xtensa_ld_iter_stack *stack = NULL;
954 xtensa_ld_iter_stack **stack_p = &stack;
956 xtensa_ld_iter front; /* Location where new insertion should occur. */
957 xtensa_ld_iter *front_p = NULL;
959 xtensa_ld_iter current; /* Location we are checking. */
960 xtensa_ld_iter *current_p = NULL;
961 bool in_literals = false;
963 if (deps->count == 0)
966 iter_stack_create (stack_p, statement);
968 while (!iter_stack_empty (stack_p))
970 bool skip_increment = false;
971 lang_statement_union_type *l = iter_stack_current (stack_p);
973 switch (l->header.type)
975 case lang_assignment_statement_enum:
976 /* Any assignment statement should block reordering across it. */
981 case lang_input_section_enum:
984 in_literals = (section_is_target (deps, l)
985 && !section_is_source (deps, l));
989 iter_stack_copy_current (stack_p, front_p);
995 current_p = ¤t;
996 iter_stack_copy_current (stack_p, current_p);
997 is_target = (section_is_target (deps, l)
998 && !section_is_source (deps, l));
1002 iter_stack_copy_current (stack_p, front_p);
1004 in_literals = false;
1010 /* Try to insert in place. */
1011 ld_xtensa_move_section_after (front_p, current_p);
1012 ld_assign_relative_paged_dot (0x100000,
1015 xtensa_use_literal_pages);
1017 /* We use this code because it's already written. */
1018 if (!ld_local_file_relocations_fit (statement, deps))
1021 ld_xtensa_move_section_after (current_p, front_p);
1022 /* Reset the literal placement. */
1023 iter_stack_copy_current (stack_p, front_p);
1027 /* Move front pointer up by one. */
1028 front_p->loc = &(*front_p->loc)->header.next;
1030 /* Do not increment the current pointer. */
1031 skip_increment = true;
1041 if (!skip_increment)
1042 iter_stack_next (stack_p);
1044 /* Be careful to update the stack_p if it now is a null. */
1045 iter_stack_update (stack_p);
1048 lang_for_each_statement_worker (xtensa_ldlang_clear_addresses, statement);
1053 xtensa_move_dependencies_to_front (reloc_deps_graph *deps,
1054 lang_wild_statement_type *w)
1056 /* Keep a front pointer and a current pointer. */
1057 lang_statement_union_type **front;
1058 lang_statement_union_type **current;
1060 /* Walk to the end of the targets. */
1061 for (front = &w->children.head;
1062 (*front != NULL) && section_is_source_or_target (deps, *front);
1063 front = &(*front)->header.next)
1069 current = &(*front)->header.next;
1070 while (*current != NULL)
1072 if (section_is_source_or_target (deps, *current))
1074 /* Insert in place. */
1075 xtensa_ld_iter front_iter;
1076 xtensa_ld_iter current_iter;
1078 front_iter.parent = (lang_statement_union_type *) w;
1079 front_iter.l = &w->children;
1080 front_iter.loc = front;
1082 current_iter.parent = (lang_statement_union_type *) w;
1083 current_iter.l = &w->children;
1084 current_iter.loc = current;
1086 ld_xtensa_move_section_after (&front_iter, ¤t_iter);
1087 front = &(*front)->header.next;
1091 current = &(*current)->header.next;
1098 deps_has_sec_edge (const reloc_deps_graph *deps, asection *src, asection *tgt)
1100 const reloc_deps_section *sec_deps;
1101 const reloc_deps_e *sec_deps_e;
1103 sec_deps = xtensa_get_section_deps (deps, src);
1104 if (sec_deps == NULL)
1107 for (sec_deps_e = sec_deps->succs;
1109 sec_deps_e = sec_deps_e->next)
1111 ASSERT (sec_deps_e->src == src);
1112 if (sec_deps_e->tgt == tgt)
1120 deps_has_edge (const reloc_deps_graph *deps,
1121 lang_statement_union_type *src,
1122 lang_statement_union_type *tgt)
1124 if (!section_is_source (deps, src))
1126 if (!section_is_target (deps, tgt))
1129 if (src->header.type != lang_input_section_enum)
1131 if (tgt->header.type != lang_input_section_enum)
1134 return deps_has_sec_edge (deps, src->input_section.section,
1135 tgt->input_section.section);
1140 add_deps_edge (reloc_deps_graph *deps, asection *src_sec, asection *tgt_sec)
1142 reloc_deps_section *src_sec_deps;
1143 reloc_deps_section *tgt_sec_deps;
1145 reloc_deps_e *src_edge;
1146 reloc_deps_e *tgt_edge;
1148 if (deps_has_sec_edge (deps, src_sec, tgt_sec))
1151 src_sec_deps = xtensa_get_section_deps (deps, src_sec);
1152 if (src_sec_deps == NULL)
1154 /* Add a section. */
1155 src_sec_deps = xmalloc (sizeof (reloc_deps_section));
1156 memset (src_sec_deps, 0, sizeof (reloc_deps_section));
1157 src_sec_deps->is_only_literal = 0;
1158 src_sec_deps->preds = NULL;
1159 src_sec_deps->succs = NULL;
1160 xtensa_set_section_deps (deps, src_sec, src_sec_deps);
1161 xtensa_append_section_deps (deps, src_sec);
1164 tgt_sec_deps = xtensa_get_section_deps (deps, tgt_sec);
1165 if (tgt_sec_deps == NULL)
1167 /* Add a section. */
1168 tgt_sec_deps = xmalloc (sizeof (reloc_deps_section));
1169 memset (tgt_sec_deps, 0, sizeof (reloc_deps_section));
1170 tgt_sec_deps->is_only_literal = 0;
1171 tgt_sec_deps->preds = NULL;
1172 tgt_sec_deps->succs = NULL;
1173 xtensa_set_section_deps (deps, tgt_sec, tgt_sec_deps);
1174 xtensa_append_section_deps (deps, tgt_sec);
1177 /* Add the edges. */
1178 src_edge = xmalloc (sizeof (reloc_deps_e));
1179 memset (src_edge, 0, sizeof (reloc_deps_e));
1180 src_edge->src = src_sec;
1181 src_edge->tgt = tgt_sec;
1182 src_edge->next = src_sec_deps->succs;
1183 src_sec_deps->succs = src_edge;
1185 tgt_edge = xmalloc (sizeof (reloc_deps_e));
1186 memset (tgt_edge, 0, sizeof (reloc_deps_e));
1187 tgt_edge->src = src_sec;
1188 tgt_edge->tgt = tgt_sec;
1189 tgt_edge->next = tgt_sec_deps->preds;
1190 tgt_sec_deps->preds = tgt_edge;
1195 build_deps_graph_callback (asection *src_sec,
1196 bfd_vma src_offset ATTRIBUTE_UNUSED,
1197 asection *target_sec,
1198 bfd_vma target_offset ATTRIBUTE_UNUSED,
1201 reloc_deps_graph *deps = closure;
1203 /* If the target is defined. */
1204 if (target_sec != NULL)
1205 add_deps_edge (deps, src_sec, target_sec);
1209 static reloc_deps_graph *
1210 ld_build_required_section_dependence (lang_statement_union_type *s)
1212 reloc_deps_graph *deps;
1213 xtensa_ld_iter_stack *stack = NULL;
1215 deps = xmalloc (sizeof (reloc_deps_graph));
1216 deps->sections = NULL;
1220 for (iter_stack_create (&stack, s);
1221 !iter_stack_empty (&stack);
1222 iter_stack_next (&stack))
1224 lang_statement_union_type *l = iter_stack_current (&stack);
1226 if (l == NULL && link_info.non_contiguous_regions)
1227 einfo (_("%F%P: Relaxation not supported with "
1228 "--enable-non-contiguous-regions.\n"));
1230 if (l->header.type == lang_input_section_enum)
1232 lang_input_section_type *input;
1233 input = &l->input_section;
1234 xtensa_callback_required_dependence (input->section->owner,
1237 /* Use the same closure. */
1238 build_deps_graph_callback,
1246 #if EXTRA_VALIDATION
1248 ld_count_children (lang_statement_union_type *s)
1251 xtensa_ld_iter_stack *stack = NULL;
1252 for (iter_stack_create (&stack, s);
1253 !iter_stack_empty (&stack);
1254 iter_stack_next (&stack))
1256 lang_statement_union_type *l = iter_stack_current (&stack);
1262 #endif /* EXTRA_VALIDATION */
1265 /* Check if a particular section is included in the link. This will only
1266 be true for one instance of a particular linkonce section. */
1268 static bool input_section_found = false;
1269 static asection *input_section_target = NULL;
1272 input_section_linked_worker (lang_statement_union_type *statement)
1274 if ((statement->header.type == lang_input_section_enum
1275 && (statement->input_section.section == input_section_target)))
1276 input_section_found = true;
1280 input_section_linked (asection *sec)
1282 input_section_found = false;
1283 input_section_target = sec;
1284 lang_for_each_statement_worker (input_section_linked_worker, stat_ptr->head);
1285 return input_section_found;
1289 /* Strip out any linkonce property tables or XCC exception tables where the
1290 associated linkonce text is from a different object file. Normally,
1291 a matching set of linkonce sections is taken from the same object file,
1292 but sometimes the files are compiled differently so that some of the
1293 linkonce sections are not present in all files. Stripping the
1294 inconsistent sections like this is not completely robust -- a much
1295 better solution is to use comdat groups. */
1297 static int linkonce_len = sizeof (".gnu.linkonce.") - 1;
1300 is_inconsistent_linkonce_section (asection *sec)
1302 bfd *abfd = sec->owner;
1303 const char *sec_name = bfd_section_name (sec);
1306 if ((bfd_section_flags (sec) & SEC_LINK_ONCE) == 0
1307 || strncmp (sec_name, ".gnu.linkonce.", linkonce_len) != 0)
1310 /* Check if this is an Xtensa property section or an exception table
1311 for Tensilica's XCC compiler. */
1312 name = sec_name + linkonce_len;
1313 if (startswith (name, "prop."))
1314 name = strchr (name + 5, '.') ? strchr (name + 5, '.') + 1 : name + 5;
1315 else if (name[1] == '.'
1316 && (name[0] == 'p' || name[0] == 'e' || name[0] == 'h'))
1323 char *dep_sec_name = xmalloc (strlen (sec_name) + 1);
1326 /* Get the associated linkonce text section and check if it is
1327 included in the link. If not, this section is inconsistent
1328 and should be stripped. */
1329 strcpy (dep_sec_name, ".gnu.linkonce.t.");
1330 strcat (dep_sec_name, name);
1331 dep_sec = bfd_get_section_by_name (abfd, dep_sec_name);
1332 if (dep_sec == NULL || ! input_section_linked (dep_sec))
1334 free (dep_sec_name);
1337 free (dep_sec_name);
1345 xtensa_strip_inconsistent_linkonce_sections (lang_statement_list_type *slist)
1347 lang_statement_union_type **s_p = &slist->head;
1350 lang_statement_union_type *s = *s_p;
1351 lang_statement_union_type *s_next = (*s_p)->header.next;
1353 switch (s->header.type)
1355 case lang_input_section_enum:
1356 if (is_inconsistent_linkonce_section (s->input_section.section))
1358 s->input_section.section->output_section = bfd_abs_section_ptr;
1364 case lang_constructors_statement_enum:
1365 xtensa_strip_inconsistent_linkonce_sections (&constructor_list);
1368 case lang_output_section_statement_enum:
1369 if (s->output_section_statement.children.head)
1370 xtensa_strip_inconsistent_linkonce_sections
1371 (&s->output_section_statement.children);
1374 case lang_wild_statement_enum:
1375 xtensa_strip_inconsistent_linkonce_sections
1376 (&s->wild_statement.children);
1379 case lang_group_statement_enum:
1380 xtensa_strip_inconsistent_linkonce_sections
1381 (&s->group_statement.children);
1384 case lang_data_statement_enum:
1385 case lang_reloc_statement_enum:
1386 case lang_object_symbols_statement_enum:
1387 case lang_output_statement_enum:
1388 case lang_target_statement_enum:
1389 case lang_input_statement_enum:
1390 case lang_assignment_statement_enum:
1391 case lang_padding_statement_enum:
1392 case lang_address_statement_enum:
1393 case lang_fill_statement_enum:
1401 s_p = &(*s_p)->header.next;
1404 /* Reset the tail of the list, in case the last entry was removed. */
1405 if (s_p != slist->tail)
1411 xtensa_wild_group_interleave_callback (lang_statement_union_type *statement)
1413 lang_wild_statement_type *w;
1414 reloc_deps_graph *deps;
1415 if (statement->header.type == lang_wild_statement_enum)
1417 #if EXTRA_VALIDATION
1418 size_t old_child_count;
1419 size_t new_child_count;
1423 w = &statement->wild_statement;
1427 /* If it has 0 or 1 section bound, then do not reorder. */
1428 if (w->children.head == NULL
1429 || (w->children.head->header.type == lang_input_section_enum
1430 && w->children.head->header.next == NULL))
1433 if (w->filenames_sorted)
1436 /* Check for sorting in a section list wildcard spec as well. */
1439 struct wildcard_list *l;
1440 for (l = w->section_list; l != NULL; l = l->next)
1442 if (l->spec.sorted == by_name)
1450 /* Special case until the NOREORDER linker directive is supported:
1451 *(.init) output sections and *(.fini) specs may NOT be reordered. */
1453 /* Check for sorting in a section list wildcard spec as well. */
1456 struct wildcard_list *l;
1457 for (l = w->section_list; l != NULL; l = l->next)
1460 && ((strcmp (".init", l->spec.name) == 0)
1461 || (strcmp (".fini", l->spec.name) == 0)))
1469 #if EXTRA_VALIDATION
1470 old_child_count = ld_count_children (statement);
1473 /* It is now officially a target. Build the graph of source
1474 section -> target section (kept as a list of edges). */
1475 deps = ld_build_required_section_dependence (statement);
1477 /* If this wildcard does not reorder.... */
1478 if (!no_reorder && deps->count != 0)
1480 /* First check for reverse dependences. Fix if possible. */
1481 xtensa_layout_wild (deps, w);
1483 xtensa_move_dependencies_to_front (deps, w);
1484 #if EXTRA_VALIDATION
1485 new_child_count = ld_count_children (statement);
1486 ASSERT (new_child_count == old_child_count);
1489 xtensa_colocate_literals (deps, statement);
1491 #if EXTRA_VALIDATION
1492 new_child_count = ld_count_children (statement);
1493 ASSERT (new_child_count == old_child_count);
1498 free_reloc_deps_graph (deps);
1504 xtensa_wild_group_interleave (lang_statement_union_type *s)
1506 lang_for_each_statement_worker (xtensa_wild_group_interleave_callback, s);
1511 xtensa_layout_wild (const reloc_deps_graph *deps, lang_wild_statement_type *w)
1513 /* If it does not fit initially, we need to do this step. Move all
1514 of the wild literal sections to a new list, then move each of
1515 them back in just before the first section they depend on. */
1516 lang_statement_union_type **s_p;
1517 #if EXTRA_VALIDATION
1518 size_t old_count, new_count;
1522 lang_wild_statement_type literal_wild;
1523 literal_wild.header.next = NULL;
1524 literal_wild.header.type = lang_wild_statement_enum;
1525 literal_wild.filename = NULL;
1526 literal_wild.filenames_sorted = false;
1527 literal_wild.section_list = NULL;
1528 literal_wild.keep_sections = false;
1529 literal_wild.children.head = NULL;
1530 literal_wild.children.tail = &literal_wild.children.head;
1532 #if EXTRA_VALIDATION
1533 old_count = ld_count_children ((lang_statement_union_type*) w);
1536 s_p = &w->children.head;
1537 while (*s_p != NULL)
1539 lang_statement_union_type *l = *s_p;
1540 if (l->header.type == lang_input_section_enum)
1542 if (section_is_target (deps, l)
1543 && ! section_is_source (deps, l))
1546 *s_p = l->header.next;
1548 w->children.tail = s_p;
1549 l->header.next = NULL;
1552 *literal_wild.children.tail = l;
1553 literal_wild.children.tail = &l->header.next;
1557 s_p = &(*s_p)->header.next;
1560 #if EXTRA_VALIDATION
1561 ct1 = ld_count_children ((lang_statement_union_type*) w);
1562 ct2 = ld_count_children ((lang_statement_union_type*) &literal_wild);
1564 ASSERT (old_count == (ct1 + ct2));
1567 /* Now place them back in front of their dependent sections. */
1569 while (literal_wild.children.head != NULL)
1571 lang_statement_union_type *lit = literal_wild.children.head;
1572 bool placed = false;
1574 #if EXTRA_VALIDATION
1580 literal_wild.children.head = lit->header.next;
1581 if (literal_wild.children.head == NULL)
1582 literal_wild.children.tail = &literal_wild.children.head;
1583 lit->header.next = NULL;
1585 /* Find a spot to place it. */
1586 for (s_p = &w->children.head; *s_p != NULL; s_p = &(*s_p)->header.next)
1588 lang_statement_union_type *src = *s_p;
1589 if (deps_has_edge (deps, src, lit))
1591 /* Place it here. */
1592 lit->header.next = *s_p;
1601 /* Put it at the end. */
1602 *w->children.tail = lit;
1603 w->children.tail = &lit->header.next;
1607 #if EXTRA_VALIDATION
1608 new_count = ld_count_children ((lang_statement_union_type*) w);
1609 ASSERT (new_count == old_count);
1615 xtensa_colocate_output_literals_callback (lang_statement_union_type *statement)
1617 reloc_deps_graph *deps;
1618 if (statement->header.type == lang_output_section_statement_enum)
1620 /* Now, we walk over the contours of the output section statement.
1622 First we build the literal section dependences as before.
1624 At the first uniquely_literal section, we mark it as a good
1625 spot to place other literals. Continue walking (and counting
1626 sizes) until we find the next literal section. If this
1627 section can be moved to the first one, then we move it. If
1628 we every find a modification of ".", start over. If we find
1629 a labeling of the current location, start over. Finally, at
1630 the end, if we require page alignment, add page alignments. */
1632 #if EXTRA_VALIDATION
1633 size_t old_child_count;
1634 size_t new_child_count;
1636 bool no_reorder = false;
1638 #if EXTRA_VALIDATION
1639 old_child_count = ld_count_children (statement);
1642 /* It is now officially a target. Build the graph of source
1643 section -> target section (kept as a list of edges). */
1645 deps = ld_build_required_section_dependence (statement);
1647 /* If this wildcard does not reorder.... */
1650 /* First check for reverse dependences. Fix if possible. */
1651 xtensa_colocate_literals (deps, statement);
1653 #if EXTRA_VALIDATION
1654 new_child_count = ld_count_children (statement);
1655 ASSERT (new_child_count == old_child_count);
1659 /* Insert align/offset assignment statement. */
1660 if (xtensa_use_literal_pages)
1662 ld_xtensa_insert_page_offsets (0, statement, deps,
1663 xtensa_use_literal_pages);
1664 lang_for_each_statement_worker (xtensa_ldlang_clear_addresses,
1669 free_reloc_deps_graph (deps);
1675 xtensa_colocate_output_literals (lang_statement_union_type *s)
1677 lang_for_each_statement_worker (xtensa_colocate_output_literals_callback, s);
1682 xtensa_ldlang_clear_addresses (lang_statement_union_type *statement)
1684 switch (statement->header.type)
1686 case lang_input_section_enum:
1688 asection *bfd_section = statement->input_section.section;
1689 bfd_section->output_offset = 0;
1699 ld_assign_relative_paged_dot (bfd_vma dot,
1700 lang_statement_union_type *s,
1701 const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
1704 /* Walk through all of the input statements in this wild statement
1705 assign dot to all of them. */
1707 xtensa_ld_iter_stack *stack = NULL;
1708 xtensa_ld_iter_stack **stack_p = &stack;
1710 bool first_section = false;
1711 bool in_literals = false;
1713 for (iter_stack_create (stack_p, s);
1714 !iter_stack_empty (stack_p);
1715 iter_stack_next (stack_p))
1717 lang_statement_union_type *l = iter_stack_current (stack_p);
1719 switch (l->header.type)
1721 case lang_input_section_enum:
1723 asection *section = l->input_section.section;
1724 size_t align_pow = section->alignment_power;
1725 bool do_xtensa_alignment = false;
1729 bool sec_is_target = section_is_target (deps, l);
1730 bool sec_is_source = section_is_source (deps, l);
1732 if (section->size != 0
1734 || (in_literals && !sec_is_target)
1735 || (!in_literals && sec_is_target)))
1737 do_xtensa_alignment = true;
1739 first_section = false;
1740 if (section->size != 0)
1741 in_literals = (sec_is_target && !sec_is_source);
1744 if (do_xtensa_alignment && xtensa_page_power != 0)
1745 dot += (1 << xtensa_page_power);
1747 dot = align_power (dot, align_pow);
1748 section->output_offset = dot;
1749 dot += section->size;
1752 case lang_fill_statement_enum:
1753 dot += l->fill_statement.size;
1755 case lang_padding_statement_enum:
1756 dot += l->padding_statement.size;
1767 ld_local_file_relocations_fit (lang_statement_union_type *statement,
1768 const reloc_deps_graph *deps ATTRIBUTE_UNUSED)
1770 /* Walk over all of the dependencies that we identified and make
1771 sure that IF the source and target are here (addr != 0):
1772 1) target addr < source addr
1773 2) (roundup(source + source_size, 4) - rounddown(target, 4))
1774 < (256K - (1 << bad align))
1775 Need a worst-case proof.... */
1777 xtensa_ld_iter_stack *stack = NULL;
1778 xtensa_ld_iter_stack **stack_p = &stack;
1779 size_t max_align_power = 0;
1780 size_t align_penalty = 256;
1784 /* Find the worst-case alignment requirement for this set of statements. */
1785 for (iter_stack_create (stack_p, statement);
1786 !iter_stack_empty (stack_p);
1787 iter_stack_next (stack_p))
1789 lang_statement_union_type *l = iter_stack_current (stack_p);
1790 if (l->header.type == lang_input_section_enum)
1792 lang_input_section_type *input = &l->input_section;
1793 asection *section = input->section;
1794 if (section->alignment_power > max_align_power)
1795 max_align_power = section->alignment_power;
1799 /* Now check that everything fits. */
1800 for (i = 0; i < deps->count; i++)
1802 asection *sec = deps->sections[i];
1803 const reloc_deps_section *deps_section =
1804 xtensa_get_section_deps (deps, sec);
1807 /* We choose to walk through the successors. */
1808 for (e = deps_section->succs; e != NULL; e = e->next)
1810 if (e->src != e->tgt
1811 && e->src->output_section == e->tgt->output_section
1812 && e->src->output_offset != 0
1813 && e->tgt->output_offset != 0)
1816 align_power (e->src->output_offset + e->src->size, 2);
1817 bfd_vma target_addr = e->tgt->output_offset & ~3;
1818 if (l32r_addr < target_addr)
1821 fprintf (stderr, "Warning: "
1822 "l32r target section before l32r\n");
1827 if (l32r_addr - target_addr > 256 * 1024 - align_penalty)
1839 ld_xtensa_insert_page_offsets (bfd_vma dot,
1840 lang_statement_union_type *s,
1841 reloc_deps_graph *deps,
1844 xtensa_ld_iter_stack *stack = NULL;
1845 xtensa_ld_iter_stack **stack_p = &stack;
1847 bool first_section = false;
1848 bool in_literals = false;
1853 for (iter_stack_create (stack_p, s);
1854 !iter_stack_empty (stack_p);
1855 iter_stack_next (stack_p))
1857 lang_statement_union_type *l = iter_stack_current (stack_p);
1859 switch (l->header.type)
1861 case lang_input_section_enum:
1863 asection *section = l->input_section.section;
1864 bool do_xtensa_alignment = false;
1868 if (section->size != 0
1870 || (in_literals && !section_is_target (deps, l))
1871 || (!in_literals && section_is_target (deps, l))))
1873 do_xtensa_alignment = true;
1875 first_section = false;
1876 if (section->size != 0)
1878 in_literals = (section_is_target (deps, l)
1879 && !section_is_source (deps, l));
1883 if (do_xtensa_alignment && xtensa_page_power != 0)
1885 /* Create an expression that increments the current address,
1886 i.e., "dot", by (1 << xtensa_align_power). */
1887 etree_type *name_op = exp_nameop (NAME, ".");
1888 etree_type *addend_op = exp_intop (1 << xtensa_page_power);
1889 etree_type *add_op = exp_binop ('+', name_op, addend_op);
1890 etree_type *assign_op = exp_assign (".", add_op, false);
1892 lang_assignment_statement_type *assign_stmt;
1893 lang_statement_union_type *assign_union;
1894 lang_statement_list_type tmplist;
1896 /* There is hidden state in "lang_add_assignment". It
1897 appends the new assignment statement to the stat_ptr
1898 list. Thus, we swap it before and after the call. */
1900 lang_list_init (&tmplist);
1901 push_stat_ptr (&tmplist);
1902 /* Warning: side effect; statement appended to stat_ptr. */
1903 assign_stmt = lang_add_assignment (assign_op);
1904 assign_union = (lang_statement_union_type *) assign_stmt;
1907 assign_union->header.next = l;
1908 *(*stack_p)->iterloc.loc = assign_union;
1909 iter_stack_next (stack_p);
1922 # Define some shell vars to insert bits of code into the standard ELF
1923 # parse_args and list_options functions.
1925 PARSE_AND_LIST_PROLOGUE='
1926 #define OPTION_OPT_SIZEOPT (300)
1927 #define OPTION_LITERAL_MOVEMENT (OPTION_OPT_SIZEOPT + 1)
1928 #define OPTION_NO_LITERAL_MOVEMENT (OPTION_LITERAL_MOVEMENT + 1)
1929 #define OPTION_ABI_WINDOWED (OPTION_NO_LITERAL_MOVEMENT + 1)
1930 #define OPTION_ABI_CALL0 (OPTION_ABI_WINDOWED + 1)
1931 extern int elf32xtensa_size_opt;
1932 extern int elf32xtensa_no_literal_movement;
1933 extern int elf32xtensa_abi;
1936 PARSE_AND_LIST_LONGOPTS='
1937 { "size-opt", no_argument, NULL, OPTION_OPT_SIZEOPT},
1938 { "literal-movement", no_argument, NULL, OPTION_LITERAL_MOVEMENT},
1939 { "no-literal-movement", no_argument, NULL, OPTION_NO_LITERAL_MOVEMENT},
1940 { "abi-windowed", no_argument, NULL, OPTION_ABI_WINDOWED},
1941 { "abi-call0", no_argument, NULL, OPTION_ABI_CALL0},
1944 PARSE_AND_LIST_OPTIONS='
1946 --size-opt When relaxing longcalls, prefer size\n\
1947 optimization over branch target alignment\n"));
1949 --abi-windowed Choose windowed ABI for the output object\n"));
1951 --abi-call0 Choose call0 ABI for the output object\n"));
1954 PARSE_AND_LIST_ARGS_CASES='
1955 case OPTION_OPT_SIZEOPT:
1956 elf32xtensa_size_opt = 1;
1958 case OPTION_LITERAL_MOVEMENT:
1959 elf32xtensa_no_literal_movement = 0;
1961 case OPTION_NO_LITERAL_MOVEMENT:
1962 elf32xtensa_no_literal_movement = 1;
1964 case OPTION_ABI_WINDOWED:
1965 elf32xtensa_abi = XTHAL_ABI_WINDOWED;
1967 case OPTION_ABI_CALL0:
1968 elf32xtensa_abi = XTHAL_ABI_CALL0;
1972 # Replace some of the standard ELF functions with our own versions.
1974 LDEMUL_BEFORE_PARSE=elf_xtensa_before_parse
1975 LDEMUL_AFTER_OPEN=elf_xtensa_after_open
1976 LDEMUL_CHOOSE_TARGET=elf_xtensa_choose_target
1977 LDEMUL_BEFORE_ALLOCATION=elf_xtensa_before_allocation