1 /* This file is is generated by a shell script. DO NOT EDIT! */
3 /* Handle embedded relocs for MIPS.
4 Copyright 1994 Free Software Foundation, Inc.
5 Written by Ian Lance Taylor <ian@cygnus.com> based on generic.em.
7 This file is part of GLD, the Gnu Linker.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #define TARGET_IS_mipsidt
25 #include "libiberty.h"
36 static void gldmipsidt_before_parse
PARAMS ((void));
37 static void gldmipsidt_after_open
PARAMS ((void));
38 static void check_sections
PARAMS ((bfd
*, asection
*, PTR
));
39 static void gldmipsidt_after_allocation
PARAMS ((void));
40 static char *gldmipsidt_get_script
PARAMS ((int *isfile
));
43 gldmipsidt_before_parse()
45 #ifndef TARGET_ /* I.e., if not generic. */
46 ldfile_output_architecture
= bfd_arch_mips
;
47 #endif /* not TARGET_ */
50 /* This function is run after all the input files have been opened.
51 We create a .rel.sdata section for each input file with a non zero
52 .sdata section. The BFD backend will fill in these sections with
53 magic numbers which can be used to relocate the data section at run
54 time. This will only do the right thing if all the input files
55 have been compiled using -membedded-pic. */
58 gldmipsidt_after_open ()
62 if (! command_line
.embedded_relocs
63 || link_info
.relocateable
)
66 for (abfd
= link_info
.input_bfds
; abfd
!= NULL
; abfd
= abfd
->link_next
)
70 datasec
= bfd_get_section_by_name (abfd
, ".sdata");
72 /* Note that we assume that the reloc_count field has already
73 been set up. We could call bfd_get_reloc_upper_bound, but
74 that returns the size of a memory buffer rather than a reloc
75 count. We do not want to call bfd_canonicalize_reloc,
76 because although it would always work it would force us to
77 read in the relocs into BFD canonical form, which would waste
78 a significant amount of time and memory. */
79 if (datasec
!= NULL
&& datasec
->reloc_count
> 0)
83 relsec
= bfd_make_section (abfd
, ".rel.sdata");
85 || ! bfd_set_section_flags (abfd
, relsec
,
90 || ! bfd_set_section_alignment (abfd
, relsec
, 2)
91 || ! bfd_set_section_size (abfd
, relsec
,
92 datasec
->reloc_count
* 4))
93 einfo (_("%F%B: can not create .rel.sdata section: %E\n"));
96 /* Double check that all other data sections are empty, as is
97 required for embedded PIC code. */
98 bfd_map_over_sections (abfd
, check_sections
, (PTR
) datasec
);
102 /* Check that of the data sections, only the .sdata section has
103 relocs. This is called via bfd_map_over_sections. */
106 check_sections (abfd
, sec
, sdatasec
)
111 if ((bfd_get_section_flags (abfd
, sec
) & SEC_CODE
) == 0
112 && sec
!= (asection
*) sdatasec
113 && sec
->reloc_count
!= 0)
114 einfo (_("%F%X: section %s has relocs; can not use --embedded-relocs\n"),
115 abfd
, bfd_get_section_name (abfd
, sec
));
118 /* This function is called after the section sizes and offsets have
119 been set. If we are generating embedded relocs, it calls a special
120 BFD backend routine to do the work. */
123 gldmipsidt_after_allocation ()
127 if (! command_line
.embedded_relocs
128 || link_info
.relocateable
)
131 for (abfd
= link_info
.input_bfds
; abfd
!= NULL
; abfd
= abfd
->link_next
)
133 asection
*datasec
, *relsec
;
136 datasec
= bfd_get_section_by_name (abfd
, ".sdata");
138 if (datasec
== NULL
|| datasec
->reloc_count
== 0)
141 relsec
= bfd_get_section_by_name (abfd
, ".rel.sdata");
142 ASSERT (relsec
!= NULL
);
144 if (! bfd_mips_ecoff_create_embedded_relocs (abfd
, &link_info
,
149 einfo (_("%B%X: can not create runtime reloc information: %E\n"),
152 einfo (_("%X%B: can not create runtime reloc information: %s\n"),
159 gldmipsidt_get_script(isfile
)
164 if (link_info
.relocateable
== true && config
.build_constructors
== true)
167 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
168 \"ecoff-littlemips\")\n\
169 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
208 ; else if (link_info
.relocateable
== true) return
209 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
210 \"ecoff-littlemips\")\n\
211 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
249 ; else if (!config
.text_read_only
) return
251 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
252 \"ecoff-littlemips\")\n\
253 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
263 PROVIDE (__runtime_reloc_start = .);\n\
265 PROVIDE (__runtime_reloc_stop = .);\n\
274 _fdata = ALIGN(16);\n\
279 _gp = ALIGN(16) + 0x8000;\n\
304 ; else if (!config
.magic_demand_paged
) return
306 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
307 \"ecoff-littlemips\")\n\
308 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
318 PROVIDE (__runtime_reloc_start = .);\n\
320 PROVIDE (__runtime_reloc_stop = .);\n\
329 _fdata = ALIGN(16);\n\
334 _gp = ALIGN(16) + 0x8000;\n\
361 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
362 \"ecoff-littlemips\")\n\
363 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
373 PROVIDE (__runtime_reloc_start = .);\n\
375 PROVIDE (__runtime_reloc_stop = .);\n\
384 _fdata = ALIGN(16);\n\
389 _gp = ALIGN(16) + 0x8000;\n\
416 struct ld_emulation_xfer_struct ld_mipsidt_emulation
=
418 gldmipsidt_before_parse
,
422 gldmipsidt_after_open
,
423 gldmipsidt_after_allocation
,
424 set_output_arch_default
,
425 ldemul_default_target
,
426 before_allocation_default
,
427 gldmipsidt_get_script
,