1 # This shell script emits a C file. -*- C -*-
2 # Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
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_Rela *internal_relocs = NULL;
102 unsigned reloc_count;
105 insn_sec = bfd_get_section_by_name (abfd, insn_sec_name);
106 if (insn_sec == NULL)
108 entry_count = insn_sec->size / 8;
110 prop_sec = bfd_get_section_by_name (abfd, prop_sec_name);
111 if (prop_sec != NULL && insn_sec != NULL)
113 *error_message = _("file already has property tables");
117 if (insn_sec->size != 0)
119 insn_contents = (bfd_byte *) bfd_malloc (insn_sec->size);
120 if (insn_contents == NULL)
122 *error_message = _("out of memory");
125 if (! bfd_get_section_contents (abfd, insn_sec, insn_contents,
126 (file_ptr) 0, insn_sec->size))
128 *error_message = _("failed to read section contents");
133 /* Create a property table section for it. */
134 prop_sec_name = strdup (prop_sec_name);
135 prop_sec = bfd_make_section_with_flags
136 (abfd, prop_sec_name, bfd_get_section_flags (abfd, insn_sec));
138 || ! bfd_set_section_alignment (abfd, prop_sec, 2))
140 *error_message = _("could not create new section");
144 prop_sec->size = entry_count * 12;
145 prop_contents = (bfd_byte *) bfd_zalloc (abfd, prop_sec->size);
146 elf_section_data (prop_sec)->this_hdr.contents = prop_contents;
148 /* The entry size and size must be set to allow the linker to compute
149 the number of relocations since it does not use reloc_count. */
150 elf_section_data (prop_sec)->rel_hdr.sh_entsize =
151 sizeof (Elf32_External_Rela);
152 elf_section_data (prop_sec)->rel_hdr.sh_size =
153 elf_section_data (insn_sec)->rel_hdr.sh_size;
155 if (prop_contents == NULL && prop_sec->size != 0)
157 *error_message = _("could not allocate section contents");
161 /* Read the relocations. */
162 reloc_count = insn_sec->reloc_count;
163 if (reloc_count != 0)
165 /* If there is already an internal_reloc, then save it so that the
166 read_relocs function freshly allocates a copy. */
167 Elf_Internal_Rela *saved_relocs = elf_section_data (insn_sec)->relocs;
169 elf_section_data (insn_sec)->relocs = NULL;
171 _bfd_elf_link_read_relocs (abfd, insn_sec, NULL, NULL, FALSE);
172 elf_section_data (insn_sec)->relocs = saved_relocs;
174 if (internal_relocs == NULL)
176 *error_message = _("out of memory");
181 /* Create a relocation section for the property section. */
182 if (internal_relocs != NULL)
184 elf_section_data (prop_sec)->relocs = internal_relocs;
185 prop_sec->reloc_count = reloc_count;
188 /* Now copy each insn table entry to the prop table entry with
189 appropriate flags. */
190 for (entry = 0; entry < entry_count; ++entry)
193 unsigned flags = (XTENSA_PROP_INSN | XTENSA_PROP_NO_TRANSFORM
194 | XTENSA_PROP_INSN_NO_REORDER);
195 value = bfd_get_32 (abfd, insn_contents + entry * 8 + 0);
196 bfd_put_32 (abfd, value, prop_contents + entry * 12 + 0);
197 value = bfd_get_32 (abfd, insn_contents + entry * 8 + 4);
198 bfd_put_32 (abfd, value, prop_contents + entry * 12 + 4);
199 bfd_put_32 (abfd, flags, prop_contents + entry * 12 + 8);
202 /* Now copy all of the relocations. Change offsets for the
203 instruction table section to offsets in the property table
209 for (i = 0; i < reloc_count; i++)
211 Elf_Internal_Rela *rela;
214 rela = &internal_relocs[i];
216 /* If this relocation is to the .xt.insn section,
217 change the section number and the offset. */
218 r_offset = rela->r_offset;
219 r_offset += 4 * (r_offset / 8);
220 rela->r_offset = r_offset;
224 remove_section (abfd, insn_sec);
227 free (insn_contents);
232 if (prop_sec && prop_sec->owner)
233 remove_section (abfd, prop_sec);
235 free (insn_contents);
237 free (internal_relocs);
243 #define PROP_SEC_BASE_NAME ".xt.prop"
244 #define INSN_SEC_BASE_NAME ".xt.insn"
245 #define LINKONCE_SEC_OLD_TEXT_BASE_NAME ".gnu.linkonce.x."
249 replace_instruction_table_sections (bfd *abfd, asection *sec)
252 const char *insn_sec_name = NULL;
253 char *prop_sec_name = NULL;
254 char *owned_prop_sec_name = NULL;
255 const char *sec_name;
257 sec_name = bfd_get_section_name (abfd, sec);
258 if (strcmp (sec_name, INSN_SEC_BASE_NAME) == 0)
260 insn_sec_name = INSN_SEC_BASE_NAME;
261 prop_sec_name = PROP_SEC_BASE_NAME;
263 else if (CONST_STRNEQ (sec_name, LINKONCE_SEC_OLD_TEXT_BASE_NAME))
265 insn_sec_name = sec_name;
266 owned_prop_sec_name = (char *) xmalloc (strlen (sec_name) + 20);
267 prop_sec_name = owned_prop_sec_name;
268 strcpy (prop_sec_name, ".gnu.linkonce.prop.t.");
269 strcat (prop_sec_name,
270 sec_name + strlen (LINKONCE_SEC_OLD_TEXT_BASE_NAME));
272 if (insn_sec_name != NULL)
274 if (! replace_insn_sec_with_prop_sec (abfd, insn_sec_name, prop_sec_name,
277 einfo (_("%P: warning: failed to convert %s table in %B (%s); subsequent disassembly may be incomplete\n"),
278 insn_sec_name, abfd, message);
281 if (owned_prop_sec_name)
282 free (owned_prop_sec_name);
286 /* This is called after all input sections have been opened to convert
287 instruction tables (.xt.insn, gnu.linkonce.x.*) tables into property
288 tables (.xt.prop) before any section placement. */
291 elf_xtensa_after_open (void)
293 /* First call the ELF version. */
294 gld${EMULATION_NAME}_after_open ();
296 /* Now search the input files looking for instruction table sections. */
297 LANG_FOR_EACH_INPUT_STATEMENT (f)
299 asection *sec = f->the_bfd->sections;
302 /* Do not use bfd_map_over_sections here since we are removing
303 sections as we iterate. */
306 next_sec = sec->next;
307 replace_instruction_table_sections (f->the_bfd, sec);
315 xt_config_info_unpack_and_check (char *data,
316 bfd_boolean *pmismatch,
332 /* Overwrite the equal sign. */
335 /* Check if this is a quoted string or a number. */
338 /* No string values are currently checked by LD;
339 just skip over the quotes. */
344 /* Overwrite the trailing quote. */
351 num = strtoul (d, &d, 0);
353 if (! strcmp (key, "ABI"))
355 if (num != XSHAL_ABI)
358 *pmsg = "ABI does not match";
361 else if (! strcmp (key, "USE_ABSOLUTE_LITERALS"))
363 if (num != XSHAL_USE_ABSOLUTE_LITERALS)
366 *pmsg = "incompatible use of the Extended L32R option";
382 #define XTINFO_NAME "Xtensa_Info"
383 #define XTINFO_NAMESZ 12
384 #define XTINFO_TYPE 1
387 check_xtensa_info (bfd *abfd, asection *info_sec)
389 char *data, *errmsg = "";
390 bfd_boolean mismatch;
392 data = xmalloc (info_sec->size);
393 if (! bfd_get_section_contents (abfd, info_sec, data, 0, info_sec->size))
394 einfo (_("%F%P:%B: cannot read contents of section %A\n"), abfd, info_sec);
396 if (info_sec->size > 24
397 && info_sec->size >= 24 + bfd_get_32 (abfd, data + 4)
398 && bfd_get_32 (abfd, data + 0) == XTINFO_NAMESZ
399 && bfd_get_32 (abfd, data + 8) == XTINFO_TYPE
400 && strcmp (data + 12, XTINFO_NAME) == 0
401 && xt_config_info_unpack_and_check (data + 12 + XTINFO_NAMESZ,
405 einfo (_("%P:%B: warning: incompatible Xtensa configuration (%s)\n"),
409 einfo (_("%P:%B: warning: cannot parse .xtensa.info section\n"), abfd);
415 /* This is called after the sections have been attached to output
416 sections, but before any sizes or addresses have been set. */
419 elf_xtensa_before_allocation (void)
421 asection *info_sec, *first_info_sec;
423 bfd_boolean is_big_endian = XCHAL_HAVE_BE;
425 /* Check that the output endianness matches the Xtensa
426 configuration. The BFD library always includes both big and
427 little endian target vectors for Xtensa, but it only supports the
428 detailed instruction encode/decode operations (such as are
429 required to process relocations) for the selected Xtensa
433 && link_info.output_bfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
435 einfo (_("%F%P: little endian output does not match "
436 "Xtensa configuration\n"));
439 && link_info.output_bfd->xvec->byteorder == BFD_ENDIAN_BIG)
441 einfo (_("%F%P: big endian output does not match "
442 "Xtensa configuration\n"));
445 /* Keep track of the first input .xtensa.info section, and as a fallback,
446 the first input bfd where a .xtensa.info section could be created.
447 After the input .xtensa.info has been checked, the contents of the
448 first one will be replaced with the output .xtensa.info table. */
452 LANG_FOR_EACH_INPUT_STATEMENT (f)
454 /* Check that the endianness for each input file matches the output.
455 The merge_private_bfd_data hook has already reported any mismatches
456 as errors, but those errors are not fatal. At this point, we
457 cannot go any further if there are any mismatches. */
458 if ((is_big_endian && f->the_bfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
459 || (!is_big_endian && f->the_bfd->xvec->byteorder == BFD_ENDIAN_BIG))
460 einfo (_("%F%P: cross-endian linking for %B not supported\n"),
464 first_bfd = f->the_bfd;
466 info_sec = bfd_get_section_by_name (f->the_bfd, ".xtensa.info");
470 if (! first_info_sec)
471 first_info_sec = info_sec;
473 /* Unpack the .xtensa.info section and check it against the current
474 Xtensa configuration. */
475 check_xtensa_info (f->the_bfd, info_sec);
477 /* Do not include this copy of .xtensa.info in the output. */
479 info_sec->flags |= SEC_EXCLUDE;
482 /* Reuse the first .xtensa.info input section to hold the output
483 .xtensa.info; or, if none were found, create a new section in the
484 first input bfd (assuming there is one). */
485 info_sec = first_info_sec;
486 if (! info_sec && first_bfd)
488 info_sec = bfd_make_section_with_flags (first_bfd, ".xtensa.info",
489 SEC_HAS_CONTENTS | SEC_READONLY);
491 einfo (_("%F%P: failed to create .xtensa.info section\n"));
495 int xtensa_info_size;
498 info_sec->flags &= ~SEC_EXCLUDE;
499 info_sec->flags |= SEC_IN_MEMORY;
501 data = xmalloc (100);
502 sprintf (data, "USE_ABSOLUTE_LITERALS=%d\nABI=%d\n",
503 XSHAL_USE_ABSOLUTE_LITERALS, XSHAL_ABI);
504 xtensa_info_size = strlen (data) + 1;
506 /* Add enough null terminators to pad to a word boundary. */
508 data[xtensa_info_size++] = 0;
509 while ((xtensa_info_size & 3) != 0);
511 info_sec->size = 12 + XTINFO_NAMESZ + xtensa_info_size;
512 info_sec->contents = xmalloc (info_sec->size);
513 bfd_put_32 (info_sec->owner, XTINFO_NAMESZ, info_sec->contents + 0);
514 bfd_put_32 (info_sec->owner, xtensa_info_size, info_sec->contents + 4);
515 bfd_put_32 (info_sec->owner, XTINFO_TYPE, info_sec->contents + 8);
516 memcpy (info_sec->contents + 12, XTINFO_NAME, XTINFO_NAMESZ);
517 memcpy (info_sec->contents + 12 + XTINFO_NAMESZ, data, xtensa_info_size);
521 /* Enable relaxation by default if the "--no-relax" option was not
522 specified. This is done here instead of in the before_parse hook
523 because there is a check in main() to prohibit use of --relax and
524 -r together and that combination should be allowed for Xtensa. */
525 if (RELAXATION_DISABLED_BY_DEFAULT)
528 xtensa_strip_inconsistent_linkonce_sections (stat_ptr);
530 gld${EMULATION_NAME}_before_allocation ();
532 xtensa_wild_group_interleave (stat_ptr->head);
534 if (RELAXATION_ENABLED)
535 xtensa_colocate_output_literals (stat_ptr->head);
537 /* TBD: We need to force the page alignments to here and only do
538 them as needed for the entire output section. Finally, if this
539 is a relocatable link then we need to add alignment notes so
540 that the literals can be separated later. */
544 typedef struct wildcard_list section_name_list;
546 typedef struct reloc_deps_e_t reloc_deps_e;
547 typedef struct reloc_deps_section_t reloc_deps_section;
548 typedef struct reloc_deps_graph_t reloc_deps_graph;
551 struct reloc_deps_e_t
553 asection *src; /* Contains l32rs. */
554 asection *tgt; /* Contains literals. */
558 /* Place these in the userdata field. */
559 struct reloc_deps_section_t
563 bfd_boolean is_only_literal;
567 struct reloc_deps_graph_t
574 static void xtensa_layout_wild
575 (const reloc_deps_graph *, lang_wild_statement_type *);
577 typedef void (*deps_callback_t) (asection *, /* src_sec */
578 bfd_vma, /* src_offset */
579 asection *, /* target_sec */
580 bfd_vma, /* target_offset */
581 void *); /* closure */
583 extern bfd_boolean xtensa_callback_required_dependence
584 (bfd *, asection *, struct bfd_link_info *, deps_callback_t, void *);
585 static void xtensa_ldlang_clear_addresses (lang_statement_union_type *);
586 static bfd_boolean ld_local_file_relocations_fit
587 (lang_statement_union_type *, const reloc_deps_graph *);
588 static bfd_vma ld_assign_relative_paged_dot
589 (bfd_vma, lang_statement_union_type *, const reloc_deps_graph *,
591 static bfd_vma ld_xtensa_insert_page_offsets
592 (bfd_vma, lang_statement_union_type *, reloc_deps_graph *, bfd_boolean);
594 static size_t ld_count_children (lang_statement_union_type *);
597 extern lang_statement_list_type constructor_list;
599 /* Begin verbatim code from ldlang.c:
600 the following are copied from ldlang.c because they are defined
604 lang_for_each_statement_worker (void (*func) (lang_statement_union_type *),
605 lang_statement_union_type *s)
607 for (; s != (lang_statement_union_type *) NULL; s = s->header.next)
611 switch (s->header.type)
613 case lang_constructors_statement_enum:
614 lang_for_each_statement_worker (func, constructor_list.head);
616 case lang_output_section_statement_enum:
617 lang_for_each_statement_worker
619 s->output_section_statement.children.head);
621 case lang_wild_statement_enum:
622 lang_for_each_statement_worker
624 s->wild_statement.children.head);
626 case lang_group_statement_enum:
627 lang_for_each_statement_worker (func,
628 s->group_statement.children.head);
630 case lang_data_statement_enum:
631 case lang_reloc_statement_enum:
632 case lang_object_symbols_statement_enum:
633 case lang_output_statement_enum:
634 case lang_target_statement_enum:
635 case lang_input_section_enum:
636 case lang_input_statement_enum:
637 case lang_assignment_statement_enum:
638 case lang_padding_statement_enum:
639 case lang_address_statement_enum:
640 case lang_fill_statement_enum:
649 /* End of verbatim code from ldlang.c. */
652 static reloc_deps_section *
653 xtensa_get_section_deps (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
656 /* We have a separate function for this so that
657 we could in the future keep a completely independent
658 structure that maps a section to its dependence edges.
659 For now, we place these in the sec->userdata field. */
660 reloc_deps_section *sec_deps = sec->userdata;
665 xtensa_set_section_deps (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
667 reloc_deps_section *deps_section)
669 sec->userdata = deps_section;
673 /* This is used to keep a list of all of the sections participating in
674 the graph so we can clean them up quickly. */
677 xtensa_append_section_deps (reloc_deps_graph *deps, asection *sec)
679 if (deps->size <= deps->count)
681 asection **new_sections;
685 new_size = deps->size * 2;
689 new_sections = xmalloc (sizeof (asection *) * new_size);
690 memset (new_sections, 0, sizeof (asection *) * new_size);
691 for (i = 0; i < deps->count; i++)
693 new_sections[i] = deps->sections[i];
695 if (deps->sections != NULL)
696 free (deps->sections);
697 deps->sections = new_sections;
698 deps->size = new_size;
700 deps->sections[deps->count] = sec;
706 free_reloc_deps_graph (reloc_deps_graph *deps)
709 for (i = 0; i < deps->count; i++)
711 asection *sec = deps->sections[i];
712 reloc_deps_section *sec_deps;
713 sec_deps = xtensa_get_section_deps (deps, sec);
717 while (sec_deps->succs != NULL)
719 next = sec_deps->succs->next;
720 free (sec_deps->succs);
721 sec_deps->succs = next;
724 while (sec_deps->preds != NULL)
726 next = sec_deps->preds->next;
727 free (sec_deps->preds);
728 sec_deps->preds = next;
732 xtensa_set_section_deps (deps, sec, NULL);
735 free (deps->sections);
742 section_is_source (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
743 lang_statement_union_type *s)
746 const reloc_deps_section *sec_deps;
748 if (s->header.type != lang_input_section_enum)
750 sec = s->input_section.section;
752 sec_deps = xtensa_get_section_deps (deps, sec);
753 return sec_deps && sec_deps->succs != NULL;
758 section_is_target (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
759 lang_statement_union_type *s)
762 const reloc_deps_section *sec_deps;
764 if (s->header.type != lang_input_section_enum)
766 sec = s->input_section.section;
768 sec_deps = xtensa_get_section_deps (deps, sec);
769 return sec_deps && sec_deps->preds != NULL;
774 section_is_source_or_target (const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
775 lang_statement_union_type *s)
777 return (section_is_source (deps, s)
778 || section_is_target (deps, s));
782 typedef struct xtensa_ld_iter_stack_t xtensa_ld_iter_stack;
783 typedef struct xtensa_ld_iter_t xtensa_ld_iter;
785 struct xtensa_ld_iter_t
787 lang_statement_union_type *parent; /* Parent of the list. */
788 lang_statement_list_type *l; /* List that holds it. */
789 lang_statement_union_type **loc; /* Place in the list. */
792 struct xtensa_ld_iter_stack_t
794 xtensa_ld_iter iterloc; /* List that hold it. */
796 xtensa_ld_iter_stack *next; /* Next in the stack. */
797 xtensa_ld_iter_stack *prev; /* Back pointer for stack. */
802 ld_xtensa_move_section_after (xtensa_ld_iter *to, xtensa_ld_iter *current)
804 lang_statement_union_type *to_next;
805 lang_statement_union_type *current_next;
806 lang_statement_union_type **e;
809 size_t old_to_count, new_to_count;
810 size_t old_current_count, new_current_count;
817 old_to_count = ld_count_children (to->parent);
818 old_current_count = ld_count_children (current->parent);
821 to_next = *(to->loc);
822 current_next = (*current->loc)->header.next;
824 *(to->loc) = *(current->loc);
826 *(current->loc) = current_next;
827 (*(to->loc))->header.next = to_next;
829 /* reset "to" list tail */
830 for (e = &to->l->head; *e != NULL; e = &(*e)->header.next)
834 /* reset "current" list tail */
835 for (e = ¤t->l->head; *e != NULL; e = &(*e)->header.next)
837 current->l->tail = e;
840 new_to_count = ld_count_children (to->parent);
841 new_current_count = ld_count_children (current->parent);
843 ASSERT ((old_to_count + old_current_count)
844 == (new_to_count + new_current_count));
849 /* Can only be called with lang_statements that have lists. Returns
850 FALSE if the list is empty. */
853 iter_stack_empty (xtensa_ld_iter_stack **stack_p)
855 return *stack_p == NULL;
860 iter_stack_push (xtensa_ld_iter_stack **stack_p,
861 lang_statement_union_type *parent)
863 xtensa_ld_iter_stack *stack;
864 lang_statement_list_type *l = NULL;
866 switch (parent->header.type)
868 case lang_output_section_statement_enum:
869 l = &parent->output_section_statement.children;
871 case lang_wild_statement_enum:
872 l = &parent->wild_statement.children;
874 case lang_group_statement_enum:
875 l = &parent->group_statement.children;
882 /* Empty. do not push. */
883 if (l->tail == &l->head)
886 stack = xmalloc (sizeof (xtensa_ld_iter_stack));
887 memset (stack, 0, sizeof (xtensa_ld_iter_stack));
888 stack->iterloc.parent = parent;
889 stack->iterloc.l = l;
890 stack->iterloc.loc = &l->head;
892 stack->next = *stack_p;
894 if (*stack_p != NULL)
895 (*stack_p)->prev = stack;
902 iter_stack_pop (xtensa_ld_iter_stack **stack_p)
904 xtensa_ld_iter_stack *stack;
910 ASSERT (stack != NULL);
914 if (stack->next != NULL)
915 stack->next->prev = NULL;
917 *stack_p = stack->next;
922 /* This MUST be called if, during iteration, the user changes the
923 underlying structure. It will check for a NULL current and advance
927 iter_stack_update (xtensa_ld_iter_stack **stack_p)
929 if (!iter_stack_empty (stack_p)
930 && (*(*stack_p)->iterloc.loc) == NULL)
932 iter_stack_pop (stack_p);
934 while (!iter_stack_empty (stack_p)
935 && ((*(*stack_p)->iterloc.loc)->header.next == NULL))
937 iter_stack_pop (stack_p);
939 if (!iter_stack_empty (stack_p))
940 (*stack_p)->iterloc.loc = &(*(*stack_p)->iterloc.loc)->header.next;
946 iter_stack_next (xtensa_ld_iter_stack **stack_p)
948 xtensa_ld_iter_stack *stack;
949 lang_statement_union_type *current;
952 current = *stack->iterloc.loc;
953 /* If we are on the first element. */
956 switch (current->header.type)
958 case lang_output_section_statement_enum:
959 case lang_wild_statement_enum:
960 case lang_group_statement_enum:
961 /* If the list if not empty, we are done. */
962 if (iter_stack_push (stack_p, *stack->iterloc.loc))
964 /* Otherwise increment the pointer as normal. */
971 while (!iter_stack_empty (stack_p)
972 && ((*(*stack_p)->iterloc.loc)->header.next == NULL))
974 iter_stack_pop (stack_p);
976 if (!iter_stack_empty (stack_p))
977 (*stack_p)->iterloc.loc = &(*(*stack_p)->iterloc.loc)->header.next;
981 static lang_statement_union_type *
982 iter_stack_current (xtensa_ld_iter_stack **stack_p)
984 return *((*stack_p)->iterloc.loc);
988 /* The iter stack is a preorder. */
991 iter_stack_create (xtensa_ld_iter_stack **stack_p,
992 lang_statement_union_type *parent)
994 iter_stack_push (stack_p, parent);
999 iter_stack_copy_current (xtensa_ld_iter_stack **stack_p, xtensa_ld_iter *front)
1001 *front = (*stack_p)->iterloc;
1006 xtensa_colocate_literals (reloc_deps_graph *deps,
1007 lang_statement_union_type *statement)
1009 /* Keep a stack of pointers to control iteration through the contours. */
1010 xtensa_ld_iter_stack *stack = NULL;
1011 xtensa_ld_iter_stack **stack_p = &stack;
1013 xtensa_ld_iter front; /* Location where new insertion should occur. */
1014 xtensa_ld_iter *front_p = NULL;
1016 xtensa_ld_iter current; /* Location we are checking. */
1017 xtensa_ld_iter *current_p = NULL;
1018 bfd_boolean in_literals = FALSE;
1020 if (deps->count == 0)
1023 iter_stack_create (stack_p, statement);
1025 while (!iter_stack_empty (stack_p))
1027 bfd_boolean skip_increment = FALSE;
1028 lang_statement_union_type *l = iter_stack_current (stack_p);
1030 switch (l->header.type)
1032 case lang_assignment_statement_enum:
1033 /* Any assignment statement should block reordering across it. */
1035 in_literals = FALSE;
1038 case lang_input_section_enum:
1039 if (front_p == NULL)
1041 in_literals = (section_is_target (deps, l)
1042 && !section_is_source (deps, l));
1046 iter_stack_copy_current (stack_p, front_p);
1051 bfd_boolean is_target;
1052 current_p = ¤t;
1053 iter_stack_copy_current (stack_p, current_p);
1054 is_target = (section_is_target (deps, l)
1055 && !section_is_source (deps, l));
1059 iter_stack_copy_current (stack_p, front_p);
1061 in_literals = FALSE;
1067 /* Try to insert in place. */
1068 ld_xtensa_move_section_after (front_p, current_p);
1069 ld_assign_relative_paged_dot (0x100000,
1072 xtensa_use_literal_pages);
1074 /* We use this code because it's already written. */
1075 if (!ld_local_file_relocations_fit (statement, deps))
1078 ld_xtensa_move_section_after (current_p, front_p);
1079 /* Reset the literal placement. */
1080 iter_stack_copy_current (stack_p, front_p);
1084 /* Move front pointer up by one. */
1085 front_p->loc = &(*front_p->loc)->header.next;
1087 /* Do not increment the current pointer. */
1088 skip_increment = TRUE;
1098 if (!skip_increment)
1099 iter_stack_next (stack_p);
1101 /* Be careful to update the stack_p if it now is a null. */
1102 iter_stack_update (stack_p);
1105 lang_for_each_statement_worker (xtensa_ldlang_clear_addresses, statement);
1110 xtensa_move_dependencies_to_front (reloc_deps_graph *deps,
1111 lang_wild_statement_type *w)
1113 /* Keep a front pointer and a current pointer. */
1114 lang_statement_union_type **front;
1115 lang_statement_union_type **current;
1117 /* Walk to the end of the targets. */
1118 for (front = &w->children.head;
1119 (*front != NULL) && section_is_source_or_target (deps, *front);
1120 front = &(*front)->header.next)
1126 current = &(*front)->header.next;
1127 while (*current != NULL)
1129 if (section_is_source_or_target (deps, *current))
1131 /* Insert in place. */
1132 xtensa_ld_iter front_iter;
1133 xtensa_ld_iter current_iter;
1135 front_iter.parent = (lang_statement_union_type *) w;
1136 front_iter.l = &w->children;
1137 front_iter.loc = front;
1139 current_iter.parent = (lang_statement_union_type *) w;
1140 current_iter.l = &w->children;
1141 current_iter.loc = current;
1143 ld_xtensa_move_section_after (&front_iter, ¤t_iter);
1144 front = &(*front)->header.next;
1148 current = &(*current)->header.next;
1155 deps_has_sec_edge (const reloc_deps_graph *deps, asection *src, asection *tgt)
1157 const reloc_deps_section *sec_deps;
1158 const reloc_deps_e *sec_deps_e;
1160 sec_deps = xtensa_get_section_deps (deps, src);
1161 if (sec_deps == NULL)
1164 for (sec_deps_e = sec_deps->succs;
1166 sec_deps_e = sec_deps_e->next)
1168 ASSERT (sec_deps_e->src == src);
1169 if (sec_deps_e->tgt == tgt)
1177 deps_has_edge (const reloc_deps_graph *deps,
1178 lang_statement_union_type *src,
1179 lang_statement_union_type *tgt)
1181 if (!section_is_source (deps, src))
1183 if (!section_is_target (deps, tgt))
1186 if (src->header.type != lang_input_section_enum)
1188 if (tgt->header.type != lang_input_section_enum)
1191 return deps_has_sec_edge (deps, src->input_section.section,
1192 tgt->input_section.section);
1197 add_deps_edge (reloc_deps_graph *deps, asection *src_sec, asection *tgt_sec)
1199 reloc_deps_section *src_sec_deps;
1200 reloc_deps_section *tgt_sec_deps;
1202 reloc_deps_e *src_edge;
1203 reloc_deps_e *tgt_edge;
1205 if (deps_has_sec_edge (deps, src_sec, tgt_sec))
1208 src_sec_deps = xtensa_get_section_deps (deps, src_sec);
1209 if (src_sec_deps == NULL)
1211 /* Add a section. */
1212 src_sec_deps = xmalloc (sizeof (reloc_deps_section));
1213 memset (src_sec_deps, 0, sizeof (reloc_deps_section));
1214 src_sec_deps->is_only_literal = 0;
1215 src_sec_deps->preds = NULL;
1216 src_sec_deps->succs = NULL;
1217 xtensa_set_section_deps (deps, src_sec, src_sec_deps);
1218 xtensa_append_section_deps (deps, src_sec);
1221 tgt_sec_deps = xtensa_get_section_deps (deps, tgt_sec);
1222 if (tgt_sec_deps == NULL)
1224 /* Add a section. */
1225 tgt_sec_deps = xmalloc (sizeof (reloc_deps_section));
1226 memset (tgt_sec_deps, 0, sizeof (reloc_deps_section));
1227 tgt_sec_deps->is_only_literal = 0;
1228 tgt_sec_deps->preds = NULL;
1229 tgt_sec_deps->succs = NULL;
1230 xtensa_set_section_deps (deps, tgt_sec, tgt_sec_deps);
1231 xtensa_append_section_deps (deps, tgt_sec);
1234 /* Add the edges. */
1235 src_edge = xmalloc (sizeof (reloc_deps_e));
1236 memset (src_edge, 0, sizeof (reloc_deps_e));
1237 src_edge->src = src_sec;
1238 src_edge->tgt = tgt_sec;
1239 src_edge->next = src_sec_deps->succs;
1240 src_sec_deps->succs = src_edge;
1242 tgt_edge = xmalloc (sizeof (reloc_deps_e));
1243 memset (tgt_edge, 0, sizeof (reloc_deps_e));
1244 tgt_edge->src = src_sec;
1245 tgt_edge->tgt = tgt_sec;
1246 tgt_edge->next = tgt_sec_deps->preds;
1247 tgt_sec_deps->preds = tgt_edge;
1252 build_deps_graph_callback (asection *src_sec,
1253 bfd_vma src_offset ATTRIBUTE_UNUSED,
1254 asection *target_sec,
1255 bfd_vma target_offset ATTRIBUTE_UNUSED,
1258 reloc_deps_graph *deps = closure;
1260 /* If the target is defined. */
1261 if (target_sec != NULL)
1262 add_deps_edge (deps, src_sec, target_sec);
1266 static reloc_deps_graph *
1267 ld_build_required_section_dependence (lang_statement_union_type *s)
1269 reloc_deps_graph *deps;
1270 xtensa_ld_iter_stack *stack = NULL;
1272 deps = xmalloc (sizeof (reloc_deps_graph));
1273 deps->sections = NULL;
1277 for (iter_stack_create (&stack, s);
1278 !iter_stack_empty (&stack);
1279 iter_stack_next (&stack))
1281 lang_statement_union_type *l = iter_stack_current (&stack);
1283 if (l->header.type == lang_input_section_enum)
1285 lang_input_section_type *input;
1286 input = &l->input_section;
1287 xtensa_callback_required_dependence (input->section->owner,
1290 /* Use the same closure. */
1291 build_deps_graph_callback,
1299 #if EXTRA_VALIDATION
1301 ld_count_children (lang_statement_union_type *s)
1304 xtensa_ld_iter_stack *stack = NULL;
1305 for (iter_stack_create (&stack, s);
1306 !iter_stack_empty (&stack);
1307 iter_stack_next (&stack))
1309 lang_statement_union_type *l = iter_stack_current (&stack);
1315 #endif /* EXTRA_VALIDATION */
1318 /* Check if a particular section is included in the link. This will only
1319 be true for one instance of a particular linkonce section. */
1321 static bfd_boolean input_section_found = FALSE;
1322 static asection *input_section_target = NULL;
1325 input_section_linked_worker (lang_statement_union_type *statement)
1327 if ((statement->header.type == lang_input_section_enum
1328 && (statement->input_section.section == input_section_target)))
1329 input_section_found = TRUE;
1333 input_section_linked (asection *sec)
1335 input_section_found = FALSE;
1336 input_section_target = sec;
1337 lang_for_each_statement_worker (input_section_linked_worker, stat_ptr->head);
1338 return input_section_found;
1342 /* Strip out any linkonce property tables or XCC exception tables where the
1343 associated linkonce text is from a different object file. Normally,
1344 a matching set of linkonce sections is taken from the same object file,
1345 but sometimes the files are compiled differently so that some of the
1346 linkonce sections are not present in all files. Stripping the
1347 inconsistent sections like this is not completely robust -- a much
1348 better solution is to use comdat groups. */
1350 static int linkonce_len = sizeof (".gnu.linkonce.") - 1;
1353 is_inconsistent_linkonce_section (asection *sec)
1355 bfd *abfd = sec->owner;
1356 const char *sec_name = bfd_get_section_name (abfd, sec);
1359 if ((bfd_get_section_flags (abfd, sec) & SEC_LINK_ONCE) == 0
1360 || strncmp (sec_name, ".gnu.linkonce.", linkonce_len) != 0)
1363 /* Check if this is an Xtensa property section or an exception table
1364 for Tensilica's XCC compiler. */
1365 name = sec_name + linkonce_len;
1366 if (CONST_STRNEQ (name, "prop."))
1367 name = strchr (name + 5, '.') + 1;
1368 else if (name[1] == '.'
1369 && (name[0] == 'p' || name[0] == 'e' || name[0] == 'h'))
1376 char *dep_sec_name = xmalloc (strlen (sec_name) + 1);
1379 /* Get the associated linkonce text section and check if it is
1380 included in the link. If not, this section is inconsistent
1381 and should be stripped. */
1382 strcpy (dep_sec_name, ".gnu.linkonce.t.");
1383 strcat (dep_sec_name, name);
1384 dep_sec = bfd_get_section_by_name (abfd, dep_sec_name);
1385 if (dep_sec == NULL || ! input_section_linked (dep_sec))
1387 free (dep_sec_name);
1390 free (dep_sec_name);
1398 xtensa_strip_inconsistent_linkonce_sections (lang_statement_list_type *slist)
1400 lang_statement_union_type **s_p = &slist->head;
1403 lang_statement_union_type *s = *s_p;
1404 lang_statement_union_type *s_next = (*s_p)->header.next;
1406 switch (s->header.type)
1408 case lang_input_section_enum:
1409 if (is_inconsistent_linkonce_section (s->input_section.section))
1411 s->input_section.section->output_section = bfd_abs_section_ptr;
1417 case lang_constructors_statement_enum:
1418 xtensa_strip_inconsistent_linkonce_sections (&constructor_list);
1421 case lang_output_section_statement_enum:
1422 if (s->output_section_statement.children.head)
1423 xtensa_strip_inconsistent_linkonce_sections
1424 (&s->output_section_statement.children);
1427 case lang_wild_statement_enum:
1428 xtensa_strip_inconsistent_linkonce_sections
1429 (&s->wild_statement.children);
1432 case lang_group_statement_enum:
1433 xtensa_strip_inconsistent_linkonce_sections
1434 (&s->group_statement.children);
1437 case lang_data_statement_enum:
1438 case lang_reloc_statement_enum:
1439 case lang_object_symbols_statement_enum:
1440 case lang_output_statement_enum:
1441 case lang_target_statement_enum:
1442 case lang_input_statement_enum:
1443 case lang_assignment_statement_enum:
1444 case lang_padding_statement_enum:
1445 case lang_address_statement_enum:
1446 case lang_fill_statement_enum:
1454 s_p = &(*s_p)->header.next;
1457 /* Reset the tail of the list, in case the last entry was removed. */
1458 if (s_p != slist->tail)
1464 xtensa_wild_group_interleave_callback (lang_statement_union_type *statement)
1466 lang_wild_statement_type *w;
1467 reloc_deps_graph *deps;
1468 if (statement->header.type == lang_wild_statement_enum)
1470 #if EXTRA_VALIDATION
1471 size_t old_child_count;
1472 size_t new_child_count;
1474 bfd_boolean no_reorder;
1476 w = &statement->wild_statement;
1480 /* If it has 0 or 1 section bound, then do not reorder. */
1481 if (w->children.head == NULL
1482 || (w->children.head->header.type == lang_input_section_enum
1483 && w->children.head->header.next == NULL))
1486 if (w->filenames_sorted)
1489 /* Check for sorting in a section list wildcard spec as well. */
1492 struct wildcard_list *l;
1493 for (l = w->section_list; l != NULL; l = l->next)
1495 if (l->spec.sorted == TRUE)
1503 /* Special case until the NOREORDER linker directive is supported:
1504 *(.init) output sections and *(.fini) specs may NOT be reordered. */
1506 /* Check for sorting in a section list wildcard spec as well. */
1509 struct wildcard_list *l;
1510 for (l = w->section_list; l != NULL; l = l->next)
1513 && ((strcmp (".init", l->spec.name) == 0)
1514 || (strcmp (".fini", l->spec.name) == 0)))
1522 #if EXTRA_VALIDATION
1523 old_child_count = ld_count_children (statement);
1526 /* It is now officially a target. Build the graph of source
1527 section -> target section (kept as a list of edges). */
1528 deps = ld_build_required_section_dependence (statement);
1530 /* If this wildcard does not reorder.... */
1531 if (!no_reorder && deps->count != 0)
1533 /* First check for reverse dependences. Fix if possible. */
1534 xtensa_layout_wild (deps, w);
1536 xtensa_move_dependencies_to_front (deps, w);
1537 #if EXTRA_VALIDATION
1538 new_child_count = ld_count_children (statement);
1539 ASSERT (new_child_count == old_child_count);
1542 xtensa_colocate_literals (deps, statement);
1544 #if EXTRA_VALIDATION
1545 new_child_count = ld_count_children (statement);
1546 ASSERT (new_child_count == old_child_count);
1551 free_reloc_deps_graph (deps);
1557 xtensa_wild_group_interleave (lang_statement_union_type *s)
1559 lang_for_each_statement_worker (xtensa_wild_group_interleave_callback, s);
1564 xtensa_layout_wild (const reloc_deps_graph *deps, lang_wild_statement_type *w)
1566 /* If it does not fit initially, we need to do this step. Move all
1567 of the wild literal sections to a new list, then move each of
1568 them back in just before the first section they depend on. */
1569 lang_statement_union_type **s_p;
1570 #if EXTRA_VALIDATION
1571 size_t old_count, new_count;
1575 lang_wild_statement_type literal_wild;
1576 literal_wild.header.next = NULL;
1577 literal_wild.header.type = lang_wild_statement_enum;
1578 literal_wild.filename = NULL;
1579 literal_wild.filenames_sorted = FALSE;
1580 literal_wild.section_list = NULL;
1581 literal_wild.keep_sections = FALSE;
1582 literal_wild.children.head = NULL;
1583 literal_wild.children.tail = &literal_wild.children.head;
1585 #if EXTRA_VALIDATION
1586 old_count = ld_count_children ((lang_statement_union_type*) w);
1589 s_p = &w->children.head;
1590 while (*s_p != NULL)
1592 lang_statement_union_type *l = *s_p;
1593 if (l->header.type == lang_input_section_enum)
1595 if (section_is_target (deps, l)
1596 && ! section_is_source (deps, l))
1599 *s_p = l->header.next;
1601 w->children.tail = s_p;
1602 l->header.next = NULL;
1605 *literal_wild.children.tail = l;
1606 literal_wild.children.tail = &l->header.next;
1610 s_p = &(*s_p)->header.next;
1613 #if EXTRA_VALIDATION
1614 ct1 = ld_count_children ((lang_statement_union_type*) w);
1615 ct2 = ld_count_children ((lang_statement_union_type*) &literal_wild);
1617 ASSERT (old_count == (ct1 + ct2));
1620 /* Now place them back in front of their dependent sections. */
1622 while (literal_wild.children.head != NULL)
1624 lang_statement_union_type *lit = literal_wild.children.head;
1625 bfd_boolean placed = FALSE;
1627 #if EXTRA_VALIDATION
1633 literal_wild.children.head = lit->header.next;
1634 if (literal_wild.children.head == NULL)
1635 literal_wild.children.tail = &literal_wild.children.head;
1636 lit->header.next = NULL;
1638 /* Find a spot to place it. */
1639 for (s_p = &w->children.head; *s_p != NULL; s_p = &(*s_p)->header.next)
1641 lang_statement_union_type *src = *s_p;
1642 if (deps_has_edge (deps, src, lit))
1644 /* Place it here. */
1645 lit->header.next = *s_p;
1654 /* Put it at the end. */
1655 *w->children.tail = lit;
1656 w->children.tail = &lit->header.next;
1660 #if EXTRA_VALIDATION
1661 new_count = ld_count_children ((lang_statement_union_type*) w);
1662 ASSERT (new_count == old_count);
1668 xtensa_colocate_output_literals_callback (lang_statement_union_type *statement)
1670 reloc_deps_graph *deps;
1671 if (statement->header.type == lang_output_section_statement_enum)
1673 /* Now, we walk over the contours of the output section statement.
1675 First we build the literal section dependences as before.
1677 At the first uniquely_literal section, we mark it as a good
1678 spot to place other literals. Continue walking (and counting
1679 sizes) until we find the next literal section. If this
1680 section can be moved to the first one, then we move it. If
1681 we every find a modification of ".", start over. If we find
1682 a labeling of the current location, start over. Finally, at
1683 the end, if we require page alignment, add page alignments. */
1685 #if EXTRA_VALIDATION
1686 size_t old_child_count;
1687 size_t new_child_count;
1689 bfd_boolean no_reorder = FALSE;
1691 #if EXTRA_VALIDATION
1692 old_child_count = ld_count_children (statement);
1695 /* It is now officially a target. Build the graph of source
1696 section -> target section (kept as a list of edges). */
1698 deps = ld_build_required_section_dependence (statement);
1700 /* If this wildcard does not reorder.... */
1703 /* First check for reverse dependences. Fix if possible. */
1704 xtensa_colocate_literals (deps, statement);
1706 #if EXTRA_VALIDATION
1707 new_child_count = ld_count_children (statement);
1708 ASSERT (new_child_count == old_child_count);
1712 /* Insert align/offset assignment statement. */
1713 if (xtensa_use_literal_pages)
1715 ld_xtensa_insert_page_offsets (0, statement, deps,
1716 xtensa_use_literal_pages);
1717 lang_for_each_statement_worker (xtensa_ldlang_clear_addresses,
1722 free_reloc_deps_graph (deps);
1728 xtensa_colocate_output_literals (lang_statement_union_type *s)
1730 lang_for_each_statement_worker (xtensa_colocate_output_literals_callback, s);
1735 xtensa_ldlang_clear_addresses (lang_statement_union_type *statement)
1737 switch (statement->header.type)
1739 case lang_input_section_enum:
1741 asection *bfd_section = statement->input_section.section;
1742 bfd_section->output_offset = 0;
1752 ld_assign_relative_paged_dot (bfd_vma dot,
1753 lang_statement_union_type *s,
1754 const reloc_deps_graph *deps ATTRIBUTE_UNUSED,
1755 bfd_boolean lit_align)
1757 /* Walk through all of the input statements in this wild statement
1758 assign dot to all of them. */
1760 xtensa_ld_iter_stack *stack = NULL;
1761 xtensa_ld_iter_stack **stack_p = &stack;
1763 bfd_boolean first_section = FALSE;
1764 bfd_boolean in_literals = FALSE;
1766 for (iter_stack_create (stack_p, s);
1767 !iter_stack_empty (stack_p);
1768 iter_stack_next (stack_p))
1770 lang_statement_union_type *l = iter_stack_current (stack_p);
1772 switch (l->header.type)
1774 case lang_input_section_enum:
1776 asection *section = l->input_section.section;
1777 size_t align_pow = section->alignment_power;
1778 bfd_boolean do_xtensa_alignment = FALSE;
1782 bfd_boolean sec_is_target = section_is_target (deps, l);
1783 bfd_boolean sec_is_source = section_is_source (deps, l);
1785 if (section->size != 0
1787 || (in_literals && !sec_is_target)
1788 || (!in_literals && sec_is_target)))
1790 do_xtensa_alignment = TRUE;
1792 first_section = FALSE;
1793 if (section->size != 0)
1794 in_literals = (sec_is_target && !sec_is_source);
1797 if (do_xtensa_alignment && xtensa_page_power != 0)
1798 dot += (1 << xtensa_page_power);
1800 dot = align_power (dot, align_pow);
1801 section->output_offset = dot;
1802 dot += section->size;
1805 case lang_fill_statement_enum:
1806 dot += l->fill_statement.size;
1808 case lang_padding_statement_enum:
1809 dot += l->padding_statement.size;
1820 ld_local_file_relocations_fit (lang_statement_union_type *statement,
1821 const reloc_deps_graph *deps ATTRIBUTE_UNUSED)
1823 /* Walk over all of the dependencies that we identified and make
1824 sure that IF the source and target are here (addr != 0):
1825 1) target addr < source addr
1826 2) (roundup(source + source_size, 4) - rounddown(target, 4))
1827 < (256K - (1 << bad align))
1828 Need a worst-case proof.... */
1830 xtensa_ld_iter_stack *stack = NULL;
1831 xtensa_ld_iter_stack **stack_p = &stack;
1832 size_t max_align_power = 0;
1833 size_t align_penalty = 256;
1837 /* Find the worst-case alignment requirement for this set of statements. */
1838 for (iter_stack_create (stack_p, statement);
1839 !iter_stack_empty (stack_p);
1840 iter_stack_next (stack_p))
1842 lang_statement_union_type *l = iter_stack_current (stack_p);
1843 if (l->header.type == lang_input_section_enum)
1845 lang_input_section_type *input = &l->input_section;
1846 asection *section = input->section;
1847 if (section->alignment_power > max_align_power)
1848 max_align_power = section->alignment_power;
1852 /* Now check that everything fits. */
1853 for (i = 0; i < deps->count; i++)
1855 asection *sec = deps->sections[i];
1856 const reloc_deps_section *deps_section =
1857 xtensa_get_section_deps (deps, sec);
1860 /* We choose to walk through the successors. */
1861 for (e = deps_section->succs; e != NULL; e = e->next)
1863 if (e->src != e->tgt
1864 && e->src->output_section == e->tgt->output_section
1865 && e->src->output_offset != 0
1866 && e->tgt->output_offset != 0)
1869 align_power (e->src->output_offset + e->src->size, 2);
1870 bfd_vma target_addr = e->tgt->output_offset & ~3;
1871 if (l32r_addr < target_addr)
1873 fprintf (stderr, "Warning: "
1874 "l32r target section before l32r\n");
1878 if (l32r_addr - target_addr > 256 * 1024 - align_penalty)
1890 ld_xtensa_insert_page_offsets (bfd_vma dot,
1891 lang_statement_union_type *s,
1892 reloc_deps_graph *deps,
1893 bfd_boolean lit_align)
1895 xtensa_ld_iter_stack *stack = NULL;
1896 xtensa_ld_iter_stack **stack_p = &stack;
1898 bfd_boolean first_section = FALSE;
1899 bfd_boolean in_literals = FALSE;
1904 for (iter_stack_create (stack_p, s);
1905 !iter_stack_empty (stack_p);
1906 iter_stack_next (stack_p))
1908 lang_statement_union_type *l = iter_stack_current (stack_p);
1910 switch (l->header.type)
1912 case lang_input_section_enum:
1914 asection *section = l->input_section.section;
1915 bfd_boolean do_xtensa_alignment = FALSE;
1919 if (section->size != 0
1921 || (in_literals && !section_is_target (deps, l))
1922 || (!in_literals && section_is_target (deps, l))))
1924 do_xtensa_alignment = TRUE;
1926 first_section = FALSE;
1927 if (section->size != 0)
1929 in_literals = (section_is_target (deps, l)
1930 && !section_is_source (deps, l));
1934 if (do_xtensa_alignment && xtensa_page_power != 0)
1936 /* Create an expression that increments the current address,
1937 i.e., "dot", by (1 << xtensa_align_power). */
1938 etree_type *name_op = exp_nameop (NAME, ".");
1939 etree_type *addend_op = exp_intop (1 << xtensa_page_power);
1940 etree_type *add_op = exp_binop ('+', name_op, addend_op);
1941 etree_type *assign_op = exp_assop ('=', ".", add_op);
1943 lang_assignment_statement_type *assign_stmt;
1944 lang_statement_union_type *assign_union;
1945 lang_statement_list_type tmplist;
1947 /* There is hidden state in "lang_add_assignment". It
1948 appends the new assignment statement to the stat_ptr
1949 list. Thus, we swap it before and after the call. */
1951 lang_list_init (&tmplist);
1952 push_stat_ptr (&tmplist);
1953 /* Warning: side effect; statement appended to stat_ptr. */
1954 assign_stmt = lang_add_assignment (assign_op);
1955 assign_union = (lang_statement_union_type *) assign_stmt;
1958 assign_union->header.next = l;
1959 *(*stack_p)->iterloc.loc = assign_union;
1960 iter_stack_next (stack_p);
1973 # Define some shell vars to insert bits of code into the standard ELF
1974 # parse_args and list_options functions.
1976 PARSE_AND_LIST_PROLOGUE='
1977 #define OPTION_OPT_SIZEOPT (300)
1978 #define OPTION_LITERAL_MOVEMENT (OPTION_OPT_SIZEOPT + 1)
1979 #define OPTION_NO_LITERAL_MOVEMENT (OPTION_LITERAL_MOVEMENT + 1)
1980 extern int elf32xtensa_size_opt;
1981 extern int elf32xtensa_no_literal_movement;
1984 PARSE_AND_LIST_LONGOPTS='
1985 { "size-opt", no_argument, NULL, OPTION_OPT_SIZEOPT},
1986 { "literal-movement", no_argument, NULL, OPTION_LITERAL_MOVEMENT},
1987 { "no-literal-movement", no_argument, NULL, OPTION_NO_LITERAL_MOVEMENT},
1990 PARSE_AND_LIST_OPTIONS='
1992 --size-opt When relaxing longcalls, prefer size\n\
1993 optimization over branch target alignment\n"));
1996 PARSE_AND_LIST_ARGS_CASES='
1997 case OPTION_OPT_SIZEOPT:
1998 elf32xtensa_size_opt = 1;
2000 case OPTION_LITERAL_MOVEMENT:
2001 elf32xtensa_no_literal_movement = 0;
2003 case OPTION_NO_LITERAL_MOVEMENT:
2004 elf32xtensa_no_literal_movement = 1;
2008 # Replace some of the standard ELF functions with our own versions.
2010 LDEMUL_BEFORE_PARSE=elf_xtensa_before_parse
2011 LDEMUL_AFTER_OPEN=elf_xtensa_after_open
2012 LDEMUL_CHOOSE_TARGET=elf_xtensa_choose_target
2013 LDEMUL_BEFORE_ALLOCATION=elf_xtensa_before_allocation