1 /* This file is is generated by a shell script. DO NOT EDIT! */
3 /* Handle embedded relocs for MIPS.
4 Copyright 1994, 2000 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"
39 static void gldmipsidt_before_parse
PARAMS ((void));
40 static void gldmipsidt_after_open
PARAMS ((void));
41 static void check_sections
PARAMS ((bfd
*, asection
*, PTR
));
42 static void gldmipsidt_after_allocation
PARAMS ((void));
43 static char *gldmipsidt_get_script
PARAMS ((int *isfile
));
46 gldmipsidt_before_parse()
48 #ifndef TARGET_ /* I.e., if not generic. */
49 ldfile_output_architecture
= bfd_arch_mips
;
50 #endif /* not TARGET_ */
53 /* This function is run after all the input files have been opened.
54 We create a .rel.sdata section for each input file with a non zero
55 .sdata section. The BFD backend will fill in these sections with
56 magic numbers which can be used to relocate the data section at run
57 time. This will only do the right thing if all the input files
58 have been compiled using -membedded-pic. */
61 gldmipsidt_after_open ()
65 if (! command_line
.embedded_relocs
66 || link_info
.relocateable
)
69 for (abfd
= link_info
.input_bfds
; abfd
!= NULL
; abfd
= abfd
->link_next
)
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. */
82 if (datasec
!= NULL
&& datasec
->reloc_count
> 0)
86 relsec
= bfd_make_section (abfd
, ".rel.sdata");
88 || ! bfd_set_section_flags (abfd
, relsec
,
93 || ! bfd_set_section_alignment (abfd
, relsec
, 2)
94 || ! bfd_set_section_size (abfd
, relsec
,
95 datasec
->reloc_count
* 4))
96 einfo (_("%F%B: can not create .rel.sdata section: %E\n"));
99 /* Double check that all other data sections are empty, as is
100 required for embedded PIC code. */
101 bfd_map_over_sections (abfd
, check_sections
, (PTR
) datasec
);
105 /* Check that of the data sections, only the .sdata section has
106 relocs. This is called via bfd_map_over_sections. */
109 check_sections (abfd
, sec
, sdatasec
)
114 if ((bfd_get_section_flags (abfd
, sec
) & SEC_CODE
) == 0
115 && sec
!= (asection
*) sdatasec
116 && sec
->reloc_count
!= 0)
117 einfo (_("%F%X: section %s has relocs; can not use --embedded-relocs\n"),
118 abfd
, bfd_get_section_name (abfd
, sec
));
121 /* This function is called after the section sizes and offsets have
122 been set. If we are generating embedded relocs, it calls a special
123 BFD backend routine to do the work. */
126 gldmipsidt_after_allocation ()
130 if (! command_line
.embedded_relocs
131 || link_info
.relocateable
)
134 for (abfd
= link_info
.input_bfds
; abfd
!= NULL
; abfd
= abfd
->link_next
)
136 asection
*datasec
, *relsec
;
139 datasec
= bfd_get_section_by_name (abfd
, ".sdata");
141 if (datasec
== NULL
|| datasec
->reloc_count
== 0)
144 relsec
= bfd_get_section_by_name (abfd
, ".rel.sdata");
145 ASSERT (relsec
!= NULL
);
147 if (! bfd_mips_ecoff_create_embedded_relocs (abfd
, &link_info
,
152 einfo (_("%B%X: can not create runtime reloc information: %E\n"),
155 einfo (_("%X%B: can not create runtime reloc information: %s\n"),
162 gldmipsidt_get_script(isfile
)
167 if (link_info
.relocateable
== true && config
.build_constructors
== true)
170 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
171 \"ecoff-littlemips\")\n\
172 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
211 ; else if (link_info
.relocateable
== true) return
212 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
213 \"ecoff-littlemips\")\n\
214 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
252 ; else if (!config
.text_read_only
) return
254 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
255 \"ecoff-littlemips\")\n\
256 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
266 PROVIDE (__runtime_reloc_start = .);\n\
268 PROVIDE (__runtime_reloc_stop = .);\n\
277 _fdata = ALIGN(16);\n\
282 _gp = ALIGN(16) + 0x8000;\n\
307 ; else if (!config
.magic_demand_paged
) return
309 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
310 \"ecoff-littlemips\")\n\
311 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
321 PROVIDE (__runtime_reloc_start = .);\n\
323 PROVIDE (__runtime_reloc_stop = .);\n\
332 _fdata = ALIGN(16);\n\
337 _gp = ALIGN(16) + 0x8000;\n\
364 "OUTPUT_FORMAT(\"ecoff-bigmips\", \"ecoff-bigmips\",\n\
365 \"ecoff-littlemips\")\n\
366 SEARCH_DIR(/usr/local/mips-idt-ecoff/lib);\n\
376 PROVIDE (__runtime_reloc_start = .);\n\
378 PROVIDE (__runtime_reloc_stop = .);\n\
387 _fdata = ALIGN(16);\n\
392 _gp = ALIGN(16) + 0x8000;\n\
419 struct ld_emulation_xfer_struct ld_mipsidt_emulation
=
421 gldmipsidt_before_parse
,
425 gldmipsidt_after_open
,
426 gldmipsidt_after_allocation
,
427 set_output_arch_default
,
428 ldemul_default_target
,
429 before_allocation_default
,
430 gldmipsidt_get_script
,