1 | /* SPARC-specific support for 64-bit ELF
|
---|
2 | Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
---|
3 | 2003 Free Software Foundation, Inc.
|
---|
4 |
|
---|
5 | This file is part of BFD, the Binary File Descriptor library.
|
---|
6 |
|
---|
7 | This program is free software; you can redistribute it and/or modify
|
---|
8 | it under the terms of the GNU General Public License as published by
|
---|
9 | the Free Software Foundation; either version 2 of the License, or
|
---|
10 | (at your option) any later version.
|
---|
11 |
|
---|
12 | This program is distributed in the hope that it will be useful,
|
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | GNU General Public License for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with this program; if not, write to the Free Software
|
---|
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
---|
20 |
|
---|
21 | #include "bfd.h"
|
---|
22 | #include "sysdep.h"
|
---|
23 | #include "libbfd.h"
|
---|
24 | #include "elf-bfd.h"
|
---|
25 | #include "opcode/sparc.h"
|
---|
26 |
|
---|
27 | /* This is defined if one wants to build upward compatible binaries
|
---|
28 | with the original sparc64-elf toolchain. The support is kept in for
|
---|
29 | now but is turned off by default. dje 970930 */
|
---|
30 | /*#define SPARC64_OLD_RELOCS*/
|
---|
31 |
|
---|
32 | #include "elf/sparc.h"
|
---|
33 |
|
---|
34 | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
|
---|
35 | #define MINUS_ONE (~ (bfd_vma) 0)
|
---|
36 |
|
---|
37 | static struct bfd_link_hash_table * sparc64_elf_bfd_link_hash_table_create
|
---|
38 | PARAMS ((bfd *));
|
---|
39 | static bfd_reloc_status_type init_insn_reloc
|
---|
40 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *,
|
---|
41 | bfd *, bfd_vma *, bfd_vma *));
|
---|
42 | static reloc_howto_type *sparc64_elf_reloc_type_lookup
|
---|
43 | PARAMS ((bfd *, bfd_reloc_code_real_type));
|
---|
44 | static void sparc64_elf_info_to_howto
|
---|
45 | PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
|
---|
46 |
|
---|
47 | static void sparc64_elf_build_plt
|
---|
48 | PARAMS ((bfd *, unsigned char *, int));
|
---|
49 | static bfd_vma sparc64_elf_plt_entry_offset
|
---|
50 | PARAMS ((bfd_vma));
|
---|
51 | static bfd_vma sparc64_elf_plt_ptr_offset
|
---|
52 | PARAMS ((bfd_vma, bfd_vma));
|
---|
53 |
|
---|
54 | static bfd_boolean sparc64_elf_check_relocs
|
---|
55 | PARAMS ((bfd *, struct bfd_link_info *, asection *sec,
|
---|
56 | const Elf_Internal_Rela *));
|
---|
57 | static bfd_boolean sparc64_elf_adjust_dynamic_symbol
|
---|
58 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
|
---|
59 | static bfd_boolean sparc64_elf_size_dynamic_sections
|
---|
60 | PARAMS ((bfd *, struct bfd_link_info *));
|
---|
61 | static int sparc64_elf_get_symbol_type
|
---|
62 | PARAMS (( Elf_Internal_Sym *, int));
|
---|
63 | static bfd_boolean sparc64_elf_add_symbol_hook
|
---|
64 | PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
|
---|
65 | const char **, flagword *, asection **, bfd_vma *));
|
---|
66 | static bfd_boolean sparc64_elf_output_arch_syms
|
---|
67 | PARAMS ((bfd *, struct bfd_link_info *, PTR,
|
---|
68 | bfd_boolean (*) (PTR, const char *, Elf_Internal_Sym *, asection *)));
|
---|
69 | static void sparc64_elf_symbol_processing
|
---|
70 | PARAMS ((bfd *, asymbol *));
|
---|
71 |
|
---|
72 | static bfd_boolean sparc64_elf_merge_private_bfd_data
|
---|
73 | PARAMS ((bfd *, bfd *));
|
---|
74 |
|
---|
75 | static bfd_boolean sparc64_elf_fake_sections
|
---|
76 | PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
|
---|
77 |
|
---|
78 | static const char *sparc64_elf_print_symbol_all
|
---|
79 | PARAMS ((bfd *, PTR, asymbol *));
|
---|
80 | static bfd_boolean sparc64_elf_new_section_hook
|
---|
81 | PARAMS ((bfd *, asection *));
|
---|
82 | static bfd_boolean sparc64_elf_relax_section
|
---|
83 | PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
|
---|
84 | static bfd_boolean sparc64_elf_relocate_section
|
---|
85 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
|
---|
86 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
|
---|
87 | static bfd_boolean sparc64_elf_finish_dynamic_symbol
|
---|
88 | PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
|
---|
89 | Elf_Internal_Sym *));
|
---|
90 | static bfd_boolean sparc64_elf_finish_dynamic_sections
|
---|
91 | PARAMS ((bfd *, struct bfd_link_info *));
|
---|
92 | static bfd_boolean sparc64_elf_object_p PARAMS ((bfd *));
|
---|
93 | static long sparc64_elf_get_reloc_upper_bound PARAMS ((bfd *, asection *));
|
---|
94 | static long sparc64_elf_get_dynamic_reloc_upper_bound PARAMS ((bfd *));
|
---|
95 | static bfd_boolean sparc64_elf_slurp_one_reloc_table
|
---|
96 | PARAMS ((bfd *, asection *, Elf_Internal_Shdr *, asymbol **, bfd_boolean));
|
---|
97 | static bfd_boolean sparc64_elf_slurp_reloc_table
|
---|
98 | PARAMS ((bfd *, asection *, asymbol **, bfd_boolean));
|
---|
99 | static long sparc64_elf_canonicalize_reloc
|
---|
100 | PARAMS ((bfd *, asection *, arelent **, asymbol **));
|
---|
101 | static long sparc64_elf_canonicalize_dynamic_reloc
|
---|
102 | PARAMS ((bfd *, arelent **, asymbol **));
|
---|
103 | static void sparc64_elf_write_relocs PARAMS ((bfd *, asection *, PTR));
|
---|
104 | static enum elf_reloc_type_class sparc64_elf_reloc_type_class
|
---|
105 | PARAMS ((const Elf_Internal_Rela *));
|
---|
106 | |
---|
107 |
|
---|
108 | /* The relocation "howto" table. */
|
---|
109 |
|
---|
110 | static bfd_reloc_status_type sparc_elf_notsup_reloc
|
---|
111 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
---|
112 | static bfd_reloc_status_type sparc_elf_wdisp16_reloc
|
---|
113 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
---|
114 | static bfd_reloc_status_type sparc_elf_hix22_reloc
|
---|
115 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
---|
116 | static bfd_reloc_status_type sparc_elf_lox10_reloc
|
---|
117 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
---|
118 |
|
---|
119 | static reloc_howto_type sparc64_elf_howto_table[] =
|
---|
120 | {
|
---|
121 | HOWTO(R_SPARC_NONE, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE),
|
---|
122 | HOWTO(R_SPARC_8, 0,0, 8,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_8", FALSE,0,0x000000ff,TRUE),
|
---|
123 | HOWTO(R_SPARC_16, 0,1,16,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_16", FALSE,0,0x0000ffff,TRUE),
|
---|
124 | HOWTO(R_SPARC_32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_32", FALSE,0,0xffffffff,TRUE),
|
---|
125 | HOWTO(R_SPARC_DISP8, 0,0, 8,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP8", FALSE,0,0x000000ff,TRUE),
|
---|
126 | HOWTO(R_SPARC_DISP16, 0,1,16,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP16", FALSE,0,0x0000ffff,TRUE),
|
---|
127 | HOWTO(R_SPARC_DISP32, 0,2,32,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP32", FALSE,0,0xffffffff,TRUE),
|
---|
128 | HOWTO(R_SPARC_WDISP30, 2,2,30,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP30", FALSE,0,0x3fffffff,TRUE),
|
---|
129 | HOWTO(R_SPARC_WDISP22, 2,2,22,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP22", FALSE,0,0x003fffff,TRUE),
|
---|
130 | HOWTO(R_SPARC_HI22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_HI22", FALSE,0,0x003fffff,TRUE),
|
---|
131 | HOWTO(R_SPARC_22, 0,2,22,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_22", FALSE,0,0x003fffff,TRUE),
|
---|
132 | HOWTO(R_SPARC_13, 0,2,13,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_13", FALSE,0,0x00001fff,TRUE),
|
---|
133 | HOWTO(R_SPARC_LO10, 0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_LO10", FALSE,0,0x000003ff,TRUE),
|
---|
134 | HOWTO(R_SPARC_GOT10, 0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT10", FALSE,0,0x000003ff,TRUE),
|
---|
135 | HOWTO(R_SPARC_GOT13, 0,2,13,FALSE,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_GOT13", FALSE,0,0x00001fff,TRUE),
|
---|
136 | HOWTO(R_SPARC_GOT22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT22", FALSE,0,0x003fffff,TRUE),
|
---|
137 | HOWTO(R_SPARC_PC10, 0,2,10,TRUE, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_PC10", FALSE,0,0x000003ff,TRUE),
|
---|
138 | HOWTO(R_SPARC_PC22, 10,2,22,TRUE, 0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PC22", FALSE,0,0x003fffff,TRUE),
|
---|
139 | HOWTO(R_SPARC_WPLT30, 2,2,30,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WPLT30", FALSE,0,0x3fffffff,TRUE),
|
---|
140 | HOWTO(R_SPARC_COPY, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_COPY", FALSE,0,0x00000000,TRUE),
|
---|
141 | HOWTO(R_SPARC_GLOB_DAT, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GLOB_DAT",FALSE,0,0x00000000,TRUE),
|
---|
142 | HOWTO(R_SPARC_JMP_SLOT, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_JMP_SLOT",FALSE,0,0x00000000,TRUE),
|
---|
143 | HOWTO(R_SPARC_RELATIVE, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_RELATIVE",FALSE,0,0x00000000,TRUE),
|
---|
144 | HOWTO(R_SPARC_UA32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA32", FALSE,0,0xffffffff,TRUE),
|
---|
145 | #ifndef SPARC64_OLD_RELOCS
|
---|
146 | HOWTO(R_SPARC_PLT32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PLT32", FALSE,0,0xffffffff,TRUE),
|
---|
147 | /* These aren't implemented yet. */
|
---|
148 | HOWTO(R_SPARC_HIPLT22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_HIPLT22", FALSE,0,0x00000000,TRUE),
|
---|
149 | HOWTO(R_SPARC_LOPLT10, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_LOPLT10", FALSE,0,0x00000000,TRUE),
|
---|
150 | HOWTO(R_SPARC_PCPLT32, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT32", FALSE,0,0x00000000,TRUE),
|
---|
151 | HOWTO(R_SPARC_PCPLT22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT22", FALSE,0,0x00000000,TRUE),
|
---|
152 | HOWTO(R_SPARC_PCPLT10, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT10", FALSE,0,0x00000000,TRUE),
|
---|
153 | #endif
|
---|
154 | HOWTO(R_SPARC_10, 0,2,10,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_10", FALSE,0,0x000003ff,TRUE),
|
---|
155 | HOWTO(R_SPARC_11, 0,2,11,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_11", FALSE,0,0x000007ff,TRUE),
|
---|
156 | HOWTO(R_SPARC_64, 0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_64", FALSE,0,MINUS_ONE, TRUE),
|
---|
157 | HOWTO(R_SPARC_OLO10, 0,2,13,FALSE,0,complain_overflow_signed, sparc_elf_notsup_reloc, "R_SPARC_OLO10", FALSE,0,0x00001fff,TRUE),
|
---|
158 | HOWTO(R_SPARC_HH22, 42,2,22,FALSE,0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_HH22", FALSE,0,0x003fffff,TRUE),
|
---|
159 | HOWTO(R_SPARC_HM10, 32,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_HM10", FALSE,0,0x000003ff,TRUE),
|
---|
160 | HOWTO(R_SPARC_LM22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_LM22", FALSE,0,0x003fffff,TRUE),
|
---|
161 | HOWTO(R_SPARC_PC_HH22, 42,2,22,TRUE, 0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_PC_HH22", FALSE,0,0x003fffff,TRUE),
|
---|
162 | HOWTO(R_SPARC_PC_HM10, 32,2,10,TRUE, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_PC_HM10", FALSE,0,0x000003ff,TRUE),
|
---|
163 | HOWTO(R_SPARC_PC_LM22, 10,2,22,TRUE, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_PC_LM22", FALSE,0,0x003fffff,TRUE),
|
---|
164 | HOWTO(R_SPARC_WDISP16, 2,2,16,TRUE, 0,complain_overflow_signed, sparc_elf_wdisp16_reloc,"R_SPARC_WDISP16", FALSE,0,0x00000000,TRUE),
|
---|
165 | HOWTO(R_SPARC_WDISP19, 2,2,19,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP19", FALSE,0,0x0007ffff,TRUE),
|
---|
166 | HOWTO(R_SPARC_UNUSED_42, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_UNUSED_42",FALSE,0,0x00000000,TRUE),
|
---|
167 | HOWTO(R_SPARC_7, 0,2, 7,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_7", FALSE,0,0x0000007f,TRUE),
|
---|
168 | HOWTO(R_SPARC_5, 0,2, 5,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_5", FALSE,0,0x0000001f,TRUE),
|
---|
169 | HOWTO(R_SPARC_6, 0,2, 6,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_6", FALSE,0,0x0000003f,TRUE),
|
---|
170 | HOWTO(R_SPARC_DISP64, 0,4,64,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP64", FALSE,0,MINUS_ONE, TRUE),
|
---|
171 | HOWTO(R_SPARC_PLT64, 0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PLT64", FALSE,0,MINUS_ONE, TRUE),
|
---|
172 | HOWTO(R_SPARC_HIX22, 0,4, 0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc, "R_SPARC_HIX22", FALSE,0,MINUS_ONE, FALSE),
|
---|
173 | HOWTO(R_SPARC_LOX10, 0,4, 0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_LOX10", FALSE,0,MINUS_ONE, FALSE),
|
---|
174 | HOWTO(R_SPARC_H44, 22,2,22,FALSE,0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_H44", FALSE,0,0x003fffff,FALSE),
|
---|
175 | HOWTO(R_SPARC_M44, 12,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_M44", FALSE,0,0x000003ff,FALSE),
|
---|
176 | HOWTO(R_SPARC_L44, 0,2,13,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_L44", FALSE,0,0x00000fff,FALSE),
|
---|
177 | HOWTO(R_SPARC_REGISTER, 0,4, 0,FALSE,0,complain_overflow_bitfield,sparc_elf_notsup_reloc, "R_SPARC_REGISTER",FALSE,0,MINUS_ONE, FALSE),
|
---|
178 | HOWTO(R_SPARC_UA64, 0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA64", FALSE,0,MINUS_ONE, TRUE),
|
---|
179 | HOWTO(R_SPARC_UA16, 0,1,16,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA16", FALSE,0,0x0000ffff,TRUE),
|
---|
180 | HOWTO(R_SPARC_TLS_GD_HI22,10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_HI22",FALSE,0,0x003fffff,TRUE),
|
---|
181 | HOWTO(R_SPARC_TLS_GD_LO10,0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_LO10",FALSE,0,0x000003ff,TRUE),
|
---|
182 | HOWTO(R_SPARC_TLS_GD_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_ADD",FALSE,0,0x00000000,TRUE),
|
---|
183 | HOWTO(R_SPARC_TLS_GD_CALL,2,2,30,TRUE,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_CALL",FALSE,0,0x3fffffff,TRUE),
|
---|
184 | HOWTO(R_SPARC_TLS_LDM_HI22,10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_HI22",FALSE,0,0x003fffff,TRUE),
|
---|
185 | HOWTO(R_SPARC_TLS_LDM_LO10,0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_LO10",FALSE,0,0x000003ff,TRUE),
|
---|
186 | HOWTO(R_SPARC_TLS_LDM_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_ADD",FALSE,0,0x00000000,TRUE),
|
---|
187 | HOWTO(R_SPARC_TLS_LDM_CALL,2,2,30,TRUE,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_CALL",FALSE,0,0x3fffffff,TRUE),
|
---|
188 | HOWTO(R_SPARC_TLS_LDO_HIX22,0,2,0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc,"R_SPARC_TLS_LDO_HIX22",FALSE,0,0x003fffff, FALSE),
|
---|
189 | HOWTO(R_SPARC_TLS_LDO_LOX10,0,2,0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_TLS_LDO_LOX10",FALSE,0,0x000003ff, FALSE),
|
---|
190 | HOWTO(R_SPARC_TLS_LDO_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDO_ADD",FALSE,0,0x00000000,TRUE),
|
---|
191 | HOWTO(R_SPARC_TLS_IE_HI22,10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_HI22",FALSE,0,0x003fffff,TRUE),
|
---|
192 | HOWTO(R_SPARC_TLS_IE_LO10,0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_LO10",FALSE,0,0x000003ff,TRUE),
|
---|
193 | HOWTO(R_SPARC_TLS_IE_LD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_LD",FALSE,0,0x00000000,TRUE),
|
---|
194 | HOWTO(R_SPARC_TLS_IE_LDX,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_LDX",FALSE,0,0x00000000,TRUE),
|
---|
195 | HOWTO(R_SPARC_TLS_IE_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_ADD",FALSE,0,0x00000000,TRUE),
|
---|
196 | HOWTO(R_SPARC_TLS_LE_HIX22,0,2,0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc, "R_SPARC_TLS_LE_HIX22",FALSE,0,0x003fffff, FALSE),
|
---|
197 | HOWTO(R_SPARC_TLS_LE_LOX10,0,2,0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_TLS_LE_LOX10",FALSE,0,0x000003ff, FALSE),
|
---|
198 | HOWTO(R_SPARC_TLS_DTPMOD32,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_DTPMOD32",FALSE,0,0x00000000,TRUE),
|
---|
199 | HOWTO(R_SPARC_TLS_DTPMOD64,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_DTPMOD64",FALSE,0,0x00000000,TRUE),
|
---|
200 | HOWTO(R_SPARC_TLS_DTPOFF32,0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_TLS_DTPOFF32",FALSE,0,0xffffffff,TRUE),
|
---|
201 | HOWTO(R_SPARC_TLS_DTPOFF64,0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_TLS_DTPOFF64",FALSE,0,MINUS_ONE,TRUE),
|
---|
202 | HOWTO(R_SPARC_TLS_TPOFF32,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_TPOFF32",FALSE,0,0x00000000,TRUE),
|
---|
203 | HOWTO(R_SPARC_TLS_TPOFF64,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_TPOFF64",FALSE,0,0x00000000,TRUE)
|
---|
204 | };
|
---|
205 |
|
---|
206 | struct elf_reloc_map {
|
---|
207 | bfd_reloc_code_real_type bfd_reloc_val;
|
---|
208 | unsigned char elf_reloc_val;
|
---|
209 | };
|
---|
210 |
|
---|
211 | static const struct elf_reloc_map sparc_reloc_map[] =
|
---|
212 | {
|
---|
213 | { BFD_RELOC_NONE, R_SPARC_NONE, },
|
---|
214 | { BFD_RELOC_16, R_SPARC_16, },
|
---|
215 | { BFD_RELOC_16_PCREL, R_SPARC_DISP16 },
|
---|
216 | { BFD_RELOC_8, R_SPARC_8 },
|
---|
217 | { BFD_RELOC_8_PCREL, R_SPARC_DISP8 },
|
---|
218 | { BFD_RELOC_CTOR, R_SPARC_64 },
|
---|
219 | { BFD_RELOC_32, R_SPARC_32 },
|
---|
220 | { BFD_RELOC_32_PCREL, R_SPARC_DISP32 },
|
---|
221 | { BFD_RELOC_HI22, R_SPARC_HI22 },
|
---|
222 | { BFD_RELOC_LO10, R_SPARC_LO10, },
|
---|
223 | { BFD_RELOC_32_PCREL_S2, R_SPARC_WDISP30 },
|
---|
224 | { BFD_RELOC_64_PCREL, R_SPARC_DISP64 },
|
---|
225 | { BFD_RELOC_SPARC22, R_SPARC_22 },
|
---|
226 | { BFD_RELOC_SPARC13, R_SPARC_13 },
|
---|
227 | { BFD_RELOC_SPARC_GOT10, R_SPARC_GOT10 },
|
---|
228 | { BFD_RELOC_SPARC_GOT13, R_SPARC_GOT13 },
|
---|
229 | { BFD_RELOC_SPARC_GOT22, R_SPARC_GOT22 },
|
---|
230 | { BFD_RELOC_SPARC_PC10, R_SPARC_PC10 },
|
---|
231 | { BFD_RELOC_SPARC_PC22, R_SPARC_PC22 },
|
---|
232 | { BFD_RELOC_SPARC_WPLT30, R_SPARC_WPLT30 },
|
---|
233 | { BFD_RELOC_SPARC_COPY, R_SPARC_COPY },
|
---|
234 | { BFD_RELOC_SPARC_GLOB_DAT, R_SPARC_GLOB_DAT },
|
---|
235 | { BFD_RELOC_SPARC_JMP_SLOT, R_SPARC_JMP_SLOT },
|
---|
236 | { BFD_RELOC_SPARC_RELATIVE, R_SPARC_RELATIVE },
|
---|
237 | { BFD_RELOC_SPARC_WDISP22, R_SPARC_WDISP22 },
|
---|
238 | { BFD_RELOC_SPARC_UA16, R_SPARC_UA16 },
|
---|
239 | { BFD_RELOC_SPARC_UA32, R_SPARC_UA32 },
|
---|
240 | { BFD_RELOC_SPARC_UA64, R_SPARC_UA64 },
|
---|
241 | { BFD_RELOC_SPARC_10, R_SPARC_10 },
|
---|
242 | { BFD_RELOC_SPARC_11, R_SPARC_11 },
|
---|
243 | { BFD_RELOC_SPARC_64, R_SPARC_64 },
|
---|
244 | { BFD_RELOC_SPARC_OLO10, R_SPARC_OLO10 },
|
---|
245 | { BFD_RELOC_SPARC_HH22, R_SPARC_HH22 },
|
---|
246 | { BFD_RELOC_SPARC_HM10, R_SPARC_HM10 },
|
---|
247 | { BFD_RELOC_SPARC_LM22, R_SPARC_LM22 },
|
---|
248 | { BFD_RELOC_SPARC_PC_HH22, R_SPARC_PC_HH22 },
|
---|
249 | { BFD_RELOC_SPARC_PC_HM10, R_SPARC_PC_HM10 },
|
---|
250 | { BFD_RELOC_SPARC_PC_LM22, R_SPARC_PC_LM22 },
|
---|
251 | { BFD_RELOC_SPARC_WDISP16, R_SPARC_WDISP16 },
|
---|
252 | { BFD_RELOC_SPARC_WDISP19, R_SPARC_WDISP19 },
|
---|
253 | { BFD_RELOC_SPARC_7, R_SPARC_7 },
|
---|
254 | { BFD_RELOC_SPARC_5, R_SPARC_5 },
|
---|
255 | { BFD_RELOC_SPARC_6, R_SPARC_6 },
|
---|
256 | { BFD_RELOC_SPARC_DISP64, R_SPARC_DISP64 },
|
---|
257 | { BFD_RELOC_SPARC_TLS_GD_HI22, R_SPARC_TLS_GD_HI22 },
|
---|
258 | { BFD_RELOC_SPARC_TLS_GD_LO10, R_SPARC_TLS_GD_LO10 },
|
---|
259 | { BFD_RELOC_SPARC_TLS_GD_ADD, R_SPARC_TLS_GD_ADD },
|
---|
260 | { BFD_RELOC_SPARC_TLS_GD_CALL, R_SPARC_TLS_GD_CALL },
|
---|
261 | { BFD_RELOC_SPARC_TLS_LDM_HI22, R_SPARC_TLS_LDM_HI22 },
|
---|
262 | { BFD_RELOC_SPARC_TLS_LDM_LO10, R_SPARC_TLS_LDM_LO10 },
|
---|
263 | { BFD_RELOC_SPARC_TLS_LDM_ADD, R_SPARC_TLS_LDM_ADD },
|
---|
264 | { BFD_RELOC_SPARC_TLS_LDM_CALL, R_SPARC_TLS_LDM_CALL },
|
---|
265 | { BFD_RELOC_SPARC_TLS_LDO_HIX22, R_SPARC_TLS_LDO_HIX22 },
|
---|
266 | { BFD_RELOC_SPARC_TLS_LDO_LOX10, R_SPARC_TLS_LDO_LOX10 },
|
---|
267 | { BFD_RELOC_SPARC_TLS_LDO_ADD, R_SPARC_TLS_LDO_ADD },
|
---|
268 | { BFD_RELOC_SPARC_TLS_IE_HI22, R_SPARC_TLS_IE_HI22 },
|
---|
269 | { BFD_RELOC_SPARC_TLS_IE_LO10, R_SPARC_TLS_IE_LO10 },
|
---|
270 | { BFD_RELOC_SPARC_TLS_IE_LD, R_SPARC_TLS_IE_LD },
|
---|
271 | { BFD_RELOC_SPARC_TLS_IE_LDX, R_SPARC_TLS_IE_LDX },
|
---|
272 | { BFD_RELOC_SPARC_TLS_IE_ADD, R_SPARC_TLS_IE_ADD },
|
---|
273 | { BFD_RELOC_SPARC_TLS_LE_HIX22, R_SPARC_TLS_LE_HIX22 },
|
---|
274 | { BFD_RELOC_SPARC_TLS_LE_LOX10, R_SPARC_TLS_LE_LOX10 },
|
---|
275 | { BFD_RELOC_SPARC_TLS_DTPMOD32, R_SPARC_TLS_DTPMOD32 },
|
---|
276 | { BFD_RELOC_SPARC_TLS_DTPMOD64, R_SPARC_TLS_DTPMOD64 },
|
---|
277 | { BFD_RELOC_SPARC_TLS_DTPOFF32, R_SPARC_TLS_DTPOFF32 },
|
---|
278 | { BFD_RELOC_SPARC_TLS_DTPOFF64, R_SPARC_TLS_DTPOFF64 },
|
---|
279 | { BFD_RELOC_SPARC_TLS_TPOFF32, R_SPARC_TLS_TPOFF32 },
|
---|
280 | { BFD_RELOC_SPARC_TLS_TPOFF64, R_SPARC_TLS_TPOFF64 },
|
---|
281 | #ifndef SPARC64_OLD_RELOCS
|
---|
282 | { BFD_RELOC_SPARC_PLT32, R_SPARC_PLT32 },
|
---|
283 | #endif
|
---|
284 | { BFD_RELOC_SPARC_PLT64, R_SPARC_PLT64 },
|
---|
285 | { BFD_RELOC_SPARC_HIX22, R_SPARC_HIX22 },
|
---|
286 | { BFD_RELOC_SPARC_LOX10, R_SPARC_LOX10 },
|
---|
287 | { BFD_RELOC_SPARC_H44, R_SPARC_H44 },
|
---|
288 | { BFD_RELOC_SPARC_M44, R_SPARC_M44 },
|
---|
289 | { BFD_RELOC_SPARC_L44, R_SPARC_L44 },
|
---|
290 | { BFD_RELOC_SPARC_REGISTER, R_SPARC_REGISTER }
|
---|
291 | };
|
---|
292 |
|
---|
293 | static reloc_howto_type *
|
---|
294 | sparc64_elf_reloc_type_lookup (abfd, code)
|
---|
295 | bfd *abfd ATTRIBUTE_UNUSED;
|
---|
296 | bfd_reloc_code_real_type code;
|
---|
297 | {
|
---|
298 | unsigned int i;
|
---|
299 | for (i = 0; i < sizeof (sparc_reloc_map) / sizeof (struct elf_reloc_map); i++)
|
---|
300 | {
|
---|
301 | if (sparc_reloc_map[i].bfd_reloc_val == code)
|
---|
302 | return &sparc64_elf_howto_table[(int) sparc_reloc_map[i].elf_reloc_val];
|
---|
303 | }
|
---|
304 | return 0;
|
---|
305 | }
|
---|
306 |
|
---|
307 | static void
|
---|
308 | sparc64_elf_info_to_howto (abfd, cache_ptr, dst)
|
---|
309 | bfd *abfd ATTRIBUTE_UNUSED;
|
---|
310 | arelent *cache_ptr;
|
---|
311 | Elf_Internal_Rela *dst;
|
---|
312 | {
|
---|
313 | BFD_ASSERT (ELF64_R_TYPE_ID (dst->r_info) < (unsigned int) R_SPARC_max_std);
|
---|
314 | cache_ptr->howto = &sparc64_elf_howto_table[ELF64_R_TYPE_ID (dst->r_info)];
|
---|
315 | }
|
---|
316 | |
---|
317 |
|
---|
318 | struct sparc64_elf_section_data
|
---|
319 | {
|
---|
320 | struct bfd_elf_section_data elf;
|
---|
321 | unsigned int do_relax, reloc_count;
|
---|
322 | };
|
---|
323 |
|
---|
324 | #define sec_do_relax(sec) \
|
---|
325 | ((struct sparc64_elf_section_data *) elf_section_data (sec))->do_relax
|
---|
326 | #define canon_reloc_count(sec) \
|
---|
327 | ((struct sparc64_elf_section_data *) elf_section_data (sec))->reloc_count
|
---|
328 |
|
---|
329 | /* Due to the way how we handle R_SPARC_OLO10, each entry in a SHT_RELA
|
---|
330 | section can represent up to two relocs, we must tell the user to allocate
|
---|
331 | more space. */
|
---|
332 |
|
---|
333 | static long
|
---|
334 | sparc64_elf_get_reloc_upper_bound (abfd, sec)
|
---|
335 | bfd *abfd ATTRIBUTE_UNUSED;
|
---|
336 | asection *sec;
|
---|
337 | {
|
---|
338 | return (sec->reloc_count * 2 + 1) * sizeof (arelent *);
|
---|
339 | }
|
---|
340 |
|
---|
341 | static long
|
---|
342 | sparc64_elf_get_dynamic_reloc_upper_bound (abfd)
|
---|
343 | bfd *abfd;
|
---|
344 | {
|
---|
345 | return _bfd_elf_get_dynamic_reloc_upper_bound (abfd) * 2;
|
---|
346 | }
|
---|
347 |
|
---|
348 | /* Read relocations for ASECT from REL_HDR. There are RELOC_COUNT of
|
---|
349 | them. We cannot use generic elf routines for this, because R_SPARC_OLO10
|
---|
350 | has secondary addend in ELF64_R_TYPE_DATA. We handle it as two relocations
|
---|
351 | for the same location, R_SPARC_LO10 and R_SPARC_13. */
|
---|
352 |
|
---|
353 | static bfd_boolean
|
---|
354 | sparc64_elf_slurp_one_reloc_table (abfd, asect, rel_hdr, symbols, dynamic)
|
---|
355 | bfd *abfd;
|
---|
356 | asection *asect;
|
---|
357 | Elf_Internal_Shdr *rel_hdr;
|
---|
358 | asymbol **symbols;
|
---|
359 | bfd_boolean dynamic;
|
---|
360 | {
|
---|
361 | PTR allocated = NULL;
|
---|
362 | bfd_byte *native_relocs;
|
---|
363 | arelent *relent;
|
---|
364 | unsigned int i;
|
---|
365 | int entsize;
|
---|
366 | bfd_size_type count;
|
---|
367 | arelent *relents;
|
---|
368 |
|
---|
369 | allocated = (PTR) bfd_malloc (rel_hdr->sh_size);
|
---|
370 | if (allocated == NULL)
|
---|
371 | goto error_return;
|
---|
372 |
|
---|
373 | if (bfd_seek (abfd, rel_hdr->sh_offset, SEEK_SET) != 0
|
---|
374 | || bfd_bread (allocated, rel_hdr->sh_size, abfd) != rel_hdr->sh_size)
|
---|
375 | goto error_return;
|
---|
376 |
|
---|
377 | native_relocs = (bfd_byte *) allocated;
|
---|
378 |
|
---|
379 | relents = asect->relocation + canon_reloc_count (asect);
|
---|
380 |
|
---|
381 | entsize = rel_hdr->sh_entsize;
|
---|
382 | BFD_ASSERT (entsize == sizeof (Elf64_External_Rela));
|
---|
383 |
|
---|
384 | count = rel_hdr->sh_size / entsize;
|
---|
385 |
|
---|
386 | for (i = 0, relent = relents; i < count;
|
---|
387 | i++, relent++, native_relocs += entsize)
|
---|
388 | {
|
---|
389 | Elf_Internal_Rela rela;
|
---|
390 |
|
---|
391 | bfd_elf64_swap_reloca_in (abfd, native_relocs, &rela);
|
---|
392 |
|
---|
393 | /* The address of an ELF reloc is section relative for an object
|
---|
394 | file, and absolute for an executable file or shared library.
|
---|
395 | The address of a normal BFD reloc is always section relative,
|
---|
396 | and the address of a dynamic reloc is absolute.. */
|
---|
397 | if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0 || dynamic)
|
---|
398 | relent->address = rela.r_offset;
|
---|
399 | else
|
---|
400 | relent->address = rela.r_offset - asect->vma;
|
---|
401 |
|
---|
402 | if (ELF64_R_SYM (rela.r_info) == 0)
|
---|
403 | relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
|
---|
404 | else
|
---|
405 | {
|
---|
406 | asymbol **ps, *s;
|
---|
407 |
|
---|
408 | ps = symbols + ELF64_R_SYM (rela.r_info) - 1;
|
---|
409 | s = *ps;
|
---|
410 |
|
---|
411 | /* Canonicalize ELF section symbols. FIXME: Why? */
|
---|
412 | if ((s->flags & BSF_SECTION_SYM) == 0)
|
---|
413 | relent->sym_ptr_ptr = ps;
|
---|
414 | else
|
---|
415 | relent->sym_ptr_ptr = s->section->symbol_ptr_ptr;
|
---|
416 | }
|
---|
417 |
|
---|
418 | relent->addend = rela.r_addend;
|
---|
419 |
|
---|
420 | BFD_ASSERT (ELF64_R_TYPE_ID (rela.r_info) < (unsigned int) R_SPARC_max_std);
|
---|
421 | if (ELF64_R_TYPE_ID (rela.r_info) == R_SPARC_OLO10)
|
---|
422 | {
|
---|
423 | relent->howto = &sparc64_elf_howto_table[R_SPARC_LO10];
|
---|
424 | relent[1].address = relent->address;
|
---|
425 | relent++;
|
---|
426 | relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
|
---|
427 | relent->addend = ELF64_R_TYPE_DATA (rela.r_info);
|
---|
428 | relent->howto = &sparc64_elf_howto_table[R_SPARC_13];
|
---|
429 | }
|
---|
430 | else
|
---|
431 | relent->howto = &sparc64_elf_howto_table[ELF64_R_TYPE_ID (rela.r_info)];
|
---|
432 | }
|
---|
433 |
|
---|
434 | canon_reloc_count (asect) += relent - relents;
|
---|
435 |
|
---|
436 | if (allocated != NULL)
|
---|
437 | free (allocated);
|
---|
438 |
|
---|
439 | return TRUE;
|
---|
440 |
|
---|
441 | error_return:
|
---|
442 | if (allocated != NULL)
|
---|
443 | free (allocated);
|
---|
444 | return FALSE;
|
---|
445 | }
|
---|
446 |
|
---|
447 | /* Read in and swap the external relocs. */
|
---|
448 |
|
---|
449 | static bfd_boolean
|
---|
450 | sparc64_elf_slurp_reloc_table (abfd, asect, symbols, dynamic)
|
---|
451 | bfd *abfd;
|
---|
452 | asection *asect;
|
---|
453 | asymbol **symbols;
|
---|
454 | bfd_boolean dynamic;
|
---|
455 | {
|
---|
456 | struct bfd_elf_section_data * const d = elf_section_data (asect);
|
---|
457 | Elf_Internal_Shdr *rel_hdr;
|
---|
458 | Elf_Internal_Shdr *rel_hdr2;
|
---|
459 | bfd_size_type amt;
|
---|
460 |
|
---|
461 | if (asect->relocation != NULL)
|
---|
462 | return TRUE;
|
---|
463 |
|
---|
464 | if (! dynamic)
|
---|
465 | {
|
---|
466 | if ((asect->flags & SEC_RELOC) == 0
|
---|
467 | || asect->reloc_count == 0)
|
---|
468 | return TRUE;
|
---|
469 |
|
---|
470 | rel_hdr = &d->rel_hdr;
|
---|
471 | rel_hdr2 = d->rel_hdr2;
|
---|
472 |
|
---|
473 | BFD_ASSERT (asect->rel_filepos == rel_hdr->sh_offset
|
---|
474 | || (rel_hdr2 && asect->rel_filepos == rel_hdr2->sh_offset));
|
---|
475 | }
|
---|
476 | else
|
---|
477 | {
|
---|
478 | /* Note that ASECT->RELOC_COUNT tends not to be accurate in this
|
---|
479 | case because relocations against this section may use the
|
---|
480 | dynamic symbol table, and in that case bfd_section_from_shdr
|
---|
481 | in elf.c does not update the RELOC_COUNT. */
|
---|
482 | if (asect->_raw_size == 0)
|
---|
483 | return TRUE;
|
---|
484 |
|
---|
485 | rel_hdr = &d->this_hdr;
|
---|
486 | asect->reloc_count = NUM_SHDR_ENTRIES (rel_hdr);
|
---|
487 | rel_hdr2 = NULL;
|
---|
488 | }
|
---|
489 |
|
---|
490 | amt = asect->reloc_count;
|
---|
491 | amt *= 2 * sizeof (arelent);
|
---|
492 | asect->relocation = (arelent *) bfd_alloc (abfd, amt);
|
---|
493 | if (asect->relocation == NULL)
|
---|
494 | return FALSE;
|
---|
495 |
|
---|
496 | /* The sparc64_elf_slurp_one_reloc_table routine increments
|
---|
497 | canon_reloc_count. */
|
---|
498 | canon_reloc_count (asect) = 0;
|
---|
499 |
|
---|
500 | if (!sparc64_elf_slurp_one_reloc_table (abfd, asect, rel_hdr, symbols,
|
---|
501 | dynamic))
|
---|
502 | return FALSE;
|
---|
503 |
|
---|
504 | if (rel_hdr2
|
---|
505 | && !sparc64_elf_slurp_one_reloc_table (abfd, asect, rel_hdr2, symbols,
|
---|
506 | dynamic))
|
---|
507 | return FALSE;
|
---|
508 |
|
---|
509 | return TRUE;
|
---|
510 | }
|
---|
511 |
|
---|
512 | /* Canonicalize the relocs. */
|
---|
513 |
|
---|
514 | static long
|
---|
515 | sparc64_elf_canonicalize_reloc (abfd, section, relptr, symbols)
|
---|
516 | bfd *abfd;
|
---|
517 | sec_ptr section;
|
---|
518 | arelent **relptr;
|
---|
519 | asymbol **symbols;
|
---|
520 | {
|
---|
521 | arelent *tblptr;
|
---|
522 | unsigned int i;
|
---|
523 | struct elf_backend_data *bed = get_elf_backend_data (abfd);
|
---|
524 |
|
---|
525 | if (! bed->s->slurp_reloc_table (abfd, section, symbols, FALSE))
|
---|
526 | return -1;
|
---|
527 |
|
---|
528 | tblptr = section->relocation;
|
---|
529 | for (i = 0; i < canon_reloc_count (section); i++)
|
---|
530 | *relptr++ = tblptr++;
|
---|
531 |
|
---|
532 | *relptr = NULL;
|
---|
533 |
|
---|
534 | return canon_reloc_count (section);
|
---|
535 | }
|
---|
536 |
|
---|
537 |
|
---|
538 | /* Canonicalize the dynamic relocation entries. Note that we return
|
---|
539 | the dynamic relocations as a single block, although they are
|
---|
540 | actually associated with particular sections; the interface, which
|
---|
541 | was designed for SunOS style shared libraries, expects that there
|
---|
542 | is only one set of dynamic relocs. Any section that was actually
|
---|
543 | installed in the BFD, and has type SHT_REL or SHT_RELA, and uses
|
---|
544 | the dynamic symbol table, is considered to be a dynamic reloc
|
---|
545 | section. */
|
---|
546 |
|
---|
547 | static long
|
---|
548 | sparc64_elf_canonicalize_dynamic_reloc (abfd, storage, syms)
|
---|
549 | bfd *abfd;
|
---|
550 | arelent **storage;
|
---|
551 | asymbol **syms;
|
---|
552 | {
|
---|
553 | asection *s;
|
---|
554 | long ret;
|
---|
555 |
|
---|
556 | if (elf_dynsymtab (abfd) == 0)
|
---|
557 | {
|
---|
558 | bfd_set_error (bfd_error_invalid_operation);
|
---|
559 | return -1;
|
---|
560 | }
|
---|
561 |
|
---|
562 | ret = 0;
|
---|
563 | for (s = abfd->sections; s != NULL; s = s->next)
|
---|
564 | {
|
---|
565 | if (elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd)
|
---|
566 | && (elf_section_data (s)->this_hdr.sh_type == SHT_RELA))
|
---|
567 | {
|
---|
568 | arelent *p;
|
---|
569 | long count, i;
|
---|
570 |
|
---|
571 | if (! sparc64_elf_slurp_reloc_table (abfd, s, syms, TRUE))
|
---|
572 | return -1;
|
---|
573 | count = canon_reloc_count (s);
|
---|
574 | p = s->relocation;
|
---|
575 | for (i = 0; i < count; i++)
|
---|
576 | *storage++ = p++;
|
---|
577 | ret += count;
|
---|
578 | }
|
---|
579 | }
|
---|
580 |
|
---|
581 | *storage = NULL;
|
---|
582 |
|
---|
583 | return ret;
|
---|
584 | }
|
---|
585 |
|
---|
586 | /* Write out the relocs. */
|
---|
587 |
|
---|
588 | static void
|
---|
589 | sparc64_elf_write_relocs (abfd, sec, data)
|
---|
590 | bfd *abfd;
|
---|
591 | asection *sec;
|
---|
592 | PTR data;
|
---|
593 | {
|
---|
594 | bfd_boolean *failedp = (bfd_boolean *) data;
|
---|
595 | Elf_Internal_Shdr *rela_hdr;
|
---|
596 | Elf64_External_Rela *outbound_relocas, *src_rela;
|
---|
597 | unsigned int idx, count;
|
---|
598 | asymbol *last_sym = 0;
|
---|
599 | int last_sym_idx = 0;
|
---|
600 |
|
---|
601 | /* If we have already failed, don't do anything. */
|
---|
602 | if (*failedp)
|
---|
603 | return;
|
---|
604 |
|
---|
605 | if ((sec->flags & SEC_RELOC) == 0)
|
---|
606 | return;
|
---|
607 |
|
---|
608 | /* The linker backend writes the relocs out itself, and sets the
|
---|
609 | reloc_count field to zero to inhibit writing them here. Also,
|
---|
610 | sometimes the SEC_RELOC flag gets set even when there aren't any
|
---|
611 | relocs. */
|
---|
612 | if (sec->reloc_count == 0)
|
---|
613 | return;
|
---|
614 |
|
---|
615 | /* We can combine two relocs that refer to the same address
|
---|
616 | into R_SPARC_OLO10 if first one is R_SPARC_LO10 and the
|
---|
617 | latter is R_SPARC_13 with no associated symbol. */
|
---|
618 | count = 0;
|
---|
619 | for (idx = 0; idx < sec->reloc_count; idx++)
|
---|
620 | {
|
---|
621 | bfd_vma addr;
|
---|
622 |
|
---|
623 | ++count;
|
---|
624 |
|
---|
625 | addr = sec->orelocation[idx]->address;
|
---|
626 | if (sec->orelocation[idx]->howto->type == R_SPARC_LO10
|
---|
627 | && idx < sec->reloc_count - 1)
|
---|
628 | {
|
---|
629 | arelent *r = sec->orelocation[idx + 1];
|
---|
630 |
|
---|
631 | if (r->howto->type == R_SPARC_13
|
---|
632 | && r->address == addr
|
---|
633 | && bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
|
---|
634 | && (*r->sym_ptr_ptr)->value == 0)
|
---|
635 | ++idx;
|
---|
636 | }
|
---|
637 | }
|
---|
638 |
|
---|
639 | rela_hdr = &elf_section_data (sec)->rel_hdr;
|
---|
640 |
|
---|
641 | rela_hdr->sh_size = rela_hdr->sh_entsize * count;
|
---|
642 | rela_hdr->contents = (PTR) bfd_alloc (abfd, rela_hdr->sh_size);
|
---|
643 | if (rela_hdr->contents == NULL)
|
---|
644 | {
|
---|
645 | *failedp = TRUE;
|
---|
646 | return;
|
---|
647 | }
|
---|
648 |
|
---|
649 | /* Figure out whether the relocations are RELA or REL relocations. */
|
---|
650 | if (rela_hdr->sh_type != SHT_RELA)
|
---|
651 | abort ();
|
---|
652 |
|
---|
653 | /* orelocation has the data, reloc_count has the count... */
|
---|
654 | outbound_relocas = (Elf64_External_Rela *) rela_hdr->contents;
|
---|
655 | src_rela = outbound_relocas;
|
---|
656 |
|
---|
657 | for (idx = 0; idx < sec->reloc_count; idx++)
|
---|
658 | {
|
---|
659 | Elf_Internal_Rela dst_rela;
|
---|
660 | arelent *ptr;
|
---|
661 | asymbol *sym;
|
---|
662 | int n;
|
---|
663 |
|
---|
664 | ptr = sec->orelocation[idx];
|
---|
665 |
|
---|
666 | /* The address of an ELF reloc is section relative for an object
|
---|
667 | file, and absolute for an executable file or shared library.
|
---|
668 | The address of a BFD reloc is always section relative. */
|
---|
669 | if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0)
|
---|
670 | dst_rela.r_offset = ptr->address;
|
---|
671 | else
|
---|
672 | dst_rela.r_offset = ptr->address + sec->vma;
|
---|
673 |
|
---|
674 | sym = *ptr->sym_ptr_ptr;
|
---|
675 | if (sym == last_sym)
|
---|
676 | n = last_sym_idx;
|
---|
677 | else if (bfd_is_abs_section (sym->section) && sym->value == 0)
|
---|
678 | n = STN_UNDEF;
|
---|
679 | else
|
---|
680 | {
|
---|
681 | last_sym = sym;
|
---|
682 | n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym);
|
---|
683 | if (n < 0)
|
---|
684 | {
|
---|
685 | *failedp = TRUE;
|
---|
686 | return;
|
---|
687 | }
|
---|
688 | last_sym_idx = n;
|
---|
689 | }
|
---|
690 |
|
---|
691 | if ((*ptr->sym_ptr_ptr)->the_bfd != NULL
|
---|
692 | && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
|
---|
693 | && ! _bfd_elf_validate_reloc (abfd, ptr))
|
---|
694 | {
|
---|
695 | *failedp = TRUE;
|
---|
696 | return;
|
---|
697 | }
|
---|
698 |
|
---|
699 | if (ptr->howto->type == R_SPARC_LO10
|
---|
700 | && idx < sec->reloc_count - 1)
|
---|
701 | {
|
---|
702 | arelent *r = sec->orelocation[idx + 1];
|
---|
703 |
|
---|
704 | if (r->howto->type == R_SPARC_13
|
---|
705 | && r->address == ptr->address
|
---|
706 | && bfd_is_abs_section ((*r->sym_ptr_ptr)->section)
|
---|
707 | && (*r->sym_ptr_ptr)->value == 0)
|
---|
708 | {
|
---|
709 | idx++;
|
---|
710 | dst_rela.r_info
|
---|
711 | = ELF64_R_INFO (n, ELF64_R_TYPE_INFO (r->addend,
|
---|
712 | R_SPARC_OLO10));
|
---|
713 | }
|
---|
714 | else
|
---|
715 | dst_rela.r_info = ELF64_R_INFO (n, R_SPARC_LO10);
|
---|
716 | }
|
---|
717 | else
|
---|
718 | dst_rela.r_info = ELF64_R_INFO (n, ptr->howto->type);
|
---|
719 |
|
---|
720 | dst_rela.r_addend = ptr->addend;
|
---|
721 | bfd_elf64_swap_reloca_out (abfd, &dst_rela, (bfd_byte *) src_rela);
|
---|
722 | ++src_rela;
|
---|
723 | }
|
---|
724 | }
|
---|
725 | |
---|
726 |
|
---|
727 | /* Sparc64 ELF linker hash table. */
|
---|
728 |
|
---|
729 | struct sparc64_elf_app_reg
|
---|
730 | {
|
---|
731 | unsigned char bind;
|
---|
732 | unsigned short shndx;
|
---|
733 | bfd *abfd;
|
---|
734 | char *name;
|
---|
735 | };
|
---|
736 |
|
---|
737 | struct sparc64_elf_link_hash_table
|
---|
738 | {
|
---|
739 | struct elf_link_hash_table root;
|
---|
740 |
|
---|
741 | struct sparc64_elf_app_reg app_regs [4];
|
---|
742 | };
|
---|
743 |
|
---|
744 | /* Get the Sparc64 ELF linker hash table from a link_info structure. */
|
---|
745 |
|
---|
746 | #define sparc64_elf_hash_table(p) \
|
---|
747 | ((struct sparc64_elf_link_hash_table *) ((p)->hash))
|
---|
748 |
|
---|
749 | /* Create a Sparc64 ELF linker hash table. */
|
---|
750 |
|
---|
751 | static struct bfd_link_hash_table *
|
---|
752 | sparc64_elf_bfd_link_hash_table_create (abfd)
|
---|
753 | bfd *abfd;
|
---|
754 | {
|
---|
755 | struct sparc64_elf_link_hash_table *ret;
|
---|
756 | bfd_size_type amt = sizeof (struct sparc64_elf_link_hash_table);
|
---|
757 |
|
---|
758 | ret = (struct sparc64_elf_link_hash_table *) bfd_zmalloc (amt);
|
---|
759 | if (ret == (struct sparc64_elf_link_hash_table *) NULL)
|
---|
760 | return NULL;
|
---|
761 |
|
---|
762 | if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
|
---|
763 | _bfd_elf_link_hash_newfunc))
|
---|
764 | {
|
---|
765 | free (ret);
|
---|
766 | return NULL;
|
---|
767 | }
|
---|
768 |
|
---|
769 | return &ret->root.root;
|
---|
770 | }
|
---|
771 | |
---|
772 |
|
---|
773 | /* Utility for performing the standard initial work of an instruction
|
---|
774 | relocation.
|
---|
775 | *PRELOCATION will contain the relocated item.
|
---|
776 | *PINSN will contain the instruction from the input stream.
|
---|
777 | If the result is `bfd_reloc_other' the caller can continue with
|
---|
778 | performing the relocation. Otherwise it must stop and return the
|
---|
779 | value to its caller. */
|
---|
780 |
|
---|
781 | static bfd_reloc_status_type
|
---|
782 | init_insn_reloc (abfd,
|
---|
783 | reloc_entry,
|
---|
784 | symbol,
|
---|
785 | data,
|
---|
786 | input_section,
|
---|
787 | output_bfd,
|
---|
788 | prelocation,
|
---|
789 | pinsn)
|
---|
790 | bfd *abfd;
|
---|
791 | arelent *reloc_entry;
|
---|
792 | asymbol *symbol;
|
---|
793 | PTR data;
|
---|
794 | asection *input_section;
|
---|
795 | bfd *output_bfd;
|
---|
796 | bfd_vma *prelocation;
|
---|
797 | bfd_vma *pinsn;
|
---|
798 | {
|
---|
799 | bfd_vma relocation;
|
---|
800 | reloc_howto_type *howto = reloc_entry->howto;
|
---|
801 |
|
---|
802 | if (output_bfd != (bfd *) NULL
|
---|
803 | && (symbol->flags & BSF_SECTION_SYM) == 0
|
---|
804 | && (! howto->partial_inplace
|
---|
805 | || reloc_entry->addend == 0))
|
---|
806 | {
|
---|
807 | reloc_entry->address += input_section->output_offset;
|
---|
808 | return bfd_reloc_ok;
|
---|
809 | }
|
---|
810 |
|
---|
811 | /* This works because partial_inplace is FALSE. */
|
---|
812 | if (output_bfd != NULL)
|
---|
813 | return bfd_reloc_continue;
|
---|
814 |
|
---|
815 | if (reloc_entry->address > input_section->_cooked_size)
|
---|
816 | return bfd_reloc_outofrange;
|
---|
817 |
|
---|
818 | relocation = (symbol->value
|
---|
819 | + symbol->section->output_section->vma
|
---|
820 | + symbol->section->output_offset);
|
---|
821 | relocation += reloc_entry->addend;
|
---|
822 | if (howto->pc_relative)
|
---|
823 | {
|
---|
824 | relocation -= (input_section->output_section->vma
|
---|
825 | + input_section->output_offset);
|
---|
826 | relocation -= reloc_entry->address;
|
---|
827 | }
|
---|
828 |
|
---|
829 | *prelocation = relocation;
|
---|
830 | *pinsn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
|
---|
831 | return bfd_reloc_other;
|
---|
832 | }
|
---|
833 |
|
---|
834 | /* For unsupported relocs. */
|
---|
835 |
|
---|
836 | static bfd_reloc_status_type
|
---|
837 | sparc_elf_notsup_reloc (abfd,
|
---|
838 | reloc_entry,
|
---|
839 | symbol,
|
---|
840 | data,
|
---|
841 | input_section,
|
---|
842 | output_bfd,
|
---|
843 | error_message)
|
---|
844 | bfd *abfd ATTRIBUTE_UNUSED;
|
---|
845 | arelent *reloc_entry ATTRIBUTE_UNUSED;
|
---|
846 | asymbol *symbol ATTRIBUTE_UNUSED;
|
---|
847 | PTR data ATTRIBUTE_UNUSED;
|
---|
848 | asection *input_section ATTRIBUTE_UNUSED;
|
---|
849 | bfd *output_bfd ATTRIBUTE_UNUSED;
|
---|
850 | char **error_message ATTRIBUTE_UNUSED;
|
---|
851 | {
|
---|
852 | return bfd_reloc_notsupported;
|
---|
853 | }
|
---|
854 |
|
---|
855 | /* Handle the WDISP16 reloc. */
|
---|
856 |
|
---|
857 | static bfd_reloc_status_type
|
---|
858 | sparc_elf_wdisp16_reloc (abfd, reloc_entry, symbol, data, input_section,
|
---|
859 | output_bfd, error_message)
|
---|
860 | bfd *abfd;
|
---|
861 | arelent *reloc_entry;
|
---|
862 | asymbol *symbol;
|
---|
863 | PTR data;
|
---|
864 | asection *input_section;
|
---|
865 | bfd *output_bfd;
|
---|
866 | char **error_message ATTRIBUTE_UNUSED;
|
---|
867 | {
|
---|
868 | bfd_vma relocation;
|
---|
869 | bfd_vma insn;
|
---|
870 | bfd_reloc_status_type status;
|
---|
871 |
|
---|
872 | status = init_insn_reloc (abfd, reloc_entry, symbol, data,
|
---|
873 | input_section, output_bfd, &relocation, &insn);
|
---|
874 | if (status != bfd_reloc_other)
|
---|
875 | return status;
|
---|
876 |
|
---|
877 | insn &= ~ (bfd_vma) 0x303fff;
|
---|
878 | insn |= (((relocation >> 2) & 0xc000) << 6) | ((relocation >> 2) & 0x3fff);
|
---|
879 | bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
|
---|
880 |
|
---|
881 | if ((bfd_signed_vma) relocation < - 0x40000
|
---|
882 | || (bfd_signed_vma) relocation > 0x3ffff)
|
---|
883 | return bfd_reloc_overflow;
|
---|
884 | else
|
---|
885 | return bfd_reloc_ok;
|
---|
886 | }
|
---|
887 |
|
---|
888 | /* Handle the HIX22 reloc. */
|
---|
889 |
|
---|
890 | static bfd_reloc_status_type
|
---|
891 | sparc_elf_hix22_reloc (abfd,
|
---|
892 | reloc_entry,
|
---|
893 | symbol,
|
---|
894 | data,
|
---|
895 | input_section,
|
---|
896 | output_bfd,
|
---|
897 | error_message)
|
---|
898 | bfd *abfd;
|
---|
899 | arelent *reloc_entry;
|
---|
900 | asymbol *symbol;
|
---|
901 | PTR data;
|
---|
902 | asection *input_section;
|
---|
903 | bfd *output_bfd;
|
---|
904 | char **error_message ATTRIBUTE_UNUSED;
|
---|
905 | {
|
---|
906 | bfd_vma relocation;
|
---|
907 | bfd_vma insn;
|
---|
908 | bfd_reloc_status_type status;
|
---|
909 |
|
---|
910 | status = init_insn_reloc (abfd, reloc_entry, symbol, data,
|
---|
911 | input_section, output_bfd, &relocation, &insn);
|
---|
912 | if (status != bfd_reloc_other)
|
---|
913 | return status;
|
---|
914 |
|
---|
915 | relocation ^= MINUS_ONE;
|
---|
916 | insn = (insn &~ (bfd_vma) 0x3fffff) | ((relocation >> 10) & 0x3fffff);
|
---|
917 | bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
|
---|
918 |
|
---|
919 | if ((relocation & ~ (bfd_vma) 0xffffffff) != 0)
|
---|
920 | return bfd_reloc_overflow;
|
---|
921 | else
|
---|
922 | return bfd_reloc_ok;
|
---|
923 | }
|
---|
924 |
|
---|
925 | /* Handle the LOX10 reloc. */
|
---|
926 |
|
---|
927 | static bfd_reloc_status_type
|
---|
928 | sparc_elf_lox10_reloc (abfd,
|
---|
929 | reloc_entry,
|
---|
930 | symbol,
|
---|
931 | data,
|
---|
932 | input_section,
|
---|
933 | output_bfd,
|
---|
934 | error_message)
|
---|
935 | bfd *abfd;
|
---|
936 | arelent *reloc_entry;
|
---|
937 | asymbol *symbol;
|
---|
938 | PTR data;
|
---|
939 | asection *input_section;
|
---|
940 | bfd *output_bfd;
|
---|
941 | char **error_message ATTRIBUTE_UNUSED;
|
---|
942 | {
|
---|
943 | bfd_vma relocation;
|
---|
944 | bfd_vma insn;
|
---|
945 | bfd_reloc_status_type status;
|
---|
946 |
|
---|
947 | status = init_insn_reloc (abfd, reloc_entry, symbol, data,
|
---|
948 | input_section, output_bfd, &relocation, &insn);
|
---|
949 | if (status != bfd_reloc_other)
|
---|
950 | return status;
|
---|
951 |
|
---|
952 | insn = (insn &~ (bfd_vma) 0x1fff) | 0x1c00 | (relocation & 0x3ff);
|
---|
953 | bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
|
---|
954 |
|
---|
955 | return bfd_reloc_ok;
|
---|
956 | }
|
---|
957 | |
---|
958 |
|
---|
959 | /* PLT/GOT stuff */
|
---|
960 |
|
---|
961 | /* Both the headers and the entries are icache aligned. */
|
---|
962 | #define PLT_ENTRY_SIZE 32
|
---|
963 | #define PLT_HEADER_SIZE (4 * PLT_ENTRY_SIZE)
|
---|
964 | #define LARGE_PLT_THRESHOLD 32768
|
---|
965 | #define GOT_RESERVED_ENTRIES 1
|
---|
966 |
|
---|
967 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/sparcv9/ld.so.1"
|
---|
968 |
|
---|
969 | /* Fill in the .plt section. */
|
---|
970 |
|
---|
971 | static void
|
---|
972 | sparc64_elf_build_plt (output_bfd, contents, nentries)
|
---|
973 | bfd *output_bfd;
|
---|
974 | unsigned char *contents;
|
---|
975 | int nentries;
|
---|
976 | {
|
---|
977 | const unsigned int nop = 0x01000000;
|
---|
978 | int i, j;
|
---|
979 |
|
---|
980 | /* The first four entries are reserved, and are initially undefined.
|
---|
981 | We fill them with `illtrap 0' to force ld.so to do something. */
|
---|
982 |
|
---|
983 | for (i = 0; i < PLT_HEADER_SIZE/4; ++i)
|
---|
984 | bfd_put_32 (output_bfd, (bfd_vma) 0, contents+i*4);
|
---|
985 |
|
---|
986 | /* The first 32768 entries are close enough to plt1 to get there via
|
---|
987 | a straight branch. */
|
---|
988 |
|
---|
989 | for (i = 4; i < LARGE_PLT_THRESHOLD && i < nentries; ++i)
|
---|
990 | {
|
---|
991 | unsigned char *entry = contents + i * PLT_ENTRY_SIZE;
|
---|
992 | unsigned int sethi, ba;
|
---|
993 |
|
---|
994 | /* sethi (. - plt0), %g1 */
|
---|
995 | sethi = 0x03000000 | (i * PLT_ENTRY_SIZE);
|
---|
996 |
|
---|
997 | /* ba,a,pt %xcc, plt1 */
|
---|
998 | ba = 0x30680000 | (((contents+PLT_ENTRY_SIZE) - (entry+4)) / 4 & 0x7ffff);
|
---|
999 |
|
---|
1000 | bfd_put_32 (output_bfd, (bfd_vma) sethi, entry);
|
---|
1001 | bfd_put_32 (output_bfd, (bfd_vma) ba, entry + 4);
|
---|
1002 | bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 8);
|
---|
1003 | bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 12);
|
---|
1004 | bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 16);
|
---|
1005 | bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 20);
|
---|
1006 | bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 24);
|
---|
1007 | bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 28);
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | /* Now the tricky bit. Entries 32768 and higher are grouped in blocks of
|
---|
1011 | 160: 160 entries and 160 pointers. This is to separate code from data,
|
---|
1012 | which is much friendlier on the cache. */
|
---|
1013 |
|
---|
1014 | for (; i < nentries; i += 160)
|
---|
1015 | {
|
---|
1016 | int block = (i + 160 <= nentries ? 160 : nentries - i);
|
---|
1017 | for (j = 0; j < block; ++j)
|
---|
1018 | {
|
---|
1019 | unsigned char *entry, *ptr;
|
---|
1020 | unsigned int ldx;
|
---|
1021 |
|
---|
1022 | entry = contents + i*PLT_ENTRY_SIZE + j*4*6;
|
---|
1023 | ptr = contents + i*PLT_ENTRY_SIZE + block*4*6 + j*8;
|
---|
1024 |
|
---|
1025 | /* ldx [%o7 + ptr - (entry+4)], %g1 */
|
---|
1026 | ldx = 0xc25be000 | ((ptr - (entry+4)) & 0x1fff);
|
---|
1027 |
|
---|
1028 | /* mov %o7,%g5
|
---|
1029 | call .+8
|
---|
1030 | nop
|
---|
1031 | ldx [%o7+P],%g1
|
---|
1032 | jmpl %o7+%g1,%g1
|
---|
1033 | mov %g5,%o7 */
|
---|
1034 | bfd_put_32 (output_bfd, (bfd_vma) 0x8a10000f, entry);
|
---|
1035 | bfd_put_32 (output_bfd, (bfd_vma) 0x40000002, entry + 4);
|
---|
1036 | bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 8);
|
---|
1037 | bfd_put_32 (output_bfd, (bfd_vma) ldx, entry + 12);
|
---|
1038 | bfd_put_32 (output_bfd, (bfd_vma) 0x83c3c001, entry + 16);
|
---|
1039 | bfd_put_32 (output_bfd, (bfd_vma) 0x9e100005, entry + 20);
|
---|
1040 |
|
---|
1041 | bfd_put_64 (output_bfd, (bfd_vma) (contents - (entry + 4)), ptr);
|
---|
1042 | }
|
---|
1043 | }
|
---|
1044 | }
|
---|
1045 |
|
---|
1046 | /* Return the offset of a particular plt entry within the .plt section. */
|
---|
1047 |
|
---|
1048 | static bfd_vma
|
---|
1049 | sparc64_elf_plt_entry_offset (index)
|
---|
1050 | bfd_vma index;
|
---|
1051 | {
|
---|
1052 | bfd_vma block, ofs;
|
---|
1053 |
|
---|
1054 | if (index < LARGE_PLT_THRESHOLD)
|
---|
1055 | return index * PLT_ENTRY_SIZE;
|
---|
1056 |
|
---|
1057 | /* See above for details. */
|
---|
1058 |
|
---|
1059 | block = (index - LARGE_PLT_THRESHOLD) / 160;
|
---|
1060 | ofs = (index - LARGE_PLT_THRESHOLD) % 160;
|
---|
1061 |
|
---|
1062 | return (LARGE_PLT_THRESHOLD + block * 160) * PLT_ENTRY_SIZE + ofs * 6 * 4;
|
---|
1063 | }
|
---|
1064 |
|
---|
1065 | static bfd_vma
|
---|
1066 | sparc64_elf_plt_ptr_offset (index, max)
|
---|
1067 | bfd_vma index;
|
---|
1068 | bfd_vma max;
|
---|
1069 | {
|
---|
1070 | bfd_vma block, ofs, last;
|
---|
1071 |
|
---|
1072 | BFD_ASSERT(index >= LARGE_PLT_THRESHOLD);
|
---|
1073 |
|
---|
1074 | /* See above for details. */
|
---|
1075 |
|
---|
1076 | block = (((index - LARGE_PLT_THRESHOLD) / 160) * 160) + LARGE_PLT_THRESHOLD;
|
---|
1077 | ofs = index - block;
|
---|
1078 | if (block + 160 > max)
|
---|
1079 | last = (max - LARGE_PLT_THRESHOLD) % 160;
|
---|
1080 | else
|
---|
1081 | last = 160;
|
---|
1082 |
|
---|
1083 | return (block * PLT_ENTRY_SIZE
|
---|
1084 | + last * 6*4
|
---|
1085 | + ofs * 8);
|
---|
1086 | }
|
---|
1087 | |
---|
1088 |
|
---|
1089 | /* Look through the relocs for a section during the first phase, and
|
---|
1090 | allocate space in the global offset table or procedure linkage
|
---|
1091 | table. */
|
---|
1092 |
|
---|
1093 | static bfd_boolean
|
---|
1094 | sparc64_elf_check_relocs (abfd, info, sec, relocs)
|
---|
1095 | bfd *abfd;
|
---|
1096 | struct bfd_link_info *info;
|
---|
1097 | asection *sec;
|
---|
1098 | const Elf_Internal_Rela *relocs;
|
---|
1099 | {
|
---|
1100 | bfd *dynobj;
|
---|
1101 | Elf_Internal_Shdr *symtab_hdr;
|
---|
1102 | struct elf_link_hash_entry **sym_hashes;
|
---|
1103 | bfd_vma *local_got_offsets;
|
---|
1104 | const Elf_Internal_Rela *rel;
|
---|
1105 | const Elf_Internal_Rela *rel_end;
|
---|
1106 | asection *sgot;
|
---|
1107 | asection *srelgot;
|
---|
1108 | asection *sreloc;
|
---|
1109 |
|
---|
1110 | if (info->relocateable || !(sec->flags & SEC_ALLOC))
|
---|
1111 | return TRUE;
|
---|
1112 |
|
---|
1113 | dynobj = elf_hash_table (info)->dynobj;
|
---|
1114 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
|
---|
1115 | sym_hashes = elf_sym_hashes (abfd);
|
---|
1116 | local_got_offsets = elf_local_got_offsets (abfd);
|
---|
1117 |
|
---|
1118 | sgot = NULL;
|
---|
1119 | srelgot = NULL;
|
---|
1120 | sreloc = NULL;
|
---|
1121 |
|
---|
1122 | rel_end = relocs + NUM_SHDR_ENTRIES (& elf_section_data (sec)->rel_hdr);
|
---|
1123 | for (rel = relocs; rel < rel_end; rel++)
|
---|
1124 | {
|
---|
1125 | unsigned long r_symndx;
|
---|
1126 | struct elf_link_hash_entry *h;
|
---|
1127 |
|
---|
1128 | r_symndx = ELF64_R_SYM (rel->r_info);
|
---|
1129 | if (r_symndx < symtab_hdr->sh_info)
|
---|
1130 | h = NULL;
|
---|
1131 | else
|
---|
1132 | h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
---|
1133 |
|
---|
1134 | switch (ELF64_R_TYPE_ID (rel->r_info))
|
---|
1135 | {
|
---|
1136 | case R_SPARC_GOT10:
|
---|
1137 | case R_SPARC_GOT13:
|
---|
1138 | case R_SPARC_GOT22:
|
---|
1139 | /* This symbol requires a global offset table entry. */
|
---|
1140 |
|
---|
1141 | if (dynobj == NULL)
|
---|
1142 | {
|
---|
1143 | /* Create the .got section. */
|
---|
1144 | elf_hash_table (info)->dynobj = dynobj = abfd;
|
---|
1145 | if (! _bfd_elf_create_got_section (dynobj, info))
|
---|
1146 | return FALSE;
|
---|
1147 | }
|
---|
1148 |
|
---|
1149 | if (sgot == NULL)
|
---|
1150 | {
|
---|
1151 | sgot = bfd_get_section_by_name (dynobj, ".got");
|
---|
1152 | BFD_ASSERT (sgot != NULL);
|
---|
1153 | }
|
---|
1154 |
|
---|
1155 | if (srelgot == NULL && (h != NULL || info->shared))
|
---|
1156 | {
|
---|
1157 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
|
---|
1158 | if (srelgot == NULL)
|
---|
1159 | {
|
---|
1160 | srelgot = bfd_make_section (dynobj, ".rela.got");
|
---|
1161 | if (srelgot == NULL
|
---|
1162 | || ! bfd_set_section_flags (dynobj, srelgot,
|
---|
1163 | (SEC_ALLOC
|
---|
1164 | | SEC_LOAD
|
---|
1165 | | SEC_HAS_CONTENTS
|
---|
1166 | | SEC_IN_MEMORY
|
---|
1167 | | SEC_LINKER_CREATED
|
---|
1168 | | SEC_READONLY))
|
---|
1169 | || ! bfd_set_section_alignment (dynobj, srelgot, 3))
|
---|
1170 | return FALSE;
|
---|
1171 | }
|
---|
1172 | }
|
---|
1173 |
|
---|
1174 | if (h != NULL)
|
---|
1175 | {
|
---|
1176 | if (h->got.offset != (bfd_vma) -1)
|
---|
1177 | {
|
---|
1178 | /* We have already allocated space in the .got. */
|
---|
1179 | break;
|
---|
1180 | }
|
---|
1181 | h->got.offset = sgot->_raw_size;
|
---|
1182 |
|
---|
1183 | /* Make sure this symbol is output as a dynamic symbol. */
|
---|
1184 | if (h->dynindx == -1)
|
---|
1185 | {
|
---|
1186 | if (! bfd_elf64_link_record_dynamic_symbol (info, h))
|
---|
1187 | return FALSE;
|
---|
1188 | }
|
---|
1189 |
|
---|
1190 | srelgot->_raw_size += sizeof (Elf64_External_Rela);
|
---|
1191 | }
|
---|
1192 | else
|
---|
1193 | {
|
---|
1194 | /* This is a global offset table entry for a local
|
---|
1195 | symbol. */
|
---|
1196 | if (local_got_offsets == NULL)
|
---|
1197 | {
|
---|
1198 | bfd_size_type size;
|
---|
1199 | register unsigned int i;
|
---|
1200 |
|
---|
1201 | size = symtab_hdr->sh_info;
|
---|
1202 | size *= sizeof (bfd_vma);
|
---|
1203 | local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
|
---|
1204 | if (local_got_offsets == NULL)
|
---|
1205 | return FALSE;
|
---|
1206 | elf_local_got_offsets (abfd) = local_got_offsets;
|
---|
1207 | for (i = 0; i < symtab_hdr->sh_info; i++)
|
---|
1208 | local_got_offsets[i] = (bfd_vma) -1;
|
---|
1209 | }
|
---|
1210 | if (local_got_offsets[r_symndx] != (bfd_vma) -1)
|
---|
1211 | {
|
---|
1212 | /* We have already allocated space in the .got. */
|
---|
1213 | break;
|
---|
1214 | }
|
---|
1215 | local_got_offsets[r_symndx] = sgot->_raw_size;
|
---|
1216 |
|
---|
1217 | if (info->shared)
|
---|
1218 | {
|
---|
1219 | /* If we are generating a shared object, we need to
|
---|
1220 | output a R_SPARC_RELATIVE reloc so that the
|
---|
1221 | dynamic linker can adjust this GOT entry. */
|
---|
1222 | srelgot->_raw_size += sizeof (Elf64_External_Rela);
|
---|
1223 | }
|
---|
1224 | }
|
---|
1225 |
|
---|
1226 | sgot->_raw_size += 8;
|
---|
1227 |
|
---|
1228 | #if 0
|
---|
1229 | /* Doesn't work for 64-bit -fPIC, since sethi/or builds
|
---|
1230 | unsigned numbers. If we permit ourselves to modify
|
---|
1231 | code so we get sethi/xor, this could work.
|
---|
1232 | Question: do we consider conditionally re-enabling
|
---|
1233 | this for -fpic, once we know about object code models? */
|
---|
1234 | /* If the .got section is more than 0x1000 bytes, we add
|
---|
1235 | 0x1000 to the value of _GLOBAL_OFFSET_TABLE_, so that 13
|
---|
1236 | bit relocations have a greater chance of working. */
|
---|
1237 | if (sgot->_raw_size >= 0x1000
|
---|
1238 | && elf_hash_table (info)->hgot->root.u.def.value == 0)
|
---|
1239 | elf_hash_table (info)->hgot->root.u.def.value = 0x1000;
|
---|
1240 | #endif
|
---|
1241 |
|
---|
1242 | break;
|
---|
1243 |
|
---|
1244 | case R_SPARC_WPLT30:
|
---|
1245 | case R_SPARC_PLT32:
|
---|
1246 | case R_SPARC_HIPLT22:
|
---|
1247 | case R_SPARC_LOPLT10:
|
---|
1248 | case R_SPARC_PCPLT32:
|
---|
1249 | case R_SPARC_PCPLT22:
|
---|
1250 | case R_SPARC_PCPLT10:
|
---|
1251 | case R_SPARC_PLT64:
|
---|
1252 | /* This symbol requires a procedure linkage table entry. We
|
---|
1253 | actually build the entry in adjust_dynamic_symbol,
|
---|
1254 | because this might be a case of linking PIC code without
|
---|
1255 | linking in any dynamic objects, in which case we don't
|
---|
1256 | need to generate a procedure linkage table after all. */
|
---|
1257 |
|
---|
1258 | if (h == NULL)
|
---|
1259 | {
|
---|
1260 | /* It does not make sense to have a procedure linkage
|
---|
1261 | table entry for a local symbol. */
|
---|
1262 | bfd_set_error (bfd_error_bad_value);
|
---|
1263 | return FALSE;
|
---|
1264 | }
|
---|
1265 |
|
---|
1266 | /* Make sure this symbol is output as a dynamic symbol. */
|
---|
1267 | if (h->dynindx == -1)
|
---|
1268 | {
|
---|
1269 | if (! bfd_elf64_link_record_dynamic_symbol (info, h))
|
---|
1270 | return FALSE;
|
---|
1271 | }
|
---|
1272 |
|
---|
1273 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
|
---|
1274 | if (ELF64_R_TYPE_ID (rel->r_info) != R_SPARC_PLT32
|
---|
1275 | && ELF64_R_TYPE_ID (rel->r_info) != R_SPARC_PLT64)
|
---|
1276 | break;
|
---|
1277 | /* Fall through. */
|
---|
1278 | case R_SPARC_PC10:
|
---|
1279 | case R_SPARC_PC22:
|
---|
1280 | case R_SPARC_PC_HH22:
|
---|
1281 | case R_SPARC_PC_HM10:
|
---|
1282 | case R_SPARC_PC_LM22:
|
---|
1283 | if (h != NULL
|
---|
1284 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
|
---|
1285 | break;
|
---|
1286 | /* Fall through. */
|
---|
1287 | case R_SPARC_DISP8:
|
---|
1288 | case R_SPARC_DISP16:
|
---|
1289 | case R_SPARC_DISP32:
|
---|
1290 | case R_SPARC_DISP64:
|
---|
1291 | case R_SPARC_WDISP30:
|
---|
1292 | case R_SPARC_WDISP22:
|
---|
1293 | case R_SPARC_WDISP19:
|
---|
1294 | case R_SPARC_WDISP16:
|
---|
1295 | if (h == NULL)
|
---|
1296 | break;
|
---|
1297 | /* Fall through. */
|
---|
1298 | case R_SPARC_8:
|
---|
1299 | case R_SPARC_16:
|
---|
1300 | case R_SPARC_32:
|
---|
1301 | case R_SPARC_HI22:
|
---|
1302 | case R_SPARC_22:
|
---|
1303 | case R_SPARC_13:
|
---|
1304 | case R_SPARC_LO10:
|
---|
1305 | case R_SPARC_UA32:
|
---|
1306 | case R_SPARC_10:
|
---|
1307 | case R_SPARC_11:
|
---|
1308 | case R_SPARC_64:
|
---|
1309 | case R_SPARC_OLO10:
|
---|
1310 | case R_SPARC_HH22:
|
---|
1311 | case R_SPARC_HM10:
|
---|
1312 | case R_SPARC_LM22:
|
---|
1313 | case R_SPARC_7:
|
---|
1314 | case R_SPARC_5:
|
---|
1315 | case R_SPARC_6:
|
---|
1316 | case R_SPARC_HIX22:
|
---|
1317 | case R_SPARC_LOX10:
|
---|
1318 | case R_SPARC_H44:
|
---|
1319 | case R_SPARC_M44:
|
---|
1320 | case R_SPARC_L44:
|
---|
1321 | case R_SPARC_UA64:
|
---|
1322 | case R_SPARC_UA16:
|
---|
1323 | /* When creating a shared object, we must copy these relocs
|
---|
1324 | into the output file. We create a reloc section in
|
---|
1325 | dynobj and make room for the reloc.
|
---|
1326 |
|
---|
1327 | But don't do this for debugging sections -- this shows up
|
---|
1328 | with DWARF2 -- first because they are not loaded, and
|
---|
1329 | second because DWARF sez the debug info is not to be
|
---|
1330 | biased by the load address. */
|
---|
1331 | if (info->shared && (sec->flags & SEC_ALLOC))
|
---|
1332 | {
|
---|
1333 | if (sreloc == NULL)
|
---|
1334 | {
|
---|
1335 | const char *name;
|
---|
1336 |
|
---|
1337 | name = (bfd_elf_string_from_elf_section
|
---|
1338 | (abfd,
|
---|
1339 | elf_elfheader (abfd)->e_shstrndx,
|
---|
1340 | elf_section_data (sec)->rel_hdr.sh_name));
|
---|
1341 | if (name == NULL)
|
---|
1342 | return FALSE;
|
---|
1343 |
|
---|
1344 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0
|
---|
1345 | && strcmp (bfd_get_section_name (abfd, sec),
|
---|
1346 | name + 5) == 0);
|
---|
1347 |
|
---|
1348 | sreloc = bfd_get_section_by_name (dynobj, name);
|
---|
1349 | if (sreloc == NULL)
|
---|
1350 | {
|
---|
1351 | flagword flags;
|
---|
1352 |
|
---|
1353 | sreloc = bfd_make_section (dynobj, name);
|
---|
1354 | flags = (SEC_HAS_CONTENTS | SEC_READONLY
|
---|
1355 | | SEC_IN_MEMORY | SEC_LINKER_CREATED);
|
---|
1356 | if ((sec->flags & SEC_ALLOC) != 0)
|
---|
1357 | flags |= SEC_ALLOC | SEC_LOAD;
|
---|
1358 | if (sreloc == NULL
|
---|
1359 | || ! bfd_set_section_flags (dynobj, sreloc, flags)
|
---|
1360 | || ! bfd_set_section_alignment (dynobj, sreloc, 3))
|
---|
1361 | return FALSE;
|
---|
1362 | }
|
---|
1363 | if (sec->flags & SEC_READONLY)
|
---|
1364 | info->flags |= DF_TEXTREL;
|
---|
1365 | }
|
---|
1366 |
|
---|
1367 | sreloc->_raw_size += sizeof (Elf64_External_Rela);
|
---|
1368 | }
|
---|
1369 | break;
|
---|
1370 |
|
---|
1371 | case R_SPARC_REGISTER:
|
---|
1372 | /* Nothing to do. */
|
---|
1373 | break;
|
---|
1374 |
|
---|
1375 | default:
|
---|
1376 | (*_bfd_error_handler) (_("%s: check_relocs: unhandled reloc type %d"),
|
---|
1377 | bfd_archive_filename (abfd),
|
---|
1378 | ELF64_R_TYPE_ID (rel->r_info));
|
---|
1379 | return FALSE;
|
---|
1380 | }
|
---|
1381 | }
|
---|
1382 |
|
---|
1383 | return TRUE;
|
---|
1384 | }
|
---|
1385 |
|
---|
1386 | /* Hook called by the linker routine which adds symbols from an object
|
---|
1387 | file. We use it for STT_REGISTER symbols. */
|
---|
1388 |
|
---|
1389 | static bfd_boolean
|
---|
1390 | sparc64_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
|
---|
1391 | bfd *abfd;
|
---|
1392 | struct bfd_link_info *info;
|
---|
1393 | const Elf_Internal_Sym *sym;
|
---|
1394 | const char **namep;
|
---|
1395 | flagword *flagsp ATTRIBUTE_UNUSED;
|
---|
1396 | asection **secp ATTRIBUTE_UNUSED;
|
---|
1397 | bfd_vma *valp ATTRIBUTE_UNUSED;
|
---|
1398 | {
|
---|
1399 | static const char *const stt_types[] = { "NOTYPE", "OBJECT", "FUNCTION" };
|
---|
1400 |
|
---|
1401 | if (ELF_ST_TYPE (sym->st_info) == STT_REGISTER)
|
---|
1402 | {
|
---|
1403 | int reg;
|
---|
1404 | struct sparc64_elf_app_reg *p;
|
---|
1405 |
|
---|
1406 | reg = (int)sym->st_value;
|
---|
1407 | switch (reg & ~1)
|
---|
1408 | {
|
---|
1409 | case 2: reg -= 2; break;
|
---|
1410 | case 6: reg -= 4; break;
|
---|
1411 | default:
|
---|
1412 | (*_bfd_error_handler)
|
---|
1413 | (_("%s: Only registers %%g[2367] can be declared using STT_REGISTER"),
|
---|
1414 | bfd_archive_filename (abfd));
|
---|
1415 | return FALSE;
|
---|
1416 | }
|
---|
1417 |
|
---|
1418 | if (info->hash->creator != abfd->xvec
|
---|
1419 | || (abfd->flags & DYNAMIC) != 0)
|
---|
1420 | {
|
---|
1421 | /* STT_REGISTER only works when linking an elf64_sparc object.
|
---|
1422 | If STT_REGISTER comes from a dynamic object, don't put it into
|
---|
1423 | the output bfd. The dynamic linker will recheck it. */
|
---|
1424 | *namep = NULL;
|
---|
1425 | return TRUE;
|
---|
1426 | }
|
---|
1427 |
|
---|
1428 | p = sparc64_elf_hash_table(info)->app_regs + reg;
|
---|
1429 |
|
---|
1430 | if (p->name != NULL && strcmp (p->name, *namep))
|
---|
1431 | {
|
---|
1432 | (*_bfd_error_handler)
|
---|
1433 | (_("Register %%g%d used incompatibly: %s in %s, previously %s in %s"),
|
---|
1434 | (int) sym->st_value,
|
---|
1435 | **namep ? *namep : "#scratch", bfd_archive_filename (abfd),
|
---|
1436 | *p->name ? p->name : "#scratch", bfd_archive_filename (p->abfd));
|
---|
1437 | return FALSE;
|
---|
1438 | }
|
---|
1439 |
|
---|
1440 | if (p->name == NULL)
|
---|
1441 | {
|
---|
1442 | if (**namep)
|
---|
1443 | {
|
---|
1444 | struct elf_link_hash_entry *h;
|
---|
1445 |
|
---|
1446 | h = (struct elf_link_hash_entry *)
|
---|
1447 | bfd_link_hash_lookup (info->hash, *namep, FALSE, FALSE, FALSE);
|
---|
1448 |
|
---|
1449 | if (h != NULL)
|
---|
1450 | {
|
---|
1451 | unsigned char type = h->type;
|
---|
1452 |
|
---|
1453 | if (type > STT_FUNC)
|
---|
1454 | type = 0;
|
---|
1455 | (*_bfd_error_handler)
|
---|
1456 | (_("Symbol `%s' has differing types: REGISTER in %s, previously %s in %s"),
|
---|
1457 | *namep, bfd_archive_filename (abfd),
|
---|
1458 | stt_types[type], bfd_archive_filename (p->abfd));
|
---|
1459 | return FALSE;
|
---|
1460 | }
|
---|
1461 |
|
---|
1462 | p->name = bfd_hash_allocate (&info->hash->table,
|
---|
1463 | strlen (*namep) + 1);
|
---|
1464 | if (!p->name)
|
---|
1465 | return FALSE;
|
---|
1466 |
|
---|
1467 | strcpy (p->name, *namep);
|
---|
1468 | }
|
---|
1469 | else
|
---|
1470 | p->name = "";
|
---|
1471 | p->bind = ELF_ST_BIND (sym->st_info);
|
---|
1472 | p->abfd = abfd;
|
---|
1473 | p->shndx = sym->st_shndx;
|
---|
1474 | }
|
---|
1475 | else
|
---|
1476 | {
|
---|
1477 | if (p->bind == STB_WEAK
|
---|
1478 | && ELF_ST_BIND (sym->st_info) == STB_GLOBAL)
|
---|
1479 | {
|
---|
1480 | p->bind = STB_GLOBAL;
|
---|
1481 | p->abfd = abfd;
|
---|
1482 | }
|
---|
1483 | }
|
---|
1484 | *namep = NULL;
|
---|
1485 | return TRUE;
|
---|
1486 | }
|
---|
1487 | else if (*namep && **namep
|
---|
1488 | && info->hash->creator == abfd->xvec)
|
---|
1489 | {
|
---|
1490 | int i;
|
---|
1491 | struct sparc64_elf_app_reg *p;
|
---|
1492 |
|
---|
1493 | p = sparc64_elf_hash_table(info)->app_regs;
|
---|
1494 | for (i = 0; i < 4; i++, p++)
|
---|
1495 | if (p->name != NULL && ! strcmp (p->name, *namep))
|
---|
1496 | {
|
---|
1497 | unsigned char type = ELF_ST_TYPE (sym->st_info);
|
---|
1498 |
|
---|
1499 | if (type > STT_FUNC)
|
---|
1500 | type = 0;
|
---|
1501 | (*_bfd_error_handler)
|
---|
1502 | (_("Symbol `%s' has differing types: %s in %s, previously REGISTER in %s"),
|
---|
1503 | *namep, stt_types[type], bfd_archive_filename (abfd),
|
---|
1504 | bfd_archive_filename (p->abfd));
|
---|
1505 | return FALSE;
|
---|
1506 | }
|
---|
1507 | }
|
---|
1508 | return TRUE;
|
---|
1509 | }
|
---|
1510 |
|
---|
1511 | /* This function takes care of emiting STT_REGISTER symbols
|
---|
1512 | which we cannot easily keep in the symbol hash table. */
|
---|
1513 |
|
---|
1514 | static bfd_boolean
|
---|
1515 | sparc64_elf_output_arch_syms (output_bfd, info, finfo, func)
|
---|
1516 | bfd *output_bfd ATTRIBUTE_UNUSED;
|
---|
1517 | struct bfd_link_info *info;
|
---|
1518 | PTR finfo;
|
---|
1519 | bfd_boolean (*func)
|
---|
1520 | PARAMS ((PTR, const char *, Elf_Internal_Sym *, asection *));
|
---|
1521 | {
|
---|
1522 | int reg;
|
---|
1523 | struct sparc64_elf_app_reg *app_regs =
|
---|
1524 | sparc64_elf_hash_table(info)->app_regs;
|
---|
1525 | Elf_Internal_Sym sym;
|
---|
1526 |
|
---|
1527 | /* We arranged in size_dynamic_sections to put the STT_REGISTER entries
|
---|
1528 | at the end of the dynlocal list, so they came at the end of the local
|
---|
1529 | symbols in the symtab. Except that they aren't STB_LOCAL, so we need
|
---|
1530 | to back up symtab->sh_info. */
|
---|
1531 | if (elf_hash_table (info)->dynlocal)
|
---|
1532 | {
|
---|
1533 | bfd * dynobj = elf_hash_table (info)->dynobj;
|
---|
1534 | asection *dynsymsec = bfd_get_section_by_name (dynobj, ".dynsym");
|
---|
1535 | struct elf_link_local_dynamic_entry *e;
|
---|
1536 |
|
---|
1537 | for (e = elf_hash_table (info)->dynlocal; e ; e = e->next)
|
---|
1538 | if (e->input_indx == -1)
|
---|
1539 | break;
|
---|
1540 | if (e)
|
---|
1541 | {
|
---|
1542 | elf_section_data (dynsymsec->output_section)->this_hdr.sh_info
|
---|
1543 | = e->dynindx;
|
---|
1544 | }
|
---|
1545 | }
|
---|
1546 |
|
---|
1547 | if (info->strip == strip_all)
|
---|
1548 | return TRUE;
|
---|
1549 |
|
---|
1550 | for (reg = 0; reg < 4; reg++)
|
---|
1551 | if (app_regs [reg].name != NULL)
|
---|
1552 | {
|
---|
1553 | if (info->strip == strip_some
|
---|
1554 | && bfd_hash_lookup (info->keep_hash,
|
---|
1555 | app_regs [reg].name,
|
---|
1556 | FALSE, FALSE) == NULL)
|
---|
1557 | continue;
|
---|
1558 |
|
---|
1559 | sym.st_value = reg < 2 ? reg + 2 : reg + 4;
|
---|
1560 | sym.st_size = 0;
|
---|
1561 | sym.st_other = 0;
|
---|
1562 | sym.st_info = ELF_ST_INFO (app_regs [reg].bind, STT_REGISTER);
|
---|
1563 | sym.st_shndx = app_regs [reg].shndx;
|
---|
1564 | if (! (*func) (finfo, app_regs [reg].name, &sym,
|
---|
1565 | sym.st_shndx == SHN_ABS
|
---|
1566 | ? bfd_abs_section_ptr : bfd_und_section_ptr))
|
---|
1567 | return FALSE;
|
---|
1568 | }
|
---|
1569 |
|
---|
1570 | return TRUE;
|
---|
1571 | }
|
---|
1572 |
|
---|
1573 | static int
|
---|
1574 | sparc64_elf_get_symbol_type (elf_sym, type)
|
---|
1575 | Elf_Internal_Sym * elf_sym;
|
---|
1576 | int type;
|
---|
1577 | {
|
---|
1578 | if (ELF_ST_TYPE (elf_sym->st_info) == STT_REGISTER)
|
---|
1579 | return STT_REGISTER;
|
---|
1580 | else
|
---|
1581 | return type;
|
---|
1582 | }
|
---|
1583 |
|
---|
1584 | /* A STB_GLOBAL,STT_REGISTER symbol should be BSF_GLOBAL
|
---|
1585 | even in SHN_UNDEF section. */
|
---|
1586 |
|
---|
1587 | static void
|
---|
1588 | sparc64_elf_symbol_processing (abfd, asym)
|
---|
1589 | bfd *abfd ATTRIBUTE_UNUSED;
|
---|
1590 | asymbol *asym;
|
---|
1591 | {
|
---|
1592 | elf_symbol_type *elfsym;
|
---|
1593 |
|
---|
1594 | elfsym = (elf_symbol_type *) asym;
|
---|
1595 | if (elfsym->internal_elf_sym.st_info
|
---|
1596 | == ELF_ST_INFO (STB_GLOBAL, STT_REGISTER))
|
---|
1597 | {
|
---|
1598 | asym->flags |= BSF_GLOBAL;
|
---|
1599 | }
|
---|
1600 | }
|
---|
1601 |
|
---|
1602 | /* Adjust a symbol defined by a dynamic object and referenced by a
|
---|
1603 | regular object. The current definition is in some section of the
|
---|
1604 | dynamic object, but we're not including those sections. We have to
|
---|
1605 | change the definition to something the rest of the link can
|
---|
1606 | understand. */
|
---|
1607 |
|
---|
1608 | static bfd_boolean
|
---|
1609 | sparc64_elf_adjust_dynamic_symbol (info, h)
|
---|
1610 | struct bfd_link_info *info;
|
---|
1611 | struct elf_link_hash_entry *h;
|
---|
1612 | {
|
---|
1613 | bfd *dynobj;
|
---|
1614 | asection *s;
|
---|
1615 | unsigned int power_of_two;
|
---|
1616 |
|
---|
1617 | dynobj = elf_hash_table (info)->dynobj;
|
---|
1618 |
|
---|
1619 | /* Make sure we know what is going on here. */
|
---|
1620 | BFD_ASSERT (dynobj != NULL
|
---|
1621 | && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
|
---|
1622 | || h->weakdef != NULL
|
---|
1623 | || ((h->elf_link_hash_flags
|
---|
1624 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0
|
---|
1625 | && (h->elf_link_hash_flags
|
---|
1626 | & ELF_LINK_HASH_REF_REGULAR) != 0
|
---|
1627 | && (h->elf_link_hash_flags
|
---|
1628 | & ELF_LINK_HASH_DEF_REGULAR) == 0)));
|
---|
1629 |
|
---|
1630 | /* If this is a function, put it in the procedure linkage table. We
|
---|
1631 | will fill in the contents of the procedure linkage table later
|
---|
1632 | (although we could actually do it here). The STT_NOTYPE
|
---|
1633 | condition is a hack specifically for the Oracle libraries
|
---|
1634 | delivered for Solaris; for some inexplicable reason, they define
|
---|
1635 | some of their functions as STT_NOTYPE when they really should be
|
---|
1636 | STT_FUNC. */
|
---|
1637 | if (h->type == STT_FUNC
|
---|
1638 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0
|
---|
1639 | || (h->type == STT_NOTYPE
|
---|
1640 | && (h->root.type == bfd_link_hash_defined
|
---|
1641 | || h->root.type == bfd_link_hash_defweak)
|
---|
1642 | && (h->root.u.def.section->flags & SEC_CODE) != 0))
|
---|
1643 | {
|
---|
1644 | if (! elf_hash_table (info)->dynamic_sections_created)
|
---|
1645 | {
|
---|
1646 | /* This case can occur if we saw a WPLT30 reloc in an input
|
---|
1647 | file, but none of the input files were dynamic objects.
|
---|
1648 | In such a case, we don't actually need to build a
|
---|
1649 | procedure linkage table, and we can just do a WDISP30
|
---|
1650 | reloc instead. */
|
---|
1651 | BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
|
---|
1652 | return TRUE;
|
---|
1653 | }
|
---|
1654 |
|
---|
1655 | s = bfd_get_section_by_name (dynobj, ".plt");
|
---|
1656 | BFD_ASSERT (s != NULL);
|
---|
1657 |
|
---|
1658 | /* The first four bit in .plt is reserved. */
|
---|
1659 | if (s->_raw_size == 0)
|
---|
1660 | s->_raw_size = PLT_HEADER_SIZE;
|
---|
1661 |
|
---|
1662 | /* To simplify matters later, just store the plt index here. */
|
---|
1663 | h->plt.offset = s->_raw_size / PLT_ENTRY_SIZE;
|
---|
1664 |
|
---|
1665 | /* If this symbol is not defined in a regular file, and we are
|
---|
1666 | not generating a shared library, then set the symbol to this
|
---|
1667 | location in the .plt. This is required to make function
|
---|
1668 | pointers compare as equal between the normal executable and
|
---|
1669 | the shared library. */
|
---|
1670 | if (! info->shared
|
---|
1671 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
|
---|
1672 | {
|
---|
1673 | h->root.u.def.section = s;
|
---|
1674 | h->root.u.def.value = sparc64_elf_plt_entry_offset (h->plt.offset);
|
---|
1675 | }
|
---|
1676 |
|
---|
1677 | /* Make room for this entry. */
|
---|
1678 | s->_raw_size += PLT_ENTRY_SIZE;
|
---|
1679 |
|
---|
1680 | /* We also need to make an entry in the .rela.plt section. */
|
---|
1681 |
|
---|
1682 | s = bfd_get_section_by_name (dynobj, ".rela.plt");
|
---|
1683 | BFD_ASSERT (s != NULL);
|
---|
1684 |
|
---|
1685 | s->_raw_size += sizeof (Elf64_External_Rela);
|
---|
1686 |
|
---|
1687 | /* The procedure linkage table size is bounded by the magnitude
|
---|
1688 | of the offset we can describe in the entry. */
|
---|
1689 | if (s->_raw_size >= (bfd_vma)1 << 32)
|
---|
1690 | {
|
---|
1691 | bfd_set_error (bfd_error_bad_value);
|
---|
1692 | return FALSE;
|
---|
1693 | }
|
---|
1694 |
|
---|
1695 | return TRUE;
|
---|
1696 | }
|
---|
1697 |
|
---|
1698 | /* If this is a weak symbol, and there is a real definition, the
|
---|
1699 | processor independent code will have arranged for us to see the
|
---|
1700 | real definition first, and we can just use the same value. */
|
---|
1701 | if (h->weakdef != NULL)
|
---|
1702 | {
|
---|
1703 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
|
---|
1704 | || h->weakdef->root.type == bfd_link_hash_defweak);
|
---|
1705 | h->root.u.def.section = h->weakdef->root.u.def.section;
|
---|
1706 | h->root.u.def.value = h->weakdef->root.u.def.value;
|
---|
1707 | return TRUE;
|
---|
1708 | }
|
---|
1709 |
|
---|
1710 | /* This is a reference to a symbol defined by a dynamic object which
|
---|
1711 | is not a function. */
|
---|
1712 |
|
---|
1713 | /* If we are creating a shared library, we must presume that the
|
---|
1714 | only references to the symbol are via the global offset table.
|
---|
1715 | For such cases we need not do anything here; the relocations will
|
---|
1716 | be handled correctly by relocate_section. */
|
---|
1717 | if (info->shared)
|
---|
1718 | return TRUE;
|
---|
1719 |
|
---|
1720 | /* We must allocate the symbol in our .dynbss section, which will
|
---|
1721 | become part of the .bss section of the executable. There will be
|
---|
1722 | an entry for this symbol in the .dynsym section. The dynamic
|
---|
1723 | object will contain position independent code, so all references
|
---|
1724 | from the dynamic object to this symbol will go through the global
|
---|
1725 | offset table. The dynamic linker will use the .dynsym entry to
|
---|
1726 | determine the address it must put in the global offset table, so
|
---|
1727 | both the dynamic object and the regular object will refer to the
|
---|
1728 | same memory location for the variable. */
|
---|
1729 |
|
---|
1730 | s = bfd_get_section_by_name (dynobj, ".dynbss");
|
---|
1731 | BFD_ASSERT (s != NULL);
|
---|
1732 |
|
---|
1733 | /* We must generate a R_SPARC_COPY reloc to tell the dynamic linker
|
---|
1734 | to copy the initial value out of the dynamic object and into the
|
---|
1735 | runtime process image. We need to remember the offset into the
|
---|
1736 | .rel.bss section we are going to use. */
|
---|
1737 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
|
---|
1738 | {
|
---|
1739 | asection *srel;
|
---|
1740 |
|
---|
1741 | srel = bfd_get_section_by_name (dynobj, ".rela.bss");
|
---|
1742 | BFD_ASSERT (srel != NULL);
|
---|
1743 | srel->_raw_size += sizeof (Elf64_External_Rela);
|
---|
1744 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
|
---|
1745 | }
|
---|
1746 |
|
---|
1747 | /* We need to figure out the alignment required for this symbol. I
|
---|
1748 | have no idea how ELF linkers handle this. 16-bytes is the size
|
---|
1749 | of the largest type that requires hard alignment -- long double. */
|
---|
1750 | power_of_two = bfd_log2 (h->size);
|
---|
1751 | if (power_of_two > 4)
|
---|
1752 | power_of_two = 4;
|
---|
1753 |
|
---|
1754 | /* Apply the required alignment. */
|
---|
1755 | s->_raw_size = BFD_ALIGN (s->_raw_size,
|
---|
1756 | (bfd_size_type) (1 << power_of_two));
|
---|
1757 | if (power_of_two > bfd_get_section_alignment (dynobj, s))
|
---|
1758 | {
|
---|
1759 | if (! bfd_set_section_alignment (dynobj, s, power_of_two))
|
---|
1760 | return FALSE;
|
---|
1761 | }
|
---|
1762 |
|
---|
1763 | /* Define the symbol as being at this point in the section. */
|
---|
1764 | h->root.u.def.section = s;
|
---|
1765 | h->root.u.def.value = s->_raw_size;
|
---|
1766 |
|
---|
1767 | /* Increment the section size to make room for the symbol. */
|
---|
1768 | s->_raw_size += h->size;
|
---|
1769 |
|
---|
1770 | return TRUE;
|
---|
1771 | }
|
---|
1772 |
|
---|
1773 | /* Set the sizes of the dynamic sections. */
|
---|
1774 |
|
---|
1775 | static bfd_boolean
|
---|
1776 | sparc64_elf_size_dynamic_sections (output_bfd, info)
|
---|
1777 | bfd *output_bfd;
|
---|
1778 | struct bfd_link_info *info;
|
---|
1779 | {
|
---|
1780 | bfd *dynobj;
|
---|
1781 | asection *s;
|
---|
1782 | bfd_boolean relplt;
|
---|
1783 |
|
---|
1784 | dynobj = elf_hash_table (info)->dynobj;
|
---|
1785 | BFD_ASSERT (dynobj != NULL);
|
---|
1786 |
|
---|
1787 | if (elf_hash_table (info)->dynamic_sections_created)
|
---|
1788 | {
|
---|
1789 | /* Set the contents of the .interp section to the interpreter. */
|
---|
1790 | if (! info->shared)
|
---|
1791 | {
|
---|
1792 | s = bfd_get_section_by_name (dynobj, ".interp");
|
---|
1793 | BFD_ASSERT (s != NULL);
|
---|
1794 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
|
---|
1795 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
|
---|
1796 | }
|
---|
1797 | }
|
---|
1798 | else
|
---|
1799 | {
|
---|
1800 | /* We may have created entries in the .rela.got section.
|
---|
1801 | However, if we are not creating the dynamic sections, we will
|
---|
1802 | not actually use these entries. Reset the size of .rela.got,
|
---|
1803 | which will cause it to get stripped from the output file
|
---|
1804 | below. */
|
---|
1805 | s = bfd_get_section_by_name (dynobj, ".rela.got");
|
---|
1806 | if (s != NULL)
|
---|
1807 | s->_raw_size = 0;
|
---|
1808 | }
|
---|
1809 |
|
---|
1810 | /* The check_relocs and adjust_dynamic_symbol entry points have
|
---|
1811 | determined the sizes of the various dynamic sections. Allocate
|
---|
1812 | memory for them. */
|
---|
1813 | relplt = FALSE;
|
---|
1814 | for (s = dynobj->sections; s != NULL; s = s->next)
|
---|
1815 | {
|
---|
1816 | const char *name;
|
---|
1817 | bfd_boolean strip;
|
---|
1818 |
|
---|
1819 | if ((s->flags & SEC_LINKER_CREATED) == 0)
|
---|
1820 | continue;
|
---|
1821 |
|
---|
1822 | /* It's OK to base decisions on the section name, because none
|
---|
1823 | of the dynobj section names depend upon the input files. */
|
---|
1824 | name = bfd_get_section_name (dynobj, s);
|
---|
1825 |
|
---|
1826 | strip = FALSE;
|
---|
1827 |
|
---|
1828 | if (strncmp (name, ".rela", 5) == 0)
|
---|
1829 | {
|
---|
1830 | if (s->_raw_size == 0)
|
---|
1831 | {
|
---|
1832 | /* If we don't need this section, strip it from the
|
---|
1833 | output file. This is to handle .rela.bss and
|
---|
1834 | .rel.plt. We must create it in
|
---|
1835 | create_dynamic_sections, because it must be created
|
---|
1836 | before the linker maps input sections to output
|
---|
1837 | sections. The linker does that before
|
---|
1838 | adjust_dynamic_symbol is called, and it is that
|
---|
1839 | function which decides whether anything needs to go
|
---|
1840 | into these sections. */
|
---|
1841 | strip = TRUE;
|
---|
1842 | }
|
---|
1843 | else
|
---|
1844 | {
|
---|
1845 | if (strcmp (name, ".rela.plt") == 0)
|
---|
1846 | relplt = TRUE;
|
---|
1847 |
|
---|
1848 | /* We use the reloc_count field as a counter if we need
|
---|
1849 | to copy relocs into the output file. */
|
---|
1850 | s->reloc_count = 0;
|
---|
1851 | }
|
---|
1852 | }
|
---|
1853 | else if (strcmp (name, ".plt") != 0
|
---|
1854 | && strncmp (name, ".got", 4) != 0)
|
---|
1855 | {
|
---|
1856 | /* It's not one of our sections, so don't allocate space. */
|
---|
1857 | continue;
|
---|
1858 | }
|
---|
1859 |
|
---|
1860 | if (strip)
|
---|
1861 | {
|
---|
1862 | _bfd_strip_section_from_output (info, s);
|
---|
1863 | continue;
|
---|
1864 | }
|
---|
1865 |
|
---|
1866 | /* Allocate memory for the section contents. Zero the memory
|
---|
1867 | for the benefit of .rela.plt, which has 4 unused entries
|
---|
1868 | at the beginning, and we don't want garbage. */
|
---|
1869 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
|
---|
1870 | if (s->contents == NULL && s->_raw_size != 0)
|
---|
1871 | return FALSE;
|
---|
1872 | }
|
---|
1873 |
|
---|
1874 | if (elf_hash_table (info)->dynamic_sections_created)
|
---|
1875 | {
|
---|
1876 | /* Add some entries to the .dynamic section. We fill in the
|
---|
1877 | values later, in sparc64_elf_finish_dynamic_sections, but we
|
---|
1878 | must add the entries now so that we get the correct size for
|
---|
1879 | the .dynamic section. The DT_DEBUG entry is filled in by the
|
---|
1880 | dynamic linker and used by the debugger. */
|
---|
1881 | #define add_dynamic_entry(TAG, VAL) \
|
---|
1882 | bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
|
---|
1883 |
|
---|
1884 | int reg;
|
---|
1885 | struct sparc64_elf_app_reg * app_regs;
|
---|
1886 | struct elf_strtab_hash *dynstr;
|
---|
1887 | struct elf_link_hash_table *eht = elf_hash_table (info);
|
---|
1888 |
|
---|
1889 | if (!info->shared)
|
---|
1890 | {
|
---|
1891 | if (!add_dynamic_entry (DT_DEBUG, 0))
|
---|
1892 | return FALSE;
|
---|
1893 | }
|
---|
1894 |
|
---|
1895 | if (relplt)
|
---|
1896 | {
|
---|
1897 | if (!add_dynamic_entry (DT_PLTGOT, 0)
|
---|
1898 | || !add_dynamic_entry (DT_PLTRELSZ, 0)
|
---|
1899 | || !add_dynamic_entry (DT_PLTREL, DT_RELA)
|
---|
1900 | || !add_dynamic_entry (DT_JMPREL, 0))
|
---|
1901 | return FALSE;
|
---|
1902 | }
|
---|
1903 |
|
---|
1904 | if (!add_dynamic_entry (DT_RELA, 0)
|
---|
1905 | || !add_dynamic_entry (DT_RELASZ, 0)
|
---|
1906 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
|
---|
1907 | return FALSE;
|
---|
1908 |
|
---|
1909 | if (info->flags & DF_TEXTREL)
|
---|
1910 | {
|
---|
1911 | if (!add_dynamic_entry (DT_TEXTREL, 0))
|
---|
1912 | return FALSE;
|
---|
1913 | }
|
---|
1914 |
|
---|
1915 | /* Add dynamic STT_REGISTER symbols and corresponding DT_SPARC_REGISTER
|
---|
1916 | entries if needed. */
|
---|
1917 | app_regs = sparc64_elf_hash_table (info)->app_regs;
|
---|
1918 | dynstr = eht->dynstr;
|
---|
1919 |
|
---|
1920 | for (reg = 0; reg < 4; reg++)
|
---|
1921 | if (app_regs [reg].name != NULL)
|
---|
1922 | {
|
---|
1923 | struct elf_link_local_dynamic_entry *entry, *e;
|
---|
1924 |
|
---|
1925 | if (!add_dynamic_entry (DT_SPARC_REGISTER, 0))
|
---|
1926 | return FALSE;
|
---|
1927 |
|
---|
1928 | entry = (struct elf_link_local_dynamic_entry *)
|
---|
1929 | bfd_hash_allocate (&info->hash->table, sizeof (*entry));
|
---|
1930 | if (entry == NULL)
|
---|
1931 | return FALSE;
|
---|
1932 |
|
---|
1933 | /* We cheat here a little bit: the symbol will not be local, so we
|
---|
1934 | put it at the end of the dynlocal linked list. We will fix it
|
---|
1935 | later on, as we have to fix other fields anyway. */
|
---|
1936 | entry->isym.st_value = reg < 2 ? reg + 2 : reg + 4;
|
---|
1937 | entry->isym.st_size = 0;
|
---|
1938 | if (*app_regs [reg].name != '\0')
|
---|
1939 | entry->isym.st_name
|
---|
1940 | = _bfd_elf_strtab_add (dynstr, app_regs[reg].name, FALSE);
|
---|
1941 | else
|
---|
1942 | entry->isym.st_name = 0;
|
---|
1943 | entry->isym.st_other = 0;
|
---|
1944 | entry->isym.st_info = ELF_ST_INFO (app_regs [reg].bind,
|
---|
1945 | STT_REGISTER);
|
---|
1946 | entry->isym.st_shndx = app_regs [reg].shndx;
|
---|
1947 | entry->next = NULL;
|
---|
1948 | entry->input_bfd = output_bfd;
|
---|
1949 | entry->input_indx = -1;
|
---|
1950 |
|
---|
1951 | if (eht->dynlocal == NULL)
|
---|
1952 | eht->dynlocal = entry;
|
---|
1953 | else
|
---|
1954 | {
|
---|
1955 | for (e = eht->dynlocal; e->next; e = e->next)
|
---|
1956 | ;
|
---|
1957 | e->next = entry;
|
---|
1958 | }
|
---|
1959 | eht->dynsymcount++;
|
---|
1960 | }
|
---|
1961 | }
|
---|
1962 | #undef add_dynamic_entry
|
---|
1963 |
|
---|
1964 | return TRUE;
|
---|
1965 | }
|
---|
1966 | |
---|
1967 |
|
---|
1968 | static bfd_boolean
|
---|
1969 | sparc64_elf_new_section_hook (abfd, sec)
|
---|
1970 | bfd *abfd;
|
---|
1971 | asection *sec;
|
---|
1972 | {
|
---|
1973 | struct sparc64_elf_section_data *sdata;
|
---|
1974 | bfd_size_type amt = sizeof (*sdata);
|
---|
1975 |
|
---|
1976 | sdata = (struct sparc64_elf_section_data *) bfd_zalloc (abfd, amt);
|
---|
1977 | if (sdata == NULL)
|
---|
1978 | return FALSE;
|
---|
1979 | sec->used_by_bfd = (PTR) sdata;
|
---|
1980 |
|
---|
1981 | return _bfd_elf_new_section_hook (abfd, sec);
|
---|
1982 | }
|
---|
1983 |
|
---|
1984 | static bfd_boolean
|
---|
1985 | sparc64_elf_relax_section (abfd, section, link_info, again)
|
---|
1986 | bfd *abfd ATTRIBUTE_UNUSED;
|
---|
1987 | asection *section ATTRIBUTE_UNUSED;
|
---|
1988 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED;
|
---|
1989 | bfd_boolean *again;
|
---|
1990 | {
|
---|
1991 | *again = FALSE;
|
---|
1992 | sec_do_relax (section) = 1;
|
---|
1993 | return TRUE;
|
---|
1994 | }
|
---|
1995 | |
---|
1996 |
|
---|
1997 | /* This is the condition under which finish_dynamic_symbol will be called
|
---|
1998 | from elflink.h. If elflink.h doesn't call our finish_dynamic_symbol
|
---|
1999 | routine, we'll need to do something about initializing any .plt and
|
---|
2000 | .got entries in relocate_section. */
|
---|
2001 | #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
|
---|
2002 | ((DYN) \
|
---|
2003 | && ((INFO)->shared \
|
---|
2004 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
|
---|
2005 | && ((H)->dynindx != -1 \
|
---|
2006 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
|
---|
2007 |
|
---|
2008 | /* Relocate a SPARC64 ELF section. */
|
---|
2009 |
|
---|
2010 | static bfd_boolean
|
---|
2011 | sparc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
|
---|
2012 | contents, relocs, local_syms, local_sections)
|
---|
2013 | bfd *output_bfd;
|
---|
2014 | struct bfd_link_info *info;
|
---|
2015 | bfd *input_bfd;
|
---|
2016 | asection *input_section;
|
---|
2017 | bfd_byte *contents;
|
---|
2018 | Elf_Internal_Rela *relocs;
|
---|
2019 | Elf_Internal_Sym *local_syms;
|
---|
2020 | asection **local_sections;
|
---|
2021 | {
|
---|
2022 | bfd *dynobj;
|
---|
2023 | Elf_Internal_Shdr *symtab_hdr;
|
---|
2024 | struct elf_link_hash_entry **sym_hashes;
|
---|
2025 | bfd_vma *local_got_offsets;
|
---|
2026 | bfd_vma got_base;
|
---|
2027 | asection *sgot;
|
---|
2028 | asection *splt;
|
---|
2029 | asection *sreloc;
|
---|
2030 | Elf_Internal_Rela *rel;
|
---|
2031 | Elf_Internal_Rela *relend;
|
---|
2032 |
|
---|
2033 | if (info->relocateable)
|
---|
2034 | return TRUE;
|
---|
2035 |
|
---|
2036 | dynobj = elf_hash_table (info)->dynobj;
|
---|
2037 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
|
---|
2038 | sym_hashes = elf_sym_hashes (input_bfd);
|
---|
2039 | local_got_offsets = elf_local_got_offsets (input_bfd);
|
---|
2040 |
|
---|
2041 | if (elf_hash_table(info)->hgot == NULL)
|
---|
2042 | got_base = 0;
|
---|
2043 | else
|
---|
2044 | got_base = elf_hash_table (info)->hgot->root.u.def.value;
|
---|
2045 |
|
---|
2046 | sgot = splt = sreloc = NULL;
|
---|
2047 |
|
---|
2048 | rel = relocs;
|
---|
2049 | relend = relocs + NUM_SHDR_ENTRIES (& elf_section_data (input_section)->rel_hdr);
|
---|
2050 | for (; rel < relend; rel++)
|
---|
2051 | {
|
---|
2052 | int r_type;
|
---|
2053 | reloc_howto_type *howto;
|
---|
2054 | unsigned long r_symndx;
|
---|
2055 | struct elf_link_hash_entry *h;
|
---|
2056 | Elf_Internal_Sym *sym;
|
---|
2057 | asection *sec;
|
---|
2058 | bfd_vma relocation, off;
|
---|
2059 | bfd_reloc_status_type r;
|
---|
2060 | bfd_boolean is_plt = FALSE;
|
---|
2061 | bfd_boolean unresolved_reloc;
|
---|
2062 |
|
---|
2063 | r_type = ELF64_R_TYPE_ID (rel->r_info);
|
---|
2064 | if (r_type < 0 || r_type >= (int) R_SPARC_max_std)
|
---|
2065 | {
|
---|
2066 | bfd_set_error (bfd_error_bad_value);
|
---|
2067 | return FALSE;
|
---|
2068 | }
|
---|
2069 | howto = sparc64_elf_howto_table + r_type;
|
---|
2070 |
|
---|
2071 | /* This is a final link. */
|
---|
2072 | r_symndx = ELF64_R_SYM (rel->r_info);
|
---|
2073 | h = NULL;
|
---|
2074 | sym = NULL;
|
---|
2075 | sec = NULL;
|
---|
2076 | unresolved_reloc = FALSE;
|
---|
2077 | if (r_symndx < symtab_hdr->sh_info)
|
---|
2078 | {
|
---|
2079 | sym = local_syms + r_symndx;
|
---|
2080 | sec = local_sections[r_symndx];
|
---|
2081 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
|
---|
2082 | }
|
---|
2083 | else
|
---|
2084 | {
|
---|
2085 | h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
---|
2086 | while (h->root.type == bfd_link_hash_indirect
|
---|
2087 | || h->root.type == bfd_link_hash_warning)
|
---|
2088 | h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
---|
2089 |
|
---|
2090 | relocation = 0;
|
---|
2091 | if (h->root.type == bfd_link_hash_defined
|
---|
2092 | || h->root.type == bfd_link_hash_defweak)
|
---|
2093 | {
|
---|
2094 | sec = h->root.u.def.section;
|
---|
2095 | if (sec->output_section == NULL)
|
---|
2096 | /* Set a flag that will be cleared later if we find a
|
---|
2097 | relocation value for this symbol. output_section
|
---|
2098 | is typically NULL for symbols satisfied by a shared
|
---|
2099 | library. */
|
---|
2100 | unresolved_reloc = TRUE;
|
---|
2101 | else
|
---|
2102 | relocation = (h->root.u.def.value
|
---|
2103 | + sec->output_section->vma
|
---|
2104 | + sec->output_offset);
|
---|
2105 | }
|
---|
2106 | else if (h->root.type == bfd_link_hash_undefweak)
|
---|
2107 | ;
|
---|
2108 | else if (info->shared
|
---|
2109 | && !info->no_undefined
|
---|
2110 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
|
---|
2111 | ;
|
---|
2112 | else
|
---|
2113 | {
|
---|
2114 | if (! ((*info->callbacks->undefined_symbol)
|
---|
2115 | (info, h->root.root.string, input_bfd,
|
---|
2116 | input_section, rel->r_offset,
|
---|
2117 | (!info->shared || info->no_undefined
|
---|
2118 | || ELF_ST_VISIBILITY (h->other)))))
|
---|
2119 | return FALSE;
|
---|
2120 |
|
---|
2121 | /* To avoid generating warning messages about truncated
|
---|
2122 | relocations, set the relocation's address to be the same as
|
---|
2123 | the start of this section. */
|
---|
2124 | if (input_section->output_section != NULL)
|
---|
2125 | relocation = input_section->output_section->vma;
|
---|
2126 | else
|
---|
2127 | relocation = 0;
|
---|
2128 | }
|
---|
2129 | }
|
---|
2130 |
|
---|
2131 | do_dynreloc:
|
---|
2132 | /* When generating a shared object, these relocations are copied
|
---|
2133 | into the output file to be resolved at run time. */
|
---|
2134 | if (info->shared && r_symndx != 0 && (input_section->flags & SEC_ALLOC))
|
---|
2135 | {
|
---|
2136 | switch (r_type)
|
---|
2137 | {
|
---|
2138 | case R_SPARC_PC10:
|
---|
2139 | case R_SPARC_PC22:
|
---|
2140 | case R_SPARC_PC_HH22:
|
---|
2141 | case R_SPARC_PC_HM10:
|
---|
2142 | case R_SPARC_PC_LM22:
|
---|
2143 | if (h != NULL
|
---|
2144 | && !strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_"))
|
---|
2145 | break;
|
---|
2146 | /* Fall through. */
|
---|
2147 | case R_SPARC_DISP8:
|
---|
2148 | case R_SPARC_DISP16:
|
---|
2149 | case R_SPARC_DISP32:
|
---|
2150 | case R_SPARC_DISP64:
|
---|
2151 | case R_SPARC_WDISP30:
|
---|
2152 | case R_SPARC_WDISP22:
|
---|
2153 | case R_SPARC_WDISP19:
|
---|
2154 | case R_SPARC_WDISP16:
|
---|
2155 | if (h == NULL)
|
---|
2156 | break;
|
---|
2157 | /* Fall through. */
|
---|
2158 | case R_SPARC_8:
|
---|
2159 | case R_SPARC_16:
|
---|
2160 | case R_SPARC_32:
|
---|
2161 | case R_SPARC_HI22:
|
---|
2162 | case R_SPARC_22:
|
---|
2163 | case R_SPARC_13:
|
---|
2164 | case R_SPARC_LO10:
|
---|
2165 | case R_SPARC_UA32:
|
---|
2166 | case R_SPARC_10:
|
---|
2167 | case R_SPARC_11:
|
---|
2168 | case R_SPARC_64:
|
---|
2169 | case R_SPARC_OLO10:
|
---|
2170 | case R_SPARC_HH22:
|
---|
2171 | case R_SPARC_HM10:
|
---|
2172 | case R_SPARC_LM22:
|
---|
2173 | case R_SPARC_7:
|
---|
2174 | case R_SPARC_5:
|
---|
2175 | case R_SPARC_6:
|
---|
2176 | case R_SPARC_HIX22:
|
---|
2177 | case R_SPARC_LOX10:
|
---|
2178 | case R_SPARC_H44:
|
---|
2179 | case R_SPARC_M44:
|
---|
2180 | case R_SPARC_L44:
|
---|
2181 | case R_SPARC_UA64:
|
---|
2182 | case R_SPARC_UA16:
|
---|
2183 | {
|
---|
2184 | Elf_Internal_Rela outrel;
|
---|
2185 | bfd_byte *loc;
|
---|
2186 | bfd_boolean skip, relocate;
|
---|
2187 |
|
---|
2188 | if (sreloc == NULL)
|
---|
2189 | {
|
---|
2190 | const char *name =
|
---|
2191 | (bfd_elf_string_from_elf_section
|
---|
2192 | (input_bfd,
|
---|
2193 | elf_elfheader (input_bfd)->e_shstrndx,
|
---|
2194 | elf_section_data (input_section)->rel_hdr.sh_name));
|
---|
2195 |
|
---|
2196 | if (name == NULL)
|
---|
2197 | return FALSE;
|
---|
2198 |
|
---|
2199 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0
|
---|
2200 | && strcmp (bfd_get_section_name(input_bfd,
|
---|
2201 | input_section),
|
---|
2202 | name + 5) == 0);
|
---|
2203 |
|
---|
2204 | sreloc = bfd_get_section_by_name (dynobj, name);
|
---|
2205 | BFD_ASSERT (sreloc != NULL);
|
---|
2206 | }
|
---|
2207 |
|
---|
2208 | skip = FALSE;
|
---|
2209 | relocate = FALSE;
|
---|
2210 |
|
---|
2211 | outrel.r_offset =
|
---|
2212 | _bfd_elf_section_offset (output_bfd, info, input_section,
|
---|
2213 | rel->r_offset);
|
---|
2214 | if (outrel.r_offset == (bfd_vma) -1)
|
---|
2215 | skip = TRUE;
|
---|
2216 | else if (outrel.r_offset == (bfd_vma) -2)
|
---|
2217 | skip = TRUE, relocate = TRUE;
|
---|
2218 |
|
---|
2219 | outrel.r_offset += (input_section->output_section->vma
|
---|
2220 | + input_section->output_offset);
|
---|
2221 |
|
---|
2222 | /* Optimize unaligned reloc usage now that we know where
|
---|
2223 | it finally resides. */
|
---|
2224 | switch (r_type)
|
---|
2225 | {
|
---|
2226 | case R_SPARC_16:
|
---|
2227 | if (outrel.r_offset & 1) r_type = R_SPARC_UA16;
|
---|
2228 | break;
|
---|
2229 | case R_SPARC_UA16:
|
---|
2230 | if (!(outrel.r_offset & 1)) r_type = R_SPARC_16;
|
---|
2231 | break;
|
---|
2232 | case R_SPARC_32:
|
---|
2233 | if (outrel.r_offset & 3) r_type = R_SPARC_UA32;
|
---|
2234 | break;
|
---|
2235 | case R_SPARC_UA32:
|
---|
2236 | if (!(outrel.r_offset & 3)) r_type = R_SPARC_32;
|
---|
2237 | break;
|
---|
2238 | case R_SPARC_64:
|
---|
2239 | if (outrel.r_offset & 7) r_type = R_SPARC_UA64;
|
---|
2240 | break;
|
---|
2241 | case R_SPARC_UA64:
|
---|
2242 | if (!(outrel.r_offset & 7)) r_type = R_SPARC_64;
|
---|
2243 | break;
|
---|
2244 | case R_SPARC_DISP8:
|
---|
2245 | case R_SPARC_DISP16:
|
---|
2246 | case R_SPARC_DISP32:
|
---|
2247 | case R_SPARC_DISP64:
|
---|
2248 | /* If the symbol is not dynamic, we should not keep
|
---|
2249 | a dynamic relocation. But an .rela.* slot has been
|
---|
2250 | allocated for it, output R_SPARC_NONE.
|
---|
2251 | FIXME: Add code tracking needed dynamic relocs as
|
---|
2252 | e.g. i386 has. */
|
---|
2253 | if (h->dynindx == -1)
|
---|
2254 | skip = TRUE, relocate = TRUE;
|
---|
2255 | break;
|
---|
2256 | }
|
---|
2257 |
|
---|
2258 | if (skip)
|
---|
2259 | memset (&outrel, 0, sizeof outrel);
|
---|
2260 | /* h->dynindx may be -1 if the symbol was marked to
|
---|
2261 | become local. */
|
---|
2262 | else if (h != NULL && ! is_plt
|
---|
2263 | && ((! info->symbolic && h->dynindx != -1)
|
---|
2264 | || (h->elf_link_hash_flags
|
---|
2265 | & ELF_LINK_HASH_DEF_REGULAR) == 0))
|
---|
2266 | {
|
---|
2267 | BFD_ASSERT (h->dynindx != -1);
|
---|
2268 | outrel.r_info
|
---|
2269 | = ELF64_R_INFO (h->dynindx,
|
---|
2270 | ELF64_R_TYPE_INFO (
|
---|
2271 | ELF64_R_TYPE_DATA (rel->r_info),
|
---|
2272 | r_type));
|
---|
2273 | outrel.r_addend = rel->r_addend;
|
---|
2274 | }
|
---|
2275 | else
|
---|
2276 | {
|
---|
2277 | outrel.r_addend = relocation + rel->r_addend;
|
---|
2278 | if (r_type == R_SPARC_64)
|
---|
2279 | outrel.r_info = ELF64_R_INFO (0, R_SPARC_RELATIVE);
|
---|
2280 | else
|
---|
2281 | {
|
---|
2282 | long indx;
|
---|
2283 |
|
---|
2284 | if (is_plt)
|
---|
2285 | sec = splt;
|
---|
2286 | else if (h == NULL)
|
---|
2287 | sec = local_sections[r_symndx];
|
---|
2288 | else
|
---|
2289 | {
|
---|
2290 | BFD_ASSERT (h->root.type == bfd_link_hash_defined
|
---|
2291 | || (h->root.type
|
---|
2292 | == bfd_link_hash_defweak));
|
---|
2293 | sec = h->root.u.def.section;
|
---|
2294 | }
|
---|
2295 | if (sec != NULL && bfd_is_abs_section (sec))
|
---|
2296 | indx = 0;
|
---|
2297 | else if (sec == NULL || sec->owner == NULL)
|
---|
2298 | {
|
---|
2299 | bfd_set_error (bfd_error_bad_value);
|
---|
2300 | return FALSE;
|
---|
2301 | }
|
---|
2302 | else
|
---|
2303 | {
|
---|
2304 | asection *osec;
|
---|
2305 |
|
---|
2306 | osec = sec->output_section;
|
---|
2307 | indx = elf_section_data (osec)->dynindx;
|
---|
2308 |
|
---|
2309 | /* We are turning this relocation into one
|
---|
2310 | against a section symbol, so subtract out
|
---|
2311 | the output section's address but not the
|
---|
2312 | offset of the input section in the output
|
---|
2313 | section. */
|
---|
2314 | outrel.r_addend -= osec->vma;
|
---|
2315 |
|
---|
2316 | /* FIXME: we really should be able to link non-pic
|
---|
2317 | shared libraries. */
|
---|
2318 | if (indx == 0)
|
---|
2319 | {
|
---|
2320 | BFD_FAIL ();
|
---|
2321 | (*_bfd_error_handler)
|
---|
2322 | (_("%s: probably compiled without -fPIC?"),
|
---|
2323 | bfd_archive_filename (input_bfd));
|
---|
2324 | bfd_set_error (bfd_error_bad_value);
|
---|
2325 | return FALSE;
|
---|
2326 | }
|
---|
2327 | }
|
---|
2328 |
|
---|
2329 | outrel.r_info
|
---|
2330 | = ELF64_R_INFO (indx,
|
---|
2331 | ELF64_R_TYPE_INFO (
|
---|
2332 | ELF64_R_TYPE_DATA (rel->r_info),
|
---|
2333 | r_type));
|
---|
2334 | }
|
---|
2335 | }
|
---|
2336 |
|
---|
2337 | loc = sreloc->contents;
|
---|
2338 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
|
---|
2339 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
|
---|
2340 |
|
---|
2341 | /* This reloc will be computed at runtime, so there's no
|
---|
2342 | need to do anything now. */
|
---|
2343 | if (! relocate)
|
---|
2344 | continue;
|
---|
2345 | }
|
---|
2346 | break;
|
---|
2347 | }
|
---|
2348 | }
|
---|
2349 |
|
---|
2350 | switch (r_type)
|
---|
2351 | {
|
---|
2352 | case R_SPARC_GOT10:
|
---|
2353 | case R_SPARC_GOT13:
|
---|
2354 | case R_SPARC_GOT22:
|
---|
2355 | /* Relocation is to the entry for this symbol in the global
|
---|
2356 | offset table. */
|
---|
2357 | if (sgot == NULL)
|
---|
2358 | {
|
---|
2359 | sgot = bfd_get_section_by_name (dynobj, ".got");
|
---|
2360 | BFD_ASSERT (sgot != NULL);
|
---|
2361 | }
|
---|
2362 |
|
---|
2363 | if (h != NULL)
|
---|
2364 | {
|
---|
2365 | bfd_boolean dyn;
|
---|
2366 |
|
---|
2367 | off = h->got.offset;
|
---|
2368 | BFD_ASSERT (off != (bfd_vma) -1);
|
---|
2369 | dyn = elf_hash_table (info)->dynamic_sections_created;
|
---|
2370 |
|
---|
2371 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
|
---|
2372 | || (info->shared
|
---|
2373 | && (info->symbolic
|
---|
2374 | || h->dynindx == -1
|
---|
2375 | || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
|
---|
2376 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
|
---|
2377 | {
|
---|
2378 | /* This is actually a static link, or it is a -Bsymbolic
|
---|
2379 | link and the symbol is defined locally, or the symbol
|
---|
2380 | was forced to be local because of a version file. We
|
---|
2381 | must initialize this entry in the global offset table.
|
---|
2382 | Since the offset must always be a multiple of 8, we
|
---|
2383 | use the least significant bit to record whether we
|
---|
2384 | have initialized it already.
|
---|
2385 |
|
---|
2386 | When doing a dynamic link, we create a .rela.got
|
---|
2387 | relocation entry to initialize the value. This is
|
---|
2388 | done in the finish_dynamic_symbol routine. */
|
---|
2389 |
|
---|
2390 | if ((off & 1) != 0)
|
---|
2391 | off &= ~1;
|
---|
2392 | else
|
---|
2393 | {
|
---|
2394 | bfd_put_64 (output_bfd, relocation,
|
---|
2395 | sgot->contents + off);
|
---|
2396 | h->got.offset |= 1;
|
---|
2397 | }
|
---|
2398 | }
|
---|
2399 | else
|
---|
2400 | unresolved_reloc = FALSE;
|
---|
2401 | }
|
---|
2402 | else
|
---|
2403 | {
|
---|
2404 | BFD_ASSERT (local_got_offsets != NULL);
|
---|
2405 | off = local_got_offsets[r_symndx];
|
---|
2406 | BFD_ASSERT (off != (bfd_vma) -1);
|
---|
2407 |
|
---|
2408 | /* The offset must always be a multiple of 8. We use
|
---|
2409 | the least significant bit to record whether we have
|
---|
2410 | already processed this entry. */
|
---|
2411 | if ((off & 1) != 0)
|
---|
2412 | off &= ~1;
|
---|
2413 | else
|
---|
2414 | {
|
---|
2415 | local_got_offsets[r_symndx] |= 1;
|
---|
2416 |
|
---|
2417 | if (info->shared)
|
---|
2418 | {
|
---|
2419 | asection *s;
|
---|
2420 | Elf_Internal_Rela outrel;
|
---|
2421 | bfd_byte *loc;
|
---|
2422 |
|
---|
2423 | /* The Solaris 2.7 64-bit linker adds the contents
|
---|
2424 | of the location to the value of the reloc.
|
---|
2425 | Note this is different behaviour to the
|
---|
2426 | 32-bit linker, which both adds the contents
|
---|
2427 | and ignores the addend. So clear the location. */
|
---|
2428 | bfd_put_64 (output_bfd, (bfd_vma) 0,
|
---|
2429 | sgot->contents + off);
|
---|
2430 |
|
---|
2431 | /* We need to generate a R_SPARC_RELATIVE reloc
|
---|
2432 | for the dynamic linker. */
|
---|
2433 | s = bfd_get_section_by_name(dynobj, ".rela.got");
|
---|
2434 | BFD_ASSERT (s != NULL);
|
---|
2435 |
|
---|
2436 | outrel.r_offset = (sgot->output_section->vma
|
---|
2437 | + sgot->output_offset
|
---|
2438 | + off);
|
---|
2439 | outrel.r_info = ELF64_R_INFO (0, R_SPARC_RELATIVE);
|
---|
2440 | outrel.r_addend = relocation;
|
---|
2441 | loc = s->contents;
|
---|
2442 | loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
|
---|
2443 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
|
---|
2444 | }
|
---|
2445 | else
|
---|
2446 | bfd_put_64 (output_bfd, relocation, sgot->contents + off);
|
---|
2447 | }
|
---|
2448 | }
|
---|
2449 | relocation = sgot->output_offset + off - got_base;
|
---|
2450 | goto do_default;
|
---|
2451 |
|
---|
2452 | case R_SPARC_WPLT30:
|
---|
2453 | case R_SPARC_PLT32:
|
---|
2454 | case R_SPARC_HIPLT22:
|
---|
2455 | case R_SPARC_LOPLT10:
|
---|
2456 | case R_SPARC_PCPLT32:
|
---|
2457 | case R_SPARC_PCPLT22:
|
---|
2458 | case R_SPARC_PCPLT10:
|
---|
2459 | case R_SPARC_PLT64:
|
---|
2460 | /* Relocation is to the entry for this symbol in the
|
---|
2461 | procedure linkage table. */
|
---|
2462 | BFD_ASSERT (h != NULL);
|
---|
2463 |
|
---|
2464 | if (h->plt.offset == (bfd_vma) -1)
|
---|
2465 | {
|
---|
2466 | /* We didn't make a PLT entry for this symbol. This
|
---|
2467 | happens when statically linking PIC code, or when
|
---|
2468 | using -Bsymbolic. */
|
---|
2469 | goto do_default;
|
---|
2470 | }
|
---|
2471 |
|
---|
2472 | if (splt == NULL)
|
---|
2473 | {
|
---|
2474 | splt = bfd_get_section_by_name (dynobj, ".plt");
|
---|
2475 | BFD_ASSERT (splt != NULL);
|
---|
2476 | }
|
---|
2477 |
|
---|
2478 | relocation = (splt->output_section->vma
|
---|
2479 | + splt->output_offset
|
---|
2480 | + sparc64_elf_plt_entry_offset (h->plt.offset));
|
---|
2481 | unresolved_reloc = FALSE;
|
---|
2482 | if (r_type == R_SPARC_WPLT30)
|
---|
2483 | goto do_wplt30;
|
---|
2484 | if (r_type == R_SPARC_PLT32 || r_type == R_SPARC_PLT64)
|
---|
2485 | {
|
---|
2486 | r_type = r_type == R_SPARC_PLT32 ? R_SPARC_32 : R_SPARC_64;
|
---|
2487 | is_plt = TRUE;
|
---|
2488 | goto do_dynreloc;
|
---|
2489 | }
|
---|
2490 | goto do_default;
|
---|
2491 |
|
---|
2492 | case R_SPARC_OLO10:
|
---|
2493 | {
|
---|
2494 | bfd_vma x;
|
---|
2495 |
|
---|
2496 | relocation += rel->r_addend;
|
---|
2497 | relocation = (relocation & 0x3ff) + ELF64_R_TYPE_DATA (rel->r_info);
|
---|
2498 |
|
---|
2499 | x = bfd_get_32 (input_bfd, contents + rel->r_offset);
|
---|
2500 | x = (x & ~(bfd_vma) 0x1fff) | (relocation & 0x1fff);
|
---|
2501 | bfd_put_32 (input_bfd, x, contents + rel->r_offset);
|
---|
2502 |
|
---|
2503 | r = bfd_check_overflow (howto->complain_on_overflow,
|
---|
2504 | howto->bitsize, howto->rightshift,
|
---|
2505 | bfd_arch_bits_per_address (input_bfd),
|
---|
2506 | relocation);
|
---|
2507 | }
|
---|
2508 | break;
|
---|
2509 |
|
---|
2510 | case R_SPARC_WDISP16:
|
---|
2511 | {
|
---|
2512 | bfd_vma x;
|
---|
2513 |
|
---|
2514 | relocation += rel->r_addend;
|
---|
2515 | /* Adjust for pc-relative-ness. */
|
---|
2516 | relocation -= (input_section->output_section->vma
|
---|
2517 | + input_section->output_offset);
|
---|
2518 | relocation -= rel->r_offset;
|
---|
2519 |
|
---|
2520 | x = bfd_get_32 (input_bfd, contents + rel->r_offset);
|
---|
2521 | x &= ~(bfd_vma) 0x303fff;
|
---|
2522 | x |= ((((relocation >> 2) & 0xc000) << 6)
|
---|
2523 | | ((relocation >> 2) & 0x3fff));
|
---|
2524 | bfd_put_32 (input_bfd, x, contents + rel->r_offset);
|
---|
2525 |
|
---|
2526 | r = bfd_check_overflow (howto->complain_on_overflow,
|
---|
2527 | howto->bitsize, howto->rightshift,
|
---|
2528 | bfd_arch_bits_per_address (input_bfd),
|
---|
2529 | relocation);
|
---|
2530 | }
|
---|
2531 | break;
|
---|
2532 |
|
---|
2533 | case R_SPARC_HIX22:
|
---|
2534 | {
|
---|
2535 | bfd_vma x;
|
---|
2536 |
|
---|
2537 | relocation += rel->r_addend;
|
---|
2538 | relocation = relocation ^ MINUS_ONE;
|
---|
2539 |
|
---|
2540 | x = bfd_get_32 (input_bfd, contents + rel->r_offset);
|
---|
2541 | x = (x & ~(bfd_vma) 0x3fffff) | ((relocation >> 10) & 0x3fffff);
|
---|
2542 | bfd_put_32 (input_bfd, x, contents + rel->r_offset);
|
---|
2543 |
|
---|
2544 | r = bfd_check_overflow (howto->complain_on_overflow,
|
---|
2545 | howto->bitsize, howto->rightshift,
|
---|
2546 | bfd_arch_bits_per_address (input_bfd),
|
---|
2547 | relocation);
|
---|
2548 | }
|
---|
2549 | break;
|
---|
2550 |
|
---|
2551 | case R_SPARC_LOX10:
|
---|
2552 | {
|
---|
2553 | bfd_vma x;
|
---|
2554 |
|
---|
2555 | relocation += rel->r_addend;
|
---|
2556 | relocation = (relocation & 0x3ff) | 0x1c00;
|
---|
2557 |
|
---|
2558 | x = bfd_get_32 (input_bfd, contents + rel->r_offset);
|
---|
2559 | x = (x & ~(bfd_vma) 0x1fff) | relocation;
|
---|
2560 | bfd_put_32 (input_bfd, x, contents + rel->r_offset);
|
---|
2561 |
|
---|
2562 | r = bfd_reloc_ok;
|
---|
2563 | }
|
---|
2564 | break;
|
---|
2565 |
|
---|
2566 | case R_SPARC_WDISP30:
|
---|
2567 | do_wplt30:
|
---|
2568 | if (sec_do_relax (input_section)
|
---|
2569 | && rel->r_offset + 4 < input_section->_raw_size)
|
---|
2570 | {
|
---|
2571 | #define G0 0
|
---|
2572 | #define O7 15
|
---|
2573 | #define XCC (2 << 20)
|
---|
2574 | #define COND(x) (((x)&0xf)<<25)
|
---|
2575 | #define CONDA COND(0x8)
|
---|
2576 | #define INSN_BPA (F2(0,1) | CONDA | BPRED | XCC)
|
---|
2577 | #define INSN_BA (F2(0,2) | CONDA)
|
---|
2578 | #define INSN_OR F3(2, 0x2, 0)
|
---|
2579 | #define INSN_NOP F2(0,4)
|
---|
2580 |
|
---|
2581 | bfd_vma x, y;
|
---|
2582 |
|
---|
2583 | /* If the instruction is a call with either:
|
---|
2584 | restore
|
---|
2585 | arithmetic instruction with rd == %o7
|
---|
2586 | where rs1 != %o7 and rs2 if it is register != %o7
|
---|
2587 | then we can optimize if the call destination is near
|
---|
2588 | by changing the call into a branch always. */
|
---|
2589 | x = bfd_get_32 (input_bfd, contents + rel->r_offset);
|
---|
2590 | y = bfd_get_32 (input_bfd, contents + rel->r_offset + 4);
|
---|
2591 | if ((x & OP(~0)) == OP(1) && (y & OP(~0)) == OP(2))
|
---|
2592 | {
|
---|
2593 | if (((y & OP3(~0)) == OP3(0x3d) /* restore */
|
---|
2594 | || ((y & OP3(0x28)) == 0 /* arithmetic */
|
---|
2595 | && (y & RD(~0)) == RD(O7)))
|
---|
2596 | && (y & RS1(~0)) != RS1(O7)
|
---|
2597 | && ((y & F3I(~0))
|
---|
2598 | || (y & RS2(~0)) != RS2(O7)))
|
---|
2599 | {
|
---|
2600 | bfd_vma reloc;
|
---|
2601 |
|
---|
2602 | reloc = relocation + rel->r_addend - rel->r_offset;
|
---|
2603 | reloc -= (input_section->output_section->vma
|
---|
2604 | + input_section->output_offset);
|
---|
2605 | if (reloc & 3)
|
---|
2606 | goto do_default;
|
---|
2607 |
|
---|
2608 | /* Ensure the branch fits into simm22. */
|
---|
2609 | if ((reloc & ~(bfd_vma)0x7fffff)
|
---|
2610 | && ((reloc | 0x7fffff) != MINUS_ONE))
|
---|
2611 | goto do_default;
|
---|
2612 | reloc >>= 2;
|
---|
2613 |
|
---|
2614 | /* Check whether it fits into simm19. */
|
---|
2615 | if ((reloc & 0x3c0000) == 0
|
---|
2616 | || (reloc & 0x3c0000) == 0x3c0000)
|
---|
2617 | x = INSN_BPA | (reloc & 0x7ffff); /* ba,pt %xcc */
|
---|
2618 | else
|
---|
2619 | x = INSN_BA | (reloc & 0x3fffff); /* ba */
|
---|
2620 | bfd_put_32 (input_bfd, x, contents + rel->r_offset);
|
---|
2621 | r = bfd_reloc_ok;
|
---|
2622 | if (rel->r_offset >= 4
|
---|
2623 | && (y & (0xffffffff ^ RS1(~0)))
|
---|
2624 | == (INSN_OR | RD(O7) | RS2(G0)))
|
---|
2625 | {
|
---|
2626 | bfd_vma z;
|
---|
2627 | unsigned int reg;
|
---|
2628 |
|
---|
2629 | z = bfd_get_32 (input_bfd,
|
---|
2630 | contents + rel->r_offset - 4);
|
---|
2631 | if ((z & (0xffffffff ^ RD(~0)))
|
---|
2632 | != (INSN_OR | RS1(O7) | RS2(G0)))
|
---|
2633 | break;
|
---|
2634 |
|
---|
2635 | /* The sequence was
|
---|
2636 | or %o7, %g0, %rN
|
---|
2637 | call foo
|
---|
2638 | or %rN, %g0, %o7
|
---|
2639 |
|
---|
2640 | If call foo was replaced with ba, replace
|
---|
2641 | or %rN, %g0, %o7 with nop. */
|
---|
2642 |
|
---|
2643 | reg = (y & RS1(~0)) >> 14;
|
---|
2644 | if (reg != ((z & RD(~0)) >> 25)
|
---|
2645 | || reg == G0 || reg == O7)
|
---|
2646 | break;
|
---|
2647 |
|
---|
2648 | bfd_put_32 (input_bfd, (bfd_vma) INSN_NOP,
|
---|
2649 | contents + rel->r_offset + 4);
|
---|
2650 | }
|
---|
2651 | break;
|
---|
2652 | }
|
---|
2653 | }
|
---|
2654 | }
|
---|
2655 | /* Fall through. */
|
---|
2656 |
|
---|
2657 | default:
|
---|
2658 | do_default:
|
---|
2659 | r = _bfd_final_link_relocate (howto, input_bfd, input_section,
|
---|
2660 | contents, rel->r_offset,
|
---|
2661 | relocation, rel->r_addend);
|
---|
2662 | break;
|
---|
2663 | }
|
---|
2664 |
|
---|
2665 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
|
---|
2666 | because such sections are not SEC_ALLOC and thus ld.so will
|
---|
2667 | not process them. */
|
---|
2668 | if (unresolved_reloc
|
---|
2669 | && !((input_section->flags & SEC_DEBUGGING) != 0
|
---|
2670 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
|
---|
2671 | (*_bfd_error_handler)
|
---|
2672 | (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
|
---|
2673 | bfd_archive_filename (input_bfd),
|
---|
2674 | bfd_get_section_name (input_bfd, input_section),
|
---|
2675 | (long) rel->r_offset,
|
---|
2676 | h->root.root.string);
|
---|
2677 |
|
---|
2678 | switch (r)
|
---|
2679 | {
|
---|
2680 | case bfd_reloc_ok:
|
---|
2681 | break;
|
---|
2682 |
|
---|
2683 | default:
|
---|
2684 | case bfd_reloc_outofrange:
|
---|
2685 | abort ();
|
---|
2686 |
|
---|
2687 | case bfd_reloc_overflow:
|
---|
2688 | {
|
---|
2689 | const char *name;
|
---|
2690 |
|
---|
2691 | /* The Solaris native linker silently disregards
|
---|
2692 | overflows. We don't, but this breaks stabs debugging
|
---|
2693 | info, whose relocations are only 32-bits wide. Ignore
|
---|
2694 | overflows for discarded entries. */
|
---|
2695 | if (r_type == R_SPARC_32
|
---|
2696 | && _bfd_elf_section_offset (output_bfd, info, input_section,
|
---|
2697 | rel->r_offset) == (bfd_vma) -1)
|
---|
2698 | break;
|
---|
2699 |
|
---|
2700 | if (h != NULL)
|
---|
2701 | {
|
---|
2702 | if (h->root.type == bfd_link_hash_undefweak
|
---|
2703 | && howto->pc_relative)
|
---|
2704 | {
|
---|
2705 | /* Assume this is a call protected by other code that
|
---|
2706 | detect the symbol is undefined. If this is the case,
|
---|
2707 | we can safely ignore the overflow. If not, the
|
---|
2708 | program is hosed anyway, and a little warning isn't
|
---|
2709 | going to help. */
|
---|
2710 | break;
|
---|
2711 | }
|
---|
2712 |
|
---|
2713 | name = h->root.root.string;
|
---|
2714 | }
|
---|
2715 | else
|
---|
2716 | {
|
---|
2717 | name = (bfd_elf_string_from_elf_section
|
---|
2718 | (input_bfd,
|
---|
2719 | symtab_hdr->sh_link,
|
---|
2720 | sym->st_name));
|
---|
2721 | if (name == NULL)
|
---|
2722 | return FALSE;
|
---|
2723 | if (*name == '\0')
|
---|
2724 | name = bfd_section_name (input_bfd, sec);
|
---|
2725 | }
|
---|
2726 | if (! ((*info->callbacks->reloc_overflow)
|
---|
2727 | (info, name, howto->name, (bfd_vma) 0,
|
---|
2728 | input_bfd, input_section, rel->r_offset)))
|
---|
2729 | return FALSE;
|
---|
2730 | }
|
---|
2731 | break;
|
---|
2732 | }
|
---|
2733 | }
|
---|
2734 |
|
---|
2735 | return TRUE;
|
---|
2736 | }
|
---|
2737 |
|
---|
2738 | /* Finish up dynamic symbol handling. We set the contents of various
|
---|
2739 | dynamic sections here. */
|
---|
2740 |
|
---|
2741 | static bfd_boolean
|
---|
2742 | sparc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
|
---|
2743 | bfd *output_bfd;
|
---|
2744 | struct bfd_link_info *info;
|
---|
2745 | struct elf_link_hash_entry *h;
|
---|
2746 | Elf_Internal_Sym *sym;
|
---|
2747 | {
|
---|
2748 | bfd *dynobj;
|
---|
2749 |
|
---|
2750 | dynobj = elf_hash_table (info)->dynobj;
|
---|
2751 |
|
---|
2752 | if (h->plt.offset != (bfd_vma) -1)
|
---|
2753 | {
|
---|
2754 | asection *splt;
|
---|
2755 | asection *srela;
|
---|
2756 | Elf_Internal_Rela rela;
|
---|
2757 | bfd_byte *loc;
|
---|
2758 |
|
---|
2759 | /* This symbol has an entry in the PLT. Set it up. */
|
---|
2760 |
|
---|
2761 | BFD_ASSERT (h->dynindx != -1);
|
---|
2762 |
|
---|
2763 | splt = bfd_get_section_by_name (dynobj, ".plt");
|
---|
2764 | srela = bfd_get_section_by_name (dynobj, ".rela.plt");
|
---|
2765 | BFD_ASSERT (splt != NULL && srela != NULL);
|
---|
2766 |
|
---|
2767 | /* Fill in the entry in the .rela.plt section. */
|
---|
2768 |
|
---|
2769 | if (h->plt.offset < LARGE_PLT_THRESHOLD)
|
---|
2770 | {
|
---|
2771 | rela.r_offset = sparc64_elf_plt_entry_offset (h->plt.offset);
|
---|
2772 | rela.r_addend = 0;
|
---|
2773 | }
|
---|
2774 | else
|
---|
2775 | {
|
---|
2776 | bfd_vma max = splt->_raw_size / PLT_ENTRY_SIZE;
|
---|
2777 | rela.r_offset = sparc64_elf_plt_ptr_offset (h->plt.offset, max);
|
---|
2778 | rela.r_addend = -(sparc64_elf_plt_entry_offset (h->plt.offset) + 4)
|
---|
2779 | -(splt->output_section->vma + splt->output_offset);
|
---|
2780 | }
|
---|
2781 | rela.r_offset += (splt->output_section->vma + splt->output_offset);
|
---|
2782 | rela.r_info = ELF64_R_INFO (h->dynindx, R_SPARC_JMP_SLOT);
|
---|
2783 |
|
---|
2784 | /* Adjust for the first 4 reserved elements in the .plt section
|
---|
2785 | when setting the offset in the .rela.plt section.
|
---|
2786 | Sun forgot to read their own ABI and copied elf32-sparc behaviour,
|
---|
2787 | thus .plt[4] has corresponding .rela.plt[0] and so on. */
|
---|
2788 |
|
---|
2789 | loc = srela->contents;
|
---|
2790 | loc += (h->plt.offset - 4) * sizeof (Elf64_External_Rela);
|
---|
2791 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
|
---|
2792 |
|
---|
2793 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
|
---|
2794 | {
|
---|
2795 | /* Mark the symbol as undefined, rather than as defined in
|
---|
2796 | the .plt section. Leave the value alone. */
|
---|
2797 | sym->st_shndx = SHN_UNDEF;
|
---|
2798 | /* If the symbol is weak, we do need to clear the value.
|
---|
2799 | Otherwise, the PLT entry would provide a definition for
|
---|
2800 | the symbol even if the symbol wasn't defined anywhere,
|
---|
2801 | and so the symbol would never be NULL. */
|
---|
2802 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK)
|
---|
2803 | == 0)
|
---|
2804 | sym->st_value = 0;
|
---|
2805 | }
|
---|
2806 | }
|
---|
2807 |
|
---|
2808 | if (h->got.offset != (bfd_vma) -1)
|
---|
2809 | {
|
---|
2810 | asection *sgot;
|
---|
2811 | asection *srela;
|
---|
2812 | Elf_Internal_Rela rela;
|
---|
2813 | bfd_byte *loc;
|
---|
2814 |
|
---|
2815 | /* This symbol has an entry in the GOT. Set it up. */
|
---|
2816 |
|
---|
2817 | sgot = bfd_get_section_by_name (dynobj, ".got");
|
---|
2818 | srela = bfd_get_section_by_name (dynobj, ".rela.got");
|
---|
2819 | BFD_ASSERT (sgot != NULL && srela != NULL);
|
---|
2820 |
|
---|
2821 | rela.r_offset = (sgot->output_section->vma
|
---|
2822 | + sgot->output_offset
|
---|
2823 | + (h->got.offset &~ (bfd_vma) 1));
|
---|
2824 |
|
---|
2825 | /* If this is a -Bsymbolic link, and the symbol is defined
|
---|
2826 | locally, we just want to emit a RELATIVE reloc. Likewise if
|
---|
2827 | the symbol was forced to be local because of a version file.
|
---|
2828 | The entry in the global offset table will already have been
|
---|
2829 | initialized in the relocate_section function. */
|
---|
2830 | if (info->shared
|
---|
2831 | && (info->symbolic || h->dynindx == -1)
|
---|
2832 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
|
---|
2833 | {
|
---|
2834 | asection *sec = h->root.u.def.section;
|
---|
2835 | rela.r_info = ELF64_R_INFO (0, R_SPARC_RELATIVE);
|
---|
2836 | rela.r_addend = (h->root.u.def.value
|
---|
2837 | + sec->output_section->vma
|
---|
2838 | + sec->output_offset);
|
---|
2839 | }
|
---|
2840 | else
|
---|
2841 | {
|
---|
2842 | rela.r_info = ELF64_R_INFO (h->dynindx, R_SPARC_GLOB_DAT);
|
---|
2843 | rela.r_addend = 0;
|
---|
2844 | }
|
---|
2845 |
|
---|
2846 | bfd_put_64 (output_bfd, (bfd_vma) 0,
|
---|
2847 | sgot->contents + (h->got.offset &~ (bfd_vma) 1));
|
---|
2848 | loc = srela->contents;
|
---|
2849 | loc += srela->reloc_count++ * sizeof (Elf64_External_Rela);
|
---|
2850 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
|
---|
2851 | }
|
---|
2852 |
|
---|
2853 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
|
---|
2854 | {
|
---|
2855 | asection *s;
|
---|
2856 | Elf_Internal_Rela rela;
|
---|
2857 | bfd_byte *loc;
|
---|
2858 |
|
---|
2859 | /* This symbols needs a copy reloc. Set it up. */
|
---|
2860 | BFD_ASSERT (h->dynindx != -1);
|
---|
2861 |
|
---|
2862 | s = bfd_get_section_by_name (h->root.u.def.section->owner,
|
---|
2863 | ".rela.bss");
|
---|
2864 | BFD_ASSERT (s != NULL);
|
---|
2865 |
|
---|
2866 | rela.r_offset = (h->root.u.def.value
|
---|
2867 | + h->root.u.def.section->output_section->vma
|
---|
2868 | + h->root.u.def.section->output_offset);
|
---|
2869 | rela.r_info = ELF64_R_INFO (h->dynindx, R_SPARC_COPY);
|
---|
2870 | rela.r_addend = 0;
|
---|
2871 | loc = s->contents + s->reloc_count++ * sizeof (Elf64_External_Rela);
|
---|
2872 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
|
---|
2873 | }
|
---|
2874 |
|
---|
2875 | /* Mark some specially defined symbols as absolute. */
|
---|
2876 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0
|
---|
2877 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
|
---|
2878 | || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
|
---|
2879 | sym->st_shndx = SHN_ABS;
|
---|
2880 |
|
---|
2881 | return TRUE;
|
---|
2882 | }
|
---|
2883 |
|
---|
2884 | /* Finish up the dynamic sections. */
|
---|
2885 |
|
---|
2886 | static bfd_boolean
|
---|
2887 | sparc64_elf_finish_dynamic_sections (output_bfd, info)
|
---|
2888 | bfd *output_bfd;
|
---|
2889 | struct bfd_link_info *info;
|
---|
2890 | {
|
---|
2891 | bfd *dynobj;
|
---|
2892 | int stt_regidx = -1;
|
---|
2893 | asection *sdyn;
|
---|
2894 | asection *sgot;
|
---|
2895 |
|
---|
2896 | dynobj = elf_hash_table (info)->dynobj;
|
---|
2897 |
|
---|
2898 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
|
---|
2899 |
|
---|
2900 | if (elf_hash_table (info)->dynamic_sections_created)
|
---|
2901 | {
|
---|
2902 | asection *splt;
|
---|
2903 | Elf64_External_Dyn *dyncon, *dynconend;
|
---|
2904 |
|
---|
2905 | splt = bfd_get_section_by_name (dynobj, ".plt");
|
---|
2906 | BFD_ASSERT (splt != NULL && sdyn != NULL);
|
---|
2907 |
|
---|
2908 | dyncon = (Elf64_External_Dyn *) sdyn->contents;
|
---|
2909 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
|
---|
2910 | for (; dyncon < dynconend; dyncon++)
|
---|
2911 | {
|
---|
2912 | Elf_Internal_Dyn dyn;
|
---|
2913 | const char *name;
|
---|
2914 | bfd_boolean size;
|
---|
2915 |
|
---|
2916 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
|
---|
2917 |
|
---|
2918 | switch (dyn.d_tag)
|
---|
2919 | {
|
---|
2920 | case DT_PLTGOT: name = ".plt"; size = FALSE; break;
|
---|
2921 | case DT_PLTRELSZ: name = ".rela.plt"; size = TRUE; break;
|
---|
2922 | case DT_JMPREL: name = ".rela.plt"; size = FALSE; break;
|
---|
2923 | case DT_SPARC_REGISTER:
|
---|
2924 | if (stt_regidx == -1)
|
---|
2925 | {
|
---|
2926 | stt_regidx =
|
---|
2927 | _bfd_elf_link_lookup_local_dynindx (info, output_bfd, -1);
|
---|
2928 | if (stt_regidx == -1)
|
---|
2929 | return FALSE;
|
---|
2930 | }
|
---|
2931 | dyn.d_un.d_val = stt_regidx++;
|
---|
2932 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
|
---|
2933 | /* fallthrough */
|
---|
2934 | default: name = NULL; size = FALSE; break;
|
---|
2935 | }
|
---|
2936 |
|
---|
2937 | if (name != NULL)
|
---|
2938 | {
|
---|
2939 | asection *s;
|
---|
2940 |
|
---|
2941 | s = bfd_get_section_by_name (output_bfd, name);
|
---|
2942 | if (s == NULL)
|
---|
2943 | dyn.d_un.d_val = 0;
|
---|
2944 | else
|
---|
2945 | {
|
---|
2946 | if (! size)
|
---|
2947 | dyn.d_un.d_ptr = s->vma;
|
---|
2948 | else
|
---|
2949 | {
|
---|
2950 | if (s->_cooked_size != 0)
|
---|
2951 | dyn.d_un.d_val = s->_cooked_size;
|
---|
2952 | else
|
---|
2953 | dyn.d_un.d_val = s->_raw_size;
|
---|
2954 | }
|
---|
2955 | }
|
---|
2956 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
|
---|
2957 | }
|
---|
2958 | }
|
---|
2959 |
|
---|
2960 | /* Initialize the contents of the .plt section. */
|
---|
2961 | if (splt->_raw_size > 0)
|
---|
2962 | sparc64_elf_build_plt (output_bfd, splt->contents,
|
---|
2963 | (int) (splt->_raw_size / PLT_ENTRY_SIZE));
|
---|
2964 |
|
---|
2965 | elf_section_data (splt->output_section)->this_hdr.sh_entsize =
|
---|
2966 | PLT_ENTRY_SIZE;
|
---|
2967 | }
|
---|
2968 |
|
---|
2969 | /* Set the first entry in the global offset table to the address of
|
---|
2970 | the dynamic section. */
|
---|
2971 | sgot = bfd_get_section_by_name (dynobj, ".got");
|
---|
2972 | BFD_ASSERT (sgot != NULL);
|
---|
2973 | if (sgot->_raw_size > 0)
|
---|
2974 | {
|
---|
2975 | if (sdyn == NULL)
|
---|
2976 | bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents);
|
---|
2977 | else
|
---|
2978 | bfd_put_64 (output_bfd,
|
---|
2979 | sdyn->output_section->vma + sdyn->output_offset,
|
---|
2980 | sgot->contents);
|
---|
2981 | }
|
---|
2982 |
|
---|
2983 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 8;
|
---|
2984 |
|
---|
2985 | return TRUE;
|
---|
2986 | }
|
---|
2987 |
|
---|
2988 | static enum elf_reloc_type_class
|
---|
2989 | sparc64_elf_reloc_type_class (rela)
|
---|
2990 | const Elf_Internal_Rela *rela;
|
---|
2991 | {
|
---|
2992 | switch ((int) ELF64_R_TYPE (rela->r_info))
|
---|
2993 | {
|
---|
2994 | case R_SPARC_RELATIVE:
|
---|
2995 | return reloc_class_relative;
|
---|
2996 | case R_SPARC_JMP_SLOT:
|
---|
2997 | return reloc_class_plt;
|
---|
2998 | case R_SPARC_COPY:
|
---|
2999 | return reloc_class_copy;
|
---|
3000 | default:
|
---|
3001 | return reloc_class_normal;
|
---|
3002 | }
|
---|
3003 | }
|
---|
3004 | |
---|
3005 |
|
---|
3006 | /* Functions for dealing with the e_flags field. */
|
---|
3007 |
|
---|
3008 | /* Merge backend specific data from an object file to the output
|
---|
3009 | object file when linking. */
|
---|
3010 |
|
---|
3011 | static bfd_boolean
|
---|
3012 | sparc64_elf_merge_private_bfd_data (ibfd, obfd)
|
---|
3013 | bfd *ibfd;
|
---|
3014 | bfd *obfd;
|
---|
3015 | {
|
---|
3016 | bfd_boolean error;
|
---|
3017 | flagword new_flags, old_flags;
|
---|
3018 | int new_mm, old_mm;
|
---|
3019 |
|
---|
3020 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
|
---|
3021 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
|
---|
3022 | return TRUE;
|
---|
3023 |
|
---|
3024 | new_flags = elf_elfheader (ibfd)->e_flags;
|
---|
3025 | old_flags = elf_elfheader (obfd)->e_flags;
|
---|
3026 |
|
---|
3027 | if (!elf_flags_init (obfd)) /* First call, no flags set */
|
---|
3028 | {
|
---|
3029 | elf_flags_init (obfd) = TRUE;
|
---|
3030 | elf_elfheader (obfd)->e_flags = new_flags;
|
---|
3031 | }
|
---|
3032 |
|
---|
3033 | else if (new_flags == old_flags) /* Compatible flags are ok */
|
---|
3034 | ;
|
---|
3035 |
|
---|
3036 | else /* Incompatible flags */
|
---|
3037 | {
|
---|
3038 | error = FALSE;
|
---|
3039 |
|
---|
3040 | #define EF_SPARC_ISA_EXTENSIONS \
|
---|
3041 | (EF_SPARC_SUN_US1 | EF_SPARC_SUN_US3 | EF_SPARC_HAL_R1)
|
---|
3042 |
|
---|
3043 | if ((ibfd->flags & DYNAMIC) != 0)
|
---|
3044 | {
|
---|
3045 | /* We don't want dynamic objects memory ordering and
|
---|
3046 | architecture to have any role. That's what dynamic linker
|
---|
3047 | should do. */
|
---|
3048 | new_flags &= ~(EF_SPARCV9_MM | EF_SPARC_ISA_EXTENSIONS);
|
---|
3049 | new_flags |= (old_flags
|
---|
3050 | & (EF_SPARCV9_MM | EF_SPARC_ISA_EXTENSIONS));
|
---|
3051 | }
|
---|
3052 | else
|
---|
3053 | {
|
---|
3054 | /* Choose the highest architecture requirements. */
|
---|
3055 | old_flags |= (new_flags & EF_SPARC_ISA_EXTENSIONS);
|
---|
3056 | new_flags |= (old_flags & EF_SPARC_ISA_EXTENSIONS);
|
---|
3057 | if ((old_flags & (EF_SPARC_SUN_US1 | EF_SPARC_SUN_US3))
|
---|
3058 | && (old_flags & EF_SPARC_HAL_R1))
|
---|
3059 | {
|
---|
3060 | error = TRUE;
|
---|
3061 | (*_bfd_error_handler)
|
---|
3062 | (_("%s: linking UltraSPARC specific with HAL specific code"),
|
---|
3063 | bfd_archive_filename (ibfd));
|
---|
3064 | }
|
---|
3065 | /* Choose the most restrictive memory ordering. */
|
---|
3066 | old_mm = (old_flags & EF_SPARCV9_MM);
|
---|
3067 | new_mm = (new_flags & EF_SPARCV9_MM);
|
---|
3068 | old_flags &= ~EF_SPARCV9_MM;
|
---|
3069 | new_flags &= ~EF_SPARCV9_MM;
|
---|
3070 | if (new_mm < old_mm)
|
---|
3071 | old_mm = new_mm;
|
---|
3072 | old_flags |= old_mm;
|
---|
3073 | new_flags |= old_mm;
|
---|
3074 | }
|
---|
3075 |
|
---|
3076 | /* Warn about any other mismatches */
|
---|
3077 | if (new_flags != old_flags)
|
---|
3078 | {
|
---|
3079 | error = TRUE;
|
---|
3080 | (*_bfd_error_handler)
|
---|
3081 | (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
|
---|
3082 | bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags);
|
---|
3083 | }
|
---|
3084 |
|
---|
3085 | elf_elfheader (obfd)->e_flags = old_flags;
|
---|
3086 |
|
---|
3087 | if (error)
|
---|
3088 | {
|
---|
3089 | bfd_set_error (bfd_error_bad_value);
|
---|
3090 | return FALSE;
|
---|
3091 | }
|
---|
3092 | }
|
---|
3093 | return TRUE;
|
---|
3094 | }
|
---|
3095 |
|
---|
3096 | /* MARCO: Set the correct entry size for the .stab section. */
|
---|
3097 |
|
---|
3098 | static bfd_boolean
|
---|
3099 | sparc64_elf_fake_sections (abfd, hdr, sec)
|
---|
3100 | bfd *abfd ATTRIBUTE_UNUSED;
|
---|
3101 | Elf_Internal_Shdr *hdr ATTRIBUTE_UNUSED;
|
---|
3102 | asection *sec;
|
---|
3103 | {
|
---|
3104 | const char *name;
|
---|
3105 |
|
---|
3106 | name = bfd_get_section_name (abfd, sec);
|
---|
3107 |
|
---|
3108 | if (strcmp (name, ".stab") == 0)
|
---|
3109 | {
|
---|
3110 | /* Even in the 64bit case the stab entries are only 12 bytes long. */
|
---|
3111 | elf_section_data (sec)->this_hdr.sh_entsize = 12;
|
---|
3112 | }
|
---|
3113 |
|
---|
3114 | return TRUE;
|
---|
3115 | }
|
---|
3116 | |
---|
3117 |
|
---|
3118 | /* Print a STT_REGISTER symbol to file FILE. */
|
---|
3119 |
|
---|
3120 | static const char *
|
---|
3121 | sparc64_elf_print_symbol_all (abfd, filep, symbol)
|
---|
3122 | bfd *abfd ATTRIBUTE_UNUSED;
|
---|
3123 | PTR filep;
|
---|
3124 | asymbol *symbol;
|
---|
3125 | {
|
---|
3126 | FILE *file = (FILE *) filep;
|
---|
3127 | int reg, type;
|
---|
3128 |
|
---|
3129 | if (ELF_ST_TYPE (((elf_symbol_type *) symbol)->internal_elf_sym.st_info)
|
---|
3130 | != STT_REGISTER)
|
---|
3131 | return NULL;
|
---|
3132 |
|
---|
3133 | reg = ((elf_symbol_type *) symbol)->internal_elf_sym.st_value;
|
---|
3134 | type = symbol->flags;
|
---|
3135 | fprintf (file, "REG_%c%c%11s%c%c R", "GOLI" [reg / 8], '0' + (reg & 7), "",
|
---|
3136 | ((type & BSF_LOCAL)
|
---|
3137 | ? (type & BSF_GLOBAL) ? '!' : 'l'
|
---|
3138 | : (type & BSF_GLOBAL) ? 'g' : ' '),
|
---|
3139 | (type & BSF_WEAK) ? 'w' : ' ');
|
---|
3140 | if (symbol->name == NULL || symbol->name [0] == '\0')
|
---|
3141 | return "#scratch";
|
---|
3142 | else
|
---|
3143 | return symbol->name;
|
---|
3144 | }
|
---|
3145 | |
---|
3146 |
|
---|
3147 | /* Set the right machine number for a SPARC64 ELF file. */
|
---|
3148 |
|
---|
3149 | static bfd_boolean
|
---|
3150 | sparc64_elf_object_p (abfd)
|
---|
3151 | bfd *abfd;
|
---|
3152 | {
|
---|
3153 | unsigned long mach = bfd_mach_sparc_v9;
|
---|
3154 |
|
---|
3155 | if (elf_elfheader (abfd)->e_flags & EF_SPARC_SUN_US3)
|
---|
3156 | mach = bfd_mach_sparc_v9b;
|
---|
3157 | else if (elf_elfheader (abfd)->e_flags & EF_SPARC_SUN_US1)
|
---|
3158 | mach = bfd_mach_sparc_v9a;
|
---|
3159 | return bfd_default_set_arch_mach (abfd, bfd_arch_sparc, mach);
|
---|
3160 | }
|
---|
3161 |
|
---|
3162 | /* Relocations in the 64 bit SPARC ELF ABI are more complex than in
|
---|
3163 | standard ELF, because R_SPARC_OLO10 has secondary addend in
|
---|
3164 | ELF64_R_TYPE_DATA field. This structure is used to redirect the
|
---|
3165 | relocation handling routines. */
|
---|
3166 |
|
---|
3167 | const struct elf_size_info sparc64_elf_size_info =
|
---|
3168 | {
|
---|
3169 | sizeof (Elf64_External_Ehdr),
|
---|
3170 | sizeof (Elf64_External_Phdr),
|
---|
3171 | sizeof (Elf64_External_Shdr),
|
---|
3172 | sizeof (Elf64_External_Rel),
|
---|
3173 | sizeof (Elf64_External_Rela),
|
---|
3174 | sizeof (Elf64_External_Sym),
|
---|
3175 | sizeof (Elf64_External_Dyn),
|
---|
3176 | sizeof (Elf_External_Note),
|
---|
3177 | 4, /* hash-table entry size. */
|
---|
3178 | /* Internal relocations per external relocations.
|
---|
3179 | For link purposes we use just 1 internal per
|
---|
3180 | 1 external, for assembly and slurp symbol table
|
---|
3181 | we use 2. */
|
---|
3182 | 1,
|
---|
3183 | 64, /* arch_size. */
|
---|
3184 | 8, /* file_align. */
|
---|
3185 | ELFCLASS64,
|
---|
3186 | EV_CURRENT,
|
---|
3187 | bfd_elf64_write_out_phdrs,
|
---|
3188 | bfd_elf64_write_shdrs_and_ehdr,
|
---|
3189 | sparc64_elf_write_relocs,
|
---|
3190 | bfd_elf64_swap_symbol_in,
|
---|
3191 | bfd_elf64_swap_symbol_out,
|
---|
3192 | sparc64_elf_slurp_reloc_table,
|
---|
3193 | bfd_elf64_slurp_symbol_table,
|
---|
3194 | bfd_elf64_swap_dyn_in,
|
---|
3195 | bfd_elf64_swap_dyn_out,
|
---|
3196 | bfd_elf64_swap_reloc_in,
|
---|
3197 | bfd_elf64_swap_reloc_out,
|
---|
3198 | bfd_elf64_swap_reloca_in,
|
---|
3199 | bfd_elf64_swap_reloca_out
|
---|
3200 | };
|
---|
3201 |
|
---|
3202 | #define TARGET_BIG_SYM bfd_elf64_sparc_vec
|
---|
3203 | #define TARGET_BIG_NAME "elf64-sparc"
|
---|
3204 | #define ELF_ARCH bfd_arch_sparc
|
---|
3205 | #define ELF_MAXPAGESIZE 0x100000
|
---|
3206 |
|
---|
3207 | /* This is the official ABI value. */
|
---|
3208 | #define ELF_MACHINE_CODE EM_SPARCV9
|
---|
3209 |
|
---|
3210 | /* This is the value that we used before the ABI was released. */
|
---|
3211 | #define ELF_MACHINE_ALT1 EM_OLD_SPARCV9
|
---|
3212 |
|
---|
3213 | #define bfd_elf64_bfd_link_hash_table_create \
|
---|
3214 | sparc64_elf_bfd_link_hash_table_create
|
---|
3215 |
|
---|
3216 | #define elf_info_to_howto \
|
---|
3217 | sparc64_elf_info_to_howto
|
---|
3218 | #define bfd_elf64_get_reloc_upper_bound \
|
---|
3219 | sparc64_elf_get_reloc_upper_bound
|
---|
3220 | #define bfd_elf64_get_dynamic_reloc_upper_bound \
|
---|
3221 | sparc64_elf_get_dynamic_reloc_upper_bound
|
---|
3222 | #define bfd_elf64_canonicalize_reloc \
|
---|
3223 | sparc64_elf_canonicalize_reloc
|
---|
3224 | #define bfd_elf64_canonicalize_dynamic_reloc \
|
---|
3225 | sparc64_elf_canonicalize_dynamic_reloc
|
---|
3226 | #define bfd_elf64_bfd_reloc_type_lookup \
|
---|
3227 | sparc64_elf_reloc_type_lookup
|
---|
3228 | #define bfd_elf64_bfd_relax_section \
|
---|
3229 | sparc64_elf_relax_section
|
---|
3230 | #define bfd_elf64_new_section_hook \
|
---|
3231 | sparc64_elf_new_section_hook
|
---|
3232 |
|
---|
3233 | #define elf_backend_create_dynamic_sections \
|
---|
3234 | _bfd_elf_create_dynamic_sections
|
---|
3235 | #define elf_backend_add_symbol_hook \
|
---|
3236 | sparc64_elf_add_symbol_hook
|
---|
3237 | #define elf_backend_get_symbol_type \
|
---|
3238 | sparc64_elf_get_symbol_type
|
---|
3239 | #define elf_backend_symbol_processing \
|
---|
3240 | sparc64_elf_symbol_processing
|
---|
3241 | #define elf_backend_check_relocs \
|
---|
3242 | sparc64_elf_check_relocs
|
---|
3243 | #define elf_backend_adjust_dynamic_symbol \
|
---|
3244 | sparc64_elf_adjust_dynamic_symbol
|
---|
3245 | #define elf_backend_size_dynamic_sections \
|
---|
3246 | sparc64_elf_size_dynamic_sections
|
---|
3247 | #define elf_backend_relocate_section \
|
---|
3248 | sparc64_elf_relocate_section
|
---|
3249 | #define elf_backend_finish_dynamic_symbol \
|
---|
3250 | sparc64_elf_finish_dynamic_symbol
|
---|
3251 | #define elf_backend_finish_dynamic_sections \
|
---|
3252 | sparc64_elf_finish_dynamic_sections
|
---|
3253 | #define elf_backend_print_symbol_all \
|
---|
3254 | sparc64_elf_print_symbol_all
|
---|
3255 | #define elf_backend_output_arch_syms \
|
---|
3256 | sparc64_elf_output_arch_syms
|
---|
3257 | #define bfd_elf64_bfd_merge_private_bfd_data \
|
---|
3258 | sparc64_elf_merge_private_bfd_data
|
---|
3259 | #define elf_backend_fake_sections \
|
---|
3260 | sparc64_elf_fake_sections
|
---|
3261 |
|
---|
3262 | #define elf_backend_size_info \
|
---|
3263 | sparc64_elf_size_info
|
---|
3264 | #define elf_backend_object_p \
|
---|
3265 | sparc64_elf_object_p
|
---|
3266 | #define elf_backend_reloc_type_class \
|
---|
3267 | sparc64_elf_reloc_type_class
|
---|
3268 |
|
---|
3269 | #define elf_backend_want_got_plt 0
|
---|
3270 | #define elf_backend_plt_readonly 0
|
---|
3271 | #define elf_backend_want_plt_sym 1
|
---|
3272 | #define elf_backend_rela_normal 1
|
---|
3273 |
|
---|
3274 | /* Section 5.2.4 of the ABI specifies a 256-byte boundary for the table. */
|
---|
3275 | #define elf_backend_plt_alignment 8
|
---|
3276 |
|
---|
3277 | #define elf_backend_got_header_size 8
|
---|
3278 | #define elf_backend_plt_header_size PLT_HEADER_SIZE
|
---|
3279 |
|
---|
3280 | #include "elf64-target.h"
|
---|