1 # This shell script emits a C file. -*- C -*-
2 # Copyright 2002, 2003 Free Software Foundation, Inc.
3 # Written by Mitch Lichtenberg <mpl@broadcom.com> and
4 # Chris Demetriou <cgd@broadcom.com> based on m68kelf.em and mipsecoff.em.
6 # This file is part of GLD, the Gnu Linker.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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.
30 echo "#define SUPPORT_EMBEDDED_RELOCS" >>e${EMULATION_NAME}.c
34 cat >>e${EMULATION_NAME}.c <<EOF
36 #ifdef SUPPORT_EMBEDDED_RELOCS
37 static void mips_elf${ELFSIZE}_check_sections (bfd *, asection *, void *);
40 /* This function is run after all the input files have been opened. */
43 mips_elf${ELFSIZE}_after_open (void)
45 /* Call the standard elf routine. */
46 gld${EMULATION_NAME}_after_open ();
48 #ifdef SUPPORT_EMBEDDED_RELOCS
49 if (command_line.embedded_relocs && (! link_info.relocatable))
53 /* In the embedded relocs mode we create a .rel.sdata section for
54 each input file with a .sdata section which has has
55 relocations. The BFD backend will fill in these sections
56 with magic numbers which can be used to relocate the data
57 section at run time. */
58 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
62 /* As first-order business, make sure that each input BFD is
63 ELF. We need to call a special BFD backend function to
64 generate the embedded relocs, and we have that function
67 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
68 einfo ("%F%B: all input objects must be ELF for --embedded-relocs\n");
70 if (bfd_get_arch_size (abfd) != ${ELFSIZE})
71 einfo ("%F%B: all input objects must be ${ELFSIZE}-bit ELF for --embedded-relocs\n");
73 datasec = bfd_get_section_by_name (abfd, ".sdata");
75 /* Note that we assume that the reloc_count field has already
76 been set up. We could call bfd_get_reloc_upper_bound, but
77 that returns the size of a memory buffer rather than a reloc
78 count. We do not want to call bfd_canonicalize_reloc,
79 because although it would always work it would force us to
80 read in the relocs into BFD canonical form, which would waste
81 a significant amount of time and memory. */
83 if (datasec != NULL && datasec->reloc_count > 0)
87 relsec = bfd_make_section (abfd, ".rel.sdata");
89 || ! bfd_set_section_flags (abfd, relsec,
94 || ! bfd_set_section_alignment (abfd, relsec,
95 (${ELFSIZE} == 32) ? 2 : 3)
96 || ! bfd_set_section_size (abfd, relsec,
98 * ((${ELFSIZE} / 8) + 8)))
99 einfo ("%F%B: cannot create .rel.sdata section: %E\n");
102 /* Double check that all other data sections have no relocs,
103 as is required for embedded PIC code. */
104 bfd_map_over_sections (abfd, mips_elf${ELFSIZE}_check_sections,
108 #endif /* SUPPORT_EMBEDDED_RELOCS */
111 #ifdef SUPPORT_EMBEDDED_RELOCS
112 /* Check that of the data sections, only the .sdata section has
113 relocs. This is called via bfd_map_over_sections. */
116 mips_elf${ELFSIZE}_check_sections (bfd *abfd, asection *sec, void *sdatasec)
118 if ((bfd_get_section_flags (abfd, sec) & SEC_DATA)
120 && sec->reloc_count != 0)
121 einfo ("%B%X: section %s has relocs; cannot use --embedded-relocs\n",
122 abfd, bfd_get_section_name (abfd, sec));
124 #endif /* SUPPORT_EMBEDDED_RELOCS */
126 /* This function is called after the section sizes and offsets have
127 been set. If we are generating embedded relocs, it calls a special
128 BFD backend routine to do the work. */
131 mips_elf${ELFSIZE}_after_allocation (void)
133 /* Call the standard elf routine. */
134 after_allocation_default ();
136 #ifdef SUPPORT_EMBEDDED_RELOCS
137 if (command_line.embedded_relocs && (! link_info.relocatable))
141 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
143 asection *datasec, *relsec;
146 datasec = bfd_get_section_by_name (abfd, ".sdata");
148 if (datasec == NULL || datasec->reloc_count == 0)
151 relsec = bfd_get_section_by_name (abfd, ".rel.sdata");
152 ASSERT (relsec != NULL);
154 if (! bfd_mips_elf${ELFSIZE}_create_embedded_relocs (abfd,
161 einfo ("%B%X: can not create runtime reloc information: %E\n",
164 einfo ("%X%B: can not create runtime reloc information: %s\n",
169 #endif /* SUPPORT_EMBEDDED_RELOCS */
174 # We have our own after_open and after_allocation functions, but they call
175 # the standard routines, so give them a different name.
176 LDEMUL_AFTER_OPEN=mips_elf${ELFSIZE}_after_open
177 LDEMUL_AFTER_ALLOCATION=mips_elf${ELFSIZE}_after_allocation