1 # This shell script emits a C file. -*- C -*-
2 # Copyright (C) 2003-2020 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-config.h>
28 #include "../bfd/elf-bfd.h"
29 #include "elf/xtensa.h"
32 /* Provide default values for new configuration settings. */
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 bfd_boolean xtensa_use_literal_pages = FALSE;
50 #define EXTRA_VALIDATION 0
54 elf_xtensa_choose_target (int argc ATTRIBUTE_UNUSED,
55 char **argv ATTRIBUTE_UNUSED)
58 return "${BIG_OUTPUT_FORMAT}";
60 return "${LITTLE_OUTPUT_FORMAT}";
65 elf_xtensa_before_parse (void)
67 /* Just call the default hook.... Tensilica's version of this function
68 does some other work that isn't relevant here. */
69 gld${EMULATION_NAME}_before_parse ();
74 remove_section (bfd *abfd, asection *os)
77 for (spp = &abfd->sections; *spp; spp = &(*spp)->next)
81 os->owner->section_count--;
88 replace_insn_sec_with_prop_sec (bfd *abfd,
89 const char *insn_sec_name,
90 const char *prop_sec_name,
95 bfd_byte *prop_contents = NULL;
96 bfd_byte *insn_contents = NULL;
99 Elf_Internal_Shdr *rel_hdr;
100 Elf_Internal_Rela *internal_relocs = NULL;
101 unsigned reloc_count;
104 insn_sec = bfd_get_section_by_name (abfd, insn_sec_name);
105 if (insn_sec == NULL)
107 entry_count = insn_sec->size / 8;
109 prop_sec = bfd_get_section_by_name (abfd, prop_sec_name);
110 if (prop_sec != NULL && insn_sec != NULL)
112 *error_message = _("file already has property tables");
116 if (insn_sec->size != 0)
118 insn_contents = (bfd_byte *) xmalloc (insn_sec->size);
119 if (! bfd_get_section_contents (abfd, insn_sec, insn_contents,
120 (file_ptr) 0, insn_sec->size))
122 *error_message = _("failed to read section contents");
127 /* Create a property table section for it. */
128 prop_sec_name = strdup (prop_sec_name);
129 prop_sec = bfd_make_section_with_flags
130 (abfd, prop_sec_name, bfd_section_flags (insn_sec));
132 || !bfd_set_section_alignment (prop_sec, 2))
134 *error_message = _("could not create new section");
138 prop_sec->size = entry_count * 12;
139 prop_contents = (bfd_byte *) bfd_zalloc (abfd, prop_sec->size);
140 elf_section_data (prop_sec)->this_hdr.contents = prop_contents;
142 /* The entry size and size must be set to allow the linker to compute
143 the number of relocations since it does not use reloc_count. */
144 rel_hdr = _bfd_elf_single_rel_hdr (prop_sec);
145 rel_hdr->sh_entsize = sizeof (Elf32_External_Rela);
146 rel_hdr->sh_size = _bfd_elf_single_rel_hdr (insn_sec)->sh_size;
148 if (prop_contents == NULL && prop_sec->size != 0)
150 *error_message = _("could not allocate section contents");
154 /* Read the relocations. */
155 reloc_count = insn_sec->reloc_count;
156 if (reloc_count != 0)
158 /* If there is already an internal_reloc, then save it so that the
159 read_relocs function freshly allocates a copy. */
160 Elf_Internal_Rela *saved_relocs = elf_section_data (insn_sec)->relocs;
162 elf_section_data (insn_sec)->relocs = NULL;
164 _bfd_elf_link_read_relocs (abfd, insn_sec, NULL, NULL, FALSE);
165 elf_section_data (insn_sec)->relocs = saved_relocs;
167 if (internal_relocs == NULL)
169 *error_message = _("out of memory");
174 /* Create a relocation section for the property section. */
175 if (internal_relocs != NULL)
177 elf_section_data (prop_sec)->relocs = internal_relocs;
178 prop_sec->reloc_count = reloc_count;
181 /* Now copy each insn table entry to the prop table entry with
182 appropriate flags. */
183 for (entry = 0; entry < entry_count; ++entry)
186 unsigned flags = (XTENSA_PROP_INSN | XTENSA_PROP_NO_TRANSFORM
187 | XTENSA_PROP_INSN_NO_REORDER);
188 value = bfd_get_32 (abfd, insn_contents + entry * 8 + 0);
189 bfd_put_32 (abfd, value, prop_contents + entry * 12 + 0);
190 value = bfd_get_32 (abfd, insn_contents + entry * 8 + 4);
191 bfd_put_32 (abfd, value, prop_contents + entry * 12 + 4);
192 bfd_put_32 (abfd, flags, prop_contents + entry * 12 + 8);
195 /* Now copy all of the relocations. Change offsets for the
196 instruction table section to offsets in the property table
202 for (i = 0; i < reloc_count; i++)
204 Elf_Internal_Rela *rela;
207 rela = &internal_relocs[i];
209 /* If this relocation is to the .xt.insn section,
210 change the section number and the offset. */
211 r_offset = rela->r_offset;
212 r_offset += 4 * (r_offset / 8);
213 rela->r_offset = r_offset;
217 remove_section (abfd, insn_sec);
220 free (insn_contents);
225 if (prop_sec && prop_sec->owner)
226 remove_section (abfd, prop_sec);
228 free (insn_contents);
230 free (internal_relocs);
236 #define PROP_SEC_BASE_NAME ".xt.prop"
237 #define INSN_SEC_BASE_NAME ".xt.insn"
238 #define LINKONCE_SEC_OLD_TEXT_BASE_NAME ".gnu.linkonce.x."
242 replace_instruction_table_sections (bfd *abfd, asection *sec)
245 const char *insn_sec_name = NULL;
246 char *prop_sec_name = NULL;
247 char *owned_prop_sec_name = NULL;
248 const char *sec_name;
250 sec_name = bfd_section_name (sec);
251 if (strcmp (sec_name, INSN_SEC_BASE_NAME) == 0)
253 insn_sec_name = INSN_SEC_BASE_NAME;
254 prop_sec_name = PROP_SEC_BASE_NAME;
256 else if (CONST_STRNEQ (sec_name, LINKONCE_SEC_OLD_TEXT_BASE_NAME))
258 insn_sec_name = sec_name;
259 owned_prop_sec_name = (char *) xmalloc (strlen (sec_name) + 20);
260 prop_sec_name = owned_prop_sec_name;
261 strcpy (prop_sec_name, ".gnu.linkonce.prop.t.");
262 strcat (prop_sec_name,
263 sec_name + strlen (LINKONCE_SEC_OLD_TEXT_BASE_NAME));
265 if (insn_sec_name != NULL)
267 if (! replace_insn_sec_with_prop_sec (abfd, insn_sec_name, prop_sec_name,
270 einfo (_("%P: warning: failed to convert %s table in %pB (%s); subsequent disassembly may be incomplete\n"),
271 insn_sec_name, abfd, message);
274 if (owned_prop_sec_name)
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,
309 bfd_boolean *pmismatch,
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 (num != XSHAL_ABI)
351 *pmsg = "ABI does not match";
354 else if (! strcmp (key, "USE_ABSOLUTE_LITERALS"))
356 if (num != XSHAL_USE_ABSOLUTE_LITERALS)
359 *pmsg = "incompatible use of the Extended L32R option";
375 #define XTINFO_NAME "Xtensa_Info"
376 #define XTINFO_NAMESZ 12
377 #define XTINFO_TYPE 1
380 check_xtensa_info (bfd *abfd, asection *info_sec)
382 char *data, *errmsg = "";
383 bfd_boolean mismatch;
385 data = xmalloc (info_sec->size);
386 if (! bfd_get_section_contents (abfd, info_sec, data, 0, info_sec->size))
387 einfo (_("%F%P: %pB: cannot read contents of section %pA\n"), abfd, info_sec);
389 if (info_sec->size > 24
390 && info_sec->size >= 24 + bfd_get_32 (abfd, data + 4)
391 && bfd_get_32 (abfd, data + 0) == XTINFO_NAMESZ
392 && bfd_get_32 (abfd, data + 8) == XTINFO_TYPE
393 && strcmp (data + 12, XTINFO_NAME) == 0
394 && xt_config_info_unpack_and_check (data + 12 + XTINFO_NAMESZ,
398 einfo (_("%P: %pB: warning: incompatible Xtensa configuration (%s)\n"),
402 einfo (_("%P: %pB: warning: cannot parse .xtensa.info section\n"), abfd);
408 /* This is called after the sections have been attached to output
409 sections, but before any sizes or addresses have been set. */
412 elf_xtensa_before_allocation (void)
414 asection *info_sec, *first_info_sec;
416 bfd_boolean is_big_endian = XCHAL_HAVE_BE;
418 /* Check that the output endianness matches the Xtensa
419 configuration. The BFD library always includes both big and
420 little endian target vectors for Xtensa, but it only supports the
421 detailed instruction encode/decode operations (such as are
422 required to process relocations) for the selected Xtensa
426 && link_info.output_bfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
428 einfo (_("%F%P: little endian output does not match "
429 "Xtensa configuration\n"));
432 && link_info.output_bfd->xvec->byteorder == BFD_ENDIAN_BIG)
434 einfo (_("%F%P: big endian output does not match "
435 "Xtensa configuration\n"));
438 /* Keep track of the first input .xtensa.info section, and as a fallback,
439 the first input bfd where a .xtensa.info section could be created.
440 After the input .xtensa.info has been checked, the contents of the
441 first one will be replaced with the output .xtensa.info table. */
445 LANG_FOR_EACH_INPUT_STATEMENT (f)
447 /* Check that the endianness for each input file matches the output.
448 The merge_private_bfd_data hook has already reported any mismatches
449 as errors, but those errors are not fatal. At this point, we
450 cannot go any further if there are any mismatches. */
451 if ((is_big_endian && f->the_bfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
452 || (!is_big_endian && f->the_bfd->xvec->byteorder == BFD_ENDIAN_BIG))
453 einfo (_("%F%P: cross-endian linking for %pB not supported\n"),
457 first_bfd = f->the_bfd;
459 info_sec = bfd_get_section_by_name (f->the_bfd, ".xtensa.info");
463 if (! first_info_sec)
464 first_info_sec = info_sec;
466 /* Unpack the .xtensa.info section and check it against the current
467 Xtensa configuration. */
468 check_xtensa_info (f->the_bfd, info_sec);
470 /* Do not include this copy of .xtensa.info in the output. */
472 info_sec->flags |= SEC_EXCLUDE;
475 /* Reuse the first .xtensa.info input section to hold the output
476 .xtensa.info; or, if none were found, create a new section in the
477 first input bfd (assuming there is one). */
478 info_sec = first_info_sec;
479 if (! info_sec && first_bfd)
481 info_sec = bfd_make_section_with_flags (first_bfd, ".xtensa.info",
482 SEC_HAS_CONTENTS | SEC_READONLY);
484 einfo (_("%F%P: failed to create .xtensa.info section\n"));
488 int xtensa_info_size;
491 info_sec->flags &= ~SEC_EXCLUDE;
492 info_sec->flags |= SEC_IN_MEMORY;
494 data = xmalloc (100);
495 sprintf (data, "USE_ABSOLUTE_LITERALS=%d\nABI=%d\n",
496 XSHAL_USE_ABSOLUTE_LITERALS, XSHAL_ABI);
497 xtensa_info_size = strlen (data) + 1;
499 /* Add enough null terminators to pad to a word boundary. */
501 data[xtensa_info_size++] = 0;
502 while ((xtensa_info_size & 3) != 0);
504 info_sec->size = 12 + XTINFO_NAMESZ + xtensa_info_size;
505 info_sec->contents = xmalloc (info_sec->size);
506 bfd_put_32 (info_sec->owner, XTINFO_NAMESZ, info_sec->contents + 0);
507 bfd_put_32 (info_sec->owner, xtensa_info_size, info_sec->contents + 4);
508 bfd_put_32 (info_sec->owner, XTINFO_TYPE, info_sec->contents + 8);
509 memcpy (info_sec->contents + 12, XTINFO_NAME, XTINFO_NAMESZ);
510 memcpy (info_sec->contents + 12 + XTINFO_NAMESZ, data, xtensa_info_size);
514 /* Enable relaxation by default if the "--no-relax" option was not
515 specified. This is done here instead of in the before_parse hook
516 because there is a check in main() to prohibit use of --relax and
517 -r together and that combination should be allowed for Xtensa. */
518 if (RELAXATION_DISABLED_BY_DEFAULT)
521 xtensa_strip_inconsistent_linkonce_sections (stat_ptr);
523 gld${EMULATION_NAME}_before_allocation ();
525 xtensa_wild_group_interleave (stat_ptr->head);
527 if (RELAXATION_ENABLED)
528 xtensa_colocate_output_literals (stat_ptr->head);
530 /* TBD: We need to force the page alignments to here and only do
531 them as needed for the entire output section. Finally, if this
532 is a relocatable link then we need to add alignment notes so
533 that the literals can be separated later. */
537 typedef struct wildcard_list section_name_list;
539 typedef struct reloc_deps_e_t reloc_deps_e;
540 typedef struct reloc_deps_section_t reloc_deps_section;
541 typedef struct reloc_deps_graph_t reloc_deps_graph;
544 struct reloc_deps_e_t
546 asection *src; /* Contains l32rs. */
547 asection *tgt; /* Contains literals. */
551 /* Place these in the userdata field. */
552 struct reloc_deps_section_t
556 bfd_boolean is_only_literal;
560 struct reloc_deps_graph_t
567 static void xtensa_layout_wild
568 (const reloc_deps_graph *, lang_wild_statement_type *);
570 typedef void (*deps_callback_t) (asection *, /* src_sec */
571 bfd_vma, /* src_offset */
572 asection *, /* target_sec */
573 bfd_vma, /* target_offset */
574 void *); /* closure */
576 extern bfd_boolean xtensa_callback_required_dependence
577 (bfd *, asection *, struct bfd_link_info *, deps_callback_t, void *);
578 static void xtensa_ldlang_clear_addresses (lang_statement_union_type *);
579 static bfd_boolean ld_local_file_relocations_fit
580 (lang_statement_union_type *, const reloc_deps_graph *);
581 static bfd_vma ld_assign_relative_paged_dot
582 (bfd_vma, lang_statement_union_type *, const reloc_deps_graph *,
584 static bfd_vma ld_xtensa_insert_page_offsets
585 (bfd_vma, lang_statement_union_type *, reloc_deps_graph *, bfd_boolean);
587 static size_t ld_count_children (lang_statement_union_type *);
590 extern lang_statement_list_type constructor_list;
592 static reloc_deps_section *
593 xtensa_get_section_deps (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
596 /* We have a separate function for this so that
597 we could in the future keep a completely independent
598 structure that maps a section to its dependence edges.
599 For now, we place these in the sec->userdata field.
600 This doesn't clash with ldlang.c use of userdata for output
601 sections, and during map output for input sections, since the
602 xtensa use is only for input sections and only extant in
603 before_allocation. */
604 reloc_deps_section *sec_deps = bfd_section_userdata (sec);
609 xtensa_set_section_deps (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
611 reloc_deps_section *deps_section)
613 bfd_set_section_userdata (sec, deps_section);
617 /* This is used to keep a list of all of the sections participating in
618 the graph so we can clean them up quickly. */
621 xtensa_append_section_deps (reloc_deps_graph *deps, asection *sec)
623 if (deps->size <= deps->count)
625 asection **new_sections;
629 new_size = deps->size * 2;
633 new_sections = xmalloc (sizeof (asection *) * new_size);
634 memset (new_sections, 0, sizeof (asection *) * new_size);
635 for (i = 0; i < deps->count; i++)
637 new_sections[i] = deps->sections[i];
639 if (deps->sections != NULL)
640 free (deps->sections);
641 deps->sections = new_sections;
642 deps->size = new_size;
644 deps->sections[deps->count] = sec;
650 free_reloc_deps_graph (reloc_deps_graph *deps)
653 for (i = 0; i < deps->count; i++)
655 asection *sec = deps->sections[i];
656 reloc_deps_section *sec_deps;
657 sec_deps = xtensa_get_section_deps (deps, sec);
661 while (sec_deps->succs != NULL)
663 next = sec_deps->succs->next;
664 free (sec_deps->succs);
665 sec_deps->succs = next;
668 while (sec_deps->preds != NULL)
670 next = sec_deps->preds->next;
671 free (sec_deps->preds);
672 sec_deps->preds = next;
676 xtensa_set_section_deps (deps, sec, NULL);
679 free (deps->sections);
686 section_is_source (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
687 lang_statement_union_type *s)
690 const reloc_deps_section *sec_deps;
692 if (s->header.type != lang_input_section_enum)
694 sec = s->input_section.section;
696 sec_deps = xtensa_get_section_deps (deps, sec);
697 return sec_deps && sec_deps->succs != NULL;
702 section_is_target (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
703 lang_statement_union_type *s)
706 const reloc_deps_section *sec_deps;
708 if (s->header.type != lang_input_section_enum)
710 sec = s->input_section.section;
712 sec_deps = xtensa_get_section_deps (deps, sec);
713 return sec_deps && sec_deps->preds != NULL;
718 section_is_source_or_target (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
719 lang_statement_union_type *s)
721 return (section_is_source (deps, s)
722 || section_is_target (deps, s));
726 typedef struct xtensa_ld_iter_stack_t xtensa_ld_iter_stack;
727 typedef struct xtensa_ld_iter_t xtensa_ld_iter;
729 struct xtensa_ld_iter_t
731 lang_statement_union_type *parent; /* Parent of the list. */
732 lang_statement_list_type *l; /* List that holds it. */
733 lang_statement_union_type **loc; /* Place in the list. */
736 struct xtensa_ld_iter_stack_t
738 xtensa_ld_iter iterloc; /* List that hold it. */
740 xtensa_ld_iter_stack *next; /* Next in the stack. */
741 xtensa_ld_iter_stack *prev; /* Back pointer for stack. */
746 ld_xtensa_move_section_after (xtensa_ld_iter *to, xtensa_ld_iter *current)
748 lang_statement_union_type *to_next;
749 lang_statement_union_type *current_next;
750 lang_statement_union_type **e;
753 size_t old_to_count, new_to_count;
754 size_t old_current_count, new_current_count;
761 old_to_count = ld_count_children (to->parent);
762 old_current_count = ld_count_children (current->parent);
765 to_next = *(to->loc);
766 current_next = (*current->loc)->header.next;
768 *(to->loc) = *(current->loc);
770 *(current->loc) = current_next;
771 (*(to->loc))->header.next = to_next;
773 /* reset "to" list tail */
774 for (e = &to->l->head; *e != NULL; e = &(*e)->header.next)
778 /* reset "current" list tail */
779 for (e = ¤t->l->head; *e != NULL; e = &(*e)->header.next)
781 current->l->tail = e;
784 new_to_count = ld_count_children (to->parent);
785 new_current_count = ld_count_children (current->parent);
787 ASSERT ((old_to_count + old_current_count)
788 == (new_to_count + new_current_count));
793 /* Can only be called with lang_statements that have lists. Returns
794 FALSE if the list is empty. */
797 iter_stack_empty (xtensa_ld_iter_stack **stack_p)
799 return *stack_p == NULL;
804 iter_stack_push (xtensa_ld_iter_stack **stack_p,
805 lang_statement_union_type *parent)
807 xtensa_ld_iter_stack *stack;
808 lang_statement_list_type *l = NULL;
810 switch (parent->header.type)
812 case lang_output_section_statement_enum:
813 l = &parent->output_section_statement.children;
815 case lang_wild_statement_enum:
816 l = &parent->wild_statement.children;
818 case lang_group_statement_enum:
819 l = &parent->group_statement.children;
826 /* Empty. do not push. */
827 if (l->tail == &l->head)
830 stack = xmalloc (sizeof (xtensa_ld_iter_stack));
831 memset (stack, 0, sizeof (xtensa_ld_iter_stack));
832 stack->iterloc.parent = parent;
833 stack->iterloc.l = l;
834 stack->iterloc.loc = &l->head;
836 stack->next = *stack_p;
838 if (*stack_p != NULL)
839 (*stack_p)->prev = stack;
846 iter_stack_pop (xtensa_ld_iter_stack **stack_p)
848 xtensa_ld_iter_stack *stack;
854 ASSERT (stack != NULL);
858 if (stack->next != NULL)
859 stack->next->prev = NULL;
861 *stack_p = stack->next;
866 /* This MUST be called if, during iteration, the user changes the
867 underlying structure. It will check for a NULL current and advance
871 iter_stack_update (xtensa_ld_iter_stack **stack_p)
873 if (!iter_stack_empty (stack_p)
874 && (*(*stack_p)->iterloc.loc) == NULL)
876 iter_stack_pop (stack_p);
878 while (!iter_stack_empty (stack_p)
879 && ((*(*stack_p)->iterloc.loc)->header.next == NULL))
881 iter_stack_pop (stack_p);
883 if (!iter_stack_empty (stack_p))
884 (*stack_p)->iterloc.loc = &(*(*stack_p)->iterloc.loc)->header.next;
890 iter_stack_next (xtensa_ld_iter_stack **stack_p)
892 xtensa_ld_iter_stack *stack;
893 lang_statement_union_type *current;
896 current = *stack->iterloc.loc;
897 /* If we are on the first element. */
900 switch (current->header.type)
902 case lang_output_section_statement_enum:
903 case lang_wild_statement_enum:
904 case lang_group_statement_enum:
905 /* If the list if not empty, we are done. */
906 if (iter_stack_push (stack_p, *stack->iterloc.loc))
908 /* Otherwise increment the pointer as normal. */
915 while (!iter_stack_empty (stack_p)
916 && ((*(*stack_p)->iterloc.loc)->header.next == NULL))
918 iter_stack_pop (stack_p);
920 if (!iter_stack_empty (stack_p))
921 (*stack_p)->iterloc.loc = &(*(*stack_p)->iterloc.loc)->header.next;
925 static lang_statement_union_type *
926 iter_stack_current (xtensa_ld_iter_stack **stack_p)
928 return *((*stack_p)->iterloc.loc);
932 /* The iter stack is a preorder. */
935 iter_stack_create (xtensa_ld_iter_stack **stack_p,
936 lang_statement_union_type *parent)
938 iter_stack_push (stack_p, parent);
943 iter_stack_copy_current (xtensa_ld_iter_stack **stack_p, xtensa_ld_iter *front)
945 *front = (*stack_p)->iterloc;
950 xtensa_colocate_literals (reloc_deps_graph *deps,
951 lang_statement_union_type *statement)
953 /* Keep a stack of pointers to control iteration through the contours. */
954 xtensa_ld_iter_stack *stack = NULL;
955 xtensa_ld_iter_stack **stack_p = &stack;
957 xtensa_ld_iter front; /* Location where new insertion should occur. */
958 xtensa_ld_iter *front_p = NULL;
960 xtensa_ld_iter current; /* Location we are checking. */
961 xtensa_ld_iter *current_p = NULL;
962 bfd_boolean in_literals = FALSE;
964 if (deps->count == 0)
967 iter_stack_create (stack_p, statement);
969 while (!iter_stack_empty (stack_p))
971 bfd_boolean skip_increment = FALSE;
972 lang_statement_union_type *l = iter_stack_current (stack_p);
974 switch (l->header.type)
976 case lang_assignment_statement_enum:
977 /* Any assignment statement should block reordering across it. */
982 case lang_input_section_enum:
985 in_literals = (section_is_target (deps, l)
986 && !section_is_source (deps, l));
990 iter_stack_copy_current (stack_p, front_p);
995 bfd_boolean is_target;
996 current_p = ¤t;
997 iter_stack_copy_current (stack_p, current_p);
998 is_target = (section_is_target (deps, l)
999 && !section_is_source (deps, l));
1003 iter_stack_copy_current (stack_p, front_p);
1005 in_literals = FALSE;
1011 /* Try to insert in place. */
1012 ld_xtensa_move_section_after (front_p, current_p);
1013 ld_assign_relative_paged_dot (0x100000,
1016 xtensa_use_literal_pages);
1018 /* We use this code because it's already written. */
1019 if (!ld_local_file_relocations_fit (statement, deps))
1022 ld_xtensa_move_section_after (current_p, front_p);
1023 /* Reset the literal placement. */
1024 iter_stack_copy_current (stack_p, front_p);
1028 /* Move front pointer up by one. */
1029 front_p->loc = &(*front_p->loc)->header.next;
1031 /* Do not increment the current pointer. */
1032 skip_increment = TRUE;
1042 if (!skip_increment)
1043 iter_stack_next (stack_p);
1045 /* Be careful to update the stack_p if it now is a null. */
1046 iter_stack_update (stack_p);
1049 lang_for_each_statement_worker (xtensa_ldlang_clear_addresses, statement);
1054 xtensa_move_dependencies_to_front (reloc_deps_graph *deps,
1055 lang_wild_statement_type *w)
1057 /* Keep a front pointer and a current pointer. */
1058 lang_statement_union_type **front;
1059 lang_statement_union_type **current;
1061 /* Walk to the end of the targets. */
1062 for (front = &w->children.head;
1063 (*front != NULL) && section_is_source_or_target (deps, *front);
1064 front = &(*front)->header.next)
1070 current = &(*front)->header.next;
1071 while (*current != NULL)
1073 if (section_is_source_or_target (deps, *current))
1075 /* Insert in place. */
1076 xtensa_ld_iter front_iter;
1077 xtensa_ld_iter current_iter;
1079 front_iter.parent = (lang_statement_union_type *) w;
1080 front_iter.l = &w->children;
1081 front_iter.loc = front;
1083 current_iter.parent = (lang_statement_union_type *) w;
1084 current_iter.l = &w->children;
1085 current_iter.loc = current;
1087 ld_xtensa_move_section_after (&front_iter, ¤t_iter);
1088 front = &(*front)->header.next;
1092 current = &(*current)->header.next;
1099 deps_has_sec_edge (const reloc_deps_graph *deps, asection *src, asection *tgt)
1101 const reloc_deps_section *sec_deps;
1102 const reloc_deps_e *sec_deps_e;
1104 sec_deps = xtensa_get_section_deps (deps, src);
1105 if (sec_deps == NULL)
1108 for (sec_deps_e = sec_deps->succs;
1110 sec_deps_e = sec_deps_e->next)
1112 ASSERT (sec_deps_e->src == src);
1113 if (sec_deps_e->tgt == tgt)
1121 deps_has_edge (const reloc_deps_graph *deps,
1122 lang_statement_union_type *src,
1123 lang_statement_union_type *tgt)
1125 if (!section_is_source (deps, src))
1127 if (!section_is_target (deps, tgt))
1130 if (src->header.type != lang_input_section_enum)
1132 if (tgt->header.type != lang_input_section_enum)
1135 return deps_has_sec_edge (deps, src->input_section.section,
1136 tgt->input_section.section);
1141 add_deps_edge (reloc_deps_graph *deps, asection *src_sec, asection *tgt_sec)
1143 reloc_deps_section *src_sec_deps;
1144 reloc_deps_section *tgt_sec_deps;
1146 reloc_deps_e *src_edge;
1147 reloc_deps_e *tgt_edge;
1149 if (deps_has_sec_edge (deps, src_sec, tgt_sec))
1152 src_sec_deps = xtensa_get_section_deps (deps, src_sec);
1153 if (src_sec_deps == NULL)
1155 /* Add a section. */
1156 src_sec_deps = xmalloc (sizeof (reloc_deps_section));
1157 memset (src_sec_deps, 0, sizeof (reloc_deps_section));
1158 src_sec_deps->is_only_literal = 0;
1159 src_sec_deps->preds = NULL;
1160 src_sec_deps->succs = NULL;
1161 xtensa_set_section_deps (deps, src_sec, src_sec_deps);
1162 xtensa_append_section_deps (deps, src_sec);
1165 tgt_sec_deps = xtensa_get_section_deps (deps, tgt_sec);
1166 if (tgt_sec_deps == NULL)
1168 /* Add a section. */
1169 tgt_sec_deps = xmalloc (sizeof (reloc_deps_section));
1170 memset (tgt_sec_deps, 0, sizeof (reloc_deps_section));
1171 tgt_sec_deps->is_only_literal = 0;
1172 tgt_sec_deps->preds = NULL;
1173 tgt_sec_deps->succs = NULL;
1174 xtensa_set_section_deps (deps, tgt_sec, tgt_sec_deps);
1175 xtensa_append_section_deps (deps, tgt_sec);
1178 /* Add the edges. */
1179 src_edge = xmalloc (sizeof (reloc_deps_e));
1180 memset (src_edge, 0, sizeof (reloc_deps_e));
1181 src_edge->src = src_sec;
1182 src_edge->tgt = tgt_sec;
1183 src_edge->next = src_sec_deps->succs;
1184 src_sec_deps->succs = src_edge;
1186 tgt_edge = xmalloc (sizeof (reloc_deps_e));
1187 memset (tgt_edge, 0, sizeof (reloc_deps_e));
1188 tgt_edge->src = src_sec;
1189 tgt_edge->tgt = tgt_sec;
1190 tgt_edge->next = tgt_sec_deps->preds;
1191 tgt_sec_deps->preds = tgt_edge;
1196 build_deps_graph_callback (asection *src_sec,
1197 bfd_vma src_offset ATTRIBUTE_UNUSED,
1198 asection *target_sec,
1199 bfd_vma target_offset ATTRIBUTE_UNUSED,
1202 reloc_deps_graph *deps = closure;
1204 /* If the target is defined. */
1205 if (target_sec != NULL)
1206 add_deps_edge (deps, src_sec, target_sec);
1210 static reloc_deps_graph *
1211 ld_build_required_section_dependence (lang_statement_union_type *s)
1213 reloc_deps_graph *deps;
1214 xtensa_ld_iter_stack *stack = NULL;
1216 deps = xmalloc (sizeof (reloc_deps_graph));
1217 deps->sections = NULL;
1221 for (iter_stack_create (&stack, s);
1222 !iter_stack_empty (&stack);
1223 iter_stack_next (&stack))
1225 lang_statement_union_type *l = iter_stack_current (&stack);
1227 if (l == NULL && link_info.non_contiguous_regions)
1229 einfo (_("Relaxation not supported with --enable-non-contiguous-regions.\n"));
1233 if (l->header.type == lang_input_section_enum)
1235 lang_input_section_type *input;
1236 input = &l->input_section;
1237 xtensa_callback_required_dependence (input->section->owner,
1240 /* Use the same closure. */
1241 build_deps_graph_callback,
1249 #if EXTRA_VALIDATION
1251 ld_count_children (lang_statement_union_type *s)
1254 xtensa_ld_iter_stack *stack = NULL;
1255 for (iter_stack_create (&stack, s);
1256 !iter_stack_empty (&stack);
1257 iter_stack_next (&stack))
1259 lang_statement_union_type *l = iter_stack_current (&stack);
1265 #endif /* EXTRA_VALIDATION */
1268 /* Check if a particular section is included in the link. This will only
1269 be true for one instance of a particular linkonce section. */
1271 static bfd_boolean input_section_found = FALSE;
1272 static asection *input_section_target = NULL;
1275 input_section_linked_worker (lang_statement_union_type *statement)
1277 if ((statement->header.type == lang_input_section_enum
1278 && (statement->input_section.section == input_section_target)))
1279 input_section_found = TRUE;
1283 input_section_linked (asection *sec)
1285 input_section_found = FALSE;
1286 input_section_target = sec;
1287 lang_for_each_statement_worker (input_section_linked_worker, stat_ptr->head);
1288 return input_section_found;
1292 /* Strip out any linkonce property tables or XCC exception tables where the
1293 associated linkonce text is from a different object file. Normally,
1294 a matching set of linkonce sections is taken from the same object file,
1295 but sometimes the files are compiled differently so that some of the
1296 linkonce sections are not present in all files. Stripping the
1297 inconsistent sections like this is not completely robust -- a much
1298 better solution is to use comdat groups. */
1300 static int linkonce_len = sizeof (".gnu.linkonce.") - 1;
1303 is_inconsistent_linkonce_section (asection *sec)
1305 bfd *abfd = sec->owner;
1306 const char *sec_name = bfd_section_name (sec);
1309 if ((bfd_section_flags (sec) & SEC_LINK_ONCE) == 0
1310 || strncmp (sec_name, ".gnu.linkonce.", linkonce_len) != 0)
1313 /* Check if this is an Xtensa property section or an exception table
1314 for Tensilica's XCC compiler. */
1315 name = sec_name + linkonce_len;
1316 if (CONST_STRNEQ (name, "prop."))
1317 name = strchr (name + 5, '.') ? strchr (name + 5, '.') + 1 : name + 5;
1318 else if (name[1] == '.'
1319 && (name[0] == 'p' || name[0] == 'e' || name[0] == 'h'))
1326 char *dep_sec_name = xmalloc (strlen (sec_name) + 1);
1329 /* Get the associated linkonce text section and check if it is
1330 included in the link. If not, this section is inconsistent
1331 and should be stripped. */
1332 strcpy (dep_sec_name, ".gnu.linkonce.t.");
1333 strcat (dep_sec_name, name);
1334 dep_sec = bfd_get_section_by_name (abfd, dep_sec_name);
1335 if (dep_sec == NULL || ! input_section_linked (dep_sec))
1337 free (dep_sec_name);
1340 free (dep_sec_name);
1348 xtensa_strip_inconsistent_linkonce_sections (lang_statement_list_type *slist)
1350 lang_statement_union_type **s_p = &slist->head;
1353 lang_statement_union_type *s = *s_p;
1354 lang_statement_union_type *s_next = (*s_p)->header.next;
1356 switch (s->header.type)
1358 case lang_input_section_enum:
1359 if (is_inconsistent_linkonce_section (s->input_section.section))
1361 s->input_section.section->output_section = bfd_abs_section_ptr;
1367 case lang_constructors_statement_enum:
1368 xtensa_strip_inconsistent_linkonce_sections (&constructor_list);
1371 case lang_output_section_statement_enum:
1372 if (s->output_section_statement.children.head)
1373 xtensa_strip_inconsistent_linkonce_sections
1374 (&s->output_section_statement.children);
1377 case lang_wild_statement_enum:
1378 xtensa_strip_inconsistent_linkonce_sections
1379 (&s->wild_statement.children);
1382 case lang_group_statement_enum:
1383 xtensa_strip_inconsistent_linkonce_sections
1384 (&s->group_statement.children);
1387 case lang_data_statement_enum:
1388 case lang_reloc_statement_enum:
1389 case lang_object_symbols_statement_enum:
1390 case lang_output_statement_enum:
1391 case lang_target_statement_enum:
1392 case lang_input_statement_enum:
1393 case lang_assignment_statement_enum:
1394 case lang_padding_statement_enum:
1395 case lang_address_statement_enum:
1396 case lang_fill_statement_enum:
1404 s_p = &(*s_p)->header.next;
1407 /* Reset the tail of the list, in case the last entry was removed. */
1408 if (s_p != slist->tail)
1414 xtensa_wild_group_interleave_callback (lang_statement_union_type *statement)
1416 lang_wild_statement_type *w;
1417 reloc_deps_graph *deps;
1418 if (statement->header.type == lang_wild_statement_enum)
1420 #if EXTRA_VALIDATION
1421 size_t old_child_count;
1422 size_t new_child_count;
1424 bfd_boolean no_reorder;
1426 w = &statement->wild_statement;
1430 /* If it has 0 or 1 section bound, then do not reorder. */
1431 if (w->children.head == NULL
1432 || (w->children.head->header.type == lang_input_section_enum
1433 && w->children.head->header.next == NULL))
1436 if (w->filenames_sorted)
1439 /* Check for sorting in a section list wildcard spec as well. */
1442 struct wildcard_list *l;
1443 for (l = w->section_list; l != NULL; l = l->next)
1445 if (l->spec.sorted == by_name)
1453 /* Special case until the NOREORDER linker directive is supported:
1454 *(.init) output sections and *(.fini) specs may NOT be reordered. */
1456 /* Check for sorting in a section list wildcard spec as well. */
1459 struct wildcard_list *l;
1460 for (l = w->section_list; l != NULL; l = l->next)
1463 && ((strcmp (".init", l->spec.name) == 0)
1464 || (strcmp (".fini", l->spec.name) == 0)))
1472 #if EXTRA_VALIDATION
1473 old_child_count = ld_count_children (statement);
1476 /* It is now officially a target. Build the graph of source
1477 section -> target section (kept as a list of edges). */
1478 deps = ld_build_required_section_dependence (statement);
1480 /* If this wildcard does not reorder.... */
1481 if (!no_reorder && deps->count != 0)
1483 /* First check for reverse dependences. Fix if possible. */
1484 xtensa_layout_wild (deps, w);
1486 xtensa_move_dependencies_to_front (deps, w);
1487 #if EXTRA_VALIDATION
1488 new_child_count = ld_count_children (statement);
1489 ASSERT (new_child_count == old_child_count);
1492 xtensa_colocate_literals (deps, statement);
1494 #if EXTRA_VALIDATION
1495 new_child_count = ld_count_children (statement);
1496 ASSERT (new_child_count == old_child_count);
1501 free_reloc_deps_graph (deps);
1507 xtensa_wild_group_interleave (lang_statement_union_type *s)
1509 lang_for_each_statement_worker (xtensa_wild_group_interleave_callback, s);
1514 xtensa_layout_wild (const reloc_deps_graph *deps, lang_wild_statement_type *w)
1516 /* If it does not fit initially, we need to do this step. Move all
1517 of the wild literal sections to a new list, then move each of
1518 them back in just before the first section they depend on. */
1519 lang_statement_union_type **s_p;
1520 #if EXTRA_VALIDATION
1521 size_t old_count, new_count;
1525 lang_wild_statement_type literal_wild;
1526 literal_wild.header.next = NULL;
1527 literal_wild.header.type = lang_wild_statement_enum;
1528 literal_wild.filename = NULL;
1529 literal_wild.filenames_sorted = FALSE;
1530 literal_wild.section_list = NULL;
1531 literal_wild.keep_sections = FALSE;
1532 literal_wild.children.head = NULL;
1533 literal_wild.children.tail = &literal_wild.children.head;
1535 #if EXTRA_VALIDATION
1536 old_count = ld_count_children ((lang_statement_union_type*) w);
1539 s_p = &w->children.head;
1540 while (*s_p != NULL)
1542 lang_statement_union_type *l = *s_p;
1543 if (l->header.type == lang_input_section_enum)
1545 if (section_is_target (deps, l)
1546 && ! section_is_source (deps, l))
1549 *s_p = l->header.next;
1551 w->children.tail = s_p;
1552 l->header.next = NULL;
1555 *literal_wild.children.tail = l;
1556 literal_wild.children.tail = &l->header.next;
1560 s_p = &(*s_p)->header.next;
1563 #if EXTRA_VALIDATION
1564 ct1 = ld_count_children ((lang_statement_union_type*) w);
1565 ct2 = ld_count_children ((lang_statement_union_type*) &literal_wild);
1567 ASSERT (old_count == (ct1 + ct2));
1570 /* Now place them back in front of their dependent sections. */
1572 while (literal_wild.children.head != NULL)
1574 lang_statement_union_type *lit = literal_wild.children.head;
1575 bfd_boolean placed = FALSE;
1577 #if EXTRA_VALIDATION
1583 literal_wild.children.head = lit->header.next;
1584 if (literal_wild.children.head == NULL)
1585 literal_wild.children.tail = &literal_wild.children.head;
1586 lit->header.next = NULL;
1588 /* Find a spot to place it. */
1589 for (s_p = &w->children.head; *s_p != NULL; s_p = &(*s_p)->header.next)
1591 lang_statement_union_type *src = *s_p;
1592 if (deps_has_edge (deps, src, lit))
1594 /* Place it here. */
1595 lit->header.next = *s_p;
1604 /* Put it at the end. */
1605 *w->children.tail = lit;
1606 w->children.tail = &lit->header.next;
1610 #if EXTRA_VALIDATION
1611 new_count = ld_count_children ((lang_statement_union_type*) w);
1612 ASSERT (new_count == old_count);
1618 xtensa_colocate_output_literals_callback (lang_statement_union_type *statement)
1620 reloc_deps_graph *deps;
1621 if (statement->header.type == lang_output_section_statement_enum)
1623 /* Now, we walk over the contours of the output section statement.
1625 First we build the literal section dependences as before.
1627 At the first uniquely_literal section, we mark it as a good
1628 spot to place other literals. Continue walking (and counting
1629 sizes) until we find the next literal section. If this
1630 section can be moved to the first one, then we move it. If
1631 we every find a modification of ".", start over. If we find
1632 a labeling of the current location, start over. Finally, at
1633 the end, if we require page alignment, add page alignments. */
1635 #if EXTRA_VALIDATION
1636 size_t old_child_count;
1637 size_t new_child_count;
1639 bfd_boolean no_reorder = FALSE;
1641 #if EXTRA_VALIDATION
1642 old_child_count = ld_count_children (statement);
1645 /* It is now officially a target. Build the graph of source
1646 section -> target section (kept as a list of edges). */
1648 deps = ld_build_required_section_dependence (statement);
1650 /* If this wildcard does not reorder.... */
1653 /* First check for reverse dependences. Fix if possible. */
1654 xtensa_colocate_literals (deps, statement);
1656 #if EXTRA_VALIDATION
1657 new_child_count = ld_count_children (statement);
1658 ASSERT (new_child_count == old_child_count);
1662 /* Insert align/offset assignment statement. */
1663 if (xtensa_use_literal_pages)
1665 ld_xtensa_insert_page_offsets (0, statement, deps,
1666 xtensa_use_literal_pages);
1667 lang_for_each_statement_worker (xtensa_ldlang_clear_addresses,
1672 free_reloc_deps_graph (deps);
1678 xtensa_colocate_output_literals (lang_statement_union_type *s)
1680 lang_for_each_statement_worker (xtensa_colocate_output_literals_callback, s);
1685 xtensa_ldlang_clear_addresses (lang_statement_union_type *statement)
1687 switch (statement->header.type)
1689 case lang_input_section_enum:
1691 asection *bfd_section = statement->input_section.section;
1692 bfd_section->output_offset = 0;
1702 ld_assign_relative_paged_dot (bfd_vma dot,
1703 lang_statement_union_type *s,
1704 const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
1705 bfd_boolean lit_align)
1707 /* Walk through all of the input statements in this wild statement
1708 assign dot to all of them. */
1710 xtensa_ld_iter_stack *stack = NULL;
1711 xtensa_ld_iter_stack **stack_p = &stack;
1713 bfd_boolean first_section = FALSE;
1714 bfd_boolean in_literals = FALSE;
1716 for (iter_stack_create (stack_p, s);
1717 !iter_stack_empty (stack_p);
1718 iter_stack_next (stack_p))
1720 lang_statement_union_type *l = iter_stack_current (stack_p);
1722 switch (l->header.type)
1724 case lang_input_section_enum:
1726 asection *section = l->input_section.section;
1727 size_t align_pow = section->alignment_power;
1728 bfd_boolean do_xtensa_alignment = FALSE;
1732 bfd_boolean sec_is_target = section_is_target (deps, l);
1733 bfd_boolean sec_is_source = section_is_source (deps, l);
1735 if (section->size != 0
1737 || (in_literals && !sec_is_target)
1738 || (!in_literals && sec_is_target)))
1740 do_xtensa_alignment = TRUE;
1742 first_section = FALSE;
1743 if (section->size != 0)
1744 in_literals = (sec_is_target && !sec_is_source);
1747 if (do_xtensa_alignment && xtensa_page_power != 0)
1748 dot += (1 << xtensa_page_power);
1750 dot = align_power (dot, align_pow);
1751 section->output_offset = dot;
1752 dot += section->size;
1755 case lang_fill_statement_enum:
1756 dot += l->fill_statement.size;
1758 case lang_padding_statement_enum:
1759 dot += l->padding_statement.size;
1770 ld_local_file_relocations_fit (lang_statement_union_type *statement,
1771 const reloc_deps_graph *deps ATTRIBUTE_UNUSED)
1773 /* Walk over all of the dependencies that we identified and make
1774 sure that IF the source and target are here (addr != 0):
1775 1) target addr < source addr
1776 2) (roundup(source + source_size, 4) - rounddown(target, 4))
1777 < (256K - (1 << bad align))
1778 Need a worst-case proof.... */
1780 xtensa_ld_iter_stack *stack = NULL;
1781 xtensa_ld_iter_stack **stack_p = &stack;
1782 size_t max_align_power = 0;
1783 size_t align_penalty = 256;
1787 /* Find the worst-case alignment requirement for this set of statements. */
1788 for (iter_stack_create (stack_p, statement);
1789 !iter_stack_empty (stack_p);
1790 iter_stack_next (stack_p))
1792 lang_statement_union_type *l = iter_stack_current (stack_p);
1793 if (l->header.type == lang_input_section_enum)
1795 lang_input_section_type *input = &l->input_section;
1796 asection *section = input->section;
1797 if (section->alignment_power > max_align_power)
1798 max_align_power = section->alignment_power;
1802 /* Now check that everything fits. */
1803 for (i = 0; i < deps->count; i++)
1805 asection *sec = deps->sections[i];
1806 const reloc_deps_section *deps_section =
1807 xtensa_get_section_deps (deps, sec);
1810 /* We choose to walk through the successors. */
1811 for (e = deps_section->succs; e != NULL; e = e->next)
1813 if (e->src != e->tgt
1814 && e->src->output_section == e->tgt->output_section
1815 && e->src->output_offset != 0
1816 && e->tgt->output_offset != 0)
1819 align_power (e->src->output_offset + e->src->size, 2);
1820 bfd_vma target_addr = e->tgt->output_offset & ~3;
1821 if (l32r_addr < target_addr)
1824 fprintf (stderr, "Warning: "
1825 "l32r target section before l32r\n");
1830 if (l32r_addr - target_addr > 256 * 1024 - align_penalty)
1842 ld_xtensa_insert_page_offsets (bfd_vma dot,
1843 lang_statement_union_type *s,
1844 reloc_deps_graph *deps,
1845 bfd_boolean lit_align)
1847 xtensa_ld_iter_stack *stack = NULL;
1848 xtensa_ld_iter_stack **stack_p = &stack;
1850 bfd_boolean first_section = FALSE;
1851 bfd_boolean in_literals = FALSE;
1856 for (iter_stack_create (stack_p, s);
1857 !iter_stack_empty (stack_p);
1858 iter_stack_next (stack_p))
1860 lang_statement_union_type *l = iter_stack_current (stack_p);
1862 switch (l->header.type)
1864 case lang_input_section_enum:
1866 asection *section = l->input_section.section;
1867 bfd_boolean do_xtensa_alignment = FALSE;
1871 if (section->size != 0
1873 || (in_literals && !section_is_target (deps, l))
1874 || (!in_literals && section_is_target (deps, l))))
1876 do_xtensa_alignment = TRUE;
1878 first_section = FALSE;
1879 if (section->size != 0)
1881 in_literals = (section_is_target (deps, l)
1882 && !section_is_source (deps, l));
1886 if (do_xtensa_alignment && xtensa_page_power != 0)
1888 /* Create an expression that increments the current address,
1889 i.e., "dot", by (1 << xtensa_align_power). */
1890 etree_type *name_op = exp_nameop (NAME, ".");
1891 etree_type *addend_op = exp_intop (1 << xtensa_page_power);
1892 etree_type *add_op = exp_binop ('+', name_op, addend_op);
1893 etree_type *assign_op = exp_assign (".", add_op, FALSE);
1895 lang_assignment_statement_type *assign_stmt;
1896 lang_statement_union_type *assign_union;
1897 lang_statement_list_type tmplist;
1899 /* There is hidden state in "lang_add_assignment". It
1900 appends the new assignment statement to the stat_ptr
1901 list. Thus, we swap it before and after the call. */
1903 lang_list_init (&tmplist);
1904 push_stat_ptr (&tmplist);
1905 /* Warning: side effect; statement appended to stat_ptr. */
1906 assign_stmt = lang_add_assignment (assign_op);
1907 assign_union = (lang_statement_union_type *) assign_stmt;
1910 assign_union->header.next = l;
1911 *(*stack_p)->iterloc.loc = assign_union;
1912 iter_stack_next (stack_p);
1925 # Define some shell vars to insert bits of code into the standard ELF
1926 # parse_args and list_options functions.
1928 PARSE_AND_LIST_PROLOGUE='
1929 #define OPTION_OPT_SIZEOPT (300)
1930 #define OPTION_LITERAL_MOVEMENT (OPTION_OPT_SIZEOPT + 1)
1931 #define OPTION_NO_LITERAL_MOVEMENT (OPTION_LITERAL_MOVEMENT + 1)
1932 extern int elf32xtensa_size_opt;
1933 extern int elf32xtensa_no_literal_movement;
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},
1942 PARSE_AND_LIST_OPTIONS='
1944 --size-opt When relaxing longcalls, prefer size\n\
1945 optimization over branch target alignment\n"));
1948 PARSE_AND_LIST_ARGS_CASES='
1949 case OPTION_OPT_SIZEOPT:
1950 elf32xtensa_size_opt = 1;
1952 case OPTION_LITERAL_MOVEMENT:
1953 elf32xtensa_no_literal_movement = 0;
1955 case OPTION_NO_LITERAL_MOVEMENT:
1956 elf32xtensa_no_literal_movement = 1;
1960 # Replace some of the standard ELF functions with our own versions.
1962 LDEMUL_BEFORE_PARSE=elf_xtensa_before_parse
1963 LDEMUL_AFTER_OPEN=elf_xtensa_after_open
1964 LDEMUL_CHOOSE_TARGET=elf_xtensa_choose_target
1965 LDEMUL_BEFORE_ALLOCATION=elf_xtensa_before_allocation