]>
Commit | Line | Data |
---|---|---|
800eeca4 | 1 | /* IA-64 support for 64-bit ELF |
01e1a5bc NC |
2 | Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
3 | 2009 Free Software Foundation, Inc. | |
800eeca4 JW |
4 | Contributed by David Mosberger-Tang <[email protected]> |
5 | ||
5e8d7549 | 6 | This file is part of BFD, the Binary File Descriptor library. |
800eeca4 | 7 | |
5e8d7549 NC |
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 | |
cd123cb7 | 10 | the Free Software Foundation; either version 3 of the License, or |
5e8d7549 | 11 | (at your option) any later version. |
800eeca4 | 12 | |
5e8d7549 NC |
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. | |
800eeca4 | 17 | |
5e8d7549 NC |
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 | |
cd123cb7 NC |
20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
21 | MA 02110-1301, USA. */ | |
800eeca4 | 22 | |
800eeca4 | 23 | #include "sysdep.h" |
3db64b00 | 24 | #include "bfd.h" |
800eeca4 JW |
25 | #include "libbfd.h" |
26 | #include "elf-bfd.h" | |
27 | #include "opcode/ia64.h" | |
28 | #include "elf/ia64.h" | |
0aa92b58 JJ |
29 | #include "objalloc.h" |
30 | #include "hashtab.h" | |
800eeca4 | 31 | |
5a260b66 L |
32 | #define ARCH_SIZE NN |
33 | ||
34 | #if ARCH_SIZE == 64 | |
35 | #define LOG_SECTION_ALIGN 3 | |
36 | #endif | |
37 | ||
38 | #if ARCH_SIZE == 32 | |
39 | #define LOG_SECTION_ALIGN 2 | |
40 | #endif | |
41 | ||
5e8d7549 | 42 | /* THE RULES for all the stuff the linker creates -- |
b34976b6 | 43 | |
5e8d7549 NC |
44 | GOT Entries created in response to LTOFF or LTOFF_FPTR |
45 | relocations. Dynamic relocs created for dynamic | |
46 | symbols in an application; REL relocs for locals | |
47 | in a shared library. | |
b34976b6 | 48 | |
5e8d7549 NC |
49 | FPTR The canonical function descriptor. Created for local |
50 | symbols in applications. Descriptors for dynamic symbols | |
51 | and local symbols in shared libraries are created by | |
52 | ld.so. Thus there are no dynamic relocs against these | |
53 | objects. The FPTR relocs for such _are_ passed through | |
54 | to the dynamic relocation tables. | |
b34976b6 | 55 | |
5e8d7549 NC |
56 | FULL_PLT Created for a PCREL21B relocation against a dynamic symbol. |
57 | Requires the creation of a PLTOFF entry. This does not | |
58 | require any dynamic relocations. | |
b34976b6 | 59 | |
5e8d7549 NC |
60 | PLTOFF Created by PLTOFF relocations. For local symbols, this |
61 | is an alternate function descriptor, and in shared libraries | |
62 | requires two REL relocations. Note that this cannot be | |
63 | transformed into an FPTR relocation, since it must be in | |
64 | range of the GP. For dynamic symbols, this is a function | |
65 | descriptor for a MIN_PLT entry, and requires one IPLT reloc. | |
b34976b6 | 66 | |
5e8d7549 | 67 | MIN_PLT Created by PLTOFF entries against dynamic symbols. This |
4cc11e76 | 68 | does not require dynamic relocations. */ |
800eeca4 | 69 | |
800eeca4 JW |
70 | #define NELEMS(a) ((int) (sizeof (a) / sizeof ((a)[0]))) |
71 | ||
72 | typedef struct bfd_hash_entry *(*new_hash_entry_func) | |
73 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); | |
74 | ||
75 | /* In dynamically (linker-) created sections, we generally need to keep track | |
76 | of the place a symbol or expression got allocated to. This is done via hash | |
77 | tables that store entries of the following type. */ | |
78 | ||
bbe66d08 | 79 | struct elfNN_ia64_dyn_sym_info |
800eeca4 JW |
80 | { |
81 | /* The addend for which this entry is relevant. */ | |
82 | bfd_vma addend; | |
83 | ||
800eeca4 JW |
84 | bfd_vma got_offset; |
85 | bfd_vma fptr_offset; | |
86 | bfd_vma pltoff_offset; | |
87 | bfd_vma plt_offset; | |
88 | bfd_vma plt2_offset; | |
13ae64f3 JJ |
89 | bfd_vma tprel_offset; |
90 | bfd_vma dtpmod_offset; | |
91 | bfd_vma dtprel_offset; | |
800eeca4 | 92 | |
4cc11e76 | 93 | /* The symbol table entry, if any, that this was derived from. */ |
800eeca4 | 94 | struct elf_link_hash_entry *h; |
3e932841 | 95 | |
800eeca4 JW |
96 | /* Used to count non-got, non-plt relocations for delayed sizing |
97 | of relocation sections. */ | |
bbe66d08 | 98 | struct elfNN_ia64_dyn_reloc_entry |
800eeca4 | 99 | { |
bbe66d08 | 100 | struct elfNN_ia64_dyn_reloc_entry *next; |
800eeca4 JW |
101 | asection *srel; |
102 | int type; | |
103 | int count; | |
ac33696c L |
104 | |
105 | /* Is this reloc against readonly section? */ | |
106 | bfd_boolean reltext; | |
800eeca4 JW |
107 | } *reloc_entries; |
108 | ||
b34976b6 | 109 | /* TRUE when the section contents have been updated. */ |
800eeca4 JW |
110 | unsigned got_done : 1; |
111 | unsigned fptr_done : 1; | |
112 | unsigned pltoff_done : 1; | |
13ae64f3 JJ |
113 | unsigned tprel_done : 1; |
114 | unsigned dtpmod_done : 1; | |
115 | unsigned dtprel_done : 1; | |
800eeca4 | 116 | |
b34976b6 | 117 | /* TRUE for the different kinds of linker data we want created. */ |
800eeca4 | 118 | unsigned want_got : 1; |
2c4c2bc0 | 119 | unsigned want_gotx : 1; |
800eeca4 JW |
120 | unsigned want_fptr : 1; |
121 | unsigned want_ltoff_fptr : 1; | |
122 | unsigned want_plt : 1; | |
123 | unsigned want_plt2 : 1; | |
124 | unsigned want_pltoff : 1; | |
13ae64f3 JJ |
125 | unsigned want_tprel : 1; |
126 | unsigned want_dtpmod : 1; | |
127 | unsigned want_dtprel : 1; | |
800eeca4 JW |
128 | }; |
129 | ||
bbe66d08 | 130 | struct elfNN_ia64_local_hash_entry |
800eeca4 | 131 | { |
0aa92b58 JJ |
132 | int id; |
133 | unsigned int r_sym; | |
396a682d L |
134 | /* The number of elements in elfNN_ia64_dyn_sym_info array. */ |
135 | unsigned int count; | |
136 | /* The number of sorted elements in elfNN_ia64_dyn_sym_info array. */ | |
137 | unsigned int sorted_count; | |
138 | /* The size of elfNN_ia64_dyn_sym_info array. */ | |
139 | unsigned int size; | |
140 | /* The array of elfNN_ia64_dyn_sym_info. */ | |
bbe66d08 | 141 | struct elfNN_ia64_dyn_sym_info *info; |
f7460f5f | 142 | |
b34976b6 | 143 | /* TRUE if this hash entry's addends was translated for |
f7460f5f JJ |
144 | SHF_MERGE optimization. */ |
145 | unsigned sec_merge_done : 1; | |
800eeca4 JW |
146 | }; |
147 | ||
bbe66d08 | 148 | struct elfNN_ia64_link_hash_entry |
800eeca4 JW |
149 | { |
150 | struct elf_link_hash_entry root; | |
396a682d L |
151 | /* The number of elements in elfNN_ia64_dyn_sym_info array. */ |
152 | unsigned int count; | |
153 | /* The number of sorted elements in elfNN_ia64_dyn_sym_info array. */ | |
154 | unsigned int sorted_count; | |
155 | /* The size of elfNN_ia64_dyn_sym_info array. */ | |
156 | unsigned int size; | |
157 | /* The array of elfNN_ia64_dyn_sym_info. */ | |
bbe66d08 | 158 | struct elfNN_ia64_dyn_sym_info *info; |
800eeca4 JW |
159 | }; |
160 | ||
bbe66d08 | 161 | struct elfNN_ia64_link_hash_table |
800eeca4 | 162 | { |
5e8d7549 | 163 | /* The main hash table. */ |
800eeca4 JW |
164 | struct elf_link_hash_table root; |
165 | ||
800eeca4 | 166 | asection *fptr_sec; /* function descriptor table (or NULL) */ |
9203ba99 | 167 | asection *rel_fptr_sec; /* dynamic relocation section for same */ |
800eeca4 JW |
168 | asection *pltoff_sec; /* private descriptors for plt (or NULL) */ |
169 | asection *rel_pltoff_sec; /* dynamic relocation section for same */ | |
170 | ||
171 | bfd_size_type minplt_entries; /* number of minplt entries */ | |
db6751f2 | 172 | unsigned reltext : 1; /* are there relocs against readonly sections? */ |
b3dfd7fe JJ |
173 | unsigned self_dtpmod_done : 1;/* has self DTPMOD entry been finished? */ |
174 | bfd_vma self_dtpmod_offset; /* .got offset to self DTPMOD entry */ | |
800eeca4 | 175 | |
0aa92b58 JJ |
176 | htab_t loc_hash_table; |
177 | void *loc_hash_memory; | |
800eeca4 JW |
178 | }; |
179 | ||
2c4c2bc0 RH |
180 | struct elfNN_ia64_allocate_data |
181 | { | |
182 | struct bfd_link_info *info; | |
183 | bfd_size_type ofs; | |
4a78a1f4 | 184 | bfd_boolean only_got; |
2c4c2bc0 RH |
185 | }; |
186 | ||
bbe66d08 JW |
187 | #define elfNN_ia64_hash_table(p) \ |
188 | ((struct elfNN_ia64_link_hash_table *) ((p)->hash)) | |
800eeca4 | 189 | |
eae50df2 L |
190 | static struct elfNN_ia64_dyn_sym_info * get_dyn_sym_info |
191 | (struct elfNN_ia64_link_hash_table *ia64_info, | |
192 | struct elf_link_hash_entry *h, | |
193 | bfd *abfd, const Elf_Internal_Rela *rel, bfd_boolean create); | |
b34976b6 | 194 | static bfd_boolean elfNN_ia64_dynamic_symbol_p |
eae50df2 L |
195 | (struct elf_link_hash_entry *h, struct bfd_link_info *info, int); |
196 | static bfd_reloc_status_type elfNN_ia64_install_value | |
197 | (bfd_byte *hit_addr, bfd_vma val, unsigned int r_type); | |
198 | static bfd_boolean elfNN_ia64_choose_gp | |
199 | (bfd *abfd, struct bfd_link_info *info); | |
200 | static void elfNN_ia64_relax_ldxmov | |
201 | (bfd_byte *contents, bfd_vma off); | |
bbe66d08 | 202 | static void elfNN_ia64_dyn_sym_traverse |
eae50df2 L |
203 | (struct elfNN_ia64_link_hash_table *ia64_info, |
204 | bfd_boolean (*func) (struct elfNN_ia64_dyn_sym_info *, PTR), | |
205 | PTR info); | |
b34976b6 | 206 | static bfd_boolean allocate_global_data_got |
eae50df2 | 207 | (struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data); |
b34976b6 | 208 | static bfd_boolean allocate_global_fptr_got |
eae50df2 | 209 | (struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data); |
b34976b6 | 210 | static bfd_boolean allocate_local_got |
eae50df2 | 211 | (struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data); |
b34976b6 | 212 | static bfd_boolean elfNN_ia64_hpux_vec |
eae50df2 L |
213 | (const bfd_target *vec); |
214 | static bfd_boolean allocate_dynrel_entries | |
215 | (struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data); | |
216 | static asection *get_pltoff | |
217 | (bfd *abfd, struct bfd_link_info *info, | |
218 | struct elfNN_ia64_link_hash_table *ia64_info); | |
800eeca4 | 219 | \f |
5e8d7549 | 220 | /* ia64-specific relocation. */ |
800eeca4 JW |
221 | |
222 | /* Perform a relocation. Not much to do here as all the hard work is | |
bbe66d08 | 223 | done in elfNN_ia64_final_link_relocate. */ |
800eeca4 | 224 | static bfd_reloc_status_type |
eae50df2 L |
225 | elfNN_ia64_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc, |
226 | asymbol *sym ATTRIBUTE_UNUSED, | |
227 | PTR data ATTRIBUTE_UNUSED, asection *input_section, | |
228 | bfd *output_bfd, char **error_message) | |
800eeca4 JW |
229 | { |
230 | if (output_bfd) | |
231 | { | |
232 | reloc->address += input_section->output_offset; | |
233 | return bfd_reloc_ok; | |
234 | } | |
6e84a906 DJ |
235 | |
236 | if (input_section->flags & SEC_DEBUGGING) | |
237 | return bfd_reloc_continue; | |
238 | ||
bbe66d08 | 239 | *error_message = "Unsupported call to elfNN_ia64_reloc"; |
800eeca4 JW |
240 | return bfd_reloc_notsupported; |
241 | } | |
242 | ||
243 | #define IA64_HOWTO(TYPE, NAME, SIZE, PCREL, IN) \ | |
244 | HOWTO (TYPE, 0, SIZE, 0, PCREL, 0, complain_overflow_signed, \ | |
eff26f78 | 245 | elfNN_ia64_reloc, NAME, FALSE, 0, -1, IN) |
800eeca4 JW |
246 | |
247 | /* This table has to be sorted according to increasing number of the | |
248 | TYPE field. */ | |
249 | static reloc_howto_type ia64_howto_table[] = | |
250 | { | |
b34976b6 AM |
251 | IA64_HOWTO (R_IA64_NONE, "NONE", 0, FALSE, TRUE), |
252 | ||
253 | IA64_HOWTO (R_IA64_IMM14, "IMM14", 0, FALSE, TRUE), | |
254 | IA64_HOWTO (R_IA64_IMM22, "IMM22", 0, FALSE, TRUE), | |
255 | IA64_HOWTO (R_IA64_IMM64, "IMM64", 0, FALSE, TRUE), | |
256 | IA64_HOWTO (R_IA64_DIR32MSB, "DIR32MSB", 2, FALSE, TRUE), | |
257 | IA64_HOWTO (R_IA64_DIR32LSB, "DIR32LSB", 2, FALSE, TRUE), | |
258 | IA64_HOWTO (R_IA64_DIR64MSB, "DIR64MSB", 4, FALSE, TRUE), | |
259 | IA64_HOWTO (R_IA64_DIR64LSB, "DIR64LSB", 4, FALSE, TRUE), | |
260 | ||
261 | IA64_HOWTO (R_IA64_GPREL22, "GPREL22", 0, FALSE, TRUE), | |
262 | IA64_HOWTO (R_IA64_GPREL64I, "GPREL64I", 0, FALSE, TRUE), | |
263 | IA64_HOWTO (R_IA64_GPREL32MSB, "GPREL32MSB", 2, FALSE, TRUE), | |
264 | IA64_HOWTO (R_IA64_GPREL32LSB, "GPREL32LSB", 2, FALSE, TRUE), | |
265 | IA64_HOWTO (R_IA64_GPREL64MSB, "GPREL64MSB", 4, FALSE, TRUE), | |
266 | IA64_HOWTO (R_IA64_GPREL64LSB, "GPREL64LSB", 4, FALSE, TRUE), | |
267 | ||
268 | IA64_HOWTO (R_IA64_LTOFF22, "LTOFF22", 0, FALSE, TRUE), | |
269 | IA64_HOWTO (R_IA64_LTOFF64I, "LTOFF64I", 0, FALSE, TRUE), | |
270 | ||
271 | IA64_HOWTO (R_IA64_PLTOFF22, "PLTOFF22", 0, FALSE, TRUE), | |
272 | IA64_HOWTO (R_IA64_PLTOFF64I, "PLTOFF64I", 0, FALSE, TRUE), | |
273 | IA64_HOWTO (R_IA64_PLTOFF64MSB, "PLTOFF64MSB", 4, FALSE, TRUE), | |
274 | IA64_HOWTO (R_IA64_PLTOFF64LSB, "PLTOFF64LSB", 4, FALSE, TRUE), | |
275 | ||
276 | IA64_HOWTO (R_IA64_FPTR64I, "FPTR64I", 0, FALSE, TRUE), | |
277 | IA64_HOWTO (R_IA64_FPTR32MSB, "FPTR32MSB", 2, FALSE, TRUE), | |
278 | IA64_HOWTO (R_IA64_FPTR32LSB, "FPTR32LSB", 2, FALSE, TRUE), | |
279 | IA64_HOWTO (R_IA64_FPTR64MSB, "FPTR64MSB", 4, FALSE, TRUE), | |
280 | IA64_HOWTO (R_IA64_FPTR64LSB, "FPTR64LSB", 4, FALSE, TRUE), | |
281 | ||
282 | IA64_HOWTO (R_IA64_PCREL60B, "PCREL60B", 0, TRUE, TRUE), | |
283 | IA64_HOWTO (R_IA64_PCREL21B, "PCREL21B", 0, TRUE, TRUE), | |
284 | IA64_HOWTO (R_IA64_PCREL21M, "PCREL21M", 0, TRUE, TRUE), | |
285 | IA64_HOWTO (R_IA64_PCREL21F, "PCREL21F", 0, TRUE, TRUE), | |
286 | IA64_HOWTO (R_IA64_PCREL32MSB, "PCREL32MSB", 2, TRUE, TRUE), | |
287 | IA64_HOWTO (R_IA64_PCREL32LSB, "PCREL32LSB", 2, TRUE, TRUE), | |
288 | IA64_HOWTO (R_IA64_PCREL64MSB, "PCREL64MSB", 4, TRUE, TRUE), | |
289 | IA64_HOWTO (R_IA64_PCREL64LSB, "PCREL64LSB", 4, TRUE, TRUE), | |
290 | ||
291 | IA64_HOWTO (R_IA64_LTOFF_FPTR22, "LTOFF_FPTR22", 0, FALSE, TRUE), | |
292 | IA64_HOWTO (R_IA64_LTOFF_FPTR64I, "LTOFF_FPTR64I", 0, FALSE, TRUE), | |
293 | IA64_HOWTO (R_IA64_LTOFF_FPTR32MSB, "LTOFF_FPTR32MSB", 2, FALSE, TRUE), | |
294 | IA64_HOWTO (R_IA64_LTOFF_FPTR32LSB, "LTOFF_FPTR32LSB", 2, FALSE, TRUE), | |
295 | IA64_HOWTO (R_IA64_LTOFF_FPTR64MSB, "LTOFF_FPTR64MSB", 4, FALSE, TRUE), | |
296 | IA64_HOWTO (R_IA64_LTOFF_FPTR64LSB, "LTOFF_FPTR64LSB", 4, FALSE, TRUE), | |
297 | ||
298 | IA64_HOWTO (R_IA64_SEGREL32MSB, "SEGREL32MSB", 2, FALSE, TRUE), | |
299 | IA64_HOWTO (R_IA64_SEGREL32LSB, "SEGREL32LSB", 2, FALSE, TRUE), | |
300 | IA64_HOWTO (R_IA64_SEGREL64MSB, "SEGREL64MSB", 4, FALSE, TRUE), | |
301 | IA64_HOWTO (R_IA64_SEGREL64LSB, "SEGREL64LSB", 4, FALSE, TRUE), | |
302 | ||
303 | IA64_HOWTO (R_IA64_SECREL32MSB, "SECREL32MSB", 2, FALSE, TRUE), | |
304 | IA64_HOWTO (R_IA64_SECREL32LSB, "SECREL32LSB", 2, FALSE, TRUE), | |
305 | IA64_HOWTO (R_IA64_SECREL64MSB, "SECREL64MSB", 4, FALSE, TRUE), | |
306 | IA64_HOWTO (R_IA64_SECREL64LSB, "SECREL64LSB", 4, FALSE, TRUE), | |
307 | ||
308 | IA64_HOWTO (R_IA64_REL32MSB, "REL32MSB", 2, FALSE, TRUE), | |
309 | IA64_HOWTO (R_IA64_REL32LSB, "REL32LSB", 2, FALSE, TRUE), | |
310 | IA64_HOWTO (R_IA64_REL64MSB, "REL64MSB", 4, FALSE, TRUE), | |
311 | IA64_HOWTO (R_IA64_REL64LSB, "REL64LSB", 4, FALSE, TRUE), | |
312 | ||
313 | IA64_HOWTO (R_IA64_LTV32MSB, "LTV32MSB", 2, FALSE, TRUE), | |
314 | IA64_HOWTO (R_IA64_LTV32LSB, "LTV32LSB", 2, FALSE, TRUE), | |
315 | IA64_HOWTO (R_IA64_LTV64MSB, "LTV64MSB", 4, FALSE, TRUE), | |
316 | IA64_HOWTO (R_IA64_LTV64LSB, "LTV64LSB", 4, FALSE, TRUE), | |
317 | ||
318 | IA64_HOWTO (R_IA64_PCREL21BI, "PCREL21BI", 0, TRUE, TRUE), | |
319 | IA64_HOWTO (R_IA64_PCREL22, "PCREL22", 0, TRUE, TRUE), | |
320 | IA64_HOWTO (R_IA64_PCREL64I, "PCREL64I", 0, TRUE, TRUE), | |
321 | ||
322 | IA64_HOWTO (R_IA64_IPLTMSB, "IPLTMSB", 4, FALSE, TRUE), | |
323 | IA64_HOWTO (R_IA64_IPLTLSB, "IPLTLSB", 4, FALSE, TRUE), | |
324 | IA64_HOWTO (R_IA64_COPY, "COPY", 4, FALSE, TRUE), | |
325 | IA64_HOWTO (R_IA64_LTOFF22X, "LTOFF22X", 0, FALSE, TRUE), | |
326 | IA64_HOWTO (R_IA64_LDXMOV, "LDXMOV", 0, FALSE, TRUE), | |
327 | ||
328 | IA64_HOWTO (R_IA64_TPREL14, "TPREL14", 0, FALSE, FALSE), | |
329 | IA64_HOWTO (R_IA64_TPREL22, "TPREL22", 0, FALSE, FALSE), | |
330 | IA64_HOWTO (R_IA64_TPREL64I, "TPREL64I", 0, FALSE, FALSE), | |
1fc0d173 JJ |
331 | IA64_HOWTO (R_IA64_TPREL64MSB, "TPREL64MSB", 4, FALSE, FALSE), |
332 | IA64_HOWTO (R_IA64_TPREL64LSB, "TPREL64LSB", 4, FALSE, FALSE), | |
b34976b6 AM |
333 | IA64_HOWTO (R_IA64_LTOFF_TPREL22, "LTOFF_TPREL22", 0, FALSE, FALSE), |
334 | ||
0ca3e455 JB |
335 | IA64_HOWTO (R_IA64_DTPMOD64MSB, "DTPMOD64MSB", 4, FALSE, FALSE), |
336 | IA64_HOWTO (R_IA64_DTPMOD64LSB, "DTPMOD64LSB", 4, FALSE, FALSE), | |
b34976b6 AM |
337 | IA64_HOWTO (R_IA64_LTOFF_DTPMOD22, "LTOFF_DTPMOD22", 0, FALSE, FALSE), |
338 | ||
339 | IA64_HOWTO (R_IA64_DTPREL14, "DTPREL14", 0, FALSE, FALSE), | |
340 | IA64_HOWTO (R_IA64_DTPREL22, "DTPREL22", 0, FALSE, FALSE), | |
341 | IA64_HOWTO (R_IA64_DTPREL64I, "DTPREL64I", 0, FALSE, FALSE), | |
1fc0d173 JJ |
342 | IA64_HOWTO (R_IA64_DTPREL32MSB, "DTPREL32MSB", 2, FALSE, FALSE), |
343 | IA64_HOWTO (R_IA64_DTPREL32LSB, "DTPREL32LSB", 2, FALSE, FALSE), | |
344 | IA64_HOWTO (R_IA64_DTPREL64MSB, "DTPREL64MSB", 4, FALSE, FALSE), | |
345 | IA64_HOWTO (R_IA64_DTPREL64LSB, "DTPREL64LSB", 4, FALSE, FALSE), | |
b34976b6 | 346 | IA64_HOWTO (R_IA64_LTOFF_DTPREL22, "LTOFF_DTPREL22", 0, FALSE, FALSE), |
800eeca4 JW |
347 | }; |
348 | ||
349 | static unsigned char elf_code_to_howto_index[R_IA64_MAX_RELOC_CODE + 1]; | |
350 | ||
351 | /* Given a BFD reloc type, return the matching HOWTO structure. */ | |
352 | ||
5e8d7549 | 353 | static reloc_howto_type * |
eae50df2 | 354 | lookup_howto (unsigned int rtype) |
800eeca4 JW |
355 | { |
356 | static int inited = 0; | |
357 | int i; | |
358 | ||
359 | if (!inited) | |
360 | { | |
361 | inited = 1; | |
362 | ||
363 | memset (elf_code_to_howto_index, 0xff, sizeof (elf_code_to_howto_index)); | |
364 | for (i = 0; i < NELEMS (ia64_howto_table); ++i) | |
365 | elf_code_to_howto_index[ia64_howto_table[i].type] = i; | |
366 | } | |
367 | ||
d0fb9a8d JJ |
368 | if (rtype > R_IA64_MAX_RELOC_CODE) |
369 | return 0; | |
800eeca4 JW |
370 | i = elf_code_to_howto_index[rtype]; |
371 | if (i >= NELEMS (ia64_howto_table)) | |
372 | return 0; | |
373 | return ia64_howto_table + i; | |
374 | } | |
375 | ||
376 | static reloc_howto_type* | |
eae50df2 L |
377 | elfNN_ia64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
378 | bfd_reloc_code_real_type bfd_code) | |
800eeca4 JW |
379 | { |
380 | unsigned int rtype; | |
381 | ||
382 | switch (bfd_code) | |
383 | { | |
384 | case BFD_RELOC_NONE: rtype = R_IA64_NONE; break; | |
385 | ||
386 | case BFD_RELOC_IA64_IMM14: rtype = R_IA64_IMM14; break; | |
387 | case BFD_RELOC_IA64_IMM22: rtype = R_IA64_IMM22; break; | |
388 | case BFD_RELOC_IA64_IMM64: rtype = R_IA64_IMM64; break; | |
389 | ||
390 | case BFD_RELOC_IA64_DIR32MSB: rtype = R_IA64_DIR32MSB; break; | |
391 | case BFD_RELOC_IA64_DIR32LSB: rtype = R_IA64_DIR32LSB; break; | |
392 | case BFD_RELOC_IA64_DIR64MSB: rtype = R_IA64_DIR64MSB; break; | |
393 | case BFD_RELOC_IA64_DIR64LSB: rtype = R_IA64_DIR64LSB; break; | |
394 | ||
395 | case BFD_RELOC_IA64_GPREL22: rtype = R_IA64_GPREL22; break; | |
396 | case BFD_RELOC_IA64_GPREL64I: rtype = R_IA64_GPREL64I; break; | |
397 | case BFD_RELOC_IA64_GPREL32MSB: rtype = R_IA64_GPREL32MSB; break; | |
398 | case BFD_RELOC_IA64_GPREL32LSB: rtype = R_IA64_GPREL32LSB; break; | |
399 | case BFD_RELOC_IA64_GPREL64MSB: rtype = R_IA64_GPREL64MSB; break; | |
400 | case BFD_RELOC_IA64_GPREL64LSB: rtype = R_IA64_GPREL64LSB; break; | |
401 | ||
402 | case BFD_RELOC_IA64_LTOFF22: rtype = R_IA64_LTOFF22; break; | |
403 | case BFD_RELOC_IA64_LTOFF64I: rtype = R_IA64_LTOFF64I; break; | |
404 | ||
405 | case BFD_RELOC_IA64_PLTOFF22: rtype = R_IA64_PLTOFF22; break; | |
406 | case BFD_RELOC_IA64_PLTOFF64I: rtype = R_IA64_PLTOFF64I; break; | |
407 | case BFD_RELOC_IA64_PLTOFF64MSB: rtype = R_IA64_PLTOFF64MSB; break; | |
408 | case BFD_RELOC_IA64_PLTOFF64LSB: rtype = R_IA64_PLTOFF64LSB; break; | |
409 | case BFD_RELOC_IA64_FPTR64I: rtype = R_IA64_FPTR64I; break; | |
410 | case BFD_RELOC_IA64_FPTR32MSB: rtype = R_IA64_FPTR32MSB; break; | |
411 | case BFD_RELOC_IA64_FPTR32LSB: rtype = R_IA64_FPTR32LSB; break; | |
412 | case BFD_RELOC_IA64_FPTR64MSB: rtype = R_IA64_FPTR64MSB; break; | |
413 | case BFD_RELOC_IA64_FPTR64LSB: rtype = R_IA64_FPTR64LSB; break; | |
414 | ||
415 | case BFD_RELOC_IA64_PCREL21B: rtype = R_IA64_PCREL21B; break; | |
748abff6 | 416 | case BFD_RELOC_IA64_PCREL21BI: rtype = R_IA64_PCREL21BI; break; |
800eeca4 JW |
417 | case BFD_RELOC_IA64_PCREL21M: rtype = R_IA64_PCREL21M; break; |
418 | case BFD_RELOC_IA64_PCREL21F: rtype = R_IA64_PCREL21F; break; | |
748abff6 RH |
419 | case BFD_RELOC_IA64_PCREL22: rtype = R_IA64_PCREL22; break; |
420 | case BFD_RELOC_IA64_PCREL60B: rtype = R_IA64_PCREL60B; break; | |
421 | case BFD_RELOC_IA64_PCREL64I: rtype = R_IA64_PCREL64I; break; | |
800eeca4 JW |
422 | case BFD_RELOC_IA64_PCREL32MSB: rtype = R_IA64_PCREL32MSB; break; |
423 | case BFD_RELOC_IA64_PCREL32LSB: rtype = R_IA64_PCREL32LSB; break; | |
424 | case BFD_RELOC_IA64_PCREL64MSB: rtype = R_IA64_PCREL64MSB; break; | |
425 | case BFD_RELOC_IA64_PCREL64LSB: rtype = R_IA64_PCREL64LSB; break; | |
426 | ||
427 | case BFD_RELOC_IA64_LTOFF_FPTR22: rtype = R_IA64_LTOFF_FPTR22; break; | |
428 | case BFD_RELOC_IA64_LTOFF_FPTR64I: rtype = R_IA64_LTOFF_FPTR64I; break; | |
a4bd8390 JW |
429 | case BFD_RELOC_IA64_LTOFF_FPTR32MSB: rtype = R_IA64_LTOFF_FPTR32MSB; break; |
430 | case BFD_RELOC_IA64_LTOFF_FPTR32LSB: rtype = R_IA64_LTOFF_FPTR32LSB; break; | |
800eeca4 JW |
431 | case BFD_RELOC_IA64_LTOFF_FPTR64MSB: rtype = R_IA64_LTOFF_FPTR64MSB; break; |
432 | case BFD_RELOC_IA64_LTOFF_FPTR64LSB: rtype = R_IA64_LTOFF_FPTR64LSB; break; | |
433 | ||
800eeca4 JW |
434 | case BFD_RELOC_IA64_SEGREL32MSB: rtype = R_IA64_SEGREL32MSB; break; |
435 | case BFD_RELOC_IA64_SEGREL32LSB: rtype = R_IA64_SEGREL32LSB; break; | |
436 | case BFD_RELOC_IA64_SEGREL64MSB: rtype = R_IA64_SEGREL64MSB; break; | |
437 | case BFD_RELOC_IA64_SEGREL64LSB: rtype = R_IA64_SEGREL64LSB; break; | |
438 | ||
439 | case BFD_RELOC_IA64_SECREL32MSB: rtype = R_IA64_SECREL32MSB; break; | |
440 | case BFD_RELOC_IA64_SECREL32LSB: rtype = R_IA64_SECREL32LSB; break; | |
441 | case BFD_RELOC_IA64_SECREL64MSB: rtype = R_IA64_SECREL64MSB; break; | |
442 | case BFD_RELOC_IA64_SECREL64LSB: rtype = R_IA64_SECREL64LSB; break; | |
443 | ||
444 | case BFD_RELOC_IA64_REL32MSB: rtype = R_IA64_REL32MSB; break; | |
445 | case BFD_RELOC_IA64_REL32LSB: rtype = R_IA64_REL32LSB; break; | |
446 | case BFD_RELOC_IA64_REL64MSB: rtype = R_IA64_REL64MSB; break; | |
447 | case BFD_RELOC_IA64_REL64LSB: rtype = R_IA64_REL64LSB; break; | |
448 | ||
449 | case BFD_RELOC_IA64_LTV32MSB: rtype = R_IA64_LTV32MSB; break; | |
450 | case BFD_RELOC_IA64_LTV32LSB: rtype = R_IA64_LTV32LSB; break; | |
451 | case BFD_RELOC_IA64_LTV64MSB: rtype = R_IA64_LTV64MSB; break; | |
452 | case BFD_RELOC_IA64_LTV64LSB: rtype = R_IA64_LTV64LSB; break; | |
453 | ||
454 | case BFD_RELOC_IA64_IPLTMSB: rtype = R_IA64_IPLTMSB; break; | |
455 | case BFD_RELOC_IA64_IPLTLSB: rtype = R_IA64_IPLTLSB; break; | |
800eeca4 JW |
456 | case BFD_RELOC_IA64_COPY: rtype = R_IA64_COPY; break; |
457 | case BFD_RELOC_IA64_LTOFF22X: rtype = R_IA64_LTOFF22X; break; | |
458 | case BFD_RELOC_IA64_LDXMOV: rtype = R_IA64_LDXMOV; break; | |
459 | ||
13ae64f3 | 460 | case BFD_RELOC_IA64_TPREL14: rtype = R_IA64_TPREL14; break; |
800eeca4 | 461 | case BFD_RELOC_IA64_TPREL22: rtype = R_IA64_TPREL22; break; |
13ae64f3 | 462 | case BFD_RELOC_IA64_TPREL64I: rtype = R_IA64_TPREL64I; break; |
800eeca4 JW |
463 | case BFD_RELOC_IA64_TPREL64MSB: rtype = R_IA64_TPREL64MSB; break; |
464 | case BFD_RELOC_IA64_TPREL64LSB: rtype = R_IA64_TPREL64LSB; break; | |
13ae64f3 JJ |
465 | case BFD_RELOC_IA64_LTOFF_TPREL22: rtype = R_IA64_LTOFF_TPREL22; break; |
466 | ||
467 | case BFD_RELOC_IA64_DTPMOD64MSB: rtype = R_IA64_DTPMOD64MSB; break; | |
468 | case BFD_RELOC_IA64_DTPMOD64LSB: rtype = R_IA64_DTPMOD64LSB; break; | |
469 | case BFD_RELOC_IA64_LTOFF_DTPMOD22: rtype = R_IA64_LTOFF_DTPMOD22; break; | |
470 | ||
471 | case BFD_RELOC_IA64_DTPREL14: rtype = R_IA64_DTPREL14; break; | |
472 | case BFD_RELOC_IA64_DTPREL22: rtype = R_IA64_DTPREL22; break; | |
473 | case BFD_RELOC_IA64_DTPREL64I: rtype = R_IA64_DTPREL64I; break; | |
474 | case BFD_RELOC_IA64_DTPREL32MSB: rtype = R_IA64_DTPREL32MSB; break; | |
475 | case BFD_RELOC_IA64_DTPREL32LSB: rtype = R_IA64_DTPREL32LSB; break; | |
476 | case BFD_RELOC_IA64_DTPREL64MSB: rtype = R_IA64_DTPREL64MSB; break; | |
477 | case BFD_RELOC_IA64_DTPREL64LSB: rtype = R_IA64_DTPREL64LSB; break; | |
478 | case BFD_RELOC_IA64_LTOFF_DTPREL22: rtype = R_IA64_LTOFF_DTPREL22; break; | |
800eeca4 JW |
479 | |
480 | default: return 0; | |
481 | } | |
482 | return lookup_howto (rtype); | |
483 | } | |
484 | ||
157090f7 AM |
485 | static reloc_howto_type * |
486 | elfNN_ia64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
487 | const char *r_name) | |
488 | { | |
489 | unsigned int i; | |
490 | ||
491 | for (i = 0; | |
492 | i < sizeof (ia64_howto_table) / sizeof (ia64_howto_table[0]); | |
493 | i++) | |
494 | if (ia64_howto_table[i].name != NULL | |
495 | && strcasecmp (ia64_howto_table[i].name, r_name) == 0) | |
496 | return &ia64_howto_table[i]; | |
497 | ||
498 | return NULL; | |
499 | } | |
500 | ||
800eeca4 JW |
501 | /* Given a ELF reloc, return the matching HOWTO structure. */ |
502 | ||
503 | static void | |
eae50df2 L |
504 | elfNN_ia64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, |
505 | arelent *bfd_reloc, | |
506 | Elf_Internal_Rela *elf_reloc) | |
800eeca4 | 507 | { |
dc810e39 AM |
508 | bfd_reloc->howto |
509 | = lookup_howto ((unsigned int) ELFNN_R_TYPE (elf_reloc->r_info)); | |
800eeca4 JW |
510 | } |
511 | \f | |
512 | #define PLT_HEADER_SIZE (3 * 16) | |
513 | #define PLT_MIN_ENTRY_SIZE (1 * 16) | |
514 | #define PLT_FULL_ENTRY_SIZE (2 * 16) | |
515 | #define PLT_RESERVED_WORDS 3 | |
516 | ||
517 | static const bfd_byte plt_header[PLT_HEADER_SIZE] = | |
518 | { | |
519 | 0x0b, 0x10, 0x00, 0x1c, 0x00, 0x21, /* [MMI] mov r2=r14;; */ | |
520 | 0xe0, 0x00, 0x08, 0x00, 0x48, 0x00, /* addl r14=0,r2 */ | |
521 | 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */ | |
522 | 0x0b, 0x80, 0x20, 0x1c, 0x18, 0x14, /* [MMI] ld8 r16=[r14],8;; */ | |
523 | 0x10, 0x41, 0x38, 0x30, 0x28, 0x00, /* ld8 r17=[r14],8 */ | |
524 | 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */ | |
525 | 0x11, 0x08, 0x00, 0x1c, 0x18, 0x10, /* [MIB] ld8 r1=[r14] */ | |
526 | 0x60, 0x88, 0x04, 0x80, 0x03, 0x00, /* mov b6=r17 */ | |
527 | 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */ | |
528 | }; | |
529 | ||
530 | static const bfd_byte plt_min_entry[PLT_MIN_ENTRY_SIZE] = | |
531 | { | |
532 | 0x11, 0x78, 0x00, 0x00, 0x00, 0x24, /* [MIB] mov r15=0 */ | |
533 | 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* nop.i 0x0 */ | |
534 | 0x00, 0x00, 0x00, 0x40 /* br.few 0 <PLT0>;; */ | |
535 | }; | |
536 | ||
537 | static const bfd_byte plt_full_entry[PLT_FULL_ENTRY_SIZE] = | |
538 | { | |
539 | 0x0b, 0x78, 0x00, 0x02, 0x00, 0x24, /* [MMI] addl r15=0,r1;; */ | |
8b6f2683 | 540 | 0x00, 0x41, 0x3c, 0x70, 0x29, 0xc0, /* ld8.acq r16=[r15],8*/ |
800eeca4 JW |
541 | 0x01, 0x08, 0x00, 0x84, /* mov r14=r1;; */ |
542 | 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, /* [MIB] ld8 r1=[r15] */ | |
543 | 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */ | |
544 | 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */ | |
545 | }; | |
546 | ||
547 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
748abff6 | 548 | |
748abff6 RH |
549 | static const bfd_byte oor_brl[16] = |
550 | { | |
551 | 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */ | |
552 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* brl.sptk.few tgt;; */ | |
553 | 0x00, 0x00, 0x00, 0xc0 | |
554 | }; | |
3f7deb8a L |
555 | |
556 | static const bfd_byte oor_ip[48] = | |
557 | { | |
558 | 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MLX] nop.m 0 */ | |
559 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, /* movl r15=0 */ | |
560 | 0x01, 0x00, 0x00, 0x60, | |
561 | 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MII] nop.m 0 */ | |
562 | 0x00, 0x01, 0x00, 0x60, 0x00, 0x00, /* mov r16=ip;; */ | |
563 | 0xf2, 0x80, 0x00, 0x80, /* add r16=r15,r16;; */ | |
564 | 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MIB] nop.m 0 */ | |
565 | 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */ | |
566 | 0x60, 0x00, 0x80, 0x00 /* br b6;; */ | |
567 | }; | |
568 | ||
569 | static size_t oor_branch_size = sizeof (oor_brl); | |
570 | ||
571 | void | |
572 | bfd_elfNN_ia64_after_parse (int itanium) | |
573 | { | |
574 | oor_branch_size = itanium ? sizeof (oor_ip) : sizeof (oor_brl); | |
575 | } | |
576 | ||
83b6bd86 L |
577 | #define BTYPE_SHIFT 6 |
578 | #define Y_SHIFT 26 | |
579 | #define X6_SHIFT 27 | |
580 | #define X4_SHIFT 27 | |
581 | #define X3_SHIFT 33 | |
582 | #define X2_SHIFT 31 | |
583 | #define X_SHIFT 33 | |
584 | #define OPCODE_SHIFT 37 | |
585 | ||
586 | #define OPCODE_BITS (0xfLL << OPCODE_SHIFT) | |
587 | #define X6_BITS (0x3fLL << X6_SHIFT) | |
588 | #define X4_BITS (0xfLL << X4_SHIFT) | |
589 | #define X3_BITS (0x7LL << X3_SHIFT) | |
590 | #define X2_BITS (0x3LL << X2_SHIFT) | |
591 | #define X_BITS (0x1LL << X_SHIFT) | |
592 | #define Y_BITS (0x1LL << Y_SHIFT) | |
593 | #define BTYPE_BITS (0x7LL << BTYPE_SHIFT) | |
594 | #define PREDICATE_BITS (0x3fLL) | |
595 | ||
596 | #define IS_NOP_B(i) \ | |
597 | (((i) & (OPCODE_BITS | X6_BITS)) == (2LL << OPCODE_SHIFT)) | |
598 | #define IS_NOP_F(i) \ | |
599 | (((i) & (OPCODE_BITS | X_BITS | X6_BITS | Y_BITS)) \ | |
600 | == (0x1LL << X6_SHIFT)) | |
601 | #define IS_NOP_I(i) \ | |
602 | (((i) & (OPCODE_BITS | X3_BITS | X6_BITS | Y_BITS)) \ | |
603 | == (0x1LL << X6_SHIFT)) | |
604 | #define IS_NOP_M(i) \ | |
605 | (((i) & (OPCODE_BITS | X3_BITS | X2_BITS | X4_BITS | Y_BITS)) \ | |
606 | == (0x1LL << X4_SHIFT)) | |
607 | #define IS_BR_COND(i) \ | |
608 | (((i) & (OPCODE_BITS | BTYPE_BITS)) == (0x4LL << OPCODE_SHIFT)) | |
609 | #define IS_BR_CALL(i) \ | |
610 | (((i) & OPCODE_BITS) == (0x5LL << OPCODE_SHIFT)) | |
611 | ||
612 | static bfd_boolean | |
613 | elfNN_ia64_relax_br (bfd_byte *contents, bfd_vma off) | |
614 | { | |
615 | unsigned int template, mlx; | |
616 | bfd_vma t0, t1, s0, s1, s2, br_code; | |
617 | long br_slot; | |
618 | bfd_byte *hit_addr; | |
619 | ||
620 | hit_addr = (bfd_byte *) (contents + off); | |
621 | br_slot = (long) hit_addr & 0x3; | |
622 | hit_addr -= br_slot; | |
623 | t0 = bfd_getl64 (hit_addr + 0); | |
624 | t1 = bfd_getl64 (hit_addr + 8); | |
625 | ||
626 | /* Check if we can turn br into brl. A label is always at the start | |
627 | of the bundle. Even if there are predicates on NOPs, we still | |
628 | perform this optimization. */ | |
629 | template = t0 & 0x1e; | |
630 | s0 = (t0 >> 5) & 0x1ffffffffffLL; | |
631 | s1 = ((t0 >> 46) | (t1 << 18)) & 0x1ffffffffffLL; | |
632 | s2 = (t1 >> 23) & 0x1ffffffffffLL; | |
633 | switch (br_slot) | |
634 | { | |
635 | case 0: | |
636 | /* Check if slot 1 and slot 2 are NOPs. Possible template is | |
637 | BBB. We only need to check nop.b. */ | |
638 | if (!(IS_NOP_B (s1) && IS_NOP_B (s2))) | |
639 | return FALSE; | |
640 | br_code = s0; | |
641 | break; | |
642 | case 1: | |
643 | /* Check if slot 2 is NOP. Possible templates are MBB and BBB. | |
644 | For BBB, slot 0 also has to be nop.b. */ | |
645 | if (!((template == 0x12 /* MBB */ | |
646 | && IS_NOP_B (s2)) | |
647 | || (template == 0x16 /* BBB */ | |
648 | && IS_NOP_B (s0) | |
649 | && IS_NOP_B (s2)))) | |
650 | return FALSE; | |
651 | br_code = s1; | |
652 | break; | |
653 | case 2: | |
654 | /* Check if slot 1 is NOP. Possible templates are MIB, MBB, BBB, | |
655 | MMB and MFB. For BBB, slot 0 also has to be nop.b. */ | |
656 | if (!((template == 0x10 /* MIB */ | |
657 | && IS_NOP_I (s1)) | |
658 | || (template == 0x12 /* MBB */ | |
659 | && IS_NOP_B (s1)) | |
660 | || (template == 0x16 /* BBB */ | |
661 | && IS_NOP_B (s0) | |
662 | && IS_NOP_B (s1)) | |
663 | || (template == 0x18 /* MMB */ | |
664 | && IS_NOP_M (s1)) | |
665 | || (template == 0x1c /* MFB */ | |
666 | && IS_NOP_F (s1)))) | |
667 | return FALSE; | |
668 | br_code = s2; | |
669 | break; | |
670 | default: | |
671 | /* It should never happen. */ | |
672 | abort (); | |
673 | } | |
9a2e389a | 674 | |
83b6bd86 L |
675 | /* We can turn br.cond/br.call into brl.cond/brl.call. */ |
676 | if (!(IS_BR_COND (br_code) || IS_BR_CALL (br_code))) | |
677 | return FALSE; | |
678 | ||
679 | /* Turn br into brl by setting bit 40. */ | |
680 | br_code |= 0x1LL << 40; | |
681 | ||
682 | /* Turn the old bundle into a MLX bundle with the same stop-bit | |
683 | variety. */ | |
684 | if (t0 & 0x1) | |
685 | mlx = 0x5; | |
686 | else | |
687 | mlx = 0x4; | |
688 | ||
689 | if (template == 0x16) | |
690 | { | |
5e27d427 L |
691 | /* For BBB, we need to put nop.m in slot 0. We keep the original |
692 | predicate only if slot 0 isn't br. */ | |
693 | if (br_slot == 0) | |
694 | t0 = 0LL; | |
695 | else | |
696 | t0 &= PREDICATE_BITS << 5; | |
83b6bd86 L |
697 | t0 |= 0x1LL << (X4_SHIFT + 5); |
698 | } | |
699 | else | |
700 | { | |
701 | /* Keep the original instruction in slot 0. */ | |
702 | t0 &= 0x1ffffffffffLL << 5; | |
703 | } | |
704 | ||
705 | t0 |= mlx; | |
706 | ||
707 | /* Put brl in slot 1. */ | |
708 | t1 = br_code << 23; | |
709 | ||
710 | bfd_putl64 (t0, hit_addr); | |
711 | bfd_putl64 (t1, hit_addr + 8); | |
712 | return TRUE; | |
713 | } | |
714 | ||
03609792 | 715 | static void |
bbb268c3 | 716 | elfNN_ia64_relax_brl (bfd_byte *contents, bfd_vma off) |
03609792 | 717 | { |
fc3ab699 | 718 | int template; |
03609792 | 719 | bfd_byte *hit_addr; |
fc3ab699 | 720 | bfd_vma t0, t1, i0, i1, i2; |
03609792 L |
721 | |
722 | hit_addr = (bfd_byte *) (contents + off); | |
723 | hit_addr -= (long) hit_addr & 0x3; | |
fc3ab699 L |
724 | t0 = bfd_getl64 (hit_addr); |
725 | t1 = bfd_getl64 (hit_addr + 8); | |
03609792 | 726 | |
7e3102a7 | 727 | /* Keep the instruction in slot 0. */ |
fc3ab699 L |
728 | i0 = (t0 >> 5) & 0x1ffffffffffLL; |
729 | /* Use nop.b for slot 1. */ | |
730 | i1 = 0x4000000000LL; | |
7e3102a7 | 731 | /* For slot 2, turn brl into br by masking out bit 40. */ |
fc3ab699 | 732 | i2 = (t1 >> 23) & 0x0ffffffffffLL; |
7e3102a7 | 733 | |
fc3ab699 L |
734 | /* Turn a MLX bundle into a MBB bundle with the same stop-bit |
735 | variety. */ | |
736 | if (t0 & 0x1) | |
737 | template = 0x13; | |
738 | else | |
739 | template = 0x12; | |
740 | t0 = (i1 << 46) | (i0 << 5) | template; | |
741 | t1 = (i2 << 23) | (i1 >> 18); | |
7e3102a7 | 742 | |
fc3ab699 L |
743 | bfd_putl64 (t0, hit_addr); |
744 | bfd_putl64 (t1, hit_addr + 8); | |
03609792 | 745 | } |
fbbc3759 L |
746 | |
747 | /* Rename some of the generic section flags to better document how they | |
748 | are used here. */ | |
749 | #define skip_relax_pass_0 need_finalize_relax | |
750 | #define skip_relax_pass_1 has_gp_reloc | |
751 | ||
748abff6 | 752 | \f |
2c4c2bc0 | 753 | /* These functions do relaxation for IA-64 ELF. */ |
748abff6 | 754 | |
b34976b6 | 755 | static bfd_boolean |
eae50df2 L |
756 | elfNN_ia64_relax_section (bfd *abfd, asection *sec, |
757 | struct bfd_link_info *link_info, | |
758 | bfd_boolean *again) | |
748abff6 RH |
759 | { |
760 | struct one_fixup | |
761 | { | |
762 | struct one_fixup *next; | |
763 | asection *tsec; | |
764 | bfd_vma toff; | |
765 | bfd_vma trampoff; | |
766 | }; | |
767 | ||
768 | Elf_Internal_Shdr *symtab_hdr; | |
769 | Elf_Internal_Rela *internal_relocs; | |
748abff6 RH |
770 | Elf_Internal_Rela *irel, *irelend; |
771 | bfd_byte *contents; | |
6cdc0ccc | 772 | Elf_Internal_Sym *isymbuf = NULL; |
bbe66d08 | 773 | struct elfNN_ia64_link_hash_table *ia64_info; |
748abff6 | 774 | struct one_fixup *fixups = NULL; |
b34976b6 AM |
775 | bfd_boolean changed_contents = FALSE; |
776 | bfd_boolean changed_relocs = FALSE; | |
2c4c2bc0 | 777 | bfd_boolean changed_got = FALSE; |
fbbc3759 L |
778 | bfd_boolean skip_relax_pass_0 = TRUE; |
779 | bfd_boolean skip_relax_pass_1 = TRUE; | |
2c4c2bc0 | 780 | bfd_vma gp = 0; |
748abff6 | 781 | |
46f5aac8 KH |
782 | /* Assume we're not going to change any sizes, and we'll only need |
783 | one pass. */ | |
b34976b6 | 784 | *again = FALSE; |
748abff6 | 785 | |
c8a1f254 NS |
786 | if (link_info->relocatable) |
787 | (*link_info->callbacks->einfo) | |
788 | (_("%P%F: --relax and -r may not be used together\n")); | |
789 | ||
04b3329b | 790 | /* Don't even try to relax for non-ELF outputs. */ |
0eddce27 | 791 | if (!is_elf_hash_table (link_info->hash)) |
04b3329b L |
792 | return FALSE; |
793 | ||
c7996ad6 | 794 | /* Nothing to do if there are no relocations or there is no need for |
fbbc3759 | 795 | the current pass. */ |
748abff6 | 796 | if ((sec->flags & SEC_RELOC) == 0 |
c7996ad6 | 797 | || sec->reloc_count == 0 |
fbbc3759 L |
798 | || (link_info->relax_pass == 0 && sec->skip_relax_pass_0) |
799 | || (link_info->relax_pass == 1 && sec->skip_relax_pass_1)) | |
b34976b6 | 800 | return TRUE; |
748abff6 | 801 | |
748abff6 RH |
802 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
803 | ||
804 | /* Load the relocations for this section. */ | |
45d6a902 | 805 | internal_relocs = (_bfd_elf_link_read_relocs |
748abff6 RH |
806 | (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL, |
807 | link_info->keep_memory)); | |
808 | if (internal_relocs == NULL) | |
b34976b6 | 809 | return FALSE; |
748abff6 | 810 | |
bbe66d08 | 811 | ia64_info = elfNN_ia64_hash_table (link_info); |
748abff6 RH |
812 | irelend = internal_relocs + sec->reloc_count; |
813 | ||
748abff6 | 814 | /* Get the section contents. */ |
748abff6 RH |
815 | if (elf_section_data (sec)->this_hdr.contents != NULL) |
816 | contents = elf_section_data (sec)->this_hdr.contents; | |
817 | else | |
818 | { | |
eea6121a | 819 | if (!bfd_malloc_and_get_section (abfd, sec, &contents)) |
748abff6 RH |
820 | goto error_return; |
821 | } | |
822 | ||
2c4c2bc0 | 823 | for (irel = internal_relocs; irel < irelend; irel++) |
748abff6 | 824 | { |
2f9bd3f6 | 825 | unsigned long r_type = ELFNN_R_TYPE (irel->r_info); |
748abff6 | 826 | bfd_vma symaddr, reladdr, trampoff, toff, roff; |
748abff6 RH |
827 | asection *tsec; |
828 | struct one_fixup *f; | |
dc810e39 | 829 | bfd_size_type amt; |
2c4c2bc0 RH |
830 | bfd_boolean is_branch; |
831 | struct elfNN_ia64_dyn_sym_info *dyn_i; | |
bf8b15af | 832 | char symtype; |
748abff6 | 833 | |
2c4c2bc0 RH |
834 | switch (r_type) |
835 | { | |
836 | case R_IA64_PCREL21B: | |
837 | case R_IA64_PCREL21BI: | |
838 | case R_IA64_PCREL21M: | |
839 | case R_IA64_PCREL21F: | |
fbbc3759 L |
840 | /* In pass 1, all br relaxations are done. We can skip it. */ |
841 | if (link_info->relax_pass == 1) | |
c7996ad6 | 842 | continue; |
fbbc3759 | 843 | skip_relax_pass_0 = FALSE; |
2c4c2bc0 RH |
844 | is_branch = TRUE; |
845 | break; | |
846 | ||
03609792 | 847 | case R_IA64_PCREL60B: |
fbbc3759 L |
848 | /* We can't optimize brl to br in pass 0 since br relaxations |
849 | will increase the code size. Defer it to pass 1. */ | |
850 | if (link_info->relax_pass == 0) | |
03609792 | 851 | { |
fbbc3759 | 852 | skip_relax_pass_1 = FALSE; |
03609792 L |
853 | continue; |
854 | } | |
855 | is_branch = TRUE; | |
856 | break; | |
857 | ||
2c4c2bc0 RH |
858 | case R_IA64_LTOFF22X: |
859 | case R_IA64_LDXMOV: | |
fbbc3759 L |
860 | /* We can't relax ldx/mov in pass 0 since br relaxations will |
861 | increase the code size. Defer it to pass 1. */ | |
862 | if (link_info->relax_pass == 0) | |
c7996ad6 | 863 | { |
fbbc3759 | 864 | skip_relax_pass_1 = FALSE; |
c7996ad6 L |
865 | continue; |
866 | } | |
2c4c2bc0 RH |
867 | is_branch = FALSE; |
868 | break; | |
869 | ||
870 | default: | |
871 | continue; | |
872 | } | |
748abff6 RH |
873 | |
874 | /* Get the value of the symbol referred to by the reloc. */ | |
bbe66d08 | 875 | if (ELFNN_R_SYM (irel->r_info) < symtab_hdr->sh_info) |
748abff6 RH |
876 | { |
877 | /* A local symbol. */ | |
6cdc0ccc AM |
878 | Elf_Internal_Sym *isym; |
879 | ||
880 | /* Read this BFD's local symbols. */ | |
881 | if (isymbuf == NULL) | |
882 | { | |
883 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; | |
884 | if (isymbuf == NULL) | |
885 | isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, | |
886 | symtab_hdr->sh_info, 0, | |
887 | NULL, NULL, NULL); | |
888 | if (isymbuf == 0) | |
889 | goto error_return; | |
890 | } | |
891 | ||
60d8b524 | 892 | isym = isymbuf + ELFNN_R_SYM (irel->r_info); |
6cdc0ccc | 893 | if (isym->st_shndx == SHN_UNDEF) |
4cc11e76 | 894 | continue; /* We can't do anything with undefined symbols. */ |
6cdc0ccc | 895 | else if (isym->st_shndx == SHN_ABS) |
748abff6 | 896 | tsec = bfd_abs_section_ptr; |
6cdc0ccc | 897 | else if (isym->st_shndx == SHN_COMMON) |
748abff6 | 898 | tsec = bfd_com_section_ptr; |
6cdc0ccc | 899 | else if (isym->st_shndx == SHN_IA_64_ANSI_COMMON) |
d9cf1b54 | 900 | tsec = bfd_com_section_ptr; |
3e932841 | 901 | else |
6cdc0ccc | 902 | tsec = bfd_section_from_elf_index (abfd, isym->st_shndx); |
748abff6 | 903 | |
6cdc0ccc | 904 | toff = isym->st_value; |
2c4c2bc0 | 905 | dyn_i = get_dyn_sym_info (ia64_info, NULL, abfd, irel, FALSE); |
bf8b15af | 906 | symtype = ELF_ST_TYPE (isym->st_info); |
748abff6 RH |
907 | } |
908 | else | |
909 | { | |
910 | unsigned long indx; | |
911 | struct elf_link_hash_entry *h; | |
748abff6 | 912 | |
bbe66d08 | 913 | indx = ELFNN_R_SYM (irel->r_info) - symtab_hdr->sh_info; |
748abff6 RH |
914 | h = elf_sym_hashes (abfd)[indx]; |
915 | BFD_ASSERT (h != NULL); | |
916 | ||
917 | while (h->root.type == bfd_link_hash_indirect | |
918 | || h->root.type == bfd_link_hash_warning) | |
919 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
920 | ||
b34976b6 | 921 | dyn_i = get_dyn_sym_info (ia64_info, h, abfd, irel, FALSE); |
748abff6 RH |
922 | |
923 | /* For branches to dynamic symbols, we're interested instead | |
924 | in a branch to the PLT entry. */ | |
2c4c2bc0 | 925 | if (is_branch && dyn_i && dyn_i->want_plt2) |
748abff6 | 926 | { |
2f9bd3f6 RH |
927 | /* Internal branches shouldn't be sent to the PLT. |
928 | Leave this for now and we'll give an error later. */ | |
929 | if (r_type != R_IA64_PCREL21B) | |
930 | continue; | |
931 | ||
cc3bd654 | 932 | tsec = ia64_info->root.splt; |
748abff6 | 933 | toff = dyn_i->plt2_offset; |
3fa1d917 | 934 | BFD_ASSERT (irel->r_addend == 0); |
748abff6 | 935 | } |
2c4c2bc0 RH |
936 | |
937 | /* Can't do anything else with dynamic symbols. */ | |
986a241f | 938 | else if (elfNN_ia64_dynamic_symbol_p (h, link_info, r_type)) |
2c4c2bc0 RH |
939 | continue; |
940 | ||
748abff6 RH |
941 | else |
942 | { | |
4cc11e76 | 943 | /* We can't do anything with undefined symbols. */ |
748abff6 RH |
944 | if (h->root.type == bfd_link_hash_undefined |
945 | || h->root.type == bfd_link_hash_undefweak) | |
946 | continue; | |
947 | ||
948 | tsec = h->root.u.def.section; | |
949 | toff = h->root.u.def.value; | |
950 | } | |
bf8b15af L |
951 | |
952 | symtype = h->type; | |
5dd23ec1 | 953 | } |
3fa1d917 | 954 | |
9f2e92c5 | 955 | if (tsec->sec_info_type == ELF_INFO_TYPE_MERGE) |
bf8b15af L |
956 | { |
957 | /* At this stage in linking, no SEC_MERGE symbol has been | |
958 | adjusted, so all references to such symbols need to be | |
959 | passed through _bfd_merged_section_offset. (Later, in | |
960 | relocate_section, all SEC_MERGE symbols *except* for | |
961 | section symbols have been adjusted.) | |
962 | ||
963 | gas may reduce relocations against symbols in SEC_MERGE | |
964 | sections to a relocation against the section symbol when | |
965 | the original addend was zero. When the reloc is against | |
966 | a section symbol we should include the addend in the | |
967 | offset passed to _bfd_merged_section_offset, since the | |
968 | location of interest is the original symbol. On the | |
969 | other hand, an access to "sym+addend" where "sym" is not | |
970 | a section symbol should not include the addend; Such an | |
971 | access is presumed to be an offset from "sym"; The | |
972 | location of interest is just "sym". */ | |
973 | if (symtype == STT_SECTION) | |
974 | toff += irel->r_addend; | |
f12123c0 | 975 | |
bf8b15af L |
976 | toff = _bfd_merged_section_offset (abfd, &tsec, |
977 | elf_section_data (tsec)->sec_info, | |
978 | toff); | |
979 | ||
980 | if (symtype != STT_SECTION) | |
981 | toff += irel->r_addend; | |
982 | } | |
9f2e92c5 L |
983 | else |
984 | toff += irel->r_addend; | |
985 | ||
3fa1d917 | 986 | symaddr = tsec->output_section->vma + tsec->output_offset + toff; |
748abff6 RH |
987 | |
988 | roff = irel->r_offset; | |
748abff6 | 989 | |
2c4c2bc0 RH |
990 | if (is_branch) |
991 | { | |
de0d9f33 L |
992 | bfd_signed_vma offset; |
993 | ||
2c4c2bc0 RH |
994 | reladdr = (sec->output_section->vma |
995 | + sec->output_offset | |
996 | + roff) & (bfd_vma) -4; | |
748abff6 | 997 | |
feddcd0d L |
998 | /* The .plt section is aligned at 32byte and the .text section |
999 | is aligned at 64byte. The .text section is right after the | |
1000 | .plt section. After the first relaxation pass, linker may | |
1001 | increase the gap between the .plt and .text sections up | |
1002 | to 32byte. We assume linker will always insert 32byte | |
1003 | between the .plt and .text sections after the the first | |
1004 | relaxation pass. */ | |
cc3bd654 | 1005 | if (tsec == ia64_info->root.splt) |
feddcd0d L |
1006 | offset = -0x1000000 + 32; |
1007 | else | |
1008 | offset = -0x1000000; | |
1009 | ||
2c4c2bc0 | 1010 | /* If the branch is in range, no need to do anything. */ |
feddcd0d | 1011 | if ((bfd_signed_vma) (symaddr - reladdr) >= offset |
2c4c2bc0 | 1012 | && (bfd_signed_vma) (symaddr - reladdr) <= 0x0FFFFF0) |
03609792 L |
1013 | { |
1014 | /* If the 60-bit branch is in 21-bit range, optimize it. */ | |
1015 | if (r_type == R_IA64_PCREL60B) | |
1016 | { | |
bbb268c3 | 1017 | elfNN_ia64_relax_brl (contents, roff); |
03609792 L |
1018 | |
1019 | irel->r_info | |
7e3102a7 | 1020 | = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info), |
03609792 L |
1021 | R_IA64_PCREL21B); |
1022 | ||
1023 | /* If the original relocation offset points to slot | |
1024 | 1, change it to slot 2. */ | |
1025 | if ((irel->r_offset & 3) == 1) | |
1026 | irel->r_offset += 1; | |
1027 | } | |
1028 | ||
1029 | continue; | |
1030 | } | |
1031 | else if (r_type == R_IA64_PCREL60B) | |
2c4c2bc0 | 1032 | continue; |
83b6bd86 L |
1033 | else if (elfNN_ia64_relax_br (contents, roff)) |
1034 | { | |
1035 | irel->r_info | |
1036 | = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info), | |
1037 | R_IA64_PCREL60B); | |
1038 | ||
1039 | /* Make the relocation offset point to slot 1. */ | |
1040 | irel->r_offset = (irel->r_offset & ~((bfd_vma) 0x3)) + 1; | |
1041 | continue; | |
1042 | } | |
748abff6 | 1043 | |
e525914f L |
1044 | /* We can't put a trampoline in a .init/.fini section. Issue |
1045 | an error. */ | |
1046 | if (strcmp (sec->output_section->name, ".init") == 0 | |
1047 | || strcmp (sec->output_section->name, ".fini") == 0) | |
1048 | { | |
1049 | (*_bfd_error_handler) | |
d003868e AM |
1050 | (_("%B: Can't relax br at 0x%lx in section `%A'. Please use brl or indirect branch."), |
1051 | sec->owner, sec, (unsigned long) roff); | |
e525914f L |
1052 | bfd_set_error (bfd_error_bad_value); |
1053 | goto error_return; | |
1054 | } | |
1055 | ||
2c4c2bc0 | 1056 | /* If the branch and target are in the same section, you've |
c5509b92 L |
1057 | got one honking big section and we can't help you unless |
1058 | you are branching backwards. You'll get an error message | |
1059 | later. */ | |
1060 | if (tsec == sec && toff > roff) | |
2c4c2bc0 | 1061 | continue; |
748abff6 | 1062 | |
2c4c2bc0 RH |
1063 | /* Look for an existing fixup to this address. */ |
1064 | for (f = fixups; f ; f = f->next) | |
1065 | if (f->tsec == tsec && f->toff == toff) | |
1066 | break; | |
748abff6 | 1067 | |
2c4c2bc0 | 1068 | if (f == NULL) |
748abff6 | 1069 | { |
2c4c2bc0 RH |
1070 | /* Two alternatives: If it's a branch to a PLT entry, we can |
1071 | make a copy of the FULL_PLT entry. Otherwise, we'll have | |
1072 | to use a `brl' insn to get where we're going. */ | |
1073 | ||
1074 | size_t size; | |
1075 | ||
cc3bd654 | 1076 | if (tsec == ia64_info->root.splt) |
2c4c2bc0 RH |
1077 | size = sizeof (plt_full_entry); |
1078 | else | |
3f7deb8a | 1079 | size = oor_branch_size; |
748abff6 | 1080 | |
2c4c2bc0 | 1081 | /* Resize the current section to make room for the new branch. */ |
eea6121a | 1082 | trampoff = (sec->size + 15) & (bfd_vma) -16; |
de0d9f33 L |
1083 | |
1084 | /* If trampoline is out of range, there is nothing we | |
1085 | can do. */ | |
1086 | offset = trampoff - (roff & (bfd_vma) -4); | |
1087 | if (offset < -0x1000000 || offset > 0x0FFFFF0) | |
1088 | continue; | |
1089 | ||
2c4c2bc0 RH |
1090 | amt = trampoff + size; |
1091 | contents = (bfd_byte *) bfd_realloc (contents, amt); | |
1092 | if (contents == NULL) | |
1093 | goto error_return; | |
eea6121a | 1094 | sec->size = amt; |
748abff6 | 1095 | |
cc3bd654 | 1096 | if (tsec == ia64_info->root.splt) |
2c4c2bc0 RH |
1097 | { |
1098 | memcpy (contents + trampoff, plt_full_entry, size); | |
748abff6 | 1099 | |
2c4c2bc0 RH |
1100 | /* Hijack the old relocation for use as the PLTOFF reloc. */ |
1101 | irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info), | |
1102 | R_IA64_PLTOFF22); | |
1103 | irel->r_offset = trampoff; | |
1104 | } | |
1105 | else | |
1106 | { | |
3f7deb8a L |
1107 | if (size == sizeof (oor_ip)) |
1108 | { | |
1109 | memcpy (contents + trampoff, oor_ip, size); | |
1110 | irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info), | |
1111 | R_IA64_PCREL64I); | |
1112 | irel->r_addend -= 16; | |
1113 | irel->r_offset = trampoff + 2; | |
1114 | } | |
1115 | else | |
1116 | { | |
1117 | memcpy (contents + trampoff, oor_brl, size); | |
1118 | irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info), | |
1119 | R_IA64_PCREL60B); | |
1120 | irel->r_offset = trampoff + 2; | |
1121 | } | |
1122 | ||
2c4c2bc0 RH |
1123 | } |
1124 | ||
1125 | /* Record the fixup so we don't do it again this section. */ | |
1126 | f = (struct one_fixup *) | |
1127 | bfd_malloc ((bfd_size_type) sizeof (*f)); | |
1128 | f->next = fixups; | |
1129 | f->tsec = tsec; | |
1130 | f->toff = toff; | |
1131 | f->trampoff = trampoff; | |
1132 | fixups = f; | |
748abff6 | 1133 | } |
2c4c2bc0 RH |
1134 | else |
1135 | { | |
de0d9f33 L |
1136 | /* If trampoline is out of range, there is nothing we |
1137 | can do. */ | |
1138 | offset = f->trampoff - (roff & (bfd_vma) -4); | |
1139 | if (offset < -0x1000000 || offset > 0x0FFFFF0) | |
1140 | continue; | |
1141 | ||
2c4c2bc0 RH |
1142 | /* Nop out the reloc, since we're finalizing things here. */ |
1143 | irel->r_info = ELFNN_R_INFO (0, R_IA64_NONE); | |
1144 | } | |
1145 | ||
de0d9f33 | 1146 | /* Fix up the existing branch to hit the trampoline. */ |
bbb268c3 JW |
1147 | if (elfNN_ia64_install_value (contents + roff, offset, r_type) |
1148 | != bfd_reloc_ok) | |
2c4c2bc0 | 1149 | goto error_return; |
748abff6 | 1150 | |
2c4c2bc0 RH |
1151 | changed_contents = TRUE; |
1152 | changed_relocs = TRUE; | |
748abff6 RH |
1153 | } |
1154 | else | |
1155 | { | |
2c4c2bc0 RH |
1156 | /* Fetch the gp. */ |
1157 | if (gp == 0) | |
1158 | { | |
1159 | bfd *obfd = sec->output_section->owner; | |
1160 | gp = _bfd_get_gp_value (obfd); | |
1161 | if (gp == 0) | |
1162 | { | |
1163 | if (!elfNN_ia64_choose_gp (obfd, link_info)) | |
1164 | goto error_return; | |
1165 | gp = _bfd_get_gp_value (obfd); | |
1166 | } | |
1167 | } | |
748abff6 | 1168 | |
2c4c2bc0 | 1169 | /* If the data is out of range, do nothing. */ |
484a4f9c RH |
1170 | if ((bfd_signed_vma) (symaddr - gp) >= 0x200000 |
1171 | ||(bfd_signed_vma) (symaddr - gp) < -0x200000) | |
2c4c2bc0 | 1172 | continue; |
748abff6 | 1173 | |
2c4c2bc0 RH |
1174 | if (r_type == R_IA64_LTOFF22X) |
1175 | { | |
1176 | irel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (irel->r_info), | |
1177 | R_IA64_GPREL22); | |
1178 | changed_relocs = TRUE; | |
1179 | if (dyn_i->want_gotx) | |
1180 | { | |
1181 | dyn_i->want_gotx = 0; | |
1182 | changed_got |= !dyn_i->want_got; | |
1183 | } | |
1184 | } | |
1185 | else | |
1186 | { | |
bbb268c3 | 1187 | elfNN_ia64_relax_ldxmov (contents, roff); |
2c4c2bc0 RH |
1188 | irel->r_info = ELFNN_R_INFO (0, R_IA64_NONE); |
1189 | changed_contents = TRUE; | |
1190 | changed_relocs = TRUE; | |
1191 | } | |
1192 | } | |
748abff6 RH |
1193 | } |
1194 | ||
2c4c2bc0 RH |
1195 | /* ??? If we created fixups, this may push the code segment large |
1196 | enough that the data segment moves, which will change the GP. | |
1197 | Reset the GP so that we re-calculate next round. We need to | |
1198 | do this at the _beginning_ of the next round; now will not do. */ | |
f12123c0 | 1199 | |
748abff6 RH |
1200 | /* Clean up and go home. */ |
1201 | while (fixups) | |
1202 | { | |
1203 | struct one_fixup *f = fixups; | |
1204 | fixups = fixups->next; | |
1205 | free (f); | |
1206 | } | |
1207 | ||
6cdc0ccc AM |
1208 | if (isymbuf != NULL |
1209 | && symtab_hdr->contents != (unsigned char *) isymbuf) | |
748abff6 RH |
1210 | { |
1211 | if (! link_info->keep_memory) | |
6cdc0ccc | 1212 | free (isymbuf); |
748abff6 RH |
1213 | else |
1214 | { | |
6cdc0ccc AM |
1215 | /* Cache the symbols for elf_link_input_bfd. */ |
1216 | symtab_hdr->contents = (unsigned char *) isymbuf; | |
748abff6 RH |
1217 | } |
1218 | } | |
1219 | ||
6cdc0ccc AM |
1220 | if (contents != NULL |
1221 | && elf_section_data (sec)->this_hdr.contents != contents) | |
748abff6 | 1222 | { |
6cdc0ccc AM |
1223 | if (!changed_contents && !link_info->keep_memory) |
1224 | free (contents); | |
748abff6 RH |
1225 | else |
1226 | { | |
6cdc0ccc AM |
1227 | /* Cache the section contents for elf_link_input_bfd. */ |
1228 | elf_section_data (sec)->this_hdr.contents = contents; | |
748abff6 RH |
1229 | } |
1230 | } | |
1231 | ||
6cdc0ccc AM |
1232 | if (elf_section_data (sec)->relocs != internal_relocs) |
1233 | { | |
1234 | if (!changed_relocs) | |
1235 | free (internal_relocs); | |
1236 | else | |
1237 | elf_section_data (sec)->relocs = internal_relocs; | |
1238 | } | |
1239 | ||
2c4c2bc0 RH |
1240 | if (changed_got) |
1241 | { | |
1242 | struct elfNN_ia64_allocate_data data; | |
1243 | data.info = link_info; | |
1244 | data.ofs = 0; | |
9d73f260 | 1245 | ia64_info->self_dtpmod_offset = (bfd_vma) -1; |
2c4c2bc0 RH |
1246 | |
1247 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_global_data_got, &data); | |
1248 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_global_fptr_got, &data); | |
1249 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_local_got, &data); | |
cc3bd654 | 1250 | ia64_info->root.sgot->size = data.ofs; |
2c4c2bc0 | 1251 | |
90b263f3 | 1252 | if (ia64_info->root.dynamic_sections_created |
cc3bd654 | 1253 | && ia64_info->root.srelgot != NULL) |
4a78a1f4 AS |
1254 | { |
1255 | /* Resize .rela.got. */ | |
cc3bd654 | 1256 | ia64_info->root.srelgot->size = 0; |
4a78a1f4 AS |
1257 | if (link_info->shared |
1258 | && ia64_info->self_dtpmod_offset != (bfd_vma) -1) | |
cc3bd654 | 1259 | ia64_info->root.srelgot->size += sizeof (ElfNN_External_Rela); |
4a78a1f4 AS |
1260 | data.only_got = TRUE; |
1261 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_dynrel_entries, | |
1262 | &data); | |
1263 | } | |
2c4c2bc0 RH |
1264 | } |
1265 | ||
fbbc3759 L |
1266 | if (link_info->relax_pass == 0) |
1267 | { | |
1268 | /* Pass 0 is only needed to relax br. */ | |
1269 | sec->skip_relax_pass_0 = skip_relax_pass_0; | |
1270 | sec->skip_relax_pass_1 = skip_relax_pass_1; | |
1271 | } | |
c7996ad6 | 1272 | |
748abff6 | 1273 | *again = changed_contents || changed_relocs; |
b34976b6 | 1274 | return TRUE; |
748abff6 RH |
1275 | |
1276 | error_return: | |
6cdc0ccc AM |
1277 | if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents) |
1278 | free (isymbuf); | |
1279 | if (contents != NULL | |
1280 | && elf_section_data (sec)->this_hdr.contents != contents) | |
1281 | free (contents); | |
1282 | if (internal_relocs != NULL | |
1283 | && elf_section_data (sec)->relocs != internal_relocs) | |
1284 | free (internal_relocs); | |
b34976b6 | 1285 | return FALSE; |
748abff6 | 1286 | } |
fbbc3759 L |
1287 | #undef skip_relax_pass_0 |
1288 | #undef skip_relax_pass_1 | |
2c4c2bc0 RH |
1289 | |
1290 | static void | |
eae50df2 | 1291 | elfNN_ia64_relax_ldxmov (bfd_byte *contents, bfd_vma off) |
2c4c2bc0 RH |
1292 | { |
1293 | int shift, r1, r3; | |
1294 | bfd_vma dword, insn; | |
1295 | ||
1296 | switch ((int)off & 0x3) | |
1297 | { | |
1298 | case 0: shift = 5; break; | |
1299 | case 1: shift = 14; off += 3; break; | |
1300 | case 2: shift = 23; off += 6; break; | |
60d8b524 | 1301 | default: |
2c4c2bc0 RH |
1302 | abort (); |
1303 | } | |
1304 | ||
bbb268c3 | 1305 | dword = bfd_getl64 (contents + off); |
2c4c2bc0 RH |
1306 | insn = (dword >> shift) & 0x1ffffffffffLL; |
1307 | ||
1308 | r1 = (insn >> 6) & 127; | |
1309 | r3 = (insn >> 20) & 127; | |
1310 | if (r1 == r3) | |
1311 | insn = 0x8000000; /* nop */ | |
1312 | else | |
1313 | insn = (insn & 0x7f01fff) | 0x10800000000LL; /* (qp) mov r1 = r3 */ | |
1314 | ||
1315 | dword &= ~(0x1ffffffffffLL << shift); | |
1316 | dword |= (insn << shift); | |
bbb268c3 | 1317 | bfd_putl64 (dword, contents + off); |
2c4c2bc0 | 1318 | } |
800eeca4 | 1319 | \f |
b34976b6 | 1320 | /* Return TRUE if NAME is an unwind table section name. */ |
81545d45 | 1321 | |
b34976b6 | 1322 | static inline bfd_boolean |
0112cd26 | 1323 | is_unwind_section_name (bfd *abfd, const char *name) |
81545d45 | 1324 | { |
d9cf1b54 AM |
1325 | if (elfNN_ia64_hpux_vec (abfd->xvec) |
1326 | && !strcmp (name, ELF_STRING_ia64_unwind_hdr)) | |
b34976b6 | 1327 | return FALSE; |
d9cf1b54 | 1328 | |
0112cd26 NC |
1329 | return ((CONST_STRNEQ (name, ELF_STRING_ia64_unwind) |
1330 | && ! CONST_STRNEQ (name, ELF_STRING_ia64_unwind_info)) | |
1331 | || CONST_STRNEQ (name, ELF_STRING_ia64_unwind_once)); | |
81545d45 RH |
1332 | } |
1333 | ||
800eeca4 | 1334 | /* Handle an IA-64 specific section when reading an object file. This |
6dc132d9 L |
1335 | is called when bfd_section_from_shdr finds a section with an unknown |
1336 | type. */ | |
800eeca4 | 1337 | |
b34976b6 | 1338 | static bfd_boolean |
6dc132d9 L |
1339 | elfNN_ia64_section_from_shdr (bfd *abfd, |
1340 | Elf_Internal_Shdr *hdr, | |
1341 | const char *name, | |
1342 | int shindex) | |
800eeca4 JW |
1343 | { |
1344 | asection *newsect; | |
1345 | ||
1346 | /* There ought to be a place to keep ELF backend specific flags, but | |
1347 | at the moment there isn't one. We just keep track of the | |
1348 | sections by their name, instead. Fortunately, the ABI gives | |
1349 | suggested names for all the MIPS specific sections, so we will | |
1350 | probably get away with this. */ | |
1351 | switch (hdr->sh_type) | |
1352 | { | |
1353 | case SHT_IA_64_UNWIND: | |
d9cf1b54 | 1354 | case SHT_IA_64_HP_OPT_ANOT: |
800eeca4 JW |
1355 | break; |
1356 | ||
1357 | case SHT_IA_64_EXT: | |
1358 | if (strcmp (name, ELF_STRING_ia64_archext) != 0) | |
b34976b6 | 1359 | return FALSE; |
800eeca4 JW |
1360 | break; |
1361 | ||
1362 | default: | |
b34976b6 | 1363 | return FALSE; |
800eeca4 JW |
1364 | } |
1365 | ||
6dc132d9 | 1366 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
b34976b6 | 1367 | return FALSE; |
800eeca4 JW |
1368 | newsect = hdr->bfd_section; |
1369 | ||
b34976b6 | 1370 | return TRUE; |
fa152c49 JW |
1371 | } |
1372 | ||
1373 | /* Convert IA-64 specific section flags to bfd internal section flags. */ | |
1374 | ||
1375 | /* ??? There is no bfd internal flag equivalent to the SHF_IA_64_NORECOV | |
1376 | flag. */ | |
1377 | ||
b34976b6 | 1378 | static bfd_boolean |
eae50df2 L |
1379 | elfNN_ia64_section_flags (flagword *flags, |
1380 | const Elf_Internal_Shdr *hdr) | |
fa152c49 | 1381 | { |
800eeca4 | 1382 | if (hdr->sh_flags & SHF_IA_64_SHORT) |
fa152c49 | 1383 | *flags |= SEC_SMALL_DATA; |
800eeca4 | 1384 | |
b34976b6 | 1385 | return TRUE; |
800eeca4 JW |
1386 | } |
1387 | ||
1388 | /* Set the correct type for an IA-64 ELF section. We do this by the | |
1389 | section name, which is a hack, but ought to work. */ | |
1390 | ||
b34976b6 | 1391 | static bfd_boolean |
eae50df2 L |
1392 | elfNN_ia64_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr, |
1393 | asection *sec) | |
800eeca4 JW |
1394 | { |
1395 | register const char *name; | |
1396 | ||
1397 | name = bfd_get_section_name (abfd, sec); | |
1398 | ||
d9cf1b54 | 1399 | if (is_unwind_section_name (abfd, name)) |
81545d45 RH |
1400 | { |
1401 | /* We don't have the sections numbered at this point, so sh_info | |
1402 | is set later, in elfNN_ia64_final_write_processing. */ | |
1403 | hdr->sh_type = SHT_IA_64_UNWIND; | |
1404 | hdr->sh_flags |= SHF_LINK_ORDER; | |
1405 | } | |
800eeca4 JW |
1406 | else if (strcmp (name, ELF_STRING_ia64_archext) == 0) |
1407 | hdr->sh_type = SHT_IA_64_EXT; | |
d9cf1b54 AM |
1408 | else if (strcmp (name, ".HP.opt_annot") == 0) |
1409 | hdr->sh_type = SHT_IA_64_HP_OPT_ANOT; | |
800eeca4 | 1410 | else if (strcmp (name, ".reloc") == 0) |
5e8d7549 NC |
1411 | /* This is an ugly, but unfortunately necessary hack that is |
1412 | needed when producing EFI binaries on IA-64. It tells | |
1413 | elf.c:elf_fake_sections() not to consider ".reloc" as a section | |
1414 | containing ELF relocation info. We need this hack in order to | |
1415 | be able to generate ELF binaries that can be translated into | |
1416 | EFI applications (which are essentially COFF objects). Those | |
1417 | files contain a COFF ".reloc" section inside an ELFNN object, | |
1418 | which would normally cause BFD to segfault because it would | |
1419 | attempt to interpret this section as containing relocation | |
1420 | entries for section "oc". With this hack enabled, ".reloc" | |
1421 | will be treated as a normal data section, which will avoid the | |
1422 | segfault. However, you won't be able to create an ELFNN binary | |
1423 | with a section named "oc" that needs relocations, but that's | |
1424 | the kind of ugly side-effects you get when detecting section | |
1425 | types based on their names... In practice, this limitation is | |
1426 | unlikely to bite. */ | |
800eeca4 JW |
1427 | hdr->sh_type = SHT_PROGBITS; |
1428 | ||
1429 | if (sec->flags & SEC_SMALL_DATA) | |
1430 | hdr->sh_flags |= SHF_IA_64_SHORT; | |
1431 | ||
75eb734c SE |
1432 | /* Some HP linkers look for the SHF_IA_64_HP_TLS flag instead of SHF_TLS. */ |
1433 | ||
1434 | if (elfNN_ia64_hpux_vec (abfd->xvec) && (sec->flags & SHF_TLS)) | |
1435 | hdr->sh_flags |= SHF_IA_64_HP_TLS; | |
1436 | ||
b34976b6 | 1437 | return TRUE; |
800eeca4 JW |
1438 | } |
1439 | ||
81545d45 RH |
1440 | /* The final processing done just before writing out an IA-64 ELF |
1441 | object file. */ | |
1442 | ||
1443 | static void | |
eae50df2 L |
1444 | elfNN_ia64_final_write_processing (bfd *abfd, |
1445 | bfd_boolean linker ATTRIBUTE_UNUSED) | |
81545d45 RH |
1446 | { |
1447 | Elf_Internal_Shdr *hdr; | |
38ce5b11 | 1448 | asection *s; |
81545d45 RH |
1449 | |
1450 | for (s = abfd->sections; s; s = s->next) | |
1451 | { | |
1452 | hdr = &elf_section_data (s)->this_hdr; | |
1453 | switch (hdr->sh_type) | |
1454 | { | |
1455 | case SHT_IA_64_UNWIND: | |
38ce5b11 L |
1456 | /* The IA-64 processor-specific ABI requires setting sh_link |
1457 | to the unwind section, whereas HP-UX requires sh_info to | |
1458 | do so. For maximum compatibility, we'll set both for | |
1459 | now... */ | |
1460 | hdr->sh_info = hdr->sh_link; | |
81545d45 RH |
1461 | break; |
1462 | } | |
1463 | } | |
9d46020e AM |
1464 | |
1465 | if (! elf_flags_init (abfd)) | |
1466 | { | |
1467 | unsigned long flags = 0; | |
1468 | ||
1469 | if (abfd->xvec->byteorder == BFD_ENDIAN_BIG) | |
1470 | flags |= EF_IA_64_BE; | |
1471 | if (bfd_get_mach (abfd) == bfd_mach_ia64_elf64) | |
1472 | flags |= EF_IA_64_ABI64; | |
1473 | ||
1474 | elf_elfheader(abfd)->e_flags = flags; | |
b34976b6 | 1475 | elf_flags_init (abfd) = TRUE; |
9d46020e | 1476 | } |
81545d45 RH |
1477 | } |
1478 | ||
800eeca4 JW |
1479 | /* Hook called by the linker routine which adds symbols from an object |
1480 | file. We use it to put .comm items in .sbss, and not .bss. */ | |
1481 | ||
b34976b6 | 1482 | static bfd_boolean |
a30e5f5f AM |
1483 | elfNN_ia64_add_symbol_hook (bfd *abfd, |
1484 | struct bfd_link_info *info, | |
eae50df2 | 1485 | Elf_Internal_Sym *sym, |
a30e5f5f AM |
1486 | const char **namep ATTRIBUTE_UNUSED, |
1487 | flagword *flagsp ATTRIBUTE_UNUSED, | |
1488 | asection **secp, | |
1489 | bfd_vma *valp) | |
800eeca4 JW |
1490 | { |
1491 | if (sym->st_shndx == SHN_COMMON | |
1049f94e | 1492 | && !info->relocatable |
c0846b23 | 1493 | && sym->st_size <= elf_gp_size (abfd)) |
800eeca4 JW |
1494 | { |
1495 | /* Common symbols less than or equal to -G nn bytes are | |
1496 | automatically put into .sbss. */ | |
1497 | ||
1498 | asection *scomm = bfd_get_section_by_name (abfd, ".scommon"); | |
1499 | ||
1500 | if (scomm == NULL) | |
1501 | { | |
3496cb2a L |
1502 | scomm = bfd_make_section_with_flags (abfd, ".scommon", |
1503 | (SEC_ALLOC | |
1504 | | SEC_IS_COMMON | |
1505 | | SEC_LINKER_CREATED)); | |
1506 | if (scomm == NULL) | |
b34976b6 | 1507 | return FALSE; |
800eeca4 JW |
1508 | } |
1509 | ||
1510 | *secp = scomm; | |
1511 | *valp = sym->st_size; | |
1512 | } | |
1513 | ||
b34976b6 | 1514 | return TRUE; |
800eeca4 JW |
1515 | } |
1516 | ||
1517 | /* Return the number of additional phdrs we will need. */ | |
1518 | ||
1519 | static int | |
a6b96beb AM |
1520 | elfNN_ia64_additional_program_headers (bfd *abfd, |
1521 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
800eeca4 JW |
1522 | { |
1523 | asection *s; | |
1524 | int ret = 0; | |
1525 | ||
1526 | /* See if we need a PT_IA_64_ARCHEXT segment. */ | |
1527 | s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_archext); | |
1528 | if (s && (s->flags & SEC_LOAD)) | |
1529 | ++ret; | |
1530 | ||
81545d45 RH |
1531 | /* Count how many PT_IA_64_UNWIND segments we need. */ |
1532 | for (s = abfd->sections; s; s = s->next) | |
d9cf1b54 | 1533 | if (is_unwind_section_name (abfd, s->name) && (s->flags & SEC_LOAD)) |
81545d45 | 1534 | ++ret; |
800eeca4 JW |
1535 | |
1536 | return ret; | |
1537 | } | |
1538 | ||
b34976b6 | 1539 | static bfd_boolean |
8ded5a0f AM |
1540 | elfNN_ia64_modify_segment_map (bfd *abfd, |
1541 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
800eeca4 JW |
1542 | { |
1543 | struct elf_segment_map *m, **pm; | |
81545d45 | 1544 | Elf_Internal_Shdr *hdr; |
800eeca4 JW |
1545 | asection *s; |
1546 | ||
1547 | /* If we need a PT_IA_64_ARCHEXT segment, it must come before | |
1548 | all PT_LOAD segments. */ | |
1549 | s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_archext); | |
1550 | if (s && (s->flags & SEC_LOAD)) | |
1551 | { | |
1552 | for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) | |
1553 | if (m->p_type == PT_IA_64_ARCHEXT) | |
1554 | break; | |
1555 | if (m == NULL) | |
1556 | { | |
dc810e39 AM |
1557 | m = ((struct elf_segment_map *) |
1558 | bfd_zalloc (abfd, (bfd_size_type) sizeof *m)); | |
800eeca4 | 1559 | if (m == NULL) |
b34976b6 | 1560 | return FALSE; |
800eeca4 JW |
1561 | |
1562 | m->p_type = PT_IA_64_ARCHEXT; | |
1563 | m->count = 1; | |
1564 | m->sections[0] = s; | |
1565 | ||
1566 | /* We want to put it after the PHDR and INTERP segments. */ | |
1567 | pm = &elf_tdata (abfd)->segment_map; | |
1568 | while (*pm != NULL | |
1569 | && ((*pm)->p_type == PT_PHDR | |
1570 | || (*pm)->p_type == PT_INTERP)) | |
1571 | pm = &(*pm)->next; | |
1572 | ||
1573 | m->next = *pm; | |
1574 | *pm = m; | |
1575 | } | |
1576 | } | |
1577 | ||
81545d45 RH |
1578 | /* Install PT_IA_64_UNWIND segments, if needed. */ |
1579 | for (s = abfd->sections; s; s = s->next) | |
800eeca4 | 1580 | { |
81545d45 RH |
1581 | hdr = &elf_section_data (s)->this_hdr; |
1582 | if (hdr->sh_type != SHT_IA_64_UNWIND) | |
1583 | continue; | |
1584 | ||
1585 | if (s && (s->flags & SEC_LOAD)) | |
800eeca4 | 1586 | { |
81545d45 | 1587 | for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) |
d9cf1b54 AM |
1588 | if (m->p_type == PT_IA_64_UNWIND) |
1589 | { | |
40c97fc6 AM |
1590 | int i; |
1591 | ||
d9cf1b54 AM |
1592 | /* Look through all sections in the unwind segment |
1593 | for a match since there may be multiple sections | |
1594 | to a segment. */ | |
40c97fc6 AM |
1595 | for (i = m->count - 1; i >= 0; --i) |
1596 | if (m->sections[i] == s) | |
1597 | break; | |
d9cf1b54 | 1598 | |
40c97fc6 | 1599 | if (i >= 0) |
d9cf1b54 AM |
1600 | break; |
1601 | } | |
81545d45 | 1602 | |
800eeca4 | 1603 | if (m == NULL) |
81545d45 | 1604 | { |
dc810e39 AM |
1605 | m = ((struct elf_segment_map *) |
1606 | bfd_zalloc (abfd, (bfd_size_type) sizeof *m)); | |
81545d45 | 1607 | if (m == NULL) |
b34976b6 | 1608 | return FALSE; |
800eeca4 | 1609 | |
81545d45 RH |
1610 | m->p_type = PT_IA_64_UNWIND; |
1611 | m->count = 1; | |
1612 | m->sections[0] = s; | |
1613 | m->next = NULL; | |
800eeca4 | 1614 | |
81545d45 RH |
1615 | /* We want to put it last. */ |
1616 | pm = &elf_tdata (abfd)->segment_map; | |
1617 | while (*pm != NULL) | |
1618 | pm = &(*pm)->next; | |
1619 | *pm = m; | |
1620 | } | |
800eeca4 JW |
1621 | } |
1622 | } | |
1623 | ||
e36284ab AM |
1624 | return TRUE; |
1625 | } | |
1626 | ||
1627 | /* Turn on PF_IA_64_NORECOV if needed. This involves traversing all of | |
1628 | the input sections for each output section in the segment and testing | |
1629 | for SHF_IA_64_NORECOV on each. */ | |
1630 | ||
1631 | static bfd_boolean | |
1632 | elfNN_ia64_modify_program_headers (bfd *abfd, | |
1633 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
1634 | { | |
1635 | struct elf_obj_tdata *tdata = elf_tdata (abfd); | |
1636 | struct elf_segment_map *m; | |
1637 | Elf_Internal_Phdr *p; | |
1638 | ||
1639 | for (p = tdata->phdr, m = tdata->segment_map; m != NULL; m = m->next, p++) | |
800eeca4 JW |
1640 | if (m->p_type == PT_LOAD) |
1641 | { | |
1642 | int i; | |
1643 | for (i = m->count - 1; i >= 0; --i) | |
1644 | { | |
8423293d | 1645 | struct bfd_link_order *order = m->sections[i]->map_head.link_order; |
e36284ab AM |
1646 | |
1647 | while (order != NULL) | |
800eeca4 JW |
1648 | { |
1649 | if (order->type == bfd_indirect_link_order) | |
1650 | { | |
1651 | asection *is = order->u.indirect.section; | |
1652 | bfd_vma flags = elf_section_data(is)->this_hdr.sh_flags; | |
1653 | if (flags & SHF_IA_64_NORECOV) | |
1654 | { | |
e36284ab | 1655 | p->p_flags |= PF_IA_64_NORECOV; |
800eeca4 JW |
1656 | goto found; |
1657 | } | |
1658 | } | |
1659 | order = order->next; | |
1660 | } | |
1661 | } | |
1662 | found:; | |
1663 | } | |
1664 | ||
b34976b6 | 1665 | return TRUE; |
800eeca4 JW |
1666 | } |
1667 | ||
800eeca4 JW |
1668 | /* According to the Tahoe assembler spec, all labels starting with a |
1669 | '.' are local. */ | |
1670 | ||
b34976b6 | 1671 | static bfd_boolean |
eae50df2 L |
1672 | elfNN_ia64_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED, |
1673 | const char *name) | |
800eeca4 JW |
1674 | { |
1675 | return name[0] == '.'; | |
1676 | } | |
1677 | ||
1678 | /* Should we do dynamic things to this symbol? */ | |
1679 | ||
b34976b6 | 1680 | static bfd_boolean |
eae50df2 L |
1681 | elfNN_ia64_dynamic_symbol_p (struct elf_link_hash_entry *h, |
1682 | struct bfd_link_info *info, int r_type) | |
800eeca4 | 1683 | { |
986a241f RH |
1684 | bfd_boolean ignore_protected |
1685 | = ((r_type & 0xf8) == 0x40 /* FPTR relocs */ | |
1686 | || (r_type & 0xf8) == 0x50); /* LTOFF_FPTR relocs */ | |
800eeca4 | 1687 | |
986a241f | 1688 | return _bfd_elf_dynamic_symbol_p (h, info, ignore_protected); |
800eeca4 JW |
1689 | } |
1690 | \f | |
800eeca4 | 1691 | static struct bfd_hash_entry* |
eae50df2 L |
1692 | elfNN_ia64_new_elf_hash_entry (struct bfd_hash_entry *entry, |
1693 | struct bfd_hash_table *table, | |
1694 | const char *string) | |
800eeca4 | 1695 | { |
bbe66d08 JW |
1696 | struct elfNN_ia64_link_hash_entry *ret; |
1697 | ret = (struct elfNN_ia64_link_hash_entry *) entry; | |
800eeca4 JW |
1698 | |
1699 | /* Allocate the structure if it has not already been allocated by a | |
1700 | subclass. */ | |
1701 | if (!ret) | |
1702 | ret = bfd_hash_allocate (table, sizeof (*ret)); | |
1703 | ||
1704 | if (!ret) | |
1705 | return 0; | |
1706 | ||
800eeca4 | 1707 | /* Call the allocation method of the superclass. */ |
bbe66d08 | 1708 | ret = ((struct elfNN_ia64_link_hash_entry *) |
800eeca4 JW |
1709 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, |
1710 | table, string)); | |
1711 | ||
4f40114d | 1712 | ret->info = NULL; |
396a682d L |
1713 | ret->count = 0; |
1714 | ret->sorted_count = 0; | |
1715 | ret->size = 0; | |
800eeca4 JW |
1716 | return (struct bfd_hash_entry *) ret; |
1717 | } | |
1718 | ||
1719 | static void | |
eae50df2 L |
1720 | elfNN_ia64_hash_copy_indirect (struct bfd_link_info *info, |
1721 | struct elf_link_hash_entry *xdir, | |
1722 | struct elf_link_hash_entry *xind) | |
800eeca4 | 1723 | { |
bbe66d08 | 1724 | struct elfNN_ia64_link_hash_entry *dir, *ind; |
800eeca4 | 1725 | |
57c7194e AM |
1726 | dir = (struct elfNN_ia64_link_hash_entry *) xdir; |
1727 | ind = (struct elfNN_ia64_link_hash_entry *) xind; | |
800eeca4 | 1728 | |
3e932841 | 1729 | /* Copy down any references that we may have already seen to the |
800eeca4 JW |
1730 | symbol which just became indirect. */ |
1731 | ||
f5385ebf AM |
1732 | dir->root.ref_dynamic |= ind->root.ref_dynamic; |
1733 | dir->root.ref_regular |= ind->root.ref_regular; | |
1734 | dir->root.ref_regular_nonweak |= ind->root.ref_regular_nonweak; | |
1735 | dir->root.needs_plt |= ind->root.needs_plt; | |
800eeca4 | 1736 | |
1e370bd2 | 1737 | if (ind->root.root.type != bfd_link_hash_indirect) |
0a991dfe AM |
1738 | return; |
1739 | ||
800eeca4 JW |
1740 | /* Copy over the got and plt data. This would have been done |
1741 | by check_relocs. */ | |
1742 | ||
fcfa13d2 | 1743 | if (ind->info != NULL) |
800eeca4 | 1744 | { |
bbe66d08 | 1745 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
396a682d L |
1746 | unsigned int count; |
1747 | ||
1748 | if (dir->info) | |
1749 | free (dir->info); | |
1750 | ||
1751 | dir->info = ind->info; | |
1752 | dir->count = ind->count; | |
1753 | dir->sorted_count = ind->sorted_count; | |
1754 | dir->size = ind->size; | |
800eeca4 | 1755 | |
800eeca4 | 1756 | ind->info = NULL; |
396a682d L |
1757 | ind->count = 0; |
1758 | ind->sorted_count = 0; | |
1759 | ind->size = 0; | |
800eeca4 JW |
1760 | |
1761 | /* Fix up the dyn_sym_info pointers to the global symbol. */ | |
396a682d L |
1762 | for (count = dir->count, dyn_i = dir->info; |
1763 | count != 0; | |
1764 | count--, dyn_i++) | |
800eeca4 JW |
1765 | dyn_i->h = &dir->root; |
1766 | } | |
800eeca4 JW |
1767 | |
1768 | /* Copy over the dynindx. */ | |
1769 | ||
fcfa13d2 | 1770 | if (ind->root.dynindx != -1) |
800eeca4 | 1771 | { |
fcfa13d2 AM |
1772 | if (dir->root.dynindx != -1) |
1773 | _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, | |
1774 | dir->root.dynstr_index); | |
800eeca4 JW |
1775 | dir->root.dynindx = ind->root.dynindx; |
1776 | dir->root.dynstr_index = ind->root.dynstr_index; | |
1777 | ind->root.dynindx = -1; | |
1778 | ind->root.dynstr_index = 0; | |
1779 | } | |
800eeca4 JW |
1780 | } |
1781 | ||
1782 | static void | |
eae50df2 L |
1783 | elfNN_ia64_hash_hide_symbol (struct bfd_link_info *info, |
1784 | struct elf_link_hash_entry *xh, | |
1785 | bfd_boolean force_local) | |
800eeca4 | 1786 | { |
bbe66d08 JW |
1787 | struct elfNN_ia64_link_hash_entry *h; |
1788 | struct elfNN_ia64_dyn_sym_info *dyn_i; | |
396a682d | 1789 | unsigned int count; |
800eeca4 | 1790 | |
bbe66d08 | 1791 | h = (struct elfNN_ia64_link_hash_entry *)xh; |
800eeca4 | 1792 | |
e5094212 | 1793 | _bfd_elf_link_hash_hide_symbol (info, &h->root, force_local); |
800eeca4 | 1794 | |
396a682d L |
1795 | for (count = h->count, dyn_i = h->info; |
1796 | count != 0; | |
1797 | count--, dyn_i++) | |
6a32c710 L |
1798 | { |
1799 | dyn_i->want_plt2 = 0; | |
1800 | dyn_i->want_plt = 0; | |
1801 | } | |
800eeca4 JW |
1802 | } |
1803 | ||
0aa92b58 JJ |
1804 | /* Compute a hash of a local hash entry. */ |
1805 | ||
1806 | static hashval_t | |
eae50df2 | 1807 | elfNN_ia64_local_htab_hash (const void *ptr) |
0aa92b58 JJ |
1808 | { |
1809 | struct elfNN_ia64_local_hash_entry *entry | |
1810 | = (struct elfNN_ia64_local_hash_entry *) ptr; | |
1811 | ||
1812 | return (((entry->id & 0xff) << 24) | ((entry->id & 0xff00) << 8)) | |
1813 | ^ entry->r_sym ^ (entry->id >> 16); | |
1814 | } | |
1815 | ||
1816 | /* Compare local hash entries. */ | |
1817 | ||
1818 | static int | |
eae50df2 | 1819 | elfNN_ia64_local_htab_eq (const void *ptr1, const void *ptr2) |
0aa92b58 JJ |
1820 | { |
1821 | struct elfNN_ia64_local_hash_entry *entry1 | |
1822 | = (struct elfNN_ia64_local_hash_entry *) ptr1; | |
1823 | struct elfNN_ia64_local_hash_entry *entry2 | |
1824 | = (struct elfNN_ia64_local_hash_entry *) ptr2; | |
1825 | ||
1826 | return entry1->id == entry2->id && entry1->r_sym == entry2->r_sym; | |
1827 | } | |
1828 | ||
800eeca4 JW |
1829 | /* Create the derived linker hash table. The IA-64 ELF port uses this |
1830 | derived hash table to keep information specific to the IA-64 ElF | |
1831 | linker (without using static variables). */ | |
1832 | ||
1833 | static struct bfd_link_hash_table* | |
eae50df2 | 1834 | elfNN_ia64_hash_table_create (bfd *abfd) |
800eeca4 | 1835 | { |
bbe66d08 | 1836 | struct elfNN_ia64_link_hash_table *ret; |
800eeca4 | 1837 | |
6e84a906 | 1838 | ret = bfd_zmalloc ((bfd_size_type) sizeof (*ret)); |
800eeca4 JW |
1839 | if (!ret) |
1840 | return 0; | |
6e84a906 | 1841 | |
800eeca4 | 1842 | if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, |
66eb6687 AM |
1843 | elfNN_ia64_new_elf_hash_entry, |
1844 | sizeof (struct elfNN_ia64_link_hash_entry))) | |
800eeca4 | 1845 | { |
6e84a906 | 1846 | free (ret); |
800eeca4 JW |
1847 | return 0; |
1848 | } | |
1849 | ||
0aa92b58 JJ |
1850 | ret->loc_hash_table = htab_try_create (1024, elfNN_ia64_local_htab_hash, |
1851 | elfNN_ia64_local_htab_eq, NULL); | |
1852 | ret->loc_hash_memory = objalloc_create (); | |
1853 | if (!ret->loc_hash_table || !ret->loc_hash_memory) | |
6e84a906 DJ |
1854 | { |
1855 | free (ret); | |
1856 | return 0; | |
1857 | } | |
1858 | ||
800eeca4 JW |
1859 | return &ret->root.root; |
1860 | } | |
1861 | ||
396a682d L |
1862 | /* Free the global elfNN_ia64_dyn_sym_info array. */ |
1863 | ||
1864 | static bfd_boolean | |
1865 | elfNN_ia64_global_dyn_info_free (void **xentry, | |
1866 | PTR unused ATTRIBUTE_UNUSED) | |
1867 | { | |
1868 | struct elfNN_ia64_link_hash_entry *entry | |
1869 | = (struct elfNN_ia64_link_hash_entry *) xentry; | |
1870 | ||
1871 | if (entry->root.root.type == bfd_link_hash_warning) | |
1872 | entry = (struct elfNN_ia64_link_hash_entry *) entry->root.root.u.i.link; | |
1873 | ||
1874 | if (entry->info) | |
1875 | { | |
1876 | free (entry->info); | |
1877 | entry->info = NULL; | |
1878 | entry->count = 0; | |
1879 | entry->sorted_count = 0; | |
1880 | entry->size = 0; | |
1881 | } | |
1882 | ||
1883 | return TRUE; | |
1884 | } | |
1885 | ||
1886 | /* Free the local elfNN_ia64_dyn_sym_info array. */ | |
1887 | ||
1888 | static bfd_boolean | |
1889 | elfNN_ia64_local_dyn_info_free (void **slot, | |
1890 | PTR unused ATTRIBUTE_UNUSED) | |
1891 | { | |
1892 | struct elfNN_ia64_local_hash_entry *entry | |
1893 | = (struct elfNN_ia64_local_hash_entry *) *slot; | |
1894 | ||
1895 | if (entry->info) | |
1896 | { | |
1897 | free (entry->info); | |
1898 | entry->info = NULL; | |
1899 | entry->count = 0; | |
1900 | entry->sorted_count = 0; | |
1901 | entry->size = 0; | |
1902 | } | |
1903 | ||
1904 | return TRUE; | |
1905 | } | |
1906 | ||
0aa92b58 | 1907 | /* Destroy IA-64 linker hash table. */ |
800eeca4 | 1908 | |
0aa92b58 | 1909 | static void |
eae50df2 | 1910 | elfNN_ia64_hash_table_free (struct bfd_link_hash_table *hash) |
800eeca4 | 1911 | { |
0aa92b58 JJ |
1912 | struct elfNN_ia64_link_hash_table *ia64_info |
1913 | = (struct elfNN_ia64_link_hash_table *) hash; | |
1914 | if (ia64_info->loc_hash_table) | |
396a682d L |
1915 | { |
1916 | htab_traverse (ia64_info->loc_hash_table, | |
1917 | elfNN_ia64_local_dyn_info_free, NULL); | |
1918 | htab_delete (ia64_info->loc_hash_table); | |
1919 | } | |
0aa92b58 JJ |
1920 | if (ia64_info->loc_hash_memory) |
1921 | objalloc_free ((struct objalloc *) ia64_info->loc_hash_memory); | |
396a682d L |
1922 | elf_link_hash_traverse (&ia64_info->root, |
1923 | elfNN_ia64_global_dyn_info_free, NULL); | |
0aa92b58 | 1924 | _bfd_generic_link_hash_table_free (hash); |
800eeca4 JW |
1925 | } |
1926 | ||
1927 | /* Traverse both local and global hash tables. */ | |
1928 | ||
bbe66d08 | 1929 | struct elfNN_ia64_dyn_sym_traverse_data |
800eeca4 | 1930 | { |
eae50df2 | 1931 | bfd_boolean (*func) (struct elfNN_ia64_dyn_sym_info *, PTR); |
800eeca4 JW |
1932 | PTR data; |
1933 | }; | |
1934 | ||
b34976b6 | 1935 | static bfd_boolean |
eae50df2 L |
1936 | elfNN_ia64_global_dyn_sym_thunk (struct bfd_hash_entry *xentry, |
1937 | PTR xdata) | |
800eeca4 | 1938 | { |
bbe66d08 JW |
1939 | struct elfNN_ia64_link_hash_entry *entry |
1940 | = (struct elfNN_ia64_link_hash_entry *) xentry; | |
1941 | struct elfNN_ia64_dyn_sym_traverse_data *data | |
1942 | = (struct elfNN_ia64_dyn_sym_traverse_data *) xdata; | |
1943 | struct elfNN_ia64_dyn_sym_info *dyn_i; | |
396a682d | 1944 | unsigned int count; |
800eeca4 | 1945 | |
e92d460e AM |
1946 | if (entry->root.root.type == bfd_link_hash_warning) |
1947 | entry = (struct elfNN_ia64_link_hash_entry *) entry->root.root.u.i.link; | |
1948 | ||
396a682d L |
1949 | for (count = entry->count, dyn_i = entry->info; |
1950 | count != 0; | |
1951 | count--, dyn_i++) | |
800eeca4 | 1952 | if (! (*data->func) (dyn_i, data->data)) |
b34976b6 AM |
1953 | return FALSE; |
1954 | return TRUE; | |
800eeca4 JW |
1955 | } |
1956 | ||
b34976b6 | 1957 | static bfd_boolean |
eae50df2 | 1958 | elfNN_ia64_local_dyn_sym_thunk (void **slot, PTR xdata) |
800eeca4 | 1959 | { |
bbe66d08 | 1960 | struct elfNN_ia64_local_hash_entry *entry |
0aa92b58 | 1961 | = (struct elfNN_ia64_local_hash_entry *) *slot; |
bbe66d08 JW |
1962 | struct elfNN_ia64_dyn_sym_traverse_data *data |
1963 | = (struct elfNN_ia64_dyn_sym_traverse_data *) xdata; | |
1964 | struct elfNN_ia64_dyn_sym_info *dyn_i; | |
396a682d | 1965 | unsigned int count; |
800eeca4 | 1966 | |
396a682d L |
1967 | for (count = entry->count, dyn_i = entry->info; |
1968 | count != 0; | |
1969 | count--, dyn_i++) | |
800eeca4 | 1970 | if (! (*data->func) (dyn_i, data->data)) |
396a682d L |
1971 | return FALSE; |
1972 | return TRUE; | |
800eeca4 JW |
1973 | } |
1974 | ||
1975 | static void | |
eae50df2 L |
1976 | elfNN_ia64_dyn_sym_traverse (struct elfNN_ia64_link_hash_table *ia64_info, |
1977 | bfd_boolean (*func) (struct elfNN_ia64_dyn_sym_info *, PTR), | |
1978 | PTR data) | |
800eeca4 | 1979 | { |
bbe66d08 | 1980 | struct elfNN_ia64_dyn_sym_traverse_data xdata; |
800eeca4 JW |
1981 | |
1982 | xdata.func = func; | |
1983 | xdata.data = data; | |
1984 | ||
1985 | elf_link_hash_traverse (&ia64_info->root, | |
bbe66d08 | 1986 | elfNN_ia64_global_dyn_sym_thunk, &xdata); |
0aa92b58 JJ |
1987 | htab_traverse (ia64_info->loc_hash_table, |
1988 | elfNN_ia64_local_dyn_sym_thunk, &xdata); | |
800eeca4 JW |
1989 | } |
1990 | \f | |
b34976b6 | 1991 | static bfd_boolean |
eae50df2 L |
1992 | elfNN_ia64_create_dynamic_sections (bfd *abfd, |
1993 | struct bfd_link_info *info) | |
800eeca4 | 1994 | { |
bbe66d08 | 1995 | struct elfNN_ia64_link_hash_table *ia64_info; |
800eeca4 JW |
1996 | asection *s; |
1997 | ||
1998 | if (! _bfd_elf_create_dynamic_sections (abfd, info)) | |
b34976b6 | 1999 | return FALSE; |
800eeca4 | 2000 | |
bbe66d08 | 2001 | ia64_info = elfNN_ia64_hash_table (info); |
800eeca4 | 2002 | |
800eeca4 | 2003 | { |
cc3bd654 L |
2004 | flagword flags = bfd_get_section_flags (abfd, ia64_info->root.sgot); |
2005 | bfd_set_section_flags (abfd, ia64_info->root.sgot, | |
2006 | SEC_SMALL_DATA | flags); | |
69bbc4c0 | 2007 | /* The .got section is always aligned at 8 bytes. */ |
cc3bd654 | 2008 | bfd_set_section_alignment (abfd, ia64_info->root.sgot, 3); |
800eeca4 JW |
2009 | } |
2010 | ||
2011 | if (!get_pltoff (abfd, info, ia64_info)) | |
b34976b6 | 2012 | return FALSE; |
800eeca4 | 2013 | |
3496cb2a L |
2014 | s = bfd_make_section_with_flags (abfd, ".rela.IA_64.pltoff", |
2015 | (SEC_ALLOC | SEC_LOAD | |
2016 | | SEC_HAS_CONTENTS | |
2017 | | SEC_IN_MEMORY | |
2018 | | SEC_LINKER_CREATED | |
2019 | | SEC_READONLY)); | |
800eeca4 | 2020 | if (s == NULL |
5a260b66 | 2021 | || !bfd_set_section_alignment (abfd, s, LOG_SECTION_ALIGN)) |
b34976b6 | 2022 | return FALSE; |
800eeca4 JW |
2023 | ia64_info->rel_pltoff_sec = s; |
2024 | ||
b34976b6 | 2025 | return TRUE; |
800eeca4 JW |
2026 | } |
2027 | ||
f7460f5f JJ |
2028 | /* Find and/or create a hash entry for local symbol. */ |
2029 | static struct elfNN_ia64_local_hash_entry * | |
eae50df2 L |
2030 | get_local_sym_hash (struct elfNN_ia64_link_hash_table *ia64_info, |
2031 | bfd *abfd, const Elf_Internal_Rela *rel, | |
2032 | bfd_boolean create) | |
f7460f5f | 2033 | { |
0aa92b58 | 2034 | struct elfNN_ia64_local_hash_entry e, *ret; |
d48770d4 | 2035 | asection *sec = abfd->sections; |
0aa92b58 JJ |
2036 | hashval_t h = (((sec->id & 0xff) << 24) | ((sec->id & 0xff00) << 8)) |
2037 | ^ ELFNN_R_SYM (rel->r_info) ^ (sec->id >> 16); | |
2038 | void **slot; | |
d48770d4 | 2039 | |
0aa92b58 JJ |
2040 | e.id = sec->id; |
2041 | e.r_sym = ELFNN_R_SYM (rel->r_info); | |
2042 | slot = htab_find_slot_with_hash (ia64_info->loc_hash_table, &e, h, | |
2043 | create ? INSERT : NO_INSERT); | |
f7460f5f | 2044 | |
0aa92b58 JJ |
2045 | if (!slot) |
2046 | return NULL; | |
f7460f5f | 2047 | |
0aa92b58 JJ |
2048 | if (*slot) |
2049 | return (struct elfNN_ia64_local_hash_entry *) *slot; | |
f7460f5f | 2050 | |
0aa92b58 JJ |
2051 | ret = (struct elfNN_ia64_local_hash_entry *) |
2052 | objalloc_alloc ((struct objalloc *) ia64_info->loc_hash_memory, | |
2053 | sizeof (struct elfNN_ia64_local_hash_entry)); | |
2054 | if (ret) | |
2055 | { | |
2056 | memset (ret, 0, sizeof (*ret)); | |
2057 | ret->id = sec->id; | |
2058 | ret->r_sym = ELFNN_R_SYM (rel->r_info); | |
2059 | *slot = ret; | |
2060 | } | |
fcf12726 | 2061 | return ret; |
f7460f5f JJ |
2062 | } |
2063 | ||
396a682d L |
2064 | /* Used to sort elfNN_ia64_dyn_sym_info array. */ |
2065 | ||
2066 | static int | |
2067 | addend_compare (const void *xp, const void *yp) | |
2068 | { | |
2069 | const struct elfNN_ia64_dyn_sym_info *x | |
2070 | = (const struct elfNN_ia64_dyn_sym_info *) xp; | |
2071 | const struct elfNN_ia64_dyn_sym_info *y | |
2072 | = (const struct elfNN_ia64_dyn_sym_info *) yp; | |
2073 | ||
c26620e3 | 2074 | return x->addend < y->addend ? -1 : x->addend > y->addend ? 1 : 0; |
396a682d L |
2075 | } |
2076 | ||
2077 | /* Sort elfNN_ia64_dyn_sym_info array and remove duplicates. */ | |
2078 | ||
2079 | static unsigned int | |
2080 | sort_dyn_sym_info (struct elfNN_ia64_dyn_sym_info *info, | |
2081 | unsigned int count) | |
2082 | { | |
293a0124 L |
2083 | bfd_vma curr, prev, got_offset; |
2084 | unsigned int i, kept, dup, diff, dest, src, len; | |
396a682d L |
2085 | |
2086 | qsort (info, count, sizeof (*info), addend_compare); | |
2087 | ||
2088 | /* Find the first duplicate. */ | |
2089 | prev = info [0].addend; | |
293a0124 | 2090 | got_offset = info [0].got_offset; |
396a682d L |
2091 | for (i = 1; i < count; i++) |
2092 | { | |
2093 | curr = info [i].addend; | |
2094 | if (curr == prev) | |
293a0124 L |
2095 | { |
2096 | /* For duplicates, make sure that GOT_OFFSET is valid. */ | |
2097 | if (got_offset == (bfd_vma) -1) | |
2098 | got_offset = info [i].got_offset; | |
2099 | break; | |
2100 | } | |
2101 | got_offset = info [i].got_offset; | |
396a682d L |
2102 | prev = curr; |
2103 | } | |
2104 | ||
293a0124 L |
2105 | /* We may move a block of elements to here. */ |
2106 | dest = i++; | |
2107 | ||
396a682d L |
2108 | /* Remove duplicates. */ |
2109 | if (i < count) | |
2110 | { | |
396a682d L |
2111 | while (i < count) |
2112 | { | |
293a0124 L |
2113 | /* For duplicates, make sure that the kept one has a valid |
2114 | got_offset. */ | |
2115 | kept = dest - 1; | |
2116 | if (got_offset != (bfd_vma) -1) | |
2117 | info [kept].got_offset = got_offset; | |
2118 | ||
396a682d | 2119 | curr = info [i].addend; |
293a0124 | 2120 | got_offset = info [i].got_offset; |
396a682d L |
2121 | |
2122 | /* Move a block of elements whose first one is different from | |
2123 | the previous. */ | |
2124 | if (curr == prev) | |
2125 | { | |
2126 | for (src = i + 1; src < count; src++) | |
293a0124 L |
2127 | { |
2128 | if (info [src].addend != curr) | |
2129 | break; | |
2130 | /* For duplicates, make sure that GOT_OFFSET is | |
2131 | valid. */ | |
2132 | if (got_offset == (bfd_vma) -1) | |
2133 | got_offset = info [src].got_offset; | |
2134 | } | |
2135 | ||
2136 | /* Make sure that the kept one has a valid got_offset. */ | |
2137 | if (got_offset != (bfd_vma) -1) | |
2138 | info [kept].got_offset = got_offset; | |
396a682d L |
2139 | } |
2140 | else | |
2141 | src = i; | |
2142 | ||
2143 | if (src >= count) | |
2144 | break; | |
2145 | ||
293a0124 | 2146 | /* Find the next duplicate. SRC will be kept. */ |
396a682d | 2147 | prev = info [src].addend; |
293a0124 | 2148 | got_offset = info [src].got_offset; |
396a682d L |
2149 | for (dup = src + 1; dup < count; dup++) |
2150 | { | |
2151 | curr = info [dup].addend; | |
2152 | if (curr == prev) | |
293a0124 L |
2153 | { |
2154 | /* Make sure that got_offset is valid. */ | |
2155 | if (got_offset == (bfd_vma) -1) | |
2156 | got_offset = info [dup].got_offset; | |
2157 | ||
2158 | /* For duplicates, make sure that the kept one has | |
2159 | a valid got_offset. */ | |
2160 | if (got_offset != (bfd_vma) -1) | |
2161 | info [dup - 1].got_offset = got_offset; | |
2162 | break; | |
2163 | } | |
2164 | got_offset = info [dup].got_offset; | |
396a682d L |
2165 | prev = curr; |
2166 | } | |
2167 | ||
2168 | /* How much to move. */ | |
2169 | len = dup - src; | |
2170 | i = dup + 1; | |
2171 | ||
2172 | if (len == 1 && dup < count) | |
2173 | { | |
2174 | /* If we only move 1 element, we combine it with the next | |
293a0124 L |
2175 | one. There must be at least a duplicate. Find the |
2176 | next different one. */ | |
396a682d | 2177 | for (diff = dup + 1, src++; diff < count; diff++, src++) |
293a0124 L |
2178 | { |
2179 | if (info [diff].addend != curr) | |
2180 | break; | |
2181 | /* Make sure that got_offset is valid. */ | |
2182 | if (got_offset == (bfd_vma) -1) | |
2183 | got_offset = info [diff].got_offset; | |
2184 | } | |
2185 | ||
2186 | /* Makre sure that the last duplicated one has an valid | |
2187 | offset. */ | |
2188 | BFD_ASSERT (curr == prev); | |
2189 | if (got_offset != (bfd_vma) -1) | |
2190 | info [diff - 1].got_offset = got_offset; | |
396a682d L |
2191 | |
2192 | if (diff < count) | |
2193 | { | |
293a0124 L |
2194 | /* Find the next duplicate. Track the current valid |
2195 | offset. */ | |
396a682d | 2196 | prev = info [diff].addend; |
293a0124 | 2197 | got_offset = info [diff].got_offset; |
396a682d L |
2198 | for (dup = diff + 1; dup < count; dup++) |
2199 | { | |
2200 | curr = info [dup].addend; | |
2201 | if (curr == prev) | |
293a0124 L |
2202 | { |
2203 | /* For duplicates, make sure that GOT_OFFSET | |
2204 | is valid. */ | |
2205 | if (got_offset == (bfd_vma) -1) | |
2206 | got_offset = info [dup].got_offset; | |
2207 | break; | |
2208 | } | |
2209 | got_offset = info [dup].got_offset; | |
396a682d L |
2210 | prev = curr; |
2211 | diff++; | |
2212 | } | |
2213 | ||
2214 | len = diff - src + 1; | |
2215 | i = diff + 1; | |
2216 | } | |
2217 | } | |
2218 | ||
2219 | memmove (&info [dest], &info [src], len * sizeof (*info)); | |
2220 | ||
2221 | dest += len; | |
2222 | } | |
2223 | ||
2224 | count = dest; | |
2225 | } | |
293a0124 L |
2226 | else |
2227 | { | |
2228 | /* When we get here, either there is no duplicate at all or | |
2229 | the only duplicate is the last element. */ | |
2230 | if (dest < count) | |
2231 | { | |
2232 | /* If the last element is a duplicate, make sure that the | |
2233 | kept one has a valid got_offset. We also update count. */ | |
2234 | if (got_offset != (bfd_vma) -1) | |
2235 | info [dest - 1].got_offset = got_offset; | |
2236 | count = dest; | |
2237 | } | |
2238 | } | |
396a682d L |
2239 | |
2240 | return count; | |
2241 | } | |
2242 | ||
800eeca4 | 2243 | /* Find and/or create a descriptor for dynamic symbol info. This will |
396a682d L |
2244 | vary based on global or local symbol, and the addend to the reloc. |
2245 | ||
2246 | We don't sort when inserting. Also, we sort and eliminate | |
2247 | duplicates if there is an unsorted section. Typically, this will | |
2248 | only happen once, because we do all insertions before lookups. We | |
2249 | then use bsearch to do a lookup. This also allows lookups to be | |
2250 | fast. So we have fast insertion (O(log N) due to duplicate check), | |
2251 | fast lookup (O(log N)) and one sort (O(N log N) expected time). | |
2252 | Previously, all lookups were O(N) because of the use of the linked | |
2253 | list and also all insertions were O(N) because of the check for | |
2254 | duplicates. There are some complications here because the array | |
2255 | size grows occasionally, which may add an O(N) factor, but this | |
2256 | should be rare. Also, we free the excess array allocation, which | |
2257 | requires a copy which is O(N), but this only happens once. */ | |
800eeca4 | 2258 | |
bbe66d08 | 2259 | static struct elfNN_ia64_dyn_sym_info * |
eae50df2 L |
2260 | get_dyn_sym_info (struct elfNN_ia64_link_hash_table *ia64_info, |
2261 | struct elf_link_hash_entry *h, bfd *abfd, | |
2262 | const Elf_Internal_Rela *rel, bfd_boolean create) | |
800eeca4 | 2263 | { |
396a682d L |
2264 | struct elfNN_ia64_dyn_sym_info **info_p, *info, *dyn_i, key; |
2265 | unsigned int *count_p, *sorted_count_p, *size_p; | |
2266 | unsigned int count, sorted_count, size; | |
800eeca4 | 2267 | bfd_vma addend = rel ? rel->r_addend : 0; |
396a682d | 2268 | bfd_size_type amt; |
3e932841 | 2269 | |
800eeca4 | 2270 | if (h) |
396a682d L |
2271 | { |
2272 | struct elfNN_ia64_link_hash_entry *global_h; | |
2273 | ||
2274 | global_h = (struct elfNN_ia64_link_hash_entry *) h; | |
2275 | info_p = &global_h->info; | |
2276 | count_p = &global_h->count; | |
2277 | sorted_count_p = &global_h->sorted_count; | |
2278 | size_p = &global_h->size; | |
2279 | } | |
800eeca4 JW |
2280 | else |
2281 | { | |
bbe66d08 | 2282 | struct elfNN_ia64_local_hash_entry *loc_h; |
800eeca4 | 2283 | |
f7460f5f | 2284 | loc_h = get_local_sym_hash (ia64_info, abfd, rel, create); |
f86b235a RH |
2285 | if (!loc_h) |
2286 | { | |
2287 | BFD_ASSERT (!create); | |
2288 | return NULL; | |
2289 | } | |
800eeca4 | 2290 | |
396a682d L |
2291 | info_p = &loc_h->info; |
2292 | count_p = &loc_h->count; | |
2293 | sorted_count_p = &loc_h->sorted_count; | |
2294 | size_p = &loc_h->size; | |
3e932841 | 2295 | } |
800eeca4 | 2296 | |
396a682d L |
2297 | count = *count_p; |
2298 | sorted_count = *sorted_count_p; | |
2299 | size = *size_p; | |
2300 | info = *info_p; | |
2301 | if (create) | |
800eeca4 | 2302 | { |
396a682d L |
2303 | /* When we create the array, we don't check for duplicates, |
2304 | except in the previously sorted section if one exists, and | |
2305 | against the last inserted entry. This allows insertions to | |
2306 | be fast. */ | |
2307 | if (info) | |
2308 | { | |
2309 | if (sorted_count) | |
2310 | { | |
2311 | /* Try bsearch first on the sorted section. */ | |
2312 | key.addend = addend; | |
2313 | dyn_i = bsearch (&key, info, sorted_count, | |
2314 | sizeof (*info), addend_compare); | |
2315 | ||
2316 | if (dyn_i) | |
2317 | { | |
2318 | return dyn_i; | |
2319 | } | |
2320 | } | |
2321 | ||
2322 | /* Do a quick check for the last inserted entry. */ | |
2323 | dyn_i = info + count - 1; | |
2324 | if (dyn_i->addend == addend) | |
2325 | { | |
2326 | return dyn_i; | |
2327 | } | |
2328 | } | |
2329 | ||
2330 | if (size == 0) | |
2331 | { | |
2332 | /* It is the very first element. We create the array of size | |
2333 | 1. */ | |
2334 | size = 1; | |
2335 | amt = size * sizeof (*info); | |
2336 | info = bfd_malloc (amt); | |
2337 | } | |
2338 | else if (size <= count) | |
2339 | { | |
2340 | /* We double the array size every time when we reach the | |
2341 | size limit. */ | |
2342 | size += size; | |
2343 | amt = size * sizeof (*info); | |
2344 | info = bfd_realloc (info, amt); | |
2345 | } | |
2346 | else | |
2347 | goto has_space; | |
2348 | ||
2349 | if (info == NULL) | |
2350 | return NULL; | |
2351 | *size_p = size; | |
2352 | *info_p = info; | |
2353 | ||
2354 | has_space: | |
2355 | /* Append the new one to the array. */ | |
2356 | dyn_i = info + count; | |
2357 | memset (dyn_i, 0, sizeof (*dyn_i)); | |
293a0124 | 2358 | dyn_i->got_offset = (bfd_vma) -1; |
800eeca4 | 2359 | dyn_i->addend = addend; |
9a2e389a | 2360 | |
396a682d L |
2361 | /* We increment count only since the new ones are unsorted and |
2362 | may have duplicate. */ | |
2363 | (*count_p)++; | |
2364 | } | |
2365 | else | |
2366 | { | |
2367 | /* It is a lookup without insertion. Sort array if part of the | |
2368 | array isn't sorted. */ | |
2369 | if (count != sorted_count) | |
2370 | { | |
2371 | count = sort_dyn_sym_info (info, count); | |
2372 | *count_p = count; | |
2373 | *sorted_count_p = count; | |
2374 | } | |
2375 | ||
2376 | /* Free unused memory. */ | |
2377 | if (size != count) | |
2378 | { | |
2379 | amt = count * sizeof (*info); | |
2380 | info = bfd_malloc (amt); | |
2381 | if (info != NULL) | |
2382 | { | |
2383 | memcpy (info, *info_p, amt); | |
2384 | free (*info_p); | |
2385 | *size_p = count; | |
2386 | *info_p = info; | |
2387 | } | |
2388 | } | |
2389 | ||
2390 | key.addend = addend; | |
2391 | dyn_i = bsearch (&key, info, count, | |
2392 | sizeof (*info), addend_compare); | |
800eeca4 JW |
2393 | } |
2394 | ||
2395 | return dyn_i; | |
2396 | } | |
2397 | ||
2398 | static asection * | |
eae50df2 L |
2399 | get_got (bfd *abfd, struct bfd_link_info *info, |
2400 | struct elfNN_ia64_link_hash_table *ia64_info) | |
800eeca4 | 2401 | { |
64bf6ae6 | 2402 | asection *got; |
800eeca4 JW |
2403 | bfd *dynobj; |
2404 | ||
cc3bd654 | 2405 | got = ia64_info->root.sgot; |
800eeca4 JW |
2406 | if (!got) |
2407 | { | |
2408 | flagword flags; | |
2409 | ||
2410 | dynobj = ia64_info->root.dynobj; | |
2411 | if (!dynobj) | |
2412 | ia64_info->root.dynobj = dynobj = abfd; | |
2413 | if (!_bfd_elf_create_got_section (dynobj, info)) | |
2414 | return 0; | |
2415 | ||
cc3bd654 | 2416 | got = ia64_info->root.sgot; |
800eeca4 | 2417 | |
8651fcf9 L |
2418 | /* The .got section is always aligned at 8 bytes. */ |
2419 | if (!bfd_set_section_alignment (abfd, got, 3)) | |
2420 | return 0; | |
2421 | ||
800eeca4 JW |
2422 | flags = bfd_get_section_flags (abfd, got); |
2423 | bfd_set_section_flags (abfd, got, SEC_SMALL_DATA | flags); | |
2424 | } | |
2425 | ||
2426 | return got; | |
2427 | } | |
2428 | ||
2429 | /* Create function descriptor section (.opd). This section is called .opd | |
4cc11e76 | 2430 | because it contains "official procedure descriptors". The "official" |
800eeca4 JW |
2431 | refers to the fact that these descriptors are used when taking the address |
2432 | of a procedure, thus ensuring a unique address for each procedure. */ | |
2433 | ||
2434 | static asection * | |
eae50df2 L |
2435 | get_fptr (bfd *abfd, struct bfd_link_info *info, |
2436 | struct elfNN_ia64_link_hash_table *ia64_info) | |
800eeca4 JW |
2437 | { |
2438 | asection *fptr; | |
2439 | bfd *dynobj; | |
2440 | ||
2441 | fptr = ia64_info->fptr_sec; | |
2442 | if (!fptr) | |
2443 | { | |
2444 | dynobj = ia64_info->root.dynobj; | |
2445 | if (!dynobj) | |
2446 | ia64_info->root.dynobj = dynobj = abfd; | |
2447 | ||
3496cb2a L |
2448 | fptr = bfd_make_section_with_flags (dynobj, ".opd", |
2449 | (SEC_ALLOC | |
2450 | | SEC_LOAD | |
2451 | | SEC_HAS_CONTENTS | |
2452 | | SEC_IN_MEMORY | |
2453 | | (info->pie ? 0 : SEC_READONLY) | |
2454 | | SEC_LINKER_CREATED)); | |
800eeca4 | 2455 | if (!fptr |
800eeca4 JW |
2456 | || !bfd_set_section_alignment (abfd, fptr, 4)) |
2457 | { | |
2458 | BFD_ASSERT (0); | |
2459 | return NULL; | |
2460 | } | |
2461 | ||
2462 | ia64_info->fptr_sec = fptr; | |
9203ba99 JJ |
2463 | |
2464 | if (info->pie) | |
2465 | { | |
2466 | asection *fptr_rel; | |
3496cb2a L |
2467 | fptr_rel = bfd_make_section_with_flags (dynobj, ".rela.opd", |
2468 | (SEC_ALLOC | SEC_LOAD | |
2469 | | SEC_HAS_CONTENTS | |
2470 | | SEC_IN_MEMORY | |
2471 | | SEC_LINKER_CREATED | |
2472 | | SEC_READONLY)); | |
9203ba99 | 2473 | if (fptr_rel == NULL |
5a260b66 L |
2474 | || !bfd_set_section_alignment (abfd, fptr_rel, |
2475 | LOG_SECTION_ALIGN)) | |
9203ba99 JJ |
2476 | { |
2477 | BFD_ASSERT (0); | |
2478 | return NULL; | |
2479 | } | |
2480 | ||
2481 | ia64_info->rel_fptr_sec = fptr_rel; | |
2482 | } | |
800eeca4 JW |
2483 | } |
2484 | ||
2485 | return fptr; | |
2486 | } | |
2487 | ||
2488 | static asection * | |
eae50df2 L |
2489 | get_pltoff (bfd *abfd, struct bfd_link_info *info ATTRIBUTE_UNUSED, |
2490 | struct elfNN_ia64_link_hash_table *ia64_info) | |
800eeca4 JW |
2491 | { |
2492 | asection *pltoff; | |
2493 | bfd *dynobj; | |
2494 | ||
2495 | pltoff = ia64_info->pltoff_sec; | |
2496 | if (!pltoff) | |
2497 | { | |
2498 | dynobj = ia64_info->root.dynobj; | |
2499 | if (!dynobj) | |
2500 | ia64_info->root.dynobj = dynobj = abfd; | |
2501 | ||
3496cb2a L |
2502 | pltoff = bfd_make_section_with_flags (dynobj, |
2503 | ELF_STRING_ia64_pltoff, | |
2504 | (SEC_ALLOC | |
2505 | | SEC_LOAD | |
2506 | | SEC_HAS_CONTENTS | |
2507 | | SEC_IN_MEMORY | |
2508 | | SEC_SMALL_DATA | |
2509 | | SEC_LINKER_CREATED)); | |
800eeca4 | 2510 | if (!pltoff |
800eeca4 JW |
2511 | || !bfd_set_section_alignment (abfd, pltoff, 4)) |
2512 | { | |
2513 | BFD_ASSERT (0); | |
2514 | return NULL; | |
2515 | } | |
2516 | ||
2517 | ia64_info->pltoff_sec = pltoff; | |
2518 | } | |
2519 | ||
2520 | return pltoff; | |
2521 | } | |
2522 | ||
2523 | static asection * | |
eae50df2 L |
2524 | get_reloc_section (bfd *abfd, |
2525 | struct elfNN_ia64_link_hash_table *ia64_info, | |
2526 | asection *sec, bfd_boolean create) | |
800eeca4 JW |
2527 | { |
2528 | const char *srel_name; | |
2529 | asection *srel; | |
2530 | bfd *dynobj; | |
2531 | ||
2532 | srel_name = (bfd_elf_string_from_elf_section | |
2533 | (abfd, elf_elfheader(abfd)->e_shstrndx, | |
2534 | elf_section_data(sec)->rel_hdr.sh_name)); | |
2535 | if (srel_name == NULL) | |
2536 | return NULL; | |
2537 | ||
0112cd26 | 2538 | BFD_ASSERT ((CONST_STRNEQ (srel_name, ".rela") |
800eeca4 JW |
2539 | && strcmp (bfd_get_section_name (abfd, sec), |
2540 | srel_name+5) == 0) | |
0112cd26 | 2541 | || (CONST_STRNEQ (srel_name, ".rel") |
800eeca4 JW |
2542 | && strcmp (bfd_get_section_name (abfd, sec), |
2543 | srel_name+4) == 0)); | |
2544 | ||
2545 | dynobj = ia64_info->root.dynobj; | |
2546 | if (!dynobj) | |
2547 | ia64_info->root.dynobj = dynobj = abfd; | |
2548 | ||
2549 | srel = bfd_get_section_by_name (dynobj, srel_name); | |
2550 | if (srel == NULL && create) | |
2551 | { | |
3496cb2a L |
2552 | srel = bfd_make_section_with_flags (dynobj, srel_name, |
2553 | (SEC_ALLOC | SEC_LOAD | |
2554 | | SEC_HAS_CONTENTS | |
2555 | | SEC_IN_MEMORY | |
2556 | | SEC_LINKER_CREATED | |
2557 | | SEC_READONLY)); | |
800eeca4 | 2558 | if (srel == NULL |
5a260b66 L |
2559 | || !bfd_set_section_alignment (dynobj, srel, |
2560 | LOG_SECTION_ALIGN)) | |
800eeca4 JW |
2561 | return NULL; |
2562 | } | |
2563 | ||
2564 | return srel; | |
2565 | } | |
2566 | ||
b34976b6 | 2567 | static bfd_boolean |
ac33696c L |
2568 | count_dyn_reloc (bfd *abfd, struct elfNN_ia64_dyn_sym_info *dyn_i, |
2569 | asection *srel, int type, bfd_boolean reltext) | |
800eeca4 | 2570 | { |
bbe66d08 | 2571 | struct elfNN_ia64_dyn_reloc_entry *rent; |
800eeca4 JW |
2572 | |
2573 | for (rent = dyn_i->reloc_entries; rent; rent = rent->next) | |
2574 | if (rent->srel == srel && rent->type == type) | |
2575 | break; | |
2576 | ||
2577 | if (!rent) | |
2578 | { | |
dc810e39 AM |
2579 | rent = ((struct elfNN_ia64_dyn_reloc_entry *) |
2580 | bfd_alloc (abfd, (bfd_size_type) sizeof (*rent))); | |
800eeca4 | 2581 | if (!rent) |
b34976b6 | 2582 | return FALSE; |
800eeca4 JW |
2583 | |
2584 | rent->next = dyn_i->reloc_entries; | |
2585 | rent->srel = srel; | |
2586 | rent->type = type; | |
2587 | rent->count = 0; | |
2588 | dyn_i->reloc_entries = rent; | |
2589 | } | |
ac33696c | 2590 | rent->reltext = reltext; |
800eeca4 JW |
2591 | rent->count++; |
2592 | ||
b34976b6 | 2593 | return TRUE; |
800eeca4 JW |
2594 | } |
2595 | ||
b34976b6 | 2596 | static bfd_boolean |
eae50df2 L |
2597 | elfNN_ia64_check_relocs (bfd *abfd, struct bfd_link_info *info, |
2598 | asection *sec, | |
2599 | const Elf_Internal_Rela *relocs) | |
800eeca4 | 2600 | { |
bbe66d08 | 2601 | struct elfNN_ia64_link_hash_table *ia64_info; |
800eeca4 JW |
2602 | const Elf_Internal_Rela *relend; |
2603 | Elf_Internal_Shdr *symtab_hdr; | |
2604 | const Elf_Internal_Rela *rel; | |
21a8f7fa | 2605 | asection *got, *fptr, *srel, *pltoff; |
396a682d L |
2606 | enum { |
2607 | NEED_GOT = 1, | |
2608 | NEED_GOTX = 2, | |
2609 | NEED_FPTR = 4, | |
2610 | NEED_PLTOFF = 8, | |
2611 | NEED_MIN_PLT = 16, | |
2612 | NEED_FULL_PLT = 32, | |
2613 | NEED_DYNREL = 64, | |
2614 | NEED_LTOFF_FPTR = 128, | |
2615 | NEED_TPREL = 256, | |
2616 | NEED_DTPMOD = 512, | |
2617 | NEED_DTPREL = 1024 | |
2618 | }; | |
2619 | int need_entry; | |
2620 | struct elf_link_hash_entry *h; | |
2621 | unsigned long r_symndx; | |
2622 | bfd_boolean maybe_dynamic; | |
800eeca4 | 2623 | |
1049f94e | 2624 | if (info->relocatable) |
b34976b6 | 2625 | return TRUE; |
800eeca4 JW |
2626 | |
2627 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
bbe66d08 | 2628 | ia64_info = elfNN_ia64_hash_table (info); |
800eeca4 | 2629 | |
21a8f7fa | 2630 | got = fptr = srel = pltoff = NULL; |
800eeca4 JW |
2631 | |
2632 | relend = relocs + sec->reloc_count; | |
396a682d L |
2633 | |
2634 | /* We scan relocations first to create dynamic relocation arrays. We | |
2635 | modified get_dyn_sym_info to allow fast insertion and support fast | |
2636 | lookup in the next loop. */ | |
2637 | for (rel = relocs; rel < relend; ++rel) | |
2638 | { | |
2639 | r_symndx = ELFNN_R_SYM (rel->r_info); | |
2640 | if (r_symndx >= symtab_hdr->sh_info) | |
2641 | { | |
2642 | long indx = r_symndx - symtab_hdr->sh_info; | |
2643 | h = elf_sym_hashes (abfd)[indx]; | |
2644 | while (h->root.type == bfd_link_hash_indirect | |
2645 | || h->root.type == bfd_link_hash_warning) | |
2646 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
2647 | } | |
2648 | else | |
2649 | h = NULL; | |
2650 | ||
2651 | /* We can only get preliminary data on whether a symbol is | |
2652 | locally or externally defined, as not all of the input files | |
2653 | have yet been processed. Do something with what we know, as | |
2654 | this may help reduce memory usage and processing time later. */ | |
2655 | maybe_dynamic = (h && ((!info->executable | |
55255dae | 2656 | && (!SYMBOLIC_BIND (info, h) |
396a682d L |
2657 | || info->unresolved_syms_in_shared_libs == RM_IGNORE)) |
2658 | || !h->def_regular | |
2659 | || h->root.type == bfd_link_hash_defweak)); | |
2660 | ||
2661 | need_entry = 0; | |
2662 | switch (ELFNN_R_TYPE (rel->r_info)) | |
2663 | { | |
2664 | case R_IA64_TPREL64MSB: | |
2665 | case R_IA64_TPREL64LSB: | |
2666 | if (info->shared || maybe_dynamic) | |
2667 | need_entry = NEED_DYNREL; | |
2668 | break; | |
2669 | ||
2670 | case R_IA64_LTOFF_TPREL22: | |
2671 | need_entry = NEED_TPREL; | |
2672 | if (info->shared) | |
2673 | info->flags |= DF_STATIC_TLS; | |
2674 | break; | |
2675 | ||
2676 | case R_IA64_DTPREL32MSB: | |
2677 | case R_IA64_DTPREL32LSB: | |
2678 | case R_IA64_DTPREL64MSB: | |
2679 | case R_IA64_DTPREL64LSB: | |
2680 | if (info->shared || maybe_dynamic) | |
2681 | need_entry = NEED_DYNREL; | |
2682 | break; | |
2683 | ||
2684 | case R_IA64_LTOFF_DTPREL22: | |
2685 | need_entry = NEED_DTPREL; | |
2686 | break; | |
2687 | ||
2688 | case R_IA64_DTPMOD64MSB: | |
2689 | case R_IA64_DTPMOD64LSB: | |
2690 | if (info->shared || maybe_dynamic) | |
2691 | need_entry = NEED_DYNREL; | |
2692 | break; | |
2693 | ||
2694 | case R_IA64_LTOFF_DTPMOD22: | |
2695 | need_entry = NEED_DTPMOD; | |
2696 | break; | |
2697 | ||
2698 | case R_IA64_LTOFF_FPTR22: | |
2699 | case R_IA64_LTOFF_FPTR64I: | |
2700 | case R_IA64_LTOFF_FPTR32MSB: | |
2701 | case R_IA64_LTOFF_FPTR32LSB: | |
2702 | case R_IA64_LTOFF_FPTR64MSB: | |
2703 | case R_IA64_LTOFF_FPTR64LSB: | |
2704 | need_entry = NEED_FPTR | NEED_GOT | NEED_LTOFF_FPTR; | |
2705 | break; | |
2706 | ||
2707 | case R_IA64_FPTR64I: | |
2708 | case R_IA64_FPTR32MSB: | |
2709 | case R_IA64_FPTR32LSB: | |
2710 | case R_IA64_FPTR64MSB: | |
2711 | case R_IA64_FPTR64LSB: | |
2712 | if (info->shared || h) | |
2713 | need_entry = NEED_FPTR | NEED_DYNREL; | |
2714 | else | |
2715 | need_entry = NEED_FPTR; | |
2716 | break; | |
2717 | ||
2718 | case R_IA64_LTOFF22: | |
2719 | case R_IA64_LTOFF64I: | |
2720 | need_entry = NEED_GOT; | |
2721 | break; | |
2722 | ||
2723 | case R_IA64_LTOFF22X: | |
2724 | need_entry = NEED_GOTX; | |
2725 | break; | |
2726 | ||
2727 | case R_IA64_PLTOFF22: | |
2728 | case R_IA64_PLTOFF64I: | |
2729 | case R_IA64_PLTOFF64MSB: | |
2730 | case R_IA64_PLTOFF64LSB: | |
2731 | need_entry = NEED_PLTOFF; | |
2732 | if (h) | |
2733 | { | |
2734 | if (maybe_dynamic) | |
2735 | need_entry |= NEED_MIN_PLT; | |
2736 | } | |
2737 | else | |
2738 | { | |
2739 | (*info->callbacks->warning) | |
2740 | (info, _("@pltoff reloc against local symbol"), 0, | |
2741 | abfd, 0, (bfd_vma) 0); | |
2742 | } | |
2743 | break; | |
2744 | ||
2745 | case R_IA64_PCREL21B: | |
2746 | case R_IA64_PCREL60B: | |
2747 | /* Depending on where this symbol is defined, we may or may not | |
2748 | need a full plt entry. Only skip if we know we'll not need | |
2749 | the entry -- static or symbolic, and the symbol definition | |
2750 | has already been seen. */ | |
2751 | if (maybe_dynamic && rel->r_addend == 0) | |
2752 | need_entry = NEED_FULL_PLT; | |
2753 | break; | |
2754 | ||
2755 | case R_IA64_IMM14: | |
2756 | case R_IA64_IMM22: | |
2757 | case R_IA64_IMM64: | |
2758 | case R_IA64_DIR32MSB: | |
2759 | case R_IA64_DIR32LSB: | |
2760 | case R_IA64_DIR64MSB: | |
2761 | case R_IA64_DIR64LSB: | |
2762 | /* Shared objects will always need at least a REL relocation. */ | |
2763 | if (info->shared || maybe_dynamic) | |
2764 | need_entry = NEED_DYNREL; | |
2765 | break; | |
2766 | ||
2767 | case R_IA64_IPLTMSB: | |
2768 | case R_IA64_IPLTLSB: | |
2769 | /* Shared objects will always need at least a REL relocation. */ | |
2770 | if (info->shared || maybe_dynamic) | |
2771 | need_entry = NEED_DYNREL; | |
2772 | break; | |
2773 | ||
2774 | case R_IA64_PCREL22: | |
2775 | case R_IA64_PCREL64I: | |
2776 | case R_IA64_PCREL32MSB: | |
2777 | case R_IA64_PCREL32LSB: | |
2778 | case R_IA64_PCREL64MSB: | |
2779 | case R_IA64_PCREL64LSB: | |
2780 | if (maybe_dynamic) | |
2781 | need_entry = NEED_DYNREL; | |
2782 | break; | |
2783 | } | |
2784 | ||
2785 | if (!need_entry) | |
2786 | continue; | |
2787 | ||
2788 | if ((need_entry & NEED_FPTR) != 0 | |
2789 | && rel->r_addend) | |
2790 | { | |
2791 | (*info->callbacks->warning) | |
2792 | (info, _("non-zero addend in @fptr reloc"), 0, | |
2793 | abfd, 0, (bfd_vma) 0); | |
2794 | } | |
2795 | ||
2796 | if (get_dyn_sym_info (ia64_info, h, abfd, rel, TRUE) == NULL) | |
2797 | return FALSE; | |
2798 | } | |
2799 | ||
2800 | /* Now, we only do lookup without insertion, which is very fast | |
9a2e389a | 2801 | with the modified get_dyn_sym_info. */ |
800eeca4 JW |
2802 | for (rel = relocs; rel < relend; ++rel) |
2803 | { | |
bbe66d08 | 2804 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
64bf6ae6 | 2805 | int dynrel_type = R_IA64_NONE; |
800eeca4 | 2806 | |
396a682d | 2807 | r_symndx = ELFNN_R_SYM (rel->r_info); |
800eeca4 JW |
2808 | if (r_symndx >= symtab_hdr->sh_info) |
2809 | { | |
2810 | /* We're dealing with a global symbol -- find its hash entry | |
2811 | and mark it as being referenced. */ | |
2812 | long indx = r_symndx - symtab_hdr->sh_info; | |
2813 | h = elf_sym_hashes (abfd)[indx]; | |
2814 | while (h->root.type == bfd_link_hash_indirect | |
2815 | || h->root.type == bfd_link_hash_warning) | |
2816 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
2817 | ||
f5385ebf | 2818 | h->ref_regular = 1; |
800eeca4 | 2819 | } |
396a682d L |
2820 | else |
2821 | h = NULL; | |
800eeca4 JW |
2822 | |
2823 | /* We can only get preliminary data on whether a symbol is | |
2824 | locally or externally defined, as not all of the input files | |
2825 | have yet been processed. Do something with what we know, as | |
2826 | this may help reduce memory usage and processing time later. */ | |
396a682d | 2827 | maybe_dynamic = (h && ((!info->executable |
55255dae | 2828 | && (!SYMBOLIC_BIND (info, h) |
396a682d L |
2829 | || info->unresolved_syms_in_shared_libs == RM_IGNORE)) |
2830 | || !h->def_regular | |
2831 | || h->root.type == bfd_link_hash_defweak)); | |
800eeca4 JW |
2832 | |
2833 | need_entry = 0; | |
bbe66d08 | 2834 | switch (ELFNN_R_TYPE (rel->r_info)) |
800eeca4 | 2835 | { |
800eeca4 JW |
2836 | case R_IA64_TPREL64MSB: |
2837 | case R_IA64_TPREL64LSB: | |
13ae64f3 JJ |
2838 | if (info->shared || maybe_dynamic) |
2839 | need_entry = NEED_DYNREL; | |
2840 | dynrel_type = R_IA64_TPREL64LSB; | |
2841 | if (info->shared) | |
2842 | info->flags |= DF_STATIC_TLS; | |
2843 | break; | |
2844 | ||
2845 | case R_IA64_LTOFF_TPREL22: | |
2846 | need_entry = NEED_TPREL; | |
2847 | if (info->shared) | |
2848 | info->flags |= DF_STATIC_TLS; | |
2849 | break; | |
2850 | ||
5a260b66 L |
2851 | case R_IA64_DTPREL32MSB: |
2852 | case R_IA64_DTPREL32LSB: | |
13ae64f3 JJ |
2853 | case R_IA64_DTPREL64MSB: |
2854 | case R_IA64_DTPREL64LSB: | |
2855 | if (info->shared || maybe_dynamic) | |
2856 | need_entry = NEED_DYNREL; | |
5a260b66 | 2857 | dynrel_type = R_IA64_DTPRELNNLSB; |
13ae64f3 JJ |
2858 | break; |
2859 | ||
2860 | case R_IA64_LTOFF_DTPREL22: | |
2861 | need_entry = NEED_DTPREL; | |
2862 | break; | |
2863 | ||
2864 | case R_IA64_DTPMOD64MSB: | |
2865 | case R_IA64_DTPMOD64LSB: | |
2866 | if (info->shared || maybe_dynamic) | |
2867 | need_entry = NEED_DYNREL; | |
2868 | dynrel_type = R_IA64_DTPMOD64LSB; | |
2869 | break; | |
2870 | ||
2871 | case R_IA64_LTOFF_DTPMOD22: | |
2872 | need_entry = NEED_DTPMOD; | |
2873 | break; | |
800eeca4 JW |
2874 | |
2875 | case R_IA64_LTOFF_FPTR22: | |
2876 | case R_IA64_LTOFF_FPTR64I: | |
a4bd8390 JW |
2877 | case R_IA64_LTOFF_FPTR32MSB: |
2878 | case R_IA64_LTOFF_FPTR32LSB: | |
800eeca4 JW |
2879 | case R_IA64_LTOFF_FPTR64MSB: |
2880 | case R_IA64_LTOFF_FPTR64LSB: | |
2881 | need_entry = NEED_FPTR | NEED_GOT | NEED_LTOFF_FPTR; | |
2882 | break; | |
2883 | ||
2884 | case R_IA64_FPTR64I: | |
2885 | case R_IA64_FPTR32MSB: | |
2886 | case R_IA64_FPTR32LSB: | |
2887 | case R_IA64_FPTR64MSB: | |
2888 | case R_IA64_FPTR64LSB: | |
02e6ad56 | 2889 | if (info->shared || h) |
800eeca4 JW |
2890 | need_entry = NEED_FPTR | NEED_DYNREL; |
2891 | else | |
2892 | need_entry = NEED_FPTR; | |
5a260b66 | 2893 | dynrel_type = R_IA64_FPTRNNLSB; |
800eeca4 JW |
2894 | break; |
2895 | ||
2896 | case R_IA64_LTOFF22: | |
800eeca4 JW |
2897 | case R_IA64_LTOFF64I: |
2898 | need_entry = NEED_GOT; | |
2899 | break; | |
2900 | ||
2c4c2bc0 RH |
2901 | case R_IA64_LTOFF22X: |
2902 | need_entry = NEED_GOTX; | |
2903 | break; | |
2904 | ||
800eeca4 JW |
2905 | case R_IA64_PLTOFF22: |
2906 | case R_IA64_PLTOFF64I: | |
2907 | case R_IA64_PLTOFF64MSB: | |
2908 | case R_IA64_PLTOFF64LSB: | |
2909 | need_entry = NEED_PLTOFF; | |
2910 | if (h) | |
2911 | { | |
2912 | if (maybe_dynamic) | |
2913 | need_entry |= NEED_MIN_PLT; | |
2914 | } | |
800eeca4 JW |
2915 | break; |
2916 | ||
2917 | case R_IA64_PCREL21B: | |
748abff6 | 2918 | case R_IA64_PCREL60B: |
800eeca4 JW |
2919 | /* Depending on where this symbol is defined, we may or may not |
2920 | need a full plt entry. Only skip if we know we'll not need | |
2921 | the entry -- static or symbolic, and the symbol definition | |
2922 | has already been seen. */ | |
2923 | if (maybe_dynamic && rel->r_addend == 0) | |
2924 | need_entry = NEED_FULL_PLT; | |
2925 | break; | |
2926 | ||
2927 | case R_IA64_IMM14: | |
2928 | case R_IA64_IMM22: | |
2929 | case R_IA64_IMM64: | |
2930 | case R_IA64_DIR32MSB: | |
2931 | case R_IA64_DIR32LSB: | |
2932 | case R_IA64_DIR64MSB: | |
2933 | case R_IA64_DIR64LSB: | |
2934 | /* Shared objects will always need at least a REL relocation. */ | |
02e6ad56 | 2935 | if (info->shared || maybe_dynamic) |
800eeca4 | 2936 | need_entry = NEED_DYNREL; |
5a260b66 | 2937 | dynrel_type = R_IA64_DIRNNLSB; |
800eeca4 JW |
2938 | break; |
2939 | ||
18b27f17 RH |
2940 | case R_IA64_IPLTMSB: |
2941 | case R_IA64_IPLTLSB: | |
2942 | /* Shared objects will always need at least a REL relocation. */ | |
2943 | if (info->shared || maybe_dynamic) | |
2944 | need_entry = NEED_DYNREL; | |
2945 | dynrel_type = R_IA64_IPLTLSB; | |
2946 | break; | |
2947 | ||
748abff6 RH |
2948 | case R_IA64_PCREL22: |
2949 | case R_IA64_PCREL64I: | |
800eeca4 JW |
2950 | case R_IA64_PCREL32MSB: |
2951 | case R_IA64_PCREL32LSB: | |
2952 | case R_IA64_PCREL64MSB: | |
2953 | case R_IA64_PCREL64LSB: | |
2954 | if (maybe_dynamic) | |
2955 | need_entry = NEED_DYNREL; | |
5a260b66 | 2956 | dynrel_type = R_IA64_PCRELNNLSB; |
800eeca4 JW |
2957 | break; |
2958 | } | |
2959 | ||
2960 | if (!need_entry) | |
2961 | continue; | |
2962 | ||
396a682d | 2963 | dyn_i = get_dyn_sym_info (ia64_info, h, abfd, rel, FALSE); |
800eeca4 JW |
2964 | |
2965 | /* Record whether or not this is a local symbol. */ | |
2966 | dyn_i->h = h; | |
2967 | ||
2968 | /* Create what's needed. */ | |
2c4c2bc0 RH |
2969 | if (need_entry & (NEED_GOT | NEED_GOTX | NEED_TPREL |
2970 | | NEED_DTPMOD | NEED_DTPREL)) | |
800eeca4 JW |
2971 | { |
2972 | if (!got) | |
2973 | { | |
2974 | got = get_got (abfd, info, ia64_info); | |
2975 | if (!got) | |
b34976b6 | 2976 | return FALSE; |
800eeca4 | 2977 | } |
13ae64f3 JJ |
2978 | if (need_entry & NEED_GOT) |
2979 | dyn_i->want_got = 1; | |
2c4c2bc0 RH |
2980 | if (need_entry & NEED_GOTX) |
2981 | dyn_i->want_gotx = 1; | |
13ae64f3 JJ |
2982 | if (need_entry & NEED_TPREL) |
2983 | dyn_i->want_tprel = 1; | |
2984 | if (need_entry & NEED_DTPMOD) | |
2985 | dyn_i->want_dtpmod = 1; | |
2986 | if (need_entry & NEED_DTPREL) | |
2987 | dyn_i->want_dtprel = 1; | |
800eeca4 JW |
2988 | } |
2989 | if (need_entry & NEED_FPTR) | |
2990 | { | |
2991 | if (!fptr) | |
2992 | { | |
2993 | fptr = get_fptr (abfd, info, ia64_info); | |
2994 | if (!fptr) | |
b34976b6 | 2995 | return FALSE; |
800eeca4 JW |
2996 | } |
2997 | ||
2998 | /* FPTRs for shared libraries are allocated by the dynamic | |
2999 | linker. Make sure this local symbol will appear in the | |
3000 | dynamic symbol table. */ | |
02e6ad56 | 3001 | if (!h && info->shared) |
800eeca4 | 3002 | { |
c152c796 | 3003 | if (! (bfd_elf_link_record_local_dynamic_symbol |
dc810e39 | 3004 | (info, abfd, (long) r_symndx))) |
b34976b6 | 3005 | return FALSE; |
800eeca4 JW |
3006 | } |
3007 | ||
3008 | dyn_i->want_fptr = 1; | |
3009 | } | |
3010 | if (need_entry & NEED_LTOFF_FPTR) | |
3011 | dyn_i->want_ltoff_fptr = 1; | |
3012 | if (need_entry & (NEED_MIN_PLT | NEED_FULL_PLT)) | |
3013 | { | |
3014 | if (!ia64_info->root.dynobj) | |
3015 | ia64_info->root.dynobj = abfd; | |
f5385ebf | 3016 | h->needs_plt = 1; |
800eeca4 JW |
3017 | dyn_i->want_plt = 1; |
3018 | } | |
3019 | if (need_entry & NEED_FULL_PLT) | |
3020 | dyn_i->want_plt2 = 1; | |
3021 | if (need_entry & NEED_PLTOFF) | |
21a8f7fa JW |
3022 | { |
3023 | /* This is needed here, in case @pltoff is used in a non-shared | |
3024 | link. */ | |
3025 | if (!pltoff) | |
3026 | { | |
3027 | pltoff = get_pltoff (abfd, info, ia64_info); | |
3028 | if (!pltoff) | |
3029 | return FALSE; | |
3030 | } | |
f12123c0 | 3031 | |
21a8f7fa JW |
3032 | dyn_i->want_pltoff = 1; |
3033 | } | |
800eeca4 JW |
3034 | if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC)) |
3035 | { | |
3036 | if (!srel) | |
3037 | { | |
b34976b6 | 3038 | srel = get_reloc_section (abfd, ia64_info, sec, TRUE); |
800eeca4 | 3039 | if (!srel) |
b34976b6 | 3040 | return FALSE; |
800eeca4 | 3041 | } |
ac33696c | 3042 | if (!count_dyn_reloc (abfd, dyn_i, srel, dynrel_type, |
de9811af | 3043 | (sec->flags & SEC_READONLY) != 0)) |
b34976b6 | 3044 | return FALSE; |
800eeca4 JW |
3045 | } |
3046 | } | |
3047 | ||
b34976b6 | 3048 | return TRUE; |
800eeca4 JW |
3049 | } |
3050 | ||
800eeca4 JW |
3051 | /* For cleanliness, and potentially faster dynamic loading, allocate |
3052 | external GOT entries first. */ | |
3053 | ||
b34976b6 | 3054 | static bfd_boolean |
eae50df2 L |
3055 | allocate_global_data_got (struct elfNN_ia64_dyn_sym_info *dyn_i, |
3056 | PTR data) | |
800eeca4 | 3057 | { |
bbe66d08 | 3058 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
800eeca4 | 3059 | |
2c4c2bc0 | 3060 | if ((dyn_i->want_got || dyn_i->want_gotx) |
800eeca4 | 3061 | && ! dyn_i->want_fptr |
986a241f | 3062 | && elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, 0)) |
800eeca4 JW |
3063 | { |
3064 | dyn_i->got_offset = x->ofs; | |
3065 | x->ofs += 8; | |
3066 | } | |
13ae64f3 JJ |
3067 | if (dyn_i->want_tprel) |
3068 | { | |
3069 | dyn_i->tprel_offset = x->ofs; | |
3070 | x->ofs += 8; | |
3071 | } | |
3072 | if (dyn_i->want_dtpmod) | |
3073 | { | |
986a241f | 3074 | if (elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, 0)) |
b3dfd7fe JJ |
3075 | { |
3076 | dyn_i->dtpmod_offset = x->ofs; | |
3077 | x->ofs += 8; | |
3078 | } | |
3079 | else | |
3080 | { | |
3081 | struct elfNN_ia64_link_hash_table *ia64_info; | |
3082 | ||
3083 | ia64_info = elfNN_ia64_hash_table (x->info); | |
3084 | if (ia64_info->self_dtpmod_offset == (bfd_vma) -1) | |
3085 | { | |
3086 | ia64_info->self_dtpmod_offset = x->ofs; | |
3087 | x->ofs += 8; | |
3088 | } | |
3089 | dyn_i->dtpmod_offset = ia64_info->self_dtpmod_offset; | |
3090 | } | |
13ae64f3 JJ |
3091 | } |
3092 | if (dyn_i->want_dtprel) | |
3093 | { | |
3094 | dyn_i->dtprel_offset = x->ofs; | |
3095 | x->ofs += 8; | |
3096 | } | |
b34976b6 | 3097 | return TRUE; |
800eeca4 JW |
3098 | } |
3099 | ||
3100 | /* Next, allocate all the GOT entries used by LTOFF_FPTR relocs. */ | |
3101 | ||
b34976b6 | 3102 | static bfd_boolean |
eae50df2 L |
3103 | allocate_global_fptr_got (struct elfNN_ia64_dyn_sym_info *dyn_i, |
3104 | PTR data) | |
800eeca4 | 3105 | { |
bbe66d08 | 3106 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
800eeca4 JW |
3107 | |
3108 | if (dyn_i->want_got | |
3109 | && dyn_i->want_fptr | |
5a260b66 | 3110 | && elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, R_IA64_FPTRNNLSB)) |
800eeca4 JW |
3111 | { |
3112 | dyn_i->got_offset = x->ofs; | |
3113 | x->ofs += 8; | |
3114 | } | |
b34976b6 | 3115 | return TRUE; |
800eeca4 JW |
3116 | } |
3117 | ||
3118 | /* Lastly, allocate all the GOT entries for local data. */ | |
3119 | ||
b34976b6 | 3120 | static bfd_boolean |
eae50df2 L |
3121 | allocate_local_got (struct elfNN_ia64_dyn_sym_info *dyn_i, |
3122 | PTR data) | |
800eeca4 | 3123 | { |
bbe66d08 | 3124 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
800eeca4 | 3125 | |
2c4c2bc0 | 3126 | if ((dyn_i->want_got || dyn_i->want_gotx) |
986a241f | 3127 | && !elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, 0)) |
800eeca4 JW |
3128 | { |
3129 | dyn_i->got_offset = x->ofs; | |
3130 | x->ofs += 8; | |
3131 | } | |
b34976b6 | 3132 | return TRUE; |
800eeca4 JW |
3133 | } |
3134 | ||
3135 | /* Search for the index of a global symbol in it's defining object file. */ | |
3136 | ||
dc810e39 | 3137 | static long |
eae50df2 | 3138 | global_sym_index (struct elf_link_hash_entry *h) |
800eeca4 JW |
3139 | { |
3140 | struct elf_link_hash_entry **p; | |
3141 | bfd *obj; | |
3142 | ||
3143 | BFD_ASSERT (h->root.type == bfd_link_hash_defined | |
3144 | || h->root.type == bfd_link_hash_defweak); | |
3145 | ||
3146 | obj = h->root.u.def.section->owner; | |
3147 | for (p = elf_sym_hashes (obj); *p != h; ++p) | |
3148 | continue; | |
3149 | ||
3150 | return p - elf_sym_hashes (obj) + elf_tdata (obj)->symtab_hdr.sh_info; | |
3151 | } | |
3152 | ||
3153 | /* Allocate function descriptors. We can do these for every function | |
3154 | in a main executable that is not exported. */ | |
3155 | ||
b34976b6 | 3156 | static bfd_boolean |
eae50df2 | 3157 | allocate_fptr (struct elfNN_ia64_dyn_sym_info *dyn_i, PTR data) |
800eeca4 | 3158 | { |
bbe66d08 | 3159 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
800eeca4 JW |
3160 | |
3161 | if (dyn_i->want_fptr) | |
3162 | { | |
3163 | struct elf_link_hash_entry *h = dyn_i->h; | |
3e932841 | 3164 | |
800eeca4 JW |
3165 | if (h) |
3166 | while (h->root.type == bfd_link_hash_indirect | |
3167 | || h->root.type == bfd_link_hash_warning) | |
3168 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3169 | ||
02e6ad56 RH |
3170 | if (!x->info->executable |
3171 | && (!h | |
3172 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
1faab634 L |
3173 | || (h->root.type != bfd_link_hash_undefweak |
3174 | && h->root.type != bfd_link_hash_undefined))) | |
800eeca4 JW |
3175 | { |
3176 | if (h && h->dynindx == -1) | |
3177 | { | |
3178 | BFD_ASSERT ((h->root.type == bfd_link_hash_defined) | |
3179 | || (h->root.type == bfd_link_hash_defweak)); | |
3180 | ||
c152c796 | 3181 | if (!bfd_elf_link_record_local_dynamic_symbol |
800eeca4 JW |
3182 | (x->info, h->root.u.def.section->owner, |
3183 | global_sym_index (h))) | |
b34976b6 | 3184 | return FALSE; |
800eeca4 JW |
3185 | } |
3186 | ||
3187 | dyn_i->want_fptr = 0; | |
3188 | } | |
3189 | else if (h == NULL || h->dynindx == -1) | |
3190 | { | |
3191 | dyn_i->fptr_offset = x->ofs; | |
3192 | x->ofs += 16; | |
3193 | } | |
3194 | else | |
3195 | dyn_i->want_fptr = 0; | |
3196 | } | |
b34976b6 | 3197 | return TRUE; |
800eeca4 JW |
3198 | } |
3199 | ||
3200 | /* Allocate all the minimal PLT entries. */ | |
3201 | ||
b34976b6 | 3202 | static bfd_boolean |
eae50df2 L |
3203 | allocate_plt_entries (struct elfNN_ia64_dyn_sym_info *dyn_i, |
3204 | PTR data) | |
800eeca4 | 3205 | { |
bbe66d08 | 3206 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
800eeca4 JW |
3207 | |
3208 | if (dyn_i->want_plt) | |
3209 | { | |
3210 | struct elf_link_hash_entry *h = dyn_i->h; | |
3211 | ||
3212 | if (h) | |
3213 | while (h->root.type == bfd_link_hash_indirect | |
3214 | || h->root.type == bfd_link_hash_warning) | |
3215 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3216 | ||
f5385ebf | 3217 | /* ??? Versioned symbols seem to lose NEEDS_PLT. */ |
986a241f | 3218 | if (elfNN_ia64_dynamic_symbol_p (h, x->info, 0)) |
800eeca4 JW |
3219 | { |
3220 | bfd_size_type offset = x->ofs; | |
3221 | if (offset == 0) | |
3222 | offset = PLT_HEADER_SIZE; | |
3223 | dyn_i->plt_offset = offset; | |
3224 | x->ofs = offset + PLT_MIN_ENTRY_SIZE; | |
3225 | ||
3226 | dyn_i->want_pltoff = 1; | |
3227 | } | |
3228 | else | |
3229 | { | |
3230 | dyn_i->want_plt = 0; | |
3231 | dyn_i->want_plt2 = 0; | |
3232 | } | |
3233 | } | |
b34976b6 | 3234 | return TRUE; |
800eeca4 JW |
3235 | } |
3236 | ||
3237 | /* Allocate all the full PLT entries. */ | |
3238 | ||
b34976b6 | 3239 | static bfd_boolean |
eae50df2 L |
3240 | allocate_plt2_entries (struct elfNN_ia64_dyn_sym_info *dyn_i, |
3241 | PTR data) | |
800eeca4 | 3242 | { |
bbe66d08 | 3243 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
800eeca4 JW |
3244 | |
3245 | if (dyn_i->want_plt2) | |
3246 | { | |
3247 | struct elf_link_hash_entry *h = dyn_i->h; | |
3248 | bfd_size_type ofs = x->ofs; | |
3249 | ||
3250 | dyn_i->plt2_offset = ofs; | |
3251 | x->ofs = ofs + PLT_FULL_ENTRY_SIZE; | |
3252 | ||
3253 | while (h->root.type == bfd_link_hash_indirect | |
3254 | || h->root.type == bfd_link_hash_warning) | |
3255 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3256 | dyn_i->h->plt.offset = ofs; | |
3257 | } | |
b34976b6 | 3258 | return TRUE; |
800eeca4 JW |
3259 | } |
3260 | ||
3261 | /* Allocate all the PLTOFF entries requested by relocations and | |
3262 | plt entries. We can't share space with allocated FPTR entries, | |
3263 | because the latter are not necessarily addressable by the GP. | |
3264 | ??? Relaxation might be able to determine that they are. */ | |
3265 | ||
b34976b6 | 3266 | static bfd_boolean |
eae50df2 L |
3267 | allocate_pltoff_entries (struct elfNN_ia64_dyn_sym_info *dyn_i, |
3268 | PTR data) | |
800eeca4 | 3269 | { |
bbe66d08 | 3270 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
800eeca4 JW |
3271 | |
3272 | if (dyn_i->want_pltoff) | |
3273 | { | |
3274 | dyn_i->pltoff_offset = x->ofs; | |
3275 | x->ofs += 16; | |
3276 | } | |
b34976b6 | 3277 | return TRUE; |
800eeca4 JW |
3278 | } |
3279 | ||
3280 | /* Allocate dynamic relocations for those symbols that turned out | |
3281 | to be dynamic. */ | |
3282 | ||
b34976b6 | 3283 | static bfd_boolean |
eae50df2 L |
3284 | allocate_dynrel_entries (struct elfNN_ia64_dyn_sym_info *dyn_i, |
3285 | PTR data) | |
800eeca4 | 3286 | { |
bbe66d08 JW |
3287 | struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data; |
3288 | struct elfNN_ia64_link_hash_table *ia64_info; | |
3289 | struct elfNN_ia64_dyn_reloc_entry *rent; | |
ef5aade5 | 3290 | bfd_boolean dynamic_symbol, shared, resolved_zero; |
800eeca4 | 3291 | |
bbe66d08 | 3292 | ia64_info = elfNN_ia64_hash_table (x->info); |
986a241f RH |
3293 | |
3294 | /* Note that this can't be used in relation to FPTR relocs below. */ | |
3295 | dynamic_symbol = elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info, 0); | |
3296 | ||
800eeca4 | 3297 | shared = x->info->shared; |
ef5aade5 L |
3298 | resolved_zero = (dyn_i->h |
3299 | && ELF_ST_VISIBILITY (dyn_i->h->other) | |
3300 | && dyn_i->h->root.type == bfd_link_hash_undefweak); | |
800eeca4 | 3301 | |
4a78a1f4 AS |
3302 | /* Take care of the GOT and PLT relocations. */ |
3303 | ||
3304 | if ((!resolved_zero | |
3305 | && (dynamic_symbol || shared) | |
3306 | && (dyn_i->want_got || dyn_i->want_gotx)) | |
3307 | || (dyn_i->want_ltoff_fptr | |
3308 | && dyn_i->h | |
3309 | && dyn_i->h->dynindx != -1)) | |
3310 | { | |
3311 | if (!dyn_i->want_ltoff_fptr | |
3312 | || !x->info->pie | |
3313 | || dyn_i->h == NULL | |
3314 | || dyn_i->h->root.type != bfd_link_hash_undefweak) | |
cc3bd654 | 3315 | ia64_info->root.srelgot->size += sizeof (ElfNN_External_Rela); |
4a78a1f4 AS |
3316 | } |
3317 | if ((dynamic_symbol || shared) && dyn_i->want_tprel) | |
cc3bd654 | 3318 | ia64_info->root.srelgot->size += sizeof (ElfNN_External_Rela); |
4a78a1f4 | 3319 | if (dynamic_symbol && dyn_i->want_dtpmod) |
cc3bd654 | 3320 | ia64_info->root.srelgot->size += sizeof (ElfNN_External_Rela); |
4a78a1f4 | 3321 | if (dynamic_symbol && dyn_i->want_dtprel) |
cc3bd654 | 3322 | ia64_info->root.srelgot->size += sizeof (ElfNN_External_Rela); |
4a78a1f4 AS |
3323 | |
3324 | if (x->only_got) | |
3325 | return TRUE; | |
3326 | ||
3327 | if (ia64_info->rel_fptr_sec && dyn_i->want_fptr) | |
3328 | { | |
3329 | if (dyn_i->h == NULL || dyn_i->h->root.type != bfd_link_hash_undefweak) | |
3330 | ia64_info->rel_fptr_sec->size += sizeof (ElfNN_External_Rela); | |
3331 | } | |
3332 | ||
3333 | if (!resolved_zero && dyn_i->want_pltoff) | |
3334 | { | |
3335 | bfd_size_type t = 0; | |
3336 | ||
3337 | /* Dynamic symbols get one IPLT relocation. Local symbols in | |
3338 | shared libraries get two REL relocations. Local symbols in | |
3339 | main applications get nothing. */ | |
3340 | if (dynamic_symbol) | |
3341 | t = sizeof (ElfNN_External_Rela); | |
3342 | else if (shared) | |
3343 | t = 2 * sizeof (ElfNN_External_Rela); | |
3344 | ||
3345 | ia64_info->rel_pltoff_sec->size += t; | |
3346 | } | |
3347 | ||
800eeca4 JW |
3348 | /* Take care of the normal data relocations. */ |
3349 | ||
3350 | for (rent = dyn_i->reloc_entries; rent; rent = rent->next) | |
3351 | { | |
18b27f17 RH |
3352 | int count = rent->count; |
3353 | ||
800eeca4 JW |
3354 | switch (rent->type) |
3355 | { | |
5a260b66 | 3356 | case R_IA64_FPTR32LSB: |
800eeca4 | 3357 | case R_IA64_FPTR64LSB: |
9203ba99 JJ |
3358 | /* Allocate one iff !want_fptr and not PIE, which by this point |
3359 | will be true only if we're actually allocating one statically | |
3360 | in the main executable. Position independent executables | |
3361 | need a relative reloc. */ | |
3362 | if (dyn_i->want_fptr && !x->info->pie) | |
800eeca4 JW |
3363 | continue; |
3364 | break; | |
5a260b66 | 3365 | case R_IA64_PCREL32LSB: |
800eeca4 JW |
3366 | case R_IA64_PCREL64LSB: |
3367 | if (!dynamic_symbol) | |
3368 | continue; | |
3369 | break; | |
5a260b66 | 3370 | case R_IA64_DIR32LSB: |
800eeca4 JW |
3371 | case R_IA64_DIR64LSB: |
3372 | if (!dynamic_symbol && !shared) | |
3373 | continue; | |
3374 | break; | |
18b27f17 RH |
3375 | case R_IA64_IPLTLSB: |
3376 | if (!dynamic_symbol && !shared) | |
3377 | continue; | |
3378 | /* Use two REL relocations for IPLT relocations | |
3379 | against local symbols. */ | |
3380 | if (!dynamic_symbol) | |
3381 | count *= 2; | |
3382 | break; | |
5a260b66 | 3383 | case R_IA64_DTPREL32LSB: |
13ae64f3 JJ |
3384 | case R_IA64_TPREL64LSB: |
3385 | case R_IA64_DTPREL64LSB: | |
3386 | case R_IA64_DTPMOD64LSB: | |
3387 | break; | |
18b27f17 RH |
3388 | default: |
3389 | abort (); | |
800eeca4 | 3390 | } |
ac33696c L |
3391 | if (rent->reltext) |
3392 | ia64_info->reltext = 1; | |
eea6121a | 3393 | rent->srel->size += sizeof (ElfNN_External_Rela) * count; |
800eeca4 JW |
3394 | } |
3395 | ||
b34976b6 | 3396 | return TRUE; |
800eeca4 JW |
3397 | } |
3398 | ||
b34976b6 | 3399 | static bfd_boolean |
eae50df2 L |
3400 | elfNN_ia64_adjust_dynamic_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED, |
3401 | struct elf_link_hash_entry *h) | |
800eeca4 JW |
3402 | { |
3403 | /* ??? Undefined symbols with PLT entries should be re-defined | |
3404 | to be the PLT entry. */ | |
3405 | ||
3406 | /* If this is a weak symbol, and there is a real definition, the | |
3407 | processor independent code will have arranged for us to see the | |
3408 | real definition first, and we can just use the same value. */ | |
f6e332e6 | 3409 | if (h->u.weakdef != NULL) |
800eeca4 | 3410 | { |
f6e332e6 AM |
3411 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
3412 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
3413 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
3414 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
b34976b6 | 3415 | return TRUE; |
800eeca4 JW |
3416 | } |
3417 | ||
3418 | /* If this is a reference to a symbol defined by a dynamic object which | |
3419 | is not a function, we might allocate the symbol in our .dynbss section | |
3420 | and allocate a COPY dynamic relocation. | |
3421 | ||
3422 | But IA-64 code is canonically PIC, so as a rule we can avoid this sort | |
3423 | of hackery. */ | |
3424 | ||
b34976b6 | 3425 | return TRUE; |
800eeca4 JW |
3426 | } |
3427 | ||
b34976b6 | 3428 | static bfd_boolean |
eae50df2 L |
3429 | elfNN_ia64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
3430 | struct bfd_link_info *info) | |
800eeca4 | 3431 | { |
bbe66d08 JW |
3432 | struct elfNN_ia64_allocate_data data; |
3433 | struct elfNN_ia64_link_hash_table *ia64_info; | |
800eeca4 JW |
3434 | asection *sec; |
3435 | bfd *dynobj; | |
b34976b6 | 3436 | bfd_boolean relplt = FALSE; |
800eeca4 JW |
3437 | |
3438 | dynobj = elf_hash_table(info)->dynobj; | |
bbe66d08 | 3439 | ia64_info = elfNN_ia64_hash_table (info); |
b3dfd7fe | 3440 | ia64_info->self_dtpmod_offset = (bfd_vma) -1; |
800eeca4 JW |
3441 | BFD_ASSERT(dynobj != NULL); |
3442 | data.info = info; | |
3443 | ||
3444 | /* Set the contents of the .interp section to the interpreter. */ | |
3445 | if (ia64_info->root.dynamic_sections_created | |
36af4a4e | 3446 | && info->executable) |
800eeca4 JW |
3447 | { |
3448 | sec = bfd_get_section_by_name (dynobj, ".interp"); | |
3449 | BFD_ASSERT (sec != NULL); | |
02e6ad56 | 3450 | sec->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER; |
eea6121a | 3451 | sec->size = strlen (ELF_DYNAMIC_INTERPRETER) + 1; |
800eeca4 JW |
3452 | } |
3453 | ||
800eeca4 JW |
3454 | /* Allocate the GOT entries. */ |
3455 | ||
cc3bd654 | 3456 | if (ia64_info->root.sgot) |
800eeca4 JW |
3457 | { |
3458 | data.ofs = 0; | |
bbe66d08 JW |
3459 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_global_data_got, &data); |
3460 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_global_fptr_got, &data); | |
3461 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_local_got, &data); | |
cc3bd654 | 3462 | ia64_info->root.sgot->size = data.ofs; |
800eeca4 JW |
3463 | } |
3464 | ||
3465 | /* Allocate the FPTR entries. */ | |
3466 | ||
3467 | if (ia64_info->fptr_sec) | |
3468 | { | |
3469 | data.ofs = 0; | |
bbe66d08 | 3470 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_fptr, &data); |
eea6121a | 3471 | ia64_info->fptr_sec->size = data.ofs; |
800eeca4 JW |
3472 | } |
3473 | ||
3474 | /* Now that we've seen all of the input files, we can decide which | |
3475 | symbols need plt entries. Allocate the minimal PLT entries first. | |
b34976b6 | 3476 | We do this even though dynamic_sections_created may be FALSE, because |
800eeca4 JW |
3477 | this has the side-effect of clearing want_plt and want_plt2. */ |
3478 | ||
3479 | data.ofs = 0; | |
bbe66d08 | 3480 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_plt_entries, &data); |
800eeca4 JW |
3481 | |
3482 | ia64_info->minplt_entries = 0; | |
3483 | if (data.ofs) | |
3484 | { | |
3485 | ia64_info->minplt_entries | |
3486 | = (data.ofs - PLT_HEADER_SIZE) / PLT_MIN_ENTRY_SIZE; | |
3487 | } | |
3488 | ||
3489 | /* Align the pointer for the plt2 entries. */ | |
dc810e39 | 3490 | data.ofs = (data.ofs + 31) & (bfd_vma) -32; |
800eeca4 | 3491 | |
bbe66d08 | 3492 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_plt2_entries, &data); |
a5a58ba4 | 3493 | if (data.ofs != 0 || ia64_info->root.dynamic_sections_created) |
800eeca4 | 3494 | { |
a5a58ba4 L |
3495 | /* FIXME: we always reserve the memory for dynamic linker even if |
3496 | there are no PLT entries since dynamic linker may assume the | |
3497 | reserved memory always exists. */ | |
3498 | ||
800eeca4 JW |
3499 | BFD_ASSERT (ia64_info->root.dynamic_sections_created); |
3500 | ||
cc3bd654 | 3501 | ia64_info->root.splt->size = data.ofs; |
800eeca4 JW |
3502 | |
3503 | /* If we've got a .plt, we need some extra memory for the dynamic | |
3504 | linker. We stuff these in .got.plt. */ | |
3505 | sec = bfd_get_section_by_name (dynobj, ".got.plt"); | |
eea6121a | 3506 | sec->size = 8 * PLT_RESERVED_WORDS; |
800eeca4 JW |
3507 | } |
3508 | ||
3509 | /* Allocate the PLTOFF entries. */ | |
3510 | ||
3511 | if (ia64_info->pltoff_sec) | |
3512 | { | |
3513 | data.ofs = 0; | |
bbe66d08 | 3514 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_pltoff_entries, &data); |
eea6121a | 3515 | ia64_info->pltoff_sec->size = data.ofs; |
800eeca4 JW |
3516 | } |
3517 | ||
3518 | if (ia64_info->root.dynamic_sections_created) | |
3519 | { | |
3520 | /* Allocate space for the dynamic relocations that turned out to be | |
3521 | required. */ | |
3522 | ||
b3dfd7fe | 3523 | if (info->shared && ia64_info->self_dtpmod_offset != (bfd_vma) -1) |
cc3bd654 | 3524 | ia64_info->root.srelgot->size += sizeof (ElfNN_External_Rela); |
4a78a1f4 | 3525 | data.only_got = FALSE; |
bbe66d08 | 3526 | elfNN_ia64_dyn_sym_traverse (ia64_info, allocate_dynrel_entries, &data); |
800eeca4 JW |
3527 | } |
3528 | ||
3529 | /* We have now determined the sizes of the various dynamic sections. | |
3530 | Allocate memory for them. */ | |
3531 | for (sec = dynobj->sections; sec != NULL; sec = sec->next) | |
3532 | { | |
b34976b6 | 3533 | bfd_boolean strip; |
800eeca4 JW |
3534 | |
3535 | if (!(sec->flags & SEC_LINKER_CREATED)) | |
3536 | continue; | |
3537 | ||
3538 | /* If we don't need this section, strip it from the output file. | |
3539 | There were several sections primarily related to dynamic | |
3540 | linking that must be create before the linker maps input | |
3541 | sections to output sections. The linker does that before | |
3542 | bfd_elf_size_dynamic_sections is called, and it is that | |
3543 | function which decides whether anything needs to go into | |
3544 | these sections. */ | |
3545 | ||
eea6121a | 3546 | strip = (sec->size == 0); |
800eeca4 | 3547 | |
cc3bd654 | 3548 | if (sec == ia64_info->root.sgot) |
b34976b6 | 3549 | strip = FALSE; |
cc3bd654 | 3550 | else if (sec == ia64_info->root.srelgot) |
800eeca4 JW |
3551 | { |
3552 | if (strip) | |
cc3bd654 | 3553 | ia64_info->root.srelgot = NULL; |
800eeca4 JW |
3554 | else |
3555 | /* We use the reloc_count field as a counter if we need to | |
3556 | copy relocs into the output file. */ | |
3557 | sec->reloc_count = 0; | |
3558 | } | |
3559 | else if (sec == ia64_info->fptr_sec) | |
3560 | { | |
3561 | if (strip) | |
3562 | ia64_info->fptr_sec = NULL; | |
3563 | } | |
55936540 JW |
3564 | else if (sec == ia64_info->rel_fptr_sec) |
3565 | { | |
3566 | if (strip) | |
3567 | ia64_info->rel_fptr_sec = NULL; | |
3568 | else | |
3569 | /* We use the reloc_count field as a counter if we need to | |
3570 | copy relocs into the output file. */ | |
3571 | sec->reloc_count = 0; | |
3572 | } | |
cc3bd654 | 3573 | else if (sec == ia64_info->root.splt) |
800eeca4 JW |
3574 | { |
3575 | if (strip) | |
cc3bd654 | 3576 | ia64_info->root.splt = NULL; |
800eeca4 JW |
3577 | } |
3578 | else if (sec == ia64_info->pltoff_sec) | |
3579 | { | |
3580 | if (strip) | |
3581 | ia64_info->pltoff_sec = NULL; | |
3582 | } | |
3583 | else if (sec == ia64_info->rel_pltoff_sec) | |
3584 | { | |
3585 | if (strip) | |
3586 | ia64_info->rel_pltoff_sec = NULL; | |
3587 | else | |
3588 | { | |
b34976b6 | 3589 | relplt = TRUE; |
800eeca4 JW |
3590 | /* We use the reloc_count field as a counter if we need to |
3591 | copy relocs into the output file. */ | |
3592 | sec->reloc_count = 0; | |
3593 | } | |
3594 | } | |
3595 | else | |
3596 | { | |
3597 | const char *name; | |
3598 | ||
3599 | /* It's OK to base decisions on the section name, because none | |
3600 | of the dynobj section names depend upon the input files. */ | |
3601 | name = bfd_get_section_name (dynobj, sec); | |
3602 | ||
3603 | if (strcmp (name, ".got.plt") == 0) | |
b34976b6 | 3604 | strip = FALSE; |
0112cd26 | 3605 | else if (CONST_STRNEQ (name, ".rel")) |
800eeca4 JW |
3606 | { |
3607 | if (!strip) | |
3608 | { | |
800eeca4 JW |
3609 | /* We use the reloc_count field as a counter if we need to |
3610 | copy relocs into the output file. */ | |
3611 | sec->reloc_count = 0; | |
3612 | } | |
3613 | } | |
3614 | else | |
3615 | continue; | |
3616 | } | |
3617 | ||
3618 | if (strip) | |
8423293d | 3619 | sec->flags |= SEC_EXCLUDE; |
800eeca4 JW |
3620 | else |
3621 | { | |
3622 | /* Allocate memory for the section contents. */ | |
eea6121a AM |
3623 | sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size); |
3624 | if (sec->contents == NULL && sec->size != 0) | |
b34976b6 | 3625 | return FALSE; |
800eeca4 JW |
3626 | } |
3627 | } | |
3628 | ||
3629 | if (elf_hash_table (info)->dynamic_sections_created) | |
3630 | { | |
3631 | /* Add some entries to the .dynamic section. We fill in the values | |
3632 | later (in finish_dynamic_sections) but we must add the entries now | |
3633 | so that we get the correct size for the .dynamic section. */ | |
3634 | ||
36af4a4e | 3635 | if (info->executable) |
800eeca4 JW |
3636 | { |
3637 | /* The DT_DEBUG entry is filled in by the dynamic linker and used | |
3638 | by the debugger. */ | |
dc810e39 | 3639 | #define add_dynamic_entry(TAG, VAL) \ |
5a580b3a | 3640 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
dc810e39 AM |
3641 | |
3642 | if (!add_dynamic_entry (DT_DEBUG, 0)) | |
b34976b6 | 3643 | return FALSE; |
800eeca4 JW |
3644 | } |
3645 | ||
dc810e39 | 3646 | if (!add_dynamic_entry (DT_IA_64_PLT_RESERVE, 0)) |
b34976b6 | 3647 | return FALSE; |
dc810e39 | 3648 | if (!add_dynamic_entry (DT_PLTGOT, 0)) |
b34976b6 | 3649 | return FALSE; |
800eeca4 JW |
3650 | |
3651 | if (relplt) | |
3652 | { | |
dc810e39 AM |
3653 | if (!add_dynamic_entry (DT_PLTRELSZ, 0) |
3654 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
3655 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
b34976b6 | 3656 | return FALSE; |
800eeca4 JW |
3657 | } |
3658 | ||
dc810e39 AM |
3659 | if (!add_dynamic_entry (DT_RELA, 0) |
3660 | || !add_dynamic_entry (DT_RELASZ, 0) | |
3661 | || !add_dynamic_entry (DT_RELAENT, sizeof (ElfNN_External_Rela))) | |
b34976b6 | 3662 | return FALSE; |
800eeca4 | 3663 | |
db6751f2 | 3664 | if (ia64_info->reltext) |
800eeca4 | 3665 | { |
dc810e39 | 3666 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 3667 | return FALSE; |
d6cf2879 | 3668 | info->flags |= DF_TEXTREL; |
800eeca4 JW |
3669 | } |
3670 | } | |
3671 | ||
3672 | /* ??? Perhaps force __gp local. */ | |
3673 | ||
b34976b6 | 3674 | return TRUE; |
800eeca4 JW |
3675 | } |
3676 | ||
3677 | static bfd_reloc_status_type | |
eae50df2 L |
3678 | elfNN_ia64_install_value (bfd_byte *hit_addr, bfd_vma v, |
3679 | unsigned int r_type) | |
800eeca4 JW |
3680 | { |
3681 | const struct ia64_operand *op; | |
3682 | int bigendian = 0, shift = 0; | |
b4677f03 AS |
3683 | bfd_vma t0, t1, dword; |
3684 | ia64_insn insn; | |
800eeca4 JW |
3685 | enum ia64_opnd opnd; |
3686 | const char *err; | |
3687 | size_t size = 8; | |
1e738b87 NC |
3688 | #ifdef BFD_HOST_U_64_BIT |
3689 | BFD_HOST_U_64_BIT val = (BFD_HOST_U_64_BIT) v; | |
3690 | #else | |
3691 | bfd_vma val = v; | |
3692 | #endif | |
800eeca4 JW |
3693 | |
3694 | opnd = IA64_OPND_NIL; | |
3695 | switch (r_type) | |
3696 | { | |
3697 | case R_IA64_NONE: | |
3698 | case R_IA64_LDXMOV: | |
3699 | return bfd_reloc_ok; | |
3700 | ||
3e932841 | 3701 | /* Instruction relocations. */ |
800eeca4 | 3702 | |
13ae64f3 JJ |
3703 | case R_IA64_IMM14: |
3704 | case R_IA64_TPREL14: | |
3705 | case R_IA64_DTPREL14: | |
3706 | opnd = IA64_OPND_IMM14; | |
3707 | break; | |
748abff6 | 3708 | |
800eeca4 JW |
3709 | case R_IA64_PCREL21F: opnd = IA64_OPND_TGT25; break; |
3710 | case R_IA64_PCREL21M: opnd = IA64_OPND_TGT25b; break; | |
748abff6 RH |
3711 | case R_IA64_PCREL60B: opnd = IA64_OPND_TGT64; break; |
3712 | case R_IA64_PCREL21B: | |
3713 | case R_IA64_PCREL21BI: | |
3714 | opnd = IA64_OPND_TGT25c; | |
3715 | break; | |
800eeca4 JW |
3716 | |
3717 | case R_IA64_IMM22: | |
3718 | case R_IA64_GPREL22: | |
3719 | case R_IA64_LTOFF22: | |
3720 | case R_IA64_LTOFF22X: | |
3721 | case R_IA64_PLTOFF22: | |
748abff6 | 3722 | case R_IA64_PCREL22: |
800eeca4 | 3723 | case R_IA64_LTOFF_FPTR22: |
13ae64f3 JJ |
3724 | case R_IA64_TPREL22: |
3725 | case R_IA64_DTPREL22: | |
3726 | case R_IA64_LTOFF_TPREL22: | |
3727 | case R_IA64_LTOFF_DTPMOD22: | |
3728 | case R_IA64_LTOFF_DTPREL22: | |
800eeca4 JW |
3729 | opnd = IA64_OPND_IMM22; |
3730 | break; | |
3731 | ||
3732 | case R_IA64_IMM64: | |
3733 | case R_IA64_GPREL64I: | |
3734 | case R_IA64_LTOFF64I: | |
3735 | case R_IA64_PLTOFF64I: | |
748abff6 | 3736 | case R_IA64_PCREL64I: |
800eeca4 JW |
3737 | case R_IA64_FPTR64I: |
3738 | case R_IA64_LTOFF_FPTR64I: | |
13ae64f3 JJ |
3739 | case R_IA64_TPREL64I: |
3740 | case R_IA64_DTPREL64I: | |
800eeca4 JW |
3741 | opnd = IA64_OPND_IMMU64; |
3742 | break; | |
3743 | ||
3744 | /* Data relocations. */ | |
3745 | ||
3746 | case R_IA64_DIR32MSB: | |
3747 | case R_IA64_GPREL32MSB: | |
3748 | case R_IA64_FPTR32MSB: | |
3749 | case R_IA64_PCREL32MSB: | |
a4bd8390 | 3750 | case R_IA64_LTOFF_FPTR32MSB: |
800eeca4 JW |
3751 | case R_IA64_SEGREL32MSB: |
3752 | case R_IA64_SECREL32MSB: | |
3753 | case R_IA64_LTV32MSB: | |
13ae64f3 | 3754 | case R_IA64_DTPREL32MSB: |
800eeca4 JW |
3755 | size = 4; bigendian = 1; |
3756 | break; | |
3757 | ||
3758 | case R_IA64_DIR32LSB: | |
3759 | case R_IA64_GPREL32LSB: | |
3760 | case R_IA64_FPTR32LSB: | |
3761 | case R_IA64_PCREL32LSB: | |
a4bd8390 | 3762 | case R_IA64_LTOFF_FPTR32LSB: |
800eeca4 JW |
3763 | case R_IA64_SEGREL32LSB: |
3764 | case R_IA64_SECREL32LSB: | |
3765 | case R_IA64_LTV32LSB: | |
13ae64f3 | 3766 | case R_IA64_DTPREL32LSB: |
800eeca4 JW |
3767 | size = 4; bigendian = 0; |
3768 | break; | |
3769 | ||
3770 | case R_IA64_DIR64MSB: | |
3771 | case R_IA64_GPREL64MSB: | |
3772 | case R_IA64_PLTOFF64MSB: | |
3773 | case R_IA64_FPTR64MSB: | |
3774 | case R_IA64_PCREL64MSB: | |
3775 | case R_IA64_LTOFF_FPTR64MSB: | |
3776 | case R_IA64_SEGREL64MSB: | |
3777 | case R_IA64_SECREL64MSB: | |
3778 | case R_IA64_LTV64MSB: | |
13ae64f3 JJ |
3779 | case R_IA64_TPREL64MSB: |
3780 | case R_IA64_DTPMOD64MSB: | |
3781 | case R_IA64_DTPREL64MSB: | |
800eeca4 JW |
3782 | size = 8; bigendian = 1; |
3783 | break; | |
3784 | ||
3785 | case R_IA64_DIR64LSB: | |
3786 | case R_IA64_GPREL64LSB: | |
3787 | case R_IA64_PLTOFF64LSB: | |
3788 | case R_IA64_FPTR64LSB: | |
3789 | case R_IA64_PCREL64LSB: | |
3790 | case R_IA64_LTOFF_FPTR64LSB: | |
3791 | case R_IA64_SEGREL64LSB: | |
3792 | case R_IA64_SECREL64LSB: | |
3793 | case R_IA64_LTV64LSB: | |
13ae64f3 JJ |
3794 | case R_IA64_TPREL64LSB: |
3795 | case R_IA64_DTPMOD64LSB: | |
3796 | case R_IA64_DTPREL64LSB: | |
800eeca4 JW |
3797 | size = 8; bigendian = 0; |
3798 | break; | |
3799 | ||
3800 | /* Unsupported / Dynamic relocations. */ | |
800eeca4 JW |
3801 | default: |
3802 | return bfd_reloc_notsupported; | |
3803 | } | |
3804 | ||
3805 | switch (opnd) | |
3806 | { | |
3807 | case IA64_OPND_IMMU64: | |
3808 | hit_addr -= (long) hit_addr & 0x3; | |
bbb268c3 JW |
3809 | t0 = bfd_getl64 (hit_addr); |
3810 | t1 = bfd_getl64 (hit_addr + 8); | |
800eeca4 JW |
3811 | |
3812 | /* tmpl/s: bits 0.. 5 in t0 | |
3813 | slot 0: bits 5..45 in t0 | |
3814 | slot 1: bits 46..63 in t0, bits 0..22 in t1 | |
3815 | slot 2: bits 23..63 in t1 */ | |
3816 | ||
3817 | /* First, clear the bits that form the 64 bit constant. */ | |
3818 | t0 &= ~(0x3ffffLL << 46); | |
3819 | t1 &= ~(0x7fffffLL | |
3820 | | (( (0x07fLL << 13) | (0x1ffLL << 27) | |
3821 | | (0x01fLL << 22) | (0x001LL << 21) | |
3822 | | (0x001LL << 36)) << 23)); | |
3823 | ||
3824 | t0 |= ((val >> 22) & 0x03ffffLL) << 46; /* 18 lsbs of imm41 */ | |
3825 | t1 |= ((val >> 40) & 0x7fffffLL) << 0; /* 23 msbs of imm41 */ | |
3826 | t1 |= ( (((val >> 0) & 0x07f) << 13) /* imm7b */ | |
3827 | | (((val >> 7) & 0x1ff) << 27) /* imm9d */ | |
3828 | | (((val >> 16) & 0x01f) << 22) /* imm5c */ | |
3829 | | (((val >> 21) & 0x001) << 21) /* ic */ | |
3830 | | (((val >> 63) & 0x001) << 36)) << 23; /* i */ | |
3831 | ||
bbb268c3 JW |
3832 | bfd_putl64 (t0, hit_addr); |
3833 | bfd_putl64 (t1, hit_addr + 8); | |
800eeca4 JW |
3834 | break; |
3835 | ||
748abff6 RH |
3836 | case IA64_OPND_TGT64: |
3837 | hit_addr -= (long) hit_addr & 0x3; | |
bbb268c3 JW |
3838 | t0 = bfd_getl64 (hit_addr); |
3839 | t1 = bfd_getl64 (hit_addr + 8); | |
748abff6 RH |
3840 | |
3841 | /* tmpl/s: bits 0.. 5 in t0 | |
3842 | slot 0: bits 5..45 in t0 | |
3843 | slot 1: bits 46..63 in t0, bits 0..22 in t1 | |
3844 | slot 2: bits 23..63 in t1 */ | |
3845 | ||
3846 | /* First, clear the bits that form the 64 bit constant. */ | |
3847 | t0 &= ~(0x3ffffLL << 46); | |
3848 | t1 &= ~(0x7fffffLL | |
3849 | | ((1LL << 36 | 0xfffffLL << 13) << 23)); | |
3850 | ||
3851 | val >>= 4; | |
3852 | t0 |= ((val >> 20) & 0xffffLL) << 2 << 46; /* 16 lsbs of imm39 */ | |
3853 | t1 |= ((val >> 36) & 0x7fffffLL) << 0; /* 23 msbs of imm39 */ | |
3854 | t1 |= ((((val >> 0) & 0xfffffLL) << 13) /* imm20b */ | |
3855 | | (((val >> 59) & 0x1LL) << 36)) << 23; /* i */ | |
3856 | ||
bbb268c3 JW |
3857 | bfd_putl64 (t0, hit_addr); |
3858 | bfd_putl64 (t1, hit_addr + 8); | |
748abff6 RH |
3859 | break; |
3860 | ||
800eeca4 JW |
3861 | default: |
3862 | switch ((long) hit_addr & 0x3) | |
3863 | { | |
3864 | case 0: shift = 5; break; | |
3865 | case 1: shift = 14; hit_addr += 3; break; | |
3866 | case 2: shift = 23; hit_addr += 6; break; | |
3e932841 | 3867 | case 3: return bfd_reloc_notsupported; /* shouldn't happen... */ |
800eeca4 | 3868 | } |
bbb268c3 | 3869 | dword = bfd_getl64 (hit_addr); |
800eeca4 JW |
3870 | insn = (dword >> shift) & 0x1ffffffffffLL; |
3871 | ||
3872 | op = elf64_ia64_operands + opnd; | |
b4677f03 | 3873 | err = (*op->insert) (op, val, &insn); |
800eeca4 JW |
3874 | if (err) |
3875 | return bfd_reloc_overflow; | |
3876 | ||
3877 | dword &= ~(0x1ffffffffffLL << shift); | |
3878 | dword |= (insn << shift); | |
bbb268c3 | 3879 | bfd_putl64 (dword, hit_addr); |
800eeca4 JW |
3880 | break; |
3881 | ||
3882 | case IA64_OPND_NIL: | |
3883 | /* A data relocation. */ | |
3884 | if (bigendian) | |
3885 | if (size == 4) | |
3886 | bfd_putb32 (val, hit_addr); | |
3887 | else | |
3888 | bfd_putb64 (val, hit_addr); | |
3889 | else | |
3890 | if (size == 4) | |
3891 | bfd_putl32 (val, hit_addr); | |
3892 | else | |
3893 | bfd_putl64 (val, hit_addr); | |
3894 | break; | |
3895 | } | |
3896 | ||
3897 | return bfd_reloc_ok; | |
3898 | } | |
3899 | ||
3900 | static void | |
eae50df2 L |
3901 | elfNN_ia64_install_dyn_reloc (bfd *abfd, struct bfd_link_info *info, |
3902 | asection *sec, asection *srel, | |
3903 | bfd_vma offset, unsigned int type, | |
3904 | long dynindx, bfd_vma addend) | |
800eeca4 JW |
3905 | { |
3906 | Elf_Internal_Rela outrel; | |
947216bf | 3907 | bfd_byte *loc; |
800eeca4 | 3908 | |
800eeca4 | 3909 | BFD_ASSERT (dynindx != -1); |
bbe66d08 | 3910 | outrel.r_info = ELFNN_R_INFO (dynindx, type); |
800eeca4 | 3911 | outrel.r_addend = addend; |
c629eae0 | 3912 | outrel.r_offset = _bfd_elf_section_offset (abfd, info, sec, offset); |
99eb2ac8 | 3913 | if (outrel.r_offset >= (bfd_vma) -2) |
800eeca4 | 3914 | { |
c629eae0 JJ |
3915 | /* Run for the hills. We shouldn't be outputting a relocation |
3916 | for this. So do what everyone else does and output a no-op. */ | |
3917 | outrel.r_info = ELFNN_R_INFO (0, R_IA64_NONE); | |
3918 | outrel.r_addend = 0; | |
3919 | outrel.r_offset = 0; | |
800eeca4 | 3920 | } |
99eb2ac8 AM |
3921 | else |
3922 | outrel.r_offset += sec->output_section->vma + sec->output_offset; | |
800eeca4 | 3923 | |
947216bf AM |
3924 | loc = srel->contents; |
3925 | loc += srel->reloc_count++ * sizeof (ElfNN_External_Rela); | |
3926 | bfd_elfNN_swap_reloca_out (abfd, &outrel, loc); | |
eea6121a | 3927 | BFD_ASSERT (sizeof (ElfNN_External_Rela) * srel->reloc_count <= srel->size); |
800eeca4 JW |
3928 | } |
3929 | ||
3930 | /* Store an entry for target address TARGET_ADDR in the linkage table | |
3931 | and return the gp-relative address of the linkage table entry. */ | |
3932 | ||
3933 | static bfd_vma | |
eae50df2 L |
3934 | set_got_entry (bfd *abfd, struct bfd_link_info *info, |
3935 | struct elfNN_ia64_dyn_sym_info *dyn_i, | |
3936 | long dynindx, bfd_vma addend, bfd_vma value, | |
3937 | unsigned int dyn_r_type) | |
800eeca4 | 3938 | { |
bbe66d08 | 3939 | struct elfNN_ia64_link_hash_table *ia64_info; |
800eeca4 | 3940 | asection *got_sec; |
b34976b6 | 3941 | bfd_boolean done; |
13ae64f3 | 3942 | bfd_vma got_offset; |
800eeca4 | 3943 | |
bbe66d08 | 3944 | ia64_info = elfNN_ia64_hash_table (info); |
cc3bd654 | 3945 | got_sec = ia64_info->root.sgot; |
800eeca4 | 3946 | |
13ae64f3 | 3947 | switch (dyn_r_type) |
800eeca4 | 3948 | { |
13ae64f3 JJ |
3949 | case R_IA64_TPREL64LSB: |
3950 | done = dyn_i->tprel_done; | |
b34976b6 | 3951 | dyn_i->tprel_done = TRUE; |
13ae64f3 JJ |
3952 | got_offset = dyn_i->tprel_offset; |
3953 | break; | |
3954 | case R_IA64_DTPMOD64LSB: | |
b3dfd7fe JJ |
3955 | if (dyn_i->dtpmod_offset != ia64_info->self_dtpmod_offset) |
3956 | { | |
3957 | done = dyn_i->dtpmod_done; | |
3958 | dyn_i->dtpmod_done = TRUE; | |
3959 | } | |
3960 | else | |
3961 | { | |
3962 | done = ia64_info->self_dtpmod_done; | |
3963 | ia64_info->self_dtpmod_done = TRUE; | |
3964 | dynindx = 0; | |
3965 | } | |
13ae64f3 JJ |
3966 | got_offset = dyn_i->dtpmod_offset; |
3967 | break; | |
5a260b66 | 3968 | case R_IA64_DTPREL32LSB: |
13ae64f3 JJ |
3969 | case R_IA64_DTPREL64LSB: |
3970 | done = dyn_i->dtprel_done; | |
b34976b6 | 3971 | dyn_i->dtprel_done = TRUE; |
13ae64f3 JJ |
3972 | got_offset = dyn_i->dtprel_offset; |
3973 | break; | |
3974 | default: | |
3975 | done = dyn_i->got_done; | |
b34976b6 | 3976 | dyn_i->got_done = TRUE; |
13ae64f3 JJ |
3977 | got_offset = dyn_i->got_offset; |
3978 | break; | |
3979 | } | |
800eeca4 | 3980 | |
13ae64f3 JJ |
3981 | BFD_ASSERT ((got_offset & 7) == 0); |
3982 | ||
3983 | if (! done) | |
3984 | { | |
800eeca4 | 3985 | /* Store the target address in the linkage table entry. */ |
13ae64f3 | 3986 | bfd_put_64 (abfd, value, got_sec->contents + got_offset); |
800eeca4 JW |
3987 | |
3988 | /* Install a dynamic relocation if needed. */ | |
9203ba99 JJ |
3989 | if (((info->shared |
3990 | && (!dyn_i->h | |
3991 | || ELF_ST_VISIBILITY (dyn_i->h->other) == STV_DEFAULT | |
3992 | || dyn_i->h->root.type != bfd_link_hash_undefweak) | |
5a260b66 | 3993 | && dyn_r_type != R_IA64_DTPREL32LSB |
9203ba99 | 3994 | && dyn_r_type != R_IA64_DTPREL64LSB) |
986a241f | 3995 | || elfNN_ia64_dynamic_symbol_p (dyn_i->h, info, dyn_r_type) |
5a260b66 L |
3996 | || (dynindx != -1 |
3997 | && (dyn_r_type == R_IA64_FPTR32LSB | |
3998 | || dyn_r_type == R_IA64_FPTR64LSB))) | |
9203ba99 JJ |
3999 | && (!dyn_i->want_ltoff_fptr |
4000 | || !info->pie | |
4001 | || !dyn_i->h | |
4002 | || dyn_i->h->root.type != bfd_link_hash_undefweak)) | |
800eeca4 | 4003 | { |
13ae64f3 JJ |
4004 | if (dynindx == -1 |
4005 | && dyn_r_type != R_IA64_TPREL64LSB | |
4006 | && dyn_r_type != R_IA64_DTPMOD64LSB | |
5a260b66 | 4007 | && dyn_r_type != R_IA64_DTPREL32LSB |
13ae64f3 | 4008 | && dyn_r_type != R_IA64_DTPREL64LSB) |
800eeca4 | 4009 | { |
5a260b66 | 4010 | dyn_r_type = R_IA64_RELNNLSB; |
800eeca4 JW |
4011 | dynindx = 0; |
4012 | addend = value; | |
4013 | } | |
4014 | ||
4015 | if (bfd_big_endian (abfd)) | |
4016 | { | |
4017 | switch (dyn_r_type) | |
4018 | { | |
5a260b66 L |
4019 | case R_IA64_REL32LSB: |
4020 | dyn_r_type = R_IA64_REL32MSB; | |
4021 | break; | |
4022 | case R_IA64_DIR32LSB: | |
4023 | dyn_r_type = R_IA64_DIR32MSB; | |
4024 | break; | |
4025 | case R_IA64_FPTR32LSB: | |
4026 | dyn_r_type = R_IA64_FPTR32MSB; | |
4027 | break; | |
4028 | case R_IA64_DTPREL32LSB: | |
4029 | dyn_r_type = R_IA64_DTPREL32MSB; | |
4030 | break; | |
800eeca4 JW |
4031 | case R_IA64_REL64LSB: |
4032 | dyn_r_type = R_IA64_REL64MSB; | |
4033 | break; | |
4034 | case R_IA64_DIR64LSB: | |
4035 | dyn_r_type = R_IA64_DIR64MSB; | |
4036 | break; | |
4037 | case R_IA64_FPTR64LSB: | |
4038 | dyn_r_type = R_IA64_FPTR64MSB; | |
4039 | break; | |
13ae64f3 JJ |
4040 | case R_IA64_TPREL64LSB: |
4041 | dyn_r_type = R_IA64_TPREL64MSB; | |
4042 | break; | |
4043 | case R_IA64_DTPMOD64LSB: | |
4044 | dyn_r_type = R_IA64_DTPMOD64MSB; | |
4045 | break; | |
4046 | case R_IA64_DTPREL64LSB: | |
4047 | dyn_r_type = R_IA64_DTPREL64MSB; | |
4048 | break; | |
800eeca4 | 4049 | default: |
b34976b6 | 4050 | BFD_ASSERT (FALSE); |
800eeca4 JW |
4051 | break; |
4052 | } | |
4053 | } | |
4054 | ||
bbe66d08 | 4055 | elfNN_ia64_install_dyn_reloc (abfd, NULL, got_sec, |
cc3bd654 | 4056 | ia64_info->root.srelgot, |
13ae64f3 | 4057 | got_offset, dyn_r_type, |
800eeca4 JW |
4058 | dynindx, addend); |
4059 | } | |
4060 | } | |
4061 | ||
4062 | /* Return the address of the linkage table entry. */ | |
4063 | value = (got_sec->output_section->vma | |
4064 | + got_sec->output_offset | |
13ae64f3 | 4065 | + got_offset); |
800eeca4 JW |
4066 | |
4067 | return value; | |
4068 | } | |
4069 | ||
4070 | /* Fill in a function descriptor consisting of the function's code | |
4071 | address and its global pointer. Return the descriptor's address. */ | |
4072 | ||
4073 | static bfd_vma | |
eae50df2 L |
4074 | set_fptr_entry (bfd *abfd, struct bfd_link_info *info, |
4075 | struct elfNN_ia64_dyn_sym_info *dyn_i, | |
4076 | bfd_vma value) | |
800eeca4 | 4077 | { |
bbe66d08 | 4078 | struct elfNN_ia64_link_hash_table *ia64_info; |
800eeca4 JW |
4079 | asection *fptr_sec; |
4080 | ||
bbe66d08 | 4081 | ia64_info = elfNN_ia64_hash_table (info); |
800eeca4 JW |
4082 | fptr_sec = ia64_info->fptr_sec; |
4083 | ||
4084 | if (!dyn_i->fptr_done) | |
4085 | { | |
4086 | dyn_i->fptr_done = 1; | |
4087 | ||
4088 | /* Fill in the function descriptor. */ | |
4089 | bfd_put_64 (abfd, value, fptr_sec->contents + dyn_i->fptr_offset); | |
4090 | bfd_put_64 (abfd, _bfd_get_gp_value (abfd), | |
4091 | fptr_sec->contents + dyn_i->fptr_offset + 8); | |
9203ba99 JJ |
4092 | if (ia64_info->rel_fptr_sec) |
4093 | { | |
4094 | Elf_Internal_Rela outrel; | |
4095 | bfd_byte *loc; | |
4096 | ||
4097 | if (bfd_little_endian (abfd)) | |
4098 | outrel.r_info = ELFNN_R_INFO (0, R_IA64_IPLTLSB); | |
4099 | else | |
4100 | outrel.r_info = ELFNN_R_INFO (0, R_IA64_IPLTMSB); | |
4101 | outrel.r_addend = value; | |
4102 | outrel.r_offset = (fptr_sec->output_section->vma | |
4103 | + fptr_sec->output_offset | |
4104 | + dyn_i->fptr_offset); | |
4105 | loc = ia64_info->rel_fptr_sec->contents; | |
4106 | loc += ia64_info->rel_fptr_sec->reloc_count++ | |
4107 | * sizeof (ElfNN_External_Rela); | |
4108 | bfd_elfNN_swap_reloca_out (abfd, &outrel, loc); | |
4109 | } | |
800eeca4 JW |
4110 | } |
4111 | ||
4112 | /* Return the descriptor's address. */ | |
4113 | value = (fptr_sec->output_section->vma | |
4114 | + fptr_sec->output_offset | |
4115 | + dyn_i->fptr_offset); | |
4116 | ||
4117 | return value; | |
4118 | } | |
4119 | ||
4120 | /* Fill in a PLTOFF entry consisting of the function's code address | |
4121 | and its global pointer. Return the descriptor's address. */ | |
4122 | ||
4123 | static bfd_vma | |
eae50df2 L |
4124 | set_pltoff_entry (bfd *abfd, struct bfd_link_info *info, |
4125 | struct elfNN_ia64_dyn_sym_info *dyn_i, | |
4126 | bfd_vma value, bfd_boolean is_plt) | |
800eeca4 | 4127 | { |
bbe66d08 | 4128 | struct elfNN_ia64_link_hash_table *ia64_info; |
800eeca4 JW |
4129 | asection *pltoff_sec; |
4130 | ||
bbe66d08 | 4131 | ia64_info = elfNN_ia64_hash_table (info); |
800eeca4 JW |
4132 | pltoff_sec = ia64_info->pltoff_sec; |
4133 | ||
4134 | /* Don't do anything if this symbol uses a real PLT entry. In | |
4135 | that case, we'll fill this in during finish_dynamic_symbol. */ | |
4136 | if ((! dyn_i->want_plt || is_plt) | |
4137 | && !dyn_i->pltoff_done) | |
4138 | { | |
18b27f17 RH |
4139 | bfd_vma gp = _bfd_get_gp_value (abfd); |
4140 | ||
800eeca4 JW |
4141 | /* Fill in the function descriptor. */ |
4142 | bfd_put_64 (abfd, value, pltoff_sec->contents + dyn_i->pltoff_offset); | |
18b27f17 | 4143 | bfd_put_64 (abfd, gp, pltoff_sec->contents + dyn_i->pltoff_offset + 8); |
800eeca4 JW |
4144 | |
4145 | /* Install dynamic relocations if needed. */ | |
ef5aade5 L |
4146 | if (!is_plt |
4147 | && info->shared | |
4148 | && (!dyn_i->h | |
4149 | || ELF_ST_VISIBILITY (dyn_i->h->other) == STV_DEFAULT | |
4150 | || dyn_i->h->root.type != bfd_link_hash_undefweak)) | |
800eeca4 JW |
4151 | { |
4152 | unsigned int dyn_r_type; | |
4153 | ||
4154 | if (bfd_big_endian (abfd)) | |
5a260b66 | 4155 | dyn_r_type = R_IA64_RELNNMSB; |
800eeca4 | 4156 | else |
5a260b66 | 4157 | dyn_r_type = R_IA64_RELNNLSB; |
800eeca4 | 4158 | |
bbe66d08 | 4159 | elfNN_ia64_install_dyn_reloc (abfd, NULL, pltoff_sec, |
800eeca4 JW |
4160 | ia64_info->rel_pltoff_sec, |
4161 | dyn_i->pltoff_offset, | |
18b27f17 | 4162 | dyn_r_type, 0, value); |
bbe66d08 | 4163 | elfNN_ia64_install_dyn_reloc (abfd, NULL, pltoff_sec, |
800eeca4 | 4164 | ia64_info->rel_pltoff_sec, |
5a260b66 | 4165 | dyn_i->pltoff_offset + ARCH_SIZE / 8, |
18b27f17 | 4166 | dyn_r_type, 0, gp); |
800eeca4 JW |
4167 | } |
4168 | ||
4169 | dyn_i->pltoff_done = 1; | |
4170 | } | |
4171 | ||
4172 | /* Return the descriptor's address. */ | |
4173 | value = (pltoff_sec->output_section->vma | |
4174 | + pltoff_sec->output_offset | |
4175 | + dyn_i->pltoff_offset); | |
4176 | ||
4177 | return value; | |
4178 | } | |
4179 | ||
13ae64f3 JJ |
4180 | /* Return the base VMA address which should be subtracted from real addresses |
4181 | when resolving @tprel() relocation. | |
4182 | Main program TLS (whose template starts at PT_TLS p_vaddr) | |
5a260b66 | 4183 | is assigned offset round(2 * size of pointer, PT_TLS p_align). */ |
13ae64f3 JJ |
4184 | |
4185 | static bfd_vma | |
eae50df2 | 4186 | elfNN_ia64_tprel_base (struct bfd_link_info *info) |
13ae64f3 | 4187 | { |
e1918d23 | 4188 | asection *tls_sec = elf_hash_table (info)->tls_sec; |
5a260b66 L |
4189 | return tls_sec->vma - align_power ((bfd_vma) ARCH_SIZE / 4, |
4190 | tls_sec->alignment_power); | |
13ae64f3 JJ |
4191 | } |
4192 | ||
4193 | /* Return the base VMA address which should be subtracted from real addresses | |
4194 | when resolving @dtprel() relocation. | |
4195 | This is PT_TLS segment p_vaddr. */ | |
4196 | ||
4197 | static bfd_vma | |
eae50df2 | 4198 | elfNN_ia64_dtprel_base (struct bfd_link_info *info) |
13ae64f3 | 4199 | { |
e1918d23 | 4200 | return elf_hash_table (info)->tls_sec->vma; |
13ae64f3 JJ |
4201 | } |
4202 | ||
f3b6f7c3 | 4203 | /* Called through qsort to sort the .IA_64.unwind section during a |
bbe66d08 | 4204 | non-relocatable link. Set elfNN_ia64_unwind_entry_compare_bfd |
f3b6f7c3 RH |
4205 | to the output bfd so we can do proper endianness frobbing. */ |
4206 | ||
bbe66d08 | 4207 | static bfd *elfNN_ia64_unwind_entry_compare_bfd; |
f3b6f7c3 RH |
4208 | |
4209 | static int | |
eae50df2 | 4210 | elfNN_ia64_unwind_entry_compare (const PTR a, const PTR b) |
f3b6f7c3 RH |
4211 | { |
4212 | bfd_vma av, bv; | |
4213 | ||
bbe66d08 JW |
4214 | av = bfd_get_64 (elfNN_ia64_unwind_entry_compare_bfd, a); |
4215 | bv = bfd_get_64 (elfNN_ia64_unwind_entry_compare_bfd, b); | |
f3b6f7c3 RH |
4216 | |
4217 | return (av < bv ? -1 : av > bv ? 1 : 0); | |
4218 | } | |
4219 | ||
2c4c2bc0 | 4220 | /* Make sure we've got ourselves a nice fat __gp value. */ |
b34976b6 | 4221 | static bfd_boolean |
eae50df2 | 4222 | elfNN_ia64_choose_gp (bfd *abfd, struct bfd_link_info *info) |
800eeca4 | 4223 | { |
2c4c2bc0 RH |
4224 | bfd_vma min_vma = (bfd_vma) -1, max_vma = 0; |
4225 | bfd_vma min_short_vma = min_vma, max_short_vma = 0; | |
4226 | struct elf_link_hash_entry *gp; | |
4227 | bfd_vma gp_val; | |
4228 | asection *os; | |
bbe66d08 | 4229 | struct elfNN_ia64_link_hash_table *ia64_info; |
9a951beb | 4230 | |
bbe66d08 | 4231 | ia64_info = elfNN_ia64_hash_table (info); |
800eeca4 | 4232 | |
2c4c2bc0 RH |
4233 | /* Find the min and max vma of all sections marked short. Also collect |
4234 | min and max vma of any type, for use in selecting a nice gp. */ | |
4235 | for (os = abfd->sections; os ; os = os->next) | |
800eeca4 | 4236 | { |
2c4c2bc0 | 4237 | bfd_vma lo, hi; |
800eeca4 | 4238 | |
2c4c2bc0 RH |
4239 | if ((os->flags & SEC_ALLOC) == 0) |
4240 | continue; | |
4241 | ||
4242 | lo = os->vma; | |
f72c3e6b | 4243 | hi = os->vma + (os->rawsize ? os->rawsize : os->size); |
2c4c2bc0 RH |
4244 | if (hi < lo) |
4245 | hi = (bfd_vma) -1; | |
4246 | ||
4247 | if (min_vma > lo) | |
4248 | min_vma = lo; | |
4249 | if (max_vma < hi) | |
4250 | max_vma = hi; | |
4251 | if (os->flags & SEC_SMALL_DATA) | |
800eeca4 | 4252 | { |
2c4c2bc0 RH |
4253 | if (min_short_vma > lo) |
4254 | min_short_vma = lo; | |
4255 | if (max_short_vma < hi) | |
4256 | max_short_vma = hi; | |
4257 | } | |
4258 | } | |
800eeca4 | 4259 | |
2c4c2bc0 RH |
4260 | /* See if the user wants to force a value. */ |
4261 | gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", FALSE, | |
4262 | FALSE, FALSE); | |
800eeca4 | 4263 | |
2c4c2bc0 RH |
4264 | if (gp |
4265 | && (gp->root.type == bfd_link_hash_defined | |
4266 | || gp->root.type == bfd_link_hash_defweak)) | |
4267 | { | |
4268 | asection *gp_sec = gp->root.u.def.section; | |
4269 | gp_val = (gp->root.u.def.value | |
4270 | + gp_sec->output_section->vma | |
4271 | + gp_sec->output_offset); | |
4272 | } | |
4273 | else | |
4274 | { | |
4275 | /* Pick a sensible value. */ | |
800eeca4 | 4276 | |
cc3bd654 | 4277 | asection *got_sec = ia64_info->root.sgot; |
2c4c2bc0 RH |
4278 | |
4279 | /* Start with just the address of the .got. */ | |
4280 | if (got_sec) | |
4281 | gp_val = got_sec->output_section->vma; | |
4282 | else if (max_short_vma != 0) | |
4283 | gp_val = min_short_vma; | |
6d2cf7d8 | 4284 | else if (max_vma - min_vma < 0x200000) |
2c4c2bc0 | 4285 | gp_val = min_vma; |
6d2cf7d8 L |
4286 | else |
4287 | gp_val = max_vma - 0x200000 + 8; | |
2c4c2bc0 RH |
4288 | |
4289 | /* If it is possible to address the entire image, but we | |
4290 | don't with the choice above, adjust. */ | |
4291 | if (max_vma - min_vma < 0x400000 | |
6d2cf7d8 L |
4292 | && (max_vma - gp_val >= 0x200000 |
4293 | || gp_val - min_vma > 0x200000)) | |
2c4c2bc0 RH |
4294 | gp_val = min_vma + 0x200000; |
4295 | else if (max_short_vma != 0) | |
4296 | { | |
4297 | /* If we don't cover all the short data, adjust. */ | |
4298 | if (max_short_vma - gp_val >= 0x200000) | |
4299 | gp_val = min_short_vma + 0x200000; | |
4300 | ||
4301 | /* If we're addressing stuff past the end, adjust back. */ | |
4302 | if (gp_val > max_vma) | |
4303 | gp_val = max_vma - 0x200000 + 8; | |
800eeca4 | 4304 | } |
2c4c2bc0 | 4305 | } |
800eeca4 | 4306 | |
2c4c2bc0 RH |
4307 | /* Validate whether all SHF_IA_64_SHORT sections are within |
4308 | range of the chosen GP. */ | |
800eeca4 | 4309 | |
2c4c2bc0 RH |
4310 | if (max_short_vma != 0) |
4311 | { | |
4312 | if (max_short_vma - min_short_vma >= 0x400000) | |
800eeca4 | 4313 | { |
2c4c2bc0 RH |
4314 | (*_bfd_error_handler) |
4315 | (_("%s: short data segment overflowed (0x%lx >= 0x400000)"), | |
4316 | bfd_get_filename (abfd), | |
4317 | (unsigned long) (max_short_vma - min_short_vma)); | |
4318 | return FALSE; | |
800eeca4 | 4319 | } |
2c4c2bc0 RH |
4320 | else if ((gp_val > min_short_vma |
4321 | && gp_val - min_short_vma > 0x200000) | |
4322 | || (gp_val < max_short_vma | |
4323 | && max_short_vma - gp_val >= 0x200000)) | |
800eeca4 | 4324 | { |
2c4c2bc0 RH |
4325 | (*_bfd_error_handler) |
4326 | (_("%s: __gp does not cover short data segment"), | |
4327 | bfd_get_filename (abfd)); | |
4328 | return FALSE; | |
4329 | } | |
4330 | } | |
800eeca4 | 4331 | |
2c4c2bc0 | 4332 | _bfd_set_gp_value (abfd, gp_val); |
800eeca4 | 4333 | |
2c4c2bc0 RH |
4334 | return TRUE; |
4335 | } | |
800eeca4 | 4336 | |
2c4c2bc0 | 4337 | static bfd_boolean |
eae50df2 | 4338 | elfNN_ia64_final_link (bfd *abfd, struct bfd_link_info *info) |
2c4c2bc0 RH |
4339 | { |
4340 | struct elfNN_ia64_link_hash_table *ia64_info; | |
4341 | asection *unwind_output_sec; | |
800eeca4 | 4342 | |
2c4c2bc0 | 4343 | ia64_info = elfNN_ia64_hash_table (info); |
800eeca4 | 4344 | |
2c4c2bc0 | 4345 | /* Make sure we've got ourselves a nice fat __gp value. */ |
1049f94e | 4346 | if (!info->relocatable) |
2c4c2bc0 | 4347 | { |
a38a2e96 | 4348 | bfd_vma gp_val; |
2c4c2bc0 RH |
4349 | struct elf_link_hash_entry *gp; |
4350 | ||
a38a2e96 L |
4351 | /* We assume after gp is set, section size will only decrease. We |
4352 | need to adjust gp for it. */ | |
4353 | _bfd_set_gp_value (abfd, 0); | |
4354 | if (! elfNN_ia64_choose_gp (abfd, info)) | |
4355 | return FALSE; | |
4356 | gp_val = _bfd_get_gp_value (abfd); | |
800eeca4 | 4357 | |
2c4c2bc0 RH |
4358 | gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", FALSE, |
4359 | FALSE, FALSE); | |
b4adccfd RH |
4360 | if (gp) |
4361 | { | |
4362 | gp->root.type = bfd_link_hash_defined; | |
4363 | gp->root.u.def.value = gp_val; | |
4364 | gp->root.u.def.section = bfd_abs_section_ptr; | |
4365 | } | |
800eeca4 JW |
4366 | } |
4367 | ||
f3b6f7c3 | 4368 | /* If we're producing a final executable, we need to sort the contents |
9a951beb RH |
4369 | of the .IA_64.unwind section. Force this section to be relocated |
4370 | into memory rather than written immediately to the output file. */ | |
4371 | unwind_output_sec = NULL; | |
1049f94e | 4372 | if (!info->relocatable) |
f3b6f7c3 RH |
4373 | { |
4374 | asection *s = bfd_get_section_by_name (abfd, ELF_STRING_ia64_unwind); | |
4375 | if (s) | |
4376 | { | |
9a951beb RH |
4377 | unwind_output_sec = s->output_section; |
4378 | unwind_output_sec->contents | |
eea6121a | 4379 | = bfd_malloc (unwind_output_sec->size); |
9a951beb | 4380 | if (unwind_output_sec->contents == NULL) |
b34976b6 | 4381 | return FALSE; |
9a951beb RH |
4382 | } |
4383 | } | |
f3b6f7c3 | 4384 | |
9a951beb | 4385 | /* Invoke the regular ELF backend linker to do all the work. */ |
c152c796 | 4386 | if (!bfd_elf_final_link (abfd, info)) |
b34976b6 | 4387 | return FALSE; |
f3b6f7c3 | 4388 | |
9a951beb RH |
4389 | if (unwind_output_sec) |
4390 | { | |
4391 | elfNN_ia64_unwind_entry_compare_bfd = abfd; | |
dc810e39 | 4392 | qsort (unwind_output_sec->contents, |
eea6121a | 4393 | (size_t) (unwind_output_sec->size / 24), |
dc810e39 AM |
4394 | 24, |
4395 | elfNN_ia64_unwind_entry_compare); | |
9a951beb RH |
4396 | |
4397 | if (! bfd_set_section_contents (abfd, unwind_output_sec, | |
dc810e39 | 4398 | unwind_output_sec->contents, (bfd_vma) 0, |
eea6121a | 4399 | unwind_output_sec->size)) |
b34976b6 | 4400 | return FALSE; |
f3b6f7c3 RH |
4401 | } |
4402 | ||
b34976b6 | 4403 | return TRUE; |
800eeca4 JW |
4404 | } |
4405 | ||
b34976b6 | 4406 | static bfd_boolean |
eae50df2 L |
4407 | elfNN_ia64_relocate_section (bfd *output_bfd, |
4408 | struct bfd_link_info *info, | |
4409 | bfd *input_bfd, | |
4410 | asection *input_section, | |
4411 | bfd_byte *contents, | |
4412 | Elf_Internal_Rela *relocs, | |
4413 | Elf_Internal_Sym *local_syms, | |
4414 | asection **local_sections) | |
800eeca4 | 4415 | { |
bbe66d08 | 4416 | struct elfNN_ia64_link_hash_table *ia64_info; |
800eeca4 JW |
4417 | Elf_Internal_Shdr *symtab_hdr; |
4418 | Elf_Internal_Rela *rel; | |
4419 | Elf_Internal_Rela *relend; | |
4420 | asection *srel; | |
b34976b6 | 4421 | bfd_boolean ret_val = TRUE; /* for non-fatal errors */ |
800eeca4 JW |
4422 | bfd_vma gp_val; |
4423 | ||
4424 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; | |
bbe66d08 | 4425 | ia64_info = elfNN_ia64_hash_table (info); |
800eeca4 JW |
4426 | |
4427 | /* Infect various flags from the input section to the output section. */ | |
1049f94e | 4428 | if (info->relocatable) |
800eeca4 JW |
4429 | { |
4430 | bfd_vma flags; | |
4431 | ||
4432 | flags = elf_section_data(input_section)->this_hdr.sh_flags; | |
4433 | flags &= SHF_IA_64_NORECOV; | |
4434 | ||
4435 | elf_section_data(input_section->output_section) | |
4436 | ->this_hdr.sh_flags |= flags; | |
4437 | } | |
4438 | ||
4439 | gp_val = _bfd_get_gp_value (output_bfd); | |
b34976b6 | 4440 | srel = get_reloc_section (input_bfd, ia64_info, input_section, FALSE); |
800eeca4 JW |
4441 | |
4442 | rel = relocs; | |
4443 | relend = relocs + input_section->reloc_count; | |
4444 | for (; rel < relend; ++rel) | |
4445 | { | |
4446 | struct elf_link_hash_entry *h; | |
bbe66d08 | 4447 | struct elfNN_ia64_dyn_sym_info *dyn_i; |
800eeca4 JW |
4448 | bfd_reloc_status_type r; |
4449 | reloc_howto_type *howto; | |
4450 | unsigned long r_symndx; | |
4451 | Elf_Internal_Sym *sym; | |
4452 | unsigned int r_type; | |
4453 | bfd_vma value; | |
4454 | asection *sym_sec; | |
4455 | bfd_byte *hit_addr; | |
b34976b6 AM |
4456 | bfd_boolean dynamic_symbol_p; |
4457 | bfd_boolean undef_weak_ref; | |
800eeca4 | 4458 | |
bbe66d08 | 4459 | r_type = ELFNN_R_TYPE (rel->r_info); |
800eeca4 JW |
4460 | if (r_type > R_IA64_MAX_RELOC_CODE) |
4461 | { | |
4462 | (*_bfd_error_handler) | |
d003868e AM |
4463 | (_("%B: unknown relocation type %d"), |
4464 | input_bfd, (int) r_type); | |
800eeca4 | 4465 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 4466 | ret_val = FALSE; |
800eeca4 JW |
4467 | continue; |
4468 | } | |
b491616a | 4469 | |
800eeca4 | 4470 | howto = lookup_howto (r_type); |
bbe66d08 | 4471 | r_symndx = ELFNN_R_SYM (rel->r_info); |
800eeca4 JW |
4472 | h = NULL; |
4473 | sym = NULL; | |
4474 | sym_sec = NULL; | |
b34976b6 | 4475 | undef_weak_ref = FALSE; |
800eeca4 JW |
4476 | |
4477 | if (r_symndx < symtab_hdr->sh_info) | |
4478 | { | |
4479 | /* Reloc against local symbol. */ | |
8517fae7 | 4480 | asection *msec; |
800eeca4 JW |
4481 | sym = local_syms + r_symndx; |
4482 | sym_sec = local_sections[r_symndx]; | |
8517fae7 AM |
4483 | msec = sym_sec; |
4484 | value = _bfd_elf_rela_local_sym (output_bfd, sym, &msec, rel); | |
ab96bf03 AM |
4485 | if (!info->relocatable |
4486 | && (sym_sec->flags & SEC_MERGE) != 0 | |
f7460f5f | 4487 | && ELF_ST_TYPE (sym->st_info) == STT_SECTION |
68bfbfcc | 4488 | && sym_sec->sec_info_type == ELF_INFO_TYPE_MERGE) |
f7460f5f JJ |
4489 | { |
4490 | struct elfNN_ia64_local_hash_entry *loc_h; | |
b34976b6 AM |
4491 | |
4492 | loc_h = get_local_sym_hash (ia64_info, input_bfd, rel, FALSE); | |
f7460f5f JJ |
4493 | if (loc_h && ! loc_h->sec_merge_done) |
4494 | { | |
4495 | struct elfNN_ia64_dyn_sym_info *dynent; | |
396a682d | 4496 | unsigned int count; |
f7460f5f | 4497 | |
396a682d L |
4498 | for (count = loc_h->count, dynent = loc_h->info; |
4499 | count != 0; | |
4500 | count--, dynent++) | |
f7460f5f JJ |
4501 | { |
4502 | msec = sym_sec; | |
4503 | dynent->addend = | |
4504 | _bfd_merged_section_offset (output_bfd, &msec, | |
4505 | elf_section_data (msec)-> | |
65765700 | 4506 | sec_info, |
f7460f5f | 4507 | sym->st_value |
753731ee | 4508 | + dynent->addend); |
f7460f5f JJ |
4509 | dynent->addend -= sym->st_value; |
4510 | dynent->addend += msec->output_section->vma | |
4511 | + msec->output_offset | |
4512 | - sym_sec->output_section->vma | |
4513 | - sym_sec->output_offset; | |
4514 | } | |
293a0124 L |
4515 | |
4516 | /* We may have introduced duplicated entries. We need | |
4517 | to remove them properly. */ | |
4518 | count = sort_dyn_sym_info (loc_h->info, loc_h->count); | |
4519 | if (count != loc_h->count) | |
4520 | { | |
4521 | loc_h->count = count; | |
4522 | loc_h->sorted_count = count; | |
4523 | } | |
396a682d | 4524 | |
f7460f5f JJ |
4525 | loc_h->sec_merge_done = 1; |
4526 | } | |
4527 | } | |
800eeca4 JW |
4528 | } |
4529 | else | |
4530 | { | |
560e09e9 NC |
4531 | bfd_boolean unresolved_reloc; |
4532 | bfd_boolean warned; | |
b2a8e766 | 4533 | struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd); |
800eeca4 | 4534 | |
b2a8e766 AM |
4535 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
4536 | r_symndx, symtab_hdr, sym_hashes, | |
4537 | h, sym_sec, value, | |
4538 | unresolved_reloc, warned); | |
800eeca4 | 4539 | |
560e09e9 | 4540 | if (h->root.type == bfd_link_hash_undefweak) |
b34976b6 | 4541 | undef_weak_ref = TRUE; |
560e09e9 NC |
4542 | else if (warned) |
4543 | continue; | |
800eeca4 JW |
4544 | } |
4545 | ||
ab96bf03 AM |
4546 | /* For relocs against symbols from removed linkonce sections, |
4547 | or sections discarded by a linker script, we just want the | |
4548 | section contents zeroed. Avoid any special processing. */ | |
4549 | if (sym_sec != NULL && elf_discarded_section (sym_sec)) | |
4550 | { | |
4551 | _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); | |
4552 | rel->r_info = 0; | |
4553 | rel->r_addend = 0; | |
4554 | continue; | |
4555 | } | |
4556 | ||
4557 | if (info->relocatable) | |
4558 | continue; | |
4559 | ||
800eeca4 JW |
4560 | hit_addr = contents + rel->r_offset; |
4561 | value += rel->r_addend; | |
986a241f | 4562 | dynamic_symbol_p = elfNN_ia64_dynamic_symbol_p (h, info, r_type); |
800eeca4 JW |
4563 | |
4564 | switch (r_type) | |
4565 | { | |
4566 | case R_IA64_NONE: | |
4567 | case R_IA64_LDXMOV: | |
4568 | continue; | |
4569 | ||
4570 | case R_IA64_IMM14: | |
4571 | case R_IA64_IMM22: | |
4572 | case R_IA64_IMM64: | |
4573 | case R_IA64_DIR32MSB: | |
4574 | case R_IA64_DIR32LSB: | |
4575 | case R_IA64_DIR64MSB: | |
4576 | case R_IA64_DIR64LSB: | |
4577 | /* Install a dynamic relocation for this reloc. */ | |
02e6ad56 | 4578 | if ((dynamic_symbol_p || info->shared) |
ec338859 | 4579 | && r_symndx != 0 |
800eeca4 JW |
4580 | && (input_section->flags & SEC_ALLOC) != 0) |
4581 | { | |
4582 | unsigned int dyn_r_type; | |
4583 | long dynindx; | |
18b27f17 | 4584 | bfd_vma addend; |
800eeca4 JW |
4585 | |
4586 | BFD_ASSERT (srel != NULL); | |
4587 | ||
838e70c5 L |
4588 | switch (r_type) |
4589 | { | |
4590 | case R_IA64_IMM14: | |
4591 | case R_IA64_IMM22: | |
4592 | case R_IA64_IMM64: | |
4593 | /* ??? People shouldn't be doing non-pic code in | |
4594 | shared libraries nor dynamic executables. */ | |
4595 | (*_bfd_error_handler) | |
d003868e AM |
4596 | (_("%B: non-pic code with imm relocation against dynamic symbol `%s'"), |
4597 | input_bfd, | |
26c61ae5 L |
4598 | h ? h->root.root.string |
4599 | : bfd_elf_sym_name (input_bfd, symtab_hdr, sym, | |
4600 | sym_sec)); | |
838e70c5 L |
4601 | ret_val = FALSE; |
4602 | continue; | |
4603 | ||
4604 | default: | |
4605 | break; | |
4606 | } | |
4607 | ||
800eeca4 JW |
4608 | /* If we don't need dynamic symbol lookup, find a |
4609 | matching RELATIVE relocation. */ | |
4610 | dyn_r_type = r_type; | |
986a241f | 4611 | if (dynamic_symbol_p) |
18b27f17 RH |
4612 | { |
4613 | dynindx = h->dynindx; | |
4614 | addend = rel->r_addend; | |
4615 | value = 0; | |
4616 | } | |
800eeca4 JW |
4617 | else |
4618 | { | |
4619 | switch (r_type) | |
4620 | { | |
4621 | case R_IA64_DIR32MSB: | |
4622 | dyn_r_type = R_IA64_REL32MSB; | |
4623 | break; | |
4624 | case R_IA64_DIR32LSB: | |
4625 | dyn_r_type = R_IA64_REL32LSB; | |
4626 | break; | |
4627 | case R_IA64_DIR64MSB: | |
4628 | dyn_r_type = R_IA64_REL64MSB; | |
4629 | break; | |
4630 | case R_IA64_DIR64LSB: | |
4631 | dyn_r_type = R_IA64_REL64LSB; | |
4632 | break; | |
4633 | ||
4634 | default: | |
838e70c5 | 4635 | break; |
800eeca4 JW |
4636 | } |
4637 | dynindx = 0; | |
18b27f17 | 4638 | addend = value; |
800eeca4 JW |
4639 | } |
4640 | ||
bbe66d08 | 4641 | elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section, |
800eeca4 | 4642 | srel, rel->r_offset, dyn_r_type, |
18b27f17 | 4643 | dynindx, addend); |
800eeca4 | 4644 | } |
ae9a127f | 4645 | /* Fall through. */ |
800eeca4 JW |
4646 | |
4647 | case R_IA64_LTV32MSB: | |
4648 | case R_IA64_LTV32LSB: | |
4649 | case R_IA64_LTV64MSB: | |
4650 | case R_IA64_LTV64LSB: | |
bbb268c3 | 4651 | r = elfNN_ia64_install_value (hit_addr, value, r_type); |
800eeca4 JW |
4652 | break; |
4653 | ||
4654 | case R_IA64_GPREL22: | |
4655 | case R_IA64_GPREL64I: | |
4656 | case R_IA64_GPREL32MSB: | |
4657 | case R_IA64_GPREL32LSB: | |
4658 | case R_IA64_GPREL64MSB: | |
4659 | case R_IA64_GPREL64LSB: | |
4660 | if (dynamic_symbol_p) | |
4661 | { | |
4662 | (*_bfd_error_handler) | |
d003868e | 4663 | (_("%B: @gprel relocation against dynamic symbol %s"), |
26c61ae5 L |
4664 | input_bfd, |
4665 | h ? h->root.root.string | |
4666 | : bfd_elf_sym_name (input_bfd, symtab_hdr, sym, | |
4667 | sym_sec)); | |
b34976b6 | 4668 | ret_val = FALSE; |
800eeca4 JW |
4669 | continue; |
4670 | } | |
4671 | value -= gp_val; | |
bbb268c3 | 4672 | r = elfNN_ia64_install_value (hit_addr, value, r_type); |
800eeca4 JW |
4673 | break; |
4674 | ||
4675 | case R_IA64_LTOFF22: | |
4676 | case R_IA64_LTOFF22X: | |
4677 | case R_IA64_LTOFF64I: | |
b34976b6 | 4678 | dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, FALSE); |
800eeca4 | 4679 | value = set_got_entry (input_bfd, info, dyn_i, (h ? h->dynindx : -1), |
5a260b66 | 4680 | rel->r_addend, value, R_IA64_DIRNNLSB); |
800eeca4 | 4681 | value -= gp_val; |
bbb268c3 | 4682 | r = elfNN_ia64_install_value (hit_addr, value, r_type); |
800eeca4 JW |
4683 | break; |
4684 | ||
4685 | case R_IA64_PLTOFF22: | |
4686 | case R_IA64_PLTOFF64I: | |
4687 | case R_IA64_PLTOFF64MSB: | |
4688 | case R_IA64_PLTOFF64LSB: | |
b34976b6 AM |
4689 | dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, FALSE); |
4690 | value = set_pltoff_entry (output_bfd, info, dyn_i, value, FALSE); | |
800eeca4 | 4691 | value -= gp_val; |
bbb268c3 | 4692 | r = elfNN_ia64_install_value (hit_addr, value, r_type); |
800eeca4 JW |
4693 | break; |
4694 | ||
4695 | case R_IA64_FPTR64I: | |
4696 | case R_IA64_FPTR32MSB: | |
4697 | case R_IA64_FPTR32LSB: | |
4698 | case R_IA64_FPTR64MSB: | |
4699 | case R_IA64_FPTR64LSB: | |
b34976b6 | 4700 | dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, FALSE); |
800eeca4 JW |
4701 | if (dyn_i->want_fptr) |
4702 | { | |
4703 | if (!undef_weak_ref) | |
4704 | value = set_fptr_entry (output_bfd, info, dyn_i, value); | |
4705 | } | |
9203ba99 | 4706 | if (!dyn_i->want_fptr || info->pie) |
800eeca4 JW |
4707 | { |
4708 | long dynindx; | |
9203ba99 JJ |
4709 | unsigned int dyn_r_type = r_type; |
4710 | bfd_vma addend = rel->r_addend; | |
800eeca4 JW |
4711 | |
4712 | /* Otherwise, we expect the dynamic linker to create | |
4713 | the entry. */ | |
4714 | ||
9203ba99 JJ |
4715 | if (dyn_i->want_fptr) |
4716 | { | |
4717 | if (r_type == R_IA64_FPTR64I) | |
4718 | { | |
4719 | /* We can't represent this without a dynamic symbol. | |
4720 | Adjust the relocation to be against an output | |
4721 | section symbol, which are always present in the | |
4722 | dynamic symbol table. */ | |
4723 | /* ??? People shouldn't be doing non-pic code in | |
4724 | shared libraries. Hork. */ | |
4725 | (*_bfd_error_handler) | |
d003868e AM |
4726 | (_("%B: linking non-pic code in a position independent executable"), |
4727 | input_bfd); | |
9203ba99 JJ |
4728 | ret_val = FALSE; |
4729 | continue; | |
4730 | } | |
4731 | dynindx = 0; | |
4732 | addend = value; | |
5a260b66 | 4733 | dyn_r_type = r_type + R_IA64_RELNNLSB - R_IA64_FPTRNNLSB; |
9203ba99 JJ |
4734 | } |
4735 | else if (h) | |
800eeca4 JW |
4736 | { |
4737 | if (h->dynindx != -1) | |
4738 | dynindx = h->dynindx; | |
4739 | else | |
4740 | dynindx = (_bfd_elf_link_lookup_local_dynindx | |
4741 | (info, h->root.u.def.section->owner, | |
4742 | global_sym_index (h))); | |
9203ba99 | 4743 | value = 0; |
800eeca4 JW |
4744 | } |
4745 | else | |
4746 | { | |
4747 | dynindx = (_bfd_elf_link_lookup_local_dynindx | |
dc810e39 | 4748 | (info, input_bfd, (long) r_symndx)); |
9203ba99 | 4749 | value = 0; |
800eeca4 JW |
4750 | } |
4751 | ||
bbe66d08 | 4752 | elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section, |
9203ba99 JJ |
4753 | srel, rel->r_offset, dyn_r_type, |
4754 | dynindx, addend); | |
800eeca4 JW |
4755 | } |
4756 | ||
bbb268c3 | 4757 | r = elfNN_ia64_install_value (hit_addr, value, r_type); |
800eeca4 JW |
4758 | break; |
4759 | ||
4760 | case R_IA64_LTOFF_FPTR22: | |
4761 | case R_IA64_LTOFF_FPTR64I: | |
a4bd8390 JW |
4762 | case R_IA64_LTOFF_FPTR32MSB: |
4763 | case R_IA64_LTOFF_FPTR32LSB: | |
800eeca4 JW |
4764 | case R_IA64_LTOFF_FPTR64MSB: |
4765 | case R_IA64_LTOFF_FPTR64LSB: | |
4766 | { | |
4767 | long dynindx; | |
4768 | ||
b34976b6 | 4769 | dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, FALSE); |
800eeca4 JW |
4770 | if (dyn_i->want_fptr) |
4771 | { | |
f12123c0 | 4772 | BFD_ASSERT (h == NULL || h->dynindx == -1); |
800eeca4 JW |
4773 | if (!undef_weak_ref) |
4774 | value = set_fptr_entry (output_bfd, info, dyn_i, value); | |
4775 | dynindx = -1; | |
4776 | } | |
4777 | else | |
4778 | { | |
4779 | /* Otherwise, we expect the dynamic linker to create | |
4780 | the entry. */ | |
4781 | if (h) | |
4782 | { | |
4783 | if (h->dynindx != -1) | |
4784 | dynindx = h->dynindx; | |
4785 | else | |
4786 | dynindx = (_bfd_elf_link_lookup_local_dynindx | |
4787 | (info, h->root.u.def.section->owner, | |
4788 | global_sym_index (h))); | |
4789 | } | |
4790 | else | |
4791 | dynindx = (_bfd_elf_link_lookup_local_dynindx | |
dc810e39 | 4792 | (info, input_bfd, (long) r_symndx)); |
800eeca4 JW |
4793 | value = 0; |
4794 | } | |
4795 | ||
4796 | value = set_got_entry (output_bfd, info, dyn_i, dynindx, | |
5a260b66 | 4797 | rel->r_addend, value, R_IA64_FPTRNNLSB); |
800eeca4 | 4798 | value -= gp_val; |
bbb268c3 | 4799 | r = elfNN_ia64_install_value (hit_addr, value, r_type); |
800eeca4 JW |
4800 | } |
4801 | break; | |
4802 | ||
4803 | case R_IA64_PCREL32MSB: | |
4804 | case R_IA64_PCREL32LSB: | |
4805 | case R_IA64_PCREL64MSB: | |
4806 | case R_IA64_PCREL64LSB: | |
4807 | /* Install a dynamic relocation for this reloc. */ | |
02e6ad56 | 4808 | if (dynamic_symbol_p && r_symndx != 0) |
800eeca4 JW |
4809 | { |
4810 | BFD_ASSERT (srel != NULL); | |
4811 | ||
bbe66d08 | 4812 | elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section, |
800eeca4 JW |
4813 | srel, rel->r_offset, r_type, |
4814 | h->dynindx, rel->r_addend); | |
4815 | } | |
4816 | goto finish_pcrel; | |
4817 | ||
800eeca4 | 4818 | case R_IA64_PCREL21B: |
748abff6 | 4819 | case R_IA64_PCREL60B: |
800eeca4 | 4820 | /* We should have created a PLT entry for any dynamic symbol. */ |
800eeca4 JW |
4821 | dyn_i = NULL; |
4822 | if (h) | |
b34976b6 | 4823 | dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, FALSE); |
800eeca4 JW |
4824 | |
4825 | if (dyn_i && dyn_i->want_plt2) | |
4826 | { | |
4827 | /* Should have caught this earlier. */ | |
4828 | BFD_ASSERT (rel->r_addend == 0); | |
4829 | ||
cc3bd654 L |
4830 | value = (ia64_info->root.splt->output_section->vma |
4831 | + ia64_info->root.splt->output_offset | |
800eeca4 JW |
4832 | + dyn_i->plt2_offset); |
4833 | } | |
4834 | else | |
4835 | { | |
4836 | /* Since there's no PLT entry, Validate that this is | |
4837 | locally defined. */ | |
4838 | BFD_ASSERT (undef_weak_ref || sym_sec->output_section != NULL); | |
4839 | ||
4840 | /* If the symbol is undef_weak, we shouldn't be trying | |
4841 | to call it. There's every chance that we'd wind up | |
4842 | with an out-of-range fixup here. Don't bother setting | |
4843 | any value at all. */ | |
4844 | if (undef_weak_ref) | |
4845 | continue; | |
4846 | } | |
4847 | goto finish_pcrel; | |
4848 | ||
2f9bd3f6 RH |
4849 | case R_IA64_PCREL21BI: |
4850 | case R_IA64_PCREL21F: | |
4851 | case R_IA64_PCREL21M: | |
748abff6 RH |
4852 | case R_IA64_PCREL22: |
4853 | case R_IA64_PCREL64I: | |
2f9bd3f6 RH |
4854 | /* The PCREL21BI reloc is specifically not intended for use with |
4855 | dynamic relocs. PCREL21F and PCREL21M are used for speculation | |
f12123c0 | 4856 | fixup code, and thus probably ought not be dynamic. The |
2f9bd3f6 RH |
4857 | PCREL22 and PCREL64I relocs aren't emitted as dynamic relocs. */ |
4858 | if (dynamic_symbol_p) | |
4859 | { | |
4860 | const char *msg; | |
4861 | ||
4862 | if (r_type == R_IA64_PCREL21BI) | |
d003868e | 4863 | msg = _("%B: @internal branch to dynamic symbol %s"); |
2f9bd3f6 | 4864 | else if (r_type == R_IA64_PCREL21F || r_type == R_IA64_PCREL21M) |
d003868e | 4865 | msg = _("%B: speculation fixup to dynamic symbol %s"); |
2f9bd3f6 | 4866 | else |
d003868e | 4867 | msg = _("%B: @pcrel relocation against dynamic symbol %s"); |
26c61ae5 L |
4868 | (*_bfd_error_handler) (msg, input_bfd, |
4869 | h ? h->root.root.string | |
4870 | : bfd_elf_sym_name (input_bfd, | |
4871 | symtab_hdr, | |
4872 | sym, | |
4873 | sym_sec)); | |
2f9bd3f6 RH |
4874 | ret_val = FALSE; |
4875 | continue; | |
4876 | } | |
4877 | goto finish_pcrel; | |
4878 | ||
800eeca4 JW |
4879 | finish_pcrel: |
4880 | /* Make pc-relative. */ | |
4881 | value -= (input_section->output_section->vma | |
4882 | + input_section->output_offset | |
4883 | + rel->r_offset) & ~ (bfd_vma) 0x3; | |
bbb268c3 | 4884 | r = elfNN_ia64_install_value (hit_addr, value, r_type); |
800eeca4 JW |
4885 | break; |
4886 | ||
4887 | case R_IA64_SEGREL32MSB: | |
4888 | case R_IA64_SEGREL32LSB: | |
4889 | case R_IA64_SEGREL64MSB: | |
4890 | case R_IA64_SEGREL64LSB: | |
d7458677 | 4891 | { |
d7458677 | 4892 | /* Find the segment that contains the output_section. */ |
2ea37f1c | 4893 | Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section |
992824d5 | 4894 | (output_bfd, input_section->output_section); |
800eeca4 | 4895 | |
2ea37f1c | 4896 | if (p == NULL) |
d7458677 | 4897 | { |
800eeca4 | 4898 | r = bfd_reloc_notsupported; |
d7458677 AM |
4899 | } |
4900 | else | |
4901 | { | |
4902 | /* The VMA of the segment is the vaddr of the associated | |
4903 | program header. */ | |
4904 | if (value > p->p_vaddr) | |
4905 | value -= p->p_vaddr; | |
4906 | else | |
4907 | value = 0; | |
bbb268c3 | 4908 | r = elfNN_ia64_install_value (hit_addr, value, r_type); |
d7458677 AM |
4909 | } |
4910 | break; | |
4911 | } | |
800eeca4 JW |
4912 | |
4913 | case R_IA64_SECREL32MSB: | |
4914 | case R_IA64_SECREL32LSB: | |
4915 | case R_IA64_SECREL64MSB: | |
4916 | case R_IA64_SECREL64LSB: | |
97ecf322 L |
4917 | /* Make output-section relative to section where the symbol |
4918 | is defined. PR 475 */ | |
bf718458 L |
4919 | if (sym_sec) |
4920 | value -= sym_sec->output_section->vma; | |
bbb268c3 | 4921 | r = elfNN_ia64_install_value (hit_addr, value, r_type); |
800eeca4 JW |
4922 | break; |
4923 | ||
800eeca4 JW |
4924 | case R_IA64_IPLTMSB: |
4925 | case R_IA64_IPLTLSB: | |
18b27f17 RH |
4926 | /* Install a dynamic relocation for this reloc. */ |
4927 | if ((dynamic_symbol_p || info->shared) | |
4928 | && (input_section->flags & SEC_ALLOC) != 0) | |
4929 | { | |
18b27f17 RH |
4930 | BFD_ASSERT (srel != NULL); |
4931 | ||
4932 | /* If we don't need dynamic symbol lookup, install two | |
4933 | RELATIVE relocations. */ | |
986a241f | 4934 | if (!dynamic_symbol_p) |
18b27f17 RH |
4935 | { |
4936 | unsigned int dyn_r_type; | |
3e932841 | 4937 | |
18b27f17 RH |
4938 | if (r_type == R_IA64_IPLTMSB) |
4939 | dyn_r_type = R_IA64_REL64MSB; | |
4940 | else | |
4941 | dyn_r_type = R_IA64_REL64LSB; | |
4942 | ||
4943 | elfNN_ia64_install_dyn_reloc (output_bfd, info, | |
4944 | input_section, | |
4945 | srel, rel->r_offset, | |
4946 | dyn_r_type, 0, value); | |
4947 | elfNN_ia64_install_dyn_reloc (output_bfd, info, | |
4948 | input_section, | |
4949 | srel, rel->r_offset + 8, | |
4950 | dyn_r_type, 0, gp_val); | |
4951 | } | |
4952 | else | |
4953 | elfNN_ia64_install_dyn_reloc (output_bfd, info, input_section, | |
4954 | srel, rel->r_offset, r_type, | |
4955 | h->dynindx, rel->r_addend); | |
4956 | } | |
4957 | ||
4958 | if (r_type == R_IA64_IPLTMSB) | |
4959 | r_type = R_IA64_DIR64MSB; | |
4960 | else | |
4961 | r_type = R_IA64_DIR64LSB; | |
bbb268c3 JW |
4962 | elfNN_ia64_install_value (hit_addr, value, r_type); |
4963 | r = elfNN_ia64_install_value (hit_addr + 8, gp_val, r_type); | |
18b27f17 | 4964 | break; |
800eeca4 | 4965 | |
13ae64f3 JJ |
4966 | case R_IA64_TPREL14: |
4967 | case R_IA64_TPREL22: | |
4968 | case R_IA64_TPREL64I: | |
0f2830ff L |
4969 | if (elf_hash_table (info)->tls_sec == NULL) |
4970 | goto missing_tls_sec; | |
13ae64f3 | 4971 | value -= elfNN_ia64_tprel_base (info); |
bbb268c3 | 4972 | r = elfNN_ia64_install_value (hit_addr, value, r_type); |
13ae64f3 JJ |
4973 | break; |
4974 | ||
4975 | case R_IA64_DTPREL14: | |
4976 | case R_IA64_DTPREL22: | |
4977 | case R_IA64_DTPREL64I: | |
5a260b66 L |
4978 | case R_IA64_DTPREL32LSB: |
4979 | case R_IA64_DTPREL32MSB: | |
b3dfd7fe JJ |
4980 | case R_IA64_DTPREL64LSB: |
4981 | case R_IA64_DTPREL64MSB: | |
0f2830ff L |
4982 | if (elf_hash_table (info)->tls_sec == NULL) |
4983 | goto missing_tls_sec; | |
13ae64f3 | 4984 | value -= elfNN_ia64_dtprel_base (info); |
bbb268c3 | 4985 | r = elfNN_ia64_install_value (hit_addr, value, r_type); |
13ae64f3 JJ |
4986 | break; |
4987 | ||
4988 | case R_IA64_LTOFF_TPREL22: | |
4989 | case R_IA64_LTOFF_DTPMOD22: | |
4990 | case R_IA64_LTOFF_DTPREL22: | |
4991 | { | |
4992 | int got_r_type; | |
a823975a JJ |
4993 | long dynindx = h ? h->dynindx : -1; |
4994 | bfd_vma r_addend = rel->r_addend; | |
13ae64f3 JJ |
4995 | |
4996 | switch (r_type) | |
4997 | { | |
4998 | default: | |
4999 | case R_IA64_LTOFF_TPREL22: | |
a823975a JJ |
5000 | if (!dynamic_symbol_p) |
5001 | { | |
0f2830ff L |
5002 | if (elf_hash_table (info)->tls_sec == NULL) |
5003 | goto missing_tls_sec; | |
a823975a JJ |
5004 | if (!info->shared) |
5005 | value -= elfNN_ia64_tprel_base (info); | |
5006 | else | |
5007 | { | |
5008 | r_addend += value - elfNN_ia64_dtprel_base (info); | |
5009 | dynindx = 0; | |
5010 | } | |
5011 | } | |
13ae64f3 JJ |
5012 | got_r_type = R_IA64_TPREL64LSB; |
5013 | break; | |
5014 | case R_IA64_LTOFF_DTPMOD22: | |
5015 | if (!dynamic_symbol_p && !info->shared) | |
5016 | value = 1; | |
5017 | got_r_type = R_IA64_DTPMOD64LSB; | |
5018 | break; | |
5019 | case R_IA64_LTOFF_DTPREL22: | |
5020 | if (!dynamic_symbol_p) | |
0f2830ff L |
5021 | { |
5022 | if (elf_hash_table (info)->tls_sec == NULL) | |
5023 | goto missing_tls_sec; | |
5024 | value -= elfNN_ia64_dtprel_base (info); | |
5025 | } | |
5a260b66 | 5026 | got_r_type = R_IA64_DTPRELNNLSB; |
13ae64f3 JJ |
5027 | break; |
5028 | } | |
b34976b6 | 5029 | dyn_i = get_dyn_sym_info (ia64_info, h, input_bfd, rel, FALSE); |
a823975a | 5030 | value = set_got_entry (input_bfd, info, dyn_i, dynindx, r_addend, |
13ae64f3 JJ |
5031 | value, got_r_type); |
5032 | value -= gp_val; | |
bbb268c3 | 5033 | r = elfNN_ia64_install_value (hit_addr, value, r_type); |
13ae64f3 JJ |
5034 | } |
5035 | break; | |
5036 | ||
800eeca4 JW |
5037 | default: |
5038 | r = bfd_reloc_notsupported; | |
5039 | break; | |
5040 | } | |
5041 | ||
5042 | switch (r) | |
5043 | { | |
5044 | case bfd_reloc_ok: | |
5045 | break; | |
5046 | ||
5047 | case bfd_reloc_undefined: | |
5048 | /* This can happen for global table relative relocs if | |
5049 | __gp is undefined. This is a panic situation so we | |
5050 | don't try to continue. */ | |
5051 | (*info->callbacks->undefined_symbol) | |
5052 | (info, "__gp", input_bfd, input_section, rel->r_offset, 1); | |
b34976b6 | 5053 | return FALSE; |
800eeca4 JW |
5054 | |
5055 | case bfd_reloc_notsupported: | |
5056 | { | |
5057 | const char *name; | |
5058 | ||
5059 | if (h) | |
5060 | name = h->root.root.string; | |
5061 | else | |
26c61ae5 L |
5062 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, |
5063 | sym_sec); | |
800eeca4 JW |
5064 | if (!(*info->callbacks->warning) (info, _("unsupported reloc"), |
5065 | name, input_bfd, | |
5066 | input_section, rel->r_offset)) | |
b34976b6 AM |
5067 | return FALSE; |
5068 | ret_val = FALSE; | |
800eeca4 JW |
5069 | } |
5070 | break; | |
5071 | ||
5072 | case bfd_reloc_dangerous: | |
5073 | case bfd_reloc_outofrange: | |
5074 | case bfd_reloc_overflow: | |
5075 | default: | |
0f2830ff | 5076 | missing_tls_sec: |
800eeca4 JW |
5077 | { |
5078 | const char *name; | |
5079 | ||
5080 | if (h) | |
f0581930 | 5081 | name = h->root.root.string; |
800eeca4 | 5082 | else |
26c61ae5 L |
5083 | name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, |
5084 | sym_sec); | |
c5509b92 L |
5085 | |
5086 | switch (r_type) | |
5087 | { | |
0f2830ff L |
5088 | case R_IA64_TPREL14: |
5089 | case R_IA64_TPREL22: | |
5090 | case R_IA64_TPREL64I: | |
5091 | case R_IA64_DTPREL14: | |
5092 | case R_IA64_DTPREL22: | |
5093 | case R_IA64_DTPREL64I: | |
5094 | case R_IA64_DTPREL32LSB: | |
5095 | case R_IA64_DTPREL32MSB: | |
5096 | case R_IA64_DTPREL64LSB: | |
5097 | case R_IA64_DTPREL64MSB: | |
5098 | case R_IA64_LTOFF_TPREL22: | |
5099 | case R_IA64_LTOFF_DTPMOD22: | |
5100 | case R_IA64_LTOFF_DTPREL22: | |
5101 | (*_bfd_error_handler) | |
5102 | (_("%B: missing TLS section for relocation %s against `%s' at 0x%lx in section `%A'."), | |
5103 | input_bfd, input_section, howto->name, name, | |
5104 | rel->r_offset); | |
5105 | break; | |
5106 | ||
c5509b92 L |
5107 | case R_IA64_PCREL21B: |
5108 | case R_IA64_PCREL21BI: | |
5109 | case R_IA64_PCREL21M: | |
5110 | case R_IA64_PCREL21F: | |
5111 | if (is_elf_hash_table (info->hash)) | |
5112 | { | |
5113 | /* Relaxtion is always performed for ELF output. | |
5114 | Overflow failures for those relocations mean | |
5115 | that the section is too big to relax. */ | |
5116 | (*_bfd_error_handler) | |
5117 | (_("%B: Can't relax br (%s) to `%s' at 0x%lx in section `%A' with size 0x%lx (> 0x1000000)."), | |
5118 | input_bfd, input_section, howto->name, name, | |
5119 | rel->r_offset, input_section->size); | |
5120 | break; | |
5121 | } | |
5122 | default: | |
5123 | if (!(*info->callbacks->reloc_overflow) (info, | |
5124 | &h->root, | |
5125 | name, | |
5126 | howto->name, | |
5127 | (bfd_vma) 0, | |
5128 | input_bfd, | |
5129 | input_section, | |
5130 | rel->r_offset)) | |
5131 | return FALSE; | |
5132 | break; | |
5133 | } | |
5134 | ||
b34976b6 | 5135 | ret_val = FALSE; |
800eeca4 JW |
5136 | } |
5137 | break; | |
5138 | } | |
5139 | } | |
5140 | ||
5141 | return ret_val; | |
5142 | } | |
5143 | ||
b34976b6 | 5144 | static bfd_boolean |
eae50df2 L |
5145 | elfNN_ia64_finish_dynamic_symbol (bfd *output_bfd, |
5146 | struct bfd_link_info *info, | |
5147 | struct elf_link_hash_entry *h, | |
5148 | Elf_Internal_Sym *sym) | |
800eeca4 | 5149 | { |
bbe66d08 JW |
5150 | struct elfNN_ia64_link_hash_table *ia64_info; |
5151 | struct elfNN_ia64_dyn_sym_info *dyn_i; | |
800eeca4 | 5152 | |
bbe66d08 | 5153 | ia64_info = elfNN_ia64_hash_table (info); |
b34976b6 | 5154 | dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, FALSE); |
800eeca4 JW |
5155 | |
5156 | /* Fill in the PLT data, if required. */ | |
5157 | if (dyn_i && dyn_i->want_plt) | |
5158 | { | |
5159 | Elf_Internal_Rela outrel; | |
5160 | bfd_byte *loc; | |
5161 | asection *plt_sec; | |
5162 | bfd_vma plt_addr, pltoff_addr, gp_val, index; | |
800eeca4 JW |
5163 | |
5164 | gp_val = _bfd_get_gp_value (output_bfd); | |
5165 | ||
5166 | /* Initialize the minimal PLT entry. */ | |
5167 | ||
5168 | index = (dyn_i->plt_offset - PLT_HEADER_SIZE) / PLT_MIN_ENTRY_SIZE; | |
cc3bd654 | 5169 | plt_sec = ia64_info->root.splt; |
800eeca4 JW |
5170 | loc = plt_sec->contents + dyn_i->plt_offset; |
5171 | ||
5172 | memcpy (loc, plt_min_entry, PLT_MIN_ENTRY_SIZE); | |
bbb268c3 JW |
5173 | elfNN_ia64_install_value (loc, index, R_IA64_IMM22); |
5174 | elfNN_ia64_install_value (loc+2, -dyn_i->plt_offset, R_IA64_PCREL21B); | |
800eeca4 JW |
5175 | |
5176 | plt_addr = (plt_sec->output_section->vma | |
5177 | + plt_sec->output_offset | |
5178 | + dyn_i->plt_offset); | |
b34976b6 | 5179 | pltoff_addr = set_pltoff_entry (output_bfd, info, dyn_i, plt_addr, TRUE); |
800eeca4 JW |
5180 | |
5181 | /* Initialize the FULL PLT entry, if needed. */ | |
5182 | if (dyn_i->want_plt2) | |
5183 | { | |
5184 | loc = plt_sec->contents + dyn_i->plt2_offset; | |
5185 | ||
5186 | memcpy (loc, plt_full_entry, PLT_FULL_ENTRY_SIZE); | |
bbb268c3 | 5187 | elfNN_ia64_install_value (loc, pltoff_addr - gp_val, R_IA64_IMM22); |
800eeca4 JW |
5188 | |
5189 | /* Mark the symbol as undefined, rather than as defined in the | |
5190 | plt section. Leave the value alone. */ | |
5191 | /* ??? We didn't redefine it in adjust_dynamic_symbol in the | |
c152c796 | 5192 | first place. But perhaps elflink.c did some for us. */ |
f5385ebf | 5193 | if (!h->def_regular) |
800eeca4 JW |
5194 | sym->st_shndx = SHN_UNDEF; |
5195 | } | |
5196 | ||
5197 | /* Create the dynamic relocation. */ | |
5198 | outrel.r_offset = pltoff_addr; | |
5199 | if (bfd_little_endian (output_bfd)) | |
bbe66d08 | 5200 | outrel.r_info = ELFNN_R_INFO (h->dynindx, R_IA64_IPLTLSB); |
800eeca4 | 5201 | else |
bbe66d08 | 5202 | outrel.r_info = ELFNN_R_INFO (h->dynindx, R_IA64_IPLTMSB); |
800eeca4 JW |
5203 | outrel.r_addend = 0; |
5204 | ||
5205 | /* This is fun. In the .IA_64.pltoff section, we've got entries | |
5206 | that correspond both to real PLT entries, and those that | |
5207 | happened to resolve to local symbols but need to be created | |
5208 | to satisfy @pltoff relocations. The .rela.IA_64.pltoff | |
5209 | relocations for the real PLT should come at the end of the | |
5210 | section, so that they can be indexed by plt entry at runtime. | |
5211 | ||
5212 | We emitted all of the relocations for the non-PLT @pltoff | |
5213 | entries during relocate_section. So we can consider the | |
5214 | existing sec->reloc_count to be the base of the array of | |
5215 | PLT relocations. */ | |
5216 | ||
947216bf AM |
5217 | loc = ia64_info->rel_pltoff_sec->contents; |
5218 | loc += ((ia64_info->rel_pltoff_sec->reloc_count + index) | |
37cd2629 | 5219 | * sizeof (ElfNN_External_Rela)); |
947216bf | 5220 | bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc); |
800eeca4 JW |
5221 | } |
5222 | ||
5223 | /* Mark some specially defined symbols as absolute. */ | |
5224 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 | |
22edb2f1 RS |
5225 | || h == ia64_info->root.hgot |
5226 | || h == ia64_info->root.hplt) | |
800eeca4 JW |
5227 | sym->st_shndx = SHN_ABS; |
5228 | ||
b34976b6 | 5229 | return TRUE; |
800eeca4 JW |
5230 | } |
5231 | ||
b34976b6 | 5232 | static bfd_boolean |
eae50df2 L |
5233 | elfNN_ia64_finish_dynamic_sections (bfd *abfd, |
5234 | struct bfd_link_info *info) | |
800eeca4 | 5235 | { |
bbe66d08 | 5236 | struct elfNN_ia64_link_hash_table *ia64_info; |
800eeca4 JW |
5237 | bfd *dynobj; |
5238 | ||
bbe66d08 | 5239 | ia64_info = elfNN_ia64_hash_table (info); |
800eeca4 JW |
5240 | dynobj = ia64_info->root.dynobj; |
5241 | ||
5242 | if (elf_hash_table (info)->dynamic_sections_created) | |
5243 | { | |
bbe66d08 | 5244 | ElfNN_External_Dyn *dyncon, *dynconend; |
800eeca4 JW |
5245 | asection *sdyn, *sgotplt; |
5246 | bfd_vma gp_val; | |
5247 | ||
5248 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); | |
5249 | sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); | |
5250 | BFD_ASSERT (sdyn != NULL); | |
bbe66d08 | 5251 | dyncon = (ElfNN_External_Dyn *) sdyn->contents; |
eea6121a | 5252 | dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size); |
800eeca4 JW |
5253 | |
5254 | gp_val = _bfd_get_gp_value (abfd); | |
5255 | ||
5256 | for (; dyncon < dynconend; dyncon++) | |
5257 | { | |
5258 | Elf_Internal_Dyn dyn; | |
800eeca4 | 5259 | |
bbe66d08 | 5260 | bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn); |
800eeca4 JW |
5261 | |
5262 | switch (dyn.d_tag) | |
5263 | { | |
5264 | case DT_PLTGOT: | |
5265 | dyn.d_un.d_ptr = gp_val; | |
5266 | break; | |
5267 | ||
5268 | case DT_PLTRELSZ: | |
5269 | dyn.d_un.d_val = (ia64_info->minplt_entries | |
bbe66d08 | 5270 | * sizeof (ElfNN_External_Rela)); |
800eeca4 JW |
5271 | break; |
5272 | ||
5273 | case DT_JMPREL: | |
5274 | /* See the comment above in finish_dynamic_symbol. */ | |
5275 | dyn.d_un.d_ptr = (ia64_info->rel_pltoff_sec->output_section->vma | |
5276 | + ia64_info->rel_pltoff_sec->output_offset | |
5277 | + (ia64_info->rel_pltoff_sec->reloc_count | |
bbe66d08 | 5278 | * sizeof (ElfNN_External_Rela))); |
800eeca4 JW |
5279 | break; |
5280 | ||
5281 | case DT_IA_64_PLT_RESERVE: | |
5282 | dyn.d_un.d_ptr = (sgotplt->output_section->vma | |
5283 | + sgotplt->output_offset); | |
5284 | break; | |
5285 | ||
5286 | case DT_RELASZ: | |
5287 | /* Do not have RELASZ include JMPREL. This makes things | |
3e932841 | 5288 | easier on ld.so. This is not what the rest of BFD set up. */ |
800eeca4 | 5289 | dyn.d_un.d_val -= (ia64_info->minplt_entries |
bbe66d08 | 5290 | * sizeof (ElfNN_External_Rela)); |
800eeca4 | 5291 | break; |
800eeca4 JW |
5292 | } |
5293 | ||
bbe66d08 | 5294 | bfd_elfNN_swap_dyn_out (abfd, &dyn, dyncon); |
800eeca4 JW |
5295 | } |
5296 | ||
ae9a127f | 5297 | /* Initialize the PLT0 entry. */ |
cc3bd654 | 5298 | if (ia64_info->root.splt) |
800eeca4 | 5299 | { |
cc3bd654 | 5300 | bfd_byte *loc = ia64_info->root.splt->contents; |
800eeca4 JW |
5301 | bfd_vma pltres; |
5302 | ||
5303 | memcpy (loc, plt_header, PLT_HEADER_SIZE); | |
5304 | ||
5305 | pltres = (sgotplt->output_section->vma | |
5306 | + sgotplt->output_offset | |
5307 | - gp_val); | |
5308 | ||
bbb268c3 | 5309 | elfNN_ia64_install_value (loc+1, pltres, R_IA64_GPREL22); |
800eeca4 JW |
5310 | } |
5311 | } | |
5312 | ||
b34976b6 | 5313 | return TRUE; |
800eeca4 JW |
5314 | } |
5315 | \f | |
ae9a127f | 5316 | /* ELF file flag handling: */ |
800eeca4 | 5317 | |
3e932841 | 5318 | /* Function to keep IA-64 specific file flags. */ |
b34976b6 | 5319 | static bfd_boolean |
eae50df2 | 5320 | elfNN_ia64_set_private_flags (bfd *abfd, flagword flags) |
800eeca4 JW |
5321 | { |
5322 | BFD_ASSERT (!elf_flags_init (abfd) | |
5323 | || elf_elfheader (abfd)->e_flags == flags); | |
5324 | ||
5325 | elf_elfheader (abfd)->e_flags = flags; | |
b34976b6 AM |
5326 | elf_flags_init (abfd) = TRUE; |
5327 | return TRUE; | |
800eeca4 JW |
5328 | } |
5329 | ||
800eeca4 JW |
5330 | /* Merge backend specific data from an object file to the output |
5331 | object file when linking. */ | |
b34976b6 | 5332 | static bfd_boolean |
eae50df2 | 5333 | elfNN_ia64_merge_private_bfd_data (bfd *ibfd, bfd *obfd) |
800eeca4 JW |
5334 | { |
5335 | flagword out_flags; | |
5336 | flagword in_flags; | |
b34976b6 | 5337 | bfd_boolean ok = TRUE; |
800eeca4 JW |
5338 | |
5339 | /* Don't even pretend to support mixed-format linking. */ | |
5340 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour | |
5341 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
b34976b6 | 5342 | return FALSE; |
800eeca4 JW |
5343 | |
5344 | in_flags = elf_elfheader (ibfd)->e_flags; | |
5345 | out_flags = elf_elfheader (obfd)->e_flags; | |
5346 | ||
5347 | if (! elf_flags_init (obfd)) | |
5348 | { | |
b34976b6 | 5349 | elf_flags_init (obfd) = TRUE; |
800eeca4 JW |
5350 | elf_elfheader (obfd)->e_flags = in_flags; |
5351 | ||
5352 | if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) | |
5353 | && bfd_get_arch_info (obfd)->the_default) | |
5354 | { | |
5355 | return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), | |
5356 | bfd_get_mach (ibfd)); | |
5357 | } | |
5358 | ||
b34976b6 | 5359 | return TRUE; |
800eeca4 JW |
5360 | } |
5361 | ||
5362 | /* Check flag compatibility. */ | |
5363 | if (in_flags == out_flags) | |
b34976b6 | 5364 | return TRUE; |
800eeca4 | 5365 | |
c43c2cc5 JW |
5366 | /* Output has EF_IA_64_REDUCEDFP set only if all inputs have it set. */ |
5367 | if (!(in_flags & EF_IA_64_REDUCEDFP) && (out_flags & EF_IA_64_REDUCEDFP)) | |
5368 | elf_elfheader (obfd)->e_flags &= ~EF_IA_64_REDUCEDFP; | |
5369 | ||
800eeca4 JW |
5370 | if ((in_flags & EF_IA_64_TRAPNIL) != (out_flags & EF_IA_64_TRAPNIL)) |
5371 | { | |
5372 | (*_bfd_error_handler) | |
d003868e AM |
5373 | (_("%B: linking trap-on-NULL-dereference with non-trapping files"), |
5374 | ibfd); | |
800eeca4 JW |
5375 | |
5376 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 5377 | ok = FALSE; |
800eeca4 JW |
5378 | } |
5379 | if ((in_flags & EF_IA_64_BE) != (out_flags & EF_IA_64_BE)) | |
5380 | { | |
5381 | (*_bfd_error_handler) | |
d003868e AM |
5382 | (_("%B: linking big-endian files with little-endian files"), |
5383 | ibfd); | |
800eeca4 JW |
5384 | |
5385 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 5386 | ok = FALSE; |
800eeca4 JW |
5387 | } |
5388 | if ((in_flags & EF_IA_64_ABI64) != (out_flags & EF_IA_64_ABI64)) | |
5389 | { | |
5390 | (*_bfd_error_handler) | |
d003868e AM |
5391 | (_("%B: linking 64-bit files with 32-bit files"), |
5392 | ibfd); | |
800eeca4 JW |
5393 | |
5394 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 5395 | ok = FALSE; |
800eeca4 | 5396 | } |
c43c2cc5 JW |
5397 | if ((in_flags & EF_IA_64_CONS_GP) != (out_flags & EF_IA_64_CONS_GP)) |
5398 | { | |
5399 | (*_bfd_error_handler) | |
d003868e AM |
5400 | (_("%B: linking constant-gp files with non-constant-gp files"), |
5401 | ibfd); | |
c43c2cc5 JW |
5402 | |
5403 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 5404 | ok = FALSE; |
c43c2cc5 JW |
5405 | } |
5406 | if ((in_flags & EF_IA_64_NOFUNCDESC_CONS_GP) | |
5407 | != (out_flags & EF_IA_64_NOFUNCDESC_CONS_GP)) | |
5408 | { | |
5409 | (*_bfd_error_handler) | |
d003868e AM |
5410 | (_("%B: linking auto-pic files with non-auto-pic files"), |
5411 | ibfd); | |
c43c2cc5 JW |
5412 | |
5413 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 5414 | ok = FALSE; |
c43c2cc5 | 5415 | } |
800eeca4 JW |
5416 | |
5417 | return ok; | |
5418 | } | |
5419 | ||
b34976b6 | 5420 | static bfd_boolean |
eae50df2 | 5421 | elfNN_ia64_print_private_bfd_data (bfd *abfd, PTR ptr) |
800eeca4 JW |
5422 | { |
5423 | FILE *file = (FILE *) ptr; | |
5424 | flagword flags = elf_elfheader (abfd)->e_flags; | |
5425 | ||
5426 | BFD_ASSERT (abfd != NULL && ptr != NULL); | |
5427 | ||
c43c2cc5 | 5428 | fprintf (file, "private flags = %s%s%s%s%s%s%s%s\n", |
800eeca4 JW |
5429 | (flags & EF_IA_64_TRAPNIL) ? "TRAPNIL, " : "", |
5430 | (flags & EF_IA_64_EXT) ? "EXT, " : "", | |
5431 | (flags & EF_IA_64_BE) ? "BE, " : "LE, ", | |
c43c2cc5 JW |
5432 | (flags & EF_IA_64_REDUCEDFP) ? "REDUCEDFP, " : "", |
5433 | (flags & EF_IA_64_CONS_GP) ? "CONS_GP, " : "", | |
5434 | (flags & EF_IA_64_NOFUNCDESC_CONS_GP) ? "NOFUNCDESC_CONS_GP, " : "", | |
5435 | (flags & EF_IA_64_ABSOLUTE) ? "ABSOLUTE, " : "", | |
800eeca4 | 5436 | (flags & EF_IA_64_ABI64) ? "ABI64" : "ABI32"); |
3e932841 | 5437 | |
800eeca4 | 5438 | _bfd_elf_print_private_bfd_data (abfd, ptr); |
b34976b6 | 5439 | return TRUE; |
800eeca4 | 5440 | } |
db6751f2 JJ |
5441 | |
5442 | static enum elf_reloc_type_class | |
eae50df2 | 5443 | elfNN_ia64_reloc_type_class (const Elf_Internal_Rela *rela) |
db6751f2 | 5444 | { |
f51e552e | 5445 | switch ((int) ELFNN_R_TYPE (rela->r_info)) |
db6751f2 JJ |
5446 | { |
5447 | case R_IA64_REL32MSB: | |
5448 | case R_IA64_REL32LSB: | |
5449 | case R_IA64_REL64MSB: | |
5450 | case R_IA64_REL64LSB: | |
5451 | return reloc_class_relative; | |
5452 | case R_IA64_IPLTMSB: | |
5453 | case R_IA64_IPLTLSB: | |
5454 | return reloc_class_plt; | |
5455 | case R_IA64_COPY: | |
5456 | return reloc_class_copy; | |
5457 | default: | |
5458 | return reloc_class_normal; | |
5459 | } | |
5460 | } | |
fcf12726 | 5461 | |
b35d266b | 5462 | static const struct bfd_elf_special_section elfNN_ia64_special_sections[] = |
2f89ff8d | 5463 | { |
0112cd26 NC |
5464 | { STRING_COMMA_LEN (".sbss"), -1, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT }, |
5465 | { STRING_COMMA_LEN (".sdata"), -1, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_IA_64_SHORT }, | |
5466 | { NULL, 0, 0, 0, 0 } | |
7f4d3958 L |
5467 | }; |
5468 | ||
da9f89d4 L |
5469 | static bfd_boolean |
5470 | elfNN_ia64_object_p (bfd *abfd) | |
5471 | { | |
5472 | asection *sec; | |
da9f89d4 L |
5473 | asection *group, *unwi, *unw; |
5474 | flagword flags; | |
5475 | const char *name; | |
5476 | char *unwi_name, *unw_name; | |
5477 | bfd_size_type amt; | |
5478 | ||
5479 | if (abfd->flags & DYNAMIC) | |
5480 | return TRUE; | |
5481 | ||
5482 | /* Flags for fake group section. */ | |
5483 | flags = (SEC_LINKER_CREATED | SEC_GROUP | SEC_LINK_ONCE | |
5484 | | SEC_EXCLUDE); | |
5485 | ||
5486 | /* We add a fake section group for each .gnu.linkonce.t.* section, | |
5487 | which isn't in a section group, and its unwind sections. */ | |
5488 | for (sec = abfd->sections; sec != NULL; sec = sec->next) | |
5489 | { | |
5490 | if (elf_sec_group (sec) == NULL | |
5491 | && ((sec->flags & (SEC_LINK_ONCE | SEC_CODE | SEC_GROUP)) | |
5492 | == (SEC_LINK_ONCE | SEC_CODE)) | |
0112cd26 | 5493 | && CONST_STRNEQ (sec->name, ".gnu.linkonce.t.")) |
da9f89d4 L |
5494 | { |
5495 | name = sec->name + 16; | |
5496 | ||
5497 | amt = strlen (name) + sizeof (".gnu.linkonce.ia64unwi."); | |
5498 | unwi_name = bfd_alloc (abfd, amt); | |
5499 | if (!unwi_name) | |
5500 | return FALSE; | |
5501 | ||
5502 | strcpy (stpcpy (unwi_name, ".gnu.linkonce.ia64unwi."), name); | |
5503 | unwi = bfd_get_section_by_name (abfd, unwi_name); | |
5504 | ||
5505 | amt = strlen (name) + sizeof (".gnu.linkonce.ia64unw."); | |
5506 | unw_name = bfd_alloc (abfd, amt); | |
5507 | if (!unw_name) | |
5508 | return FALSE; | |
5509 | ||
5510 | strcpy (stpcpy (unw_name, ".gnu.linkonce.ia64unw."), name); | |
5511 | unw = bfd_get_section_by_name (abfd, unw_name); | |
5512 | ||
da9f89d4 L |
5513 | /* We need to create a fake group section for it and its |
5514 | unwind sections. */ | |
3496cb2a L |
5515 | group = bfd_make_section_anyway_with_flags (abfd, name, |
5516 | flags); | |
5517 | if (group == NULL) | |
da9f89d4 L |
5518 | return FALSE; |
5519 | ||
5520 | /* Move the fake group section to the beginning. */ | |
5daa8fe7 | 5521 | bfd_section_list_remove (abfd, group); |
04dd1667 | 5522 | bfd_section_list_prepend (abfd, group); |
da9f89d4 L |
5523 | |
5524 | elf_next_in_group (group) = sec; | |
5525 | ||
5526 | elf_group_name (sec) = name; | |
5527 | elf_next_in_group (sec) = sec; | |
5528 | elf_sec_group (sec) = group; | |
5529 | ||
5530 | if (unwi) | |
5531 | { | |
5532 | elf_group_name (unwi) = name; | |
5533 | elf_next_in_group (unwi) = sec; | |
5534 | elf_next_in_group (sec) = unwi; | |
5535 | elf_sec_group (unwi) = group; | |
5536 | } | |
5537 | ||
5538 | if (unw) | |
5539 | { | |
5540 | elf_group_name (unw) = name; | |
5541 | if (unwi) | |
5542 | { | |
5543 | elf_next_in_group (unw) = elf_next_in_group (unwi); | |
5544 | elf_next_in_group (unwi) = unw; | |
5545 | } | |
5546 | else | |
5547 | { | |
5548 | elf_next_in_group (unw) = sec; | |
5549 | elf_next_in_group (sec) = unw; | |
5550 | } | |
5551 | elf_sec_group (unw) = group; | |
5552 | } | |
5553 | ||
5554 | /* Fake SHT_GROUP section header. */ | |
5555 | elf_section_data (group)->this_hdr.bfd_section = group; | |
5556 | elf_section_data (group)->this_hdr.sh_type = SHT_GROUP; | |
5557 | } | |
5558 | } | |
5559 | return TRUE; | |
5560 | } | |
5561 | ||
b34976b6 | 5562 | static bfd_boolean |
d9cf1b54 AM |
5563 | elfNN_ia64_hpux_vec (const bfd_target *vec) |
5564 | { | |
5565 | extern const bfd_target bfd_elfNN_ia64_hpux_big_vec; | |
5566 | return (vec == & bfd_elfNN_ia64_hpux_big_vec); | |
5567 | } | |
5568 | ||
fcf12726 | 5569 | static void |
eae50df2 L |
5570 | elfNN_hpux_post_process_headers (bfd *abfd, |
5571 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
fcf12726 AM |
5572 | { |
5573 | Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd); | |
5574 | ||
d1036acb | 5575 | i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi; |
fcf12726 AM |
5576 | i_ehdrp->e_ident[EI_ABIVERSION] = 1; |
5577 | } | |
d9cf1b54 | 5578 | |
eae50df2 L |
5579 | static bfd_boolean |
5580 | elfNN_hpux_backend_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED, | |
5581 | asection *sec, int *retval) | |
d9cf1b54 AM |
5582 | { |
5583 | if (bfd_is_com_section (sec)) | |
5584 | { | |
5585 | *retval = SHN_IA_64_ANSI_COMMON; | |
b34976b6 | 5586 | return TRUE; |
d9cf1b54 | 5587 | } |
b34976b6 | 5588 | return FALSE; |
d9cf1b54 | 5589 | } |
b59dd4a5 L |
5590 | |
5591 | static void | |
5592 | elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, | |
5593 | asymbol *asym) | |
5594 | { | |
5f1cb353 | 5595 | elf_symbol_type *elfsym = (elf_symbol_type *) asym; |
b59dd4a5 L |
5596 | |
5597 | switch (elfsym->internal_elf_sym.st_shndx) | |
5598 | { | |
5599 | case SHN_IA_64_ANSI_COMMON: | |
5600 | asym->section = bfd_com_section_ptr; | |
5601 | asym->value = elfsym->internal_elf_sym.st_size; | |
5602 | asym->flags &= ~BSF_GLOBAL; | |
5603 | break; | |
5604 | } | |
5605 | } | |
5606 | ||
01e1a5bc NC |
5607 | static bfd_boolean |
5608 | elfNN_vms_section_from_shdr (bfd *abfd, | |
5609 | Elf_Internal_Shdr *hdr, | |
5610 | const char *name, | |
5611 | int shindex) | |
5612 | { | |
5613 | asection *newsect; | |
5614 | ||
5615 | switch (hdr->sh_type) | |
5616 | { | |
5617 | case SHT_IA_64_VMS_TRACE: | |
5618 | case SHT_IA_64_VMS_DEBUG: | |
5619 | case SHT_IA_64_VMS_DEBUG_STR: | |
5620 | break; | |
5621 | ||
5622 | default: | |
5623 | return elfNN_ia64_section_from_shdr (abfd, hdr, name, shindex); | |
5624 | } | |
5625 | ||
5626 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) | |
5627 | return FALSE; | |
5628 | newsect = hdr->bfd_section; | |
5629 | ||
5630 | return TRUE; | |
5631 | } | |
5632 | ||
5633 | static bfd_boolean | |
5634 | elfNN_vms_object_p (bfd *abfd) | |
5635 | { | |
5636 | Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd); | |
5637 | Elf_Internal_Phdr *i_phdr = elf_tdata (abfd)->phdr; | |
5638 | unsigned int i; | |
5639 | unsigned int num_text = 0; | |
5640 | unsigned int num_data = 0; | |
5641 | unsigned int num_rodata = 0; | |
5642 | char name[16]; | |
5643 | ||
5644 | if (!elfNN_ia64_object_p (abfd)) | |
5645 | return FALSE; | |
5646 | ||
5647 | for (i = 0; i < i_ehdrp->e_phnum; i++, i_phdr++) | |
5648 | { | |
5649 | /* Is there a section for this segment? */ | |
5650 | bfd_vma base_vma = i_phdr->p_vaddr; | |
5651 | bfd_vma limit_vma = base_vma + i_phdr->p_filesz; | |
5652 | ||
5653 | if (i_phdr->p_type != PT_LOAD) | |
5654 | continue; | |
5655 | ||
5656 | again: | |
5657 | while (base_vma < limit_vma) | |
5658 | { | |
5659 | bfd_vma next_vma = limit_vma; | |
5660 | asection *nsec; | |
5661 | asection *sec; | |
5662 | flagword flags; | |
5663 | char *nname = NULL; | |
5664 | ||
5665 | /* Find a section covering base_vma. */ | |
5666 | for (sec = abfd->sections; sec != NULL; sec = sec->next) | |
5667 | { | |
5668 | if ((sec->flags & (SEC_ALLOC | SEC_LOAD)) == 0) | |
5669 | continue; | |
5670 | if (sec->vma <= base_vma && sec->vma + sec->size > base_vma) | |
5671 | { | |
5672 | base_vma = sec->vma + sec->size; | |
5673 | goto again; | |
5674 | } | |
5675 | if (sec->vma < next_vma && sec->vma + sec->size >= base_vma) | |
5676 | next_vma = sec->vma; | |
5677 | } | |
5678 | ||
5679 | /* No section covering [base_vma; next_vma). Create a fake one. */ | |
5680 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; | |
5681 | if (i_phdr->p_flags & PF_X) | |
5682 | { | |
5683 | flags |= SEC_CODE; | |
5684 | if (num_text++ == 0) | |
5685 | nname = ".text"; | |
5686 | else | |
5687 | sprintf (name, ".text$%u", num_text); | |
5688 | } | |
5689 | else if ((i_phdr->p_flags & (PF_R | PF_W)) == PF_R) | |
5690 | { | |
5691 | flags |= SEC_READONLY; | |
5692 | sprintf (name, ".rodata$%u", num_rodata++); | |
5693 | } | |
5694 | else | |
5695 | { | |
5696 | flags |= SEC_DATA; | |
5697 | sprintf (name, ".data$%u", num_data++); | |
5698 | } | |
5699 | ||
5700 | /* Allocate name. */ | |
5701 | if (nname == NULL) | |
5702 | { | |
5703 | size_t name_len = strlen (name) + 1; | |
5704 | nname = bfd_alloc (abfd, name_len); | |
5705 | if (nname == NULL) | |
5706 | return FALSE; | |
5707 | memcpy (nname, name, name_len); | |
5708 | } | |
5709 | ||
5710 | /* Create and fill new section. */ | |
5711 | nsec = bfd_make_section_anyway_with_flags (abfd, nname, flags); | |
5712 | if (nsec == NULL) | |
5713 | return FALSE; | |
5714 | nsec->vma = base_vma; | |
5715 | nsec->size = next_vma - base_vma; | |
5716 | nsec->filepos = i_phdr->p_offset + (base_vma - i_phdr->p_vaddr); | |
5717 | ||
5718 | base_vma = next_vma; | |
5719 | } | |
5720 | } | |
5721 | return TRUE; | |
5722 | } | |
5723 | ||
5724 | static void | |
5725 | elfNN_vms_post_process_headers (bfd *abfd, | |
5726 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
5727 | { | |
5728 | Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd); | |
5729 | ||
5730 | i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_OPENVMS; | |
5731 | i_ehdrp->e_ident[EI_ABIVERSION] = 2; | |
5732 | } | |
5733 | ||
5734 | static bfd_boolean | |
5735 | elfNN_vms_section_processing (bfd *abfd ATTRIBUTE_UNUSED, | |
5736 | Elf_Internal_Shdr *hdr) | |
5737 | { | |
5738 | if (hdr->bfd_section != NULL) | |
5739 | { | |
5740 | const char *name = bfd_get_section_name (abfd, hdr->bfd_section); | |
5741 | ||
5742 | if (strcmp (name, ".text") == 0) | |
5743 | hdr->sh_flags |= SHF_IA_64_VMS_SHARED; | |
5744 | else if ((strcmp (name, ".debug") == 0) | |
5745 | || (strcmp (name, ".debug_abbrev") == 0) | |
5746 | || (strcmp (name, ".debug_aranges") == 0) | |
5747 | || (strcmp (name, ".debug_frame") == 0) | |
5748 | || (strcmp (name, ".debug_info") == 0) | |
5749 | || (strcmp (name, ".debug_loc") == 0) | |
5750 | || (strcmp (name, ".debug_macinfo") == 0) | |
5751 | || (strcmp (name, ".debug_pubnames") == 0) | |
5752 | || (strcmp (name, ".debug_pubtypes") == 0)) | |
5753 | hdr->sh_type = SHT_IA_64_VMS_DEBUG; | |
5754 | else if ((strcmp (name, ".debug_line") == 0) | |
5755 | || (strcmp (name, ".debug_ranges") == 0)) | |
5756 | hdr->sh_type = SHT_IA_64_VMS_TRACE; | |
5757 | else if (strcmp (name, ".debug_str") == 0) | |
5758 | hdr->sh_type = SHT_IA_64_VMS_DEBUG_STR; | |
5759 | else if (strcmp (name, ".vms_display_name_info") == 0) | |
5760 | { | |
5761 | int idx, symcount; | |
5762 | asymbol **syms; | |
5763 | struct elf_obj_tdata *t = elf_tdata (abfd); | |
5764 | int buf[2]; | |
5765 | int demangler_sym_idx = -1; | |
5766 | ||
5767 | symcount = bfd_get_symcount (abfd); | |
5768 | syms = bfd_get_outsymbols (abfd); | |
5769 | for (idx = 0; idx < symcount; idx++) | |
5770 | { | |
5771 | asymbol *sym; | |
5772 | sym = syms[idx]; | |
5773 | if ((sym->flags & (BSF_DEBUGGING | BSF_DYNAMIC)) | |
5774 | && strchr (sym->name, '@') | |
5775 | && (strcmp (sym->section->name, BFD_ABS_SECTION_NAME) == 0)) | |
5776 | { | |
5777 | demangler_sym_idx = sym->udata.i; | |
5778 | break; | |
5779 | } | |
5780 | } | |
5781 | ||
5782 | hdr->sh_type = SHT_IA_64_VMS_DISPLAY_NAME_INFO; | |
5783 | hdr->sh_entsize = 4; | |
5784 | hdr->sh_addralign = 0; | |
5785 | hdr->sh_link = t->symtab_section; | |
5786 | ||
5787 | /* Find symtab index of demangler routine and stuff it in | |
5788 | the second long word of section data. */ | |
5789 | ||
5790 | if (demangler_sym_idx > -1) | |
5791 | { | |
5792 | bfd_seek (abfd, hdr->sh_offset, SEEK_SET); | |
5793 | bfd_bread (buf, hdr->sh_size, abfd); | |
5794 | buf [1] = demangler_sym_idx; | |
5795 | bfd_seek (abfd, hdr->sh_offset, SEEK_SET); | |
5796 | bfd_bwrite (buf, hdr->sh_size, abfd); | |
5797 | } | |
5798 | } | |
5799 | } | |
5800 | ||
5801 | return TRUE; | |
5802 | } | |
5803 | ||
5804 | /* The final processing done just before writing out a VMS IA-64 ELF | |
5805 | object file. */ | |
5806 | ||
5807 | static void | |
5808 | elfNN_vms_final_write_processing (bfd *abfd, | |
5809 | bfd_boolean linker ATTRIBUTE_UNUSED) | |
5810 | { | |
5811 | Elf_Internal_Shdr *hdr; | |
5812 | asection *s; | |
5813 | int unwind_info_sect_idx = 0; | |
5814 | ||
5815 | for (s = abfd->sections; s; s = s->next) | |
5816 | { | |
5817 | hdr = &elf_section_data (s)->this_hdr; | |
5818 | ||
5819 | if (strcmp (bfd_get_section_name (abfd, hdr->bfd_section), | |
5820 | ".IA_64.unwind_info") == 0) | |
5821 | unwind_info_sect_idx = elf_section_data (s)->this_idx; | |
5822 | ||
5823 | switch (hdr->sh_type) | |
5824 | { | |
5825 | case SHT_IA_64_UNWIND: | |
5826 | /* VMS requires sh_info to point to the unwind info section. */ | |
5827 | hdr->sh_info = unwind_info_sect_idx; | |
5828 | break; | |
5829 | } | |
5830 | } | |
5831 | ||
5832 | if (! elf_flags_init (abfd)) | |
5833 | { | |
5834 | unsigned long flags = 0; | |
5835 | ||
5836 | if (abfd->xvec->byteorder == BFD_ENDIAN_BIG) | |
5837 | flags |= EF_IA_64_BE; | |
5838 | if (bfd_get_mach (abfd) == bfd_mach_ia64_elf64) | |
5839 | flags |= EF_IA_64_ABI64; | |
5840 | ||
5841 | elf_elfheader(abfd)->e_flags = flags; | |
5842 | elf_flags_init (abfd) = TRUE; | |
5843 | } | |
5844 | } | |
5845 | ||
5846 | static bfd_boolean | |
5847 | elfNN_vms_close_and_cleanup (bfd *abfd) | |
5848 | { | |
5849 | if (bfd_get_format (abfd) == bfd_object) | |
5850 | { | |
5851 | long isize, irsize; | |
5852 | ||
5853 | if (elf_shstrtab (abfd) != NULL) | |
5854 | _bfd_elf_strtab_free (elf_shstrtab (abfd)); | |
5855 | ||
5856 | /* Pad to 8 byte boundary for IPF/VMS. */ | |
5857 | isize = bfd_get_size (abfd); | |
5858 | if ((irsize = isize/8*8) < isize) | |
5859 | { | |
5860 | int ishort = (irsize + 8) - isize; | |
5861 | bfd_seek (abfd, isize, SEEK_SET); | |
5862 | bfd_bwrite (bfd_zmalloc (ishort), ishort, abfd); | |
5863 | } | |
5864 | } | |
5865 | ||
5866 | return _bfd_generic_close_and_cleanup (abfd); | |
5867 | } | |
800eeca4 | 5868 | \f |
bbe66d08 JW |
5869 | #define TARGET_LITTLE_SYM bfd_elfNN_ia64_little_vec |
5870 | #define TARGET_LITTLE_NAME "elfNN-ia64-little" | |
5871 | #define TARGET_BIG_SYM bfd_elfNN_ia64_big_vec | |
5872 | #define TARGET_BIG_NAME "elfNN-ia64-big" | |
800eeca4 JW |
5873 | #define ELF_ARCH bfd_arch_ia64 |
5874 | #define ELF_MACHINE_CODE EM_IA_64 | |
5875 | #define ELF_MACHINE_ALT1 1999 /* EAS2.3 */ | |
5876 | #define ELF_MACHINE_ALT2 1998 /* EAS2.2 */ | |
5877 | #define ELF_MAXPAGESIZE 0x10000 /* 64KB */ | |
24718e3b | 5878 | #define ELF_COMMONPAGESIZE 0x4000 /* 16KB */ |
800eeca4 JW |
5879 | |
5880 | #define elf_backend_section_from_shdr \ | |
bbe66d08 | 5881 | elfNN_ia64_section_from_shdr |
fa152c49 | 5882 | #define elf_backend_section_flags \ |
bbe66d08 | 5883 | elfNN_ia64_section_flags |
800eeca4 | 5884 | #define elf_backend_fake_sections \ |
bbe66d08 | 5885 | elfNN_ia64_fake_sections |
81545d45 RH |
5886 | #define elf_backend_final_write_processing \ |
5887 | elfNN_ia64_final_write_processing | |
800eeca4 | 5888 | #define elf_backend_add_symbol_hook \ |
bbe66d08 | 5889 | elfNN_ia64_add_symbol_hook |
800eeca4 | 5890 | #define elf_backend_additional_program_headers \ |
bbe66d08 | 5891 | elfNN_ia64_additional_program_headers |
800eeca4 | 5892 | #define elf_backend_modify_segment_map \ |
bbe66d08 | 5893 | elfNN_ia64_modify_segment_map |
e36284ab AM |
5894 | #define elf_backend_modify_program_headers \ |
5895 | elfNN_ia64_modify_program_headers | |
800eeca4 | 5896 | #define elf_info_to_howto \ |
bbe66d08 | 5897 | elfNN_ia64_info_to_howto |
800eeca4 | 5898 | |
bbe66d08 JW |
5899 | #define bfd_elfNN_bfd_reloc_type_lookup \ |
5900 | elfNN_ia64_reloc_type_lookup | |
157090f7 AM |
5901 | #define bfd_elfNN_bfd_reloc_name_lookup \ |
5902 | elfNN_ia64_reloc_name_lookup | |
bbe66d08 JW |
5903 | #define bfd_elfNN_bfd_is_local_label_name \ |
5904 | elfNN_ia64_is_local_label_name | |
5905 | #define bfd_elfNN_bfd_relax_section \ | |
5906 | elfNN_ia64_relax_section | |
800eeca4 | 5907 | |
da9f89d4 L |
5908 | #define elf_backend_object_p \ |
5909 | elfNN_ia64_object_p | |
5910 | ||
800eeca4 | 5911 | /* Stuff for the BFD linker: */ |
bbe66d08 JW |
5912 | #define bfd_elfNN_bfd_link_hash_table_create \ |
5913 | elfNN_ia64_hash_table_create | |
0aa92b58 JJ |
5914 | #define bfd_elfNN_bfd_link_hash_table_free \ |
5915 | elfNN_ia64_hash_table_free | |
800eeca4 | 5916 | #define elf_backend_create_dynamic_sections \ |
bbe66d08 | 5917 | elfNN_ia64_create_dynamic_sections |
800eeca4 | 5918 | #define elf_backend_check_relocs \ |
bbe66d08 | 5919 | elfNN_ia64_check_relocs |
800eeca4 | 5920 | #define elf_backend_adjust_dynamic_symbol \ |
bbe66d08 | 5921 | elfNN_ia64_adjust_dynamic_symbol |
800eeca4 | 5922 | #define elf_backend_size_dynamic_sections \ |
bbe66d08 | 5923 | elfNN_ia64_size_dynamic_sections |
74541ad4 AM |
5924 | #define elf_backend_omit_section_dynsym \ |
5925 | ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true) | |
800eeca4 | 5926 | #define elf_backend_relocate_section \ |
bbe66d08 | 5927 | elfNN_ia64_relocate_section |
800eeca4 | 5928 | #define elf_backend_finish_dynamic_symbol \ |
bbe66d08 | 5929 | elfNN_ia64_finish_dynamic_symbol |
800eeca4 | 5930 | #define elf_backend_finish_dynamic_sections \ |
bbe66d08 JW |
5931 | elfNN_ia64_finish_dynamic_sections |
5932 | #define bfd_elfNN_bfd_final_link \ | |
5933 | elfNN_ia64_final_link | |
5934 | ||
bbe66d08 JW |
5935 | #define bfd_elfNN_bfd_merge_private_bfd_data \ |
5936 | elfNN_ia64_merge_private_bfd_data | |
5937 | #define bfd_elfNN_bfd_set_private_flags \ | |
5938 | elfNN_ia64_set_private_flags | |
5939 | #define bfd_elfNN_bfd_print_private_bfd_data \ | |
5940 | elfNN_ia64_print_private_bfd_data | |
800eeca4 JW |
5941 | |
5942 | #define elf_backend_plt_readonly 1 | |
5943 | #define elf_backend_want_plt_sym 0 | |
5944 | #define elf_backend_plt_alignment 5 | |
5945 | #define elf_backend_got_header_size 0 | |
800eeca4 JW |
5946 | #define elf_backend_want_got_plt 1 |
5947 | #define elf_backend_may_use_rel_p 1 | |
5948 | #define elf_backend_may_use_rela_p 1 | |
5949 | #define elf_backend_default_use_rela_p 1 | |
5950 | #define elf_backend_want_dynbss 0 | |
bbe66d08 JW |
5951 | #define elf_backend_copy_indirect_symbol elfNN_ia64_hash_copy_indirect |
5952 | #define elf_backend_hide_symbol elfNN_ia64_hash_hide_symbol | |
508c3946 | 5953 | #define elf_backend_fixup_symbol _bfd_elf_link_hash_fixup_symbol |
db6751f2 | 5954 | #define elf_backend_reloc_type_class elfNN_ia64_reloc_type_class |
b491616a | 5955 | #define elf_backend_rela_normal 1 |
29ef7005 | 5956 | #define elf_backend_special_sections elfNN_ia64_special_sections |
d4d2b80b | 5957 | #define elf_backend_default_execstack 0 |
800eeca4 | 5958 | |
185d09ad | 5959 | /* FIXME: PR 290: The Intel C compiler generates SHT_IA_64_UNWIND with |
e04bcc6d | 5960 | SHF_LINK_ORDER. But it doesn't set the sh_link or sh_info fields. |
185d09ad L |
5961 | We don't want to flood users with so many error messages. We turn |
5962 | off the warning for now. It will be turned on later when the Intel | |
5963 | compiler is fixed. */ | |
5964 | #define elf_backend_link_order_error_handler NULL | |
5965 | ||
bbe66d08 | 5966 | #include "elfNN-target.h" |
7b6dab7f | 5967 | |
fcf12726 AM |
5968 | /* HPUX-specific vectors. */ |
5969 | ||
5970 | #undef TARGET_LITTLE_SYM | |
5971 | #undef TARGET_LITTLE_NAME | |
5972 | #undef TARGET_BIG_SYM | |
5973 | #define TARGET_BIG_SYM bfd_elfNN_ia64_hpux_big_vec | |
5974 | #undef TARGET_BIG_NAME | |
5975 | #define TARGET_BIG_NAME "elfNN-ia64-hpux-big" | |
5976 | ||
254ed743 NC |
5977 | /* These are HP-UX specific functions. */ |
5978 | ||
fcf12726 AM |
5979 | #undef elf_backend_post_process_headers |
5980 | #define elf_backend_post_process_headers elfNN_hpux_post_process_headers | |
5981 | ||
d9cf1b54 AM |
5982 | #undef elf_backend_section_from_bfd_section |
5983 | #define elf_backend_section_from_bfd_section elfNN_hpux_backend_section_from_bfd_section | |
5984 | ||
b59dd4a5 L |
5985 | #undef elf_backend_symbol_processing |
5986 | #define elf_backend_symbol_processing elfNN_hpux_backend_symbol_processing | |
5987 | ||
5e8d7549 NC |
5988 | #undef elf_backend_want_p_paddr_set_to_zero |
5989 | #define elf_backend_want_p_paddr_set_to_zero 1 | |
5990 | ||
24718e3b | 5991 | #undef ELF_COMMONPAGESIZE |
d1036acb L |
5992 | #undef ELF_OSABI |
5993 | #define ELF_OSABI ELFOSABI_HPUX | |
fcf12726 AM |
5994 | |
5995 | #undef elfNN_bed | |
5996 | #define elfNN_bed elfNN_ia64_hpux_bed | |
5997 | ||
5998 | #include "elfNN-target.h" | |
5e8d7549 | 5999 | |
01e1a5bc NC |
6000 | /* VMS-specific vectors. */ |
6001 | ||
6002 | #undef TARGET_LITTLE_SYM | |
6003 | #define TARGET_LITTLE_SYM bfd_elfNN_ia64_vms_vec | |
6004 | #undef TARGET_LITTLE_NAME | |
6005 | #define TARGET_LITTLE_NAME "elfNN-ia64-vms" | |
6006 | #undef TARGET_BIG_SYM | |
6007 | #undef TARGET_BIG_NAME | |
6008 | ||
6009 | /* These are VMS specific functions. */ | |
6010 | ||
6011 | #undef elf_backend_object_p | |
6012 | #define elf_backend_object_p elfNN_vms_object_p | |
6013 | ||
6014 | #undef elf_backend_section_from_shdr | |
6015 | #define elf_backend_section_from_shdr elfNN_vms_section_from_shdr | |
6016 | ||
6017 | #undef elf_backend_post_process_headers | |
6018 | #define elf_backend_post_process_headers elfNN_vms_post_process_headers | |
6019 | ||
6020 | #undef elf_backend_section_processing | |
6021 | #define elf_backend_section_processing elfNN_vms_section_processing | |
6022 | ||
6023 | #undef elf_backend_final_write_processing | |
6024 | #define elf_backend_final_write_processing elfNN_vms_final_write_processing | |
6025 | ||
6026 | #undef bfd_elfNN_close_and_cleanup | |
6027 | #define bfd_elfNN_close_and_cleanup elfNN_vms_close_and_cleanup | |
6028 | ||
6029 | #undef elf_backend_section_from_bfd_section | |
6030 | ||
6031 | #undef elf_backend_symbol_processing | |
6032 | ||
5e8d7549 | 6033 | #undef elf_backend_want_p_paddr_set_to_zero |
01e1a5bc NC |
6034 | |
6035 | #undef ELF_MAXPAGESIZE | |
6036 | #define ELF_MAXPAGESIZE 0x10000 /* 64KB */ | |
6037 | ||
6038 | #undef elfNN_bed | |
6039 | #define elfNN_bed elfNN_ia64_vms_bed | |
6040 | ||
6041 | #include "elfNN-target.h" |