Add support for the Z80 processor family
[binutils.git] / bfd / elf-vxworks.c
blob708177a2eeb1ccce25634fd5bba0249ee1a3354b
1 /* VxWorks support for ELF
2 Copyright 2005 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
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.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
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.
21 /* This file provides routines used by all VxWorks targets. */
23 #include "bfd.h"
24 #include "sysdep.h"
25 #include "libbfd.h"
26 #include "elf-bfd.h"
27 #include "elf-vxworks.h"
29 /* Tweak magic VxWorks symbols as they are loaded. */
30 bfd_boolean
31 elf_vxworks_add_symbol_hook (bfd *abfd ATTRIBUTE_UNUSED,
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)
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)
48 && (strcmp (*namep, "__GOTT_INDEX__") == 0
49 || strcmp (*namep, "__GOTT_BASE__") == 0))
51 sym->st_info = ELF_ST_INFO (STB_WEAK, ELF_ST_TYPE (sym->st_info));
52 *flagsp |= BSF_WEAK;
55 return TRUE;
59 /* Tweak magic VxWorks symbols as they are written to the output file. */
60 bfd_boolean
61 elf_vxworks_link_output_symbol_hook (const char *name,
62 Elf_Internal_Sym *sym)
64 /* Reverse the effects of the hack in elf_vxworks_add_symbol_hook. */
65 if (strcmp (name, "__GOTT_INDEX__") == 0
66 || strcmp (name, "__GOTT_BASE__") == 0)
67 sym->st_info = ELF_ST_INFO (STB_GLOBAL, ELF_ST_TYPE (sym->st_info));
69 return TRUE;
73 /* Copy relocations into the output file. Fixes up relocations againt PLT
74 entries, then calls the generic routine. */
76 bfd_boolean
77 elf_vxworks_emit_relocs (bfd *output_bfd,
78 asection *input_section,
79 Elf_Internal_Shdr *input_rel_hdr,
80 Elf_Internal_Rela *internal_relocs,
81 struct elf_link_hash_entry **rel_hash)
83 const struct elf_backend_data *bed;
84 Elf_Internal_Rela *irela;
85 Elf_Internal_Rela *irelaend;
86 int j;
88 bed = get_elf_backend_data (output_bfd);
90 irela = internal_relocs;
91 irelaend = irela + (NUM_SHDR_ENTRIES (input_rel_hdr)
92 * bed->s->int_rels_per_ext_rel);
93 while (irela < irelaend)
95 if ((output_bfd->flags & (DYNAMIC|EXEC_P))
96 && *rel_hash
97 && (*rel_hash)->def_dynamic
98 && !(*rel_hash)->def_regular
99 && (*rel_hash)->root.type == bfd_link_hash_defined
100 && (*rel_hash)->root.u.def.section->output_section != NULL)
102 /* This is a relocation from an executable or shared library
103 against a symbol in a different shared library. We are
104 creating a definition in the output file but it does not come
105 from any of our normal (.o) files. ie. a PLT stub.
106 Normally this would be a relocation against against SHN_UNDEF
107 with the VMA of the PLT stub. This upsets the VxWorks loader.
108 Convert it to a section-relative relocation.
109 This gets some other symbols (for instance .dynbss),
110 but is conservatively correct. */
111 for (j = 0; j < bed->s->int_rels_per_ext_rel; j++)
113 asection *sec = (*rel_hash)->root.u.def.section;
114 int this_idx =
115 elf_section_data (sec->output_section)->this_idx;
117 irela[j].r_info = ELF32_R_INFO (this_idx,
118 ELF32_R_TYPE (irela[j].r_info));
119 irela[j].r_addend += (*rel_hash)->root.u.def.value;
120 irela[j].r_addend += sec->output_offset;
122 /* Stop the generic routine adjusting this entry. */
123 *rel_hash = NULL;
125 irela += bed->s->int_rels_per_ext_rel;
126 rel_hash++;
128 return _bfd_elf_link_output_relocs (output_bfd, input_section,
129 input_rel_hdr, internal_relocs,
130 rel_hash);
134 /* Set the sh_link and sh_info fields on the static plt relocation secton. */
136 void
137 elf_vxworks_final_write_processing (bfd *abfd,
138 bfd_boolean linker ATTRIBUTE_UNUSED)
140 asection * sec;
141 struct bfd_elf_section_data *d;
143 sec = bfd_get_section_by_name (abfd, ".rel.plt.unloaded");
144 if (!sec)
145 sec = bfd_get_section_by_name (abfd, ".rela.plt.unloaded");
146 if (!sec)
147 return;
148 d = elf_section_data (sec);
149 d->this_hdr.sh_link = elf_tdata (abfd)->symtab_section;
150 sec = bfd_get_section_by_name (abfd, ".plt");
151 if (sec)
152 d->this_hdr.sh_info = elf_section_data (sec)->this_idx;