1 # This shell script emits a C file. -*- C -*-
2 # Copyright (C) 2003-2016 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 elf32.em, and defines extra xtensa-elf
27 #include <xtensa-config.h>
28 #include "../bfd/elf-bfd.h"
29 #include "../bfd/libbfd.h"
30 #include "elf/xtensa.h"
33 /* Provide default values for new configuration settings. */
38 static void xtensa_wild_group_interleave (lang_statement_union_type *);
39 static void xtensa_colocate_output_literals (lang_statement_union_type *);
40 static void xtensa_strip_inconsistent_linkonce_sections
41 (lang_statement_list_type *);
44 /* This number is irrelevant until we turn on use_literal_pages */
45 static bfd_vma xtensa_page_power = 12; /* 4K pages. */
47 /* To force a page break between literals and text, change
48 xtensa_use_literal_pages to "TRUE". */
49 static bfd_boolean xtensa_use_literal_pages = FALSE;
51 #define EXTRA_VALIDATION 0
55 elf_xtensa_choose_target (int argc ATTRIBUTE_UNUSED,
56 char **argv ATTRIBUTE_UNUSED)
59 return "${BIG_OUTPUT_FORMAT}";
61 return "${LITTLE_OUTPUT_FORMAT}";
66 elf_xtensa_before_parse (void)
68 /* Just call the default hook.... Tensilica's version of this function
69 does some other work that isn't relevant here. */
70 gld${EMULATION_NAME}_before_parse ();
75 remove_section (bfd *abfd, asection *os)
78 for (spp = &abfd->sections; *spp; spp = &(*spp)->next)
82 os->owner->section_count--;
89 replace_insn_sec_with_prop_sec (bfd *abfd,
90 const char *insn_sec_name,
91 const char *prop_sec_name,
96 bfd_byte *prop_contents = NULL;
97 bfd_byte *insn_contents = NULL;
100 Elf_Internal_Shdr *rel_hdr;
101 Elf_Internal_Rela *internal_relocs = NULL;
102 unsigned reloc_count;
105 insn_sec = bfd_get_section_by_name (abfd, insn_sec_name);
106 if (insn_sec == NULL)
108 entry_count = insn_sec->size / 8;
110 prop_sec = bfd_get_section_by_name (abfd, prop_sec_name);
111 if (prop_sec != NULL && insn_sec != NULL)
113 *error_message = _("file already has property tables");
117 if (insn_sec->size != 0)
119 insn_contents = (bfd_byte *) bfd_malloc (insn_sec->size);
120 if (insn_contents == NULL)
122 *error_message = _("out of memory");
125 if (! bfd_get_section_contents (abfd, insn_sec, insn_contents,
126 (file_ptr) 0, insn_sec->size))
128 *error_message = _("failed to read section contents");
133 /* Create a property table section for it. */
134 prop_sec_name = strdup (prop_sec_name);
135 prop_sec = bfd_make_section_with_flags
136 (abfd, prop_sec_name, bfd_get_section_flags (abfd, insn_sec));
138 || ! bfd_set_section_alignment (abfd, prop_sec, 2))
140 *error_message = _("could not create new section");
144 prop_sec->size = entry_count * 12;
145 prop_contents = (bfd_byte *) bfd_zalloc (abfd, prop_sec->size);
146 elf_section_data (prop_sec)->this_hdr.contents = prop_contents;
148 /* The entry size and size must be set to allow the linker to compute
149 the number of relocations since it does not use reloc_count. */
150 rel_hdr = _bfd_elf_single_rel_hdr (prop_sec);
151 rel_hdr->sh_entsize = sizeof (Elf32_External_Rela);
152 rel_hdr->sh_size = _bfd_elf_single_rel_hdr (insn_sec)->sh_size;
154 if (prop_contents == NULL && prop_sec->size != 0)
156 *error_message = _("could not allocate section contents");
160 /* Read the relocations. */
161 reloc_count = insn_sec->reloc_count;
162 if (reloc_count != 0)
164 /* If there is already an internal_reloc, then save it so that the
165 read_relocs function freshly allocates a copy. */
166 Elf_Internal_Rela *saved_relocs = elf_section_data (insn_sec)->relocs;
168 elf_section_data (insn_sec)->relocs = NULL;
170 _bfd_elf_link_read_relocs (abfd, insn_sec, NULL, NULL, FALSE);
171 elf_section_data (insn_sec)->relocs = saved_relocs;
173 if (internal_relocs == NULL)
175 *error_message = _("out of memory");
180 /* Create a relocation section for the property section. */
181 if (internal_relocs != NULL)
183 elf_section_data (prop_sec)->relocs = internal_relocs;
184 prop_sec->reloc_count = reloc_count;
187 /* Now copy each insn table entry to the prop table entry with
188 appropriate flags. */
189 for (entry = 0; entry < entry_count; ++entry)
192 unsigned flags = (XTENSA_PROP_INSN | XTENSA_PROP_NO_TRANSFORM
193 | XTENSA_PROP_INSN_NO_REORDER);
194 value = bfd_get_32 (abfd, insn_contents + entry * 8 + 0);
195 bfd_put_32 (abfd, value, prop_contents + entry * 12 + 0);
196 value = bfd_get_32 (abfd, insn_contents + entry * 8 + 4);
197 bfd_put_32 (abfd, value, prop_contents + entry * 12 + 4);
198 bfd_put_32 (abfd, flags, prop_contents + entry * 12 + 8);
201 /* Now copy all of the relocations. Change offsets for the
202 instruction table section to offsets in the property table
208 for (i = 0; i < reloc_count; i++)
210 Elf_Internal_Rela *rela;
213 rela = &internal_relocs[i];
215 /* If this relocation is to the .xt.insn section,
216 change the section number and the offset. */
217 r_offset = rela->r_offset;
218 r_offset += 4 * (r_offset / 8);
219 rela->r_offset = r_offset;
223 remove_section (abfd, insn_sec);
226 free (insn_contents);
231 if (prop_sec && prop_sec->owner)
232 remove_section (abfd, prop_sec);
234 free (insn_contents);
236 free (internal_relocs);
242 #define PROP_SEC_BASE_NAME ".xt.prop"
243 #define INSN_SEC_BASE_NAME ".xt.insn"
244 #define LINKONCE_SEC_OLD_TEXT_BASE_NAME ".gnu.linkonce.x."
248 replace_instruction_table_sections (bfd *abfd, asection *sec)
251 const char *insn_sec_name = NULL;
252 char *prop_sec_name = NULL;
253 char *owned_prop_sec_name = NULL;
254 const char *sec_name;
256 sec_name = bfd_get_section_name (abfd, sec);
257 if (strcmp (sec_name, INSN_SEC_BASE_NAME) == 0)
259 insn_sec_name = INSN_SEC_BASE_NAME;
260 prop_sec_name = PROP_SEC_BASE_NAME;
262 else if (CONST_STRNEQ (sec_name, LINKONCE_SEC_OLD_TEXT_BASE_NAME))
264 insn_sec_name = sec_name;
265 owned_prop_sec_name = (char *) xmalloc (strlen (sec_name) + 20);
266 prop_sec_name = owned_prop_sec_name;
267 strcpy (prop_sec_name, ".gnu.linkonce.prop.t.");
268 strcat (prop_sec_name,
269 sec_name + strlen (LINKONCE_SEC_OLD_TEXT_BASE_NAME));
271 if (insn_sec_name != NULL)
273 if (! replace_insn_sec_with_prop_sec (abfd, insn_sec_name, prop_sec_name,
276 einfo (_("%P: warning: failed to convert %s table in %B (%s); subsequent disassembly may be incomplete\n"),
277 insn_sec_name, abfd, message);
280 if (owned_prop_sec_name)
281 free (owned_prop_sec_name);
285 /* This is called after all input sections have been opened to convert
286 instruction tables (.xt.insn, gnu.linkonce.x.*) tables into property
287 tables (.xt.prop) before any section placement. */
290 elf_xtensa_after_open (void)
292 /* First call the ELF version. */
293 gld${EMULATION_NAME}_after_open ();
295 /* Now search the input files looking for instruction table sections. */
296 LANG_FOR_EACH_INPUT_STATEMENT (f)
298 asection *sec = f->the_bfd->sections;
301 /* Do not use bfd_map_over_sections here since we are removing
302 sections as we iterate. */
305 next_sec = sec->next;
306 replace_instruction_table_sections (f->the_bfd, sec);
314 xt_config_info_unpack_and_check (char *data,
315 bfd_boolean *pmismatch,
331 /* Overwrite the equal sign. */
334 /* Check if this is a quoted string or a number. */
337 /* No string values are currently checked by LD;
338 just skip over the quotes. */
343 /* Overwrite the trailing quote. */
350 num = strtoul (d, &d, 0);
352 if (! strcmp (key, "ABI"))
354 if (num != XSHAL_ABI)
357 *pmsg = "ABI does not match";
360 else if (! strcmp (key, "USE_ABSOLUTE_LITERALS"))
362 if (num != XSHAL_USE_ABSOLUTE_LITERALS)
365 *pmsg = "incompatible use of the Extended L32R option";
381 #define XTINFO_NAME "Xtensa_Info"
382 #define XTINFO_NAMESZ 12
383 #define XTINFO_TYPE 1
386 check_xtensa_info (bfd *abfd, asection *info_sec)
388 char *data, *errmsg = "";
389 bfd_boolean mismatch;
391 data = xmalloc (info_sec->size);
392 if (! bfd_get_section_contents (abfd, info_sec, data, 0, info_sec->size))
393 einfo (_("%F%P:%B: cannot read contents of section %A\n"), abfd, info_sec);
395 if (info_sec->size > 24
396 && info_sec->size >= 24 + bfd_get_32 (abfd, data + 4)
397 && bfd_get_32 (abfd, data + 0) == XTINFO_NAMESZ
398 && bfd_get_32 (abfd, data + 8) == XTINFO_TYPE
399 && strcmp (data + 12, XTINFO_NAME) == 0
400 && xt_config_info_unpack_and_check (data + 12 + XTINFO_NAMESZ,
404 einfo (_("%P:%B: warning: incompatible Xtensa configuration (%s)\n"),
408 einfo (_("%P:%B: warning: cannot parse .xtensa.info section\n"), abfd);
414 /* This is called after the sections have been attached to output
415 sections, but before any sizes or addresses have been set. */
418 elf_xtensa_before_allocation (void)
420 asection *info_sec, *first_info_sec;
422 bfd_boolean is_big_endian = XCHAL_HAVE_BE;
424 /* Check that the output endianness matches the Xtensa
425 configuration. The BFD library always includes both big and
426 little endian target vectors for Xtensa, but it only supports the
427 detailed instruction encode/decode operations (such as are
428 required to process relocations) for the selected Xtensa
432 && link_info.output_bfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
434 einfo (_("%F%P: little endian output does not match "
435 "Xtensa configuration\n"));
438 && link_info.output_bfd->xvec->byteorder == BFD_ENDIAN_BIG)
440 einfo (_("%F%P: big endian output does not match "
441 "Xtensa configuration\n"));
444 /* Keep track of the first input .xtensa.info section, and as a fallback,
445 the first input bfd where a .xtensa.info section could be created.
446 After the input .xtensa.info has been checked, the contents of the
447 first one will be replaced with the output .xtensa.info table. */
451 LANG_FOR_EACH_INPUT_STATEMENT (f)
453 /* Check that the endianness for each input file matches the output.
454 The merge_private_bfd_data hook has already reported any mismatches
455 as errors, but those errors are not fatal. At this point, we
456 cannot go any further if there are any mismatches. */
457 if ((is_big_endian && f->the_bfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
458 || (!is_big_endian && f->the_bfd->xvec->byteorder == BFD_ENDIAN_BIG))
459 einfo (_("%F%P: cross-endian linking for %B not supported\n"),
463 first_bfd = f->the_bfd;
465 info_sec = bfd_get_section_by_name (f->the_bfd, ".xtensa.info");
469 if (! first_info_sec)
470 first_info_sec = info_sec;
472 /* Unpack the .xtensa.info section and check it against the current
473 Xtensa configuration. */
474 check_xtensa_info (f->the_bfd, info_sec);
476 /* Do not include this copy of .xtensa.info in the output. */
478 info_sec->flags |= SEC_EXCLUDE;
481 /* Reuse the first .xtensa.info input section to hold the output
482 .xtensa.info; or, if none were found, create a new section in the
483 first input bfd (assuming there is one). */
484 info_sec = first_info_sec;
485 if (! info_sec && first_bfd)
487 info_sec = bfd_make_section_with_flags (first_bfd, ".xtensa.info",
488 SEC_HAS_CONTENTS | SEC_READONLY);
490 einfo (_("%F%P: failed to create .xtensa.info section\n"));
494 int xtensa_info_size;
497 info_sec->flags &= ~SEC_EXCLUDE;
498 info_sec->flags |= SEC_IN_MEMORY;
500 data = xmalloc (100);
501 sprintf (data, "USE_ABSOLUTE_LITERALS=%d\nABI=%d\n",
502 XSHAL_USE_ABSOLUTE_LITERALS, XSHAL_ABI);
503 xtensa_info_size = strlen (data) + 1;
505 /* Add enough null terminators to pad to a word boundary. */
507 data[xtensa_info_size++] = 0;
508 while ((xtensa_info_size & 3) != 0);
510 info_sec->size = 12 + XTINFO_NAMESZ + xtensa_info_size;
511 info_sec->contents = xmalloc (info_sec->size);
512 bfd_put_32 (info_sec->owner, XTINFO_NAMESZ, info_sec->contents + 0);
513 bfd_put_32 (info_sec->owner, xtensa_info_size, info_sec->contents + 4);
514 bfd_put_32 (info_sec->owner, XTINFO_TYPE, info_sec->contents + 8);
515 memcpy (info_sec->contents + 12, XTINFO_NAME, XTINFO_NAMESZ);
516 memcpy (info_sec->contents + 12 + XTINFO_NAMESZ, data, xtensa_info_size);
520 /* Enable relaxation by default if the "--no-relax" option was not
521 specified. This is done here instead of in the before_parse hook
522 because there is a check in main() to prohibit use of --relax and
523 -r together and that combination should be allowed for Xtensa. */
524 if (RELAXATION_DISABLED_BY_DEFAULT)
527 xtensa_strip_inconsistent_linkonce_sections (stat_ptr);
529 gld${EMULATION_NAME}_before_allocation ();
531 xtensa_wild_group_interleave (stat_ptr->head);
533 if (RELAXATION_ENABLED)
534 xtensa_colocate_output_literals (stat_ptr->head);
536 /* TBD: We need to force the page alignments to here and only do
537 them as needed for the entire output section. Finally, if this
538 is a relocatable link then we need to add alignment notes so
539 that the literals can be separated later. */
543 typedef struct wildcard_list section_name_list;
545 typedef struct reloc_deps_e_t reloc_deps_e;
546 typedef struct reloc_deps_section_t reloc_deps_section;
547 typedef struct reloc_deps_graph_t reloc_deps_graph;
550 struct reloc_deps_e_t
552 asection *src; /* Contains l32rs. */
553 asection *tgt; /* Contains literals. */
557 /* Place these in the userdata field. */
558 struct reloc_deps_section_t
562 bfd_boolean is_only_literal;
566 struct reloc_deps_graph_t
573 static void xtensa_layout_wild
574 (const reloc_deps_graph *, lang_wild_statement_type *);
576 typedef void (*deps_callback_t) (asection *, /* src_sec */
577 bfd_vma, /* src_offset */
578 asection *, /* target_sec */
579 bfd_vma, /* target_offset */
580 void *); /* closure */
582 extern bfd_boolean xtensa_callback_required_dependence
583 (bfd *, asection *, struct bfd_link_info *, deps_callback_t, void *);
584 static void xtensa_ldlang_clear_addresses (lang_statement_union_type *);
585 static bfd_boolean ld_local_file_relocations_fit
586 (lang_statement_union_type *, const reloc_deps_graph *);
587 static bfd_vma ld_assign_relative_paged_dot
588 (bfd_vma, lang_statement_union_type *, const reloc_deps_graph *,
590 static bfd_vma ld_xtensa_insert_page_offsets
591 (bfd_vma, lang_statement_union_type *, reloc_deps_graph *, bfd_boolean);
593 static size_t ld_count_children (lang_statement_union_type *);
596 extern lang_statement_list_type constructor_list;
598 static reloc_deps_section *
599 xtensa_get_section_deps (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
602 /* We have a separate function for this so that
603 we could in the future keep a completely independent
604 structure that maps a section to its dependence edges.
605 For now, we place these in the sec->userdata field. */
606 reloc_deps_section *sec_deps = sec->userdata;
611 xtensa_set_section_deps (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
613 reloc_deps_section *deps_section)
615 sec->userdata = 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 if (deps->sections != NULL)
642 free (deps->sections);
643 deps->sections = new_sections;
644 deps->size = new_size;
646 deps->sections[deps->count] = sec;
652 free_reloc_deps_graph (reloc_deps_graph *deps)
655 for (i = 0; i < deps->count; i++)
657 asection *sec = deps->sections[i];
658 reloc_deps_section *sec_deps;
659 sec_deps = xtensa_get_section_deps (deps, sec);
663 while (sec_deps->succs != NULL)
665 next = sec_deps->succs->next;
666 free (sec_deps->succs);
667 sec_deps->succs = next;
670 while (sec_deps->preds != NULL)
672 next = sec_deps->preds->next;
673 free (sec_deps->preds);
674 sec_deps->preds = next;
678 xtensa_set_section_deps (deps, sec, NULL);
681 free (deps->sections);
688 section_is_source (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
689 lang_statement_union_type *s)
692 const reloc_deps_section *sec_deps;
694 if (s->header.type != lang_input_section_enum)
696 sec = s->input_section.section;
698 sec_deps = xtensa_get_section_deps (deps, sec);
699 return sec_deps && sec_deps->succs != NULL;
704 section_is_target (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
705 lang_statement_union_type *s)
708 const reloc_deps_section *sec_deps;
710 if (s->header.type != lang_input_section_enum)
712 sec = s->input_section.section;
714 sec_deps = xtensa_get_section_deps (deps, sec);
715 return sec_deps && sec_deps->preds != NULL;
720 section_is_source_or_target (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
721 lang_statement_union_type *s)
723 return (section_is_source (deps, s)
724 || section_is_target (deps, s));
728 typedef struct xtensa_ld_iter_stack_t xtensa_ld_iter_stack;
729 typedef struct xtensa_ld_iter_t xtensa_ld_iter;
731 struct xtensa_ld_iter_t
733 lang_statement_union_type *parent; /* Parent of the list. */
734 lang_statement_list_type *l; /* List that holds it. */
735 lang_statement_union_type **loc; /* Place in the list. */
738 struct xtensa_ld_iter_stack_t
740 xtensa_ld_iter iterloc; /* List that hold it. */
742 xtensa_ld_iter_stack *next; /* Next in the stack. */
743 xtensa_ld_iter_stack *prev; /* Back pointer for stack. */
748 ld_xtensa_move_section_after (xtensa_ld_iter *to, xtensa_ld_iter *current)
750 lang_statement_union_type *to_next;
751 lang_statement_union_type *current_next;
752 lang_statement_union_type **e;
755 size_t old_to_count, new_to_count;
756 size_t old_current_count, new_current_count;
763 old_to_count = ld_count_children (to->parent);
764 old_current_count = ld_count_children (current->parent);
767 to_next = *(to->loc);
768 current_next = (*current->loc)->header.next;
770 *(to->loc) = *(current->loc);
772 *(current->loc) = current_next;
773 (*(to->loc))->header.next = to_next;
775 /* reset "to" list tail */
776 for (e = &to->l->head; *e != NULL; e = &(*e)->header.next)
780 /* reset "current" list tail */
781 for (e = ¤t->l->head; *e != NULL; e = &(*e)->header.next)
783 current->l->tail = e;
786 new_to_count = ld_count_children (to->parent);
787 new_current_count = ld_count_children (current->parent);
789 ASSERT ((old_to_count + old_current_count)
790 == (new_to_count + new_current_count));
795 /* Can only be called with lang_statements that have lists. Returns
796 FALSE if the list is empty. */
799 iter_stack_empty (xtensa_ld_iter_stack **stack_p)
801 return *stack_p == NULL;
806 iter_stack_push (xtensa_ld_iter_stack **stack_p,
807 lang_statement_union_type *parent)
809 xtensa_ld_iter_stack *stack;
810 lang_statement_list_type *l = NULL;
812 switch (parent->header.type)
814 case lang_output_section_statement_enum:
815 l = &parent->output_section_statement.children;
817 case lang_wild_statement_enum:
818 l = &parent->wild_statement.children;
820 case lang_group_statement_enum:
821 l = &parent->group_statement.children;
828 /* Empty. do not push. */
829 if (l->tail == &l->head)
832 stack = xmalloc (sizeof (xtensa_ld_iter_stack));
833 memset (stack, 0, sizeof (xtensa_ld_iter_stack));
834 stack->iterloc.parent = parent;
835 stack->iterloc.l = l;
836 stack->iterloc.loc = &l->head;
838 stack->next = *stack_p;
840 if (*stack_p != NULL)
841 (*stack_p)->prev = stack;
848 iter_stack_pop (xtensa_ld_iter_stack **stack_p)
850 xtensa_ld_iter_stack *stack;
856 ASSERT (stack != NULL);
860 if (stack->next != NULL)
861 stack->next->prev = NULL;
863 *stack_p = stack->next;
868 /* This MUST be called if, during iteration, the user changes the
869 underlying structure. It will check for a NULL current and advance
873 iter_stack_update (xtensa_ld_iter_stack **stack_p)
875 if (!iter_stack_empty (stack_p)
876 && (*(*stack_p)->iterloc.loc) == NULL)
878 iter_stack_pop (stack_p);
880 while (!iter_stack_empty (stack_p)
881 && ((*(*stack_p)->iterloc.loc)->header.next == NULL))
883 iter_stack_pop (stack_p);
885 if (!iter_stack_empty (stack_p))
886 (*stack_p)->iterloc.loc = &(*(*stack_p)->iterloc.loc)->header.next;
892 iter_stack_next (xtensa_ld_iter_stack **stack_p)
894 xtensa_ld_iter_stack *stack;
895 lang_statement_union_type *current;
898 current = *stack->iterloc.loc;
899 /* If we are on the first element. */
902 switch (current->header.type)
904 case lang_output_section_statement_enum:
905 case lang_wild_statement_enum:
906 case lang_group_statement_enum:
907 /* If the list if not empty, we are done. */
908 if (iter_stack_push (stack_p, *stack->iterloc.loc))
910 /* Otherwise increment the pointer as normal. */
917 while (!iter_stack_empty (stack_p)
918 && ((*(*stack_p)->iterloc.loc)->header.next == NULL))
920 iter_stack_pop (stack_p);
922 if (!iter_stack_empty (stack_p))
923 (*stack_p)->iterloc.loc = &(*(*stack_p)->iterloc.loc)->header.next;
927 static lang_statement_union_type *
928 iter_stack_current (xtensa_ld_iter_stack **stack_p)
930 return *((*stack_p)->iterloc.loc);
934 /* The iter stack is a preorder. */
937 iter_stack_create (xtensa_ld_iter_stack **stack_p,
938 lang_statement_union_type *parent)
940 iter_stack_push (stack_p, parent);
945 iter_stack_copy_current (xtensa_ld_iter_stack **stack_p, xtensa_ld_iter *front)
947 *front = (*stack_p)->iterloc;
952 xtensa_colocate_literals (reloc_deps_graph *deps,
953 lang_statement_union_type *statement)
955 /* Keep a stack of pointers to control iteration through the contours. */
956 xtensa_ld_iter_stack *stack = NULL;
957 xtensa_ld_iter_stack **stack_p = &stack;
959 xtensa_ld_iter front; /* Location where new insertion should occur. */
960 xtensa_ld_iter *front_p = NULL;
962 xtensa_ld_iter current; /* Location we are checking. */
963 xtensa_ld_iter *current_p = NULL;
964 bfd_boolean in_literals = FALSE;
966 if (deps->count == 0)
969 iter_stack_create (stack_p, statement);
971 while (!iter_stack_empty (stack_p))
973 bfd_boolean skip_increment = FALSE;
974 lang_statement_union_type *l = iter_stack_current (stack_p);
976 switch (l->header.type)
978 case lang_assignment_statement_enum:
979 /* Any assignment statement should block reordering across it. */
984 case lang_input_section_enum:
987 in_literals = (section_is_target (deps, l)
988 && !section_is_source (deps, l));
992 iter_stack_copy_current (stack_p, front_p);
997 bfd_boolean is_target;
998 current_p = ¤t;
999 iter_stack_copy_current (stack_p, current_p);
1000 is_target = (section_is_target (deps, l)
1001 && !section_is_source (deps, l));
1005 iter_stack_copy_current (stack_p, front_p);
1007 in_literals = FALSE;
1013 /* Try to insert in place. */
1014 ld_xtensa_move_section_after (front_p, current_p);
1015 ld_assign_relative_paged_dot (0x100000,
1018 xtensa_use_literal_pages);
1020 /* We use this code because it's already written. */
1021 if (!ld_local_file_relocations_fit (statement, deps))
1024 ld_xtensa_move_section_after (current_p, front_p);
1025 /* Reset the literal placement. */
1026 iter_stack_copy_current (stack_p, front_p);
1030 /* Move front pointer up by one. */
1031 front_p->loc = &(*front_p->loc)->header.next;
1033 /* Do not increment the current pointer. */
1034 skip_increment = TRUE;
1044 if (!skip_increment)
1045 iter_stack_next (stack_p);
1047 /* Be careful to update the stack_p if it now is a null. */
1048 iter_stack_update (stack_p);
1051 lang_for_each_statement_worker (xtensa_ldlang_clear_addresses, statement);
1056 xtensa_move_dependencies_to_front (reloc_deps_graph *deps,
1057 lang_wild_statement_type *w)
1059 /* Keep a front pointer and a current pointer. */
1060 lang_statement_union_type **front;
1061 lang_statement_union_type **current;
1063 /* Walk to the end of the targets. */
1064 for (front = &w->children.head;
1065 (*front != NULL) && section_is_source_or_target (deps, *front);
1066 front = &(*front)->header.next)
1072 current = &(*front)->header.next;
1073 while (*current != NULL)
1075 if (section_is_source_or_target (deps, *current))
1077 /* Insert in place. */
1078 xtensa_ld_iter front_iter;
1079 xtensa_ld_iter current_iter;
1081 front_iter.parent = (lang_statement_union_type *) w;
1082 front_iter.l = &w->children;
1083 front_iter.loc = front;
1085 current_iter.parent = (lang_statement_union_type *) w;
1086 current_iter.l = &w->children;
1087 current_iter.loc = current;
1089 ld_xtensa_move_section_after (&front_iter, ¤t_iter);
1090 front = &(*front)->header.next;
1094 current = &(*current)->header.next;
1101 deps_has_sec_edge (const reloc_deps_graph *deps, asection *src, asection *tgt)
1103 const reloc_deps_section *sec_deps;
1104 const reloc_deps_e *sec_deps_e;
1106 sec_deps = xtensa_get_section_deps (deps, src);
1107 if (sec_deps == NULL)
1110 for (sec_deps_e = sec_deps->succs;
1112 sec_deps_e = sec_deps_e->next)
1114 ASSERT (sec_deps_e->src == src);
1115 if (sec_deps_e->tgt == tgt)
1123 deps_has_edge (const reloc_deps_graph *deps,
1124 lang_statement_union_type *src,
1125 lang_statement_union_type *tgt)
1127 if (!section_is_source (deps, src))
1129 if (!section_is_target (deps, tgt))
1132 if (src->header.type != lang_input_section_enum)
1134 if (tgt->header.type != lang_input_section_enum)
1137 return deps_has_sec_edge (deps, src->input_section.section,
1138 tgt->input_section.section);
1143 add_deps_edge (reloc_deps_graph *deps, asection *src_sec, asection *tgt_sec)
1145 reloc_deps_section *src_sec_deps;
1146 reloc_deps_section *tgt_sec_deps;
1148 reloc_deps_e *src_edge;
1149 reloc_deps_e *tgt_edge;
1151 if (deps_has_sec_edge (deps, src_sec, tgt_sec))
1154 src_sec_deps = xtensa_get_section_deps (deps, src_sec);
1155 if (src_sec_deps == NULL)
1157 /* Add a section. */
1158 src_sec_deps = xmalloc (sizeof (reloc_deps_section));
1159 memset (src_sec_deps, 0, sizeof (reloc_deps_section));
1160 src_sec_deps->is_only_literal = 0;
1161 src_sec_deps->preds = NULL;
1162 src_sec_deps->succs = NULL;
1163 xtensa_set_section_deps (deps, src_sec, src_sec_deps);
1164 xtensa_append_section_deps (deps, src_sec);
1167 tgt_sec_deps = xtensa_get_section_deps (deps, tgt_sec);
1168 if (tgt_sec_deps == NULL)
1170 /* Add a section. */
1171 tgt_sec_deps = xmalloc (sizeof (reloc_deps_section));
1172 memset (tgt_sec_deps, 0, sizeof (reloc_deps_section));
1173 tgt_sec_deps->is_only_literal = 0;
1174 tgt_sec_deps->preds = NULL;
1175 tgt_sec_deps->succs = NULL;
1176 xtensa_set_section_deps (deps, tgt_sec, tgt_sec_deps);
1177 xtensa_append_section_deps (deps, tgt_sec);
1180 /* Add the edges. */
1181 src_edge = xmalloc (sizeof (reloc_deps_e));
1182 memset (src_edge, 0, sizeof (reloc_deps_e));
1183 src_edge->src = src_sec;
1184 src_edge->tgt = tgt_sec;
1185 src_edge->next = src_sec_deps->succs;
1186 src_sec_deps->succs = src_edge;
1188 tgt_edge = xmalloc (sizeof (reloc_deps_e));
1189 memset (tgt_edge, 0, sizeof (reloc_deps_e));
1190 tgt_edge->src = src_sec;
1191 tgt_edge->tgt = tgt_sec;
1192 tgt_edge->next = tgt_sec_deps->preds;
1193 tgt_sec_deps->preds = tgt_edge;
1198 build_deps_graph_callback (asection *src_sec,
1199 bfd_vma src_offset ATTRIBUTE_UNUSED,
1200 asection *target_sec,
1201 bfd_vma target_offset ATTRIBUTE_UNUSED,
1204 reloc_deps_graph *deps = closure;
1206 /* If the target is defined. */
1207 if (target_sec != NULL)
1208 add_deps_edge (deps, src_sec, target_sec);
1212 static reloc_deps_graph *
1213 ld_build_required_section_dependence (lang_statement_union_type *s)
1215 reloc_deps_graph *deps;
1216 xtensa_ld_iter_stack *stack = NULL;
1218 deps = xmalloc (sizeof (reloc_deps_graph));
1219 deps->sections = NULL;
1223 for (iter_stack_create (&stack, s);
1224 !iter_stack_empty (&stack);
1225 iter_stack_next (&stack))
1227 lang_statement_union_type *l = iter_stack_current (&stack);
1229 if (l->header.type == lang_input_section_enum)
1231 lang_input_section_type *input;
1232 input = &l->input_section;
1233 xtensa_callback_required_dependence (input->section->owner,
1236 /* Use the same closure. */
1237 build_deps_graph_callback,
1245 #if EXTRA_VALIDATION
1247 ld_count_children (lang_statement_union_type *s)
1250 xtensa_ld_iter_stack *stack = NULL;
1251 for (iter_stack_create (&stack, s);
1252 !iter_stack_empty (&stack);
1253 iter_stack_next (&stack))
1255 lang_statement_union_type *l = iter_stack_current (&stack);
1261 #endif /* EXTRA_VALIDATION */
1264 /* Check if a particular section is included in the link. This will only
1265 be true for one instance of a particular linkonce section. */
1267 static bfd_boolean input_section_found = FALSE;
1268 static asection *input_section_target = NULL;
1271 input_section_linked_worker (lang_statement_union_type *statement)
1273 if ((statement->header.type == lang_input_section_enum
1274 && (statement->input_section.section == input_section_target)))
1275 input_section_found = TRUE;
1279 input_section_linked (asection *sec)
1281 input_section_found = FALSE;
1282 input_section_target = sec;
1283 lang_for_each_statement_worker (input_section_linked_worker, stat_ptr->head);
1284 return input_section_found;
1288 /* Strip out any linkonce property tables or XCC exception tables where the
1289 associated linkonce text is from a different object file. Normally,
1290 a matching set of linkonce sections is taken from the same object file,
1291 but sometimes the files are compiled differently so that some of the
1292 linkonce sections are not present in all files. Stripping the
1293 inconsistent sections like this is not completely robust -- a much
1294 better solution is to use comdat groups. */
1296 static int linkonce_len = sizeof (".gnu.linkonce.") - 1;
1299 is_inconsistent_linkonce_section (asection *sec)
1301 bfd *abfd = sec->owner;
1302 const char *sec_name = bfd_get_section_name (abfd, sec);
1305 if ((bfd_get_section_flags (abfd, sec) & SEC_LINK_ONCE) == 0
1306 || strncmp (sec_name, ".gnu.linkonce.", linkonce_len) != 0)
1309 /* Check if this is an Xtensa property section or an exception table
1310 for Tensilica's XCC compiler. */
1311 name = sec_name + linkonce_len;
1312 if (CONST_STRNEQ (name, "prop."))
1313 name = strchr (name + 5, '.') ? strchr (name + 5, '.') + 1 : name + 5;
1314 else if (name[1] == '.'
1315 && (name[0] == 'p' || name[0] == 'e' || name[0] == 'h'))
1322 char *dep_sec_name = xmalloc (strlen (sec_name) + 1);
1325 /* Get the associated linkonce text section and check if it is
1326 included in the link. If not, this section is inconsistent
1327 and should be stripped. */
1328 strcpy (dep_sec_name, ".gnu.linkonce.t.");
1329 strcat (dep_sec_name, name);
1330 dep_sec = bfd_get_section_by_name (abfd, dep_sec_name);
1331 if (dep_sec == NULL || ! input_section_linked (dep_sec))
1333 free (dep_sec_name);
1336 free (dep_sec_name);
1344 xtensa_strip_inconsistent_linkonce_sections (lang_statement_list_type *slist)
1346 lang_statement_union_type **s_p = &slist->head;
1349 lang_statement_union_type *s = *s_p;
1350 lang_statement_union_type *s_next = (*s_p)->header.next;
1352 switch (s->header.type)
1354 case lang_input_section_enum:
1355 if (is_inconsistent_linkonce_section (s->input_section.section))
1357 s->input_section.section->output_section = bfd_abs_section_ptr;
1363 case lang_constructors_statement_enum:
1364 xtensa_strip_inconsistent_linkonce_sections (&constructor_list);
1367 case lang_output_section_statement_enum:
1368 if (s->output_section_statement.children.head)
1369 xtensa_strip_inconsistent_linkonce_sections
1370 (&s->output_section_statement.children);
1373 case lang_wild_statement_enum:
1374 xtensa_strip_inconsistent_linkonce_sections
1375 (&s->wild_statement.children);
1378 case lang_group_statement_enum:
1379 xtensa_strip_inconsistent_linkonce_sections
1380 (&s->group_statement.children);
1383 case lang_data_statement_enum:
1384 case lang_reloc_statement_enum:
1385 case lang_object_symbols_statement_enum:
1386 case lang_output_statement_enum:
1387 case lang_target_statement_enum:
1388 case lang_input_statement_enum:
1389 case lang_assignment_statement_enum:
1390 case lang_padding_statement_enum:
1391 case lang_address_statement_enum:
1392 case lang_fill_statement_enum:
1400 s_p = &(*s_p)->header.next;
1403 /* Reset the tail of the list, in case the last entry was removed. */
1404 if (s_p != slist->tail)
1410 xtensa_wild_group_interleave_callback (lang_statement_union_type *statement)
1412 lang_wild_statement_type *w;
1413 reloc_deps_graph *deps;
1414 if (statement->header.type == lang_wild_statement_enum)
1416 #if EXTRA_VALIDATION
1417 size_t old_child_count;
1418 size_t new_child_count;
1420 bfd_boolean no_reorder;
1422 w = &statement->wild_statement;
1426 /* If it has 0 or 1 section bound, then do not reorder. */
1427 if (w->children.head == NULL
1428 || (w->children.head->header.type == lang_input_section_enum
1429 && w->children.head->header.next == NULL))
1432 if (w->filenames_sorted)
1435 /* Check for sorting in a section list wildcard spec as well. */
1438 struct wildcard_list *l;
1439 for (l = w->section_list; l != NULL; l = l->next)
1441 if (l->spec.sorted == TRUE)
1449 /* Special case until the NOREORDER linker directive is supported:
1450 *(.init) output sections and *(.fini) specs may NOT be reordered. */
1452 /* Check for sorting in a section list wildcard spec as well. */
1455 struct wildcard_list *l;
1456 for (l = w->section_list; l != NULL; l = l->next)
1459 && ((strcmp (".init", l->spec.name) == 0)
1460 || (strcmp (".fini", l->spec.name) == 0)))
1468 #if EXTRA_VALIDATION
1469 old_child_count = ld_count_children (statement);
1472 /* It is now officially a target. Build the graph of source
1473 section -> target section (kept as a list of edges). */
1474 deps = ld_build_required_section_dependence (statement);
1476 /* If this wildcard does not reorder.... */
1477 if (!no_reorder && deps->count != 0)
1479 /* First check for reverse dependences. Fix if possible. */
1480 xtensa_layout_wild (deps, w);
1482 xtensa_move_dependencies_to_front (deps, w);
1483 #if EXTRA_VALIDATION
1484 new_child_count = ld_count_children (statement);
1485 ASSERT (new_child_count == old_child_count);
1488 xtensa_colocate_literals (deps, statement);
1490 #if EXTRA_VALIDATION
1491 new_child_count = ld_count_children (statement);
1492 ASSERT (new_child_count == old_child_count);
1497 free_reloc_deps_graph (deps);
1503 xtensa_wild_group_interleave (lang_statement_union_type *s)
1505 lang_for_each_statement_worker (xtensa_wild_group_interleave_callback, s);
1510 xtensa_layout_wild (const reloc_deps_graph *deps, lang_wild_statement_type *w)
1512 /* If it does not fit initially, we need to do this step. Move all
1513 of the wild literal sections to a new list, then move each of
1514 them back in just before the first section they depend on. */
1515 lang_statement_union_type **s_p;
1516 #if EXTRA_VALIDATION
1517 size_t old_count, new_count;
1521 lang_wild_statement_type literal_wild;
1522 literal_wild.header.next = NULL;
1523 literal_wild.header.type = lang_wild_statement_enum;
1524 literal_wild.filename = NULL;
1525 literal_wild.filenames_sorted = FALSE;
1526 literal_wild.section_list = NULL;
1527 literal_wild.keep_sections = FALSE;
1528 literal_wild.children.head = NULL;
1529 literal_wild.children.tail = &literal_wild.children.head;
1531 #if EXTRA_VALIDATION
1532 old_count = ld_count_children ((lang_statement_union_type*) w);
1535 s_p = &w->children.head;
1536 while (*s_p != NULL)
1538 lang_statement_union_type *l = *s_p;
1539 if (l->header.type == lang_input_section_enum)
1541 if (section_is_target (deps, l)
1542 && ! section_is_source (deps, l))
1545 *s_p = l->header.next;
1547 w->children.tail = s_p;
1548 l->header.next = NULL;
1551 *literal_wild.children.tail = l;
1552 literal_wild.children.tail = &l->header.next;
1556 s_p = &(*s_p)->header.next;
1559 #if EXTRA_VALIDATION
1560 ct1 = ld_count_children ((lang_statement_union_type*) w);
1561 ct2 = ld_count_children ((lang_statement_union_type*) &literal_wild);
1563 ASSERT (old_count == (ct1 + ct2));
1566 /* Now place them back in front of their dependent sections. */
1568 while (literal_wild.children.head != NULL)
1570 lang_statement_union_type *lit = literal_wild.children.head;
1571 bfd_boolean placed = FALSE;
1573 #if EXTRA_VALIDATION
1579 literal_wild.children.head = lit->header.next;
1580 if (literal_wild.children.head == NULL)
1581 literal_wild.children.tail = &literal_wild.children.head;
1582 lit->header.next = NULL;
1584 /* Find a spot to place it. */
1585 for (s_p = &w->children.head; *s_p != NULL; s_p = &(*s_p)->header.next)
1587 lang_statement_union_type *src = *s_p;
1588 if (deps_has_edge (deps, src, lit))
1590 /* Place it here. */
1591 lit->header.next = *s_p;
1600 /* Put it at the end. */
1601 *w->children.tail = lit;
1602 w->children.tail = &lit->header.next;
1606 #if EXTRA_VALIDATION
1607 new_count = ld_count_children ((lang_statement_union_type*) w);
1608 ASSERT (new_count == old_count);
1614 xtensa_colocate_output_literals_callback (lang_statement_union_type *statement)
1616 reloc_deps_graph *deps;
1617 if (statement->header.type == lang_output_section_statement_enum)
1619 /* Now, we walk over the contours of the output section statement.
1621 First we build the literal section dependences as before.
1623 At the first uniquely_literal section, we mark it as a good
1624 spot to place other literals. Continue walking (and counting
1625 sizes) until we find the next literal section. If this
1626 section can be moved to the first one, then we move it. If
1627 we every find a modification of ".", start over. If we find
1628 a labeling of the current location, start over. Finally, at
1629 the end, if we require page alignment, add page alignments. */
1631 #if EXTRA_VALIDATION
1632 size_t old_child_count;
1633 size_t new_child_count;
1635 bfd_boolean no_reorder = FALSE;
1637 #if EXTRA_VALIDATION
1638 old_child_count = ld_count_children (statement);
1641 /* It is now officially a target. Build the graph of source
1642 section -> target section (kept as a list of edges). */
1644 deps = ld_build_required_section_dependence (statement);
1646 /* If this wildcard does not reorder.... */
1649 /* First check for reverse dependences. Fix if possible. */
1650 xtensa_colocate_literals (deps, statement);
1652 #if EXTRA_VALIDATION
1653 new_child_count = ld_count_children (statement);
1654 ASSERT (new_child_count == old_child_count);
1658 /* Insert align/offset assignment statement. */
1659 if (xtensa_use_literal_pages)
1661 ld_xtensa_insert_page_offsets (0, statement, deps,
1662 xtensa_use_literal_pages);
1663 lang_for_each_statement_worker (xtensa_ldlang_clear_addresses,
1668 free_reloc_deps_graph (deps);
1674 xtensa_colocate_output_literals (lang_statement_union_type *s)
1676 lang_for_each_statement_worker (xtensa_colocate_output_literals_callback, s);
1681 xtensa_ldlang_clear_addresses (lang_statement_union_type *statement)
1683 switch (statement->header.type)
1685 case lang_input_section_enum:
1687 asection *bfd_section = statement->input_section.section;
1688 bfd_section->output_offset = 0;
1698 ld_assign_relative_paged_dot (bfd_vma dot,
1699 lang_statement_union_type *s,
1700 const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
1701 bfd_boolean lit_align)
1703 /* Walk through all of the input statements in this wild statement
1704 assign dot to all of them. */
1706 xtensa_ld_iter_stack *stack = NULL;
1707 xtensa_ld_iter_stack **stack_p = &stack;
1709 bfd_boolean first_section = FALSE;
1710 bfd_boolean in_literals = FALSE;
1712 for (iter_stack_create (stack_p, s);
1713 !iter_stack_empty (stack_p);
1714 iter_stack_next (stack_p))
1716 lang_statement_union_type *l = iter_stack_current (stack_p);
1718 switch (l->header.type)
1720 case lang_input_section_enum:
1722 asection *section = l->input_section.section;
1723 size_t align_pow = section->alignment_power;
1724 bfd_boolean do_xtensa_alignment = FALSE;
1728 bfd_boolean sec_is_target = section_is_target (deps, l);
1729 bfd_boolean sec_is_source = section_is_source (deps, l);
1731 if (section->size != 0
1733 || (in_literals && !sec_is_target)
1734 || (!in_literals && sec_is_target)))
1736 do_xtensa_alignment = TRUE;
1738 first_section = FALSE;
1739 if (section->size != 0)
1740 in_literals = (sec_is_target && !sec_is_source);
1743 if (do_xtensa_alignment && xtensa_page_power != 0)
1744 dot += (1 << xtensa_page_power);
1746 dot = align_power (dot, align_pow);
1747 section->output_offset = dot;
1748 dot += section->size;
1751 case lang_fill_statement_enum:
1752 dot += l->fill_statement.size;
1754 case lang_padding_statement_enum:
1755 dot += l->padding_statement.size;
1766 ld_local_file_relocations_fit (lang_statement_union_type *statement,
1767 const reloc_deps_graph *deps ATTRIBUTE_UNUSED)
1769 /* Walk over all of the dependencies that we identified and make
1770 sure that IF the source and target are here (addr != 0):
1771 1) target addr < source addr
1772 2) (roundup(source + source_size, 4) - rounddown(target, 4))
1773 < (256K - (1 << bad align))
1774 Need a worst-case proof.... */
1776 xtensa_ld_iter_stack *stack = NULL;
1777 xtensa_ld_iter_stack **stack_p = &stack;
1778 size_t max_align_power = 0;
1779 size_t align_penalty = 256;
1783 /* Find the worst-case alignment requirement for this set of statements. */
1784 for (iter_stack_create (stack_p, statement);
1785 !iter_stack_empty (stack_p);
1786 iter_stack_next (stack_p))
1788 lang_statement_union_type *l = iter_stack_current (stack_p);
1789 if (l->header.type == lang_input_section_enum)
1791 lang_input_section_type *input = &l->input_section;
1792 asection *section = input->section;
1793 if (section->alignment_power > max_align_power)
1794 max_align_power = section->alignment_power;
1798 /* Now check that everything fits. */
1799 for (i = 0; i < deps->count; i++)
1801 asection *sec = deps->sections[i];
1802 const reloc_deps_section *deps_section =
1803 xtensa_get_section_deps (deps, sec);
1806 /* We choose to walk through the successors. */
1807 for (e = deps_section->succs; e != NULL; e = e->next)
1809 if (e->src != e->tgt
1810 && e->src->output_section == e->tgt->output_section
1811 && e->src->output_offset != 0
1812 && e->tgt->output_offset != 0)
1815 align_power (e->src->output_offset + e->src->size, 2);
1816 bfd_vma target_addr = e->tgt->output_offset & ~3;
1817 if (l32r_addr < target_addr)
1820 fprintf (stderr, "Warning: "
1821 "l32r target section before l32r\n");
1826 if (l32r_addr - target_addr > 256 * 1024 - align_penalty)
1838 ld_xtensa_insert_page_offsets (bfd_vma dot,
1839 lang_statement_union_type *s,
1840 reloc_deps_graph *deps,
1841 bfd_boolean lit_align)
1843 xtensa_ld_iter_stack *stack = NULL;
1844 xtensa_ld_iter_stack **stack_p = &stack;
1846 bfd_boolean first_section = FALSE;
1847 bfd_boolean in_literals = FALSE;
1852 for (iter_stack_create (stack_p, s);
1853 !iter_stack_empty (stack_p);
1854 iter_stack_next (stack_p))
1856 lang_statement_union_type *l = iter_stack_current (stack_p);
1858 switch (l->header.type)
1860 case lang_input_section_enum:
1862 asection *section = l->input_section.section;
1863 bfd_boolean do_xtensa_alignment = FALSE;
1867 if (section->size != 0
1869 || (in_literals && !section_is_target (deps, l))
1870 || (!in_literals && section_is_target (deps, l))))
1872 do_xtensa_alignment = TRUE;
1874 first_section = FALSE;
1875 if (section->size != 0)
1877 in_literals = (section_is_target (deps, l)
1878 && !section_is_source (deps, l));
1882 if (do_xtensa_alignment && xtensa_page_power != 0)
1884 /* Create an expression that increments the current address,
1885 i.e., "dot", by (1 << xtensa_align_power). */
1886 etree_type *name_op = exp_nameop (NAME, ".");
1887 etree_type *addend_op = exp_intop (1 << xtensa_page_power);
1888 etree_type *add_op = exp_binop ('+', name_op, addend_op);
1889 etree_type *assign_op = exp_assign (".", add_op, FALSE);
1891 lang_assignment_statement_type *assign_stmt;
1892 lang_statement_union_type *assign_union;
1893 lang_statement_list_type tmplist;
1895 /* There is hidden state in "lang_add_assignment". It
1896 appends the new assignment statement to the stat_ptr
1897 list. Thus, we swap it before and after the call. */
1899 lang_list_init (&tmplist);
1900 push_stat_ptr (&tmplist);
1901 /* Warning: side effect; statement appended to stat_ptr. */
1902 assign_stmt = lang_add_assignment (assign_op);
1903 assign_union = (lang_statement_union_type *) assign_stmt;
1906 assign_union->header.next = l;
1907 *(*stack_p)->iterloc.loc = assign_union;
1908 iter_stack_next (stack_p);
1921 # Define some shell vars to insert bits of code into the standard ELF
1922 # parse_args and list_options functions.
1924 PARSE_AND_LIST_PROLOGUE='
1925 #define OPTION_OPT_SIZEOPT (300)
1926 #define OPTION_LITERAL_MOVEMENT (OPTION_OPT_SIZEOPT + 1)
1927 #define OPTION_NO_LITERAL_MOVEMENT (OPTION_LITERAL_MOVEMENT + 1)
1928 extern int elf32xtensa_size_opt;
1929 extern int elf32xtensa_no_literal_movement;
1932 PARSE_AND_LIST_LONGOPTS='
1933 { "size-opt", no_argument, NULL, OPTION_OPT_SIZEOPT},
1934 { "literal-movement", no_argument, NULL, OPTION_LITERAL_MOVEMENT},
1935 { "no-literal-movement", no_argument, NULL, OPTION_NO_LITERAL_MOVEMENT},
1938 PARSE_AND_LIST_OPTIONS='
1940 --size-opt When relaxing longcalls, prefer size\n\
1941 optimization over branch target alignment\n"));
1944 PARSE_AND_LIST_ARGS_CASES='
1945 case OPTION_OPT_SIZEOPT:
1946 elf32xtensa_size_opt = 1;
1948 case OPTION_LITERAL_MOVEMENT:
1949 elf32xtensa_no_literal_movement = 0;
1951 case OPTION_NO_LITERAL_MOVEMENT:
1952 elf32xtensa_no_literal_movement = 1;
1956 # Replace some of the standard ELF functions with our own versions.
1958 LDEMUL_BEFORE_PARSE=elf_xtensa_before_parse
1959 LDEMUL_AFTER_OPEN=elf_xtensa_after_open
1960 LDEMUL_CHOOSE_TARGET=elf_xtensa_choose_target
1961 LDEMUL_BEFORE_ALLOCATION=elf_xtensa_before_allocation