Deleted Added
full compact
elf-vxworks.c (214157) elf-vxworks.c (214634)
1/* VxWorks support for ELF
1/* VxWorks support for ELF
2 Copyright 2005 Free Software Foundation, Inc.
2 Copyright 2005, 2007 Free Software Foundation, Inc.
3
4 This file is part of BFD, the Binary File Descriptor library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10

--- 4 unchanged lines hidden (view full) ---

15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/* This file provides routines used by all VxWorks targets. */
22
3
4 This file is part of BFD, the Binary File Descriptor library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10

--- 4 unchanged lines hidden (view full) ---

15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/* This file provides routines used by all VxWorks targets. */
22
23#include "bfd.h"
24#include "sysdep.h"
23#include "sysdep.h"
24#include "bfd.h"
25#include "libbfd.h"
26#include "elf-bfd.h"
27#include "elf-vxworks.h"
28
25#include "libbfd.h"
26#include "elf-bfd.h"
27#include "elf-vxworks.h"
28
29/* Return true if symbol NAME, as defined by ABFD, is one of the special
30 __GOTT_BASE__ or __GOTT_INDEX__ symbols. */
31
32static bfd_boolean
33elf_vxworks_gott_symbol_p (bfd *abfd, const char *name)
34{
35 char leading;
36
37 leading = bfd_get_symbol_leading_char (abfd);
38 if (leading)
39 {
40 if (*name != leading)
41 return FALSE;
42 name++;
43 }
44 return (strcmp (name, "__GOTT_BASE__") == 0
45 || strcmp (name, "__GOTT_INDEX__") == 0);
46}
47
29/* Tweak magic VxWorks symbols as they are loaded. */
30bfd_boolean
48/* Tweak magic VxWorks symbols as they are loaded. */
49bfd_boolean
31elf_vxworks_add_symbol_hook (bfd *abfd ATTRIBUTE_UNUSED,
50elf_vxworks_add_symbol_hook (bfd *abfd,
32 struct bfd_link_info *info,
33 Elf_Internal_Sym *sym,
34 const char **namep,
35 flagword *flagsp,
36 asection **secp ATTRIBUTE_UNUSED,
37 bfd_vma *valp ATTRIBUTE_UNUSED)
38{
39 /* Ideally these "magic" symbols would be exported by libc.so.1
40 which would be found via a DT_NEEDED tag, and then handled
41 specially by the linker at runtime. Except shared libraries
42 don't even link to libc.so.1 by default...
43 If the symbol is imported from, or will be put in a shared library,
44 give the symbol weak binding to get the desired samantics.
45 This transformation will be undone in
46 elf_i386_vxworks_link_output_symbol_hook. */
47 if ((info->shared || abfd->flags & DYNAMIC)
51 struct bfd_link_info *info,
52 Elf_Internal_Sym *sym,
53 const char **namep,
54 flagword *flagsp,
55 asection **secp ATTRIBUTE_UNUSED,
56 bfd_vma *valp ATTRIBUTE_UNUSED)
57{
58 /* Ideally these "magic" symbols would be exported by libc.so.1
59 which would be found via a DT_NEEDED tag, and then handled
60 specially by the linker at runtime. Except shared libraries
61 don't even link to libc.so.1 by default...
62 If the symbol is imported from, or will be put in a shared library,
63 give the symbol weak binding to get the desired samantics.
64 This transformation will be undone in
65 elf_i386_vxworks_link_output_symbol_hook. */
66 if ((info->shared || abfd->flags & DYNAMIC)
48 && (strcmp (*namep, "__GOTT_INDEX__") == 0
49 || strcmp (*namep, "__GOTT_BASE__") == 0))
67 && elf_vxworks_gott_symbol_p (abfd, *namep))
50 {
51 sym->st_info = ELF_ST_INFO (STB_WEAK, ELF_ST_TYPE (sym->st_info));
52 *flagsp |= BSF_WEAK;
53 }
54
55 return TRUE;
56}
57

--- 51 unchanged lines hidden (view full) ---

109
110/* Tweak magic VxWorks symbols as they are written to the output file. */
111bfd_boolean
112elf_vxworks_link_output_symbol_hook (struct bfd_link_info *info
113 ATTRIBUTE_UNUSED,
114 const char *name,
115 Elf_Internal_Sym *sym,
116 asection *input_sec ATTRIBUTE_UNUSED,
68 {
69 sym->st_info = ELF_ST_INFO (STB_WEAK, ELF_ST_TYPE (sym->st_info));
70 *flagsp |= BSF_WEAK;
71 }
72
73 return TRUE;
74}
75

--- 51 unchanged lines hidden (view full) ---

127
128/* Tweak magic VxWorks symbols as they are written to the output file. */
129bfd_boolean
130elf_vxworks_link_output_symbol_hook (struct bfd_link_info *info
131 ATTRIBUTE_UNUSED,
132 const char *name,
133 Elf_Internal_Sym *sym,
134 asection *input_sec ATTRIBUTE_UNUSED,
117 struct elf_link_hash_entry *h
118 ATTRIBUTE_UNUSED)
135 struct elf_link_hash_entry *h)
119{
136{
120 /* Ignore the first dummy symbol. */
121 if (!name)
122 return TRUE;
123
124 /* Reverse the effects of the hack in elf_vxworks_add_symbol_hook. */
137 /* Reverse the effects of the hack in elf_vxworks_add_symbol_hook. */
125 if (strcmp (name, "__GOTT_INDEX__") == 0
126 || strcmp (name, "__GOTT_BASE__") == 0)
138 if (h
139 && h->root.type == bfd_link_hash_undefweak
140 && elf_vxworks_gott_symbol_p (h->root.u.undef.abfd, name))
127 sym->st_info = ELF_ST_INFO (STB_GLOBAL, ELF_ST_TYPE (sym->st_info));
128
129 return TRUE;
130}
131
132
133/* Copy relocations into the output file. Fixes up relocations againt PLT
134 entries, then calls the generic routine. */

--- 16 unchanged lines hidden (view full) ---

151 irelaend = irela + (NUM_SHDR_ENTRIES (input_rel_hdr)
152 * bed->s->int_rels_per_ext_rel);
153 while (irela < irelaend)
154 {
155 if ((output_bfd->flags & (DYNAMIC|EXEC_P))
156 && *rel_hash
157 && (*rel_hash)->def_dynamic
158 && !(*rel_hash)->def_regular
141 sym->st_info = ELF_ST_INFO (STB_GLOBAL, ELF_ST_TYPE (sym->st_info));
142
143 return TRUE;
144}
145
146
147/* Copy relocations into the output file. Fixes up relocations againt PLT
148 entries, then calls the generic routine. */

--- 16 unchanged lines hidden (view full) ---

165 irelaend = irela + (NUM_SHDR_ENTRIES (input_rel_hdr)
166 * bed->s->int_rels_per_ext_rel);
167 while (irela < irelaend)
168 {
169 if ((output_bfd->flags & (DYNAMIC|EXEC_P))
170 && *rel_hash
171 && (*rel_hash)->def_dynamic
172 && !(*rel_hash)->def_regular
159 && (*rel_hash)->root.type == bfd_link_hash_defined
173 && ((*rel_hash)->root.type == bfd_link_hash_defined
174 || (*rel_hash)->root.type == bfd_link_hash_defweak)
160 && (*rel_hash)->root.u.def.section->output_section != NULL)
161 {
162 /* This is a relocation from an executable or shared library
163 against a symbol in a different shared library. We are
164 creating a definition in the output file but it does not come
165 from any of our normal (.o) files. ie. a PLT stub.
166 Normally this would be a relocation against against SHN_UNDEF
167 with the VMA of the PLT stub. This upsets the VxWorks loader.
168 Convert it to a section-relative relocation.
169 This gets some other symbols (for instance .dynbss),
170 but is conservatively correct. */
171 for (j = 0; j < bed->s->int_rels_per_ext_rel; j++)
172 {
173 asection *sec = (*rel_hash)->root.u.def.section;
175 && (*rel_hash)->root.u.def.section->output_section != NULL)
176 {
177 /* This is a relocation from an executable or shared library
178 against a symbol in a different shared library. We are
179 creating a definition in the output file but it does not come
180 from any of our normal (.o) files. ie. a PLT stub.
181 Normally this would be a relocation against against SHN_UNDEF
182 with the VMA of the PLT stub. This upsets the VxWorks loader.
183 Convert it to a section-relative relocation.
184 This gets some other symbols (for instance .dynbss),
185 but is conservatively correct. */
186 for (j = 0; j < bed->s->int_rels_per_ext_rel; j++)
187 {
188 asection *sec = (*rel_hash)->root.u.def.section;
174 int this_idx =
175 elf_section_data (sec->output_section)->this_idx;
189 int this_idx = sec->output_section->target_index;
176
177 irela[j].r_info = ELF32_R_INFO (this_idx,
178 ELF32_R_TYPE (irela[j].r_info));
179 irela[j].r_addend += (*rel_hash)->root.u.def.value;
180 irela[j].r_addend += sec->output_offset;
181 }
182 /* Stop the generic routine adjusting this entry. */
183 *rel_hash = NULL;

--- 30 unchanged lines hidden ---
190
191 irela[j].r_info = ELF32_R_INFO (this_idx,
192 ELF32_R_TYPE (irela[j].r_info));
193 irela[j].r_addend += (*rel_hash)->root.u.def.value;
194 irela[j].r_addend += sec->output_offset;
195 }
196 /* Stop the generic routine adjusting this entry. */
197 *rel_hash = NULL;

--- 30 unchanged lines hidden ---