1 # This shell script emits a C file. -*- C -*-
2 # Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009
3 # Free Software Foundation, Inc.
5 # This file is part of the GNU Binutils.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 # This file is sourced from elf32.em, and defines extra xtensa-elf
28 #include <xtensa-config.h>
29 #include "../bfd/elf-bfd.h"
30 #include "../bfd/libbfd.h"
31 #include "elf/xtensa.h"
34 /* Provide default values for new configuration settings. */
39 static void xtensa_wild_group_interleave (lang_statement_union_type *);
40 static void xtensa_colocate_output_literals (lang_statement_union_type *);
41 static void xtensa_strip_inconsistent_linkonce_sections
42 (lang_statement_list_type *);
45 /* This number is irrelevant until we turn on use_literal_pages */
46 static bfd_vma xtensa_page_power = 12; /* 4K pages. */
48 /* To force a page break between literals and text, change
49 xtensa_use_literal_pages to "TRUE". */
50 static bfd_boolean xtensa_use_literal_pages = FALSE;
52 #define EXTRA_VALIDATION 0
56 elf_xtensa_choose_target (int argc ATTRIBUTE_UNUSED,
57 char **argv ATTRIBUTE_UNUSED)
60 return "${BIG_OUTPUT_FORMAT}";
62 return "${LITTLE_OUTPUT_FORMAT}";
67 elf_xtensa_before_parse (void)
69 /* Just call the default hook.... Tensilica's version of this function
70 does some other work that isn't relevant here. */
71 gld${EMULATION_NAME}_before_parse ();
76 remove_section (bfd *abfd, asection *os)
79 for (spp = &abfd->sections; *spp; spp = &(*spp)->next)
83 os->owner->section_count--;
90 replace_insn_sec_with_prop_sec (bfd *abfd,
91 const char *insn_sec_name,
92 const char *prop_sec_name,
97 bfd_byte *prop_contents = NULL;
98 bfd_byte *insn_contents = NULL;
101 Elf_Internal_Shdr *symtab_hdr;
102 Elf_Internal_Rela *internal_relocs = NULL;
103 unsigned reloc_count;
106 insn_sec = bfd_get_section_by_name (abfd, insn_sec_name);
107 if (insn_sec == NULL)
109 entry_count = insn_sec->size / 8;
111 prop_sec = bfd_get_section_by_name (abfd, prop_sec_name);
112 if (prop_sec != NULL && insn_sec != NULL)
114 *error_message = _("file already has property tables");
118 if (insn_sec->size != 0)
120 insn_contents = (bfd_byte *) bfd_malloc (insn_sec->size);
121 if (insn_contents == NULL)
123 *error_message = _("out of memory");
126 if (! bfd_get_section_contents (abfd, insn_sec, insn_contents,
127 (file_ptr) 0, insn_sec->size))
129 *error_message = _("failed to read section contents");
134 /* Create a property table section for it. */
135 prop_sec_name = strdup (prop_sec_name);
136 prop_sec = bfd_make_section_with_flags
137 (abfd, prop_sec_name, bfd_get_section_flags (abfd, insn_sec));
139 || ! bfd_set_section_alignment (abfd, prop_sec, 2))
141 *error_message = _("could not create new section");
145 prop_sec->size = entry_count * 12;
146 prop_contents = (bfd_byte *) bfd_zalloc (abfd, prop_sec->size);
147 elf_section_data (prop_sec)->this_hdr.contents = prop_contents;
149 /* The entry size and size must be set to allow the linker to compute
150 the number of relocations since it does not use reloc_count. */
151 elf_section_data (prop_sec)->rel_hdr.sh_entsize =
152 sizeof (Elf32_External_Rela);
153 elf_section_data (prop_sec)->rel_hdr.sh_size =
154 elf_section_data (insn_sec)->rel_hdr.sh_size;
156 if (prop_contents == NULL && prop_sec->size != 0)
158 *error_message = _("could not allocate section contents");
162 /* Read the relocations. */
163 reloc_count = insn_sec->reloc_count;
164 if (reloc_count != 0)
166 /* If there is already an internal_reloc, then save it so that the
167 read_relocs function freshly allocates a copy. */
168 Elf_Internal_Rela *saved_relocs = elf_section_data (insn_sec)->relocs;
170 elf_section_data (insn_sec)->relocs = NULL;
172 _bfd_elf_link_read_relocs (abfd, insn_sec, NULL, NULL, FALSE);
173 elf_section_data (insn_sec)->relocs = saved_relocs;
175 if (internal_relocs == NULL)
177 *error_message = _("out of memory");
182 /* Create a relocation section for the property section. */
183 if (internal_relocs != NULL)
185 elf_section_data (prop_sec)->relocs = internal_relocs;
186 prop_sec->reloc_count = reloc_count;
189 /* Now copy each insn table entry to the prop table entry with
190 appropriate flags. */
191 for (entry = 0; entry < entry_count; ++entry)
194 unsigned flags = (XTENSA_PROP_INSN | XTENSA_PROP_NO_TRANSFORM
195 | XTENSA_PROP_INSN_NO_REORDER);
196 value = bfd_get_32 (abfd, insn_contents + entry * 8 + 0);
197 bfd_put_32 (abfd, value, prop_contents + entry * 12 + 0);
198 value = bfd_get_32 (abfd, insn_contents + entry * 8 + 4);
199 bfd_put_32 (abfd, value, prop_contents + entry * 12 + 4);
200 bfd_put_32 (abfd, flags, prop_contents + entry * 12 + 8);
203 /* Now copy all of the relocations. Change offsets for the
204 instruction table section to offsets in the property table
209 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
211 for (i = 0; i < reloc_count; i++)
213 Elf_Internal_Rela *rela;
216 rela = &internal_relocs[i];
218 /* If this relocation is to the .xt.insn section,
219 change the section number and the offset. */
220 r_offset = rela->r_offset;
221 r_offset += 4 * (r_offset / 8);
222 rela->r_offset = r_offset;
226 remove_section (abfd, insn_sec);
229 free (insn_contents);
234 if (prop_sec && prop_sec->owner)
235 remove_section (abfd, prop_sec);
237 free (insn_contents);
239 free (internal_relocs);
245 #define PROP_SEC_BASE_NAME ".xt.prop"
246 #define INSN_SEC_BASE_NAME ".xt.insn"
247 #define LINKONCE_SEC_OLD_TEXT_BASE_NAME ".gnu.linkonce.x."
251 replace_instruction_table_sections (bfd *abfd, asection *sec)
254 const char *insn_sec_name = NULL;
255 char *prop_sec_name = NULL;
256 char *owned_prop_sec_name = NULL;
257 const char *sec_name;
259 sec_name = bfd_get_section_name (abfd, sec);
260 if (strcmp (sec_name, INSN_SEC_BASE_NAME) == 0)
262 insn_sec_name = INSN_SEC_BASE_NAME;
263 prop_sec_name = PROP_SEC_BASE_NAME;
265 else if (CONST_STRNEQ (sec_name, LINKONCE_SEC_OLD_TEXT_BASE_NAME))
267 insn_sec_name = sec_name;
268 owned_prop_sec_name = (char *) xmalloc (strlen (sec_name) + 20);
269 prop_sec_name = owned_prop_sec_name;
270 strcpy (prop_sec_name, ".gnu.linkonce.prop.t.");
271 strcat (prop_sec_name,
272 sec_name + strlen (LINKONCE_SEC_OLD_TEXT_BASE_NAME));
274 if (insn_sec_name != NULL)
276 if (! replace_insn_sec_with_prop_sec (abfd, insn_sec_name, prop_sec_name,
279 einfo (_("%P: warning: failed to convert %s table in %B (%s); subsequent disassembly may be incomplete\n"),
280 insn_sec_name, abfd, message);
283 if (owned_prop_sec_name)
284 free (owned_prop_sec_name);
288 /* This is called after all input sections have been opened to convert
289 instruction tables (.xt.insn, gnu.linkonce.x.*) tables into property
290 tables (.xt.prop) before any section placement. */
293 elf_xtensa_after_open (void)
295 /* First call the ELF version. */
296 gld${EMULATION_NAME}_after_open ();
298 /* Now search the input files looking for instruction table sections. */
299 LANG_FOR_EACH_INPUT_STATEMENT (f)
301 asection *sec = f->the_bfd->sections;
304 /* Do not use bfd_map_over_sections here since we are removing
305 sections as we iterate. */
308 next_sec = sec->next;
309 replace_instruction_table_sections (f->the_bfd, sec);
317 xt_config_info_unpack_and_check (char *data,
318 bfd_boolean *pmismatch,
334 /* Overwrite the equal sign. */
337 /* Check if this is a quoted string or a number. */
340 /* No string values are currently checked by LD;
341 just skip over the quotes. */
346 /* Overwrite the trailing quote. */
353 num = strtoul (d, &d, 0);
355 if (! strcmp (key, "ABI"))
357 if (num != XSHAL_ABI)
360 *pmsg = "ABI does not match";
363 else if (! strcmp (key, "USE_ABSOLUTE_LITERALS"))
365 if (num != XSHAL_USE_ABSOLUTE_LITERALS)
368 *pmsg = "incompatible use of the Extended L32R option";
384 #define XTINFO_NAME "Xtensa_Info"
385 #define XTINFO_NAMESZ 12
386 #define XTINFO_TYPE 1
389 check_xtensa_info (bfd *abfd, asection *info_sec)
391 char *data, *errmsg = "";
392 bfd_boolean mismatch;
394 data = xmalloc (info_sec->size);
395 if (! bfd_get_section_contents (abfd, info_sec, data, 0, info_sec->size))
396 einfo (_("%F%P:%B: cannot read contents of section %A\n"), abfd, info_sec);
398 if (info_sec->size > 24
399 && info_sec->size >= 24 + bfd_get_32 (abfd, data + 4)
400 && bfd_get_32 (abfd, data + 0) == XTINFO_NAMESZ
401 && bfd_get_32 (abfd, data + 8) == XTINFO_TYPE
402 && strcmp (data + 12, XTINFO_NAME) == 0
403 && xt_config_info_unpack_and_check (data + 12 + XTINFO_NAMESZ,
407 einfo (_("%P:%B: warning: incompatible Xtensa configuration (%s)\n"),
411 einfo (_("%P:%B: warning: cannot parse .xtensa.info section\n"), abfd);
417 /* This is called after the sections have been attached to output
418 sections, but before any sizes or addresses have been set. */
421 elf_xtensa_before_allocation (void)
423 asection *info_sec, *first_info_sec;
425 bfd_boolean is_big_endian = XCHAL_HAVE_BE;
427 /* Check that the output endianness matches the Xtensa
428 configuration. The BFD library always includes both big and
429 little endian target vectors for Xtensa, but it only supports the
430 detailed instruction encode/decode operations (such as are
431 required to process relocations) for the selected Xtensa
435 && link_info.output_bfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
437 einfo (_("%F%P: little endian output does not match "
438 "Xtensa configuration\n"));
441 && link_info.output_bfd->xvec->byteorder == BFD_ENDIAN_BIG)
443 einfo (_("%F%P: big endian output does not match "
444 "Xtensa configuration\n"));
447 /* Keep track of the first input .xtensa.info section, and as a fallback,
448 the first input bfd where a .xtensa.info section could be created.
449 After the input .xtensa.info has been checked, the contents of the
450 first one will be replaced with the output .xtensa.info table. */
454 LANG_FOR_EACH_INPUT_STATEMENT (f)
456 /* Check that the endianness for each input file matches the output.
457 The merge_private_bfd_data hook has already reported any mismatches
458 as errors, but those errors are not fatal. At this point, we
459 cannot go any further if there are any mismatches. */
460 if ((is_big_endian && f->the_bfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
461 || (!is_big_endian && f->the_bfd->xvec->byteorder == BFD_ENDIAN_BIG))
462 einfo (_("%F%P: cross-endian linking for %B not supported\n"),
466 first_bfd = f->the_bfd;
468 info_sec = bfd_get_section_by_name (f->the_bfd, ".xtensa.info");
472 if (! first_info_sec)
473 first_info_sec = info_sec;
475 /* Unpack the .xtensa.info section and check it against the current
476 Xtensa configuration. */
477 check_xtensa_info (f->the_bfd, info_sec);
479 /* Do not include this copy of .xtensa.info in the output. */
481 info_sec->flags |= SEC_EXCLUDE;
484 /* Reuse the first .xtensa.info input section to hold the output
485 .xtensa.info; or, if none were found, create a new section in the
486 first input bfd (assuming there is one). */
487 info_sec = first_info_sec;
488 if (! info_sec && first_bfd)
490 info_sec = bfd_make_section_with_flags (first_bfd, ".xtensa.info",
491 SEC_HAS_CONTENTS | SEC_READONLY);
493 einfo (_("%F%P: failed to create .xtensa.info section\n"));
497 int xtensa_info_size;
500 info_sec->flags &= ~SEC_EXCLUDE;
501 info_sec->flags |= SEC_IN_MEMORY;
503 data = xmalloc (100);
504 sprintf (data, "USE_ABSOLUTE_LITERALS=%d\nABI=%d\n",
505 XSHAL_USE_ABSOLUTE_LITERALS, XSHAL_ABI);
506 xtensa_info_size = strlen (data) + 1;
508 /* Add enough null terminators to pad to a word boundary. */
510 data[xtensa_info_size++] = 0;
511 while ((xtensa_info_size & 3) != 0);
513 info_sec->size = 12 + XTINFO_NAMESZ + xtensa_info_size;
514 info_sec->contents = xmalloc (info_sec->size);
515 bfd_put_32 (info_sec->owner, XTINFO_NAMESZ, info_sec->contents + 0);
516 bfd_put_32 (info_sec->owner, xtensa_info_size, info_sec->contents + 4);
517 bfd_put_32 (info_sec->owner, XTINFO_TYPE, info_sec->contents + 8);
518 memcpy (info_sec->contents + 12, XTINFO_NAME, XTINFO_NAMESZ);
519 memcpy (info_sec->contents + 12 + XTINFO_NAMESZ, data, xtensa_info_size);
523 /* Enable relaxation by default if the "--no-relax" option was not
524 specified. This is done here instead of in the before_parse hook
525 because there is a check in main() to prohibit use of --relax and
526 -r together and that combination should be allowed for Xtensa. */
527 if (RELAXATION_DISABLED_BY_DEFAULT)
530 xtensa_strip_inconsistent_linkonce_sections (stat_ptr);
532 gld${EMULATION_NAME}_before_allocation ();
534 xtensa_wild_group_interleave (stat_ptr->head);
536 if (RELAXATION_ENABLED)
537 xtensa_colocate_output_literals (stat_ptr->head);
539 /* TBD: We need to force the page alignments to here and only do
540 them as needed for the entire output section. Finally, if this
541 is a relocatable link then we need to add alignment notes so
542 that the literals can be separated later. */
546 typedef struct wildcard_list section_name_list;
548 typedef struct reloc_deps_e_t reloc_deps_e;
549 typedef struct reloc_deps_section_t reloc_deps_section;
550 typedef struct reloc_deps_graph_t reloc_deps_graph;
553 struct reloc_deps_e_t
555 asection *src; /* Contains l32rs. */
556 asection *tgt; /* Contains literals. */
560 /* Place these in the userdata field. */
561 struct reloc_deps_section_t
565 bfd_boolean is_only_literal;
569 struct reloc_deps_graph_t
576 static void xtensa_layout_wild
577 (const reloc_deps_graph *, lang_wild_statement_type *);
579 typedef void (*deps_callback_t) (asection *, /* src_sec */
580 bfd_vma, /* src_offset */
581 asection *, /* target_sec */
582 bfd_vma, /* target_offset */
583 void *); /* closure */
585 extern bfd_boolean xtensa_callback_required_dependence
586 (bfd *, asection *, struct bfd_link_info *, deps_callback_t, void *);
587 static void xtensa_ldlang_clear_addresses (lang_statement_union_type *);
588 static bfd_boolean ld_local_file_relocations_fit
589 (lang_statement_union_type *, const reloc_deps_graph *);
590 static bfd_vma ld_assign_relative_paged_dot
591 (bfd_vma, lang_statement_union_type *, const reloc_deps_graph *,
593 static bfd_vma ld_xtensa_insert_page_offsets
594 (bfd_vma, lang_statement_union_type *, reloc_deps_graph *, bfd_boolean);
596 static size_t ld_count_children (lang_statement_union_type *);
599 extern lang_statement_list_type constructor_list;
601 /* Begin verbatim code from ldlang.c:
602 the following are copied from ldlang.c because they are defined
606 lang_for_each_statement_worker (void (*func) (lang_statement_union_type *),
607 lang_statement_union_type *s)
609 for (; s != (lang_statement_union_type *) NULL; s = s->header.next)
613 switch (s->header.type)
615 case lang_constructors_statement_enum:
616 lang_for_each_statement_worker (func, constructor_list.head);
618 case lang_output_section_statement_enum:
619 lang_for_each_statement_worker
621 s->output_section_statement.children.head);
623 case lang_wild_statement_enum:
624 lang_for_each_statement_worker
626 s->wild_statement.children.head);
628 case lang_group_statement_enum:
629 lang_for_each_statement_worker (func,
630 s->group_statement.children.head);
632 case lang_data_statement_enum:
633 case lang_reloc_statement_enum:
634 case lang_object_symbols_statement_enum:
635 case lang_output_statement_enum:
636 case lang_target_statement_enum:
637 case lang_input_section_enum:
638 case lang_input_statement_enum:
639 case lang_assignment_statement_enum:
640 case lang_padding_statement_enum:
641 case lang_address_statement_enum:
642 case lang_fill_statement_enum:
651 /* End of verbatim code from ldlang.c. */
654 static reloc_deps_section *
655 xtensa_get_section_deps (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
658 /* We have a separate function for this so that
659 we could in the future keep a completely independent
660 structure that maps a section to its dependence edges.
661 For now, we place these in the sec->userdata field. */
662 reloc_deps_section *sec_deps = sec->userdata;
667 xtensa_set_section_deps (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
669 reloc_deps_section *deps_section)
671 sec->userdata = deps_section;
675 /* This is used to keep a list of all of the sections participating in
676 the graph so we can clean them up quickly. */
679 xtensa_append_section_deps (reloc_deps_graph *deps, asection *sec)
681 if (deps->size <= deps->count)
683 asection **new_sections;
687 new_size = deps->size * 2;
691 new_sections = xmalloc (sizeof (asection *) * new_size);
692 memset (new_sections, 0, sizeof (asection *) * new_size);
693 for (i = 0; i < deps->count; i++)
695 new_sections[i] = deps->sections[i];
697 if (deps->sections != NULL)
698 free (deps->sections);
699 deps->sections = new_sections;
700 deps->size = new_size;
702 deps->sections[deps->count] = sec;
708 free_reloc_deps_graph (reloc_deps_graph *deps)
711 for (i = 0; i < deps->count; i++)
713 asection *sec = deps->sections[i];
714 reloc_deps_section *sec_deps;
715 sec_deps = xtensa_get_section_deps (deps, sec);
719 while (sec_deps->succs != NULL)
721 next = sec_deps->succs->next;
722 free (sec_deps->succs);
723 sec_deps->succs = next;
726 while (sec_deps->preds != NULL)
728 next = sec_deps->preds->next;
729 free (sec_deps->preds);
730 sec_deps->preds = next;
734 xtensa_set_section_deps (deps, sec, NULL);
737 free (deps->sections);
744 section_is_source (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
745 lang_statement_union_type *s)
748 const reloc_deps_section *sec_deps;
750 if (s->header.type != lang_input_section_enum)
752 sec = s->input_section.section;
754 sec_deps = xtensa_get_section_deps (deps, sec);
755 return sec_deps && sec_deps->succs != NULL;
760 section_is_target (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
761 lang_statement_union_type *s)
764 const reloc_deps_section *sec_deps;
766 if (s->header.type != lang_input_section_enum)
768 sec = s->input_section.section;
770 sec_deps = xtensa_get_section_deps (deps, sec);
771 return sec_deps && sec_deps->preds != NULL;
776 section_is_source_or_target (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
777 lang_statement_union_type *s)
779 return (section_is_source (deps, s)
780 || section_is_target (deps, s));
784 typedef struct xtensa_ld_iter_stack_t xtensa_ld_iter_stack;
785 typedef struct xtensa_ld_iter_t xtensa_ld_iter;
787 struct xtensa_ld_iter_t
789 lang_statement_union_type *parent; /* Parent of the list. */
790 lang_statement_list_type *l; /* List that holds it. */
791 lang_statement_union_type **loc; /* Place in the list. */
794 struct xtensa_ld_iter_stack_t
796 xtensa_ld_iter iterloc; /* List that hold it. */
798 xtensa_ld_iter_stack *next; /* Next in the stack. */
799 xtensa_ld_iter_stack *prev; /* Back pointer for stack. */
804 ld_xtensa_move_section_after (xtensa_ld_iter *to, xtensa_ld_iter *current)
806 lang_statement_union_type *to_next;
807 lang_statement_union_type *current_next;
808 lang_statement_union_type **e;
811 size_t old_to_count, new_to_count;
812 size_t old_current_count, new_current_count;
819 old_to_count = ld_count_children (to->parent);
820 old_current_count = ld_count_children (current->parent);
823 to_next = *(to->loc);
824 current_next = (*current->loc)->header.next;
826 *(to->loc) = *(current->loc);
828 *(current->loc) = current_next;
829 (*(to->loc))->header.next = to_next;
831 /* reset "to" list tail */
832 for (e = &to->l->head; *e != NULL; e = &(*e)->header.next)
836 /* reset "current" list tail */
837 for (e = ¤t->l->head; *e != NULL; e = &(*e)->header.next)
839 current->l->tail = e;
842 new_to_count = ld_count_children (to->parent);
843 new_current_count = ld_count_children (current->parent);
845 ASSERT ((old_to_count + old_current_count)
846 == (new_to_count + new_current_count));
851 /* Can only be called with lang_statements that have lists. Returns
852 FALSE if the list is empty. */
855 iter_stack_empty (xtensa_ld_iter_stack **stack_p)
857 return *stack_p == NULL;
862 iter_stack_push (xtensa_ld_iter_stack **stack_p,
863 lang_statement_union_type *parent)
865 xtensa_ld_iter_stack *stack;
866 lang_statement_list_type *l = NULL;
868 switch (parent->header.type)
870 case lang_output_section_statement_enum:
871 l = &parent->output_section_statement.children;
873 case lang_wild_statement_enum:
874 l = &parent->wild_statement.children;
876 case lang_group_statement_enum:
877 l = &parent->group_statement.children;
884 /* Empty. do not push. */
885 if (l->tail == &l->head)
888 stack = xmalloc (sizeof (xtensa_ld_iter_stack));
889 memset (stack, 0, sizeof (xtensa_ld_iter_stack));
890 stack->iterloc.parent = parent;
891 stack->iterloc.l = l;
892 stack->iterloc.loc = &l->head;
894 stack->next = *stack_p;
896 if (*stack_p != NULL)
897 (*stack_p)->prev = stack;
904 iter_stack_pop (xtensa_ld_iter_stack **stack_p)
906 xtensa_ld_iter_stack *stack;
912 ASSERT (stack != NULL);
916 if (stack->next != NULL)
917 stack->next->prev = NULL;
919 *stack_p = stack->next;
924 /* This MUST be called if, during iteration, the user changes the
925 underlying structure. It will check for a NULL current and advance
929 iter_stack_update (xtensa_ld_iter_stack **stack_p)
931 if (!iter_stack_empty (stack_p)
932 && (*(*stack_p)->iterloc.loc) == NULL)
934 iter_stack_pop (stack_p);
936 while (!iter_stack_empty (stack_p)
937 && ((*(*stack_p)->iterloc.loc)->header.next == NULL))
939 iter_stack_pop (stack_p);
941 if (!iter_stack_empty (stack_p))
942 (*stack_p)->iterloc.loc = &(*(*stack_p)->iterloc.loc)->header.next;
948 iter_stack_next (xtensa_ld_iter_stack **stack_p)
950 xtensa_ld_iter_stack *stack;
951 lang_statement_union_type *current;
954 current = *stack->iterloc.loc;
955 /* If we are on the first element. */
958 switch (current->header.type)
960 case lang_output_section_statement_enum:
961 case lang_wild_statement_enum:
962 case lang_group_statement_enum:
963 /* If the list if not empty, we are done. */
964 if (iter_stack_push (stack_p, *stack->iterloc.loc))
966 /* Otherwise increment the pointer as normal. */
973 while (!iter_stack_empty (stack_p)
974 && ((*(*stack_p)->iterloc.loc)->header.next == NULL))
976 iter_stack_pop (stack_p);
978 if (!iter_stack_empty (stack_p))
979 (*stack_p)->iterloc.loc = &(*(*stack_p)->iterloc.loc)->header.next;
983 static lang_statement_union_type *
984 iter_stack_current (xtensa_ld_iter_stack **stack_p)
986 return *((*stack_p)->iterloc.loc);
990 /* The iter stack is a preorder. */
993 iter_stack_create (xtensa_ld_iter_stack **stack_p,
994 lang_statement_union_type *parent)
996 iter_stack_push (stack_p, parent);
1001 iter_stack_copy_current (xtensa_ld_iter_stack **stack_p, xtensa_ld_iter *front)
1003 *front = (*stack_p)->iterloc;
1008 xtensa_colocate_literals (reloc_deps_graph *deps,
1009 lang_statement_union_type *statement)
1011 /* Keep a stack of pointers to control iteration through the contours. */
1012 xtensa_ld_iter_stack *stack = NULL;
1013 xtensa_ld_iter_stack **stack_p = &stack;
1015 xtensa_ld_iter front; /* Location where new insertion should occur. */
1016 xtensa_ld_iter *front_p = NULL;
1018 xtensa_ld_iter current; /* Location we are checking. */
1019 xtensa_ld_iter *current_p = NULL;
1020 bfd_boolean in_literals = FALSE;
1022 if (deps->count == 0)
1025 iter_stack_create (stack_p, statement);
1027 while (!iter_stack_empty (stack_p))
1029 bfd_boolean skip_increment = FALSE;
1030 lang_statement_union_type *l = iter_stack_current (stack_p);
1032 switch (l->header.type)
1034 case lang_assignment_statement_enum:
1035 /* Any assignment statement should block reordering across it. */
1037 in_literals = FALSE;
1040 case lang_input_section_enum:
1041 if (front_p == NULL)
1043 in_literals = (section_is_target (deps, l)
1044 && !section_is_source (deps, l));
1048 iter_stack_copy_current (stack_p, front_p);
1053 bfd_boolean is_target;
1054 current_p = ¤t;
1055 iter_stack_copy_current (stack_p, current_p);
1056 is_target = (section_is_target (deps, l)
1057 && !section_is_source (deps, l));
1061 iter_stack_copy_current (stack_p, front_p);
1063 in_literals = FALSE;
1069 /* Try to insert in place. */
1070 ld_xtensa_move_section_after (front_p, current_p);
1071 ld_assign_relative_paged_dot (0x100000,
1074 xtensa_use_literal_pages);
1076 /* We use this code because it's already written. */
1077 if (!ld_local_file_relocations_fit (statement, deps))
1080 ld_xtensa_move_section_after (current_p, front_p);
1081 /* Reset the literal placement. */
1082 iter_stack_copy_current (stack_p, front_p);
1086 /* Move front pointer up by one. */
1087 front_p->loc = &(*front_p->loc)->header.next;
1089 /* Do not increment the current pointer. */
1090 skip_increment = TRUE;
1100 if (!skip_increment)
1101 iter_stack_next (stack_p);
1103 /* Be careful to update the stack_p if it now is a null. */
1104 iter_stack_update (stack_p);
1107 lang_for_each_statement_worker (xtensa_ldlang_clear_addresses, statement);
1112 xtensa_move_dependencies_to_front (reloc_deps_graph *deps,
1113 lang_wild_statement_type *w)
1115 /* Keep a front pointer and a current pointer. */
1116 lang_statement_union_type **front;
1117 lang_statement_union_type **current;
1119 /* Walk to the end of the targets. */
1120 for (front = &w->children.head;
1121 (*front != NULL) && section_is_source_or_target (deps, *front);
1122 front = &(*front)->header.next)
1128 current = &(*front)->header.next;
1129 while (*current != NULL)
1131 if (section_is_source_or_target (deps, *current))
1133 /* Insert in place. */
1134 xtensa_ld_iter front_iter;
1135 xtensa_ld_iter current_iter;
1137 front_iter.parent = (lang_statement_union_type *) w;
1138 front_iter.l = &w->children;
1139 front_iter.loc = front;
1141 current_iter.parent = (lang_statement_union_type *) w;
1142 current_iter.l = &w->children;
1143 current_iter.loc = current;
1145 ld_xtensa_move_section_after (&front_iter, ¤t_iter);
1146 front = &(*front)->header.next;
1150 current = &(*current)->header.next;
1157 deps_has_sec_edge (const reloc_deps_graph *deps, asection *src, asection *tgt)
1159 const reloc_deps_section *sec_deps;
1160 const reloc_deps_e *sec_deps_e;
1162 sec_deps = xtensa_get_section_deps (deps, src);
1163 if (sec_deps == NULL)
1166 for (sec_deps_e = sec_deps->succs;
1168 sec_deps_e = sec_deps_e->next)
1170 ASSERT (sec_deps_e->src == src);
1171 if (sec_deps_e->tgt == tgt)
1179 deps_has_edge (const reloc_deps_graph *deps,
1180 lang_statement_union_type *src,
1181 lang_statement_union_type *tgt)
1183 if (!section_is_source (deps, src))
1185 if (!section_is_target (deps, tgt))
1188 if (src->header.type != lang_input_section_enum)
1190 if (tgt->header.type != lang_input_section_enum)
1193 return deps_has_sec_edge (deps, src->input_section.section,
1194 tgt->input_section.section);
1199 add_deps_edge (reloc_deps_graph *deps, asection *src_sec, asection *tgt_sec)
1201 reloc_deps_section *src_sec_deps;
1202 reloc_deps_section *tgt_sec_deps;
1204 reloc_deps_e *src_edge;
1205 reloc_deps_e *tgt_edge;
1207 if (deps_has_sec_edge (deps, src_sec, tgt_sec))
1210 src_sec_deps = xtensa_get_section_deps (deps, src_sec);
1211 if (src_sec_deps == NULL)
1213 /* Add a section. */
1214 src_sec_deps = xmalloc (sizeof (reloc_deps_section));
1215 memset (src_sec_deps, 0, sizeof (reloc_deps_section));
1216 src_sec_deps->is_only_literal = 0;
1217 src_sec_deps->preds = NULL;
1218 src_sec_deps->succs = NULL;
1219 xtensa_set_section_deps (deps, src_sec, src_sec_deps);
1220 xtensa_append_section_deps (deps, src_sec);
1223 tgt_sec_deps = xtensa_get_section_deps (deps, tgt_sec);
1224 if (tgt_sec_deps == NULL)
1226 /* Add a section. */
1227 tgt_sec_deps = xmalloc (sizeof (reloc_deps_section));
1228 memset (tgt_sec_deps, 0, sizeof (reloc_deps_section));
1229 tgt_sec_deps->is_only_literal = 0;
1230 tgt_sec_deps->preds = NULL;
1231 tgt_sec_deps->succs = NULL;
1232 xtensa_set_section_deps (deps, tgt_sec, tgt_sec_deps);
1233 xtensa_append_section_deps (deps, tgt_sec);
1236 /* Add the edges. */
1237 src_edge = xmalloc (sizeof (reloc_deps_e));
1238 memset (src_edge, 0, sizeof (reloc_deps_e));
1239 src_edge->src = src_sec;
1240 src_edge->tgt = tgt_sec;
1241 src_edge->next = src_sec_deps->succs;
1242 src_sec_deps->succs = src_edge;
1244 tgt_edge = xmalloc (sizeof (reloc_deps_e));
1245 memset (tgt_edge, 0, sizeof (reloc_deps_e));
1246 tgt_edge->src = src_sec;
1247 tgt_edge->tgt = tgt_sec;
1248 tgt_edge->next = tgt_sec_deps->preds;
1249 tgt_sec_deps->preds = tgt_edge;
1254 build_deps_graph_callback (asection *src_sec,
1255 bfd_vma src_offset ATTRIBUTE_UNUSED,
1256 asection *target_sec,
1257 bfd_vma target_offset ATTRIBUTE_UNUSED,
1260 reloc_deps_graph *deps = closure;
1262 /* If the target is defined. */
1263 if (target_sec != NULL)
1264 add_deps_edge (deps, src_sec, target_sec);
1268 static reloc_deps_graph *
1269 ld_build_required_section_dependence (lang_statement_union_type *s)
1271 reloc_deps_graph *deps;
1272 xtensa_ld_iter_stack *stack = NULL;
1274 deps = xmalloc (sizeof (reloc_deps_graph));
1275 deps->sections = NULL;
1279 for (iter_stack_create (&stack, s);
1280 !iter_stack_empty (&stack);
1281 iter_stack_next (&stack))
1283 lang_statement_union_type *l = iter_stack_current (&stack);
1285 if (l->header.type == lang_input_section_enum)
1287 lang_input_section_type *input;
1288 input = &l->input_section;
1289 xtensa_callback_required_dependence (input->section->owner,
1292 /* Use the same closure. */
1293 build_deps_graph_callback,
1301 #if EXTRA_VALIDATION
1303 ld_count_children (lang_statement_union_type *s)
1306 xtensa_ld_iter_stack *stack = NULL;
1307 for (iter_stack_create (&stack, s);
1308 !iter_stack_empty (&stack);
1309 iter_stack_next (&stack))
1311 lang_statement_union_type *l = iter_stack_current (&stack);
1317 #endif /* EXTRA_VALIDATION */
1320 /* Check if a particular section is included in the link. This will only
1321 be true for one instance of a particular linkonce section. */
1323 static bfd_boolean input_section_found = FALSE;
1324 static asection *input_section_target = NULL;
1327 input_section_linked_worker (lang_statement_union_type *statement)
1329 if ((statement->header.type == lang_input_section_enum
1330 && (statement->input_section.section == input_section_target)))
1331 input_section_found = TRUE;
1335 input_section_linked (asection *sec)
1337 input_section_found = FALSE;
1338 input_section_target = sec;
1339 lang_for_each_statement_worker (input_section_linked_worker, stat_ptr->head);
1340 return input_section_found;
1344 /* Strip out any linkonce property tables or XCC exception tables where the
1345 associated linkonce text is from a different object file. Normally,
1346 a matching set of linkonce sections is taken from the same object file,
1347 but sometimes the files are compiled differently so that some of the
1348 linkonce sections are not present in all files. Stripping the
1349 inconsistent sections like this is not completely robust -- a much
1350 better solution is to use comdat groups. */
1352 static int linkonce_len = sizeof (".gnu.linkonce.") - 1;
1355 is_inconsistent_linkonce_section (asection *sec)
1357 bfd *abfd = sec->owner;
1358 const char *sec_name = bfd_get_section_name (abfd, sec);
1361 if ((bfd_get_section_flags (abfd, sec) & SEC_LINK_ONCE) == 0
1362 || strncmp (sec_name, ".gnu.linkonce.", linkonce_len) != 0)
1365 /* Check if this is an Xtensa property section or an exception table
1366 for Tensilica's XCC compiler. */
1367 name = sec_name + linkonce_len;
1368 if (CONST_STRNEQ (name, "prop."))
1369 name = strchr (name + 5, '.') + 1;
1370 else if (name[1] == '.'
1371 && (name[0] == 'p' || name[0] == 'e' || name[0] == 'h'))
1378 char *dep_sec_name = xmalloc (strlen (sec_name) + 1);
1381 /* Get the associated linkonce text section and check if it is
1382 included in the link. If not, this section is inconsistent
1383 and should be stripped. */
1384 strcpy (dep_sec_name, ".gnu.linkonce.t.");
1385 strcat (dep_sec_name, name);
1386 dep_sec = bfd_get_section_by_name (abfd, dep_sec_name);
1387 if (dep_sec == NULL || ! input_section_linked (dep_sec))
1389 free (dep_sec_name);
1392 free (dep_sec_name);
1400 xtensa_strip_inconsistent_linkonce_sections (lang_statement_list_type *slist)
1402 lang_statement_union_type **s_p = &slist->head;
1405 lang_statement_union_type *s = *s_p;
1406 lang_statement_union_type *s_next = (*s_p)->header.next;
1408 switch (s->header.type)
1410 case lang_input_section_enum:
1411 if (is_inconsistent_linkonce_section (s->input_section.section))
1413 s->input_section.section->output_section = bfd_abs_section_ptr;
1419 case lang_constructors_statement_enum:
1420 xtensa_strip_inconsistent_linkonce_sections (&constructor_list);
1423 case lang_output_section_statement_enum:
1424 if (s->output_section_statement.children.head)
1425 xtensa_strip_inconsistent_linkonce_sections
1426 (&s->output_section_statement.children);
1429 case lang_wild_statement_enum:
1430 xtensa_strip_inconsistent_linkonce_sections
1431 (&s->wild_statement.children);
1434 case lang_group_statement_enum:
1435 xtensa_strip_inconsistent_linkonce_sections
1436 (&s->group_statement.children);
1439 case lang_data_statement_enum:
1440 case lang_reloc_statement_enum:
1441 case lang_object_symbols_statement_enum:
1442 case lang_output_statement_enum:
1443 case lang_target_statement_enum:
1444 case lang_input_statement_enum:
1445 case lang_assignment_statement_enum:
1446 case lang_padding_statement_enum:
1447 case lang_address_statement_enum:
1448 case lang_fill_statement_enum:
1456 s_p = &(*s_p)->header.next;
1459 /* Reset the tail of the list, in case the last entry was removed. */
1460 if (s_p != slist->tail)
1466 xtensa_wild_group_interleave_callback (lang_statement_union_type *statement)
1468 lang_wild_statement_type *w;
1469 reloc_deps_graph *deps;
1470 if (statement->header.type == lang_wild_statement_enum)
1472 #if EXTRA_VALIDATION
1473 size_t old_child_count;
1474 size_t new_child_count;
1476 bfd_boolean no_reorder;
1478 w = &statement->wild_statement;
1482 /* If it has 0 or 1 section bound, then do not reorder. */
1483 if (w->children.head == NULL
1484 || (w->children.head->header.type == lang_input_section_enum
1485 && w->children.head->header.next == NULL))
1488 if (w->filenames_sorted)
1491 /* Check for sorting in a section list wildcard spec as well. */
1494 struct wildcard_list *l;
1495 for (l = w->section_list; l != NULL; l = l->next)
1497 if (l->spec.sorted == TRUE)
1505 /* Special case until the NOREORDER linker directive is supported:
1506 *(.init) output sections and *(.fini) specs may NOT be reordered. */
1508 /* Check for sorting in a section list wildcard spec as well. */
1511 struct wildcard_list *l;
1512 for (l = w->section_list; l != NULL; l = l->next)
1515 && ((strcmp (".init", l->spec.name) == 0)
1516 || (strcmp (".fini", l->spec.name) == 0)))
1524 #if EXTRA_VALIDATION
1525 old_child_count = ld_count_children (statement);
1528 /* It is now officially a target. Build the graph of source
1529 section -> target section (kept as a list of edges). */
1530 deps = ld_build_required_section_dependence (statement);
1532 /* If this wildcard does not reorder.... */
1533 if (!no_reorder && deps->count != 0)
1535 /* First check for reverse dependences. Fix if possible. */
1536 xtensa_layout_wild (deps, w);
1538 xtensa_move_dependencies_to_front (deps, w);
1539 #if EXTRA_VALIDATION
1540 new_child_count = ld_count_children (statement);
1541 ASSERT (new_child_count == old_child_count);
1544 xtensa_colocate_literals (deps, statement);
1546 #if EXTRA_VALIDATION
1547 new_child_count = ld_count_children (statement);
1548 ASSERT (new_child_count == old_child_count);
1553 free_reloc_deps_graph (deps);
1559 xtensa_wild_group_interleave (lang_statement_union_type *s)
1561 lang_for_each_statement_worker (xtensa_wild_group_interleave_callback, s);
1566 xtensa_layout_wild (const reloc_deps_graph *deps, lang_wild_statement_type *w)
1568 /* If it does not fit initially, we need to do this step. Move all
1569 of the wild literal sections to a new list, then move each of
1570 them back in just before the first section they depend on. */
1571 lang_statement_union_type **s_p;
1572 #if EXTRA_VALIDATION
1573 size_t old_count, new_count;
1577 lang_wild_statement_type literal_wild;
1578 literal_wild.header.next = NULL;
1579 literal_wild.header.type = lang_wild_statement_enum;
1580 literal_wild.filename = NULL;
1581 literal_wild.filenames_sorted = FALSE;
1582 literal_wild.section_list = NULL;
1583 literal_wild.keep_sections = FALSE;
1584 literal_wild.children.head = NULL;
1585 literal_wild.children.tail = &literal_wild.children.head;
1587 #if EXTRA_VALIDATION
1588 old_count = ld_count_children ((lang_statement_union_type*) w);
1591 s_p = &w->children.head;
1592 while (*s_p != NULL)
1594 lang_statement_union_type *l = *s_p;
1595 if (l->header.type == lang_input_section_enum)
1597 if (section_is_target (deps, l)
1598 && ! section_is_source (deps, l))
1601 *s_p = l->header.next;
1603 w->children.tail = s_p;
1604 l->header.next = NULL;
1607 *literal_wild.children.tail = l;
1608 literal_wild.children.tail = &l->header.next;
1612 s_p = &(*s_p)->header.next;
1615 #if EXTRA_VALIDATION
1616 ct1 = ld_count_children ((lang_statement_union_type*) w);
1617 ct2 = ld_count_children ((lang_statement_union_type*) &literal_wild);
1619 ASSERT (old_count == (ct1 + ct2));
1622 /* Now place them back in front of their dependent sections. */
1624 while (literal_wild.children.head != NULL)
1626 lang_statement_union_type *lit = literal_wild.children.head;
1627 bfd_boolean placed = FALSE;
1629 #if EXTRA_VALIDATION
1635 literal_wild.children.head = lit->header.next;
1636 if (literal_wild.children.head == NULL)
1637 literal_wild.children.tail = &literal_wild.children.head;
1638 lit->header.next = NULL;
1640 /* Find a spot to place it. */
1641 for (s_p = &w->children.head; *s_p != NULL; s_p = &(*s_p)->header.next)
1643 lang_statement_union_type *src = *s_p;
1644 if (deps_has_edge (deps, src, lit))
1646 /* Place it here. */
1647 lit->header.next = *s_p;
1656 /* Put it at the end. */
1657 *w->children.tail = lit;
1658 w->children.tail = &lit->header.next;
1662 #if EXTRA_VALIDATION
1663 new_count = ld_count_children ((lang_statement_union_type*) w);
1664 ASSERT (new_count == old_count);
1670 xtensa_colocate_output_literals_callback (lang_statement_union_type *statement)
1672 lang_output_section_statement_type *os;
1673 reloc_deps_graph *deps;
1674 if (statement->header.type == lang_output_section_statement_enum)
1676 /* Now, we walk over the contours of the output section statement.
1678 First we build the literal section dependences as before.
1680 At the first uniquely_literal section, we mark it as a good
1681 spot to place other literals. Continue walking (and counting
1682 sizes) until we find the next literal section. If this
1683 section can be moved to the first one, then we move it. If
1684 we every find a modification of ".", start over. If we find
1685 a labeling of the current location, start over. Finally, at
1686 the end, if we require page alignment, add page alignments. */
1688 #if EXTRA_VALIDATION
1689 size_t old_child_count;
1690 size_t new_child_count;
1692 bfd_boolean no_reorder = FALSE;
1694 os = &statement->output_section_statement;
1696 #if EXTRA_VALIDATION
1697 old_child_count = ld_count_children (statement);
1700 /* It is now officially a target. Build the graph of source
1701 section -> target section (kept as a list of edges). */
1703 deps = ld_build_required_section_dependence (statement);
1705 /* If this wildcard does not reorder.... */
1708 /* First check for reverse dependences. Fix if possible. */
1709 xtensa_colocate_literals (deps, statement);
1711 #if EXTRA_VALIDATION
1712 new_child_count = ld_count_children (statement);
1713 ASSERT (new_child_count == old_child_count);
1717 /* Insert align/offset assignment statement. */
1718 if (xtensa_use_literal_pages)
1720 ld_xtensa_insert_page_offsets (0, statement, deps,
1721 xtensa_use_literal_pages);
1722 lang_for_each_statement_worker (xtensa_ldlang_clear_addresses,
1727 free_reloc_deps_graph (deps);
1733 xtensa_colocate_output_literals (lang_statement_union_type *s)
1735 lang_for_each_statement_worker (xtensa_colocate_output_literals_callback, s);
1740 xtensa_ldlang_clear_addresses (lang_statement_union_type *statement)
1742 switch (statement->header.type)
1744 case lang_input_section_enum:
1746 asection *bfd_section = statement->input_section.section;
1747 bfd_section->output_offset = 0;
1757 ld_assign_relative_paged_dot (bfd_vma dot,
1758 lang_statement_union_type *s,
1759 const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
1760 bfd_boolean lit_align)
1762 /* Walk through all of the input statements in this wild statement
1763 assign dot to all of them. */
1765 xtensa_ld_iter_stack *stack = NULL;
1766 xtensa_ld_iter_stack **stack_p = &stack;
1768 bfd_boolean first_section = FALSE;
1769 bfd_boolean in_literals = FALSE;
1771 for (iter_stack_create (stack_p, s);
1772 !iter_stack_empty (stack_p);
1773 iter_stack_next (stack_p))
1775 lang_statement_union_type *l = iter_stack_current (stack_p);
1777 switch (l->header.type)
1779 case lang_input_section_enum:
1781 asection *section = l->input_section.section;
1782 size_t align_pow = section->alignment_power;
1783 bfd_boolean do_xtensa_alignment = FALSE;
1787 bfd_boolean sec_is_target = section_is_target (deps, l);
1788 bfd_boolean sec_is_source = section_is_source (deps, l);
1790 if (section->size != 0
1792 || (in_literals && !sec_is_target)
1793 || (!in_literals && sec_is_target)))
1795 do_xtensa_alignment = TRUE;
1797 first_section = FALSE;
1798 if (section->size != 0)
1799 in_literals = (sec_is_target && !sec_is_source);
1802 if (do_xtensa_alignment && xtensa_page_power != 0)
1803 dot += (1 << xtensa_page_power);
1805 dot = align_power (dot, align_pow);
1806 section->output_offset = dot;
1807 dot += section->size;
1810 case lang_fill_statement_enum:
1811 dot += l->fill_statement.size;
1813 case lang_padding_statement_enum:
1814 dot += l->padding_statement.size;
1825 ld_local_file_relocations_fit (lang_statement_union_type *statement,
1826 const reloc_deps_graph *deps ATTRIBUTE_UNUSED)
1828 /* Walk over all of the dependencies that we identified and make
1829 sure that IF the source and target are here (addr != 0):
1830 1) target addr < source addr
1831 2) (roundup(source + source_size, 4) - rounddown(target, 4))
1832 < (256K - (1 << bad align))
1833 Need a worst-case proof.... */
1835 xtensa_ld_iter_stack *stack = NULL;
1836 xtensa_ld_iter_stack **stack_p = &stack;
1837 size_t max_align_power = 0;
1838 size_t align_penalty = 256;
1842 /* Find the worst-case alignment requirement for this set of statements. */
1843 for (iter_stack_create (stack_p, statement);
1844 !iter_stack_empty (stack_p);
1845 iter_stack_next (stack_p))
1847 lang_statement_union_type *l = iter_stack_current (stack_p);
1848 if (l->header.type == lang_input_section_enum)
1850 lang_input_section_type *input = &l->input_section;
1851 asection *section = input->section;
1852 if (section->alignment_power > max_align_power)
1853 max_align_power = section->alignment_power;
1857 /* Now check that everything fits. */
1858 for (i = 0; i < deps->count; i++)
1860 asection *sec = deps->sections[i];
1861 const reloc_deps_section *deps_section =
1862 xtensa_get_section_deps (deps, sec);
1865 /* We choose to walk through the successors. */
1866 for (e = deps_section->succs; e != NULL; e = e->next)
1868 if (e->src != e->tgt
1869 && e->src->output_section == e->tgt->output_section
1870 && e->src->output_offset != 0
1871 && e->tgt->output_offset != 0)
1874 align_power (e->src->output_offset + e->src->size, 2);
1875 bfd_vma target_addr = e->tgt->output_offset & ~3;
1876 if (l32r_addr < target_addr)
1878 fprintf (stderr, "Warning: "
1879 "l32r target section before l32r\n");
1883 if (l32r_addr - target_addr > 256 * 1024 - align_penalty)
1895 ld_xtensa_insert_page_offsets (bfd_vma dot,
1896 lang_statement_union_type *s,
1897 reloc_deps_graph *deps,
1898 bfd_boolean lit_align)
1900 xtensa_ld_iter_stack *stack = NULL;
1901 xtensa_ld_iter_stack **stack_p = &stack;
1903 bfd_boolean first_section = FALSE;
1904 bfd_boolean in_literals = FALSE;
1909 for (iter_stack_create (stack_p, s);
1910 !iter_stack_empty (stack_p);
1911 iter_stack_next (stack_p))
1913 lang_statement_union_type *l = iter_stack_current (stack_p);
1915 switch (l->header.type)
1917 case lang_input_section_enum:
1919 asection *section = l->input_section.section;
1920 bfd_boolean do_xtensa_alignment = FALSE;
1924 if (section->size != 0
1926 || (in_literals && !section_is_target (deps, l))
1927 || (!in_literals && section_is_target (deps, l))))
1929 do_xtensa_alignment = TRUE;
1931 first_section = FALSE;
1932 if (section->size != 0)
1934 in_literals = (section_is_target (deps, l)
1935 && !section_is_source (deps, l));
1939 if (do_xtensa_alignment && xtensa_page_power != 0)
1941 /* Create an expression that increments the current address,
1942 i.e., "dot", by (1 << xtensa_align_power). */
1943 etree_type *name_op = exp_nameop (NAME, ".");
1944 etree_type *addend_op = exp_intop (1 << xtensa_page_power);
1945 etree_type *add_op = exp_binop ('+', name_op, addend_op);
1946 etree_type *assign_op = exp_assop ('=', ".", add_op);
1948 lang_assignment_statement_type *assign_stmt;
1949 lang_statement_union_type *assign_union;
1950 lang_statement_list_type tmplist;
1952 /* There is hidden state in "lang_add_assignment". It
1953 appends the new assignment statement to the stat_ptr
1954 list. Thus, we swap it before and after the call. */
1956 lang_list_init (&tmplist);
1957 push_stat_ptr (&tmplist);
1958 /* Warning: side effect; statement appended to stat_ptr. */
1959 assign_stmt = lang_add_assignment (assign_op);
1960 assign_union = (lang_statement_union_type *) assign_stmt;
1963 assign_union->header.next = l;
1964 *(*stack_p)->iterloc.loc = assign_union;
1965 iter_stack_next (stack_p);
1978 # Define some shell vars to insert bits of code into the standard ELF
1979 # parse_args and list_options functions.
1981 PARSE_AND_LIST_PROLOGUE='
1982 #define OPTION_OPT_SIZEOPT (300)
1983 #define OPTION_LITERAL_MOVEMENT (OPTION_OPT_SIZEOPT + 1)
1984 #define OPTION_NO_LITERAL_MOVEMENT (OPTION_LITERAL_MOVEMENT + 1)
1985 extern int elf32xtensa_size_opt;
1986 extern int elf32xtensa_no_literal_movement;
1989 PARSE_AND_LIST_LONGOPTS='
1990 { "size-opt", no_argument, NULL, OPTION_OPT_SIZEOPT},
1991 { "literal-movement", no_argument, NULL, OPTION_LITERAL_MOVEMENT},
1992 { "no-literal-movement", no_argument, NULL, OPTION_NO_LITERAL_MOVEMENT},
1995 PARSE_AND_LIST_OPTIONS='
1997 --size-opt When relaxing longcalls, prefer size\n\
1998 optimization over branch target alignment\n"));
2001 PARSE_AND_LIST_ARGS_CASES='
2002 case OPTION_OPT_SIZEOPT:
2003 elf32xtensa_size_opt = 1;
2005 case OPTION_LITERAL_MOVEMENT:
2006 elf32xtensa_no_literal_movement = 0;
2008 case OPTION_NO_LITERAL_MOVEMENT:
2009 elf32xtensa_no_literal_movement = 1;
2013 # Replace some of the standard ELF functions with our own versions.
2015 LDEMUL_BEFORE_PARSE=elf_xtensa_before_parse
2016 LDEMUL_AFTER_OPEN=elf_xtensa_after_open
2017 LDEMUL_CHOOSE_TARGET=elf_xtensa_choose_target
2018 LDEMUL_BEFORE_ALLOCATION=elf_xtensa_before_allocation