| 1 | # Copyright 2002 Free Software Foundation, Inc.
|
|---|
| 2 | # Written by Mitch Lichtenberg <mpl@broadcom.com> and
|
|---|
| 3 | # Chris Demetriou <cgd@broadcom.com> based on m68kelf.em and mipsecoff.em.
|
|---|
| 4 | #
|
|---|
| 5 | # This file is part of GLD, the Gnu Linker.
|
|---|
| 6 | #
|
|---|
| 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 2 of the License, or
|
|---|
| 10 | # (at your option) any later version.
|
|---|
| 11 | #
|
|---|
| 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.
|
|---|
| 16 | #
|
|---|
| 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|---|
| 20 | # This shell script emits a C file. -*- C -*-
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 | # This file is sourced from elf32.em, and defines some extra routines for m68k
|
|---|
| 24 | # embedded systems using ELF and for some other systems using m68k ELF. While
|
|---|
| 25 | # it is sourced from elf32.em for all m68k ELF configurations, here we include
|
|---|
| 26 | # only the features we want depending on the configuration.
|
|---|
| 27 |
|
|---|
| 28 | case ${target} in
|
|---|
| 29 | mips*-*-elf)
|
|---|
| 30 | echo "#define SUPPORT_EMBEDDED_RELOCS" >>e${EMULATION_NAME}.c
|
|---|
| 31 | ;;
|
|---|
| 32 | esac
|
|---|
| 33 |
|
|---|
| 34 | cat >>e${EMULATION_NAME}.c <<EOF
|
|---|
| 35 |
|
|---|
| 36 | static void mips_elf${ELFSIZE}_after_open PARAMS ((void));
|
|---|
| 37 | #ifdef SUPPORT_EMBEDDED_RELOCS
|
|---|
| 38 | static void mips_elf${ELFSIZE}_check_sections PARAMS ((bfd *, asection *,
|
|---|
| 39 | PTR));
|
|---|
| 40 | #endif
|
|---|
| 41 | static void mips_elf${ELFSIZE}_after_allocation PARAMS ((void));
|
|---|
| 42 |
|
|---|
| 43 | /* This function is run after all the input files have been opened. */
|
|---|
| 44 |
|
|---|
| 45 | static void
|
|---|
| 46 | mips_elf${ELFSIZE}_after_open()
|
|---|
| 47 | {
|
|---|
| 48 | /* Call the standard elf routine. */
|
|---|
| 49 | gld${EMULATION_NAME}_after_open ();
|
|---|
| 50 |
|
|---|
| 51 | #ifdef SUPPORT_EMBEDDED_RELOCS
|
|---|
| 52 | if (command_line.embedded_relocs && (! link_info.relocateable))
|
|---|
| 53 | {
|
|---|
| 54 | bfd *abfd;
|
|---|
| 55 |
|
|---|
| 56 | /* In the embedded relocs mode we create a .rel.sdata section for
|
|---|
| 57 | each input file with a .sdata section which has has
|
|---|
| 58 | relocations. The BFD backend will fill in these sections
|
|---|
| 59 | with magic numbers which can be used to relocate the data
|
|---|
| 60 | section at run time. */
|
|---|
| 61 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
|
|---|
| 62 | {
|
|---|
| 63 | asection *datasec;
|
|---|
| 64 |
|
|---|
| 65 | /* As first-order business, make sure that each input BFD is
|
|---|
| 66 | ELF. We need to call a special BFD backend function to
|
|---|
| 67 | generate the embedded relocs, and we have that function
|
|---|
| 68 | only for ELF */
|
|---|
| 69 |
|
|---|
| 70 | if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
|
|---|
| 71 | einfo ("%F%B: all input objects must be ELF for --embedded-relocs\n");
|
|---|
| 72 |
|
|---|
| 73 | if (bfd_get_arch_size (abfd) != ${ELFSIZE})
|
|---|
| 74 | einfo ("%F%B: all input objects must be ${ELFSIZE}-bit ELF for --embedded-relocs\n");
|
|---|
| 75 |
|
|---|
| 76 | datasec = bfd_get_section_by_name (abfd, ".sdata");
|
|---|
| 77 |
|
|---|
| 78 | /* Note that we assume that the reloc_count field has already
|
|---|
| 79 | been set up. We could call bfd_get_reloc_upper_bound, but
|
|---|
| 80 | that returns the size of a memory buffer rather than a reloc
|
|---|
| 81 | count. We do not want to call bfd_canonicalize_reloc,
|
|---|
| 82 | because although it would always work it would force us to
|
|---|
| 83 | read in the relocs into BFD canonical form, which would waste
|
|---|
| 84 | a significant amount of time and memory. */
|
|---|
| 85 |
|
|---|
| 86 | if (datasec != NULL && datasec->reloc_count > 0)
|
|---|
| 87 | {
|
|---|
| 88 | asection *relsec;
|
|---|
| 89 |
|
|---|
| 90 | relsec = bfd_make_section (abfd, ".rel.sdata");
|
|---|
| 91 | if (relsec == NULL
|
|---|
| 92 | || ! bfd_set_section_flags (abfd, relsec,
|
|---|
| 93 | (SEC_ALLOC
|
|---|
| 94 | | SEC_LOAD
|
|---|
| 95 | | SEC_HAS_CONTENTS
|
|---|
| 96 | | SEC_IN_MEMORY))
|
|---|
| 97 | || ! bfd_set_section_alignment (abfd, relsec,
|
|---|
| 98 | (${ELFSIZE} == 32) ? 2 : 3)
|
|---|
| 99 | || ! bfd_set_section_size (abfd, relsec,
|
|---|
| 100 | datasec->reloc_count
|
|---|
| 101 | * ((${ELFSIZE} / 8) + 8)))
|
|---|
| 102 | einfo ("%F%B: cannot create .rel.sdata section: %E\n");
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | /* Double check that all other data sections have no relocs,
|
|---|
| 106 | as is required for embedded PIC code. */
|
|---|
| 107 | bfd_map_over_sections (abfd, mips_elf${ELFSIZE}_check_sections,
|
|---|
| 108 | (PTR) datasec);
|
|---|
| 109 | }
|
|---|
| 110 | }
|
|---|
| 111 | #endif /* SUPPORT_EMBEDDED_RELOCS */
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | #ifdef SUPPORT_EMBEDDED_RELOCS
|
|---|
| 115 | /* Check that of the data sections, only the .sdata section has
|
|---|
| 116 | relocs. This is called via bfd_map_over_sections. */
|
|---|
| 117 |
|
|---|
| 118 | static void
|
|---|
| 119 | mips_elf${ELFSIZE}_check_sections (abfd, sec, sdatasec)
|
|---|
| 120 | bfd *abfd;
|
|---|
| 121 | asection *sec;
|
|---|
| 122 | PTR sdatasec;
|
|---|
| 123 | {
|
|---|
| 124 | if ((bfd_get_section_flags (abfd, sec) & SEC_DATA)
|
|---|
| 125 | && sec != (asection *) sdatasec
|
|---|
| 126 | && sec->reloc_count != 0)
|
|---|
| 127 | einfo ("%B%X: section %s has relocs; cannot use --embedded-relocs\n",
|
|---|
| 128 | abfd, bfd_get_section_name (abfd, sec));
|
|---|
| 129 | }
|
|---|
| 130 | #endif /* SUPPORT_EMBEDDED_RELOCS */
|
|---|
| 131 |
|
|---|
| 132 | /* This function is called after the section sizes and offsets have
|
|---|
| 133 | been set. If we are generating embedded relocs, it calls a special
|
|---|
| 134 | BFD backend routine to do the work. */
|
|---|
| 135 |
|
|---|
| 136 | static void
|
|---|
| 137 | mips_elf${ELFSIZE}_after_allocation ()
|
|---|
| 138 | {
|
|---|
| 139 | /* Call the standard elf routine. */
|
|---|
| 140 | after_allocation_default ();
|
|---|
| 141 |
|
|---|
| 142 | #ifdef SUPPORT_EMBEDDED_RELOCS
|
|---|
| 143 | if (command_line.embedded_relocs && (! link_info.relocateable))
|
|---|
| 144 | {
|
|---|
| 145 | bfd *abfd;
|
|---|
| 146 |
|
|---|
| 147 | for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
|
|---|
| 148 | {
|
|---|
| 149 | asection *datasec, *relsec;
|
|---|
| 150 | char *errmsg;
|
|---|
| 151 |
|
|---|
| 152 | datasec = bfd_get_section_by_name (abfd, ".sdata");
|
|---|
| 153 |
|
|---|
| 154 | if (datasec == NULL || datasec->reloc_count == 0)
|
|---|
| 155 | continue;
|
|---|
| 156 |
|
|---|
| 157 | relsec = bfd_get_section_by_name (abfd, ".rel.sdata");
|
|---|
| 158 | ASSERT (relsec != NULL);
|
|---|
| 159 |
|
|---|
| 160 | if (! bfd_mips_elf${ELFSIZE}_create_embedded_relocs (abfd,
|
|---|
| 161 | &link_info,
|
|---|
| 162 | datasec,
|
|---|
| 163 | relsec,
|
|---|
| 164 | &errmsg))
|
|---|
| 165 | {
|
|---|
| 166 | if (errmsg == NULL)
|
|---|
| 167 | einfo ("%B%X: can not create runtime reloc information: %E\n",
|
|---|
| 168 | abfd);
|
|---|
| 169 | else
|
|---|
| 170 | einfo ("%X%B: can not create runtime reloc information: %s\n",
|
|---|
| 171 | abfd, errmsg);
|
|---|
| 172 | }
|
|---|
| 173 | }
|
|---|
| 174 | }
|
|---|
| 175 | #endif /* SUPPORT_EMBEDDED_RELOCS */
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | EOF
|
|---|
| 179 |
|
|---|
| 180 | # We have our own after_open and after_allocation functions, but they call
|
|---|
| 181 | # the standard routines, so give them a different name.
|
|---|
| 182 | LDEMUL_AFTER_OPEN=mips_elf${ELFSIZE}_after_open
|
|---|
| 183 | LDEMUL_AFTER_ALLOCATION=mips_elf${ELFSIZE}_after_allocation
|
|---|